Skip to content

Isolate test failure from #57570 #57757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,19 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
const expected = isExternalOrCommonJsModule(newFile) ? newFile.packageJsonLocations?.length ?? 0 : 0;
const existing = impliedFormatPackageJsons.get(newFile.path) ?? emptyArray;
for (let i = existing.length; i < expected; i++) {
// Somehow, this loop is incorrect. Before the debug assertion happens in the failing test,
// a referenced config file is updated to include "declarationDir": "decls", which causes
// a file from that project to be renamed from `.../logic/index.d.ts` to
// `.../logic/decls/index.d.ts` between `oldProgram` and `newProgram` here. The new
// version of the source file has an additional package.json lookup location
// (`.../logic/decls/package.json`) compared to the old. `existing.length` is 5 and
// `expected` is 6, so the loop runs once to create a file watcher for the last element
// of `newFile.packageJsonLocations`, which is `/package.json`, incrementing its
// `files` count. It seems like the correct behavior would have been to create a file
// watcher for the *new* package.json location, which happens to be the *first* element
// of `newFile.packageJsonLocations`, but I'm not sure how this code is supposed to know
// which locations have been added and/or removed - relying on length/order doesn't appear
// to be reliable.
createFileWatcherOfAffectingLocation(newFile.packageJsonLocations![i], /*forResolution*/ false);
}
if (existing.length > expected) {
Expand Down
4 changes: 4 additions & 0 deletions src/testRunner/unittests/helpers/sampleProjectReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function getFsContentsForSampleProjectReferences(): FsContents {
[libFile.path]: libFile.content,
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
compilerOptions: {
module: "nodenext",
target: "es5",
composite: true,
declaration: true,
declarationMap: true,
Expand Down Expand Up @@ -64,6 +66,8 @@ export function getFsContentsForSampleProjectReferences(): FsContents {
],
files: ["index.ts"],
compilerOptions: {
module: "nodenext",
target: "es5",
composite: true,
declaration: true,
forceConsistentCasingInFileNames: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
sys.writeFile(
"/user/username/projects/sample1/logic/tsconfig.json",
jsonToReadableText({
compilerOptions: { composite: true, declaration: true, declarationDir: "decls" },
compilerOptions: { module: "nodenext", target: "es5", composite: true, declaration: true, declarationDir: "decls" },
references: [{ path: "../core" }],
}),
);
Expand Down