vitest 0.27.2 → 0.28.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.md +4 -93
- package/browser.d.ts +1 -1
- package/dist/browser.d.ts +11 -13
- package/dist/browser.js +10 -34
- package/dist/{chunk-api-setup.029198e3.js → chunk-api-setup.52751a38.js} +27 -12
- package/dist/chunk-constants.797d3ebf.js +42 -0
- package/dist/{chunk-env-node.787e9561.js → chunk-env-node.ffd1183b.js} +26 -0
- package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
- package/dist/chunk-integrations-coverage.48e6286b.js +3993 -0
- package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
- package/dist/chunk-integrations-run-once.38756e30.js +27 -0
- package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
- package/dist/{chunk-node-git.125c9008.js → chunk-node-git.d9ad64ab.js} +6 -7
- package/dist/{chunk-snapshot-manager.ce714e21.js → chunk-node-pkg.dcdf4369.js} +12653 -9324
- package/dist/{chunk-runtime-mocker.58511c38.js → chunk-runtime-mocker.03017e8c.js} +14 -13
- package/dist/{chunk-runtime-rpc.d709e91b.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
- package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
- package/dist/chunk-snapshot-env.6457638e.js +11 -0
- package/dist/chunk-utils-base.977ae74f.js +77 -0
- package/dist/chunk-utils-env.860d90c2.js +6 -0
- package/dist/chunk-utils-global.442d1d33.js +73 -0
- package/dist/{chunk-utils-import.054ab315.js → chunk-utils-import.9911c99d.js} +3289 -169
- package/dist/chunk-utils-tasks.1b603032.js +103 -0
- package/dist/cli-wrapper.js +8 -6
- package/dist/cli.js +18 -15
- package/dist/config.cjs +10 -7
- package/dist/config.d.ts +22 -4
- package/dist/config.js +10 -8
- package/dist/entry.js +244 -28
- package/dist/env-afee91f0.d.ts +10 -0
- package/dist/environments.d.ts +7 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +160 -11
- package/dist/index.js +18 -18
- package/dist/loader.js +9 -8
- package/dist/node.d.ts +9 -7
- package/dist/node.js +20 -17
- package/dist/runners-chunk.js +215 -0
- package/dist/runners.d.ts +39 -0
- package/dist/runners.js +18 -0
- package/dist/spy.js +1 -2
- package/dist/suite.d.ts +2 -0
- package/dist/suite.js +2 -18
- package/dist/{types-d97c72c7.d.ts → types-c800444e.d.ts} +196 -437
- package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
- package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
- package/dist/worker.js +17 -16
- package/package.json +22 -12
- package/runners.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/dist/chunk-integrations-coverage.44413252.js +0 -240
- package/dist/chunk-integrations-globals.0024ce21.js +0 -27
- package/dist/chunk-mock-date.c543fa3e.js +0 -349
- package/dist/chunk-runtime-chain.2da9e75c.js +0 -2595
- package/dist/chunk-runtime-error.de671af0.js +0 -144
- package/dist/chunk-runtime-setup.35da9209.js +0 -649
- package/dist/chunk-utils-env.f4a39d2c.js +0 -228
- package/dist/chunk-utils-source-map.5f5d12cf.js +0 -408
- package/dist/chunk-utils-timers.52534f96.js +0 -3573
- package/dist/index-50755efe.d.ts +0 -258
- package/dist/vendor-index.451e37bc.js +0 -1071
- package/dist/vendor-index.723a074f.js +0 -102
- package/dist/vendor-index.9c919048.js +0 -61
- package/dist/vendor-index.9f20a9be.js +0 -6291
|
@@ -1,1071 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import childProcess from 'node:child_process';
|
|
4
|
-
import process$1 from 'node:process';
|
|
5
|
-
import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.e6c27006.js';
|
|
6
|
-
import url from 'node:url';
|
|
7
|
-
import { constants } from 'os';
|
|
8
|
-
import os from 'node:os';
|
|
9
|
-
|
|
10
|
-
function stripFinalNewline(input) {
|
|
11
|
-
const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
|
|
12
|
-
const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
|
|
13
|
-
|
|
14
|
-
if (input[input.length - 1] === LF) {
|
|
15
|
-
input = input.slice(0, -1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (input[input.length - 1] === CR) {
|
|
19
|
-
input = input.slice(0, -1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return input;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function pathKey(options = {}) {
|
|
26
|
-
const {
|
|
27
|
-
env = process.env,
|
|
28
|
-
platform = process.platform
|
|
29
|
-
} = options;
|
|
30
|
-
|
|
31
|
-
if (platform !== 'win32') {
|
|
32
|
-
return 'PATH';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function npmRunPath(options = {}) {
|
|
39
|
-
const {
|
|
40
|
-
cwd = process$1.cwd(),
|
|
41
|
-
path: path_ = process$1.env[pathKey()],
|
|
42
|
-
execPath = process$1.execPath,
|
|
43
|
-
} = options;
|
|
44
|
-
|
|
45
|
-
let previous;
|
|
46
|
-
const cwdString = cwd instanceof URL ? url.fileURLToPath(cwd) : cwd;
|
|
47
|
-
let cwdPath = path.resolve(cwdString);
|
|
48
|
-
const result = [];
|
|
49
|
-
|
|
50
|
-
while (previous !== cwdPath) {
|
|
51
|
-
result.push(path.join(cwdPath, 'node_modules/.bin'));
|
|
52
|
-
previous = cwdPath;
|
|
53
|
-
cwdPath = path.resolve(cwdPath, '..');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Ensure the running `node` binary is used.
|
|
57
|
-
result.push(path.resolve(cwdString, execPath, '..'));
|
|
58
|
-
|
|
59
|
-
return [...result, path_].join(path.delimiter);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function npmRunPathEnv({env = process$1.env, ...options} = {}) {
|
|
63
|
-
env = {...env};
|
|
64
|
-
|
|
65
|
-
const path = pathKey({env});
|
|
66
|
-
options.path = env[path];
|
|
67
|
-
env[path] = npmRunPath(options);
|
|
68
|
-
|
|
69
|
-
return env;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
|
|
73
|
-
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
|
|
74
|
-
// `Function#prototype` is non-writable and non-configurable so can never be modified.
|
|
75
|
-
if (property === 'length' || property === 'prototype') {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// `Function#arguments` and `Function#caller` should not be copied. They were reported to be present in `Reflect.ownKeys` for some devices in React Native (#41), so we explicitly ignore them here.
|
|
80
|
-
if (property === 'arguments' || property === 'caller') {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
|
85
|
-
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
|
86
|
-
|
|
87
|
-
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
Object.defineProperty(to, property, fromDescriptor);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// `Object.defineProperty()` throws if the property exists, is not configurable and either:
|
|
95
|
-
// - one its descriptors is changed
|
|
96
|
-
// - it is non-writable and its value is changed
|
|
97
|
-
const canCopyProperty = function (toDescriptor, fromDescriptor) {
|
|
98
|
-
return toDescriptor === undefined || toDescriptor.configurable || (
|
|
99
|
-
toDescriptor.writable === fromDescriptor.writable &&
|
|
100
|
-
toDescriptor.enumerable === fromDescriptor.enumerable &&
|
|
101
|
-
toDescriptor.configurable === fromDescriptor.configurable &&
|
|
102
|
-
(toDescriptor.writable || toDescriptor.value === fromDescriptor.value)
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const changePrototype = (to, from) => {
|
|
107
|
-
const fromPrototype = Object.getPrototypeOf(from);
|
|
108
|
-
if (fromPrototype === Object.getPrototypeOf(to)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
Object.setPrototypeOf(to, fromPrototype);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
|
|
116
|
-
|
|
117
|
-
const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
|
|
118
|
-
const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
|
|
119
|
-
|
|
120
|
-
// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
|
|
121
|
-
// We use `bind()` instead of a closure for the same reason.
|
|
122
|
-
// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
|
|
123
|
-
const changeToString = (to, from, name) => {
|
|
124
|
-
const withName = name === '' ? '' : `with ${name.trim()}() `;
|
|
125
|
-
const newToString = wrappedToString.bind(null, withName, from.toString());
|
|
126
|
-
// Ensure `to.toString.toString` is non-enumerable and has the same `same`
|
|
127
|
-
Object.defineProperty(newToString, 'name', toStringName);
|
|
128
|
-
Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString});
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {
|
|
132
|
-
const {name} = to;
|
|
133
|
-
|
|
134
|
-
for (const property of Reflect.ownKeys(from)) {
|
|
135
|
-
copyProperty(to, from, property, ignoreNonConfigurable);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
changePrototype(to, from);
|
|
139
|
-
changeToString(to, from, name);
|
|
140
|
-
|
|
141
|
-
return to;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const calledFunctions = new WeakMap();
|
|
145
|
-
|
|
146
|
-
const onetime = (function_, options = {}) => {
|
|
147
|
-
if (typeof function_ !== 'function') {
|
|
148
|
-
throw new TypeError('Expected a function');
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let returnValue;
|
|
152
|
-
let callCount = 0;
|
|
153
|
-
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
154
|
-
|
|
155
|
-
const onetime = function (...arguments_) {
|
|
156
|
-
calledFunctions.set(onetime, ++callCount);
|
|
157
|
-
|
|
158
|
-
if (callCount === 1) {
|
|
159
|
-
returnValue = function_.apply(this, arguments_);
|
|
160
|
-
function_ = null;
|
|
161
|
-
} else if (options.throw === true) {
|
|
162
|
-
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return returnValue;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
mimicFunction(onetime, function_);
|
|
169
|
-
calledFunctions.set(onetime, callCount);
|
|
170
|
-
|
|
171
|
-
return onetime;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
onetime.callCount = function_ => {
|
|
175
|
-
if (!calledFunctions.has(function_)) {
|
|
176
|
-
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return calledFunctions.get(function_);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const getRealtimeSignals=function(){
|
|
183
|
-
const length=SIGRTMAX-SIGRTMIN+1;
|
|
184
|
-
return Array.from({length},getRealtimeSignal);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const getRealtimeSignal=function(value,index){
|
|
188
|
-
return {
|
|
189
|
-
name:`SIGRT${index+1}`,
|
|
190
|
-
number:SIGRTMIN+index,
|
|
191
|
-
action:"terminate",
|
|
192
|
-
description:"Application-specific signal (realtime)",
|
|
193
|
-
standard:"posix"};
|
|
194
|
-
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const SIGRTMIN=34;
|
|
198
|
-
const SIGRTMAX=64;
|
|
199
|
-
|
|
200
|
-
const SIGNALS=[
|
|
201
|
-
{
|
|
202
|
-
name:"SIGHUP",
|
|
203
|
-
number:1,
|
|
204
|
-
action:"terminate",
|
|
205
|
-
description:"Terminal closed",
|
|
206
|
-
standard:"posix"},
|
|
207
|
-
|
|
208
|
-
{
|
|
209
|
-
name:"SIGINT",
|
|
210
|
-
number:2,
|
|
211
|
-
action:"terminate",
|
|
212
|
-
description:"User interruption with CTRL-C",
|
|
213
|
-
standard:"ansi"},
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
name:"SIGQUIT",
|
|
217
|
-
number:3,
|
|
218
|
-
action:"core",
|
|
219
|
-
description:"User interruption with CTRL-\\",
|
|
220
|
-
standard:"posix"},
|
|
221
|
-
|
|
222
|
-
{
|
|
223
|
-
name:"SIGILL",
|
|
224
|
-
number:4,
|
|
225
|
-
action:"core",
|
|
226
|
-
description:"Invalid machine instruction",
|
|
227
|
-
standard:"ansi"},
|
|
228
|
-
|
|
229
|
-
{
|
|
230
|
-
name:"SIGTRAP",
|
|
231
|
-
number:5,
|
|
232
|
-
action:"core",
|
|
233
|
-
description:"Debugger breakpoint",
|
|
234
|
-
standard:"posix"},
|
|
235
|
-
|
|
236
|
-
{
|
|
237
|
-
name:"SIGABRT",
|
|
238
|
-
number:6,
|
|
239
|
-
action:"core",
|
|
240
|
-
description:"Aborted",
|
|
241
|
-
standard:"ansi"},
|
|
242
|
-
|
|
243
|
-
{
|
|
244
|
-
name:"SIGIOT",
|
|
245
|
-
number:6,
|
|
246
|
-
action:"core",
|
|
247
|
-
description:"Aborted",
|
|
248
|
-
standard:"bsd"},
|
|
249
|
-
|
|
250
|
-
{
|
|
251
|
-
name:"SIGBUS",
|
|
252
|
-
number:7,
|
|
253
|
-
action:"core",
|
|
254
|
-
description:
|
|
255
|
-
"Bus error due to misaligned, non-existing address or paging error",
|
|
256
|
-
standard:"bsd"},
|
|
257
|
-
|
|
258
|
-
{
|
|
259
|
-
name:"SIGEMT",
|
|
260
|
-
number:7,
|
|
261
|
-
action:"terminate",
|
|
262
|
-
description:"Command should be emulated but is not implemented",
|
|
263
|
-
standard:"other"},
|
|
264
|
-
|
|
265
|
-
{
|
|
266
|
-
name:"SIGFPE",
|
|
267
|
-
number:8,
|
|
268
|
-
action:"core",
|
|
269
|
-
description:"Floating point arithmetic error",
|
|
270
|
-
standard:"ansi"},
|
|
271
|
-
|
|
272
|
-
{
|
|
273
|
-
name:"SIGKILL",
|
|
274
|
-
number:9,
|
|
275
|
-
action:"terminate",
|
|
276
|
-
description:"Forced termination",
|
|
277
|
-
standard:"posix",
|
|
278
|
-
forced:true},
|
|
279
|
-
|
|
280
|
-
{
|
|
281
|
-
name:"SIGUSR1",
|
|
282
|
-
number:10,
|
|
283
|
-
action:"terminate",
|
|
284
|
-
description:"Application-specific signal",
|
|
285
|
-
standard:"posix"},
|
|
286
|
-
|
|
287
|
-
{
|
|
288
|
-
name:"SIGSEGV",
|
|
289
|
-
number:11,
|
|
290
|
-
action:"core",
|
|
291
|
-
description:"Segmentation fault",
|
|
292
|
-
standard:"ansi"},
|
|
293
|
-
|
|
294
|
-
{
|
|
295
|
-
name:"SIGUSR2",
|
|
296
|
-
number:12,
|
|
297
|
-
action:"terminate",
|
|
298
|
-
description:"Application-specific signal",
|
|
299
|
-
standard:"posix"},
|
|
300
|
-
|
|
301
|
-
{
|
|
302
|
-
name:"SIGPIPE",
|
|
303
|
-
number:13,
|
|
304
|
-
action:"terminate",
|
|
305
|
-
description:"Broken pipe or socket",
|
|
306
|
-
standard:"posix"},
|
|
307
|
-
|
|
308
|
-
{
|
|
309
|
-
name:"SIGALRM",
|
|
310
|
-
number:14,
|
|
311
|
-
action:"terminate",
|
|
312
|
-
description:"Timeout or timer",
|
|
313
|
-
standard:"posix"},
|
|
314
|
-
|
|
315
|
-
{
|
|
316
|
-
name:"SIGTERM",
|
|
317
|
-
number:15,
|
|
318
|
-
action:"terminate",
|
|
319
|
-
description:"Termination",
|
|
320
|
-
standard:"ansi"},
|
|
321
|
-
|
|
322
|
-
{
|
|
323
|
-
name:"SIGSTKFLT",
|
|
324
|
-
number:16,
|
|
325
|
-
action:"terminate",
|
|
326
|
-
description:"Stack is empty or overflowed",
|
|
327
|
-
standard:"other"},
|
|
328
|
-
|
|
329
|
-
{
|
|
330
|
-
name:"SIGCHLD",
|
|
331
|
-
number:17,
|
|
332
|
-
action:"ignore",
|
|
333
|
-
description:"Child process terminated, paused or unpaused",
|
|
334
|
-
standard:"posix"},
|
|
335
|
-
|
|
336
|
-
{
|
|
337
|
-
name:"SIGCLD",
|
|
338
|
-
number:17,
|
|
339
|
-
action:"ignore",
|
|
340
|
-
description:"Child process terminated, paused or unpaused",
|
|
341
|
-
standard:"other"},
|
|
342
|
-
|
|
343
|
-
{
|
|
344
|
-
name:"SIGCONT",
|
|
345
|
-
number:18,
|
|
346
|
-
action:"unpause",
|
|
347
|
-
description:"Unpaused",
|
|
348
|
-
standard:"posix",
|
|
349
|
-
forced:true},
|
|
350
|
-
|
|
351
|
-
{
|
|
352
|
-
name:"SIGSTOP",
|
|
353
|
-
number:19,
|
|
354
|
-
action:"pause",
|
|
355
|
-
description:"Paused",
|
|
356
|
-
standard:"posix",
|
|
357
|
-
forced:true},
|
|
358
|
-
|
|
359
|
-
{
|
|
360
|
-
name:"SIGTSTP",
|
|
361
|
-
number:20,
|
|
362
|
-
action:"pause",
|
|
363
|
-
description:"Paused using CTRL-Z or \"suspend\"",
|
|
364
|
-
standard:"posix"},
|
|
365
|
-
|
|
366
|
-
{
|
|
367
|
-
name:"SIGTTIN",
|
|
368
|
-
number:21,
|
|
369
|
-
action:"pause",
|
|
370
|
-
description:"Background process cannot read terminal input",
|
|
371
|
-
standard:"posix"},
|
|
372
|
-
|
|
373
|
-
{
|
|
374
|
-
name:"SIGBREAK",
|
|
375
|
-
number:21,
|
|
376
|
-
action:"terminate",
|
|
377
|
-
description:"User interruption with CTRL-BREAK",
|
|
378
|
-
standard:"other"},
|
|
379
|
-
|
|
380
|
-
{
|
|
381
|
-
name:"SIGTTOU",
|
|
382
|
-
number:22,
|
|
383
|
-
action:"pause",
|
|
384
|
-
description:"Background process cannot write to terminal output",
|
|
385
|
-
standard:"posix"},
|
|
386
|
-
|
|
387
|
-
{
|
|
388
|
-
name:"SIGURG",
|
|
389
|
-
number:23,
|
|
390
|
-
action:"ignore",
|
|
391
|
-
description:"Socket received out-of-band data",
|
|
392
|
-
standard:"bsd"},
|
|
393
|
-
|
|
394
|
-
{
|
|
395
|
-
name:"SIGXCPU",
|
|
396
|
-
number:24,
|
|
397
|
-
action:"core",
|
|
398
|
-
description:"Process timed out",
|
|
399
|
-
standard:"bsd"},
|
|
400
|
-
|
|
401
|
-
{
|
|
402
|
-
name:"SIGXFSZ",
|
|
403
|
-
number:25,
|
|
404
|
-
action:"core",
|
|
405
|
-
description:"File too big",
|
|
406
|
-
standard:"bsd"},
|
|
407
|
-
|
|
408
|
-
{
|
|
409
|
-
name:"SIGVTALRM",
|
|
410
|
-
number:26,
|
|
411
|
-
action:"terminate",
|
|
412
|
-
description:"Timeout or timer",
|
|
413
|
-
standard:"bsd"},
|
|
414
|
-
|
|
415
|
-
{
|
|
416
|
-
name:"SIGPROF",
|
|
417
|
-
number:27,
|
|
418
|
-
action:"terminate",
|
|
419
|
-
description:"Timeout or timer",
|
|
420
|
-
standard:"bsd"},
|
|
421
|
-
|
|
422
|
-
{
|
|
423
|
-
name:"SIGWINCH",
|
|
424
|
-
number:28,
|
|
425
|
-
action:"ignore",
|
|
426
|
-
description:"Terminal window size changed",
|
|
427
|
-
standard:"bsd"},
|
|
428
|
-
|
|
429
|
-
{
|
|
430
|
-
name:"SIGIO",
|
|
431
|
-
number:29,
|
|
432
|
-
action:"terminate",
|
|
433
|
-
description:"I/O is available",
|
|
434
|
-
standard:"other"},
|
|
435
|
-
|
|
436
|
-
{
|
|
437
|
-
name:"SIGPOLL",
|
|
438
|
-
number:29,
|
|
439
|
-
action:"terminate",
|
|
440
|
-
description:"Watched event",
|
|
441
|
-
standard:"other"},
|
|
442
|
-
|
|
443
|
-
{
|
|
444
|
-
name:"SIGINFO",
|
|
445
|
-
number:29,
|
|
446
|
-
action:"ignore",
|
|
447
|
-
description:"Request for process information",
|
|
448
|
-
standard:"other"},
|
|
449
|
-
|
|
450
|
-
{
|
|
451
|
-
name:"SIGPWR",
|
|
452
|
-
number:30,
|
|
453
|
-
action:"terminate",
|
|
454
|
-
description:"Device running out of power",
|
|
455
|
-
standard:"systemv"},
|
|
456
|
-
|
|
457
|
-
{
|
|
458
|
-
name:"SIGSYS",
|
|
459
|
-
number:31,
|
|
460
|
-
action:"core",
|
|
461
|
-
description:"Invalid system call",
|
|
462
|
-
standard:"other"},
|
|
463
|
-
|
|
464
|
-
{
|
|
465
|
-
name:"SIGUNUSED",
|
|
466
|
-
number:31,
|
|
467
|
-
action:"terminate",
|
|
468
|
-
description:"Invalid system call",
|
|
469
|
-
standard:"other"}];
|
|
470
|
-
|
|
471
|
-
const getSignals=function(){
|
|
472
|
-
const realtimeSignals=getRealtimeSignals();
|
|
473
|
-
const signals=[...SIGNALS,...realtimeSignals].map(normalizeSignal);
|
|
474
|
-
return signals;
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
const normalizeSignal=function({
|
|
484
|
-
name,
|
|
485
|
-
number:defaultNumber,
|
|
486
|
-
description,
|
|
487
|
-
action,
|
|
488
|
-
forced=false,
|
|
489
|
-
standard})
|
|
490
|
-
{
|
|
491
|
-
const{
|
|
492
|
-
signals:{[name]:constantSignal}}=
|
|
493
|
-
constants;
|
|
494
|
-
const supported=constantSignal!==undefined;
|
|
495
|
-
const number=supported?constantSignal:defaultNumber;
|
|
496
|
-
return {name,number,description,supported,action,forced,standard};
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
const getSignalsByName=function(){
|
|
500
|
-
const signals=getSignals();
|
|
501
|
-
return signals.reduce(getSignalByName,{});
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
const getSignalByName=function(
|
|
505
|
-
signalByNameMemo,
|
|
506
|
-
{name,number,description,supported,action,forced,standard})
|
|
507
|
-
{
|
|
508
|
-
return {
|
|
509
|
-
...signalByNameMemo,
|
|
510
|
-
[name]:{name,number,description,supported,action,forced,standard}};
|
|
511
|
-
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
const signalsByName=getSignalsByName();
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const getSignalsByNumber=function(){
|
|
520
|
-
const signals=getSignals();
|
|
521
|
-
const length=SIGRTMAX+1;
|
|
522
|
-
const signalsA=Array.from({length},(value,number)=>
|
|
523
|
-
getSignalByNumber(number,signals));
|
|
524
|
-
|
|
525
|
-
return Object.assign({},...signalsA);
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
const getSignalByNumber=function(number,signals){
|
|
529
|
-
const signal=findSignalByNumber(number,signals);
|
|
530
|
-
|
|
531
|
-
if(signal===undefined){
|
|
532
|
-
return {};
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
const{name,description,supported,action,forced,standard}=signal;
|
|
536
|
-
return {
|
|
537
|
-
[number]:{
|
|
538
|
-
name,
|
|
539
|
-
number,
|
|
540
|
-
description,
|
|
541
|
-
supported,
|
|
542
|
-
action,
|
|
543
|
-
forced,
|
|
544
|
-
standard}};
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
const findSignalByNumber=function(number,signals){
|
|
552
|
-
const signal=signals.find(({name})=>constants.signals[name]===number);
|
|
553
|
-
|
|
554
|
-
if(signal!==undefined){
|
|
555
|
-
return signal;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return signals.find((signalA)=>signalA.number===number);
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
getSignalsByNumber();
|
|
562
|
-
|
|
563
|
-
const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {
|
|
564
|
-
if (timedOut) {
|
|
565
|
-
return `timed out after ${timeout} milliseconds`;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
if (isCanceled) {
|
|
569
|
-
return 'was canceled';
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (errorCode !== undefined) {
|
|
573
|
-
return `failed with ${errorCode}`;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
if (signal !== undefined) {
|
|
577
|
-
return `was killed with ${signal} (${signalDescription})`;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
if (exitCode !== undefined) {
|
|
581
|
-
return `failed with exit code ${exitCode}`;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
return 'failed';
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
const makeError = ({
|
|
588
|
-
stdout,
|
|
589
|
-
stderr,
|
|
590
|
-
all,
|
|
591
|
-
error,
|
|
592
|
-
signal,
|
|
593
|
-
exitCode,
|
|
594
|
-
command,
|
|
595
|
-
escapedCommand,
|
|
596
|
-
timedOut,
|
|
597
|
-
isCanceled,
|
|
598
|
-
killed,
|
|
599
|
-
parsed: {options: {timeout}},
|
|
600
|
-
}) => {
|
|
601
|
-
// `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
|
|
602
|
-
// We normalize them to `undefined`
|
|
603
|
-
exitCode = exitCode === null ? undefined : exitCode;
|
|
604
|
-
signal = signal === null ? undefined : signal;
|
|
605
|
-
const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;
|
|
606
|
-
|
|
607
|
-
const errorCode = error && error.code;
|
|
608
|
-
|
|
609
|
-
const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
|
|
610
|
-
const execaMessage = `Command ${prefix}: ${command}`;
|
|
611
|
-
const isError = Object.prototype.toString.call(error) === '[object Error]';
|
|
612
|
-
const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
|
|
613
|
-
const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');
|
|
614
|
-
|
|
615
|
-
if (isError) {
|
|
616
|
-
error.originalMessage = error.message;
|
|
617
|
-
error.message = message;
|
|
618
|
-
} else {
|
|
619
|
-
error = new Error(message);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
error.shortMessage = shortMessage;
|
|
623
|
-
error.command = command;
|
|
624
|
-
error.escapedCommand = escapedCommand;
|
|
625
|
-
error.exitCode = exitCode;
|
|
626
|
-
error.signal = signal;
|
|
627
|
-
error.signalDescription = signalDescription;
|
|
628
|
-
error.stdout = stdout;
|
|
629
|
-
error.stderr = stderr;
|
|
630
|
-
|
|
631
|
-
if (all !== undefined) {
|
|
632
|
-
error.all = all;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
if ('bufferedData' in error) {
|
|
636
|
-
delete error.bufferedData;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
error.failed = true;
|
|
640
|
-
error.timedOut = Boolean(timedOut);
|
|
641
|
-
error.isCanceled = isCanceled;
|
|
642
|
-
error.killed = killed && !timedOut;
|
|
643
|
-
|
|
644
|
-
return error;
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
const aliases = ['stdin', 'stdout', 'stderr'];
|
|
648
|
-
|
|
649
|
-
const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
|
|
650
|
-
|
|
651
|
-
const normalizeStdio = options => {
|
|
652
|
-
if (!options) {
|
|
653
|
-
return;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
const {stdio} = options;
|
|
657
|
-
|
|
658
|
-
if (stdio === undefined) {
|
|
659
|
-
return aliases.map(alias => options[alias]);
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
if (hasAlias(options)) {
|
|
663
|
-
throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
if (typeof stdio === 'string') {
|
|
667
|
-
return stdio;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
if (!Array.isArray(stdio)) {
|
|
671
|
-
throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
const length = Math.max(stdio.length, aliases.length);
|
|
675
|
-
return Array.from({length}, (value, index) => stdio[index]);
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
|
|
679
|
-
|
|
680
|
-
// Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
|
|
681
|
-
const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => {
|
|
682
|
-
const killResult = kill(signal);
|
|
683
|
-
setKillTimeout(kill, signal, options, killResult);
|
|
684
|
-
return killResult;
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
const setKillTimeout = (kill, signal, options, killResult) => {
|
|
688
|
-
if (!shouldForceKill(signal, options, killResult)) {
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
const timeout = getForceKillAfterTimeout(options);
|
|
693
|
-
const t = setTimeout(() => {
|
|
694
|
-
kill('SIGKILL');
|
|
695
|
-
}, timeout);
|
|
696
|
-
|
|
697
|
-
// Guarded because there's no `.unref()` when `execa` is used in the renderer
|
|
698
|
-
// process in Electron. This cannot be tested since we don't run tests in
|
|
699
|
-
// Electron.
|
|
700
|
-
// istanbul ignore else
|
|
701
|
-
if (t.unref) {
|
|
702
|
-
t.unref();
|
|
703
|
-
}
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
|
|
707
|
-
|
|
708
|
-
const isSigterm = signal => signal === os.constants.signals.SIGTERM
|
|
709
|
-
|| (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
|
|
710
|
-
|
|
711
|
-
const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {
|
|
712
|
-
if (forceKillAfterTimeout === true) {
|
|
713
|
-
return DEFAULT_FORCE_KILL_TIMEOUT;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
|
|
717
|
-
throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
return forceKillAfterTimeout;
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
// `childProcess.cancel()`
|
|
724
|
-
const spawnedCancel = (spawned, context) => {
|
|
725
|
-
const killResult = spawned.kill();
|
|
726
|
-
|
|
727
|
-
if (killResult) {
|
|
728
|
-
context.isCanceled = true;
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
const timeoutKill = (spawned, signal, reject) => {
|
|
733
|
-
spawned.kill(signal);
|
|
734
|
-
reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
// `timeout` option handling
|
|
738
|
-
const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => {
|
|
739
|
-
if (timeout === 0 || timeout === undefined) {
|
|
740
|
-
return spawnedPromise;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
let timeoutId;
|
|
744
|
-
const timeoutPromise = new Promise((resolve, reject) => {
|
|
745
|
-
timeoutId = setTimeout(() => {
|
|
746
|
-
timeoutKill(spawned, killSignal, reject);
|
|
747
|
-
}, timeout);
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
const safeSpawnedPromise = spawnedPromise.finally(() => {
|
|
751
|
-
clearTimeout(timeoutId);
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
return Promise.race([timeoutPromise, safeSpawnedPromise]);
|
|
755
|
-
};
|
|
756
|
-
|
|
757
|
-
const validateTimeout = ({timeout}) => {
|
|
758
|
-
if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
|
|
759
|
-
throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
// `cleanup` option handling
|
|
764
|
-
const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => {
|
|
765
|
-
if (!cleanup || detached) {
|
|
766
|
-
return timedPromise;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
const removeExitHandler = signalExit.exports(() => {
|
|
770
|
-
spawned.kill();
|
|
771
|
-
});
|
|
772
|
-
|
|
773
|
-
return timedPromise.finally(() => {
|
|
774
|
-
removeExitHandler();
|
|
775
|
-
});
|
|
776
|
-
};
|
|
777
|
-
|
|
778
|
-
function isStream(stream) {
|
|
779
|
-
return stream !== null
|
|
780
|
-
&& typeof stream === 'object'
|
|
781
|
-
&& typeof stream.pipe === 'function';
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
// `input` option
|
|
785
|
-
const handleInput = (spawned, input) => {
|
|
786
|
-
// Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
|
|
787
|
-
// @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
|
|
788
|
-
if (input === undefined || spawned.stdin === undefined) {
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
if (isStream(input)) {
|
|
793
|
-
input.pipe(spawned.stdin);
|
|
794
|
-
} else {
|
|
795
|
-
spawned.stdin.end(input);
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
// `all` interleaves `stdout` and `stderr`
|
|
800
|
-
const makeAllStream = (spawned, {all}) => {
|
|
801
|
-
if (!all || (!spawned.stdout && !spawned.stderr)) {
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
const mixed = mergeStream();
|
|
806
|
-
|
|
807
|
-
if (spawned.stdout) {
|
|
808
|
-
mixed.add(spawned.stdout);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
if (spawned.stderr) {
|
|
812
|
-
mixed.add(spawned.stderr);
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
return mixed;
|
|
816
|
-
};
|
|
817
|
-
|
|
818
|
-
// On failure, `result.stdout|stderr|all` should contain the currently buffered stream
|
|
819
|
-
const getBufferedData = async (stream, streamPromise) => {
|
|
820
|
-
if (!stream) {
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
stream.destroy();
|
|
825
|
-
|
|
826
|
-
try {
|
|
827
|
-
return await streamPromise;
|
|
828
|
-
} catch (error) {
|
|
829
|
-
return error.bufferedData;
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
|
|
833
|
-
const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
|
|
834
|
-
if (!stream || !buffer) {
|
|
835
|
-
return;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
if (encoding) {
|
|
839
|
-
return getStream.exports(stream, {encoding, maxBuffer});
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
return getStream.exports.buffer(stream, {maxBuffer});
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
// Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)
|
|
846
|
-
const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {
|
|
847
|
-
const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});
|
|
848
|
-
const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});
|
|
849
|
-
const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});
|
|
850
|
-
|
|
851
|
-
try {
|
|
852
|
-
return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
|
|
853
|
-
} catch (error) {
|
|
854
|
-
return Promise.all([
|
|
855
|
-
{error, signal: error.signal, timedOut: error.timedOut},
|
|
856
|
-
getBufferedData(stdout, stdoutPromise),
|
|
857
|
-
getBufferedData(stderr, stderrPromise),
|
|
858
|
-
getBufferedData(all, allPromise),
|
|
859
|
-
]);
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
|
|
863
|
-
const nativePromisePrototype = (async () => {})().constructor.prototype;
|
|
864
|
-
const descriptors = ['then', 'catch', 'finally'].map(property => [
|
|
865
|
-
property,
|
|
866
|
-
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
|
|
867
|
-
]);
|
|
868
|
-
|
|
869
|
-
// The return value is a mixin of `childProcess` and `Promise`
|
|
870
|
-
const mergePromise = (spawned, promise) => {
|
|
871
|
-
for (const [property, descriptor] of descriptors) {
|
|
872
|
-
// Starting the main `promise` is deferred to avoid consuming streams
|
|
873
|
-
const value = typeof promise === 'function'
|
|
874
|
-
? (...args) => Reflect.apply(descriptor.value, promise(), args)
|
|
875
|
-
: descriptor.value.bind(promise);
|
|
876
|
-
|
|
877
|
-
Reflect.defineProperty(spawned, property, {...descriptor, value});
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
return spawned;
|
|
881
|
-
};
|
|
882
|
-
|
|
883
|
-
// Use promises instead of `child_process` events
|
|
884
|
-
const getSpawnedPromise = spawned => new Promise((resolve, reject) => {
|
|
885
|
-
spawned.on('exit', (exitCode, signal) => {
|
|
886
|
-
resolve({exitCode, signal});
|
|
887
|
-
});
|
|
888
|
-
|
|
889
|
-
spawned.on('error', error => {
|
|
890
|
-
reject(error);
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
if (spawned.stdin) {
|
|
894
|
-
spawned.stdin.on('error', error => {
|
|
895
|
-
reject(error);
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
});
|
|
899
|
-
|
|
900
|
-
const normalizeArgs = (file, args = []) => {
|
|
901
|
-
if (!Array.isArray(args)) {
|
|
902
|
-
return [file];
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
return [file, ...args];
|
|
906
|
-
};
|
|
907
|
-
|
|
908
|
-
const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
|
|
909
|
-
const DOUBLE_QUOTES_REGEXP = /"/g;
|
|
910
|
-
|
|
911
|
-
const escapeArg = arg => {
|
|
912
|
-
if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
|
|
913
|
-
return arg;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`;
|
|
917
|
-
};
|
|
918
|
-
|
|
919
|
-
const joinCommand = (file, args) => normalizeArgs(file, args).join(' ');
|
|
920
|
-
|
|
921
|
-
const getEscapedCommand = (file, args) => normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' ');
|
|
922
|
-
|
|
923
|
-
const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
|
|
924
|
-
|
|
925
|
-
const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => {
|
|
926
|
-
const env = extendEnv ? {...process$1.env, ...envOption} : envOption;
|
|
927
|
-
|
|
928
|
-
if (preferLocal) {
|
|
929
|
-
return npmRunPathEnv({env, cwd: localDir, execPath});
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
return env;
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
const handleArguments = (file, args, options = {}) => {
|
|
936
|
-
const parsed = crossSpawn.exports._parse(file, args, options);
|
|
937
|
-
file = parsed.command;
|
|
938
|
-
args = parsed.args;
|
|
939
|
-
options = parsed.options;
|
|
940
|
-
|
|
941
|
-
options = {
|
|
942
|
-
maxBuffer: DEFAULT_MAX_BUFFER,
|
|
943
|
-
buffer: true,
|
|
944
|
-
stripFinalNewline: true,
|
|
945
|
-
extendEnv: true,
|
|
946
|
-
preferLocal: false,
|
|
947
|
-
localDir: options.cwd || process$1.cwd(),
|
|
948
|
-
execPath: process$1.execPath,
|
|
949
|
-
encoding: 'utf8',
|
|
950
|
-
reject: true,
|
|
951
|
-
cleanup: true,
|
|
952
|
-
all: false,
|
|
953
|
-
windowsHide: true,
|
|
954
|
-
...options,
|
|
955
|
-
};
|
|
956
|
-
|
|
957
|
-
options.env = getEnv(options);
|
|
958
|
-
|
|
959
|
-
options.stdio = normalizeStdio(options);
|
|
960
|
-
|
|
961
|
-
if (process$1.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {
|
|
962
|
-
// #116
|
|
963
|
-
args.unshift('/q');
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
return {file, args, options, parsed};
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
const handleOutput = (options, value, error) => {
|
|
970
|
-
if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
|
|
971
|
-
// When `execaSync()` errors, we normalize it to '' to mimic `execa()`
|
|
972
|
-
return error === undefined ? undefined : '';
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
if (options.stripFinalNewline) {
|
|
976
|
-
return stripFinalNewline(value);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
return value;
|
|
980
|
-
};
|
|
981
|
-
|
|
982
|
-
function execa(file, args, options) {
|
|
983
|
-
const parsed = handleArguments(file, args, options);
|
|
984
|
-
const command = joinCommand(file, args);
|
|
985
|
-
const escapedCommand = getEscapedCommand(file, args);
|
|
986
|
-
|
|
987
|
-
validateTimeout(parsed.options);
|
|
988
|
-
|
|
989
|
-
let spawned;
|
|
990
|
-
try {
|
|
991
|
-
spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
|
|
992
|
-
} catch (error) {
|
|
993
|
-
// Ensure the returned error is always both a promise and a child process
|
|
994
|
-
const dummySpawned = new childProcess.ChildProcess();
|
|
995
|
-
const errorPromise = Promise.reject(makeError({
|
|
996
|
-
error,
|
|
997
|
-
stdout: '',
|
|
998
|
-
stderr: '',
|
|
999
|
-
all: '',
|
|
1000
|
-
command,
|
|
1001
|
-
escapedCommand,
|
|
1002
|
-
parsed,
|
|
1003
|
-
timedOut: false,
|
|
1004
|
-
isCanceled: false,
|
|
1005
|
-
killed: false,
|
|
1006
|
-
}));
|
|
1007
|
-
return mergePromise(dummySpawned, errorPromise);
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
const spawnedPromise = getSpawnedPromise(spawned);
|
|
1011
|
-
const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
|
|
1012
|
-
const processDone = setExitHandler(spawned, parsed.options, timedPromise);
|
|
1013
|
-
|
|
1014
|
-
const context = {isCanceled: false};
|
|
1015
|
-
|
|
1016
|
-
spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
|
|
1017
|
-
spawned.cancel = spawnedCancel.bind(null, spawned, context);
|
|
1018
|
-
|
|
1019
|
-
const handlePromise = async () => {
|
|
1020
|
-
const [{error, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
|
|
1021
|
-
const stdout = handleOutput(parsed.options, stdoutResult);
|
|
1022
|
-
const stderr = handleOutput(parsed.options, stderrResult);
|
|
1023
|
-
const all = handleOutput(parsed.options, allResult);
|
|
1024
|
-
|
|
1025
|
-
if (error || exitCode !== 0 || signal !== null) {
|
|
1026
|
-
const returnedError = makeError({
|
|
1027
|
-
error,
|
|
1028
|
-
exitCode,
|
|
1029
|
-
signal,
|
|
1030
|
-
stdout,
|
|
1031
|
-
stderr,
|
|
1032
|
-
all,
|
|
1033
|
-
command,
|
|
1034
|
-
escapedCommand,
|
|
1035
|
-
parsed,
|
|
1036
|
-
timedOut,
|
|
1037
|
-
isCanceled: context.isCanceled || (parsed.options.signal ? parsed.options.signal.aborted : false),
|
|
1038
|
-
killed: spawned.killed,
|
|
1039
|
-
});
|
|
1040
|
-
|
|
1041
|
-
if (!parsed.options.reject) {
|
|
1042
|
-
return returnedError;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
throw returnedError;
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
return {
|
|
1049
|
-
command,
|
|
1050
|
-
escapedCommand,
|
|
1051
|
-
exitCode: 0,
|
|
1052
|
-
stdout,
|
|
1053
|
-
stderr,
|
|
1054
|
-
all,
|
|
1055
|
-
failed: false,
|
|
1056
|
-
timedOut: false,
|
|
1057
|
-
isCanceled: false,
|
|
1058
|
-
killed: false,
|
|
1059
|
-
};
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
const handlePromiseOnce = onetime(handlePromise);
|
|
1063
|
-
|
|
1064
|
-
handleInput(spawned, parsed.options.input);
|
|
1065
|
-
|
|
1066
|
-
spawned.all = makeAllStream(spawned, parsed.options);
|
|
1067
|
-
|
|
1068
|
-
return mergePromise(spawned, handlePromiseOnce);
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
export { execa as e };
|