@rollup-extras/plugin-clean 1.3.1 → 1.3.3
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 +5 -77
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +2 -74
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -3,86 +3,14 @@
|
|
|
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');
|
|
6
8
|
|
|
7
|
-
function
|
|
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
|
-
}
|
|
34
|
-
|
|
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
|
-
}
|
|
80
|
-
|
|
81
|
-
function index (options = {}) {
|
|
9
|
+
function index (options$1 = {}) {
|
|
82
10
|
const inProgress = new Map();
|
|
83
11
|
const hasChildrenInProgress = new Map();
|
|
84
12
|
let deleted = false;
|
|
85
|
-
const normalizedOptions = getOptions(options, {
|
|
13
|
+
const normalizedOptions = options.getOptions(options$1, {
|
|
86
14
|
pluginName: '@rollup-extras/plugin-clean',
|
|
87
15
|
deleteOnce: true,
|
|
88
16
|
verbose: false,
|
|
@@ -90,7 +18,7 @@ function index (options = {}) {
|
|
|
90
18
|
}, 'targets');
|
|
91
19
|
const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
|
|
92
20
|
let { targets } = normalizedOptions;
|
|
93
|
-
const instance = multiConfigPluginBase(false, pluginName, cleanup);
|
|
21
|
+
const instance = mutliConfigPluginBase.multiConfigPluginBase(false, pluginName, cleanup);
|
|
94
22
|
const baseAddInstance = instance.api.addInstance;
|
|
95
23
|
const baseRenderStart = instance.renderStart;
|
|
96
24
|
if (outputPlugin) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Plugin } from 'rollup';
|
|
2
2
|
import { CleanPluginOptions } from './types';
|
|
3
|
-
export default function (options?: CleanPluginOptions):
|
|
3
|
+
export default function (options?: CleanPluginOptions): Plugin & {
|
|
4
4
|
api: {
|
|
5
|
-
addInstance():
|
|
5
|
+
addInstance(): Plugin;
|
|
6
6
|
};
|
|
7
7
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,80 +1,8 @@
|
|
|
1
1
|
import fs from 'fs/promises';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { createLogger } from '@niceties/logger';
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
4
|
+
import { getOptions } from '@rollup-extras/utils/options';
|
|
5
|
+
import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
|
|
78
6
|
|
|
79
7
|
function index (options = {}) {
|
|
80
8
|
const inProgress = new Map();
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.3",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@rollup-extras/plugin-clean",
|
|
5
5
|
"author": {
|
|
@@ -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-internal": "1.0.
|
|
63
|
+
"pkgbld-internal": "1.0.3"
|
|
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.3"
|
|
71
71
|
}
|
|
72
72
|
}
|