@rollup-extras/plugin-clean 1.3.0 → 1.3.1
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 +80 -13
- package/dist/index.mjs +76 -4
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -3,19 +3,86 @@
|
|
|
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');
|
|
7
|
-
var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
|
|
8
6
|
|
|
9
|
-
function
|
|
7
|
+
function getOptions(options, defaults, field, factory) {
|
|
8
|
+
const newOptions = recursiveArrayOptions(options, field);
|
|
9
|
+
return getOptionsObject((newOptions ? newOptions : options), defaults, factory);
|
|
10
|
+
}
|
|
11
|
+
function recursiveArrayOptions(options, field) {
|
|
12
|
+
if (typeof options === 'string') {
|
|
13
|
+
return { [field]: [options] };
|
|
14
|
+
}
|
|
15
|
+
else if (Array.isArray(options)) {
|
|
16
|
+
return { [field]: options };
|
|
17
|
+
}
|
|
18
|
+
else if (typeof options === 'object') {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
return field in options ? Object.assign(Object.assign({}, options), recursiveArrayOptions(options[field], field)) : options;
|
|
21
|
+
}
|
|
22
|
+
console.warn(`cannot process options: '${options}', reverting to defaults`);
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
function getOptionsObject(options, defaults, factory) {
|
|
26
|
+
const result = Object.assign(Object.assign({}, defaults), options);
|
|
27
|
+
if (factory) {
|
|
28
|
+
for (const [k, v] of Object.entries(factory)) {
|
|
29
|
+
result[k] = v(result, k);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
10
34
|
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
function multiConfigPluginBase(useWriteBundle, pluginName, execute, onFinalHook) {
|
|
36
|
+
const finalHook = useWriteBundle ? 'writeBundle' : 'generateBundle';
|
|
37
|
+
let remainingOutputsCount = 0, configsCount = 0;
|
|
38
|
+
const configs = new Set();
|
|
39
|
+
const instance = {
|
|
40
|
+
name: pluginName,
|
|
41
|
+
renderStart,
|
|
42
|
+
[finalHook]: writeBundle,
|
|
43
|
+
api: { addInstance }
|
|
44
|
+
};
|
|
45
|
+
return instance;
|
|
46
|
+
function addInstance() {
|
|
47
|
+
const configId = ++configsCount;
|
|
48
|
+
configs.add(configId);
|
|
49
|
+
return {
|
|
50
|
+
name: `${pluginName}#${configId}`,
|
|
51
|
+
renderStart: () => {
|
|
52
|
+
configs.delete(configId);
|
|
53
|
+
return renderStart();
|
|
54
|
+
},
|
|
55
|
+
[finalHook]: writeBundle
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function renderStart() {
|
|
59
|
+
++remainingOutputsCount;
|
|
60
|
+
}
|
|
61
|
+
async function writeBundle(options, bundle) {
|
|
62
|
+
--remainingOutputsCount;
|
|
63
|
+
if (onFinalHook) {
|
|
64
|
+
await onFinalHook.call(this, options, bundle, configs.size, remainingOutputsCount);
|
|
65
|
+
}
|
|
66
|
+
if (configs.size === 0 && remainingOutputsCount === 0) {
|
|
67
|
+
// do work
|
|
68
|
+
try {
|
|
69
|
+
await execute.call(this, options, bundle);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
// reset configs
|
|
73
|
+
for (let i = configsCount; i > 0; --i) {
|
|
74
|
+
configs.add(i);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
13
80
|
|
|
14
|
-
function index (options
|
|
81
|
+
function index (options = {}) {
|
|
15
82
|
const inProgress = new Map();
|
|
16
83
|
const hasChildrenInProgress = new Map();
|
|
17
84
|
let deleted = false;
|
|
18
|
-
const normalizedOptions =
|
|
85
|
+
const normalizedOptions = getOptions(options, {
|
|
19
86
|
pluginName: '@rollup-extras/plugin-clean',
|
|
20
87
|
deleteOnce: true,
|
|
21
88
|
verbose: false,
|
|
@@ -23,7 +90,7 @@ function index (options$1 = {}) {
|
|
|
23
90
|
}, 'targets');
|
|
24
91
|
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
25
92
|
let { targets } = normalizedOptions;
|
|
26
|
-
const instance =
|
|
93
|
+
const instance = multiConfigPluginBase(false, pluginName, cleanup);
|
|
27
94
|
const baseAddInstance = instance.api.addInstance;
|
|
28
95
|
const baseRenderStart = instance.renderStart;
|
|
29
96
|
if (outputPlugin) {
|
|
@@ -82,7 +149,7 @@ function index (options$1 = {}) {
|
|
|
82
149
|
}
|
|
83
150
|
}
|
|
84
151
|
async function removeDir(dir) {
|
|
85
|
-
const normalizedDir = normalizeSlash(
|
|
152
|
+
const normalizedDir = normalizeSlash(path.normalize(dir));
|
|
86
153
|
if (inProgress.has(normalizedDir)) {
|
|
87
154
|
return outputPlugin && inProgress.get(normalizedDir);
|
|
88
155
|
}
|
|
@@ -112,12 +179,12 @@ function index (options$1 = {}) {
|
|
|
112
179
|
async function doRemove(normalizedDir) {
|
|
113
180
|
const logger$1 = logger.createLogger(pluginName);
|
|
114
181
|
try {
|
|
115
|
-
logger$1.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* info */ : 0 /* verbose */);
|
|
116
|
-
await
|
|
182
|
+
logger$1.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* LogLevel.info */ : 0 /* LogLevel.verbose */);
|
|
183
|
+
await fs.rm(normalizedDir, { recursive: true });
|
|
117
184
|
logger$1.finish(`cleaned '${normalizedDir}'`);
|
|
118
185
|
}
|
|
119
186
|
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
120
|
-
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
|
|
187
|
+
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* LogLevel.warn */;
|
|
121
188
|
logger$1.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
122
189
|
}
|
|
123
190
|
}
|
|
@@ -134,7 +201,7 @@ function normalizeSlash(dir) {
|
|
|
134
201
|
return dir;
|
|
135
202
|
}
|
|
136
203
|
function* parentDirs(dir) {
|
|
137
|
-
while (((dir =
|
|
204
|
+
while (((dir = path.dirname(dir)) !== '.') && (dir !== '/')) {
|
|
138
205
|
yield dir;
|
|
139
206
|
}
|
|
140
207
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,80 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { createLogger } from '@niceties/logger';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
function getOptions(options, defaults, field, factory) {
|
|
6
|
+
const newOptions = recursiveArrayOptions(options, field);
|
|
7
|
+
return getOptionsObject((newOptions ? newOptions : options), defaults, factory);
|
|
8
|
+
}
|
|
9
|
+
function recursiveArrayOptions(options, field) {
|
|
10
|
+
if (typeof options === 'string') {
|
|
11
|
+
return { [field]: [options] };
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(options)) {
|
|
14
|
+
return { [field]: options };
|
|
15
|
+
}
|
|
16
|
+
else if (typeof options === 'object') {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
return field in options ? Object.assign(Object.assign({}, options), recursiveArrayOptions(options[field], field)) : options;
|
|
19
|
+
}
|
|
20
|
+
console.warn(`cannot process options: '${options}', reverting to defaults`);
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
function getOptionsObject(options, defaults, factory) {
|
|
24
|
+
const result = Object.assign(Object.assign({}, defaults), options);
|
|
25
|
+
if (factory) {
|
|
26
|
+
for (const [k, v] of Object.entries(factory)) {
|
|
27
|
+
result[k] = v(result, k);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function multiConfigPluginBase(useWriteBundle, pluginName, execute, onFinalHook) {
|
|
34
|
+
const finalHook = useWriteBundle ? 'writeBundle' : 'generateBundle';
|
|
35
|
+
let remainingOutputsCount = 0, configsCount = 0;
|
|
36
|
+
const configs = new Set();
|
|
37
|
+
const instance = {
|
|
38
|
+
name: pluginName,
|
|
39
|
+
renderStart,
|
|
40
|
+
[finalHook]: writeBundle,
|
|
41
|
+
api: { addInstance }
|
|
42
|
+
};
|
|
43
|
+
return instance;
|
|
44
|
+
function addInstance() {
|
|
45
|
+
const configId = ++configsCount;
|
|
46
|
+
configs.add(configId);
|
|
47
|
+
return {
|
|
48
|
+
name: `${pluginName}#${configId}`,
|
|
49
|
+
renderStart: () => {
|
|
50
|
+
configs.delete(configId);
|
|
51
|
+
return renderStart();
|
|
52
|
+
},
|
|
53
|
+
[finalHook]: writeBundle
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function renderStart() {
|
|
57
|
+
++remainingOutputsCount;
|
|
58
|
+
}
|
|
59
|
+
async function writeBundle(options, bundle) {
|
|
60
|
+
--remainingOutputsCount;
|
|
61
|
+
if (onFinalHook) {
|
|
62
|
+
await onFinalHook.call(this, options, bundle, configs.size, remainingOutputsCount);
|
|
63
|
+
}
|
|
64
|
+
if (configs.size === 0 && remainingOutputsCount === 0) {
|
|
65
|
+
// do work
|
|
66
|
+
try {
|
|
67
|
+
await execute.call(this, options, bundle);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
// reset configs
|
|
71
|
+
for (let i = configsCount; i > 0; --i) {
|
|
72
|
+
configs.add(i);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
6
78
|
|
|
7
79
|
function index (options = {}) {
|
|
8
80
|
const inProgress = new Map();
|
|
@@ -105,12 +177,12 @@ function index (options = {}) {
|
|
|
105
177
|
async function doRemove(normalizedDir) {
|
|
106
178
|
const logger = createLogger(pluginName);
|
|
107
179
|
try {
|
|
108
|
-
logger.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* info */ : 0 /* verbose */);
|
|
180
|
+
logger.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* LogLevel.info */ : 0 /* LogLevel.verbose */);
|
|
109
181
|
await fs.rm(normalizedDir, { recursive: true });
|
|
110
182
|
logger.finish(`cleaned '${normalizedDir}'`);
|
|
111
183
|
}
|
|
112
184
|
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
113
|
-
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
|
|
185
|
+
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* LogLevel.warn */;
|
|
114
186
|
logger.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
|
|
115
187
|
}
|
|
116
188
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@rollup-extras/plugin-clean",
|
|
5
5
|
"author": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"delete"
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "pkgbld",
|
|
41
|
+
"build": "pkgbld-internal",
|
|
42
42
|
"test": "jest --collectCoverage",
|
|
43
43
|
"lint": "eslint ./src",
|
|
44
44
|
"semantic-release": "npx semantic-release"
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"ts-jest": "28.0.2",
|
|
61
61
|
"typescript": "4.6.x",
|
|
62
62
|
"update-monorepo-package-json": "0.2.0",
|
|
63
|
-
"pkgbld": "1.2
|
|
63
|
+
"pkgbld-internal": "1.0.2"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"rollup": "^2.60.1 || ^3.0.0"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@niceties/logger": "^1.1.4",
|
|
70
|
-
"@rollup-extras/utils": "^1.3.
|
|
70
|
+
"@rollup-extras/utils": "^1.3.1"
|
|
71
71
|
}
|
|
72
72
|
}
|