@rollup-extras/plugin-clean 1.0.2 → 1.1.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.
Files changed (3) hide show
  1. package/dist/index.cjs +12 -29
  2. package/dist/index.mjs +11 -28
  3. package/package.json +24 -29
package/dist/index.cjs CHANGED
@@ -3,17 +3,23 @@
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');
6
7
 
7
8
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
9
 
9
10
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
10
11
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
11
12
 
12
- function index (options = {}) {
13
+ function index (options$1 = {}) {
13
14
  const deleted = new Map();
14
- const normailizedOptions = normalizeOptions(options);
15
- const { pluginName, deleteOnce, verbose, outputPlugin } = normailizedOptions;
16
- let { targets } = normailizedOptions;
15
+ const normalizedOptions = options.getOptions(options$1, {
16
+ pluginName: '@rollup-extras/plugin-clean',
17
+ deleteOnce: true,
18
+ verbose: false,
19
+ outputPlugin: true
20
+ }, 'targets');
21
+ const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
22
+ let { targets } = normalizedOptions;
17
23
  const pluginInstance = {
18
24
  name: pluginName
19
25
  };
@@ -51,7 +57,7 @@ function index (options = {}) {
51
57
  async function removeDir(dir) {
52
58
  const normalizedDir = normalizeSlash(path__default["default"].normalize(dir));
53
59
  if (deleteOnce && deleted.has(normalizedDir)) {
54
- return deleted.get(normalizedDir);
60
+ return outputPlugin && deleted.get(normalizedDir);
55
61
  }
56
62
  const removePromise = doRemove(normalizedDir);
57
63
  deleted.set(normalizedDir, removePromise);
@@ -66,7 +72,7 @@ function index (options = {}) {
66
72
  }
67
73
  catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
68
74
  const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
69
- logger$1.finish(`failed cleaning '${normalizedDir}'\n${e.stack}`, loglevel);
75
+ logger$1.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
70
76
  }
71
77
  }
72
78
  }
@@ -75,29 +81,6 @@ function normalizeSlash(dir) {
75
81
  return `${dir.substring(0, dir.length - 1)}`;
76
82
  }
77
83
  return dir;
78
- }
79
- function normalizeOptions(userOptions) {
80
- var _a, _b, _c, _d;
81
- const options = {
82
- pluginName: (_a = userOptions.pluginName) !== null && _a !== void 0 ? _a : '@rollup-extras/plugin-clean',
83
- deleteOnce: (_b = userOptions.deleteOnce) !== null && _b !== void 0 ? _b : true,
84
- verbose: (_c = userOptions.verbose) !== null && _c !== void 0 ? _c : false,
85
- outputPlugin: (_d = userOptions.outputPlugin) !== null && _d !== void 0 ? _d : true,
86
- targets: getTargets(userOptions)
87
- };
88
- return options;
89
- }
90
- function getTargets(userOptions) {
91
- if (typeof userOptions === 'string') {
92
- return [userOptions];
93
- }
94
- if (Array.isArray(userOptions)) {
95
- return userOptions;
96
- }
97
- if (typeof userOptions === 'object') {
98
- return 'targets' in userOptions ? getTargets(userOptions.targets) : undefined;
99
- }
100
- return [];
101
84
  }
102
85
 
103
86
  module.exports = index;
package/dist/index.mjs CHANGED
@@ -1,12 +1,18 @@
1
1
  import fs from 'fs/promises';
2
2
  import path from 'path';
3
3
  import { createLogger } from '@niceties/logger';
4
+ import { getOptions } from '@rollup-extras/utils/options';
4
5
 
5
6
  function index (options = {}) {
6
7
  const deleted = new Map();
7
- const normailizedOptions = normalizeOptions(options);
8
- const { pluginName, deleteOnce, verbose, outputPlugin } = normailizedOptions;
9
- let { targets } = normailizedOptions;
8
+ const normalizedOptions = getOptions(options, {
9
+ pluginName: '@rollup-extras/plugin-clean',
10
+ deleteOnce: true,
11
+ verbose: false,
12
+ outputPlugin: true
13
+ }, 'targets');
14
+ const { pluginName, deleteOnce, verbose, outputPlugin } = normalizedOptions;
15
+ let { targets } = normalizedOptions;
10
16
  const pluginInstance = {
11
17
  name: pluginName
12
18
  };
@@ -44,7 +50,7 @@ function index (options = {}) {
44
50
  async function removeDir(dir) {
45
51
  const normalizedDir = normalizeSlash(path.normalize(dir));
46
52
  if (deleteOnce && deleted.has(normalizedDir)) {
47
- return deleted.get(normalizedDir);
53
+ return outputPlugin && deleted.get(normalizedDir);
48
54
  }
49
55
  const removePromise = doRemove(normalizedDir);
50
56
  deleted.set(normalizedDir, removePromise);
@@ -59,7 +65,7 @@ function index (options = {}) {
59
65
  }
60
66
  catch (e) { // eslint-disable-line @typescript-eslint/no-explicit-any
61
67
  const loglevel = e['code'] === 'ENOENT' ? undefined : 2 /* warn */;
62
- logger.finish(`failed cleaning '${normalizedDir}'\n${e.stack}`, loglevel);
68
+ logger.finish(`failed cleaning '${normalizedDir}'`, loglevel, e);
63
69
  }
64
70
  }
65
71
  }
@@ -68,29 +74,6 @@ function normalizeSlash(dir) {
68
74
  return `${dir.substring(0, dir.length - 1)}`;
69
75
  }
70
76
  return dir;
71
- }
72
- function normalizeOptions(userOptions) {
73
- var _a, _b, _c, _d;
74
- const options = {
75
- pluginName: (_a = userOptions.pluginName) !== null && _a !== void 0 ? _a : '@rollup-extras/plugin-clean',
76
- deleteOnce: (_b = userOptions.deleteOnce) !== null && _b !== void 0 ? _b : true,
77
- verbose: (_c = userOptions.verbose) !== null && _c !== void 0 ? _c : false,
78
- outputPlugin: (_d = userOptions.outputPlugin) !== null && _d !== void 0 ? _d : true,
79
- targets: getTargets(userOptions)
80
- };
81
- return options;
82
- }
83
- function getTargets(userOptions) {
84
- if (typeof userOptions === 'string') {
85
- return [userOptions];
86
- }
87
- if (Array.isArray(userOptions)) {
88
- return userOptions;
89
- }
90
- if (typeof userOptions === 'object') {
91
- return 'targets' in userOptions ? getTargets(userOptions.targets) : undefined;
92
- }
93
- return [];
94
77
  }
95
78
 
96
79
  export { index as default };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.2",
2
+ "version": "1.1.1",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-clean",
5
5
  "author": {
@@ -30,48 +30,43 @@
30
30
  "url": "https://github.com/kshutkin/rollup-extras/issues"
31
31
  },
32
32
  "homepage": "https://github.com/kshutkin/rollup-extras/plugin-clean/README.md",
33
+ "readme": "README.md",
34
+ "description": "Rollup plugin to clean a directory during build.",
33
35
  "keywords": [
34
- "rollup-plugin"
36
+ "rollup-plugin",
37
+ "clean",
38
+ "delete"
35
39
  ],
36
40
  "scripts": {
37
- "build": "rimraf ./dist && rollup -c",
38
- "dev": "rimraf ./dist && rollup -c -w",
41
+ "build": "pkgbld",
39
42
  "test": "jest --collectCoverage",
40
43
  "lint": "eslint ./src",
41
44
  "semantic-release": "npx semantic-release"
42
45
  },
43
46
  "devDependencies": {
44
- "@rollup/plugin-commonjs": "21.0.1",
45
- "@rollup/plugin-node-resolve": "13.0.6",
46
47
  "@semantic-release/changelog": "6.0.1",
47
- "@semantic-release/commit-analyzer": "9.0.1",
48
+ "@semantic-release/commit-analyzer": "9.0.2",
48
49
  "@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",
50
+ "@semantic-release/npm": "8.0.3",
51
+ "@semantic-release/release-notes-generator": "10.0.3",
52
+ "@types/jest": "27.0.3",
53
+ "@typescript-eslint/eslint-plugin": "5.8.1",
54
+ "@typescript-eslint/parser": "5.8.1",
54
55
  "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",
56
+ "eslint": "8.5.0",
57
+ "jest": "27.4.5",
58
+ "semantic-release": "18.0.1",
65
59
  "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"
60
+ "ts-jest": "27.1.2",
61
+ "typescript": "4.5.x",
62
+ "update-monorepo-package-json": "0.2.0",
63
+ "pkgbld": "1.1.3"
69
64
  },
70
65
  "peerDependencies": {
71
- "rollup": "^2.60.2"
66
+ "rollup": "^2.60.1"
72
67
  },
73
68
  "dependencies": {
74
- "@niceties/logger": "^1.0.4"
75
- },
76
- "readme": "ERROR: No README data found!"
69
+ "@niceties/logger": "^1.1.0",
70
+ "@rollup-extras/utils": "^1.2.0"
71
+ }
77
72
  }