Skip to content

Commit 8b72280

Browse files
committed
Rewrite in TypeScript
Resolve #18
1 parent d1359af commit 8b72280

File tree

6 files changed

+81
-76
lines changed

6 files changed

+81
-76
lines changed

.babelrc.js

-5
This file was deleted.

index.d.ts

-30
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"types": "index.d.ts",
1010
"scripts": {
1111
"clean": "rimraf coverage dist",
12-
"build": "rollup -c",
12+
"build": "tsc",
1313
"lint": "eslint src tests",
1414
"postpublish": "yarn clean",
1515
"prepublishOnly": "yarn lint && yarn test && yarn clean && yarn build",

src/index.js

-40
This file was deleted.

src/index.ts

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { deleteAsync, type Options as DelOptions } from 'del'
2+
import type { AsyncPluginHooks, Plugin } from 'rollup'
3+
4+
export interface Options extends DelOptions {
5+
/**
6+
* Rollup hook the plugin should use.
7+
* @default 'buildStart'
8+
* end
9+
*/
10+
readonly hook?: AsyncPluginHooks
11+
12+
/**
13+
* Delete items once. Useful in watch mode.
14+
* @default false
15+
*/
16+
readonly runOnce?: boolean
17+
18+
/**
19+
* Patterns of files and folders to be deleted.
20+
* @default []
21+
*/
22+
readonly targets?: readonly string[] | string
23+
24+
/**
25+
* Outputs removed files and folders to console.
26+
* @default false
27+
*/
28+
readonly verbose?: boolean
29+
}
30+
31+
export default function del(options: Options = {}): Plugin {
32+
const {
33+
hook = 'buildStart',
34+
runOnce = false,
35+
targets = [],
36+
verbose = false,
37+
...delOptions
38+
} = options
39+
40+
let deleted = false
41+
42+
return {
43+
name: 'delete',
44+
// eslint-disable-next-line perfectionist/sort-objects
45+
[hook]: async () => {
46+
if (runOnce && deleted) {
47+
return
48+
}
49+
50+
const paths = await deleteAsync(targets, delOptions)
51+
52+
if (verbose || delOptions.dryRun) {
53+
const message = delOptions.dryRun
54+
? `Expected files and folders to be deleted: ${paths.length}`
55+
: `Deleted files and folders: ${paths.length}`
56+
57+
console.log(message)
58+
59+
if (paths.length) {
60+
paths.forEach((path) => {
61+
console.log(path)
62+
})
63+
}
64+
}
65+
66+
// eslint-disable-next-line require-atomic-updates
67+
deleted = true
68+
}
69+
}
70+
}

tsconfig.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "@tsconfig/node18",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"noImplicitReturns": true,
6+
"outDir": "dist",
7+
"verbatimModuleSyntax": true
8+
},
9+
"include": ["src"]
10+
}

0 commit comments

Comments
 (0)