From fdb45d43a06c031302248b55c8864c362e117ab5 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Tue, 12 Mar 2024 17:05:07 -0700 Subject: [PATCH] Create failing test --- src/compiler/resolutionCache.ts | 13 +++++++++++++ .../unittests/helpers/sampleProjectReferences.ts | 4 ++++ .../unittests/tscWatch/projectsWithReferences.ts | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index 375083077b241..f8cfc9cb16b54 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -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) { diff --git a/src/testRunner/unittests/helpers/sampleProjectReferences.ts b/src/testRunner/unittests/helpers/sampleProjectReferences.ts index c4a1623f9fd54..f69432ff2e8ed 100644 --- a/src/testRunner/unittests/helpers/sampleProjectReferences.ts +++ b/src/testRunner/unittests/helpers/sampleProjectReferences.ts @@ -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, @@ -64,6 +66,8 @@ export function getFsContentsForSampleProjectReferences(): FsContents { ], files: ["index.ts"], compilerOptions: { + module: "nodenext", + target: "es5", composite: true, declaration: true, forceConsistentCasingInFileNames: true, diff --git a/src/testRunner/unittests/tscWatch/projectsWithReferences.ts b/src/testRunner/unittests/tscWatch/projectsWithReferences.ts index 333a0629dadca..3931b1868ea5e 100644 --- a/src/testRunner/unittests/tscWatch/projectsWithReferences.ts +++ b/src/testRunner/unittests/tscWatch/projectsWithReferences.ts @@ -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" }], }), );