Skip to content

Commit af081f7

Browse files
committed
Do check for ambient module to determine if resolution should be watched.
1 parent 42cb772 commit af081f7

File tree

7 files changed

+28
-31
lines changed

7 files changed

+28
-31
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,
@@ -498,7 +497,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
498497
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
499498
let filesWithInvalidatedResolutions: Set<Path> | undefined;
500499
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyMap<Path, readonly string[]> | undefined;
501-
const nonRelativeExternalModuleResolutions = createMultiMap<string, ResolutionWithFailedLookupLocations>();
500+
const nonRelativeExternalModuleResolutions = new Set<ResolutionWithFailedLookupLocations>();
502501

503502
const resolutionsWithFailedLookups = new Set<ResolutionWithFailedLookupLocations>();
504503
const resolutionsWithOnlyAffectingLocations = new Set<ResolutionWithFailedLookupLocations>();
@@ -673,8 +672,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
673672
libraryResolutionCache.clearAllExceptPackageJsonInfoCache();
674673
// perDirectoryResolvedModuleNames and perDirectoryResolvedTypeReferenceDirectives could be non empty if there was exception during program update
675674
// (between startCachingPerDirectoryResolution and finishCachingPerDirectoryResolution)
676-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
677-
nonRelativeExternalModuleResolutions.clear();
675+
watchFailedLookupLocationOfNonRelativeModuleResolutions();
678676
}
679677

680678
function cleanupLibResolutionWatching(newProgram: Program | undefined) {
@@ -693,8 +691,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
693691
function finishCachingPerDirectoryResolution(newProgram: Program | undefined, oldProgram: Program | undefined) {
694692
filesWithInvalidatedNonRelativeUnresolvedImports = undefined;
695693
allModuleAndTypeResolutionsAreInvalidated = false;
696-
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
697-
nonRelativeExternalModuleResolutions.clear();
694+
watchFailedLookupLocationOfNonRelativeModuleResolutions();
698695
// Update file watches
699696
if (newProgram !== oldProgram) {
700697
cleanupLibResolutionWatching(newProgram);
@@ -983,7 +980,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
983980
watchFailedLookupLocationOfResolution(resolution);
984981
}
985982
else {
986-
nonRelativeExternalModuleResolutions.add(name, resolution);
983+
nonRelativeExternalModuleResolutions.add(resolution);
987984
}
988985
const resolved = getResolutionWithResolvedFileName(resolution);
989986
if (resolved && resolved.resolvedFileName) {
@@ -1116,14 +1113,9 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
11161113
packageJsonMap?.delete(resolutionHost.toPath(path));
11171114
}
11181115

1119-
function watchFailedLookupLocationOfNonRelativeModuleResolutions(resolutions: ResolutionWithFailedLookupLocations[], name: string) {
1120-
const program = resolutionHost.getCurrentProgram();
1121-
if (!program || !program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(name)) {
1122-
resolutions.forEach(watchFailedLookupLocationOfResolution);
1123-
}
1124-
else {
1125-
resolutions.forEach(resolution => watchAffectingLocationsOfResolution(resolution, /*addToResolutionsWithOnlyAffectingLocations*/ true));
1126-
}
1116+
function watchFailedLookupLocationOfNonRelativeModuleResolutions() {
1117+
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfResolution);
1118+
nonRelativeExternalModuleResolutions.clear();
11271119
}
11281120

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

src/testRunner/unittests/helpers/tscWatch.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export interface TscWatchCompileChange<T extends ts.BuilderProgram = ts.EmitAndS
4040
) => void;
4141
// TODO:: sheetal: Needing these fields are technically issues that need to be fixed later
4242
symlinksNotReflected?: readonly string[];
43-
skipStructureCheck?: true;
4443
}
4544
export interface TscWatchCheckOptions {
4645
baselineSourceMap?: boolean;
@@ -239,7 +238,7 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
239238
});
240239

241240
if (edits) {
242-
for (const { caption, edit, timeouts, symlinksNotReflected, skipStructureCheck } of edits) {
241+
for (const { caption, edit, timeouts, symlinksNotReflected } of edits) {
243242
oldSnap = applyEdit(sys, baseline, edit, caption);
244243
timeouts(sys, programs, watchOrSolution);
245244
programs = watchBaseline({
@@ -251,7 +250,7 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
251250
baselineSourceMap,
252251
baselineDependencies,
253252
caption,
254-
resolutionCache: !skipStructureCheck ? (watchOrSolution as ts.WatchOfConfigFile<T> | undefined)?.getResolutionCache?.() : undefined,
253+
resolutionCache: (watchOrSolution as ts.WatchOfConfigFile<T> | undefined)?.getResolutionCache?.(),
255254
useSourceOfProjectReferenceRedirect,
256255
symlinksNotReflected,
257256
});

src/testRunner/unittests/tscWatch/resolutionCache.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@ declare module "fs" {
296296
}
297297
`),
298298
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
299-
// This is currently issue with ambient modules in same file not leading to resolution watching
300-
// In this case initially resolution is watched and will continued to be watched but
301-
// incremental check will determine that the resolution should not be watched as thats what would have happened if we had started tsc --watch at this state.
302-
skipStructureCheck: true,
303299
}
304300
]
305301
});

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)