@@ -999,14 +999,14 @@ namespace ts.projectSystem {
999
999
proj . updateGraph ( ) ;
1000
1000
1001
1001
assert . deepEqual (
1002
- proj . getCachedUnresolvedImportsPerFile_TestOnly ( ) . get ( < Path > f1 . path ) ,
1002
+ proj . cachedUnresolvedImportsPerFile . get ( < Path > f1 . path ) ,
1003
1003
[ "foo" , "foo" , "foo" , "@bar/router" , "@bar/common" , "@bar/common" ]
1004
1004
) ;
1005
1005
1006
1006
installer . installAll ( /*expectedCount*/ 1 ) ;
1007
1007
} ) ;
1008
1008
1009
- it ( "should recompute resolutions after typings are installed " , ( ) => {
1009
+ it ( "cached unresolved typings are not recomputed if program structure did not change " , ( ) => {
1010
1010
const host = createServerHost ( [ ] ) ;
1011
1011
const session = createSession ( host ) ;
1012
1012
const f = {
@@ -1029,7 +1029,7 @@ namespace ts.projectSystem {
1029
1029
const projectService = session . getProjectService ( ) ;
1030
1030
checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
1031
1031
const proj = projectService . inferredProjects [ 0 ] ;
1032
- const version1 = proj . getCachedUnresolvedImportsPerFile_TestOnly ( ) . getVersion ( ) ;
1032
+ const version1 = proj . lastCachedUnresolvedImportsList ;
1033
1033
1034
1034
// make a change that should not affect the structure of the program
1035
1035
const changeRequest : server . protocol . ChangeRequest = {
@@ -1047,8 +1047,8 @@ namespace ts.projectSystem {
1047
1047
} ;
1048
1048
session . executeCommand ( changeRequest ) ;
1049
1049
host . checkTimeoutQueueLengthAndRun ( 2 ) ; // This enqueues the updategraph and refresh inferred projects
1050
- const version2 = proj . getCachedUnresolvedImportsPerFile_TestOnly ( ) . getVersion ( ) ;
1051
- assert . notEqual ( version1 , version2 , "set of unresolved imports should change" ) ;
1050
+ const version2 = proj . lastCachedUnresolvedImportsList ;
1051
+ assert . strictEqual ( version1 , version2 , "set of unresolved imports should change" ) ;
1052
1052
} ) ;
1053
1053
1054
1054
it ( "expired cache entry (inferred project, should install typings)" , ( ) => {
@@ -1621,4 +1621,75 @@ namespace ts.projectSystem {
1621
1621
assert . deepEqual ( commands , expectedCommands , "commands" ) ;
1622
1622
} ) ;
1623
1623
} ) ;
1624
+
1625
+ describe ( "recomputing resolutions of unresolved imports" , ( ) => {
1626
+ const globalTypingsCacheLocation = "/tmp" ;
1627
+ const appPath = "/a/b/app.js" as Path ;
1628
+ const foooPath = "/a/b/node_modules/fooo/index.d.ts" ;
1629
+ function verifyResolvedModuleOfFooo ( project : server . Project ) {
1630
+ const foooResolution = project . getLanguageService ( ) . getProgram ( ) . getSourceFileByPath ( appPath ) . resolvedModules . get ( "fooo" ) ;
1631
+ assert . equal ( foooResolution . resolvedFileName , foooPath ) ;
1632
+ return foooResolution ;
1633
+ }
1634
+
1635
+ function verifyUnresolvedImportResolutions ( appContents : string , typingNames : string [ ] , typingFiles : FileOrFolder [ ] ) {
1636
+ const app : FileOrFolder = {
1637
+ path : appPath ,
1638
+ content : `${ appContents } import * as x from "fooo";`
1639
+ } ;
1640
+ const fooo : FileOrFolder = {
1641
+ path : foooPath ,
1642
+ content : `export var x: string;`
1643
+ } ;
1644
+ const host = createServerHost ( [ app , fooo ] ) ;
1645
+ const installer = new ( class extends Installer {
1646
+ constructor ( ) {
1647
+ super ( host , { globalTypingsCacheLocation, typesRegistry : createTypesRegistry ( "foo" ) } ) ;
1648
+ }
1649
+ installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : TI . RequestCompletedAction ) {
1650
+ executeCommand ( this , host , typingNames , typingFiles , cb ) ;
1651
+ }
1652
+ } ) ( ) ;
1653
+ const projectService = createProjectService ( host , { typingsInstaller : installer } ) ;
1654
+ projectService . openClientFile ( app . path ) ;
1655
+ projectService . checkNumberOfProjects ( { inferredProjects : 1 } ) ;
1656
+
1657
+ const proj = projectService . inferredProjects [ 0 ] ;
1658
+ checkProjectActualFiles ( proj , [ app . path , fooo . path ] ) ;
1659
+ const foooResolution1 = verifyResolvedModuleOfFooo ( proj ) ;
1660
+
1661
+ installer . installAll ( /*expectedCount*/ 1 ) ;
1662
+ host . checkTimeoutQueueLengthAndRun ( 2 ) ;
1663
+ checkProjectActualFiles ( proj , typingFiles . map ( f => f . path ) . concat ( app . path , fooo . path ) ) ;
1664
+ const foooResolution2 = verifyResolvedModuleOfFooo ( proj ) ;
1665
+ assert . strictEqual ( foooResolution1 , foooResolution2 ) ;
1666
+ }
1667
+
1668
+ it ( "correctly invalidate the resolutions with typing names" , ( ) => {
1669
+ verifyUnresolvedImportResolutions ( 'import * as a from "foo";' , [ "foo" ] , [ {
1670
+ path : `${ globalTypingsCacheLocation } /node_modules/foo/index.d.ts` ,
1671
+ content : "export function a(): void;"
1672
+ } ] ) ;
1673
+ } ) ;
1674
+
1675
+ it ( "correctly invalidate the resolutions with typing names that are trimmed" , ( ) => {
1676
+ const fooAA : FileOrFolder = {
1677
+ path : `${ globalTypingsCacheLocation } /node_modules/foo/a/a.d.ts` ,
1678
+ content : "export function a (): void;"
1679
+ } ;
1680
+ const fooAB : FileOrFolder = {
1681
+ path : `${ globalTypingsCacheLocation } /node_modules/foo/a/b.d.ts` ,
1682
+ content : "export function b (): void;"
1683
+ } ;
1684
+ const fooAC : FileOrFolder = {
1685
+ path : `${ globalTypingsCacheLocation } /node_modules/foo/a/c.d.ts` ,
1686
+ content : "export function c (): void;"
1687
+ } ;
1688
+ verifyUnresolvedImportResolutions ( `
1689
+ import * as a from "foo/a/a";
1690
+ import * as b from "foo/a/b";
1691
+ import * as c from "foo/a/c";
1692
+ ` , [ "foo" ] , [ fooAA , fooAB , fooAC ] ) ;
1693
+ } ) ;
1694
+ } ) ;
1624
1695
}
0 commit comments