mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:19:30 -06:00
Ensure that we are checking if correct file with resolved path is present in the new program when removing the existing packageJson watching (#57988)
This commit is contained in:
parent
35f4f033eb
commit
12402f2609
@ -750,7 +750,8 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
else impliedFormatPackageJsons.delete(newFile.resolvedPath);
|
||||
});
|
||||
impliedFormatPackageJsons.forEach((existing, path) => {
|
||||
if (!newProgram?.getSourceFileByPath(path)) {
|
||||
const newFile = newProgram?.getSourceFileByPath(path);
|
||||
if (!newFile || newFile.resolvedPath !== path) {
|
||||
existing.forEach(location => fileWatchesOfAffectingLocations.get(location)!.files--);
|
||||
impliedFormatPackageJsons.delete(path);
|
||||
}
|
||||
|
||||
@ -29,3 +29,7 @@ export interface FsContents {
|
||||
export function libPath(forLib: string) {
|
||||
return `${ts.getDirectoryPath(libFile.path)}/lib.${forLib}.d.ts`;
|
||||
}
|
||||
|
||||
export function getProjectConfigWithNodeNext(withNodeNext: boolean | undefined) {
|
||||
return withNodeNext ? { module: "nodenext", target: "es5" } : undefined;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
getProjectConfigWithNodeNext,
|
||||
} from "./contents";
|
||||
import {
|
||||
loadProjectFromFiles,
|
||||
@ -16,13 +17,10 @@ import {
|
||||
libFile,
|
||||
} from "./virtualFileSystemWithWatch";
|
||||
|
||||
export function getSampleProjectConfigWithNodeNext(withNodeNext: boolean | undefined) {
|
||||
return withNodeNext ? { module: "nodenext", target: "es5" } : undefined;
|
||||
}
|
||||
export function getFsContentsForSampleProjectReferencesLogicConfig(withNodeNext?: boolean) {
|
||||
return jsonToReadableText({
|
||||
compilerOptions: {
|
||||
...getSampleProjectConfigWithNodeNext(withNodeNext),
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
declaration: true,
|
||||
sourceMap: true,
|
||||
@ -39,7 +37,7 @@ export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean):
|
||||
[libFile.path]: libFile.content,
|
||||
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
|
||||
compilerOptions: {
|
||||
...getSampleProjectConfigWithNodeNext(withNodeNext),
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
declaration: true,
|
||||
declarationMap: true,
|
||||
@ -69,7 +67,7 @@ export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean):
|
||||
],
|
||||
files: ["index.ts"],
|
||||
compilerOptions: {
|
||||
...getSampleProjectConfigWithNodeNext(withNodeNext),
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
declaration: true,
|
||||
forceConsistentCasingInFileNames: true,
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
} from "../helpers";
|
||||
import {
|
||||
FsContents,
|
||||
getProjectConfigWithNodeNext,
|
||||
libContent,
|
||||
} from "./contents";
|
||||
import {
|
||||
@ -19,9 +20,10 @@ export function getFsContentsForTransitiveReferencesRefsAdts() {
|
||||
`;
|
||||
}
|
||||
|
||||
export function getFsContentsForTransitiveReferencesBConfig() {
|
||||
export function getFsContentsForTransitiveReferencesBConfig(withNodeNext: boolean) {
|
||||
return jsonToReadableText({
|
||||
compilerOptions: {
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
baseUrl: "./",
|
||||
paths: {
|
||||
@ -33,14 +35,17 @@ export function getFsContentsForTransitiveReferencesBConfig() {
|
||||
});
|
||||
}
|
||||
|
||||
export function getFsContentsForTransitiveReferencesAConfig() {
|
||||
export function getFsContentsForTransitiveReferencesAConfig(withNodeNext: boolean) {
|
||||
return jsonToReadableText({
|
||||
compilerOptions: { composite: true },
|
||||
compilerOptions: {
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
},
|
||||
files: ["a.ts"],
|
||||
});
|
||||
}
|
||||
|
||||
export function getFsContentsForTransitiveReferences(): FsContents {
|
||||
export function getFsContentsForTransitiveReferences(withNodeNext?: boolean): FsContents {
|
||||
return {
|
||||
"/user/username/projects/transitiveReferences/refs/a.d.ts": getFsContentsForTransitiveReferencesRefsAdts(),
|
||||
"/user/username/projects/transitiveReferences/a.ts": dedent`
|
||||
@ -56,11 +61,12 @@ export function getFsContentsForTransitiveReferences(): FsContents {
|
||||
b;
|
||||
X;
|
||||
`,
|
||||
"/user/username/projects/transitiveReferences/tsconfig.a.json": getFsContentsForTransitiveReferencesAConfig(),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.b.json": getFsContentsForTransitiveReferencesBConfig(),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.a.json": getFsContentsForTransitiveReferencesAConfig(!!withNodeNext),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.b.json": getFsContentsForTransitiveReferencesBConfig(!!withNodeNext),
|
||||
"/user/username/projects/transitiveReferences/tsconfig.c.json": jsonToReadableText({
|
||||
files: ["c.ts"],
|
||||
compilerOptions: {
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
baseUrl: "./",
|
||||
paths: {
|
||||
"@ref/*": ["./refs/*"],
|
||||
|
||||
@ -5,7 +5,9 @@ import {
|
||||
jsonToReadableText,
|
||||
} from "../helpers";
|
||||
import {
|
||||
getSampleProjectConfigWithNodeNext,
|
||||
getProjectConfigWithNodeNext,
|
||||
} from "../helpers/contents";
|
||||
import {
|
||||
getSysForSampleProjectReferences,
|
||||
} from "../helpers/sampleProjectReferences";
|
||||
import {
|
||||
@ -28,7 +30,7 @@ import {
|
||||
} from "../helpers/virtualFileSystemWithWatch";
|
||||
|
||||
describe("unittests:: tsc-watch:: projects with references: invoking when references are already built", () => {
|
||||
function verify(withNodeNext: boolean) {
|
||||
function verifySampleProject(withNodeNext: boolean) {
|
||||
verifyTscWatch({
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: `on sample project${withNodeNext ? " with nodenext" : ""}`,
|
||||
@ -66,7 +68,7 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
"/user/username/projects/sample1/logic/tsconfig.json",
|
||||
jsonToReadableText({
|
||||
compilerOptions: {
|
||||
...getSampleProjectConfigWithNodeNext(withNodeNext),
|
||||
...getProjectConfigWithNodeNext(withNodeNext),
|
||||
composite: true,
|
||||
declaration: true,
|
||||
declarationDir: "decls",
|
||||
@ -83,8 +85,8 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
baselineDependencies: true,
|
||||
});
|
||||
}
|
||||
verify(/*withNodeNext*/ false);
|
||||
verify(/*withNodeNext*/ true);
|
||||
verifySampleProject(/*withNodeNext*/ false);
|
||||
verifySampleProject(/*withNodeNext*/ true);
|
||||
|
||||
function changeCompilerOpitonsPaths(sys: TestServerHost, config: string, newPaths: object) {
|
||||
const configJson = JSON.parse(sys.readFile(config)!);
|
||||
@ -92,77 +94,81 @@ describe("unittests:: tsc-watch:: projects with references: invoking when refere
|
||||
sys.writeFile(config, jsonToReadableText(configJson));
|
||||
}
|
||||
|
||||
verifyTscWatch({
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: "on transitive references",
|
||||
sys: () =>
|
||||
solutionBuildWithBaseline(
|
||||
createWatchedSystem(
|
||||
getFsContentsForTransitiveReferences(),
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
function verifyTransitiveReferences(withNodeNext: boolean) {
|
||||
verifyTscWatch({
|
||||
scenario: "projectsWithReferences",
|
||||
subScenario: `on transitive references${withNodeNext ? " with nodenext" : ""}`,
|
||||
sys: () =>
|
||||
solutionBuildWithBaseline(
|
||||
createWatchedSystem(
|
||||
getFsContentsForTransitiveReferences(withNodeNext),
|
||||
{ currentDirectory: `/user/username/projects/transitiveReferences` },
|
||||
),
|
||||
["tsconfig.c.json"],
|
||||
),
|
||||
["tsconfig.c.json"],
|
||||
),
|
||||
commandLineArgs: ["-w", "-p", "tsconfig.c.json", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "non local edit b ts, and build b",
|
||||
edit: sys => {
|
||||
sys.appendFile("b.ts", `export function gfoo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["tsconfig.b.json"]);
|
||||
solutionBuilder.build();
|
||||
commandLineArgs: ["-w", "-p", "tsconfig.c.json", "--traceResolution", "--explainFiles"],
|
||||
edits: [
|
||||
{
|
||||
caption: "non local edit b ts, and build b",
|
||||
edit: sys => {
|
||||
sys.appendFile("b.ts", `export function gfoo() { }`);
|
||||
const solutionBuilder = createSolutionBuilder(sys, ["tsconfig.b.json"]);
|
||||
solutionBuilder.build();
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "edit on config file",
|
||||
edit: sys => {
|
||||
sys.ensureFileOrFolder({
|
||||
path: "/user/username/projects/transitiveReferences/nrefs/a.d.ts",
|
||||
content: sys.readFile("/user/username/projects/transitiveReferences/refs/a.d.ts")!,
|
||||
});
|
||||
changeCompilerOpitonsPaths(sys, "tsconfig.c.json", { "@ref/*": ["./nrefs/*"] });
|
||||
{
|
||||
caption: "edit on config file",
|
||||
edit: sys => {
|
||||
sys.ensureFileOrFolder({
|
||||
path: "/user/username/projects/transitiveReferences/nrefs/a.d.ts",
|
||||
content: sys.readFile("/user/username/projects/transitiveReferences/refs/a.d.ts")!,
|
||||
});
|
||||
changeCompilerOpitonsPaths(sys, "tsconfig.c.json", { "@ref/*": ["./nrefs/*"] });
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.c.json", { "@ref/*": ["./refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "edit in referenced config file",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.b.json", { "@ref/*": ["./nrefs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert referenced config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.b.json", { "@ref/*": ["./refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting referenced config file",
|
||||
edit: sys => sys.deleteFile("tsconfig.b.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting referenced config file",
|
||||
edit: sys => sys.writeFile("tsconfig.b.json", getFsContentsForTransitiveReferencesBConfig()),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting transitively referenced config file",
|
||||
edit: sys => sys.deleteFile("tsconfig.a.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting transitively referenced config file",
|
||||
edit: sys => sys.writeFile("tsconfig.a.json", getFsContentsForTransitiveReferencesAConfig()),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
baselineDependencies: true,
|
||||
});
|
||||
{
|
||||
caption: "Revert config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.c.json", { "@ref/*": ["./refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "edit in referenced config file",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.b.json", { "@ref/*": ["./nrefs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert referenced config file edit",
|
||||
edit: sys => changeCompilerOpitonsPaths(sys, "tsconfig.b.json", { "@ref/*": ["./refs/*"] }),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting referenced config file",
|
||||
edit: sys => sys.deleteFile("tsconfig.b.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting referenced config file",
|
||||
edit: sys => sys.writeFile("tsconfig.b.json", getFsContentsForTransitiveReferencesBConfig(withNodeNext)),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "deleting transitively referenced config file",
|
||||
edit: sys => sys.deleteFile("tsconfig.a.json"),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
{
|
||||
caption: "Revert deleting transitively referenced config file",
|
||||
edit: sys => sys.writeFile("tsconfig.a.json", getFsContentsForTransitiveReferencesAConfig(withNodeNext)),
|
||||
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
|
||||
},
|
||||
],
|
||||
baselineDependencies: true,
|
||||
});
|
||||
}
|
||||
verifyTransitiveReferences(/*withNodeNext*/ false);
|
||||
verifyTransitiveReferences(/*withNodeNext*/ true);
|
||||
|
||||
verifyTscWatch({
|
||||
scenario: "projectsWithReferences",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user