@rollup-extras/plugin-clean 1.3.4 → 1.3.5
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/LICENSE +1 -1
- package/README.md +7 -7
- package/dist/index.cjs +125 -126
- package/dist/index.d.ts +7 -7
- package/dist/index.mjs +125 -126
- package/dist/types.d.ts +7 -7
- package/package.json +13 -28
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ 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
|
-
[
|
|
18
|
+
[Changelog](./CHANGELOG.md)
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
@@ -63,15 +63,15 @@ or
|
|
|
63
63
|
clean({targets: ['dir1', 'dir2']})
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
Other
|
|
66
|
+
Other supported fields in options object: `pluginName`, `deleteOnce`, `outputPlugin` and `verbose`.
|
|
67
67
|
|
|
68
|
-
`pluginName` is just for debugging
|
|
68
|
+
`pluginName` is just for debugging purposes so you can understand which instance of the plugin is responsible for an error.
|
|
69
69
|
|
|
70
|
-
`deleteOnce` can be set to `false` if you want to clean directory every rebuild.
|
|
70
|
+
`deleteOnce` can be set to `false` if you want to clean the directory every rebuild.
|
|
71
71
|
|
|
72
|
-
`outputPlugin` can be set to `false` if you want plugin to trigger earlier (use with caution, you may want to define `targets`
|
|
72
|
+
`outputPlugin` can be set to `false` if you want plugin to trigger earlier (use with caution, you may want to define `targets` yourself in this mode)
|
|
73
73
|
|
|
74
|
-
`verbose` is to get more messages in console.
|
|
74
|
+
`verbose` is to get more messages in the console.
|
|
75
75
|
|
|
76
76
|
## Configuration
|
|
77
77
|
|
|
@@ -93,4 +93,4 @@ type CleanPluginOptions = {
|
|
|
93
93
|
|
|
94
94
|
# License
|
|
95
95
|
|
|
96
|
-
[MIT](
|
|
96
|
+
[MIT](https://github.com/kshutkin/rollup-extras/blob/main/LICENSE)
|
package/dist/index.cjs
CHANGED
|
@@ -6,132 +6,131 @@ var logger = require('@niceties/logger');
|
|
|
6
6
|
var options = require('@rollup-extras/utils/options');
|
|
7
7
|
var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
|
|
8
8
|
|
|
9
|
-
function index (options$1 = {}) {
|
|
10
|
-
const inProgress = new Map();
|
|
11
|
-
const hasChildrenInProgress = new Map();
|
|
12
|
-
let deleted = false;
|
|
13
|
-
const normalizedOptions = options.getOptions(options$1, {
|
|
14
|
-
pluginName: '@rollup-extras/plugin-clean',
|
|
15
|
-
deleteOnce: true,
|
|
16
|
-
verbose: false,
|
|
17
|
-
outputPlugin: true
|
|
18
|
-
}, 'targets');
|
|
19
|
-
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
20
|
-
let { targets } = normalizedOptions;
|
|
21
|
-
const instance = mutliConfigPluginBase.multiConfigPluginBase(false, pluginName, cleanup);
|
|
22
|
-
const baseAddInstance = instance.api.addInstance;
|
|
23
|
-
const baseRenderStart = instance.renderStart;
|
|
24
|
-
if (outputPlugin) {
|
|
25
|
-
instance.renderStart = async function (options, inputOptions) {
|
|
26
|
-
baseRenderStart.call(this, options, inputOptions);
|
|
27
|
-
await renderStart(options);
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
instance.buildStart = buildStart;
|
|
32
|
-
instance.options = optionsHook;
|
|
33
|
-
}
|
|
34
|
-
instance.api.addInstance = () => {
|
|
35
|
-
const instance = baseAddInstance();
|
|
36
|
-
const baseRenderStart = instance.renderStart;
|
|
37
|
-
if (outputPlugin) {
|
|
38
|
-
instance.renderStart = async function (options, inputOptions) {
|
|
39
|
-
baseRenderStart.call(this, options, inputOptions);
|
|
40
|
-
await renderStart(options);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
instance.buildStart = buildStart;
|
|
45
|
-
instance.options = optionsHook;
|
|
46
|
-
}
|
|
47
|
-
return instance;
|
|
48
|
-
};
|
|
49
|
-
return instance;
|
|
50
|
-
async function optionsHook(config) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
9
|
+
function index (options$1 = {}) {
|
|
10
|
+
const inProgress = new Map();
|
|
11
|
+
const hasChildrenInProgress = new Map();
|
|
12
|
+
let deleted = false;
|
|
13
|
+
const normalizedOptions = options.getOptions(options$1, {
|
|
14
|
+
pluginName: '@rollup-extras/plugin-clean',
|
|
15
|
+
deleteOnce: true,
|
|
16
|
+
verbose: false,
|
|
17
|
+
outputPlugin: true
|
|
18
|
+
}, 'targets');
|
|
19
|
+
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
20
|
+
let { targets } = normalizedOptions;
|
|
21
|
+
const instance = mutliConfigPluginBase.multiConfigPluginBase(false, pluginName, cleanup);
|
|
22
|
+
const baseAddInstance = instance.api.addInstance;
|
|
23
|
+
const baseRenderStart = instance.renderStart;
|
|
24
|
+
if (outputPlugin) {
|
|
25
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
26
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
27
|
+
await renderStart(options);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
instance.buildStart = buildStart;
|
|
32
|
+
instance.options = optionsHook;
|
|
33
|
+
}
|
|
34
|
+
instance.api.addInstance = () => {
|
|
35
|
+
const instance = baseAddInstance();
|
|
36
|
+
const baseRenderStart = instance.renderStart;
|
|
37
|
+
if (outputPlugin) {
|
|
38
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
39
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
40
|
+
await renderStart(options);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
instance.buildStart = buildStart;
|
|
45
|
+
instance.options = optionsHook;
|
|
46
|
+
}
|
|
47
|
+
return instance;
|
|
48
|
+
};
|
|
49
|
+
return instance;
|
|
50
|
+
async function optionsHook(config) {
|
|
51
|
+
if (!targets && config) {
|
|
52
|
+
targets = (Array.isArray(config.output) ? config.output.map(item => item.dir) : [config.output?.dir])
|
|
53
|
+
.filter(Boolean);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
async function buildStart() {
|
|
58
|
+
if (deleted) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (targets) {
|
|
62
|
+
await Promise.all(targets.map(removeDir));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function renderStart(options) {
|
|
66
|
+
if (deleted) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!targets) {
|
|
70
|
+
if (options.dir) {
|
|
71
|
+
await removeDir(options.dir);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
await Promise.all(targets.map(removeDir));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function removeDir(dir) {
|
|
79
|
+
const normalizedDir = normalizeSlash(path.normalize(dir));
|
|
80
|
+
if (inProgress.has(normalizedDir)) {
|
|
81
|
+
return outputPlugin && inProgress.get(normalizedDir);
|
|
82
|
+
}
|
|
83
|
+
let removePromise;
|
|
84
|
+
let parentsInProgress;
|
|
85
|
+
if (hasChildrenInProgress.has(dir)) {
|
|
86
|
+
removePromise = Promise.resolve(hasChildrenInProgress.get(dir))
|
|
87
|
+
.then(() => doRemove(normalizedDir));
|
|
88
|
+
}
|
|
89
|
+
else if ((parentsInProgress = Array.from(parentDirs(dir)).filter(item => inProgress.has(item))).length > 0) {
|
|
90
|
+
return inProgress.get(parentsInProgress[0]);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
removePromise = doRemove(normalizedDir);
|
|
94
|
+
}
|
|
95
|
+
inProgress.set(normalizedDir, removePromise);
|
|
96
|
+
for (const parentDir of parentDirs(dir)) {
|
|
97
|
+
if (!hasChildrenInProgress.has(parentDir)) {
|
|
98
|
+
hasChildrenInProgress.set(parentDir, removePromise);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
hasChildrenInProgress.set(parentDir, Promise.all([removePromise, hasChildrenInProgress.get(parentDir)]));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return removePromise;
|
|
105
|
+
}
|
|
106
|
+
async function doRemove(normalizedDir) {
|
|
107
|
+
const logger$1 = logger.createLogger(pluginName);
|
|
108
|
+
try {
|
|
109
|
+
logger$1.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* LogLevel.info */ : 0 /* LogLevel.verbose */);
|
|
110
|
+
await fs.rm(normalizedDir, { recursive: true });
|
|
111
|
+
logger$1.finish(`cleaned '${normalizedDir}'`);
|
|
112
|
+
}
|
|
113
|
+
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
114
|
+
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* LogLevel.warn */;
|
|
115
|
+
logger$1.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function cleanup() {
|
|
119
|
+
inProgress.clear();
|
|
120
|
+
hasChildrenInProgress.clear();
|
|
121
|
+
deleted = deleteOnce;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function normalizeSlash(dir) {
|
|
125
|
+
if (dir.endsWith('/')) {
|
|
126
|
+
return `${dir.substring(0, dir.length - 1)}`;
|
|
127
|
+
}
|
|
128
|
+
return dir;
|
|
129
|
+
}
|
|
130
|
+
function* parentDirs(dir) {
|
|
131
|
+
while (((dir = path.dirname(dir)) !== '.') && (dir !== '/')) {
|
|
132
|
+
yield dir;
|
|
133
|
+
}
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
module.exports = index;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
import { CleanPluginOptions } from './types';
|
|
3
|
-
export default function (options?: CleanPluginOptions): Plugin & {
|
|
4
|
-
api: {
|
|
5
|
-
addInstance(): Plugin;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
1
|
+
import { Plugin } from 'rollup';
|
|
2
|
+
import { CleanPluginOptions } from './types';
|
|
3
|
+
export default function (options?: CleanPluginOptions): Plugin & {
|
|
4
|
+
api: {
|
|
5
|
+
addInstance(): Plugin;
|
|
6
|
+
};
|
|
7
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -4,132 +4,131 @@ import { createLogger } from '@niceties/logger';
|
|
|
4
4
|
import { getOptions } from '@rollup-extras/utils/options';
|
|
5
5
|
import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
|
|
6
6
|
|
|
7
|
-
function index (options = {}) {
|
|
8
|
-
const inProgress = new Map();
|
|
9
|
-
const hasChildrenInProgress = new Map();
|
|
10
|
-
let deleted = false;
|
|
11
|
-
const normalizedOptions = getOptions(options, {
|
|
12
|
-
pluginName: '@rollup-extras/plugin-clean',
|
|
13
|
-
deleteOnce: true,
|
|
14
|
-
verbose: false,
|
|
15
|
-
outputPlugin: true
|
|
16
|
-
}, 'targets');
|
|
17
|
-
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
18
|
-
let { targets } = normalizedOptions;
|
|
19
|
-
const instance = multiConfigPluginBase(false, pluginName, cleanup);
|
|
20
|
-
const baseAddInstance = instance.api.addInstance;
|
|
21
|
-
const baseRenderStart = instance.renderStart;
|
|
22
|
-
if (outputPlugin) {
|
|
23
|
-
instance.renderStart = async function (options, inputOptions) {
|
|
24
|
-
baseRenderStart.call(this, options, inputOptions);
|
|
25
|
-
await renderStart(options);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
instance.buildStart = buildStart;
|
|
30
|
-
instance.options = optionsHook;
|
|
31
|
-
}
|
|
32
|
-
instance.api.addInstance = () => {
|
|
33
|
-
const instance = baseAddInstance();
|
|
34
|
-
const baseRenderStart = instance.renderStart;
|
|
35
|
-
if (outputPlugin) {
|
|
36
|
-
instance.renderStart = async function (options, inputOptions) {
|
|
37
|
-
baseRenderStart.call(this, options, inputOptions);
|
|
38
|
-
await renderStart(options);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
instance.buildStart = buildStart;
|
|
43
|
-
instance.options = optionsHook;
|
|
44
|
-
}
|
|
45
|
-
return instance;
|
|
46
|
-
};
|
|
47
|
-
return instance;
|
|
48
|
-
async function optionsHook(config) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
7
|
+
function index (options = {}) {
|
|
8
|
+
const inProgress = new Map();
|
|
9
|
+
const hasChildrenInProgress = new Map();
|
|
10
|
+
let deleted = false;
|
|
11
|
+
const normalizedOptions = getOptions(options, {
|
|
12
|
+
pluginName: '@rollup-extras/plugin-clean',
|
|
13
|
+
deleteOnce: true,
|
|
14
|
+
verbose: false,
|
|
15
|
+
outputPlugin: true
|
|
16
|
+
}, 'targets');
|
|
17
|
+
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
18
|
+
let { targets } = normalizedOptions;
|
|
19
|
+
const instance = multiConfigPluginBase(false, pluginName, cleanup);
|
|
20
|
+
const baseAddInstance = instance.api.addInstance;
|
|
21
|
+
const baseRenderStart = instance.renderStart;
|
|
22
|
+
if (outputPlugin) {
|
|
23
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
24
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
25
|
+
await renderStart(options);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
instance.buildStart = buildStart;
|
|
30
|
+
instance.options = optionsHook;
|
|
31
|
+
}
|
|
32
|
+
instance.api.addInstance = () => {
|
|
33
|
+
const instance = baseAddInstance();
|
|
34
|
+
const baseRenderStart = instance.renderStart;
|
|
35
|
+
if (outputPlugin) {
|
|
36
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
37
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
38
|
+
await renderStart(options);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
instance.buildStart = buildStart;
|
|
43
|
+
instance.options = optionsHook;
|
|
44
|
+
}
|
|
45
|
+
return instance;
|
|
46
|
+
};
|
|
47
|
+
return instance;
|
|
48
|
+
async function optionsHook(config) {
|
|
49
|
+
if (!targets && config) {
|
|
50
|
+
targets = (Array.isArray(config.output) ? config.output.map(item => item.dir) : [config.output?.dir])
|
|
51
|
+
.filter(Boolean);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
async function buildStart() {
|
|
56
|
+
if (deleted) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (targets) {
|
|
60
|
+
await Promise.all(targets.map(removeDir));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function renderStart(options) {
|
|
64
|
+
if (deleted) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!targets) {
|
|
68
|
+
if (options.dir) {
|
|
69
|
+
await removeDir(options.dir);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
await Promise.all(targets.map(removeDir));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function removeDir(dir) {
|
|
77
|
+
const normalizedDir = normalizeSlash(path.normalize(dir));
|
|
78
|
+
if (inProgress.has(normalizedDir)) {
|
|
79
|
+
return outputPlugin && inProgress.get(normalizedDir);
|
|
80
|
+
}
|
|
81
|
+
let removePromise;
|
|
82
|
+
let parentsInProgress;
|
|
83
|
+
if (hasChildrenInProgress.has(dir)) {
|
|
84
|
+
removePromise = Promise.resolve(hasChildrenInProgress.get(dir))
|
|
85
|
+
.then(() => doRemove(normalizedDir));
|
|
86
|
+
}
|
|
87
|
+
else if ((parentsInProgress = Array.from(parentDirs(dir)).filter(item => inProgress.has(item))).length > 0) {
|
|
88
|
+
return inProgress.get(parentsInProgress[0]);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
removePromise = doRemove(normalizedDir);
|
|
92
|
+
}
|
|
93
|
+
inProgress.set(normalizedDir, removePromise);
|
|
94
|
+
for (const parentDir of parentDirs(dir)) {
|
|
95
|
+
if (!hasChildrenInProgress.has(parentDir)) {
|
|
96
|
+
hasChildrenInProgress.set(parentDir, removePromise);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
hasChildrenInProgress.set(parentDir, Promise.all([removePromise, hasChildrenInProgress.get(parentDir)]));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return removePromise;
|
|
103
|
+
}
|
|
104
|
+
async function doRemove(normalizedDir) {
|
|
105
|
+
const logger = createLogger(pluginName);
|
|
106
|
+
try {
|
|
107
|
+
logger.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* LogLevel.info */ : 0 /* LogLevel.verbose */);
|
|
108
|
+
await fs.rm(normalizedDir, { recursive: true });
|
|
109
|
+
logger.finish(`cleaned '${normalizedDir}'`);
|
|
110
|
+
}
|
|
111
|
+
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
112
|
+
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* LogLevel.warn */;
|
|
113
|
+
logger.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function cleanup() {
|
|
117
|
+
inProgress.clear();
|
|
118
|
+
hasChildrenInProgress.clear();
|
|
119
|
+
deleted = deleteOnce;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function normalizeSlash(dir) {
|
|
123
|
+
if (dir.endsWith('/')) {
|
|
124
|
+
return `${dir.substring(0, dir.length - 1)}`;
|
|
125
|
+
}
|
|
126
|
+
return dir;
|
|
127
|
+
}
|
|
128
|
+
function* parentDirs(dir) {
|
|
129
|
+
while (((dir = path.dirname(dir)) !== '.') && (dir !== '/')) {
|
|
130
|
+
yield dir;
|
|
131
|
+
}
|
|
133
132
|
}
|
|
134
133
|
|
|
135
134
|
export { index as default };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
targets?: string | string[];
|
|
3
|
-
pluginName?: string;
|
|
4
|
-
deleteOnce?: boolean;
|
|
5
|
-
outputPlugin?: boolean;
|
|
6
|
-
verbose?: boolean;
|
|
7
|
-
} | string | string[];
|
|
1
|
+
export type CleanPluginOptions = {
|
|
2
|
+
targets?: string | string[];
|
|
3
|
+
pluginName?: string;
|
|
4
|
+
deleteOnce?: boolean;
|
|
5
|
+
outputPlugin?: boolean;
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
} | string | string[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.5",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@rollup-extras/plugin-clean",
|
|
5
5
|
"author": {
|
|
@@ -38,36 +38,21 @@
|
|
|
38
38
|
"clean",
|
|
39
39
|
"delete"
|
|
40
40
|
],
|
|
41
|
-
"scripts": {
|
|
42
|
-
"build": "pkgbld-internal",
|
|
43
|
-
"test": "jest --collectCoverage",
|
|
44
|
-
"lint": "eslint ./src",
|
|
45
|
-
"semantic-release": "npx semantic-release"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@semantic-release/changelog": "6.0.1",
|
|
49
|
-
"@semantic-release/commit-analyzer": "9.0.2",
|
|
50
|
-
"@semantic-release/git": "10.0.1",
|
|
51
|
-
"@semantic-release/npm": "9.0.1",
|
|
52
|
-
"@semantic-release/release-notes-generator": "10.0.3",
|
|
53
|
-
"@types/jest": "27.5.1",
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "5.24.0",
|
|
55
|
-
"@typescript-eslint/parser": "5.24.0",
|
|
56
|
-
"conventional-changelog-angular": "5.0.13",
|
|
57
|
-
"eslint": "8.15.0",
|
|
58
|
-
"jest": "28.1.0",
|
|
59
|
-
"semantic-release": "19.0.3",
|
|
60
|
-
"semantic-release-monorepo": "7.0.5",
|
|
61
|
-
"ts-jest": "28.0.2",
|
|
62
|
-
"typescript": "4.6.x",
|
|
63
|
-
"update-monorepo-package-json": "0.2.0",
|
|
64
|
-
"pkgbld-internal": "1.0.3"
|
|
65
|
-
},
|
|
66
41
|
"peerDependencies": {
|
|
67
42
|
"rollup": "^2.60.1 || ^3.0.0"
|
|
68
43
|
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"rollup": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
69
49
|
"dependencies": {
|
|
70
50
|
"@niceties/logger": "^1.1.4",
|
|
71
|
-
"@rollup-extras/utils": "^1.
|
|
51
|
+
"@rollup-extras/utils": "^1.4.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "pkgbld-internal",
|
|
55
|
+
"test": "jest --collectCoverage",
|
|
56
|
+
"lint": "eslint ./src"
|
|
72
57
|
}
|
|
73
|
-
}
|
|
58
|
+
}
|