Skip to content

Commit 34a2cb3

Browse files
committed
For now make sure module resolution cache usage doesnt go past program creation
1 parent cb61bfe commit 34a2cb3

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,9 @@ export function resolvePackageNameToPackageJson(
779779
containingDirectory: string,
780780
options: CompilerOptions,
781781
host: ModuleResolutionHost,
782-
cache: ModuleResolutionCache | undefined,
782+
cache: PackageJsonInfoCache | undefined,
783783
): PackageJsonInfo | undefined {
784-
const moduleResolutionState = getTemporaryModuleResolutionState(cache?.getPackageJsonInfoCache(), host, options);
784+
const moduleResolutionState = getTemporaryModuleResolutionState(cache, host, options);
785785

786786
return forEachAncestorDirectory(containingDirectory, ancestorDirectory => {
787787
if (getBaseFileName(ancestorDirectory) !== "node_modules") {
@@ -2201,7 +2201,7 @@ export function getEntrypointsFromPackageJsonInfo(
22012201
packageJsonInfo: PackageJsonInfo,
22022202
options: CompilerOptions,
22032203
host: GetPackageJsonEntrypointsHost,
2204-
cache: ModuleResolutionCache | undefined,
2204+
cache: PackageJsonInfoCache | undefined,
22052205
resolveJs?: boolean,
22062206
): string[] | false {
22072207
if (!resolveJs && packageJsonInfo.contents.resolvedEntrypoints !== undefined) {
@@ -2213,7 +2213,7 @@ export function getEntrypointsFromPackageJsonInfo(
22132213
let entrypoints: string[] | undefined;
22142214
const extensions = Extensions.TypeScript | Extensions.Declaration | (resolveJs ? Extensions.JavaScript : 0);
22152215
const features = getNodeResolutionFeatures(options);
2216-
const loadPackageJsonMainState = getTemporaryModuleResolutionState(cache?.getPackageJsonInfoCache(), host, options);
2216+
const loadPackageJsonMainState = getTemporaryModuleResolutionState(cache, host, options);
22172217
loadPackageJsonMainState.conditions = getConditions(options);
22182218
loadPackageJsonMainState.requestContainingDirectory = packageJsonInfo.packageDirectory;
22192219
const mainResolution = loadNodeModuleFromDirectoryWorker(

src/compiler/program.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,14 +1865,16 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
18651865
resolvedLibProcessing = undefined;
18661866
resolvedModulesProcessing = undefined;
18671867
resolvedTypeReferenceDirectiveNamesProcessing = undefined;
1868+
const packageJsonCache = moduleResolutionCache?.getPackageJsonInfoCache();
1869+
moduleResolutionCache = undefined;
18681870

18691871
const program: Program = {
18701872
getRootFileNames: () => rootNames,
18711873
getSourceFile,
18721874
getSourceFileByPath,
18731875
getSourceFiles: () => files,
18741876
getMissingFilePaths: () => missingFileNames,
1875-
getModuleResolutionCache: () => moduleResolutionCache,
1877+
getPackageJsonInfoCache: () => packageJsonCache,
18761878
getFilesByNameMap: () => filesByName,
18771879
getCompilerOptions: () => options,
18781880
getSyntacticDiagnostics,

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4686,7 +4686,7 @@ export interface Program extends ScriptReferenceHost {
46864686
*/
46874687
getMissingFilePaths(): Map<Path, string>;
46884688
/** @internal */
4689-
getModuleResolutionCache(): ModuleResolutionCache | undefined;
4689+
getPackageJsonInfoCache(): PackageJsonInfoCache | undefined;
46904690
/** @internal */
46914691
getFilesByNameMap(): Map<Path, SourceFile | false | undefined>;
46924692

src/server/project.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
833833
return this.resolutionCache.getModuleResolutionCache();
834834
}
835835

836+
/** @internal */
837+
getPackageJsonInfoCache() {
838+
return this.resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache();
839+
}
840+
836841
/** @internal */
837842
resolveTypeReferenceDirectiveReferences<T extends string | FileReference>(
838843
typeDirectiveReferences: readonly T[],
@@ -2633,7 +2638,7 @@ export class AutoImportProviderProject extends Project {
26332638
hostProject.currentDirectory,
26342639
compilerOptions,
26352640
host,
2636-
program.getModuleResolutionCache(),
2641+
program.getPackageJsonInfoCache(),
26372642
);
26382643
if (packageJson) {
26392644
const entrypoints = getRootNamesFromPackageJson(packageJson, program, symlinkCache);
@@ -2653,7 +2658,7 @@ export class AutoImportProviderProject extends Project {
26532658
directory,
26542659
compilerOptions,
26552660
host,
2656-
program.getModuleResolutionCache(),
2661+
program.getPackageJsonInfoCache(),
26572662
);
26582663
if (typesPackageJson) {
26592664
const entrypoints = getRootNamesFromPackageJson(typesPackageJson, program, symlinkCache);
@@ -2693,7 +2698,7 @@ export class AutoImportProviderProject extends Project {
26932698
packageJson,
26942699
compilerOptions,
26952700
host,
2696-
program.getModuleResolutionCache(),
2701+
program.getPackageJsonInfoCache(),
26972702
resolveJs,
26982703
);
26992704
if (entrypoints) {
@@ -2844,8 +2849,8 @@ export class AutoImportProviderProject extends Project {
28442849
}
28452850

28462851
/** @internal */
2847-
override getModuleResolutionCache() {
2848-
return this.hostProject.getCurrentProgram()?.getModuleResolutionCache();
2852+
override getPackageJsonInfoCache() {
2853+
return this.hostProject.getPackageJsonInfoCache();
28492854
}
28502855
}
28512856

src/server/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,7 @@ export class Session<TMessage = string> implements EventSender {
16011601
if (nodeModulesPathParts && fileName.lastIndexOf(nodeModulesPathPart) === nodeModulesPathParts.topLevelNodeModulesIndex) {
16021602
// Second check ensures the fileName only contains one `/node_modules/`. If there's more than one I give up.
16031603
const packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
1604-
const packageJsonCache = project.getModuleResolutionCache()?.getPackageJsonInfoCache();
1604+
const packageJsonCache = project.getPackageJsonInfoCache();
16051605
const compilerOptions = project.getCompilationSettings();
16061606
const packageJson = getPackageScopeForPath(getNormalizedAbsolutePath(packageDirectory + "/package.json", project.getCurrentDirectory()), getTemporaryModuleResolutionState(packageJsonCache, project, compilerOptions));
16071607
if (!packageJson) return undefined;
@@ -1612,7 +1612,7 @@ export class Session<TMessage = string> implements EventSender {
16121612
packageJson,
16131613
{ moduleResolution: ModuleResolutionKind.Node10 },
16141614
project,
1615-
project.getModuleResolutionCache(),
1615+
packageJsonCache,
16161616
);
16171617
// This substring is correct only because we checked for a single `/node_modules/` at the top.
16181618
const packageNamePathPart = fileName.substring(

src/services/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ export function createModuleSpecifierResolutionHost(program: Program, host: Lang
24662466
useCaseSensitiveFileNames: maybeBind(host, host.useCaseSensitiveFileNames),
24672467
getSymlinkCache: maybeBind(host, host.getSymlinkCache) || program.getSymlinkCache,
24682468
getModuleSpecifierCache: maybeBind(host, host.getModuleSpecifierCache),
2469-
getPackageJsonInfoCache: () => program.getModuleResolutionCache()?.getPackageJsonInfoCache(),
2469+
getPackageJsonInfoCache: () => program.getPackageJsonInfoCache(),
24702470
getGlobalTypingsCacheLocation: maybeBind(host, host.getGlobalTypingsCacheLocation),
24712471
redirectTargetsMap: program.redirectTargetsMap,
24722472
getProjectReferenceRedirect: fileName => program.getProjectReferenceRedirect(fileName),

0 commit comments

Comments
 (0)