Skip to content

Fix incorrect use of "path" instead of "resolvedPath" when watching file's package json locations #57931

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

Merged
merged 2 commits into from
Mar 25, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
cleanupLibResolutionWatching(newProgram);
newProgram?.getSourceFiles().forEach(newFile => {
const expected = isExternalOrCommonJsModule(newFile) ? newFile.packageJsonLocations?.length ?? 0 : 0;
const existing = impliedFormatPackageJsons.get(newFile.path) ?? emptyArray;
const existing = impliedFormatPackageJsons.get(newFile.resolvedPath) ?? emptyArray;
for (let i = existing.length; i < expected; i++) {
createFileWatcherOfAffectingLocation(newFile.packageJsonLocations![i], /*forResolution*/ false);
}
Expand All @@ -746,8 +746,8 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
fileWatchesOfAffectingLocations.get(existing[i])!.files--;
}
}
if (expected) impliedFormatPackageJsons.set(newFile.path, newFile.packageJsonLocations!);
else impliedFormatPackageJsons.delete(newFile.path);
if (expected) impliedFormatPackageJsons.set(newFile.resolvedPath, newFile.packageJsonLocations!);
else impliedFormatPackageJsons.delete(newFile.resolvedPath);
});
impliedFormatPackageJsons.forEach((existing, path) => {
if (!newProgram?.getSourceFileByPath(path)) {
Expand Down
16 changes: 11 additions & 5 deletions src/testRunner/unittests/helpers/sampleProjectReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import {
libFile,
} from "./virtualFileSystemWithWatch";

export function getFsContentsForSampleProjectReferencesLogicConfig() {
export function getSampleProjectConfigWithNodeNext(withNodeNext: boolean | undefined) {
return withNodeNext ? { module: "nodenext", target: "es5" } : undefined;
}
export function getFsContentsForSampleProjectReferencesLogicConfig(withNodeNext?: boolean) {
return jsonToReadableText({
compilerOptions: {
...getSampleProjectConfigWithNodeNext(withNodeNext),
composite: true,
declaration: true,
sourceMap: true,
Expand All @@ -30,11 +34,12 @@ export function getFsContentsForSampleProjectReferencesLogicConfig() {
],
});
}
export function getFsContentsForSampleProjectReferences(): FsContents {
export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean): FsContents {
return {
[libFile.path]: libFile.content,
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
compilerOptions: {
...getSampleProjectConfigWithNodeNext(withNodeNext),
composite: true,
declaration: true,
declarationMap: true,
Expand All @@ -48,7 +53,7 @@ export function getFsContentsForSampleProjectReferences(): FsContents {
`,
"/user/username/projects/sample1/core/some_decl.d.ts": `declare const dts: any;`,
"/user/username/projects/sample1/core/anotherModule.ts": `export const World = "hello";`,
"/user/username/projects/sample1/logic/tsconfig.json": getFsContentsForSampleProjectReferencesLogicConfig(),
"/user/username/projects/sample1/logic/tsconfig.json": getFsContentsForSampleProjectReferencesLogicConfig(withNodeNext),
"/user/username/projects/sample1/logic/index.ts": dedent`
import * as c from '../core/index';
export function getSecondsInDay() {
Expand All @@ -64,6 +69,7 @@ export function getFsContentsForSampleProjectReferences(): FsContents {
],
files: ["index.ts"],
compilerOptions: {
...getSampleProjectConfigWithNodeNext(withNodeNext),
composite: true,
declaration: true,
forceConsistentCasingInFileNames: true,
Expand Down Expand Up @@ -93,9 +99,9 @@ export function getFsForSampleProjectReferences() {
);
}

export function getSysForSampleProjectReferences() {
export function getSysForSampleProjectReferences(withNodeNext?: boolean) {
return createWatchedSystem(
getFsContentsForSampleProjectReferences(),
getFsContentsForSampleProjectReferences(withNodeNext),
{
currentDirectory: "/user/username/projects/sample1",
},
Expand Down
100 changes: 55 additions & 45 deletions src/testRunner/unittests/tscWatch/projectsWithReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
jsonToReadableText,
} from "../helpers";
import {
getSampleProjectConfigWithNodeNext,
getSysForSampleProjectReferences,
} from "../helpers/sampleProjectReferences";
import {
Expand All @@ -27,54 +28,63 @@ import {
} from "../helpers/virtualFileSystemWithWatch";

describe("unittests:: tsc-watch:: projects with references: invoking when references are already built", () => {
verifyTscWatch({
scenario: "projectsWithReferences",
subScenario: "on sample project",
sys: () =>
solutionBuildWithBaseline(
getSysForSampleProjectReferences(),
["tests"],
),
commandLineArgs: ["-w", "-p", "tests", "--traceResolution", "--explainFiles"],
edits: [
{
caption: "local edit in logic ts, and build logic",
edit: sys => {
sys.appendFile("/user/username/projects/sample1/logic/index.ts", `function foo() { }`);
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
solutionBuilder.build();
function verify(withNodeNext: boolean) {
verifyTscWatch({
scenario: "projectsWithReferences",
subScenario: `on sample project${withNodeNext ? " with nodenext" : ""}`,
sys: () =>
solutionBuildWithBaseline(
getSysForSampleProjectReferences(withNodeNext),
["tests"],
),
commandLineArgs: ["-w", "-p", "tests", "--traceResolution", "--explainFiles"],
edits: [
{
caption: "local edit in logic ts, and build logic",
edit: sys => {
sys.appendFile("/user/username/projects/sample1/logic/index.ts", `function foo() { }`);
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
solutionBuilder.build();
},
// not ideal, but currently because of d.ts but no new file is written
// There will be timeout queued even though file contents are same
timeouts: noop,
},
// not ideal, but currently because of d.ts but no new file is written
// There will be timeout queued even though file contents are same
timeouts: noop,
},
{
caption: "non local edit in logic ts, and build logic",
edit: sys => {
sys.appendFile("/user/username/projects/sample1/logic/index.ts", `export function gfoo() { }`);
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
solutionBuilder.build();
{
caption: "non local edit in logic ts, and build logic",
edit: sys => {
sys.appendFile("/user/username/projects/sample1/logic/index.ts", `export function gfoo() { }`);
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
solutionBuilder.build();
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "change in project reference config file builds correctly",
edit: sys => {
sys.writeFile(
"/user/username/projects/sample1/logic/tsconfig.json",
jsonToReadableText({
compilerOptions: { composite: true, declaration: true, declarationDir: "decls" },
references: [{ path: "../core" }],
}),
);
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
solutionBuilder.build();
{
caption: "change in project reference config file builds correctly",
edit: sys => {
sys.writeFile(
"/user/username/projects/sample1/logic/tsconfig.json",
jsonToReadableText({
compilerOptions: {
...getSampleProjectConfigWithNodeNext(withNodeNext),
composite: true,
declaration: true,
declarationDir: "decls",
},
references: [{ path: "../core" }],
}),
);
const solutionBuilder = createSolutionBuilder(sys, ["logic"]);
solutionBuilder.build();
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
],
baselineDependencies: true,
});
],
baselineDependencies: true,
});
}
verify(/*withNodeNext*/ false);
verify(/*withNodeNext*/ true);

function changeCompilerOpitonsPaths(sys: TestServerHost, config: string, newPaths: object) {
const configJson = JSON.parse(sys.readFile(config)!);
Expand Down
Loading