Skip to content

Commit 2974d93

Browse files
author
Your Name
committed
exclude pathsBasePath from document registry cache key
1 parent c9e7428 commit 2974d93

File tree

5 files changed

+482
-8
lines changed

5 files changed

+482
-8
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ function compilerOptionValueToString(value: unknown): string {
959959

960960
/** @internal */
961961
export function getKeyForCompilerOptions(options: CompilerOptions, affectingOptionDeclarations: readonly CommandLineOption[]): string {
962-
return affectingOptionDeclarations.map(option => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|") + `|${options.pathsBasePath}`;
962+
return affectingOptionDeclarations.map(option => compilerOptionValueToString(getCompilerOptionValue(options, option))).join("|");
963963
}
964964

965965
/** @internal */
@@ -1042,7 +1042,7 @@ function createCacheWithRedirects<K, V>(ownOptions: CompilerOptions | undefined,
10421042
function getRedirectsCacheKey(options: CompilerOptions) {
10431043
let result = optionsToRedirectsKey.get(options);
10441044
if (!result) {
1045-
optionsToRedirectsKey.set(options, result = getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations) as RedirectsCacheKey);
1045+
optionsToRedirectsKey.set(options, result = (getKeyForCompilerOptions(options, moduleResolutionOptionDeclarations) + `|${options.pathsBasePath}`) as RedirectsCacheKey);
10461046
}
10471047
return result;
10481048
}

src/testRunner/unittests/tsserver/documentRegistry.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,63 @@ describe("unittests:: tsserver:: documentRegistry:: document registry in project
123123
});
124124
});
125125

126+
describe("unittests:: tsserver:: documentRegistry:: projects with different pathsBasePath share the same document registry bucket", () => {
127+
function getProject(session: TestSession, config: File) {
128+
return session.getProjectService().configuredProjects.get(config.path.toLowerCase())!;
129+
}
130+
131+
it("shares document registry bucket for projects with same compiler options but different pathsBasePath", () => {
132+
const sharedFile: File = {
133+
path: "/home/src/projects/shared/utils.d.ts",
134+
content: "export const util: number;",
135+
};
136+
137+
const configA: File = {
138+
path: "/home/src/projects/projectA/tsconfig.json",
139+
content: jsonToReadableText({
140+
compilerOptions: { paths: { "@utils": ["../shared/utils.d.ts"] } },
141+
files: ["index.ts"],
142+
}),
143+
};
144+
const indexA: File = {
145+
path: "/home/src/projects/projectA/index.ts",
146+
content: `import { util } from "@utils";`,
147+
};
148+
149+
const configB: File = {
150+
path: "/home/src/projects/projectB/tsconfig.json",
151+
content: jsonToReadableText({
152+
compilerOptions: { paths: { "@utils": ["../shared/utils.d.ts"] } },
153+
files: ["index.ts"],
154+
}),
155+
};
156+
const indexB: File = {
157+
path: "/home/src/projects/projectB/index.ts",
158+
content: `import { util } from "@utils";`,
159+
};
160+
161+
const host = TestServerHost.createServerHost([sharedFile, configA, indexA, configB, indexB]);
162+
const session = new TestSession(host);
163+
openFilesForSession([
164+
{ file: indexA, projectRootPath: "/home/src/projects/projectA" },
165+
{ file: indexB, projectRootPath: "/home/src/projects/projectB" },
166+
], session);
167+
168+
const projectA = getProject(session, configA);
169+
const projectB = getProject(session, configB);
170+
171+
// Both projects should reuse the same source file instance for the shared file
172+
const sharedInfo = session.getProjectService().getScriptInfo(sharedFile.path)!;
173+
const sourceFileA = projectA.getSourceFile(sharedInfo.path);
174+
const sourceFileB = projectB.getSourceFile(sharedInfo.path);
175+
assert.equal(sourceFileA, sourceFileB, "Both projects should share the same source file instance from the document registry");
176+
177+
session.logger.log("DocumentRegistry::");
178+
session.logger.log(reportDocumentRegistryStats(session.getProjectService().documentRegistry).join("\n"));
179+
baselineTsserverLogs("documentRegistry", "shares document registry bucket for projects with different pathsBasePath", session);
180+
});
181+
});
182+
126183
describe("unittests:: tsserver:: documentRegistry:: works when reusing orphan script info with different scriptKind", () => {
127184
it("works when reusing orphan script info with different scriptKind", () => {
128185
const host = TestServerHost.createServerHost({});

tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan,-and-orphan-script-info-changes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ ScriptInfos::
196196
/user/username/projects/myproject/tsconfig.json
197197

198198
DocumentRegistry::
199-
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
199+
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
200200
/user/username/projects/myproject/index.ts: TS 1
201201
/user/username/projects/myproject/module1.d.ts: TS 1
202202
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
@@ -262,7 +262,7 @@ Info seq [hh:mm:ss:mss] Files (2)
262262

263263
Info seq [hh:mm:ss:mss] -----------------------------------------------
264264
DocumentRegistry::
265-
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
265+
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
266266
/user/username/projects/myproject/index.ts: TS 1
267267
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
268268
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
@@ -357,7 +357,7 @@ Info seq [hh:mm:ss:mss] Files (3)
357357

358358
Info seq [hh:mm:ss:mss] -----------------------------------------------
359359
DocumentRegistry::
360-
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
360+
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
361361
/user/username/projects/myproject/index.ts: TS 1
362362
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
363363
/user/username/projects/myproject/module1.d.ts: TS 1

tests/baselines/reference/tsserver/documentRegistry/Caches-the-source-file-if-script-info-is-orphan.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ ScriptInfos::
196196
/user/username/projects/myproject/tsconfig.json
197197

198198
DocumentRegistry::
199-
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
199+
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
200200
/user/username/projects/myproject/index.ts: TS 1
201201
/user/username/projects/myproject/module1.d.ts: TS 1
202202
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
@@ -262,7 +262,7 @@ Info seq [hh:mm:ss:mss] Files (2)
262262

263263
Info seq [hh:mm:ss:mss] -----------------------------------------------
264264
DocumentRegistry::
265-
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
265+
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
266266
/user/username/projects/myproject/index.ts: TS 1
267267
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
268268
Before request
@@ -349,7 +349,7 @@ Info seq [hh:mm:ss:mss] Files (3)
349349

350350
Info seq [hh:mm:ss:mss] -----------------------------------------------
351351
DocumentRegistry::
352-
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
352+
Key:: undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined|undefined
353353
/user/username/projects/myproject/index.ts: TS 1
354354
/home/src/tslibs/ts/lib/lib.es2025.full.d.ts: TS 1
355355
/user/username/projects/myproject/module1.d.ts: TS 1

0 commit comments

Comments
 (0)