mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix incorrect use of "path" instead of "resolvedPath" when watching file's package json locations (#57931)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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() {
|
||||
@@ -64,6 +69,7 @@ export function getFsContentsForSampleProjectReferences(): FsContents {
|
||||
],
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
...getSampleProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
declaration: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
@@ -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",
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
getSampleProjectConfigWithNodeNext,
|
||||
getSysForSampleProjectReferences,
|
||||
} from "../helpers/sampleProjectReferences";
|
||||
import {
|
||||
@@ -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)!);
|
||||
|
||||
+1643
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user