@rollup-extras/plugin-clean 1.0.0
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 +21 -0
- package/README.md +37 -0
- package/dist/index.cjs +59 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +52 -0
- package/dist/types.d.ts +6 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Konstantin Shutkin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Plugin Clean
|
|
2
|
+
|
|
3
|
+
Rollup plugin to clean a directory during build.
|
|
4
|
+
|
|
5
|
+
Points:
|
|
6
|
+
|
|
7
|
+
- Uses fs.rm to remove directories that shipped with nodejs and has built-in retries
|
|
8
|
+
- Can be used with no configuration
|
|
9
|
+
- Runs once per directory by default (good for watch mode)
|
|
10
|
+
- Minimal amount of logs by default
|
|
11
|
+
|
|
12
|
+
No globs support, please use [rollup-plugin-delete](https://github.com/vladshcherbin/rollup-plugin-delete) for globs.
|
|
13
|
+
|
|
14
|
+
Plugin runs on `renderStart` per each output and uses output.dir as a default target.
|
|
15
|
+
|
|
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
|
+
|
|
18
|
+
## Configuration
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
export type CleanPluginOptions = {
|
|
22
|
+
targets?: string | string[], // defaulted to output.dir per output
|
|
23
|
+
pluginName?: string, // for debugging purposes, default is `@rollup-extras/plugin-clean`
|
|
24
|
+
runOnce?: boolean, // default true
|
|
25
|
+
verbose?: boolean // default false
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Prior Art
|
|
30
|
+
|
|
31
|
+
- https://github.com/vladshcherbin/rollup-plugin-delete
|
|
32
|
+
- https://github.com/saf33r/rollup-plugin-cleaner
|
|
33
|
+
- https://github.com/DongShelton/rollup-plugin-clear
|
|
34
|
+
|
|
35
|
+
# License
|
|
36
|
+
|
|
37
|
+
[MIT](./LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs/promises');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var logger = require('@niceties/logger');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
10
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
11
|
+
|
|
12
|
+
function index ({ targets, pluginName, runOnce, verbose } = {}) {
|
|
13
|
+
const deleted = new Set();
|
|
14
|
+
pluginName !== null && pluginName !== void 0 ? pluginName : (pluginName = '@rollup-extras/plugin-clean');
|
|
15
|
+
runOnce !== null && runOnce !== void 0 ? runOnce : (runOnce = true);
|
|
16
|
+
return {
|
|
17
|
+
name: pluginName,
|
|
18
|
+
async renderStart(options) {
|
|
19
|
+
if (!targets) {
|
|
20
|
+
if (options.dir) {
|
|
21
|
+
await removeDir(options.dir);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
if (Array.isArray(targets)) {
|
|
26
|
+
await Promise.all(targets.map(removeDir));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await removeDir(targets);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
async function removeDir(dir) {
|
|
35
|
+
const normalizedDir = normalizeSlash(path__default["default"].normalize(dir));
|
|
36
|
+
if (runOnce && deleted.has(normalizedDir)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
deleted.add(normalizedDir);
|
|
40
|
+
const logger$1 = logger.createLogger(pluginName);
|
|
41
|
+
try {
|
|
42
|
+
logger$1.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* info */ : 0 /* verbose */);
|
|
43
|
+
await fs__default["default"].rm(normalizedDir, { recursive: true });
|
|
44
|
+
logger$1.finish(`cleaned '${normalizedDir}'`);
|
|
45
|
+
}
|
|
46
|
+
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
|
|
48
|
+
logger$1.finish(`failed cleaning '${normalizedDir}'\n${e.stack}`, loglevel);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function normalizeSlash(dir) {
|
|
53
|
+
if (dir.endsWith('/')) {
|
|
54
|
+
return `${dir.substring(0, dir.length - 1)}`;
|
|
55
|
+
}
|
|
56
|
+
return dir;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = index;
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { createLogger } from '@niceties/logger';
|
|
4
|
+
|
|
5
|
+
function index ({ targets, pluginName, runOnce, verbose } = {}) {
|
|
6
|
+
const deleted = new Set();
|
|
7
|
+
pluginName !== null && pluginName !== void 0 ? pluginName : (pluginName = '@rollup-extras/plugin-clean');
|
|
8
|
+
runOnce !== null && runOnce !== void 0 ? runOnce : (runOnce = true);
|
|
9
|
+
return {
|
|
10
|
+
name: pluginName,
|
|
11
|
+
async renderStart(options) {
|
|
12
|
+
if (!targets) {
|
|
13
|
+
if (options.dir) {
|
|
14
|
+
await removeDir(options.dir);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
if (Array.isArray(targets)) {
|
|
19
|
+
await Promise.all(targets.map(removeDir));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
await removeDir(targets);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
async function removeDir(dir) {
|
|
28
|
+
const normalizedDir = normalizeSlash(path.normalize(dir));
|
|
29
|
+
if (runOnce && deleted.has(normalizedDir)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
deleted.add(normalizedDir);
|
|
33
|
+
const logger = createLogger(pluginName);
|
|
34
|
+
try {
|
|
35
|
+
logger.start(`cleaning '${normalizedDir}'`, verbose ? 1 /* info */ : 0 /* verbose */);
|
|
36
|
+
await fs.rm(normalizedDir, { recursive: true });
|
|
37
|
+
logger.finish(`cleaned '${normalizedDir}'`);
|
|
38
|
+
}
|
|
39
|
+
catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
40
|
+
const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
|
|
41
|
+
logger.finish(`failed cleaning '${normalizedDir}'\n${e.stack}`, loglevel);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function normalizeSlash(dir) {
|
|
46
|
+
if (dir.endsWith('/')) {
|
|
47
|
+
return `${dir.substring(0, dir.length - 1)}`;
|
|
48
|
+
}
|
|
49
|
+
return dir;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { index as default };
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"name": "@rollup-extras/plugin-clean",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Konstantin Shutkin"
|
|
7
|
+
},
|
|
8
|
+
"funding": "https://www.donationalerts.com/r/excitingcode",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
|
+
"module": "./dist/index.mjs",
|
|
18
|
+
"typings": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=15"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/kshutkin/rollup-extras.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/kshutkin/rollup-extras/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/kshutkin/rollup-extras/plugin-clean/README.md",
|
|
33
|
+
"keywords": [
|
|
34
|
+
"rollup-plugin"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "rimraf ./dist && rollup -c",
|
|
38
|
+
"dev": "rimraf ./dist && rollup -c -w",
|
|
39
|
+
"test": "jest --collectCoverage",
|
|
40
|
+
"lint": "eslint ./src",
|
|
41
|
+
"semantic-release": "npx semantic-release"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@rollup/plugin-commonjs": "21.0.1",
|
|
45
|
+
"@rollup/plugin-node-resolve": "13.0.6",
|
|
46
|
+
"@semantic-release/changelog": "6.0.1",
|
|
47
|
+
"@semantic-release/commit-analyzer": "9.0.1",
|
|
48
|
+
"@semantic-release/git": "10.0.1",
|
|
49
|
+
"@semantic-release/npm": "8.0.2",
|
|
50
|
+
"@semantic-release/release-notes-generator": "10.0.2",
|
|
51
|
+
"@types/jest": "27.0.2",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "5.3.0",
|
|
53
|
+
"@typescript-eslint/parser": "5.3.0",
|
|
54
|
+
"conventional-changelog-angular": "5.0.13",
|
|
55
|
+
"eslint": "8.1.0",
|
|
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
|
+
"semantic-release": "18.0.0",
|
|
65
|
+
"semantic-release-monorepo": "7.0.5",
|
|
66
|
+
"ts-jest": "27.0.7",
|
|
67
|
+
"typescript": "4.4.x",
|
|
68
|
+
"update-monorepo-package-json": "0.1.6"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"rollup": "^2.60.2"
|
|
72
|
+
},
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"@niceties/logger": "1.0.4"
|
|
75
|
+
},
|
|
76
|
+
"readme": "ERROR: No README data found!"
|
|
77
|
+
}
|