Skip to content

Commit d82070d

Browse files
committed
Use a temporary file for the transformation
1 parent eeebefe commit d82070d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cli.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ program
4242
for (const file of files) {
4343
const filePath = path.resolve(file);
4444
const newPath = filePath.replace(/\.jsx?$/, '.tsx');
45-
45+
const temporaryPath = filePath.replace(/\.jsx?$/, `_js2ts_${+new Date()}.tsx`);
4646
try {
47-
fs.renameSync(filePath, newPath);
48-
const result = run(newPath, prettierOptions);
47+
fs.copyFileSync(filePath, temporaryPath);
48+
const result = run(temporaryPath, prettierOptions);
4949
fs.writeFileSync(newPath, result);
50+
fs.unlinkSync(filePath);
51+
fs.unlinkSync(temporaryPath);
5052
} catch (error) {
5153
console.warn(`Failed to convert ${file}`);
5254
console.warn(error);

0 commit comments

Comments
 (0)