Skip to content

Commit d51b8cf

Browse files
authored
Do not delete output file names that are same as input file name (#43448)
* Add failing test case * Do not delete output file names that are same as input file name Fixes #43116
1 parent 3dd68b8 commit d51b8cf

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/compiler/tsbuildPublic.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,11 @@ namespace ts {
17171717
continue;
17181718
}
17191719
const outputs = getAllProjectOutputs(parsed, !host.useCaseSensitiveFileNames());
1720+
if (!outputs.length) continue;
1721+
const inputFileNames = new Set(parsed.fileNames.map(f => toPath(state, f)));
17201722
for (const output of outputs) {
1723+
// If output name is same as input file name, do not delete and ignore the error
1724+
if (inputFileNames.has(toPath(state, output))) continue;
17211725
if (host.fileExists(output)) {
17221726
if (filesToDelete) {
17231727
filesToDelete.push(output);

src/testRunner/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"unittests/services/textChanges.ts",
114114
"unittests/services/transpile.ts",
115115
"unittests/tsbuild/amdModulesWithOut.ts",
116+
"unittests/tsbuild/clean.ts",
116117
"unittests/tsbuild/configFileErrors.ts",
117118
"unittests/tsbuild/configFileExtends.ts",
118119
"unittests/tsbuild/containerOnlyReferenced.ts",
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace ts {
2+
describe("unittests:: tsbuild - clean", () => {
3+
verifyTsc({
4+
scenario: "clean",
5+
subScenario: `file name and output name clashing`,
6+
commandLineArgs: ["--b", "/src/tsconfig.json", "-clean"],
7+
fs: () => loadProjectFromFiles({
8+
"/src/index.js": "",
9+
"/src/bar.ts": "",
10+
"/src/tsconfig.json": JSON.stringify({
11+
compilerOptions: { allowJs: true },
12+
}),
13+
}),
14+
});
15+
});
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
4+
5+
//// [/src/bar.ts]
6+
7+
8+
//// [/src/index.js]
9+
10+
11+
//// [/src/tsconfig.json]
12+
{"compilerOptions":{"allowJs":true}}
13+
14+
15+
16+
Output::
17+
/lib/tsc --b /src/tsconfig.json -clean
18+
exitCode:: ExitStatus.Success
19+
20+

0 commit comments

Comments
 (0)