diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index fb04d7b7a18..9755022e313 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -51,6 +51,7 @@ namespace ts { getCachedDirectoryStructureHost(): CachedDirectoryStructureHost | undefined; projectName?: string; getGlobalCache?(): string | undefined; + globalCacheResolutionModuleName?(externalModuleName: string): string; writeLog(s: string): void; maxNumberOfFilesToIterateForInvalidation?: number; getCurrentProgram(): Program | undefined; @@ -235,7 +236,12 @@ namespace ts { if (globalCache !== undefined && !isExternalModuleNameRelative(moduleName) && !(primaryResult.resolvedModule && extensionIsTS(primaryResult.resolvedModule.extension))) { // create different collection of failed lookup locations for second pass // if it will fail and we've already found something during the first pass - we don't want to pollute its results - const { resolvedModule, failedLookupLocations } = loadModuleFromGlobalCache(moduleName, resolutionHost.projectName, compilerOptions, host, globalCache); + const { resolvedModule, failedLookupLocations } = loadModuleFromGlobalCache( + Debug.assertDefined(resolutionHost.globalCacheResolutionModuleName)(moduleName), + resolutionHost.projectName, + compilerOptions, + host, + globalCache); if (resolvedModule) { return { resolvedModule, failedLookupLocations: addRange(primaryResult.failedLookupLocations as string[], failedLookupLocations) }; } diff --git a/src/jsTyping/jsTyping.ts b/src/jsTyping/jsTyping.ts index 379ca6491a6..c2b2ad3f5b3 100644 --- a/src/jsTyping/jsTyping.ts +++ b/src/jsTyping/jsTyping.ts @@ -70,6 +70,10 @@ namespace ts.JsTyping { export const nodeCoreModules = arrayToSet(nodeCoreModuleList); + export function nonRelativeModuleNameForTypingCache(moduleName: string) { + return nodeCoreModules.has(moduleName) ? "node" : moduleName; + } + /** * A map of loose file names to library names that we are confident require typings */ @@ -150,7 +154,7 @@ namespace ts.JsTyping { // add typings for unresolved imports if (unresolvedImports) { const module = deduplicate( - unresolvedImports.map(moduleId => nodeCoreModules.has(moduleId) ? "node" : moduleId), + unresolvedImports.map(nonRelativeModuleNameForTypingCache), equateStringsCaseSensitive, compareStringsCaseSensitive); addInferredTypings(module, "Inferred typings from unresolved imports"); diff --git a/src/server/project.ts b/src/server/project.ts index e10a0988f71..a1a43a430f1 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -457,6 +457,9 @@ namespace ts.server { return this.getTypeAcquisition().enable ? this.projectService.typingsInstaller.globalTypingsCacheLocation : undefined; } + /*@internal*/ + globalCacheResolutionModuleName = JsTyping.nonRelativeModuleNameForTypingCache; + /*@internal*/ fileIsOpen(filePath: Path) { return this.projectService.openFiles.has(filePath); diff --git a/src/testRunner/unittests/tsserver/typingsInstaller.ts b/src/testRunner/unittests/tsserver/typingsInstaller.ts index a2111d131e9..bcce68fe0de 100644 --- a/src/testRunner/unittests/tsserver/typingsInstaller.ts +++ b/src/testRunner/unittests/tsserver/typingsInstaller.ts @@ -1831,9 +1831,11 @@ declare module "stream" { checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]); // Here, since typings doesnt contain node typings and resolution fails and - // node typings go out of project + // node typings go out of project, + // but because we handle core node modules when resolving from typings cache + // node typings are included in the project host.checkTimeoutQueueLengthAndRun(2); - checkProjectActualFiles(proj, [file.path, libFile.path]); + checkProjectActualFiles(proj, [file.path, libFile.path, nodeTyping.path]); }); });