@@ -999,14 +999,14 @@ namespace ts.projectSystem {
999999 proj . updateGraph ( ) ;
10001000
10011001 assert . deepEqual (
1002- proj . getCachedUnresolvedImportsPerFile_TestOnly ( ) . get ( < Path > f1 . path ) ,
1002+ proj . cachedUnresolvedImportsPerFile . get ( < Path > f1 . path ) ,
10031003 [ "foo" , "foo" , "foo" , "@bar/router" , "@bar/common" , "@bar/common" ]
10041004 ) ;
10051005
10061006 installer . installAll ( /*expectedCount*/ 1 ) ;
10071007 } ) ;
10081008
1009- it ( "should recompute resolutions after typings are installed " , ( ) => {
1009+ it ( "cached unresolved typings are not recomputed if program structure did not change " , ( ) => {
10101010 const host = createServerHost ( [ ] ) ;
10111011 const session = createSession ( host ) ;
10121012 const f = {
@@ -1029,7 +1029,7 @@ namespace ts.projectSystem {
10291029 const projectService = session . getProjectService ( ) ;
10301030 checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
10311031 const proj = projectService . inferredProjects [ 0 ] ;
1032- const version1 = proj . getCachedUnresolvedImportsPerFile_TestOnly ( ) . getVersion ( ) ;
1032+ const version1 = proj . lastCachedUnresolvedImportsList ;
10331033
10341034 // make a change that should not affect the structure of the program
10351035 const changeRequest : server . protocol . ChangeRequest = {
@@ -1047,8 +1047,8 @@ namespace ts.projectSystem {
10471047 } ;
10481048 session . executeCommand ( changeRequest ) ;
10491049 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" ) ;
10521052 } ) ;
10531053
10541054 it ( "expired cache entry (inferred project, should install typings)" , ( ) => {
@@ -1621,4 +1621,75 @@ namespace ts.projectSystem {
16211621 assert . deepEqual ( commands , expectedCommands , "commands" ) ;
16221622 } ) ;
16231623 } ) ;
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+ } ) ;
16241695}
0 commit comments