Add option --stopBuildOnErrors to tsbuild to get previous behavior of not building downstream projects if upstream has errors (#59433)

This commit is contained in:
Sheetal Nandi
2024-08-16 19:02:42 -07:00
committed by GitHub
parent f850298f70
commit d06fb82d7c
13 changed files with 3702 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ export function getFsContentsForSampleProjectReferencesLogicConfig(withNodeNext?
],
});
}
export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean): FsContents {
export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean, skipReferenceCoreFromTest?: boolean): FsContents {
return {
[libFile.path]: libFile.content,
"/user/username/projects/sample1/core/tsconfig.json": jsonToReadableText({
@@ -55,10 +55,14 @@ export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean):
export const m = mod;
`,
"/user/username/projects/sample1/tests/tsconfig.json": jsonToReadableText({
references: [
{ path: "../core" },
{ path: "../logic" },
],
references: !skipReferenceCoreFromTest ?
[
{ path: "../core" },
{ path: "../logic" },
] :
[
{ path: "../logic" },
],
files: ["index.ts"],
compilerOptions: {
...getProjectConfigWithNodeNext(withNodeNext),
@@ -81,9 +85,9 @@ export function getFsContentsForSampleProjectReferences(withNodeNext?: boolean):
};
}
export function getFsForSampleProjectReferences() {
export function getFsForSampleProjectReferences(withNodeNext?: boolean, skipReferenceCoreFromTest?: boolean) {
return loadProjectFromFiles(
getFsContentsForSampleProjectReferences(),
getFsContentsForSampleProjectReferences(withNodeNext, skipReferenceCoreFromTest),
{
cwd: "/user/username/projects/sample1",
executingFilePath: libFile.path,
@@ -91,9 +95,9 @@ export function getFsForSampleProjectReferences() {
);
}
export function getSysForSampleProjectReferences(withNodeNext?: boolean) {
export function getSysForSampleProjectReferences(withNodeNext?: boolean, skipReferenceCoreFromTest?: boolean) {
return createWatchedSystem(
getFsContentsForSampleProjectReferences(withNodeNext),
getFsContentsForSampleProjectReferences(withNodeNext, skipReferenceCoreFromTest),
{
currentDirectory: "/user/username/projects/sample1",
},

View File

@@ -359,6 +359,23 @@ describe("unittests:: tsbuild:: on 'sample1' project", () => {
modifyFs: fs => replaceText(fs, "logic/index.ts", "c.multiply(10, 15)", `c.muitply()`),
edits: noChangeOnlyRuns,
});
[false, true].forEach(skipReferenceCoreFromTest =>
verifyTsc({
scenario: "sample1",
subScenario: `skips builds downstream projects if upstream projects have errors with stopBuildOnErrors${skipReferenceCoreFromTest ? " when test does not reference core" : ""}`,
fs: () => getFsForSampleProjectReferences(/*withNodeNext*/ undefined, skipReferenceCoreFromTest),
commandLineArgs: ["--b", "tests", "--verbose", "--stopBuildOnErrors"],
modifyFs: fs => appendText(fs, "core/index.ts", `multiply();`),
edits: [
noChangeRun,
{
caption: "fix error",
edit: fs => replaceText(fs, "core/index.ts", "multiply();", ""),
},
],
})
);
});
describe("project invalidation", () => {

View File

@@ -316,6 +316,28 @@ createSomeObject().message;`,
}
verifyIncrementalErrors("when preserveWatchOutput is not used", ts.emptyArray);
verifyIncrementalErrors("when preserveWatchOutput is passed on command line", ["--preserveWatchOutput"]);
verifyIncrementalErrors("when stopBuildOnErrors is passed on command line", ["--stopBuildOnErrors"]);
[false, true].forEach(skipReferenceCoreFromTest =>
verifyTscWatch({
scenario: "programUpdates",
subScenario: `skips builds downstream projects if upstream projects have errors with stopBuildOnErrors${skipReferenceCoreFromTest ? " when test does not reference core" : ""}`,
sys: () => {
const sys = getSysForSampleProjectReferences(/*withNodeNext*/ undefined, skipReferenceCoreFromTest);
sys.appendFile("core/index.ts", `multiply();`);
return sys;
},
commandLineArgs: ["--b", "-w", "tests", "--verbose", "--stopBuildOnErrors"],
edits: [{
caption: "fix error",
edit: sys => sys.replaceFileText("core/index.ts", "multiply();", ""),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks();
sys.runQueuedTimeoutCallbacks();
},
}],
})
);
describe("when declaration emit errors are present", () => {
const solution = "solution";