Skip to content

Commit

Permalink
When tsc --build --clean, only remove tsbuildinfo if its incremental …
Browse files Browse the repository at this point in the history
…build
  • Loading branch information
sheetalkamat committed Jun 2, 2022
1 parent 0cf9e30 commit e4e6672
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 36 deletions.
28 changes: 19 additions & 9 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2033,21 +2033,19 @@ namespace ts {
reportParseConfigFileDiagnostic(state, resolvedPath);
continue;
}
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(parsed.options);
if (buildInfoPath) {
// Only delete buildInfo as thats sufficient
removeOutput(buildInfoPath, resolvedPath);
continue;
}
const outputs = getAllProjectOutputs(parsed, !host.useCaseSensitiveFileNames());
if (!outputs.length) continue;
const inputFileNames = new Set(parsed.fileNames.map(f => toPath(state, f)));
for (const output of outputs) {
// If output name is same as input file name, do not delete and ignore the error
if (inputFileNames.has(toPath(state, output))) continue;
if (host.fileExists(output)) {
if (filesToDelete) {
filesToDelete.push(output);
}
else {
host.deleteFile(output);
invalidateProject(state, resolvedPath, ConfigFileProgramReloadLevel.None);
}
}
removeOutput(output, resolvedPath);
}
}

Expand All @@ -2056,6 +2054,18 @@ namespace ts {
}

return ExitStatus.Success;

function removeOutput(output: string, resolvedPath: ResolvedConfigFilePath) {
if (host.fileExists(output)) {
if (filesToDelete) {
filesToDelete.push(output);
}
else {
host.deleteFile(output);
invalidateProject(state, resolvedPath, ConfigFileProgramReloadLevel.None);
}
}
}
}

function invalidateProject(state: SolutionBuilderState, resolved: ResolvedConfigFilePath, reloadLevel: ConfigFileProgramReloadLevel) {
Expand Down
12 changes: 0 additions & 12 deletions tests/baselines/reference/tsbuild/outFile/clean-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,20 +596,8 @@ Output::
exitCode:: ExitStatus.Success


//// [/src/2/second-output.d.ts] unlink
//// [/src/2/second-output.d.ts.map] unlink
//// [/src/2/second-output.js] unlink
//// [/src/2/second-output.js.map] unlink
//// [/src/2/second-output.tsbuildinfo] unlink
//// [/src/first/bin/first-output.d.ts] unlink
//// [/src/first/bin/first-output.d.ts.map] unlink
//// [/src/first/bin/first-output.js] unlink
//// [/src/first/bin/first-output.js.map] unlink
//// [/src/first/bin/first-output.tsbuildinfo] unlink
//// [/src/third/thirdjs/output/third-output.d.ts] unlink
//// [/src/third/thirdjs/output/third-output.d.ts.map] unlink
//// [/src/third/thirdjs/output/third-output.js] unlink
//// [/src/third/thirdjs/output/third-output.js.map] unlink
//// [/src/third/thirdjs/output/third-output.tsbuildinfo] unlink


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,4 @@ Output::
exitCode:: ExitStatus.Success


//// [/src/2/second-output.d.ts] unlink
//// [/src/2/second-output.d.ts.map] unlink
//// [/src/2/second-output.js] unlink
//// [/src/2/second-output.js.map] unlink
//// [/src/2/second-output.tsbuildinfo] unlink
Original file line number Diff line number Diff line change
Expand Up @@ -390,19 +390,8 @@ Output::
exitCode:: ExitStatus.Success


//// [/src/core/anotherModule.d.ts] unlink
//// [/src/core/anotherModule.d.ts.map] unlink
//// [/src/core/anotherModule.js] unlink
//// [/src/core/index.d.ts] unlink
//// [/src/core/index.d.ts.map] unlink
//// [/src/core/index.js] unlink
//// [/src/core/tsconfig.tsbuildinfo] unlink
//// [/src/logic/index.d.ts] unlink
//// [/src/logic/index.js] unlink
//// [/src/logic/index.js.map] unlink
//// [/src/logic/tsconfig.tsbuildinfo] unlink
//// [/src/tests/index.d.ts] unlink
//// [/src/tests/index.js] unlink
//// [/src/tests/tsconfig.tsbuildinfo] unlink


Expand Down

0 comments on commit e4e6672

Please sign in to comment.