@@ -6488,4 +6488,76 @@ namespace ts.projectSystem {
6488
6488
verifyWatchedDirectories ( /*useProjectAtRoot*/ false ) ;
6489
6489
} ) ;
6490
6490
} ) ;
6491
+
6492
+ describe ( "tsserverProjectSystem typingsInstaller on inferred Project" , ( ) => {
6493
+ it ( "when projectRootPath is provided" , ( ) => {
6494
+ const projects = "/users/username/projects" ;
6495
+ const projectRootPath = `${ projects } /san2` ;
6496
+ const file : FileOrFolder = {
6497
+ path : `${ projectRootPath } /x.js` ,
6498
+ content : "const aaaaaaav = 1;"
6499
+ } ;
6500
+
6501
+ const currentDirectory = `${ projects } /anotherProject` ;
6502
+ const packageJsonInCurrentDirectory : FileOrFolder = {
6503
+ path : `${ currentDirectory } /package.json` ,
6504
+ content : JSON . stringify ( {
6505
+ devDependencies : {
6506
+ pkgcurrentdirectory : ""
6507
+ } ,
6508
+ } )
6509
+ } ;
6510
+ const packageJsonOfPkgcurrentdirectory : FileOrFolder = {
6511
+ path : `${ currentDirectory } /node_modules/pkgcurrentdirectory/package.json` ,
6512
+ content : JSON . stringify ( {
6513
+ name : "pkgcurrentdirectory" ,
6514
+ main : "index.js" ,
6515
+ typings : "index.d.ts"
6516
+ } )
6517
+ } ;
6518
+ const indexOfPkgcurrentdirectory : FileOrFolder = {
6519
+ path : `${ currentDirectory } /node_modules/pkgcurrentdirectory/index.d.ts` ,
6520
+ content : "export function foo() { }"
6521
+ } ;
6522
+
6523
+ const typingsCache = `/users/username/Library/Caches/typescript/2.7` ;
6524
+ const typingsCachePackageJson : FileOrFolder = {
6525
+ path : `${ typingsCache } /package.json` ,
6526
+ content : JSON . stringify ( {
6527
+ devDependencies : {
6528
+ } ,
6529
+ } )
6530
+ } ;
6531
+
6532
+ const files = [ file , packageJsonInCurrentDirectory , packageJsonOfPkgcurrentdirectory , indexOfPkgcurrentdirectory , typingsCachePackageJson ] ;
6533
+ const host = createServerHost ( files , { currentDirectory } ) ;
6534
+
6535
+ const typesRegistry = createMap < void > ( ) ;
6536
+ typesRegistry . set ( "pkgcurrentdirectory" , void 0 ) ;
6537
+ const typingsInstaller = new TestTypingsInstaller ( typingsCache , /*throttleLimit*/ 5 , host , typesRegistry ) ;
6538
+
6539
+ const projectService = createProjectService ( host , { typingsInstaller } ) ;
6540
+
6541
+ projectService . setCompilerOptionsForInferredProjects ( {
6542
+ module : ModuleKind . CommonJS ,
6543
+ target : ScriptTarget . ES2016 ,
6544
+ jsx : JsxEmit . Preserve ,
6545
+ experimentalDecorators : true ,
6546
+ allowJs : true ,
6547
+ allowSyntheticDefaultImports : true ,
6548
+ allowNonTsExtensions : true
6549
+ } ) ;
6550
+
6551
+ projectService . openClientFile ( file . path , file . content , ScriptKind . JS , projectRootPath ) ;
6552
+
6553
+ const project = projectService . inferredProjects [ 0 ] ;
6554
+ assert . isDefined ( project ) ;
6555
+
6556
+ // Ensure that we use result from types cache when getting ls
6557
+ assert . isDefined ( project . getLanguageService ( ) ) ;
6558
+
6559
+ // Verify that the pkgcurrentdirectory from the current directory isnt picked up
6560
+ checkProjectActualFiles ( project , [ file . path ] ) ;
6561
+ } ) ;
6562
+ } ) ;
6491
6563
}
0 commit comments