Skip to content

Commit 3e91652

Browse files
authored
Merge pull request #27688 from Microsoft/fixTsBuildIncrementalNoErrorScenario
Remove any existing errors in case of successful build in tsbuild watch mode
2 parents dd764b3 + ba0f558 commit 3e91652

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/compiler/tsbuild.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,9 @@ namespace ts {
10661066
type: UpToDateStatusType.UpToDate,
10671067
newestDeclarationFileContentChangedTime: anyDtsChanged ? maximumDate : newestDeclarationFileContentChangedTime
10681068
};
1069+
if (options.watch) {
1070+
diagnostics.removeKey(proj);
1071+
}
10691072
projectStatus.setValue(proj, status);
10701073
return resultFlags;
10711074

src/testRunner/unittests/tsbuildWatchMode.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,58 @@ function myFunc() { return 100; }`);
356356
}
357357
});
358358

359+
it("when referenced project change introduces error in the down stream project and then fixes it", () => {
360+
const subProjectLibrary = `${projectsLocation}/${project}/Library`;
361+
const libraryTs: File = {
362+
path: `${subProjectLibrary}/library.ts`,
363+
content: `
364+
interface SomeObject
365+
{
366+
message: string;
367+
}
368+
369+
export function createSomeObject(): SomeObject
370+
{
371+
return {
372+
message: "new Object"
373+
};
374+
}`
375+
};
376+
const libraryTsconfig: File = {
377+
path: `${subProjectLibrary}/tsconfig.json`,
378+
content: JSON.stringify({ compilerOptions: { composite: true } })
379+
};
380+
const subProjectApp = `${projectsLocation}/${project}/App`;
381+
const appTs: File = {
382+
path: `${subProjectApp}/app.ts`,
383+
content: `import { createSomeObject } from "../Library/library";
384+
createSomeObject().message;`
385+
};
386+
const appTsconfig: File = {
387+
path: `${subProjectApp}/tsconfig.json`,
388+
content: JSON.stringify({ references: [{ path: "../Library" }] })
389+
};
390+
391+
const files = [libFile, libraryTs, libraryTsconfig, appTs, appTsconfig];
392+
const host = createWatchedSystem(files, { currentDirectory: `${projectsLocation}/${project}` });
393+
createSolutionBuilderWithWatch(host, ["App"]);
394+
checkOutputErrorsInitial(host, emptyArray);
395+
396+
// Change message in library to message2
397+
host.writeFile(libraryTs.path, libraryTs.content.replace(/message/g, "message2"));
398+
host.checkTimeoutQueueLengthAndRun(1); // Build library
399+
host.checkTimeoutQueueLengthAndRun(1); // Build App
400+
checkOutputErrorsIncremental(host, [
401+
"App/app.ts(2,20): error TS2551: Property 'message' does not exist on type 'SomeObject'. Did you mean 'message2'?\n"
402+
]);
403+
404+
// Revert library changes
405+
host.writeFile(libraryTs.path, libraryTs.content);
406+
host.checkTimeoutQueueLengthAndRun(1); // Build library
407+
host.checkTimeoutQueueLengthAndRun(1); // Build App
408+
checkOutputErrorsIncremental(host, emptyArray);
409+
});
410+
359411
describe("reports errors in all projects on incremental compile", () => {
360412
function verifyIncrementalErrors(defaultBuildOptions?: BuildOptions, disabledConsoleClear?: boolean) {
361413
const host = createSolutionInWatchMode(allFiles, defaultBuildOptions, disabledConsoleClear);

0 commit comments

Comments
 (0)