js-build-tools 2.4.0 → 3.0.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/README.md +334 -205
- package/dist/build.js +59 -48
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +12 -13
- package/dist/bundle.min.js +1 -1
- package/dist/bundleLint.js +17 -18
- package/dist/bundleLint.min.js +1 -1
- package/dist/bundleMinify.js +8 -9
- package/dist/bundleMinify.min.js +1 -1
- package/dist/copyFonts.js +12 -0
- package/dist/copyFonts.min.js +1 -0
- package/dist/default.js +1 -1
- package/dist/default.min.js +1 -1
- package/dist/dist.js +7 -8
- package/dist/distLint.js +17 -18
- package/dist/distLint.min.js +1 -1
- package/dist/distMinify.js +8 -9
- package/dist/distMinify.min.js +1 -1
- package/dist/images.js +11 -0
- package/dist/images.min.js +1 -0
- package/dist/partials/addToReadme.js +13 -14
- package/dist/partials/beginWatcher.js +9 -10
- package/dist/partials/clean.js +10 -11
- package/dist/partials/copyFor.js +16 -0
- package/dist/partials/distFor.js +16 -17
- package/dist/partials/distForSrc.js +9 -10
- package/dist/partials/distSeries.js +19 -20
- package/dist/partials/imagesFor.js +34 -0
- package/dist/partials/minifyFor.js +15 -16
- package/dist/partials/readmeTemplate.js +11 -12
- package/dist/partials/removeDirectory.js +11 -12
- package/dist/partials/runOnChange.js +27 -27
- package/dist/partials/sassFor.js +20 -21
- package/dist/partials/tsFor.js +20 -21
- package/dist/partials.js +35 -31
- package/dist/partials.min.js +1 -1
- package/dist/test-helpers/setUp.js +52 -60
- package/dist/testFull.js +17 -18
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +10 -28
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +19 -20
- package/dist/testQuick.min.js +1 -1
- package/dist/typeScript.js +7 -8
- package/dist/utilities/dotGet.js +50 -0
- package/dist/utilities/dotNotate.js +77 -0
- package/dist/utilities/dotSet.js +44 -0
- package/dist/utilities/isObject.js +10 -0
- package/dist/utilities/strAfter.js +14 -0
- package/dist/utilities/strBefore.js +14 -0
- package/dist/watchFull.js +10 -11
- package/dist/watchTest.js +13 -14
- package/dist/watchTest.min.js +1 -1
- package/functions/build.js +15 -5
- package/functions/build.test.js +278 -42
- package/functions/bundle.js +3 -4
- package/functions/bundle.test.js +6 -6
- package/functions/bundleLint.js +2 -3
- package/functions/bundleLint.test.js +5 -5
- package/functions/bundleMinify.js +1 -2
- package/functions/bundleMinify.test.js +1 -1
- package/functions/copyFonts.js +11 -0
- package/functions/copyFonts.test.js +31 -0
- package/functions/default.js +1 -1
- package/functions/default.test.js +2 -2
- package/functions/dist.js +0 -1
- package/functions/dist.test.js +1 -1
- package/functions/distLint.js +2 -3
- package/functions/distLint.test.js +3 -3
- package/functions/distMinify.js +1 -2
- package/functions/distMinify.test.js +1 -1
- package/functions/images.js +10 -0
- package/functions/images.test.js +138 -0
- package/functions/partials/addToReadme.js +2 -3
- package/functions/partials/addToReadme.test.js +2 -2
- package/functions/partials/beginWatcher.js +1 -2
- package/functions/partials/beginWatcher.test.js +1 -1
- package/functions/partials/clean.js +0 -1
- package/functions/partials/copyFor.js +13 -0
- package/functions/partials/copyFor.test.js +34 -0
- package/functions/partials/distFor.js +1 -2
- package/functions/partials/distFor.test.js +4 -4
- package/functions/partials/distForSrc.js +3 -4
- package/functions/partials/distForSrc.test.js +6 -6
- package/functions/partials/distSeries.js +2 -3
- package/functions/partials/distSeries.test.js +5 -5
- package/functions/partials/imagesFor.js +33 -0
- package/functions/partials/imagesFor.test.js +143 -0
- package/functions/partials/minifyFor.js +0 -1
- package/functions/partials/minifyFor.test.js +1 -1
- package/functions/partials/readmeTemplate.js +3 -4
- package/functions/partials/readmeTemplate.test.js +2 -2
- package/functions/partials/removeDirectory.js +0 -1
- package/functions/partials/runOnChange.js +5 -6
- package/functions/partials/runOnChange.test.js +9 -9
- package/functions/partials/sassFor.js +1 -2
- package/functions/partials/sassFor.test.js +3 -3
- package/functions/partials/tsFor.js +3 -4
- package/functions/partials/tsFor.test.js +2 -2
- package/functions/partials.js +5 -1
- package/functions/partials.test.js +1 -1
- package/functions/sass.test.js +2 -2
- package/functions/test-helpers/setUp.js +24 -32
- package/functions/testFull.js +2 -3
- package/functions/testFull.test.js +1 -1
- package/functions/testHelpers.js +3 -20
- package/functions/testHelpers.test.js +1 -1
- package/functions/testQuick.js +1 -2
- package/functions/testQuick.test.js +1 -1
- package/functions/typeScript.js +0 -1
- package/functions/typeScript.test.js +0 -2
- package/functions/utilities/dotGet.js +47 -0
- package/functions/utilities/dotNotate.js +68 -0
- package/functions/utilities/dotSet.js +41 -0
- package/functions/utilities/isObject.js +9 -0
- package/functions/utilities/strAfter.js +13 -0
- package/functions/utilities/strBefore.js +13 -0
- package/functions/watchFull.js +0 -1
- package/functions/watchFull.test.js +1 -1
- package/functions/watchTest.js +1 -2
- package/functions/watchTest.test.js +1 -1
- package/gulp.config.js +153 -79
- package/gulpfile.base.js +5 -1
- package/jsdoc.base.js +1 -1
- package/package.json +13 -9
- package/vendor/array-union/index.js +31 -0
- package/vendor/easy-transform-stream/index.js +54 -0
- package/vendor/globby/gitignore.js +96 -0
- package/vendor/globby/index.js +191 -0
- package/vendor/globby/node_modules/slash/index.js +16 -0
- package/vendor/globby/stream-utils.js +58 -0
- package/vendor/globby/to-path.js +20 -0
- package/vendor/gulp-imagemin/index.js +128 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/index.js +265 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/utilities.js +36 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/ansi-styles/index.js +217 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/supports-color/index.js +154 -0
- package/vendor/gulp-plugin-extras/index.js +42 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/index.js +265 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/utilities.js +36 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/ansi-styles/index.js +217 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/supports-color/index.js +154 -0
- package/vendor/gulp-plugin-extras/plugin-error.js +145 -0
- package/vendor/ignore/index.js +468 -0
- package/vendor/imagemin/index.js +90 -0
- package/vendor/imagemin-gifsicle/index.js +33 -0
- package/vendor/imagemin-mozjpeg/index.js +100 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +260 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/command.js +47 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/error.js +102 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +123 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/promise.js +47 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stdio.js +50 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +124 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/core.js +238 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/main.js +89 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/realtime.js +24 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/signals.js +44 -0
- package/vendor/imagemin-mozjpeg/node_modules/is-stream/index.js +25 -0
- package/vendor/imagemin-mozjpeg/node_modules/mimic-fn/index.js +70 -0
- package/vendor/imagemin-mozjpeg/node_modules/npm-run-path/index.js +52 -0
- package/vendor/imagemin-mozjpeg/node_modules/onetime/index.js +43 -0
- package/vendor/imagemin-mozjpeg/node_modules/path-key/index.js +20 -0
- package/vendor/imagemin-mozjpeg/node_modules/strip-final-newline/index.js +17 -0
- package/vendor/imagemin-optipng/index.js +44 -0
- package/vendor/imagemin-svgo/index.js +27 -0
- package/vendor/is-jpg/index.js +12 -0
- package/vendor/junk/index.js +49 -0
- package/vendor/mozjpeg/index.js +9 -0
- package/vendor/mozjpeg/lib/index.js +18 -0
- package/vendor/mozjpeg/package.json +49 -0
- package/vendor/mozjpeg/vendor/cjpeg +0 -0
- package/vendor/mozjpeg/vendor/source/mozjpeg.tar.gz +0 -0
- package/vendor/p-pipe/index.js +22 -0
- package/vendor/plur/index.js +32 -0
- package/vendor/pretty-bytes/index.js +71 -0
- package/vendor/slash/index.js +12 -0
- package/dist/test-helpers/circularObject.js +0 -50
- package/dist/test-helpers/countMatches.js +0 -12
- package/dist/test-helpers/deepReferenceObject.js +0 -20
- package/dist/test-helpers/domItem.js +0 -33
- package/dist/test-helpers/jsonDom.js +0 -20
- package/dist/test-helpers/linkedList.js +0 -23
- package/dist/test-helpers/logObject.js +0 -21
- package/dist/test-helpers/multiReferenceObject.js +0 -20
- package/dist/test-helpers/nodeTree.js +0 -28
- package/functions/test-helpers/circularObject.js +0 -28
- package/functions/test-helpers/circularObject.test.js +0 -14
- package/functions/test-helpers/countMatches.js +0 -11
- package/functions/test-helpers/countMatches.test.js +0 -9
- package/functions/test-helpers/deepReferenceObject.js +0 -25
- package/functions/test-helpers/deepReferenceObject.test.js +0 -7
- package/functions/test-helpers/domItem.js +0 -31
- package/functions/test-helpers/domItem.test.js +0 -12
- package/functions/test-helpers/jsonDom.js +0 -16
- package/functions/test-helpers/jsonDom.test.js +0 -12
- package/functions/test-helpers/linkedList.js +0 -10
- package/functions/test-helpers/linkedList.test.js +0 -22
- package/functions/test-helpers/logObject.js +0 -18
- package/functions/test-helpers/logObject.test.js +0 -20
- package/functions/test-helpers/multiReferenceObject.js +0 -25
- package/functions/test-helpers/multiReferenceObject.test.js +0 -14
- package/functions/test-helpers/nodeTree.js +0 -11
- package/functions/test-helpers/nodeTree.test.js +0 -18
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createSupportsColor = createSupportsColor;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _nodeProcess = _interopRequireDefault(require("node:process"));
|
|
9
|
+
var _nodeOs = _interopRequireDefault(require("node:os"));
|
|
10
|
+
var _nodeTty = _interopRequireDefault(require("node:tty"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
|
|
13
|
+
/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
|
|
14
|
+
function hasFlag(flag) {
|
|
15
|
+
let argv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalThis.Deno ? globalThis.Deno.args : _nodeProcess.default.argv;
|
|
16
|
+
const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
|
|
17
|
+
const position = argv.indexOf(prefix + flag);
|
|
18
|
+
const terminatorPosition = argv.indexOf('--');
|
|
19
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
20
|
+
}
|
|
21
|
+
const {
|
|
22
|
+
env
|
|
23
|
+
} = _nodeProcess.default;
|
|
24
|
+
let flagForceColor;
|
|
25
|
+
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
|
|
26
|
+
flagForceColor = 0;
|
|
27
|
+
} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
|
|
28
|
+
flagForceColor = 1;
|
|
29
|
+
}
|
|
30
|
+
function envForceColor() {
|
|
31
|
+
if ('FORCE_COLOR' in env) {
|
|
32
|
+
if (env.FORCE_COLOR === 'true') {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
if (env.FORCE_COLOR === 'false') {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function translateLevel(level) {
|
|
42
|
+
if (level === 0) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
level,
|
|
47
|
+
hasBasic: true,
|
|
48
|
+
has256: level >= 2,
|
|
49
|
+
has16m: level >= 3
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function _supportsColor(haveStream) {
|
|
53
|
+
let {
|
|
54
|
+
streamIsTTY,
|
|
55
|
+
sniffFlags = true
|
|
56
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
57
|
+
const noFlagForceColor = envForceColor();
|
|
58
|
+
if (noFlagForceColor !== undefined) {
|
|
59
|
+
flagForceColor = noFlagForceColor;
|
|
60
|
+
}
|
|
61
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
62
|
+
if (forceColor === 0) {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
if (sniffFlags) {
|
|
66
|
+
if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
|
|
67
|
+
return 3;
|
|
68
|
+
}
|
|
69
|
+
if (hasFlag('color=256')) {
|
|
70
|
+
return 2;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Check for Azure DevOps pipelines.
|
|
75
|
+
// Has to be above the `!streamIsTTY` check.
|
|
76
|
+
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
const min = forceColor || 0;
|
|
83
|
+
if (env.TERM === 'dumb') {
|
|
84
|
+
return min;
|
|
85
|
+
}
|
|
86
|
+
if (_nodeProcess.default.platform === 'win32') {
|
|
87
|
+
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
88
|
+
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
89
|
+
const osRelease = _nodeOs.default.release().split('.');
|
|
90
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
91
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
92
|
+
}
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
if ('CI' in env) {
|
|
96
|
+
if ('GITHUB_ACTIONS' in env || 'GITEA_ACTIONS' in env) {
|
|
97
|
+
return 3;
|
|
98
|
+
}
|
|
99
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
return min;
|
|
103
|
+
}
|
|
104
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
105
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
106
|
+
}
|
|
107
|
+
if (env.COLORTERM === 'truecolor') {
|
|
108
|
+
return 3;
|
|
109
|
+
}
|
|
110
|
+
if (env.TERM === 'xterm-kitty') {
|
|
111
|
+
return 3;
|
|
112
|
+
}
|
|
113
|
+
if ('TERM_PROGRAM' in env) {
|
|
114
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
115
|
+
switch (env.TERM_PROGRAM) {
|
|
116
|
+
case 'iTerm.app':
|
|
117
|
+
{
|
|
118
|
+
return version >= 3 ? 3 : 2;
|
|
119
|
+
}
|
|
120
|
+
case 'Apple_Terminal':
|
|
121
|
+
{
|
|
122
|
+
return 2;
|
|
123
|
+
}
|
|
124
|
+
// No default
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
128
|
+
return 2;
|
|
129
|
+
}
|
|
130
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
131
|
+
return 1;
|
|
132
|
+
}
|
|
133
|
+
if ('COLORTERM' in env) {
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
return min;
|
|
137
|
+
}
|
|
138
|
+
function createSupportsColor(stream) {
|
|
139
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
140
|
+
const level = _supportsColor(stream, {
|
|
141
|
+
streamIsTTY: stream && stream.isTTY,
|
|
142
|
+
...options
|
|
143
|
+
});
|
|
144
|
+
return translateLevel(level);
|
|
145
|
+
}
|
|
146
|
+
const supportsColor = {
|
|
147
|
+
stdout: createSupportsColor({
|
|
148
|
+
isTTY: _nodeTty.default.isatty(1)
|
|
149
|
+
}),
|
|
150
|
+
stderr: createSupportsColor({
|
|
151
|
+
isTTY: _nodeTty.default.isatty(2)
|
|
152
|
+
})
|
|
153
|
+
};
|
|
154
|
+
var _default = exports.default = supportsColor;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
require("core-js/modules/esnext.async-iterator.filter.js");
|
|
8
|
+
require("core-js/modules/esnext.async-iterator.map.js");
|
|
9
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.filter.js");
|
|
11
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
12
|
+
require("core-js/modules/esnext.set.add-all.js");
|
|
13
|
+
require("core-js/modules/esnext.set.delete-all.js");
|
|
14
|
+
require("core-js/modules/esnext.set.difference.js");
|
|
15
|
+
require("core-js/modules/esnext.set.every.js");
|
|
16
|
+
require("core-js/modules/esnext.set.filter.js");
|
|
17
|
+
require("core-js/modules/esnext.set.find.js");
|
|
18
|
+
require("core-js/modules/esnext.set.intersection.js");
|
|
19
|
+
require("core-js/modules/esnext.set.is-disjoint-from.js");
|
|
20
|
+
require("core-js/modules/esnext.set.is-subset-of.js");
|
|
21
|
+
require("core-js/modules/esnext.set.is-superset-of.js");
|
|
22
|
+
require("core-js/modules/esnext.set.join.js");
|
|
23
|
+
require("core-js/modules/esnext.set.map.js");
|
|
24
|
+
require("core-js/modules/esnext.set.reduce.js");
|
|
25
|
+
require("core-js/modules/esnext.set.some.js");
|
|
26
|
+
require("core-js/modules/esnext.set.symmetric-difference.js");
|
|
27
|
+
require("core-js/modules/esnext.set.union.js");
|
|
28
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
29
|
+
var _index = _interopRequireDefault(require("./node_modules/chalk/source/index.js"));
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
+
/*
|
|
32
|
+
The MIT License (MIT)
|
|
33
|
+
|
|
34
|
+
Copyright (c) 2015, 2017-2018, 2022 Blaine Bublitz <blaine.bublitz@gmail.com> and Eric Schoffstall <yo@contra.io>
|
|
35
|
+
|
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
37
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
38
|
+
in the Software without restriction, including without limitation the rights
|
|
39
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
40
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
41
|
+
furnished to do so, subject to the following conditions:
|
|
42
|
+
|
|
43
|
+
The above copyright notice and this permission notice shall be included in all
|
|
44
|
+
copies or substantial portions of the Software.
|
|
45
|
+
|
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
47
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
48
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
49
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
50
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
51
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
52
|
+
SOFTWARE.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
// Adapted from https://github.com/gulpjs/plugin-error 2.0.1
|
|
56
|
+
|
|
57
|
+
const nonEnum = ['message', 'name', 'stack'];
|
|
58
|
+
const ignored = new Set([...nonEnum, '__safety', '_stack', 'plugin', 'showProperties', 'showStack', 'domain', 'domainEmitter', 'domainThrown']);
|
|
59
|
+
const props = ['fileName', 'lineNumber', 'message', 'name', 'plugin', 'showProperties', 'showStack', 'stack'];
|
|
60
|
+
class PluginError extends Error {
|
|
61
|
+
constructor(plugin, message, options) {
|
|
62
|
+
super();
|
|
63
|
+
const options_ = setDefaults(plugin, message, options);
|
|
64
|
+
Object.assign(this, options_);
|
|
65
|
+
if (typeof options_.error === 'object') {
|
|
66
|
+
this.message = options_.error.message;
|
|
67
|
+
this.stack = options_.error.stack;
|
|
68
|
+
this.cause = options_.error.cause;
|
|
69
|
+
Object.assign(this, options_.error);
|
|
70
|
+
}
|
|
71
|
+
for (const prop of props) {
|
|
72
|
+
if (prop in options_) {
|
|
73
|
+
this[prop] = options_[prop];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!this.stack) {
|
|
77
|
+
const safety = {
|
|
78
|
+
toString: this._messageWithDetails.bind(this) + '\nStack:'
|
|
79
|
+
};
|
|
80
|
+
Error.captureStackTrace(safety, this.constructor);
|
|
81
|
+
this.__safety = safety;
|
|
82
|
+
}
|
|
83
|
+
if (!this.plugin) {
|
|
84
|
+
throw new Error('Missing plugin name');
|
|
85
|
+
}
|
|
86
|
+
if (!this.message) {
|
|
87
|
+
throw new Error('Missing error message');
|
|
88
|
+
}
|
|
89
|
+
if (message instanceof Error && options_.error.isPresentable) {
|
|
90
|
+
this.showStack = false;
|
|
91
|
+
this.showProperties = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_messageWithDetails() {
|
|
95
|
+
let message_ = "Message:\n ".concat(this.message);
|
|
96
|
+
const details = this._messageDetails();
|
|
97
|
+
if (details) {
|
|
98
|
+
message_ += "\n".concat(details);
|
|
99
|
+
}
|
|
100
|
+
return message_;
|
|
101
|
+
}
|
|
102
|
+
_messageDetails() {
|
|
103
|
+
if (!this.showProperties) {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
const relevantProps = Object.keys(this).filter(key => !ignored.has(key));
|
|
107
|
+
return relevantProps.length > 0 ? "Details:\n".concat(relevantProps.map(prop => " ".concat(prop, ": ").concat(this[prop])).join('\n')) : '';
|
|
108
|
+
}
|
|
109
|
+
toString() {
|
|
110
|
+
const message_ = this.showStack ? this.__safety ? this.__safety.stack : this.stack : this._messageWithDetails();
|
|
111
|
+
return formatMessage(message_, this);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.default = PluginError;
|
|
115
|
+
function formatMessage(message, thisArg) {
|
|
116
|
+
return "".concat(_index.default.red(thisArg.name), " in plugin \"").concat(_index.default.cyan(thisArg.plugin), "\"\n").concat(message);
|
|
117
|
+
}
|
|
118
|
+
function setDefaults(plugin, message, options) {
|
|
119
|
+
if (typeof plugin === 'object') {
|
|
120
|
+
return {
|
|
121
|
+
...plugin
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (message instanceof Error) {
|
|
125
|
+
options = {
|
|
126
|
+
...options,
|
|
127
|
+
error: message
|
|
128
|
+
};
|
|
129
|
+
} else if (typeof message === 'object') {
|
|
130
|
+
options = {
|
|
131
|
+
...message
|
|
132
|
+
};
|
|
133
|
+
} else {
|
|
134
|
+
options = {
|
|
135
|
+
...options,
|
|
136
|
+
message
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
options.plugin = plugin;
|
|
140
|
+
return {
|
|
141
|
+
showStack: false,
|
|
142
|
+
showProperties: true,
|
|
143
|
+
...options
|
|
144
|
+
};
|
|
145
|
+
}
|