@rollup-extras/plugin-clean 1.0.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -3
- package/dist/index.cjs +51 -24
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +51 -24
- package/dist/types.d.ts +3 -2
- package/package.json +12 -18
package/README.md
CHANGED
|
@@ -15,15 +15,74 @@ Plugin runs on `renderStart` per each output and uses output.dir as a default ta
|
|
|
15
15
|
|
|
16
16
|
Uses [`@niceties/logger`](https://github.com/kshutkin/niceties/blob/main/logger/README.md) to log messages, can be configured through `@niceties/logger` API.
|
|
17
17
|
|
|
18
|
+
[Changlelog](./CHANGELOG.md)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
npm install --save-dev @rollup-extras/plugin-clean
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Examples
|
|
27
|
+
|
|
28
|
+
Normal usage:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import clean from '@rollup-extras/plugin-clean';
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
input: 'src/index.js',
|
|
35
|
+
|
|
36
|
+
output: {
|
|
37
|
+
format: 'es',
|
|
38
|
+
dir: 'dest'
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
plugins: [clean()],
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To override / provide target directory to clean use:
|
|
46
|
+
```javascript
|
|
47
|
+
clean('dir')
|
|
48
|
+
```
|
|
49
|
+
or
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
clean(['dir1', 'dir2'])
|
|
53
|
+
```
|
|
54
|
+
or
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
clean({targets: 'dir1'})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
or
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
clean({targets: ['dir1', 'dir2']})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Other supporded fields in options object: `pluginName`, `deleteOnce`, `outputPlugin` and `verbose`.
|
|
67
|
+
|
|
68
|
+
`pluginName` is just for debugging purpose so you can understand which instance of plugin responsible for an error.
|
|
69
|
+
|
|
70
|
+
`deleteOnce` can be set to `false` if you want to clean directory every rebuild.
|
|
71
|
+
|
|
72
|
+
`outputPlugin` can be set to `false` if you want plugin to trigger earlier (use with caution, you may want to define `targets` youself in this mode)
|
|
73
|
+
|
|
74
|
+
`verbose` is to get more messages in console.
|
|
75
|
+
|
|
18
76
|
## Configuration
|
|
19
77
|
|
|
20
78
|
```typescript
|
|
21
|
-
|
|
79
|
+
type CleanPluginOptions = {
|
|
22
80
|
targets?: string | string[], // defaulted to output.dir per output
|
|
23
81
|
pluginName?: string, // for debugging purposes, default is `@rollup-extras/plugin-clean`
|
|
24
|
-
|
|
82
|
+
deleteOnce?: boolean, // default true
|
|
83
|
+
outputPlugin?: boolean, // default true
|
|
25
84
|
verbose?: boolean // default false
|
|
26
|
-
};
|
|
85
|
+
} | string | string[];
|
|
27
86
|
```
|
|
28
87
|
|
|
29
88
|
## Prior Art
|
package/dist/index.cjs
CHANGED
|
@@ -3,40 +3,67 @@
|
|
|
3
3
|
var fs = require('fs/promises');
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var logger = require('@niceties/logger');
|
|
6
|
+
var options = require('@rollup-extras/utils/options');
|
|
6
7
|
|
|
7
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
9
|
|
|
9
10
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
10
11
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
11
12
|
|
|
12
|
-
function index (
|
|
13
|
-
const deleted = new
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
function index (options$1 = {}) {
|
|
14
|
+
const deleted = new Map();
|
|
15
|
+
const normalizedOptions = options.getOptions(options$1, {
|
|
16
|
+
pluginName: '@rollup-extras/plugin-clean',
|
|
17
|
+
deleteOnce: true,
|
|
18
|
+
verbose: false,
|
|
19
|
+
outputPlugin: true
|
|
20
|
+
}, 'targets');
|
|
21
|
+
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
22
|
+
let { targets } = normalizedOptions;
|
|
23
|
+
const pluginInstance = {
|
|
24
|
+
name: pluginName
|
|
25
|
+
};
|
|
26
|
+
if (outputPlugin) {
|
|
27
|
+
pluginInstance.renderStart = renderStart;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
pluginInstance.buildStart = buildStart;
|
|
31
|
+
pluginInstance.options = optionsHook;
|
|
32
|
+
}
|
|
33
|
+
return pluginInstance;
|
|
34
|
+
async function optionsHook(config) {
|
|
35
|
+
var _a;
|
|
36
|
+
if (!targets && config) {
|
|
37
|
+
targets = (Array.isArray(config.output) ? config.output.map(item => item.dir) : [(_a = config.output) === null || _a === void 0 ? void 0 : _a.dir])
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
async function buildStart() {
|
|
43
|
+
if (targets) {
|
|
44
|
+
await Promise.all(targets.map(removeDir));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function renderStart(options) {
|
|
48
|
+
if (!targets) {
|
|
49
|
+
if (options.dir) {
|
|
50
|
+
await removeDir(options.dir);
|
|
31
51
|
}
|
|
32
52
|
}
|
|
33
|
-
|
|
53
|
+
else {
|
|
54
|
+
await Promise.all(targets.map(removeDir));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
34
57
|
async function removeDir(dir) {
|
|
35
58
|
const normalizedDir = normalizeSlash(path__default["default"].normalize(dir));
|
|
36
|
-
if (
|
|
37
|
-
return;
|
|
59
|
+
if (deleteOnce && deleted.has(normalizedDir)) {
|
|
60
|
+
return outputPlugin && deleted.get(normalizedDir);
|
|
38
61
|
}
|
|
39
|
-
|
|
62
|
+
const removePromise = doRemove(normalizedDir);
|
|
63
|
+
deleted.set(normalizedDir, removePromise);
|
|
64
|
+
return removePromise;
|
|
65
|
+
}
|
|
66
|
+
async function doRemove(normalizedDir) {
|
|
40
67
|
const logger$1 = logger.createLogger(pluginName);
|
|
41
68
|
try {
|
|
42
69
|
logger$1.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* info */ : 0 /* verbose */);
|
|
@@ -45,7 +72,7 @@ function index ({ targets, pluginName, runOnce, verbose } = {}) {
|
|
|
45
72
|
}
|
|
46
73
|
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
47
74
|
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
|
|
48
|
-
logger$1.finish(`failed cleaning '${normalizedDir}'
|
|
75
|
+
logger$1.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
49
76
|
}
|
|
50
77
|
}
|
|
51
78
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { PluginHooks } from 'rollup';
|
|
2
2
|
import { CleanPluginOptions } from './types';
|
|
3
|
-
export default function (
|
|
3
|
+
export default function (options?: CleanPluginOptions): Partial<PluginHooks>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,35 +1,62 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { createLogger } from '@niceties/logger';
|
|
4
|
+
import { getOptions } from '@rollup-extras/utils/options';
|
|
4
5
|
|
|
5
|
-
function index (
|
|
6
|
-
const deleted = new
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
function index (options = {}) {
|
|
7
|
+
const deleted = new Map();
|
|
8
|
+
const normalizedOptions = getOptions(options, {
|
|
9
|
+
pluginName: '@rollup-extras/plugin-clean',
|
|
10
|
+
deleteOnce: true,
|
|
11
|
+
verbose: false,
|
|
12
|
+
outputPlugin: true
|
|
13
|
+
}, 'targets');
|
|
14
|
+
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
15
|
+
let { targets } = normalizedOptions;
|
|
16
|
+
const pluginInstance = {
|
|
17
|
+
name: pluginName
|
|
18
|
+
};
|
|
19
|
+
if (outputPlugin) {
|
|
20
|
+
pluginInstance.renderStart = renderStart;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
pluginInstance.buildStart = buildStart;
|
|
24
|
+
pluginInstance.options = optionsHook;
|
|
25
|
+
}
|
|
26
|
+
return pluginInstance;
|
|
27
|
+
async function optionsHook(config) {
|
|
28
|
+
var _a;
|
|
29
|
+
if (!targets && config) {
|
|
30
|
+
targets = (Array.isArray(config.output) ? config.output.map(item => item.dir) : [(_a = config.output) === null || _a === void 0 ? void 0 : _a.dir])
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
async function buildStart() {
|
|
36
|
+
if (targets) {
|
|
37
|
+
await Promise.all(targets.map(removeDir));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function renderStart(options) {
|
|
41
|
+
if (!targets) {
|
|
42
|
+
if (options.dir) {
|
|
43
|
+
await removeDir(options.dir);
|
|
24
44
|
}
|
|
25
45
|
}
|
|
26
|
-
|
|
46
|
+
else {
|
|
47
|
+
await Promise.all(targets.map(removeDir));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
27
50
|
async function removeDir(dir) {
|
|
28
51
|
const normalizedDir = normalizeSlash(path.normalize(dir));
|
|
29
|
-
if (
|
|
30
|
-
return;
|
|
52
|
+
if (deleteOnce && deleted.has(normalizedDir)) {
|
|
53
|
+
return outputPlugin && deleted.get(normalizedDir);
|
|
31
54
|
}
|
|
32
|
-
|
|
55
|
+
const removePromise = doRemove(normalizedDir);
|
|
56
|
+
deleted.set(normalizedDir, removePromise);
|
|
57
|
+
return removePromise;
|
|
58
|
+
}
|
|
59
|
+
async function doRemove(normalizedDir) {
|
|
33
60
|
const logger = createLogger(pluginName);
|
|
34
61
|
try {
|
|
35
62
|
logger.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* info */ : 0 /* verbose */);
|
|
@@ -38,7 +65,7 @@ function index ({ targets, pluginName, runOnce, verbose } = {}) {
|
|
|
38
65
|
}
|
|
39
66
|
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
40
67
|
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
|
|
41
|
-
logger.finish(`failed cleaning '${normalizedDir}'
|
|
68
|
+
logger.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
71
|
}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.4",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@rollup-extras/plugin-clean",
|
|
5
5
|
"author": {
|
|
@@ -30,19 +30,19 @@
|
|
|
30
30
|
"url": "https://github.com/kshutkin/rollup-extras/issues"
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/kshutkin/rollup-extras/plugin-clean/README.md",
|
|
33
|
+
"readme": "README.md",
|
|
34
|
+
"description": "Rollup plugin to clean a directory during build.",
|
|
33
35
|
"keywords": [
|
|
34
|
-
"rollup-plugin"
|
|
36
|
+
"rollup-plugin",
|
|
37
|
+
"clean"
|
|
35
38
|
],
|
|
36
39
|
"scripts": {
|
|
37
|
-
"build": "
|
|
38
|
-
"dev": "rimraf ./dist && rollup -c -w",
|
|
40
|
+
"build": "pkgbld",
|
|
39
41
|
"test": "jest --collectCoverage",
|
|
40
42
|
"lint": "eslint ./src",
|
|
41
43
|
"semantic-release": "npx semantic-release"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
|
-
"@rollup/plugin-commonjs": "21.0.1",
|
|
45
|
-
"@rollup/plugin-node-resolve": "13.0.6",
|
|
46
46
|
"@semantic-release/changelog": "6.0.1",
|
|
47
47
|
"@semantic-release/commit-analyzer": "9.0.1",
|
|
48
48
|
"@semantic-release/git": "10.0.1",
|
|
@@ -54,24 +54,18 @@
|
|
|
54
54
|
"conventional-changelog-angular": "5.0.13",
|
|
55
55
|
"eslint": "8.1.0",
|
|
56
56
|
"jest": "27.3.1",
|
|
57
|
-
"lodash": "4.17.21",
|
|
58
|
-
"rimraf": "3.0.2",
|
|
59
|
-
"is-builtin-module": "3.1.0",
|
|
60
|
-
"rollup": "2.60.1",
|
|
61
|
-
"rollup-plugin-terser": "7.0.2",
|
|
62
|
-
"rollup-plugin-typescript2": "0.31.1",
|
|
63
|
-
"rollup-plugin-preprocess": "0.0.4",
|
|
64
57
|
"semantic-release": "18.0.0",
|
|
65
58
|
"semantic-release-monorepo": "7.0.5",
|
|
66
59
|
"ts-jest": "27.0.7",
|
|
67
|
-
"typescript": "4.
|
|
68
|
-
"update-monorepo-package-json": "0.
|
|
60
|
+
"typescript": "4.5.x",
|
|
61
|
+
"update-monorepo-package-json": "0.2.0",
|
|
62
|
+
"pkgbld": "1.1.1"
|
|
69
63
|
},
|
|
70
64
|
"peerDependencies": {
|
|
71
65
|
"rollup": "^2.60.2"
|
|
72
66
|
},
|
|
73
67
|
"dependencies": {
|
|
74
|
-
"@niceties/logger": "1.0
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
"@niceties/logger": "^1.1.0",
|
|
69
|
+
"@rollup-extras/utils": "^1.0.1"
|
|
70
|
+
}
|
|
77
71
|
}
|