Skip to content

Commit cabe48e

Browse files
committed
Do check for ambient module to determine if resolution should be watched.
1 parent d210074 commit cabe48e

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

src/compiler/resolutionCache.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
CompilerOptions,
88
createModeAwareCache,
99
createModuleResolutionCache,
10-
createMultiMap,
1110
createTypeReferenceDirectiveResolutionCache,
1211
createTypeReferenceResolutionLoader,
1312
Debug,
@@ -418,7 +417,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
418417
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
419418
let filesWithInvalidatedResolutions: Set<Path> | undefined;
420419
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyMap<Path, readonly string[]> | undefined;
421-
const nonRelativeExternalModuleResolutions = createMultiMap<string, ResolutionWithFailedLookupLocations>();
420+
const nonRelativeExternalModuleResolutions = new Set<ResolutionWithFailedLookupLocations>();
422421

423422
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
424423
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();
@@ -583,8 +582,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
583582
libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
584583
// perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
585584
// (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
586-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
587-
nonRelativeExternalModuleResolutions.clear();
585+
watchFailedLookupLocationOfNonRelativeModuleResolutions();
588586
}
589587

590588
function cleanupLibResolutionWatching(newProgram: Program | undefined) {
@@ -603,8 +601,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
603601
function finishCachingPerDirectoryResolution(newProgram: Program | undefined, oldProgram: Program | undefined) {
604602
filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
605603
allModuleAndTypeResolutionsAreInvalidated = false;
606-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
607-
nonRelativeExternalModuleResolutions.clear();
604+
watchFailedLookupLocationOfNonRelativeModuleResolutions();
608605
// Update file watches
609606
if (newProgram !== oldProgram) {
610607
cleanupLibResolutionWatching(newProgram);
@@ -944,7 +941,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
944941
watchFailedLookupLocationOfResolution(resolution);
945942
}
946943
else {
947-
nonRelativeExternalModuleResolutions.add(name, resolution);
944+
nonRelativeExternalModuleResolutions.add(resolution);
948945
}
949946
const resolved = getResolutionWithResolvedFileName(resolution);
950947
if (resolved && resolved.resolvedFileName) {
@@ -1065,14 +1062,9 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
10651062
}
10661063
}
10671064

1068-
function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions: ResolutionWithFailedLookupLocations[], name: string) {
1069-
const program = resolutionHost.getCurrentProgram();
1070-
if (!program || !program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name)) {
1071-
resolutions.forEach(watchFailedLookupLocationOfResolution);
1072-
}
1073-
else {
1074-
resolutions.forEach(resolution => watchAffectingLocationsOfResolution(resolution, /*addToResolutionsWithOnlyAffectingLocations*/ true));
1075-
}
1065+
function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
1066+
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
1067+
nonRelativeExternalModuleResolutions.clear();
10761068
}
10771069

10781070
function setDirectoryWatcher(dir: string, dirPath: Path, nonRecursive?: boolean) {

tests/baselines/reference/tscWatch/resolutionCache/works-when-module-resolution-changes-to-ambient-module.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,10 @@ Shape signatures in builder refreshed for::
145145
/users/username/projects/project/node_modules/@types/node/index.d.ts (used version)
146146

147147
PolledWatches::
148-
/users/username/projects/node_modules/@types:
149-
{"pollingInterval":500}
150-
151-
PolledWatches *deleted*::
152148
/users/username/projects/node_modules:
153149
{"pollingInterval":500}
150+
/users/username/projects/node_modules/@types:
151+
{"pollingInterval":500}
154152

155153
FsWatches::
156154
/a/lib/lib.d.ts:
@@ -163,12 +161,10 @@ FsWatches::
163161
{}
164162

165163
FsWatchesRecursive::
166-
/users/username/projects/project/node_modules/@types:
167-
{}
168-
169-
FsWatchesRecursive *deleted*::
170164
/users/username/projects/project/node_modules:
171165
{}
166+
/users/username/projects/project/node_modules/@types:
167+
{}
172168

173169
exitCode:: ExitStatus.undefined
174170

tests/baselines/reference/tsserver/completions/works-when-files-are-included-from-two-different-drives-of-windows.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: e:/myproject/node
9292
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: e:/myproject/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
9393
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: c:/typescript/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
9494
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: c:/typescript/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
95-
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: c:/typescript/node_modules/@types/react/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
9695
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: e:/myproject/node_modules/react-router-dom/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
9796
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: c:/typescript/node_modules/@types/react-router-dom/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
97+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: c:/typescript/node_modules/@types/react/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
9898
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: e:/myproject/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
9999
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: e:/myproject/src/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
100100
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: e:/myproject/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots

tests/baselines/reference/tsserver/projectErrors/correct-errors-when-resolution-resolves-to-file-that-has-same-ambient-module-and-is-also-module.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /us
7474
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
7575
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
7676
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
77+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/src 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
78+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/src 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Failed Lookup Locations
7779
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules/@types 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Type roots
7880
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/myproject/node_modules/@types 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Type roots
7981
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/node_modules/@types 1 undefined Project: /users/username/projects/myproject/tsconfig.json WatchType: Type roots

tests/baselines/reference/tsserver/resolutionCache/when-resolves-to-ambient-module.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/pr
100100
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node_modules 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
101101
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
102102
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
103+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
104+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
105+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
106+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
107+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
108+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src 0 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Failed Lookup Locations
103109
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots
104110
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/typings 1 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: Type roots
105111
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/projects/myproject/src/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
@@ -155,6 +161,12 @@ PolledWatches::
155161
FsWatches::
156162
/a/lib/lib.d.ts: *new*
157163
{}
164+
/user/username/projects: *new*
165+
{}
166+
/user/username/projects/myproject: *new*
167+
{}
168+
/user/username/projects/myproject/src: *new*
169+
{}
158170
/user/username/projects/myproject/src/somefolder/module1.ts: *new*
159171
{}
160172
/user/username/projects/myproject/src/tsconfig.json: *new*

0 commit comments

Comments
 (0)