diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 9a5e6d29504..c875c7fa72b 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -893,21 +893,37 @@ function compilerOptionValueToString(value: unknown): string { } /** @internal */ -export function getKeyForCompilerOptions(currentDirectory: string | undefined, options: CompilerOptions, affectingOptionDeclarations: readonly CommandLineOption[]) { +export function getKeyForCompilerOptions( + options: CompilerOptions, + host: ModuleResolutionHost | undefined, + currentDirectory: string, + affectingOptionDeclarations: readonly CommandLineOption[], +) { return affectingOptionDeclarations.map(option => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|") + `|${options.pathsBasePath}` // TypeRoots are already serialized before so no need to serialize again - + `|${getEffectiveTypeRootsForKeyOfCompilerOptions(options, currentDirectory)}`; + + `|${tryGetDefaultEffectiveTypeRoots(options, host, currentDirectory)}`; } -function getEffectiveTypeRootsForKeyOfCompilerOptions( +/** @internal */ +export function tryGetDefaultEffectiveTypeRoots( options: CompilerOptions, - currentDirectory: string | undefined, + host: ModuleResolutionHost | undefined, + currentDirectory: string, ) { - // TypeRoots are already serialized before so no need to serialize again + // TypeRoots are already handled by affectsModuleResolution so caller of this method has handled them if (options.typeRoots) return undefined; // Get the directory to traverse for type roots - return options.configFilePath ? getDirectoryPath(options.configFilePath) : currentDirectory; + const mainDirForTypeRoots = options.configFilePath ? getDirectoryPath(options.configFilePath) : + host?.getCurrentDirectory ? host.getCurrentDirectory() : + currentDirectory; + if (!mainDirForTypeRoots || !host?.directoryExists) return mainDirForTypeRoots; + // Filter out non-existent directories + let typeRoots: string[] | undefined; + forEachAncestorDirectory(normalizePath(mainDirForTypeRoots), directory => { + if (host.directoryExists!(combinePaths(directory, nodeModulesAtTypes))) (typeRoots ??= []).push(directory); + }); + return typeRoots && compilerOptionValueToString(typeRoots); } /** @internal */ @@ -921,10 +937,10 @@ export interface CacheWithRedirects { /** @internal */ export type RedirectsCacheKey = string & { __compilerOptionsKey: any; }; -/** @internal */ -export function createCacheWithRedirects( +function createCacheWithRedirects( currentDirectory: string, ownOptions: CompilerOptions | undefined, + getModuleResolutionHost: (() => ModuleResolutionHost) | undefined, optionsToRedirectsKey: Map, ): CacheWithRedirects { const redirectsMap = new Map>(); @@ -979,13 +995,11 @@ export function createCacheWithRedirects( } function clear() { - const ownKey = ownOptions && optionsToRedirectsKey.get(ownOptions); ownMap.clear(); redirectsMap.clear(); optionsToRedirectsKey.clear(); redirectsKeyToMap.clear(); if (ownOptions) { - if (ownKey) optionsToRedirectsKey.set(ownOptions, ownKey); redirectsMap.set(ownOptions, ownMap); } } @@ -993,7 +1007,15 @@ export function createCacheWithRedirects( function getRedirectsCacheKey(options: CompilerOptions) { let result = optionsToRedirectsKey.get(options); if (!result) { - optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(currentDirectory, options, moduleResolutionOptionDeclarations) as RedirectsCacheKey); + optionsToRedirectsKey.set( + options, + result = getKeyForCompilerOptions( + options, + getModuleResolutionHost?.(), + currentDirectory, + moduleResolutionOptionDeclarations, + ) as RedirectsCacheKey, + ); } return result; } @@ -1034,11 +1056,13 @@ function createPerDirectoryResolutionCache( currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, options: CompilerOptions | undefined, + getModuleResolutionHost: (() => ModuleResolutionHost) | undefined, optionsToRedirectsKey: Map, ): PerDirectoryResolutionCache { const directoryToModuleNameMap = createCacheWithRedirects>( currentDirectory, options, + getModuleResolutionHost, optionsToRedirectsKey, ); return { @@ -1142,11 +1166,13 @@ function createNonRelativeNameResolutionCache( getCanonicalFileName: (s: string) => string, options: CompilerOptions | undefined, getResolvedFileName: (result: T) => string | undefined, + getModuleResolutionHost: (() => ModuleResolutionHost) | undefined, optionsToRedirectsKey: Map, ): NonRelativeNameResolutionCache { const moduleNameToDirectoryMap = createCacheWithRedirects>( currentDirectory, options, + getModuleResolutionHost, optionsToRedirectsKey, ); return { @@ -1257,6 +1283,7 @@ function createModuleOrTypeReferenceResolutionCache( options: CompilerOptions | undefined, packageJsonInfoCache: PackageJsonInfoCache | undefined, getResolvedFileName: (result: T) => string | undefined, + getModuleResolutionHost: (() => ModuleResolutionHost) | undefined, optionsToRedirectsKey: Map | undefined, ): ModuleOrTypeReferenceResolutionCache { optionsToRedirectsKey ??= new Map(); @@ -1264,6 +1291,7 @@ function createModuleOrTypeReferenceResolutionCache( currentDirectory, getCanonicalFileName, options, + getModuleResolutionHost, optionsToRedirectsKey, ); const nonRelativeNameResolutionCache = createNonRelativeNameResolutionCache( @@ -1271,6 +1299,7 @@ function createModuleOrTypeReferenceResolutionCache( getCanonicalFileName, options, getResolvedFileName, + getModuleResolutionHost, optionsToRedirectsKey, ); packageJsonInfoCache ??= createPackageJsonInfoCache(currentDirectory, getCanonicalFileName); @@ -1307,21 +1336,7 @@ export function createModuleResolutionCache( getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache, -): ModuleResolutionCache; -/** @internal */ -export function createModuleResolutionCache( - currentDirectory: string, - getCanonicalFileName: (s: string) => string, - options?: CompilerOptions, - packageJsonInfoCache?: PackageJsonInfoCache, - optionsToRedirectsKey?: Map, -): ModuleResolutionCache; -export function createModuleResolutionCache( - currentDirectory: string, - getCanonicalFileName: (s: string) => string, - options?: CompilerOptions, - packageJsonInfoCache?: PackageJsonInfoCache, - optionsToRedirectsKey?: Map, + getModuleResolutionHost?: () => ModuleResolutionHost, ): ModuleResolutionCache { const result = createModuleOrTypeReferenceResolutionCache( currentDirectory, @@ -1329,7 +1344,8 @@ export function createModuleResolutionCache( options, packageJsonInfoCache, getOriginalOrResolvedModuleFileName, - optionsToRedirectsKey, + getModuleResolutionHost, + /*optionsToRedirectsKey*/ undefined, ) as ModuleResolutionCache; result.getOrCreateCacheForModuleName = (nonRelativeName, mode, redirectedReference) => result.getOrCreateCacheForNonRelativeName(nonRelativeName, mode, redirectedReference); return result; @@ -1340,6 +1356,7 @@ export function createTypeReferenceDirectiveResolutionCache( getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache, + getModuleResolutionHost?: () => ModuleResolutionHost, ): TypeReferenceDirectiveResolutionCache; /** @internal */ export function createTypeReferenceDirectiveResolutionCache( @@ -1347,6 +1364,7 @@ export function createTypeReferenceDirectiveResolutionCache( getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache, + getModuleResolutionHost?: () => ModuleResolutionHost, optionsToRedirectsKey?: Map, ): TypeReferenceDirectiveResolutionCache; export function createTypeReferenceDirectiveResolutionCache( @@ -1354,6 +1372,7 @@ export function createTypeReferenceDirectiveResolutionCache( getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache, + getModuleResolutionHost?: () => ModuleResolutionHost, optionsToRedirectsKey?: Map, ): TypeReferenceDirectiveResolutionCache { return createModuleOrTypeReferenceResolutionCache( @@ -1362,6 +1381,7 @@ export function createTypeReferenceDirectiveResolutionCache( options, packageJsonInfoCache, getOriginalOrResolvedTypeReferenceFileName, + getModuleResolutionHost, optionsToRedirectsKey, ); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 113c9561791..3c76633e615 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -133,6 +133,7 @@ import { getNormalizedAbsolutePath, getNormalizedAbsolutePathWithoutRoot, getNormalizedPathComponents, + getOptionsForLibraryResolution, getOutputDeclarationFileName, getOutputPathsForBundle, getPackageScopeForPath, @@ -317,6 +318,7 @@ import { toPath as ts_toPath, trace, tracing, + tryGetDefaultEffectiveTypeRoots, TsConfigSourceFile, TypeChecker, typeDirectiveIsEqualTo, @@ -1444,11 +1446,12 @@ export const plainJSErrors = new Set([ /** * Determine if source file needs to be re-created even if its text hasn't changed */ -function shouldProgramCreateNewSourceFiles(program: Program | undefined, newOptions: CompilerOptions): boolean { +function shouldProgramCreateNewSourceFiles(program: Program | undefined, newOptions: CompilerOptions, defaultEffectiveTypeRoots: string | undefined): boolean { if (!program) return false; // If any compiler options change, we can't reuse old source file even if version match // The change in options like these could result in change in syntax tree or `sourceFile.bindDiagnostics`. - return optionsHaveChanges(program.getCompilerOptions(), newOptions, sourceFileAffectingCompilerOptions); + return program.getDefaultEffectiveTypeRoots() !== defaultEffectiveTypeRoots || + optionsHaveChanges(program.getCompilerOptions(), newOptions, sourceFileAffectingCompilerOptions); } function createCreateProgramOptions(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[], typeScriptVersion?: string): CreateProgramOptions { @@ -1591,7 +1594,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg moduleResolutionCache = host.getModuleResolutionCache?.(); } else { - moduleResolutionCache = createModuleResolutionCache(currentDirectory, getCanonicalFileName, options); + moduleResolutionCache = createModuleResolutionCache( + currentDirectory, + getCanonicalFileName, + options, + /*packageJsonInfoCache*/ undefined, + () => host, + ); actualResolveModuleNamesWorker = (moduleNames, containingFile, redirectedReference, options, containingSourceFile) => loadWithModeAwareCache( moduleNames, @@ -1632,6 +1641,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg getCanonicalFileName, /*options*/ undefined, moduleResolutionCache?.getPackageJsonInfoCache(), + () => host, moduleResolutionCache?.optionsToRedirectsKey, ); actualResolveTypeReferenceDirectiveNamesWorker = (typeDirectiveNames, containingFile, redirectedReference, options, containingSourceFile) => @@ -1653,7 +1663,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg actualResolveLibrary = host.resolveLibrary.bind(host); } else { - const libraryResolutionCache = createModuleResolutionCache(currentDirectory, getCanonicalFileName, options, moduleResolutionCache?.getPackageJsonInfoCache()); + const libraryResolutionCache = createModuleResolutionCache( + currentDirectory, + getCanonicalFileName, + getOptionsForLibraryResolution(options), + moduleResolutionCache?.getPackageJsonInfoCache(), + () => host, + ); actualResolveLibrary = (libraryName, resolveFrom, options) => resolveLibrary(libraryName, resolveFrom, options, host, libraryResolutionCache); } @@ -1698,8 +1714,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg }); const readFile = host.readFile.bind(host) as typeof host.readFile; + // If there is change in default effective type roots presence, we need to re-create source file + const defaultEffectiveTypeRoots = tryGetDefaultEffectiveTypeRoots(options, host, currentDirectory); + tracing?.push(tracing.Phase.Program, "shouldProgramCreateNewSourceFiles", { hasOldProgram: !!oldProgram }); - const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options); + const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options, defaultEffectiveTypeRoots); tracing?.pop(); // We set `structuralIsReused` to `undefined` because `tryReuseStructureFromOldProgram` calls `tryReuseStructureFromOldProgram` which checks // `structuralIsReused`, which would be a TDZ violation if it was not set in advance to `undefined`. @@ -1810,13 +1829,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg // old file wasn't redirect but new file is (oldSourceFile.resolvedPath === oldSourceFile.path && newFile.resolvedPath !== oldSourceFile.path) ) { - host.onReleaseOldSourceFile(oldSourceFile, oldProgram.getCompilerOptions(), !!getSourceFileByPath(oldSourceFile.path)); + host.onReleaseOldSourceFile(oldSourceFile, !!getSourceFileByPath(oldSourceFile.path)); } } if (!host.getParsedCommandLine) { oldProgram.forEachResolvedProjectReference(resolvedProjectReference => { if (!getResolvedProjectReferenceByPath(resolvedProjectReference.sourceFile.path)) { - host.onReleaseOldSourceFile!(resolvedProjectReference.sourceFile, oldProgram!.getCompilerOptions(), /*hasSourceFileByPath*/ false); + host.onReleaseOldSourceFile!(resolvedProjectReference.sourceFile, /*hasSourceFileByPath*/ false); } }); } @@ -1831,7 +1850,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg const oldReference = parent?.commandLine.projectReferences![index] || oldProgram!.getProjectReferences()![index]; const oldRefPath = resolveProjectReferencePath(oldReference); if (!projectReferenceRedirects?.has(toPath(oldRefPath))) { - host.onReleaseParsedCommandLine!(oldRefPath, oldResolvedRef, oldProgram!.getCompilerOptions()); + host.onReleaseParsedCommandLine!(oldRefPath, oldResolvedRef); } }, ); @@ -1874,6 +1893,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives, getAutomaticTypeDirectiveNames: () => automaticTypeDirectiveNames!, getAutomaticTypeDirectiveResolutions: () => automaticTypeDirectiveResolutions, + getDefaultEffectiveTypeRoots: () => defaultEffectiveTypeRoots, isSourceFileFromExternalLibrary, isSourceFileDefaultLibrary, getSourceFileFromReference, @@ -2350,7 +2370,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg // check properties that can affect structure of the program or module resolution strategy // if any of these properties has changed - structure cannot be reused const oldOptions = oldProgram.getCompilerOptions(); - if (changesAffectModuleResolution(oldOptions, options)) { + if (changesAffectModuleResolution(oldOptions, options) || defaultEffectiveTypeRoots !== oldProgram.getDefaultEffectiveTypeRoots()) { return StructureIsReused.Not; } diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index 751e4b32b37..9e803d325e2 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -450,6 +450,8 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD getCurrentDirectory(), resolutionHost.getCanonicalFileName, resolutionHost.getCompilationSettings(), + /*packageJsonInfoCache*/ undefined, + getModuleResolutionHost, ); const resolvedTypeReferenceDirectives = new Map>(); @@ -458,6 +460,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD resolutionHost.getCanonicalFileName, resolutionHost.getCompilationSettings(), moduleResolutionCache.getPackageJsonInfoCache(), + getModuleResolutionHost, moduleResolutionCache.optionsToRedirectsKey, ); @@ -467,6 +470,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD resolutionHost.getCanonicalFileName, getOptionsForLibraryResolution(resolutionHost.getCompilationSettings()), moduleResolutionCache.getPackageJsonInfoCache(), + getModuleResolutionHost, ); const directoryWatchesOfFailedLookups = new Map(); @@ -654,8 +658,12 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD hasChangedAutomaticTypeDirectiveNames = false; } + function getModuleResolutionHost() { + return resolutionHost.getCompilerHost?.() || resolutionHost; + } + function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, redirectedReference?: ResolvedProjectReference, mode?: ResolutionMode): CachedResolvedModuleWithFailedLookupLocations { - const host = resolutionHost.getCompilerHost?.() || resolutionHost; + const host = getModuleResolutionHost(); const primaryResult = ts_resolveModuleName(moduleName, containingFile, compilerOptions, host, moduleResolutionCache, redirectedReference, mode); // return result immediately only if global cache support is not enabled or if it is .ts, .tsx or .d.ts if (!resolutionHost.getGlobalCache) { diff --git a/src/compiler/tsbuildPublic.ts b/src/compiler/tsbuildPublic.ts index 8512e52f07f..49eb5d13e48 100644 --- a/src/compiler/tsbuildPublic.ts +++ b/src/compiler/tsbuildPublic.ts @@ -440,7 +440,13 @@ function createSolutionBuilderState(watch: boolean, ho compilerHost.getModuleResolutionCache = maybeBind(host, host.getModuleResolutionCache); let moduleResolutionCache: ModuleResolutionCache | undefined, typeReferenceDirectiveResolutionCache: TypeReferenceDirectiveResolutionCache | undefined; if (!compilerHost.resolveModuleNameLiterals && !compilerHost.resolveModuleNames) { - moduleResolutionCache = createModuleResolutionCache(compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName); + moduleResolutionCache = createModuleResolutionCache( + compilerHost.getCurrentDirectory(), + compilerHost.getCanonicalFileName, + /*options*/ undefined, + /*packageJsonInfoCache*/ undefined, + () => compilerHost, + ); compilerHost.resolveModuleNameLiterals = (moduleNames, containingFile, redirectedReference, options, containingSourceFile) => loadWithModeAwareCache( moduleNames, @@ -460,6 +466,7 @@ function createSolutionBuilderState(watch: boolean, ho compilerHost.getCanonicalFileName, /*options*/ undefined, moduleResolutionCache?.getPackageJsonInfoCache(), + () => compilerHost, moduleResolutionCache?.optionsToRedirectsKey, ); compilerHost.resolveTypeReferenceDirectiveReferences = (typeDirectiveNames, containingFile, redirectedReference, options, containingSourceFile) => @@ -476,7 +483,13 @@ function createSolutionBuilderState(watch: boolean, ho } let libraryResolutionCache: ModuleResolutionCache | undefined; if (!compilerHost.resolveLibrary) { - libraryResolutionCache = createModuleResolutionCache(compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, /*options*/ undefined, moduleResolutionCache?.getPackageJsonInfoCache()); + libraryResolutionCache = createModuleResolutionCache( + compilerHost.getCurrentDirectory(), + compilerHost.getCanonicalFileName, + /*options*/ undefined, + moduleResolutionCache?.getPackageJsonInfoCache(), + () => compilerHost, + ); compilerHost.resolveLibrary = (libraryName, resolveFrom, options) => resolveLibrary( libraryName, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 56b0009e53a..a4f99a5be4d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4700,6 +4700,7 @@ export interface Program extends ScriptReferenceHost { /** @internal */ getResolvedTypeReferenceDirectives(): ModeAwareCache; /** @internal */ getAutomaticTypeDirectiveNames(): string[]; /** @internal */ getAutomaticTypeDirectiveResolutions(): ModeAwareCache; + /** @internal */ getDefaultEffectiveTypeRoots(): string | undefined; isSourceFileFromExternalLibrary(file: SourceFile): boolean; isSourceFileDefaultLibrary(file: SourceFile): boolean; @@ -7767,8 +7768,8 @@ export interface CompilerHost extends ModuleResolutionHost { */ hasInvalidatedLibResolutions?(libFileName: string): boolean; getEnvironmentVariable?(name: string): string | undefined; - /** @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void; - /** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void; + /** @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, hasSourceFileByPath: boolean): void; + /** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined): void; /** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */ hasInvalidatedResolutions?(filePath: Path): boolean; /** @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames; diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 6f432177ac8..9b071fbb100 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -799,7 +799,7 @@ export function createWatchProgram(host: WatchCompiler return text !== undefined ? getSourceFileVersionAsHashFromText(compilerHost, text) : undefined; } - function onReleaseOldSourceFile(oldSourceFile: SourceFile, _oldOptions: CompilerOptions, hasSourceFileByPath: boolean) { + function onReleaseOldSourceFile(oldSourceFile: SourceFile, hasSourceFileByPath: boolean) { const hostSourceFileInfo = sourceFilesCache.get(oldSourceFile.resolvedPath); // If this is the source file thats in the cache and new program doesnt need it, // remove the cached entry. diff --git a/src/harness/incrementalUtils.ts b/src/harness/incrementalUtils.ts index eecece904f1..cf18b5e0475 100644 --- a/src/harness/incrementalUtils.ts +++ b/src/harness/incrementalUtils.ts @@ -83,7 +83,7 @@ function verifyDocumentRegistry(service: ts.server.ProjectService) { if (project.noDtsResolutionProject) collectStats(project.noDtsResolutionProject); const program = project.getCurrentProgram(); if (!program) return; - const key = service.documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions(), program.getCurrentDirectory()); + const key = program.getDocumentRegistryBucketKey(); program.getSourceFiles().forEach(f => { const keyWithMode = service.documentRegistry.getDocumentRegistryBucketKeyWithMode(key, f.impliedNodeFormat); let mapForKeyWithMode = stats.get(keyWithMode); diff --git a/src/services/documentRegistry.ts b/src/services/documentRegistry.ts index b60e4feeef0..6aed53847d6 100644 --- a/src/services/documentRegistry.ts +++ b/src/services/documentRegistry.ts @@ -17,6 +17,7 @@ import { IScriptSnapshot, isDeclarationFileName, MinimalResolutionCacheHost, + ModuleResolutionHost, Path, ResolutionMode, ScriptKind, @@ -68,7 +69,7 @@ export interface DocumentRegistry { version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, - currentDirectoryForDocument?: string, + host?: ModuleResolutionHost, ): SourceFile; acquireDocumentWithKey( @@ -104,7 +105,7 @@ export interface DocumentRegistry { version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, - currentDirectoryForDocument?: string, + host?: ModuleResolutionHost, ): SourceFile; updateDocumentWithKey( @@ -118,7 +119,7 @@ export interface DocumentRegistry { sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, ): SourceFile; - getKeyForCompilationSettings(settings: CompilerOptions, currentDirectoryForDocument?: string): DocumentRegistryBucketKey; + getKeyForCompilationSettings(settings: CompilerOptions, host?: ModuleResolutionHost): DocumentRegistryBucketKey; /** @internal */ getDocumentRegistryBucketKeyWithMode(key: DocumentRegistryBucketKey, mode: ResolutionMode): DocumentRegistryBucketKeyWithMode; /** @@ -146,7 +147,7 @@ export interface DocumentRegistry { * @param impliedNodeFormat The implied source file format of the file to be released * @param currentDirectoryForDocument The current directory of the file to be released */ - releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode, currentDirectoryForDocument?: string): void; // eslint-disable-line @typescript-eslint/unified-signatures + releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode, host?: ModuleResolutionHost): void; // eslint-disable-line @typescript-eslint/unified-signatures /** * @deprecated pass scriptKind for and impliedNodeFormat correctness */ releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind): void; @@ -233,10 +234,10 @@ export function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boole version: string, scriptKind?: ScriptKind, languageVersionOrOptions?: CreateSourceFileOptions | ScriptTarget, - currentDirectoryForDocument?: string, + host?: ModuleResolutionHost, ): SourceFile { const path = toPath(fileName, currentDirectory, getCanonicalFileName); - const key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings), currentDirectoryForDocument); + const key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings), host); return acquireDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions); } @@ -251,10 +252,10 @@ export function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boole version: string, scriptKind?: ScriptKind, languageVersionOrOptions?: CreateSourceFileOptions | ScriptTarget, - currentDirectoryForDocument?: string, + host?: ModuleResolutionHost, ): SourceFile { const path = toPath(fileName, currentDirectory, getCanonicalFileName); - const key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings), currentDirectoryForDocument); + const key = getKeyForCompilationSettings(getCompilationSettings(compilationSettings), host); return updateDocumentWithKey(fileName, path, compilationSettings, key, scriptSnapshot, version, scriptKind, languageVersionOrOptions); } @@ -383,10 +384,10 @@ export function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boole compilationSettings: CompilerOptions, scriptKind?: ScriptKind, impliedNodeFormat?: ResolutionMode, - currentDirectoryForDocument?: string, + host?: ModuleResolutionHost, ): void { const path = toPath(fileName, currentDirectory, getCanonicalFileName); - const key = getKeyForCompilationSettings(compilationSettings, currentDirectoryForDocument); + const key = getKeyForCompilationSettings(compilationSettings, host); return releaseDocumentWithKey(path, key, scriptKind, impliedNodeFormat); } @@ -422,10 +423,15 @@ export function createDocumentRegistryInternal(useCaseSensitiveFileNames?: boole reportStats, getBuckets: () => buckets, }; -} -function getKeyForCompilationSettings(settings: CompilerOptions, currentDirectoryForDocument: string | undefined): DocumentRegistryBucketKey { - return getKeyForCompilerOptions(currentDirectoryForDocument, settings, sourceFileAffectingCompilerOptions) as DocumentRegistryBucketKey; + function getKeyForCompilationSettings(settings: CompilerOptions, host: ModuleResolutionHost | undefined): DocumentRegistryBucketKey { + return getKeyForCompilerOptions( + settings, + host, + currentDirectory, + sourceFileAffectingCompilerOptions, + ) as DocumentRegistryBucketKey; + } } function getDocumentRegistryBucketKeyWithMode(key: DocumentRegistryBucketKey, mode: ResolutionMode) { diff --git a/src/services/services.ts b/src/services/services.ts index f033bec4075..e63a134da28 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1716,7 +1716,7 @@ export function createLanguageService( // The call to isProgramUptoDate below may refer back to documentRegistryBucketKey; // calculate this early so it's not undefined if downleveled to a var (or, if emitted // as a const variable without downleveling, doesn't crash). - const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings, currentDirectory); + const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings, compilerHost); let releasedScriptKinds: Set | undefined = new Set(); // If the program is already up-to-date, we can reuse it @@ -1741,6 +1741,7 @@ export function createLanguageService( projectReferences, }; program = createProgram(options); + program.getDocumentRegistryBucketKey = () => documentRegistryBucketKey; // 'getOrCreateSourceFile' depends on caching but should be used past this point. // After this point, the cache needs to be cleared to allow all collected snapshots to be released @@ -1785,20 +1786,19 @@ export function createLanguageService( ); } - function onReleaseParsedCommandLine(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, oldOptions: CompilerOptions) { + function onReleaseParsedCommandLine(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined) { if (host.getParsedCommandLine) { - host.onReleaseParsedCommandLine?.(configFileName, oldResolvedRef, oldOptions); + host.onReleaseParsedCommandLine?.(configFileName, oldResolvedRef); } else if (oldResolvedRef) { - onReleaseOldSourceFile(oldResolvedRef.sourceFile, oldOptions); + onReleaseOldSourceFile(oldResolvedRef.sourceFile); } } // Release any files we have acquired in the old program but are // not part of the new program. - function onReleaseOldSourceFile(oldSourceFile: SourceFile, oldOptions: CompilerOptions) { - const oldSettingsKey = documentRegistry.getKeyForCompilationSettings(oldOptions, currentDirectory); - documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, oldSettingsKey, oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat); + function onReleaseOldSourceFile(oldSourceFile: SourceFile) { + documentRegistry.releaseDocumentWithKey(oldSourceFile.resolvedPath, program.getDocumentRegistryBucketKey(), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat); } function getOrCreateSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined { @@ -1821,7 +1821,7 @@ export function createLanguageService( // Check if the language version has changed since we last created a program; if they are the same, // it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile // can not be reused. we have to dump all syntax trees and create new ones. - if (!shouldCreateNewSourceFile) { + if (!shouldCreateNewSourceFile) { // Handle when directories get created // Check if the old program had this file already const oldSourceFile = program && program.getSourceFileByPath(path); if (oldSourceFile) { @@ -1857,7 +1857,7 @@ export function createLanguageService( // Release old source file and fall through to aquire new file with new script kind documentRegistry.releaseDocumentWithKey( oldSourceFile.resolvedPath, - documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions(), program.getCurrentDirectory()), + program.getDocumentRegistryBucketKey(), oldSourceFile.scriptKind, oldSourceFile.impliedNodeFormat, ); @@ -1948,7 +1948,7 @@ export function createLanguageService( function cleanupSemanticCache(): void { if (program) { // Use paths to ensure we are using correct key and paths as document registry could be created with different current directory than host - const key = documentRegistry.getKeyForCompilationSettings(program.getCompilerOptions(), program.getCurrentDirectory()); + const key = program.getDocumentRegistryBucketKey(); forEach(program.getSourceFiles(), f => documentRegistry.releaseDocumentWithKey(f.resolvedPath, key, f.scriptKind, f.impliedNodeFormat)); program = undefined!; // TODO: GH#18217 } diff --git a/src/services/types.ts b/src/services/types.ts index 18a52a5e6fc..b276176c800 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -7,6 +7,7 @@ import { DiagnosticWithLocation, DocumentHighlights, DocumentPositionMapper, + DocumentRegistryBucketKey, EmitOutput, ExportInfoMap, ExportMapInfoKey, @@ -188,6 +189,13 @@ declare module "../compiler/types" { } } +declare module "../compiler/types" { + /** @internal */ + export interface Program { + getDocumentRegistryBucketKey(): DocumentRegistryBucketKey; + } +} + /** * Represents an immutable snapshot of a script at a specified time.Once acquired, the * snapshot is observably immutable. i.e. the same calls with the same parameters will return @@ -425,7 +433,7 @@ export interface LanguageServiceHost extends GetEffectiveTypeRootsHost, MinimalR /** @internal */ getPackageJsonAutoImportProvider?(): Program | undefined; /** @internal */ sendPerformanceEvent?(kind: PerformanceEvent["kind"], durationMs: number): void; getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined; - /** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void; + /** @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined): void; /** @internal */ getIncompleteCompletionsCache?(): IncompleteCompletionsCache; } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3763155deaa..d0b3a9fae15 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -9539,8 +9539,8 @@ declare namespace ts { * this list is only the set of defaults that are implicitly included. */ function getAutomaticTypeDirectiveNames(options: CompilerOptions, host: ModuleResolutionHost): string[]; - function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): ModuleResolutionCache; - function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache): TypeReferenceDirectiveResolutionCache; + function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache, getModuleResolutionHost?: () => ModuleResolutionHost): ModuleResolutionCache; + function createTypeReferenceDirectiveResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions, packageJsonInfoCache?: PackageJsonInfoCache, getModuleResolutionHost?: () => ModuleResolutionHost): TypeReferenceDirectiveResolutionCache; function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache, mode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined; function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference, resolutionMode?: ResolutionMode): ResolvedModuleWithFailedLookupLocations; function bundlerModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations; @@ -11408,7 +11408,7 @@ declare namespace ts { * @param version Current version of the file. Only used if the file was not found * in the registry and a new one was created. */ - acquireDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, currentDirectoryForDocument?: string): SourceFile; + acquireDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, host?: ModuleResolutionHost): SourceFile; acquireDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget): SourceFile; /** * Request an updated version of an already existing SourceFile with a given fileName @@ -11425,9 +11425,9 @@ declare namespace ts { * @param scriptSnapshot Text of the file. * @param version Current version of the file. */ - updateDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, currentDirectoryForDocument?: string): SourceFile; + updateDocument(fileName: string, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget, host?: ModuleResolutionHost): SourceFile; updateDocumentWithKey(fileName: string, path: Path, compilationSettingsOrHost: CompilerOptions | MinimalResolutionCacheHost, key: DocumentRegistryBucketKey, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind, sourceFileOptions?: CreateSourceFileOptions | ScriptTarget): SourceFile; - getKeyForCompilationSettings(settings: CompilerOptions, currentDirectoryForDocument?: string): DocumentRegistryBucketKey; + getKeyForCompilationSettings(settings: CompilerOptions, host?: ModuleResolutionHost): DocumentRegistryBucketKey; /** * Informs the DocumentRegistry that a file is not needed any longer. * @@ -11453,7 +11453,7 @@ declare namespace ts { * @param impliedNodeFormat The implied source file format of the file to be released * @param currentDirectoryForDocument The current directory of the file to be released */ - releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode, currentDirectoryForDocument?: string): void; + releaseDocument(fileName: string, compilationSettings: CompilerOptions, scriptKind: ScriptKind, impliedNodeFormat: ResolutionMode, host?: ModuleResolutionHost): void; /** * @deprecated pass scriptKind for and impliedNodeFormat correctness */ releaseDocumentWithKey(path: Path, key: DocumentRegistryBucketKey, scriptKind?: ScriptKind): void; diff --git a/tests/baselines/reference/tsbuild/moduleResolution/sharing-across-references-despite-typeRoots-are-not-specified.js b/tests/baselines/reference/tsbuild/moduleResolution/sharing-across-references-despite-typeRoots-are-not-specified.js index ea1263ca349..f2025d0bd46 100644 --- a/tests/baselines/reference/tsbuild/moduleResolution/sharing-across-references-despite-typeRoots-are-not-specified.js +++ b/tests/baselines/reference/tsbuild/moduleResolution/sharing-across-references-despite-typeRoots-are-not-specified.js @@ -77,14 +77,7 @@ Module resolution kind is not specified, using 'Node10'. Loading module 'moduleX' from 'node_modules' folder, target file types: TypeScript, Declaration. Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration. Directory '/users/username/projects/app/node_modules' does not exist, skipping all lookups in it. -File '/users/username/projects/node_modules/moduleX/package.json' does not exist according to earlier cached lookups. -File '/users/username/projects/node_modules/moduleX.ts' does not exist. -File '/users/username/projects/node_modules/moduleX.tsx' does not exist. -File '/users/username/projects/node_modules/moduleX.d.ts' does not exist. -File '/users/username/projects/node_modules/moduleX/index.ts' does not exist. -File '/users/username/projects/node_modules/moduleX/index.tsx' does not exist. -File '/users/username/projects/node_modules/moduleX/index.d.ts' exists - use it as a name resolution result. -Resolving real path for '/users/username/projects/node_modules/moduleX/index.d.ts', result '/users/username/projects/node_modules/moduleX/index.d.ts'. +Resolution for module 'moduleX' was found in cache from location '/users/username/projects'. ======== Module name 'moduleX' was successfully resolved to '/users/username/projects/node_modules/moduleX/index.d.ts'. ======== ======== Resolving module '../common/moduleB' from '/users/username/projects/app/appB.ts'. ======== Module resolution kind is not specified, using 'Node10'. diff --git a/tests/baselines/reference/tscWatch/resolutionCache/works-when-installing-something-in-node_modules-or-@types-when-there-is-no-notification-from-fs-for-index-file.js b/tests/baselines/reference/tscWatch/resolutionCache/works-when-installing-something-in-node_modules-or-@types-when-there-is-no-notification-from-fs-for-index-file.js index d3930c936fd..5a2909f2cb7 100644 --- a/tests/baselines/reference/tscWatch/resolutionCache/works-when-installing-something-in-node_modules-or-@types-when-there-is-no-notification-from-fs-for-index-file.js +++ b/tests/baselines/reference/tscWatch/resolutionCache/works-when-installing-something-in-node_modules-or-@types-when-there-is-no-notification-from-fs-for-index-file.js @@ -352,7 +352,7 @@ FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/ Program root files: ["/user/username/projects/myproject/worker.ts"] Program options: {"watch":true,"extendedDiagnostics":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"} -Program structureReused: SafeModules +Program structureReused: Not Program files:: /a/lib/lib.d.ts /user/username/projects/myproject/worker.ts diff --git a/tests/baselines/reference/tscWatch/resolutionCache/works-when-module-resolution-changes-to-ambient-module.js b/tests/baselines/reference/tscWatch/resolutionCache/works-when-module-resolution-changes-to-ambient-module.js index 25b4f698510..c63622972c1 100644 --- a/tests/baselines/reference/tscWatch/resolutionCache/works-when-module-resolution-changes-to-ambient-module.js +++ b/tests/baselines/reference/tscWatch/resolutionCache/works-when-module-resolution-changes-to-ambient-module.js @@ -130,7 +130,7 @@ sysLog:: /users/username/projects/project/node_modules/@types:: Changing watcher Program root files: ["/users/username/projects/project/foo.ts"] Program options: {"watch":true} -Program structureReused: SafeModules +Program structureReused: Not Program files:: /a/lib/lib.d.ts /users/username/projects/project/foo.ts diff --git a/tests/baselines/reference/tscWatch/resolutionCache/works-when-renaming-node_modules-folder-that-already-contains-@types-folder.js b/tests/baselines/reference/tscWatch/resolutionCache/works-when-renaming-node_modules-folder-that-already-contains-@types-folder.js index afa65bed75b..021e9e7c5ed 100644 --- a/tests/baselines/reference/tscWatch/resolutionCache/works-when-renaming-node_modules-folder-that-already-contains-@types-folder.js +++ b/tests/baselines/reference/tscWatch/resolutionCache/works-when-renaming-node_modules-folder-that-already-contains-@types-folder.js @@ -122,7 +122,7 @@ sysLog:: /user/username/projects/myproject/node_modules/@types:: Changing watche Program root files: ["/user/username/projects/myproject/a.ts"] Program options: {"watch":true} -Program structureReused: SafeModules +Program structureReused: Not Program files:: /a/lib/lib.d.ts /user/username/projects/myproject/node_modules/@types/qqq/index.d.ts diff --git a/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-after-installation.js b/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-after-installation.js index 3c6606e4d8b..ce04a18a8f6 100644 --- a/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-after-installation.js +++ b/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-after-installation.js @@ -1864,7 +1864,7 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /user/username/ro Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /user/username/rootfolder/otherfolder/node_modules 1 undefined Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json WatchType: Failed Lookup Locations Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /user/username/rootfolder/node_modules 1 undefined Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json WatchType: Failed Lookup Locations Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /user/username/rootfolder/node_modules 1 undefined Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json WatchType: Failed Lookup Locations -Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json Version: 2 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms Info seq [hh:mm:ss:mss] Project '/user/username/rootfolder/otherfolder/a/b/tsconfig.json' (Configured) Info seq [hh:mm:ss:mss] Files (3) /a/lib/lib.d.ts Text-1 "/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }" diff --git a/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-inbetween-installation.js b/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-inbetween-installation.js index d13e936e2ba..76447871834 100644 --- a/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-inbetween-installation.js +++ b/tests/baselines/reference/tsserver/cachingFileSystemInformation/npm-install-works-when-timeout-occurs-inbetween-installation.js @@ -1143,7 +1143,7 @@ Before running Timeout callback:: count: 2 Info seq [hh:mm:ss:mss] Running: /user/username/rootfolder/otherfolder/a/b/tsconfig.json Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json -Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json Version: 3 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/rootfolder/otherfolder/a/b/tsconfig.json Version: 3 structureChanged: true structureIsReused:: Not Elapsed:: *ms Info seq [hh:mm:ss:mss] Project '/user/username/rootfolder/otherfolder/a/b/tsconfig.json' (Configured) Info seq [hh:mm:ss:mss] Files (2) /a/lib/lib.d.ts Text-1 "/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }" diff --git a/tests/baselines/reference/tsserver/cachingFileSystemInformation/when-node_modules-dont-receive-event-for-the-@types-file-addition.js b/tests/baselines/reference/tsserver/cachingFileSystemInformation/when-node_modules-dont-receive-event-for-the-@types-file-addition.js index de718e0ffd4..a0922192820 100644 --- a/tests/baselines/reference/tsserver/cachingFileSystemInformation/when-node_modules-dont-receive-event-for-the-@types-file-addition.js +++ b/tests/baselines/reference/tsserver/cachingFileSystemInformation/when-node_modules-dont-receive-event-for-the-@types-file-addition.js @@ -126,7 +126,7 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/username/fo Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/folder/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /user/username/folder/node_modules 1 undefined Project: /user/username/folder/myproject/tsconfig.json WatchType: Failed Lookup Locations Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /user/username/folder/node_modules 1 undefined Project: /user/username/folder/myproject/tsconfig.json WatchType: Failed Lookup Locations -Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/folder/myproject/tsconfig.json Version: 2 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /user/username/folder/myproject/tsconfig.json Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms Info seq [hh:mm:ss:mss] Project '/user/username/folder/myproject/tsconfig.json' (Configured) Info seq [hh:mm:ss:mss] Files (3) /a/lib/lib.d.ts Text-1 "/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }" diff --git a/tests/baselines/reference/tsserver/cachingFileSystemInformation/works-using-legacy-resolution-logic.js b/tests/baselines/reference/tsserver/cachingFileSystemInformation/works-using-legacy-resolution-logic.js index 2a4226cca8a..69499b2ba87 100644 --- a/tests/baselines/reference/tsserver/cachingFileSystemInformation/works-using-legacy-resolution-logic.js +++ b/tests/baselines/reference/tsserver/cachingFileSystemInformation/works-using-legacy-resolution-logic.js @@ -49,7 +49,9 @@ Info seq [hh:mm:ss:mss] ../f1.ts(1,1): error TS2304: Cannot find name 'foo'. Info seq [hh:mm:ss:mss] fileExists:: Info seq [hh:mm:ss:mss] directoryExists:: - +/c/d/node_modules/@types: 1 +/c/node_modules/@types: 1 +/node_modules/@types: 1 Info seq [hh:mm:ss:mss] getDirectories:: Info seq [hh:mm:ss:mss] readFile:: @@ -155,9 +157,9 @@ Info seq [hh:mm:ss:mss] fileExists:: Info seq [hh:mm:ss:mss] directoryExists:: /c: 1 /c/d: 1 -/c/d/node_modules/@types: 1 -/c/node_modules/@types: 1 -/node_modules/@types: 1 +/c/d/node_modules/@types: 3 +/c/node_modules/@types: 3 +/node_modules/@types: 3 Info seq [hh:mm:ss:mss] getDirectories:: Info seq [hh:mm:ss:mss] readFile:: diff --git a/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan,-and-orphan-script-info-changes.js b/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan,-and-orphan-script-info-changes.js index 89705359646..8fa9a5e0130 100644 --- a/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan,-and-orphan-script-info-changes.js +++ b/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan,-and-orphan-script-info-changes.js @@ -69,7 +69,7 @@ Info seq [hh:mm:ss:mss] Open files: Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/index.ts ProjectRootPath: undefined Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json DocumentRegistry:: - Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|/user/username/projects/myproject + Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined /user/username/projects/myproject/index.ts: TS 1 /user/username/projects/myproject/module1.d.ts: TS 1 /a/lib/lib.d.ts: TS 1 @@ -88,7 +88,7 @@ Info seq [hh:mm:ss:mss] Files (2) Info seq [hh:mm:ss:mss] ----------------------------------------------- DocumentRegistry:: - Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|/user/username/projects/myproject + Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined /user/username/projects/myproject/index.ts: TS 1 /a/lib/lib.d.ts: TS 1 Info seq [hh:mm:ss:mss] FileWatcher:: Triggered with /user/username/projects/myproject/module1.d.ts 1:: WatchInfo: /user/username/projects/myproject/module1.d.ts 500 undefined WatchType: Closed Script info @@ -111,7 +111,7 @@ Info seq [hh:mm:ss:mss] Files (3) Info seq [hh:mm:ss:mss] ----------------------------------------------- DocumentRegistry:: - Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|/user/username/projects/myproject + Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined /user/username/projects/myproject/index.ts: TS 1 /a/lib/lib.d.ts: TS 1 /user/username/projects/myproject/module1.d.ts: TS 1 \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan.js b/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan.js index 74830124e2d..f64fe38191a 100644 --- a/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan.js +++ b/tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan.js @@ -69,7 +69,7 @@ Info seq [hh:mm:ss:mss] Open files: Info seq [hh:mm:ss:mss] FileName: /user/username/projects/myproject/index.ts ProjectRootPath: undefined Info seq [hh:mm:ss:mss] Projects: /user/username/projects/myproject/tsconfig.json DocumentRegistry:: - Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|/user/username/projects/myproject + Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined /user/username/projects/myproject/index.ts: TS 1 /user/username/projects/myproject/module1.d.ts: TS 1 /a/lib/lib.d.ts: TS 1 @@ -88,7 +88,7 @@ Info seq [hh:mm:ss:mss] Files (2) Info seq [hh:mm:ss:mss] ----------------------------------------------- DocumentRegistry:: - Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|/user/username/projects/myproject + Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined /user/username/projects/myproject/index.ts: TS 1 /a/lib/lib.d.ts: TS 1 Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json @@ -109,7 +109,7 @@ Info seq [hh:mm:ss:mss] Files (3) Info seq [hh:mm:ss:mss] ----------------------------------------------- DocumentRegistry:: - Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|/user/username/projects/myproject + Key:: undefined|undefined|undefined|undefined|undefined|false|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined /user/username/projects/myproject/index.ts: TS 1 /a/lib/lib.d.ts: TS 1 /user/username/projects/myproject/module1.d.ts: TS 1 \ No newline at end of file diff --git a/tests/baselines/reference/tsserver/resolutionCache/npm-install-@types-works.js b/tests/baselines/reference/tsserver/resolutionCache/npm-install-@types-works.js index bce62766f02..1c0c20c956b 100644 --- a/tests/baselines/reference/tsserver/resolutionCache/npm-install-@types-works.js +++ b/tests/baselines/reference/tsserver/resolutionCache/npm-install-@types-works.js @@ -245,7 +245,7 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /a/b/projects/tem Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /a/b/projects/temp/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache Info seq [hh:mm:ss:mss] DirectoryWatcher:: Close:: WatchInfo: /a/b/projects/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Close:: WatchInfo: /a/b/projects/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations -Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* Version: 2 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* Version: 2 structureChanged: true structureIsReused:: Not Elapsed:: *ms Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred) Info seq [hh:mm:ss:mss] Files (3) /a/lib/lib.d.ts Text-1 "/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }" diff --git a/tests/baselines/reference/tsserver/resolutionCache/sharing-across-references-despite-typeRoots-are-not-specified.js b/tests/baselines/reference/tsserver/resolutionCache/sharing-across-references-despite-typeRoots-are-not-specified.js index 3add727fc8d..b07eecf34be 100644 --- a/tests/baselines/reference/tsserver/resolutionCache/sharing-across-references-despite-typeRoots-are-not-specified.js +++ b/tests/baselines/reference/tsserver/resolutionCache/sharing-across-references-despite-typeRoots-are-not-specified.js @@ -105,14 +105,7 @@ Info seq [hh:mm:ss:mss] Module resolution kind is not specified, using 'Node10' Info seq [hh:mm:ss:mss] Loading module 'moduleX' from 'node_modules' folder, target file types: TypeScript, Declaration. Info seq [hh:mm:ss:mss] Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration. Info seq [hh:mm:ss:mss] Directory '/users/username/projects/common/node_modules' does not exist, skipping all lookups in it. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX/package.json' does not exist according to earlier cached lookups. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX.ts' does not exist. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX.tsx' does not exist. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX.d.ts' does not exist. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX/index.ts' does not exist. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX/index.tsx' does not exist. -Info seq [hh:mm:ss:mss] File '/users/username/projects/node_modules/moduleX/index.d.ts' exists - use it as a name resolution result. -Info seq [hh:mm:ss:mss] Resolving real path for '/users/username/projects/node_modules/moduleX/index.d.ts', result '/users/username/projects/node_modules/moduleX/index.d.ts'. +Info seq [hh:mm:ss:mss] Resolution for module 'moduleX' was found in cache from location '/users/username/projects'. Info seq [hh:mm:ss:mss] ======== Module name 'moduleX' was successfully resolved to '/users/username/projects/node_modules/moduleX/index.d.ts'. ======== Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/app/node_modules 1 undefined Project: /users/username/projects/app/tsconfig.json WatchType: Failed Lookup Locations Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /users/username/projects/app/node_modules 1 undefined Project: /users/username/projects/app/tsconfig.json WatchType: Failed Lookup Locations diff --git a/tests/baselines/reference/tsserver/watchEnvironment/watching-npm-install-in-codespaces-where-workspaces-folder-is-hosted-at-root.js b/tests/baselines/reference/tsserver/watchEnvironment/watching-npm-install-in-codespaces-where-workspaces-folder-is-hosted-at-root.js index 785cc8b0455..98b7a3e01c9 100644 --- a/tests/baselines/reference/tsserver/watchEnvironment/watching-npm-install-in-codespaces-where-workspaces-folder-is-hosted-at-root.js +++ b/tests/baselines/reference/tsserver/watchEnvironment/watching-npm-install-in-codespaces-where-workspaces-folder-is-hosted-at-root.js @@ -539,7 +539,7 @@ Info seq [hh:mm:ss:mss] Scheduled: *ensureProjectForOpenFiles*, Cancelled earli Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /workspaces/somerepo/src/tsconfig.json Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /workspaces/somerepo/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /workspaces/somerepo/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache -Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /workspaces/somerepo/src/tsconfig.json Version: 3 structureChanged: true structureIsReused:: SafeModules Elapsed:: *ms +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /workspaces/somerepo/src/tsconfig.json Version: 3 structureChanged: true structureIsReused:: Not Elapsed:: *ms Info seq [hh:mm:ss:mss] Project '/workspaces/somerepo/src/tsconfig.json' (Configured) Info seq [hh:mm:ss:mss] Files (3) /a/lib/lib.d.ts Text-1 "/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }"