@rollup-extras/plugin-clean 1.1.1 → 1.2.2
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/dist/index.cjs +68 -12
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +68 -12
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var fs = require('fs/promises');
|
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var logger = require('@niceties/logger');
|
|
6
6
|
var options = require('@rollup-extras/utils/options');
|
|
7
|
+
var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
|
|
7
8
|
|
|
8
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
10
|
|
|
@@ -11,7 +12,9 @@ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
|
11
12
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
12
13
|
|
|
13
14
|
function index (options$1 = {}) {
|
|
14
|
-
const
|
|
15
|
+
const inProgress = new Map();
|
|
16
|
+
const hasChildrenInProgress = new Map();
|
|
17
|
+
let deleted = false;
|
|
15
18
|
const normalizedOptions = options.getOptions(options$1, {
|
|
16
19
|
pluginName: '@rollup-extras/plugin-clean',
|
|
17
20
|
deleteOnce: true,
|
|
@@ -20,17 +23,35 @@ function index (options$1 = {}) {
|
|
|
20
23
|
}, 'targets');
|
|
21
24
|
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
22
25
|
let { targets } = normalizedOptions;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
const instance = mutliConfigPluginBase.multiConfigPluginBase(false, pluginName, cleanup);
|
|
27
|
+
const baseAddInstance = instance.api.addInstance;
|
|
28
|
+
const baseRenderStart = instance.renderStart;
|
|
26
29
|
if (outputPlugin) {
|
|
27
|
-
|
|
30
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
31
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
32
|
+
await renderStart(options);
|
|
33
|
+
};
|
|
28
34
|
}
|
|
29
35
|
else {
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
instance.buildStart = buildStart;
|
|
37
|
+
instance.options = optionsHook;
|
|
32
38
|
}
|
|
33
|
-
|
|
39
|
+
instance.api.addInstance = () => {
|
|
40
|
+
const instance = baseAddInstance();
|
|
41
|
+
const baseRenderStart = instance.renderStart;
|
|
42
|
+
if (outputPlugin) {
|
|
43
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
44
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
45
|
+
await renderStart(options);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
instance.buildStart = buildStart;
|
|
50
|
+
instance.options = optionsHook;
|
|
51
|
+
}
|
|
52
|
+
return instance;
|
|
53
|
+
};
|
|
54
|
+
return instance;
|
|
34
55
|
async function optionsHook(config) {
|
|
35
56
|
var _a;
|
|
36
57
|
if (!targets && config) {
|
|
@@ -40,11 +61,17 @@ function index (options$1 = {}) {
|
|
|
40
61
|
return null;
|
|
41
62
|
}
|
|
42
63
|
async function buildStart() {
|
|
64
|
+
if (deleted) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
43
67
|
if (targets) {
|
|
44
68
|
await Promise.all(targets.map(removeDir));
|
|
45
69
|
}
|
|
46
70
|
}
|
|
47
71
|
async function renderStart(options) {
|
|
72
|
+
if (deleted) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
48
75
|
if (!targets) {
|
|
49
76
|
if (options.dir) {
|
|
50
77
|
await removeDir(options.dir);
|
|
@@ -56,11 +83,30 @@ function index (options$1 = {}) {
|
|
|
56
83
|
}
|
|
57
84
|
async function removeDir(dir) {
|
|
58
85
|
const normalizedDir = normalizeSlash(path__default["default"].normalize(dir));
|
|
59
|
-
if (
|
|
60
|
-
return outputPlugin &&
|
|
86
|
+
if (inProgress.has(normalizedDir)) {
|
|
87
|
+
return outputPlugin && inProgress.get(normalizedDir);
|
|
88
|
+
}
|
|
89
|
+
let removePromise;
|
|
90
|
+
let parentsInProgress;
|
|
91
|
+
if (hasChildrenInProgress.has(dir)) {
|
|
92
|
+
removePromise = Promise.resolve(hasChildrenInProgress.get(dir))
|
|
93
|
+
.then(() => doRemove(normalizedDir));
|
|
94
|
+
}
|
|
95
|
+
else if ((parentsInProgress = Array.from(parentDirs(dir)).filter(item => inProgress.has(item))).length > 0) {
|
|
96
|
+
return inProgress.get(parentsInProgress[0]);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
removePromise = doRemove(normalizedDir);
|
|
100
|
+
}
|
|
101
|
+
inProgress.set(normalizedDir, removePromise);
|
|
102
|
+
for (const parentDir of parentDirs(dir)) {
|
|
103
|
+
if (!hasChildrenInProgress.has(parentDir)) {
|
|
104
|
+
hasChildrenInProgress.set(parentDir, removePromise);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
hasChildrenInProgress.set(parentDir, Promise.all([removePromise, hasChildrenInProgress.get(parentDir)]));
|
|
108
|
+
}
|
|
61
109
|
}
|
|
62
|
-
const removePromise = doRemove(normalizedDir);
|
|
63
|
-
deleted.set(normalizedDir, removePromise);
|
|
64
110
|
return removePromise;
|
|
65
111
|
}
|
|
66
112
|
async function doRemove(normalizedDir) {
|
|
@@ -75,12 +121,22 @@ function index (options$1 = {}) {
|
|
|
75
121
|
logger$1.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
76
122
|
}
|
|
77
123
|
}
|
|
124
|
+
function cleanup() {
|
|
125
|
+
inProgress.clear();
|
|
126
|
+
hasChildrenInProgress.clear();
|
|
127
|
+
deleted = deleteOnce;
|
|
128
|
+
}
|
|
78
129
|
}
|
|
79
130
|
function normalizeSlash(dir) {
|
|
80
131
|
if (dir.endsWith('/')) {
|
|
81
132
|
return `${dir.substring(0, dir.length - 1)}`;
|
|
82
133
|
}
|
|
83
134
|
return dir;
|
|
135
|
+
}
|
|
136
|
+
function* parentDirs(dir) {
|
|
137
|
+
while (((dir = path__default["default"].dirname(dir)) !== '.') && (dir !== '/')) {
|
|
138
|
+
yield dir;
|
|
139
|
+
}
|
|
84
140
|
}
|
|
85
141
|
|
|
86
142
|
module.exports = index;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { PluginHooks } from 'rollup';
|
|
2
2
|
import { CleanPluginOptions } from './types';
|
|
3
|
-
export default function (options?: CleanPluginOptions): Partial<PluginHooks
|
|
3
|
+
export default function (options?: CleanPluginOptions): Partial<PluginHooks> & {
|
|
4
|
+
api: {
|
|
5
|
+
addInstance(): void;
|
|
6
|
+
};
|
|
7
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,12 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { createLogger } from '@niceties/logger';
|
|
4
4
|
import { getOptions } from '@rollup-extras/utils/options';
|
|
5
|
+
import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
|
|
5
6
|
|
|
6
7
|
function index (options = {}) {
|
|
7
|
-
const
|
|
8
|
+
const inProgress = new Map();
|
|
9
|
+
const hasChildrenInProgress = new Map();
|
|
10
|
+
let deleted = false;
|
|
8
11
|
const normalizedOptions = getOptions(options, {
|
|
9
12
|
pluginName: '@rollup-extras/plugin-clean',
|
|
10
13
|
deleteOnce: true,
|
|
@@ -13,17 +16,35 @@ function index (options = {}) {
|
|
|
13
16
|
}, 'targets');
|
|
14
17
|
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
15
18
|
let { targets } = normalizedOptions;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const instance = multiConfigPluginBase(false, pluginName, cleanup);
|
|
20
|
+
const baseAddInstance = instance.api.addInstance;
|
|
21
|
+
const baseRenderStart = instance.renderStart;
|
|
19
22
|
if (outputPlugin) {
|
|
20
|
-
|
|
23
|
+
instance.renderStart = async function (options, inputOptions) {
|
|
24
|
+
baseRenderStart.call(this, options, inputOptions);
|
|
25
|
+
await renderStart(options);
|
|
26
|
+
};
|
|
21
27
|
}
|
|
22
28
|
else {
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
instance.buildStart = buildStart;
|
|
30
|
+
instance.options = optionsHook;
|
|
25
31
|
}
|
|
26
|
-
|
|
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;
|
|
27
48
|
async function optionsHook(config) {
|
|
28
49
|
var _a;
|
|
29
50
|
if (!targets && config) {
|
|
@@ -33,11 +54,17 @@ function index (options = {}) {
|
|
|
33
54
|
return null;
|
|
34
55
|
}
|
|
35
56
|
async function buildStart() {
|
|
57
|
+
if (deleted) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
36
60
|
if (targets) {
|
|
37
61
|
await Promise.all(targets.map(removeDir));
|
|
38
62
|
}
|
|
39
63
|
}
|
|
40
64
|
async function renderStart(options) {
|
|
65
|
+
if (deleted) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
41
68
|
if (!targets) {
|
|
42
69
|
if (options.dir) {
|
|
43
70
|
await removeDir(options.dir);
|
|
@@ -49,11 +76,30 @@ function index (options = {}) {
|
|
|
49
76
|
}
|
|
50
77
|
async function removeDir(dir) {
|
|
51
78
|
const normalizedDir = normalizeSlash(path.normalize(dir));
|
|
52
|
-
if (
|
|
53
|
-
return outputPlugin &&
|
|
79
|
+
if (inProgress.has(normalizedDir)) {
|
|
80
|
+
return outputPlugin && inProgress.get(normalizedDir);
|
|
81
|
+
}
|
|
82
|
+
let removePromise;
|
|
83
|
+
let parentsInProgress;
|
|
84
|
+
if (hasChildrenInProgress.has(dir)) {
|
|
85
|
+
removePromise = Promise.resolve(hasChildrenInProgress.get(dir))
|
|
86
|
+
.then(() => doRemove(normalizedDir));
|
|
87
|
+
}
|
|
88
|
+
else if ((parentsInProgress = Array.from(parentDirs(dir)).filter(item => inProgress.has(item))).length > 0) {
|
|
89
|
+
return inProgress.get(parentsInProgress[0]);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
removePromise = doRemove(normalizedDir);
|
|
93
|
+
}
|
|
94
|
+
inProgress.set(normalizedDir, removePromise);
|
|
95
|
+
for (const parentDir of parentDirs(dir)) {
|
|
96
|
+
if (!hasChildrenInProgress.has(parentDir)) {
|
|
97
|
+
hasChildrenInProgress.set(parentDir, removePromise);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
hasChildrenInProgress.set(parentDir, Promise.all([removePromise, hasChildrenInProgress.get(parentDir)]));
|
|
101
|
+
}
|
|
54
102
|
}
|
|
55
|
-
const removePromise = doRemove(normalizedDir);
|
|
56
|
-
deleted.set(normalizedDir, removePromise);
|
|
57
103
|
return removePromise;
|
|
58
104
|
}
|
|
59
105
|
async function doRemove(normalizedDir) {
|
|
@@ -68,12 +114,22 @@ function index (options = {}) {
|
|
|
68
114
|
logger.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
69
115
|
}
|
|
70
116
|
}
|
|
117
|
+
function cleanup() {
|
|
118
|
+
inProgress.clear();
|
|
119
|
+
hasChildrenInProgress.clear();
|
|
120
|
+
deleted = deleteOnce;
|
|
121
|
+
}
|
|
71
122
|
}
|
|
72
123
|
function normalizeSlash(dir) {
|
|
73
124
|
if (dir.endsWith('/')) {
|
|
74
125
|
return `${dir.substring(0, dir.length - 1)}`;
|
|
75
126
|
}
|
|
76
127
|
return dir;
|
|
128
|
+
}
|
|
129
|
+
function* parentDirs(dir) {
|
|
130
|
+
while (((dir = path.dirname(dir)) !== '.') && (dir !== '/')) {
|
|
131
|
+
yield dir;
|
|
132
|
+
}
|
|
77
133
|
}
|
|
78
134
|
|
|
79
135
|
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.2.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@rollup-extras/plugin-clean",
|
|
5
5
|
"author": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/kshutkin/rollup-extras/issues"
|
|
31
31
|
},
|
|
32
|
-
"homepage": "https://github.com/kshutkin/rollup-extras/plugin-clean/README.md",
|
|
32
|
+
"homepage": "https://github.com/kshutkin/rollup-extras/blob/main/plugin-clean/README.md",
|
|
33
33
|
"readme": "README.md",
|
|
34
34
|
"description": "Rollup plugin to clean a directory during build.",
|
|
35
35
|
"keywords": [
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"rollup": "^2.60.1"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@niceties/logger": "^1.1.
|
|
70
|
-
"@rollup-extras/utils": "^1.2.
|
|
69
|
+
"@niceties/logger": "^1.1.3",
|
|
70
|
+
"@rollup-extras/utils": "^1.2.1"
|
|
71
71
|
}
|
|
72
72
|
}
|