Skip to content

Commit ff23f7d

Browse files
committed
chore: use rollup-plugin-rm to clean dist
1 parent a48e12a commit ff23f7d

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"prettier": "^3.1.0",
8989
"rollup": "^4.6.1",
9090
"rollup-plugin-dts": "^6.1.0",
91+
"rollup-plugin-rm": "^1.0.2",
9192
"simple-git-hooks": "^2.9.0",
9293
"tslib": "^2.6.2",
9394
"typescript": "^5.3.3",

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
import { createRequire } from 'node:module'
2-
import fs from 'node:fs/promises'
3-
import { type Plugin, defineConfig } from 'rollup'
2+
import { defineConfig } from 'rollup'
43
import ts from '@rollup/plugin-typescript'
54
import resolve from '@rollup/plugin-node-resolve'
65
import json from '@rollup/plugin-json'
76
import dts from 'rollup-plugin-dts'
7+
import rm from 'rollup-plugin-rm'
88

99
const require = createRequire(import.meta.url)
1010
const pkg = require('./package.json')
1111

1212
const external = ['esbuild', ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
1313

14-
function clean(when: 'buildStart' | 'buildEnd', target: string): Plugin {
15-
const _clean = async (target): Promise<void> => {
16-
await fs.rm(target, { recursive: true, force: true }).catch(() => {})
17-
}
18-
return {
19-
name: 'clean',
20-
buildStart: async (): Promise<void> => {
21-
if (when !== 'buildStart') return
22-
await _clean(target)
23-
},
24-
buildEnd: async (): Promise<void> => {
25-
if (when !== 'buildEnd') return
26-
await _clean(target)
27-
}
28-
}
29-
}
30-
3114
export default defineConfig([
3215
{
3316
input: ['src/index.ts', 'src/cli.ts'],
@@ -47,7 +30,7 @@ export default defineConfig([
4730
],
4831
external,
4932
plugins: [
50-
clean('buildStart', 'dist'),
33+
rm('dist', 'buildStart'),
5134
json(),
5235
ts({ compilerOptions: { rootDir: 'src', declaration: true, declarationDir: 'dist/types' } }),
5336
resolve()
@@ -59,6 +42,6 @@ export default defineConfig([
5942
{
6043
input: 'dist/types/index.d.ts',
6144
output: [{ file: pkg.types, format: 'es' }],
62-
plugins: [dts(), clean('buildEnd', 'dist/types')]
45+
plugins: [dts(), rm('dist/types', 'buildEnd')]
6346
}
6447
])

0 commit comments

Comments
 (0)