Skip to content

Commit

Permalink
Do not delete output file names that are same as input file name (#43448
Browse files Browse the repository at this point in the history
)

* Add failing test case

* Do not delete output file names that are same as input file name
Fixes #43116
  • Loading branch information
sheetalkamat committed Mar 30, 2021
1 parent 3dd68b8 commit d51b8cf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,11 @@ namespace ts {
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);
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"unittests/services/textChanges.ts",
"unittests/services/transpile.ts",
"unittests/tsbuild/amdModulesWithOut.ts",
"unittests/tsbuild/clean.ts",
"unittests/tsbuild/configFileErrors.ts",
"unittests/tsbuild/configFileExtends.ts",
"unittests/tsbuild/containerOnlyReferenced.ts",
Expand Down
16 changes: 16 additions & 0 deletions src/testRunner/unittests/tsbuild/clean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace ts {
describe("unittests:: tsbuild - clean", () => {
verifyTsc({
scenario: "clean",
subScenario: `file name and output name clashing`,
commandLineArgs: ["--b", "/src/tsconfig.json", "-clean"],
fs: () => loadProjectFromFiles({
"/src/index.js": "",
"/src/bar.ts": "",
"/src/tsconfig.json": JSON.stringify({
compilerOptions: { allowJs: true },
}),
}),
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Input::
//// [/lib/lib.d.ts]


//// [/src/bar.ts]


//// [/src/index.js]


//// [/src/tsconfig.json]
{"compilerOptions":{"allowJs":true}}



Output::
/lib/tsc --b /src/tsconfig.json -clean
exitCode:: ExitStatus.Success


0 comments on commit d51b8cf

Please sign in to comment.