js-build-tools 2.3.1 → 3.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.
Files changed (199) hide show
  1. package/README.md +334 -205
  2. package/dist/build.js +16 -5
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +12 -13
  5. package/dist/bundle.min.js +1 -1
  6. package/dist/bundleLint.js +17 -18
  7. package/dist/bundleLint.min.js +1 -1
  8. package/dist/bundleMinify.js +8 -9
  9. package/dist/bundleMinify.min.js +1 -1
  10. package/dist/copyFonts.js +12 -0
  11. package/dist/copyFonts.min.js +1 -0
  12. package/dist/default.js +15 -15
  13. package/dist/default.min.js +1 -1
  14. package/dist/dist.js +0 -1
  15. package/dist/distLint.js +17 -18
  16. package/dist/distLint.min.js +1 -1
  17. package/dist/distMinify.js +8 -9
  18. package/dist/distMinify.min.js +1 -1
  19. package/dist/images.js +11 -0
  20. package/dist/images.min.js +1 -0
  21. package/dist/partials/addToReadme.js +13 -14
  22. package/dist/partials/beginWatcher.js +9 -10
  23. package/dist/partials/clean.js +0 -1
  24. package/dist/partials/copyFor.js +16 -0
  25. package/dist/partials/distFor.js +16 -17
  26. package/dist/partials/distForSrc.js +9 -10
  27. package/dist/partials/distSeries.js +19 -20
  28. package/dist/partials/imagesFor.js +34 -0
  29. package/dist/partials/minifyFor.js +0 -1
  30. package/dist/partials/readmeTemplate.js +11 -12
  31. package/dist/partials/removeDirectory.js +5 -6
  32. package/dist/partials/runOnChange.js +27 -27
  33. package/dist/partials/sassFor.js +2 -3
  34. package/dist/partials/tsFor.js +20 -21
  35. package/dist/partials.js +5 -1
  36. package/dist/partials.min.js +1 -1
  37. package/dist/sass.js +7 -7
  38. package/dist/test-helpers/setUp.js +31 -39
  39. package/dist/testFull.js +17 -18
  40. package/dist/testFull.min.js +1 -1
  41. package/dist/testHelpers.js +10 -28
  42. package/dist/testHelpers.min.js +1 -1
  43. package/dist/testQuick.js +19 -20
  44. package/dist/testQuick.min.js +1 -1
  45. package/dist/typeScript.js +0 -1
  46. package/dist/utilities/dotGet.js +50 -0
  47. package/dist/utilities/dotNotate.js +77 -0
  48. package/dist/utilities/dotSet.js +44 -0
  49. package/dist/utilities/isObject.js +10 -0
  50. package/dist/watchFull.js +0 -1
  51. package/dist/watchTest.js +13 -14
  52. package/dist/watchTest.min.js +1 -1
  53. package/functions/build.js +15 -5
  54. package/functions/build.test.js +278 -42
  55. package/functions/bundle.js +3 -4
  56. package/functions/bundle.test.js +6 -6
  57. package/functions/bundleLint.js +2 -3
  58. package/functions/bundleLint.test.js +5 -5
  59. package/functions/bundleMinify.js +1 -2
  60. package/functions/bundleMinify.test.js +1 -1
  61. package/functions/copyFonts.js +11 -0
  62. package/functions/copyFonts.test.js +31 -0
  63. package/functions/default.js +1 -1
  64. package/functions/default.test.js +2 -2
  65. package/functions/dist.js +0 -1
  66. package/functions/dist.test.js +1 -1
  67. package/functions/distLint.js +2 -3
  68. package/functions/distLint.test.js +3 -3
  69. package/functions/distMinify.js +1 -2
  70. package/functions/distMinify.test.js +1 -1
  71. package/functions/images.js +10 -0
  72. package/functions/images.test.js +138 -0
  73. package/functions/partials/addToReadme.js +2 -3
  74. package/functions/partials/addToReadme.test.js +2 -2
  75. package/functions/partials/beginWatcher.js +1 -2
  76. package/functions/partials/beginWatcher.test.js +1 -1
  77. package/functions/partials/clean.js +0 -1
  78. package/functions/partials/copyFor.js +13 -0
  79. package/functions/partials/copyFor.test.js +34 -0
  80. package/functions/partials/distFor.js +1 -2
  81. package/functions/partials/distFor.test.js +4 -4
  82. package/functions/partials/distForSrc.js +3 -4
  83. package/functions/partials/distForSrc.test.js +6 -6
  84. package/functions/partials/distSeries.js +2 -3
  85. package/functions/partials/distSeries.test.js +5 -5
  86. package/functions/partials/imagesFor.js +33 -0
  87. package/functions/partials/imagesFor.test.js +143 -0
  88. package/functions/partials/minifyFor.js +0 -1
  89. package/functions/partials/minifyFor.test.js +1 -1
  90. package/functions/partials/readmeTemplate.js +3 -4
  91. package/functions/partials/readmeTemplate.test.js +2 -2
  92. package/functions/partials/removeDirectory.js +22 -23
  93. package/functions/partials/runOnChange.js +5 -6
  94. package/functions/partials/runOnChange.test.js +9 -9
  95. package/functions/partials/sassFor.js +1 -2
  96. package/functions/partials/sassFor.test.js +3 -3
  97. package/functions/partials/tsFor.js +3 -4
  98. package/functions/partials/tsFor.test.js +2 -2
  99. package/functions/partials.js +5 -1
  100. package/functions/partials.test.js +1 -1
  101. package/functions/sass.test.js +2 -2
  102. package/functions/test-helpers/setUp.js +24 -32
  103. package/functions/testFull.js +2 -3
  104. package/functions/testFull.test.js +1 -1
  105. package/functions/testHelpers.js +3 -20
  106. package/functions/testHelpers.test.js +1 -1
  107. package/functions/testQuick.js +1 -2
  108. package/functions/testQuick.test.js +1 -1
  109. package/functions/typeScript.js +0 -1
  110. package/functions/typeScript.test.js +0 -2
  111. package/functions/utilities/dotGet.js +47 -0
  112. package/functions/utilities/dotNotate.js +68 -0
  113. package/functions/utilities/dotSet.js +41 -0
  114. package/functions/utilities/isObject.js +9 -0
  115. package/functions/watchFull.js +0 -1
  116. package/functions/watchFull.test.js +1 -1
  117. package/functions/watchTest.js +1 -2
  118. package/functions/watchTest.test.js +1 -1
  119. package/gulp.config.js +153 -79
  120. package/gulpfile.base.js +5 -1
  121. package/jsdoc.base.js +1 -1
  122. package/package.json +13 -9
  123. package/vendor/array-union/index.js +31 -0
  124. package/vendor/easy-transform-stream/index.js +58 -0
  125. package/vendor/globby/gitignore.js +100 -0
  126. package/vendor/globby/index.js +195 -0
  127. package/vendor/globby/node_modules/slash/index.js +16 -0
  128. package/vendor/globby/stream-utils.js +58 -0
  129. package/vendor/globby/to-path.js +20 -0
  130. package/vendor/gulp-imagemin/index.js +128 -0
  131. package/vendor/gulp-imagemin/node_modules/chalk/source/index.js +265 -0
  132. package/vendor/gulp-imagemin/node_modules/chalk/source/utilities.js +36 -0
  133. package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/ansi-styles/index.js +217 -0
  134. package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/supports-color/index.js +154 -0
  135. package/vendor/gulp-plugin-extras/index.js +46 -0
  136. package/vendor/gulp-plugin-extras/node_modules/chalk/source/index.js +265 -0
  137. package/vendor/gulp-plugin-extras/node_modules/chalk/source/utilities.js +36 -0
  138. package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/ansi-styles/index.js +217 -0
  139. package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/supports-color/index.js +154 -0
  140. package/vendor/gulp-plugin-extras/plugin-error.js +145 -0
  141. package/vendor/ignore/index.js +468 -0
  142. package/vendor/imagemin/index.js +94 -0
  143. package/vendor/imagemin-gifsicle/index.js +37 -0
  144. package/vendor/imagemin-mozjpeg/index.js +104 -0
  145. package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +264 -0
  146. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/command.js +47 -0
  147. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/error.js +102 -0
  148. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +123 -0
  149. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/promise.js +47 -0
  150. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stdio.js +50 -0
  151. package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +128 -0
  152. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/core.js +238 -0
  153. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/main.js +89 -0
  154. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/realtime.js +24 -0
  155. package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/signals.js +44 -0
  156. package/vendor/imagemin-mozjpeg/node_modules/is-stream/index.js +25 -0
  157. package/vendor/imagemin-mozjpeg/node_modules/mimic-fn/index.js +70 -0
  158. package/vendor/imagemin-mozjpeg/node_modules/npm-run-path/index.js +52 -0
  159. package/vendor/imagemin-mozjpeg/node_modules/onetime/index.js +43 -0
  160. package/vendor/imagemin-mozjpeg/node_modules/path-key/index.js +20 -0
  161. package/vendor/imagemin-mozjpeg/node_modules/strip-final-newline/index.js +17 -0
  162. package/vendor/imagemin-optipng/index.js +44 -0
  163. package/vendor/imagemin-svgo/index.js +27 -0
  164. package/vendor/is-jpg/index.js +12 -0
  165. package/vendor/junk/index.js +49 -0
  166. package/vendor/mozjpeg/index.js +9 -0
  167. package/vendor/mozjpeg/lib/index.js +18 -0
  168. package/vendor/mozjpeg/package.json +50 -0
  169. package/vendor/p-pipe/index.js +26 -0
  170. package/vendor/plur/index.js +32 -0
  171. package/vendor/pretty-bytes/index.js +71 -0
  172. package/vendor/slash/index.js +12 -0
  173. package/dist/test-helpers/circularObject.js +0 -50
  174. package/dist/test-helpers/countMatches.js +0 -12
  175. package/dist/test-helpers/deepReferenceObject.js +0 -20
  176. package/dist/test-helpers/domItem.js +0 -33
  177. package/dist/test-helpers/jsonDom.js +0 -20
  178. package/dist/test-helpers/linkedList.js +0 -23
  179. package/dist/test-helpers/logObject.js +0 -21
  180. package/dist/test-helpers/multiReferenceObject.js +0 -20
  181. package/dist/test-helpers/nodeTree.js +0 -28
  182. package/functions/test-helpers/circularObject.js +0 -28
  183. package/functions/test-helpers/circularObject.test.js +0 -14
  184. package/functions/test-helpers/countMatches.js +0 -11
  185. package/functions/test-helpers/countMatches.test.js +0 -9
  186. package/functions/test-helpers/deepReferenceObject.js +0 -25
  187. package/functions/test-helpers/deepReferenceObject.test.js +0 -7
  188. package/functions/test-helpers/domItem.js +0 -31
  189. package/functions/test-helpers/domItem.test.js +0 -12
  190. package/functions/test-helpers/jsonDom.js +0 -16
  191. package/functions/test-helpers/jsonDom.test.js +0 -12
  192. package/functions/test-helpers/linkedList.js +0 -10
  193. package/functions/test-helpers/linkedList.test.js +0 -22
  194. package/functions/test-helpers/logObject.js +0 -18
  195. package/functions/test-helpers/logObject.test.js +0 -20
  196. package/functions/test-helpers/multiReferenceObject.js +0 -25
  197. package/functions/test-helpers/multiReferenceObject.test.js +0 -14
  198. package/functions/test-helpers/nodeTree.js +0 -11
  199. package/functions/test-helpers/nodeTree.test.js +0 -18
@@ -0,0 +1,104 @@
1
+ async function exportImageminMozjpeg () {
2
+ "use strict";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _nodeBuffer = require("node:buffer");
9
+ var _index = require("./node_modules/execa/index.js");
10
+ var _index2 = _interopRequireDefault(require("../is-jpg/index.js"));
11
+ var _index3 = _interopRequireDefault(require("../mozjpeg/index.js"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ const imageminMozjpeg = options => async buffer => {
14
+ options = {
15
+ trellis: true,
16
+ trellisDC: true,
17
+ overshoot: true,
18
+ ...options
19
+ };
20
+ if (!_nodeBuffer.Buffer.isBuffer(buffer)) {
21
+ return Promise.reject(new TypeError('Expected a buffer'));
22
+ }
23
+ if (!(0, _index2.default)(buffer)) {
24
+ return Promise.resolve(buffer);
25
+ }
26
+
27
+ // TODO: Remove these sometime far in the future
28
+ if (options.fastcrush) {
29
+ return Promise.reject(new Error('Option `fastcrush` was renamed to `fastCrush`'));
30
+ }
31
+ if (options.maxmemory) {
32
+ return Promise.reject(new Error('Option `maxmemory` was renamed to `maxMemory`'));
33
+ }
34
+ if (options.notrellis) {
35
+ return Promise.reject(new Error('Option `notrellis` was renamed to `trellis` and inverted'));
36
+ }
37
+ if (options.noovershoot) {
38
+ return Promise.reject(new Error('Option `noovershoot` was renamed to `overshoot` and inverted'));
39
+ }
40
+ const args = [];
41
+ if (typeof options.quality !== 'undefined') {
42
+ args.push('-quality', options.quality);
43
+ }
44
+ if (options.progressive === false) {
45
+ args.push('-baseline');
46
+ }
47
+ if (options.targa) {
48
+ args.push('-targa');
49
+ }
50
+ if (options.revert) {
51
+ args.push('-revert');
52
+ }
53
+ if (options.fastCrush) {
54
+ args.push('-fastcrush');
55
+ }
56
+ if (typeof options.dcScanOpt !== 'undefined') {
57
+ args.push('-dc-scan-opt', options.dcScanOpt);
58
+ }
59
+ if (!options.trellis) {
60
+ args.push('-notrellis');
61
+ }
62
+ if (!options.trellisDC) {
63
+ args.push('-notrellis-dc');
64
+ }
65
+ if (options.tune) {
66
+ args.push("-tune-".concat(options.tune));
67
+ }
68
+ if (!options.overshoot) {
69
+ args.push('-noovershoot');
70
+ }
71
+ if (options.arithmetic) {
72
+ args.push('-arithmetic');
73
+ }
74
+ if (options.dct) {
75
+ args.push('-dct', options.dct);
76
+ }
77
+ if (options.quantBaseline) {
78
+ args.push('-quant-baseline', options.quantBaseline);
79
+ }
80
+ if (typeof options.quantTable !== 'undefined') {
81
+ args.push('-quant-table', options.quantTable);
82
+ }
83
+ if (options.smooth) {
84
+ args.push('-smooth', options.smooth);
85
+ }
86
+ if (options.maxMemory) {
87
+ args.push('-maxmemory', options.maxMemory);
88
+ }
89
+ if (options.sample) {
90
+ args.push('-sample', options.sample.join(','));
91
+ }
92
+ const {
93
+ stdout
94
+ } = await (0, _index.execa)(_index3.default, args, {
95
+ encoding: null,
96
+ input: buffer,
97
+ maxBuffer: Number.POSITIVE_INFINITY
98
+ });
99
+ return stdout;
100
+ };
101
+ var _default = exports.default = imageminMozjpeg;
102
+ }
103
+
104
+ exportImageminMozjpeg()
@@ -0,0 +1,264 @@
1
+ async function exportExeca () {
2
+ "use strict";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.execa = execa;
8
+ exports.execaCommand = execaCommand;
9
+ exports.execaCommandSync = execaCommandSync;
10
+ exports.execaNode = execaNode;
11
+ exports.execaSync = execaSync;
12
+ require("core-js/modules/esnext.async-iterator.filter.js");
13
+ require("core-js/modules/esnext.iterator.constructor.js");
14
+ require("core-js/modules/esnext.iterator.filter.js");
15
+ require("core-js/modules/web.dom-collections.iterator.js");
16
+ var _nodeBuffer = require("node:buffer");
17
+ var _nodePath = _interopRequireDefault(require("node:path"));
18
+ var _nodeChild_process = _interopRequireDefault(require("node:child_process"));
19
+ var _nodeProcess = _interopRequireDefault(require("node:process"));
20
+ var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
21
+ var _index = _interopRequireDefault(require("../strip-final-newline/index.js"));
22
+ var _index2 = require("../npm-run-path/index.js");
23
+ var _index3 = _interopRequireDefault(require("../onetime/index.js"));
24
+ var _error = require("./lib/error.js");
25
+ var _stdio = require("./lib/stdio.js");
26
+ var _kill = require("./lib/kill.js");
27
+ var _stream = require("./lib/stream.js");
28
+ var _promise = require("./lib/promise.js");
29
+ var _command = require("./lib/command.js");
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+ const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
32
+ const getEnv = _ref => {
33
+ let {
34
+ env: envOption,
35
+ extendEnv,
36
+ preferLocal,
37
+ localDir,
38
+ execPath
39
+ } = _ref;
40
+ const env = extendEnv ? {
41
+ ..._nodeProcess.default.env,
42
+ ...envOption
43
+ } : envOption;
44
+ if (preferLocal) {
45
+ return (0, _index2.npmRunPathEnv)({
46
+ env,
47
+ cwd: localDir,
48
+ execPath
49
+ });
50
+ }
51
+ return env;
52
+ };
53
+ const handleArguments = function (file, args) {
54
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
55
+ const parsed = _crossSpawn.default._parse(file, args, options);
56
+ file = parsed.command;
57
+ args = parsed.args;
58
+ options = parsed.options;
59
+ options = {
60
+ maxBuffer: DEFAULT_MAX_BUFFER,
61
+ buffer: true,
62
+ stripFinalNewline: true,
63
+ extendEnv: true,
64
+ preferLocal: false,
65
+ localDir: options.cwd || _nodeProcess.default.cwd(),
66
+ execPath: _nodeProcess.default.execPath,
67
+ encoding: 'utf8',
68
+ reject: true,
69
+ cleanup: true,
70
+ all: false,
71
+ windowsHide: true,
72
+ ...options
73
+ };
74
+ options.env = getEnv(options);
75
+ options.stdio = (0, _stdio.normalizeStdio)(options);
76
+ if (_nodeProcess.default.platform === 'win32' && _nodePath.default.basename(file, '.exe') === 'cmd') {
77
+ // #116
78
+ args.unshift('/q');
79
+ }
80
+ return {
81
+ file,
82
+ args,
83
+ options,
84
+ parsed
85
+ };
86
+ };
87
+ const handleOutput = (options, value, error) => {
88
+ if (typeof value !== 'string' && !_nodeBuffer.Buffer.isBuffer(value)) {
89
+ // When `execaSync()` errors, we normalize it to '' to mimic `execa()`
90
+ return error === undefined ? undefined : '';
91
+ }
92
+ if (options.stripFinalNewline) {
93
+ return (0, _index.default)(value);
94
+ }
95
+ return value;
96
+ };
97
+ function execa(file, args, options) {
98
+ const parsed = handleArguments(file, args, options);
99
+ const command = (0, _command.joinCommand)(file, args);
100
+ const escapedCommand = (0, _command.getEscapedCommand)(file, args);
101
+ (0, _kill.validateTimeout)(parsed.options);
102
+ let spawned;
103
+ try {
104
+ spawned = _nodeChild_process.default.spawn(parsed.file, parsed.args, parsed.options);
105
+ } catch (error) {
106
+ // Ensure the returned error is always both a promise and a child process
107
+ const dummySpawned = new _nodeChild_process.default.ChildProcess();
108
+ const errorPromise = Promise.reject((0, _error.makeError)({
109
+ error,
110
+ stdout: '',
111
+ stderr: '',
112
+ all: '',
113
+ command,
114
+ escapedCommand,
115
+ parsed,
116
+ timedOut: false,
117
+ isCanceled: false,
118
+ killed: false
119
+ }));
120
+ return (0, _promise.mergePromise)(dummySpawned, errorPromise);
121
+ }
122
+ const spawnedPromise = (0, _promise.getSpawnedPromise)(spawned);
123
+ const timedPromise = (0, _kill.setupTimeout)(spawned, parsed.options, spawnedPromise);
124
+ const processDone = (0, _kill.setExitHandler)(spawned, parsed.options, timedPromise);
125
+ const context = {
126
+ isCanceled: false
127
+ };
128
+ spawned.kill = _kill.spawnedKill.bind(null, spawned.kill.bind(spawned));
129
+ spawned.cancel = _kill.spawnedCancel.bind(null, spawned, context);
130
+ const handlePromise = async () => {
131
+ const [{
132
+ error,
133
+ exitCode,
134
+ signal,
135
+ timedOut
136
+ }, stdoutResult, stderrResult, allResult] = await (0, _stream.getSpawnedResult)(spawned, parsed.options, processDone);
137
+ const stdout = handleOutput(parsed.options, stdoutResult);
138
+ const stderr = handleOutput(parsed.options, stderrResult);
139
+ const all = handleOutput(parsed.options, allResult);
140
+ if (error || exitCode !== 0 || signal !== null) {
141
+ const returnedError = (0, _error.makeError)({
142
+ error,
143
+ exitCode,
144
+ signal,
145
+ stdout,
146
+ stderr,
147
+ all,
148
+ command,
149
+ escapedCommand,
150
+ parsed,
151
+ timedOut,
152
+ isCanceled: context.isCanceled || (parsed.options.signal ? parsed.options.signal.aborted : false),
153
+ killed: spawned.killed
154
+ });
155
+ if (!parsed.options.reject) {
156
+ return returnedError;
157
+ }
158
+ throw returnedError;
159
+ }
160
+ return {
161
+ command,
162
+ escapedCommand,
163
+ exitCode: 0,
164
+ stdout,
165
+ stderr,
166
+ all,
167
+ failed: false,
168
+ timedOut: false,
169
+ isCanceled: false,
170
+ killed: false
171
+ };
172
+ };
173
+ const handlePromiseOnce = (0, _index3.default)(handlePromise);
174
+ (0, _stream.handleInput)(spawned, parsed.options.input);
175
+ spawned.all = (0, _stream.makeAllStream)(spawned, parsed.options);
176
+ return (0, _promise.mergePromise)(spawned, handlePromiseOnce);
177
+ }
178
+ function execaSync(file, args, options) {
179
+ const parsed = handleArguments(file, args, options);
180
+ const command = (0, _command.joinCommand)(file, args);
181
+ const escapedCommand = (0, _command.getEscapedCommand)(file, args);
182
+ (0, _stream.validateInputSync)(parsed.options);
183
+ let result;
184
+ try {
185
+ result = _nodeChild_process.default.spawnSync(parsed.file, parsed.args, parsed.options);
186
+ } catch (error) {
187
+ throw (0, _error.makeError)({
188
+ error,
189
+ stdout: '',
190
+ stderr: '',
191
+ all: '',
192
+ command,
193
+ escapedCommand,
194
+ parsed,
195
+ timedOut: false,
196
+ isCanceled: false,
197
+ killed: false
198
+ });
199
+ }
200
+ const stdout = handleOutput(parsed.options, result.stdout, result.error);
201
+ const stderr = handleOutput(parsed.options, result.stderr, result.error);
202
+ if (result.error || result.status !== 0 || result.signal !== null) {
203
+ const error = (0, _error.makeError)({
204
+ stdout,
205
+ stderr,
206
+ error: result.error,
207
+ signal: result.signal,
208
+ exitCode: result.status,
209
+ command,
210
+ escapedCommand,
211
+ parsed,
212
+ timedOut: result.error && result.error.code === 'ETIMEDOUT',
213
+ isCanceled: false,
214
+ killed: result.signal !== null
215
+ });
216
+ if (!parsed.options.reject) {
217
+ return error;
218
+ }
219
+ throw error;
220
+ }
221
+ return {
222
+ command,
223
+ escapedCommand,
224
+ exitCode: 0,
225
+ stdout,
226
+ stderr,
227
+ failed: false,
228
+ timedOut: false,
229
+ isCanceled: false,
230
+ killed: false
231
+ };
232
+ }
233
+ function execaCommand(command, options) {
234
+ const [file, ...args] = (0, _command.parseCommand)(command);
235
+ return execa(file, args, options);
236
+ }
237
+ function execaCommandSync(command, options) {
238
+ const [file, ...args] = (0, _command.parseCommand)(command);
239
+ return execaSync(file, args, options);
240
+ }
241
+ function execaNode(scriptPath, args) {
242
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
243
+ if (args && !Array.isArray(args) && typeof args === 'object') {
244
+ options = args;
245
+ args = [];
246
+ }
247
+ const stdio = (0, _stdio.normalizeStdioNode)(options);
248
+ const defaultExecArgv = _nodeProcess.default.execArgv.filter(arg => !arg.startsWith('--inspect'));
249
+ const {
250
+ nodePath = _nodeProcess.default.execPath,
251
+ nodeOptions = defaultExecArgv
252
+ } = options;
253
+ return execa(nodePath, [...nodeOptions, scriptPath, ...(Array.isArray(args) ? args : [])], {
254
+ ...options,
255
+ stdin: undefined,
256
+ stdout: undefined,
257
+ stderr: undefined,
258
+ stdio,
259
+ shell: false
260
+ });
261
+ }
262
+ }
263
+
264
+ exportExeca()
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseCommand = exports.joinCommand = exports.getEscapedCommand = void 0;
7
+ require("core-js/modules/es.string.replace.js");
8
+ require("core-js/modules/esnext.async-iterator.map.js");
9
+ require("core-js/modules/esnext.iterator.map.js");
10
+ require("core-js/modules/web.dom-collections.iterator.js");
11
+ const normalizeArgs = function (file) {
12
+ let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
13
+ if (!Array.isArray(args)) {
14
+ return [file];
15
+ }
16
+ return [file, ...args];
17
+ };
18
+ const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
19
+ const DOUBLE_QUOTES_REGEXP = /"/g;
20
+ const escapeArg = arg => {
21
+ if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
22
+ return arg;
23
+ }
24
+ return "\"".concat(arg.replace(DOUBLE_QUOTES_REGEXP, '\\"'), "\"");
25
+ };
26
+ const joinCommand = (file, args) => normalizeArgs(file, args).join(' ');
27
+ exports.joinCommand = joinCommand;
28
+ const getEscapedCommand = (file, args) => normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' ');
29
+ exports.getEscapedCommand = getEscapedCommand;
30
+ const SPACES_REGEXP = / +/g;
31
+
32
+ // Handle `execaCommand()`
33
+ const parseCommand = command => {
34
+ const tokens = [];
35
+ for (const token of command.trim().split(SPACES_REGEXP)) {
36
+ // Allow spaces to be escaped by a backslash if not meant as a delimiter
37
+ const previousToken = tokens[tokens.length - 1];
38
+ if (previousToken && previousToken.endsWith('\\')) {
39
+ // Merge previous token with current one
40
+ tokens[tokens.length - 1] = "".concat(previousToken.slice(0, -1), " ").concat(token);
41
+ } else {
42
+ tokens.push(token);
43
+ }
44
+ }
45
+ return tokens;
46
+ };
47
+ exports.parseCommand = parseCommand;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.makeError = void 0;
7
+ require("core-js/modules/esnext.async-iterator.filter.js");
8
+ require("core-js/modules/esnext.iterator.constructor.js");
9
+ require("core-js/modules/esnext.iterator.filter.js");
10
+ var _main = require("../../human-signals/build/src/main.js");
11
+ const getErrorPrefix = _ref => {
12
+ let {
13
+ timedOut,
14
+ timeout,
15
+ errorCode,
16
+ signal,
17
+ signalDescription,
18
+ exitCode,
19
+ isCanceled
20
+ } = _ref;
21
+ if (timedOut) {
22
+ return "timed out after ".concat(timeout, " milliseconds");
23
+ }
24
+ if (isCanceled) {
25
+ return 'was canceled';
26
+ }
27
+ if (errorCode !== undefined) {
28
+ return "failed with ".concat(errorCode);
29
+ }
30
+ if (signal !== undefined) {
31
+ return "was killed with ".concat(signal, " (").concat(signalDescription, ")");
32
+ }
33
+ if (exitCode !== undefined) {
34
+ return "failed with exit code ".concat(exitCode);
35
+ }
36
+ return 'failed';
37
+ };
38
+ const makeError = _ref2 => {
39
+ let {
40
+ stdout,
41
+ stderr,
42
+ all,
43
+ error,
44
+ signal,
45
+ exitCode,
46
+ command,
47
+ escapedCommand,
48
+ timedOut,
49
+ isCanceled,
50
+ killed,
51
+ parsed: {
52
+ options: {
53
+ timeout
54
+ }
55
+ }
56
+ } = _ref2;
57
+ // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
58
+ // We normalize them to `undefined`
59
+ exitCode = exitCode === null ? undefined : exitCode;
60
+ signal = signal === null ? undefined : signal;
61
+ const signalDescription = signal === undefined ? undefined : _main.signalsByName[signal].description;
62
+ const errorCode = error && error.code;
63
+ const prefix = getErrorPrefix({
64
+ timedOut,
65
+ timeout,
66
+ errorCode,
67
+ signal,
68
+ signalDescription,
69
+ exitCode,
70
+ isCanceled
71
+ });
72
+ const execaMessage = "Command ".concat(prefix, ": ").concat(command);
73
+ const isError = Object.prototype.toString.call(error) === '[object Error]';
74
+ const shortMessage = isError ? "".concat(execaMessage, "\n").concat(error.message) : execaMessage;
75
+ const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');
76
+ if (isError) {
77
+ error.originalMessage = error.message;
78
+ error.message = message;
79
+ } else {
80
+ error = new Error(message);
81
+ }
82
+ error.shortMessage = shortMessage;
83
+ error.command = command;
84
+ error.escapedCommand = escapedCommand;
85
+ error.exitCode = exitCode;
86
+ error.signal = signal;
87
+ error.signalDescription = signalDescription;
88
+ error.stdout = stdout;
89
+ error.stderr = stderr;
90
+ if (all !== undefined) {
91
+ error.all = all;
92
+ }
93
+ if ('bufferedData' in error) {
94
+ delete error.bufferedData;
95
+ }
96
+ error.failed = true;
97
+ error.timedOut = Boolean(timedOut);
98
+ error.isCanceled = isCanceled;
99
+ error.killed = killed && !timedOut;
100
+ return error;
101
+ };
102
+ exports.makeError = makeError;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateTimeout = exports.spawnedKill = exports.spawnedCancel = exports.setupTimeout = exports.setExitHandler = void 0;
7
+ require("core-js/modules/es.promise.finally.js");
8
+ require("core-js/modules/web.dom-collections.iterator.js");
9
+ var _nodeOs = _interopRequireDefault(require("node:os"));
10
+ var _signalExit = _interopRequireDefault(require("signal-exit"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
13
+
14
+ // Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
15
+ const spawnedKill = function (kill) {
16
+ let signal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'SIGTERM';
17
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
18
+ const killResult = kill(signal);
19
+ setKillTimeout(kill, signal, options, killResult);
20
+ return killResult;
21
+ };
22
+ exports.spawnedKill = spawnedKill;
23
+ const setKillTimeout = (kill, signal, options, killResult) => {
24
+ if (!shouldForceKill(signal, options, killResult)) {
25
+ return;
26
+ }
27
+ const timeout = getForceKillAfterTimeout(options);
28
+ const t = setTimeout(() => {
29
+ kill('SIGKILL');
30
+ }, timeout);
31
+
32
+ // Guarded because there's no `.unref()` when `execa` is used in the renderer
33
+ // process in Electron. This cannot be tested since we don't run tests in
34
+ // Electron.
35
+ // istanbul ignore else
36
+ if (t.unref) {
37
+ t.unref();
38
+ }
39
+ };
40
+ const shouldForceKill = (signal, _ref, killResult) => {
41
+ let {
42
+ forceKillAfterTimeout
43
+ } = _ref;
44
+ return isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
45
+ };
46
+ const isSigterm = signal => signal === _nodeOs.default.constants.signals.SIGTERM || typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM';
47
+ const getForceKillAfterTimeout = _ref2 => {
48
+ let {
49
+ forceKillAfterTimeout = true
50
+ } = _ref2;
51
+ if (forceKillAfterTimeout === true) {
52
+ return DEFAULT_FORCE_KILL_TIMEOUT;
53
+ }
54
+ if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
55
+ throw new TypeError("Expected the `forceKillAfterTimeout` option to be a non-negative integer, got `".concat(forceKillAfterTimeout, "` (").concat(typeof forceKillAfterTimeout, ")"));
56
+ }
57
+ return forceKillAfterTimeout;
58
+ };
59
+
60
+ // `childProcess.cancel()`
61
+ const spawnedCancel = (spawned, context) => {
62
+ const killResult = spawned.kill();
63
+ if (killResult) {
64
+ context.isCanceled = true;
65
+ }
66
+ };
67
+ exports.spawnedCancel = spawnedCancel;
68
+ const timeoutKill = (spawned, signal, reject) => {
69
+ spawned.kill(signal);
70
+ reject(Object.assign(new Error('Timed out'), {
71
+ timedOut: true,
72
+ signal
73
+ }));
74
+ };
75
+
76
+ // `timeout` option handling
77
+ const setupTimeout = (spawned, _ref3, spawnedPromise) => {
78
+ let {
79
+ timeout,
80
+ killSignal = 'SIGTERM'
81
+ } = _ref3;
82
+ if (timeout === 0 || timeout === undefined) {
83
+ return spawnedPromise;
84
+ }
85
+ let timeoutId;
86
+ const timeoutPromise = new Promise((resolve, reject) => {
87
+ timeoutId = setTimeout(() => {
88
+ timeoutKill(spawned, killSignal, reject);
89
+ }, timeout);
90
+ });
91
+ const safeSpawnedPromise = spawnedPromise.finally(() => {
92
+ clearTimeout(timeoutId);
93
+ });
94
+ return Promise.race([timeoutPromise, safeSpawnedPromise]);
95
+ };
96
+ exports.setupTimeout = setupTimeout;
97
+ const validateTimeout = _ref4 => {
98
+ let {
99
+ timeout
100
+ } = _ref4;
101
+ if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
102
+ throw new TypeError("Expected the `timeout` option to be a non-negative integer, got `".concat(timeout, "` (").concat(typeof timeout, ")"));
103
+ }
104
+ };
105
+
106
+ // `cleanup` option handling
107
+ exports.validateTimeout = validateTimeout;
108
+ const setExitHandler = async (spawned, _ref5, timedPromise) => {
109
+ let {
110
+ cleanup,
111
+ detached
112
+ } = _ref5;
113
+ if (!cleanup || detached) {
114
+ return timedPromise;
115
+ }
116
+ const removeExitHandler = (0, _signalExit.default)(() => {
117
+ spawned.kill();
118
+ });
119
+ return timedPromise.finally(() => {
120
+ removeExitHandler();
121
+ });
122
+ };
123
+ exports.setExitHandler = setExitHandler;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mergePromise = exports.getSpawnedPromise = void 0;
7
+ require("core-js/modules/web.dom-collections.iterator.js");
8
+ const nativePromisePrototype = (async () => {})().constructor.prototype;
9
+ const descriptors = ['then', 'catch', 'finally'].map(property => [property, Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property)]);
10
+
11
+ // The return value is a mixin of `childProcess` and `Promise`
12
+ const mergePromise = (spawned, promise) => {
13
+ for (const [property, descriptor] of descriptors) {
14
+ // Starting the main `promise` is deferred to avoid consuming streams
15
+ const value = typeof promise === 'function' ? function () {
16
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
17
+ args[_key] = arguments[_key];
18
+ }
19
+ return Reflect.apply(descriptor.value, promise(), args);
20
+ } : descriptor.value.bind(promise);
21
+ Reflect.defineProperty(spawned, property, {
22
+ ...descriptor,
23
+ value
24
+ });
25
+ }
26
+ return spawned;
27
+ };
28
+
29
+ // Use promises instead of `child_process` events
30
+ exports.mergePromise = mergePromise;
31
+ const getSpawnedPromise = spawned => new Promise((resolve, reject) => {
32
+ spawned.on('exit', (exitCode, signal) => {
33
+ resolve({
34
+ exitCode,
35
+ signal
36
+ });
37
+ });
38
+ spawned.on('error', error => {
39
+ reject(error);
40
+ });
41
+ if (spawned.stdin) {
42
+ spawned.stdin.on('error', error => {
43
+ reject(error);
44
+ });
45
+ }
46
+ });
47
+ exports.getSpawnedPromise = getSpawnedPromise;