Skip to content

Commit 317c061

Browse files
committed
refactor(script): Improve build script compatibility by replacing rm -rf with a Node.js script
This commit replaces the `rm -rf dist` command in the build script with a cross-platform Node.js script (`scripts/cleanDist.ts`). This enhances compatibility, particularly for Windows environments where `rm -rf` is not natively available. The new script uses `node:fs/promises` to delete the 'dist' directory.
1 parent 666eeb5 commit 317c061

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"dist"
1818
],
1919
"scripts": {
20-
"build": "rm -rf dist && tsc",
20+
"build": "bun run scripts/cleanDist.ts && tsc",
2121
"release": "bun run build && np",
2222
"test": "bun test",
2323
"typecheck": "tsc --noEmit"

scripts/cleanDist.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { rm } from "node:fs/promises";
2+
3+
const dirToDelete = "dist";
4+
5+
async function cleanDist() {
6+
try {
7+
const dirExists = await Bun.file(dirToDelete).exists();
8+
if (dirExists) {
9+
await rm(dirToDelete, { recursive: true, force: true });
10+
console.log(`Directory '${dirToDelete}' successfully deleted.`);
11+
}
12+
} catch (error) {
13+
console.error(`Error deleting directory '${dirToDelete}':`, error);
14+
process.exit(1);
15+
}
16+
}
17+
18+
cleanDist();

0 commit comments

Comments
 (0)