vitest 0.0.114 → 0.0.115
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 +5 -5
- package/dist/cli.js +1107 -31
- package/dist/{constants-9c7f06df.js → constants-5968a78c.js} +1 -1
- package/dist/{diff-3cfdad26.js → diff-67678e1f.js} +1 -1
- package/dist/entry.js +11 -11
- package/dist/{global-12653c72.js → global-bc40af7c.js} +4 -4
- package/dist/{index-61c8686f.js → index-648e7ab2.js} +62 -62
- package/dist/index-6e709f57.js +781 -0
- package/dist/{index-ea5153a0.js → index-7c024e16.js} +27 -2
- package/dist/{index-ebf35a56.js → index-7f57c252.js} +1 -1
- package/dist/{index-36694964.js → index-b4f86684.js} +143 -93
- package/dist/{index-9f4b9905.js → index-ce49e384.js} +33 -800
- package/dist/{index-7889832e.js → index-e909c175.js} +25 -16
- package/dist/index.d.ts +72 -9
- package/dist/index.js +3 -3
- package/dist/{middleware-85ff8fbf.js → middleware-647438b9.js} +2 -2
- package/dist/node.d.ts +70 -7
- package/dist/node.js +8 -7
- package/dist/rpc-8c7cc374.js +5 -0
- package/dist/utils.js +1 -1
- package/dist/{vi-67e478ef.js → vi-2115c609.js} +1 -2
- package/dist/worker.js +8 -7
- package/package.json +3 -2
- package/vitest.mjs +1 -20
- package/dist/rpc-85fe6402.js +0 -10
package/dist/cli.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import require$$0 from 'readline';
|
|
1
|
+
import require$$0$1 from 'readline';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import childProcess from 'child_process';
|
|
6
|
+
import process$1 from 'process';
|
|
7
|
+
import { m as mergeStream, g as getStream, c as crossSpawn } from './index-6e709f57.js';
|
|
8
|
+
import require$$0, { constants } from 'os';
|
|
9
|
+
import { s as signalExit } from './index-648e7ab2.js';
|
|
10
|
+
import { e as ensurePackageInstalled } from './index-7c024e16.js';
|
|
11
|
+
import { c as createVitest } from './index-b4f86684.js';
|
|
12
|
+
import './_commonjsHelpers-c9e3b764.js';
|
|
13
|
+
import 'fs';
|
|
14
|
+
import 'stream';
|
|
15
|
+
import 'util';
|
|
16
|
+
import 'assert';
|
|
5
17
|
import 'url';
|
|
6
18
|
import 'tty';
|
|
7
19
|
import 'local-pkg';
|
|
8
|
-
import 'path';
|
|
9
|
-
import 'fs';
|
|
10
20
|
import 'vite';
|
|
11
|
-
import '
|
|
12
|
-
import 'os';
|
|
13
|
-
import 'util';
|
|
14
|
-
import 'stream';
|
|
15
|
-
import './constants-9c7f06df.js';
|
|
21
|
+
import './constants-5968a78c.js';
|
|
16
22
|
import './magic-string.es-94000aea.js';
|
|
17
23
|
import 'perf_hooks';
|
|
18
|
-
import './diff-
|
|
19
|
-
import '
|
|
20
|
-
import './_commonjsHelpers-c9e3b764.js';
|
|
21
|
-
import 'assert';
|
|
24
|
+
import './diff-67678e1f.js';
|
|
25
|
+
import 'module';
|
|
22
26
|
import 'worker_threads';
|
|
23
27
|
import 'tinypool';
|
|
24
|
-
import './index-
|
|
28
|
+
import './index-e909c175.js';
|
|
25
29
|
|
|
26
30
|
function toArr(any) {
|
|
27
31
|
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
@@ -636,7 +640,1067 @@ class CAC extends EventEmitter {
|
|
|
636
640
|
|
|
637
641
|
const cac = (name = "") => new CAC(name);
|
|
638
642
|
|
|
639
|
-
|
|
643
|
+
function stripFinalNewline(input) {
|
|
644
|
+
const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
|
|
645
|
+
const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
|
|
646
|
+
|
|
647
|
+
if (input[input.length - 1] === LF) {
|
|
648
|
+
input = input.slice(0, -1);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (input[input.length - 1] === CR) {
|
|
652
|
+
input = input.slice(0, -1);
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
return input;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function pathKey(options = {}) {
|
|
659
|
+
const {
|
|
660
|
+
env = process.env,
|
|
661
|
+
platform = process.platform
|
|
662
|
+
} = options;
|
|
663
|
+
|
|
664
|
+
if (platform !== 'win32') {
|
|
665
|
+
return 'PATH';
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
return Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function npmRunPath(options = {}) {
|
|
672
|
+
const {
|
|
673
|
+
cwd = process$1.cwd(),
|
|
674
|
+
path: path_ = process$1.env[pathKey()],
|
|
675
|
+
execPath = process$1.execPath,
|
|
676
|
+
} = options;
|
|
677
|
+
|
|
678
|
+
let previous;
|
|
679
|
+
let cwdPath = path.resolve(cwd);
|
|
680
|
+
const result = [];
|
|
681
|
+
|
|
682
|
+
while (previous !== cwdPath) {
|
|
683
|
+
result.push(path.join(cwdPath, 'node_modules/.bin'));
|
|
684
|
+
previous = cwdPath;
|
|
685
|
+
cwdPath = path.resolve(cwdPath, '..');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// Ensure the running `node` binary is used.
|
|
689
|
+
result.push(path.resolve(cwd, execPath, '..'));
|
|
690
|
+
|
|
691
|
+
return [...result, path_].join(path.delimiter);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function npmRunPathEnv({env = process$1.env, ...options} = {}) {
|
|
695
|
+
env = {...env};
|
|
696
|
+
|
|
697
|
+
const path = pathKey({env});
|
|
698
|
+
options.path = env[path];
|
|
699
|
+
env[path] = npmRunPath(options);
|
|
700
|
+
|
|
701
|
+
return env;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
|
|
705
|
+
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
|
|
706
|
+
// `Function#prototype` is non-writable and non-configurable so can never be modified.
|
|
707
|
+
if (property === 'length' || property === 'prototype') {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// `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.
|
|
712
|
+
if (property === 'arguments' || property === 'caller') {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
|
717
|
+
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
|
718
|
+
|
|
719
|
+
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
Object.defineProperty(to, property, fromDescriptor);
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// `Object.defineProperty()` throws if the property exists, is not configurable and either:
|
|
727
|
+
// - one its descriptors is changed
|
|
728
|
+
// - it is non-writable and its value is changed
|
|
729
|
+
const canCopyProperty = function (toDescriptor, fromDescriptor) {
|
|
730
|
+
return toDescriptor === undefined || toDescriptor.configurable || (
|
|
731
|
+
toDescriptor.writable === fromDescriptor.writable &&
|
|
732
|
+
toDescriptor.enumerable === fromDescriptor.enumerable &&
|
|
733
|
+
toDescriptor.configurable === fromDescriptor.configurable &&
|
|
734
|
+
(toDescriptor.writable || toDescriptor.value === fromDescriptor.value)
|
|
735
|
+
);
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
const changePrototype = (to, from) => {
|
|
739
|
+
const fromPrototype = Object.getPrototypeOf(from);
|
|
740
|
+
if (fromPrototype === Object.getPrototypeOf(to)) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
Object.setPrototypeOf(to, fromPrototype);
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
|
|
748
|
+
|
|
749
|
+
const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
|
|
750
|
+
const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
|
|
751
|
+
|
|
752
|
+
// We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
|
|
753
|
+
// We use `bind()` instead of a closure for the same reason.
|
|
754
|
+
// Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
|
|
755
|
+
const changeToString = (to, from, name) => {
|
|
756
|
+
const withName = name === '' ? '' : `with ${name.trim()}() `;
|
|
757
|
+
const newToString = wrappedToString.bind(null, withName, from.toString());
|
|
758
|
+
// Ensure `to.toString.toString` is non-enumerable and has the same `same`
|
|
759
|
+
Object.defineProperty(newToString, 'name', toStringName);
|
|
760
|
+
Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString});
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {
|
|
764
|
+
const {name} = to;
|
|
765
|
+
|
|
766
|
+
for (const property of Reflect.ownKeys(from)) {
|
|
767
|
+
copyProperty(to, from, property, ignoreNonConfigurable);
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
changePrototype(to, from);
|
|
771
|
+
changeToString(to, from, name);
|
|
772
|
+
|
|
773
|
+
return to;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const calledFunctions = new WeakMap();
|
|
777
|
+
|
|
778
|
+
const onetime = (function_, options = {}) => {
|
|
779
|
+
if (typeof function_ !== 'function') {
|
|
780
|
+
throw new TypeError('Expected a function');
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
let returnValue;
|
|
784
|
+
let callCount = 0;
|
|
785
|
+
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
786
|
+
|
|
787
|
+
const onetime = function (...arguments_) {
|
|
788
|
+
calledFunctions.set(onetime, ++callCount);
|
|
789
|
+
|
|
790
|
+
if (callCount === 1) {
|
|
791
|
+
returnValue = function_.apply(this, arguments_);
|
|
792
|
+
function_ = null;
|
|
793
|
+
} else if (options.throw === true) {
|
|
794
|
+
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
return returnValue;
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
mimicFunction(onetime, function_);
|
|
801
|
+
calledFunctions.set(onetime, callCount);
|
|
802
|
+
|
|
803
|
+
return onetime;
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
onetime.callCount = function_ => {
|
|
807
|
+
if (!calledFunctions.has(function_)) {
|
|
808
|
+
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
return calledFunctions.get(function_);
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
const getRealtimeSignals=function(){
|
|
815
|
+
const length=SIGRTMAX-SIGRTMIN+1;
|
|
816
|
+
return Array.from({length},getRealtimeSignal);
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
const getRealtimeSignal=function(value,index){
|
|
820
|
+
return {
|
|
821
|
+
name:`SIGRT${index+1}`,
|
|
822
|
+
number:SIGRTMIN+index,
|
|
823
|
+
action:"terminate",
|
|
824
|
+
description:"Application-specific signal (realtime)",
|
|
825
|
+
standard:"posix"};
|
|
826
|
+
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
const SIGRTMIN=34;
|
|
830
|
+
const SIGRTMAX=64;
|
|
831
|
+
|
|
832
|
+
const SIGNALS=[
|
|
833
|
+
{
|
|
834
|
+
name:"SIGHUP",
|
|
835
|
+
number:1,
|
|
836
|
+
action:"terminate",
|
|
837
|
+
description:"Terminal closed",
|
|
838
|
+
standard:"posix"},
|
|
839
|
+
|
|
840
|
+
{
|
|
841
|
+
name:"SIGINT",
|
|
842
|
+
number:2,
|
|
843
|
+
action:"terminate",
|
|
844
|
+
description:"User interruption with CTRL-C",
|
|
845
|
+
standard:"ansi"},
|
|
846
|
+
|
|
847
|
+
{
|
|
848
|
+
name:"SIGQUIT",
|
|
849
|
+
number:3,
|
|
850
|
+
action:"core",
|
|
851
|
+
description:"User interruption with CTRL-\\",
|
|
852
|
+
standard:"posix"},
|
|
853
|
+
|
|
854
|
+
{
|
|
855
|
+
name:"SIGILL",
|
|
856
|
+
number:4,
|
|
857
|
+
action:"core",
|
|
858
|
+
description:"Invalid machine instruction",
|
|
859
|
+
standard:"ansi"},
|
|
860
|
+
|
|
861
|
+
{
|
|
862
|
+
name:"SIGTRAP",
|
|
863
|
+
number:5,
|
|
864
|
+
action:"core",
|
|
865
|
+
description:"Debugger breakpoint",
|
|
866
|
+
standard:"posix"},
|
|
867
|
+
|
|
868
|
+
{
|
|
869
|
+
name:"SIGABRT",
|
|
870
|
+
number:6,
|
|
871
|
+
action:"core",
|
|
872
|
+
description:"Aborted",
|
|
873
|
+
standard:"ansi"},
|
|
874
|
+
|
|
875
|
+
{
|
|
876
|
+
name:"SIGIOT",
|
|
877
|
+
number:6,
|
|
878
|
+
action:"core",
|
|
879
|
+
description:"Aborted",
|
|
880
|
+
standard:"bsd"},
|
|
881
|
+
|
|
882
|
+
{
|
|
883
|
+
name:"SIGBUS",
|
|
884
|
+
number:7,
|
|
885
|
+
action:"core",
|
|
886
|
+
description:
|
|
887
|
+
"Bus error due to misaligned, non-existing address or paging error",
|
|
888
|
+
standard:"bsd"},
|
|
889
|
+
|
|
890
|
+
{
|
|
891
|
+
name:"SIGEMT",
|
|
892
|
+
number:7,
|
|
893
|
+
action:"terminate",
|
|
894
|
+
description:"Command should be emulated but is not implemented",
|
|
895
|
+
standard:"other"},
|
|
896
|
+
|
|
897
|
+
{
|
|
898
|
+
name:"SIGFPE",
|
|
899
|
+
number:8,
|
|
900
|
+
action:"core",
|
|
901
|
+
description:"Floating point arithmetic error",
|
|
902
|
+
standard:"ansi"},
|
|
903
|
+
|
|
904
|
+
{
|
|
905
|
+
name:"SIGKILL",
|
|
906
|
+
number:9,
|
|
907
|
+
action:"terminate",
|
|
908
|
+
description:"Forced termination",
|
|
909
|
+
standard:"posix",
|
|
910
|
+
forced:true},
|
|
911
|
+
|
|
912
|
+
{
|
|
913
|
+
name:"SIGUSR1",
|
|
914
|
+
number:10,
|
|
915
|
+
action:"terminate",
|
|
916
|
+
description:"Application-specific signal",
|
|
917
|
+
standard:"posix"},
|
|
918
|
+
|
|
919
|
+
{
|
|
920
|
+
name:"SIGSEGV",
|
|
921
|
+
number:11,
|
|
922
|
+
action:"core",
|
|
923
|
+
description:"Segmentation fault",
|
|
924
|
+
standard:"ansi"},
|
|
925
|
+
|
|
926
|
+
{
|
|
927
|
+
name:"SIGUSR2",
|
|
928
|
+
number:12,
|
|
929
|
+
action:"terminate",
|
|
930
|
+
description:"Application-specific signal",
|
|
931
|
+
standard:"posix"},
|
|
932
|
+
|
|
933
|
+
{
|
|
934
|
+
name:"SIGPIPE",
|
|
935
|
+
number:13,
|
|
936
|
+
action:"terminate",
|
|
937
|
+
description:"Broken pipe or socket",
|
|
938
|
+
standard:"posix"},
|
|
939
|
+
|
|
940
|
+
{
|
|
941
|
+
name:"SIGALRM",
|
|
942
|
+
number:14,
|
|
943
|
+
action:"terminate",
|
|
944
|
+
description:"Timeout or timer",
|
|
945
|
+
standard:"posix"},
|
|
946
|
+
|
|
947
|
+
{
|
|
948
|
+
name:"SIGTERM",
|
|
949
|
+
number:15,
|
|
950
|
+
action:"terminate",
|
|
951
|
+
description:"Termination",
|
|
952
|
+
standard:"ansi"},
|
|
953
|
+
|
|
954
|
+
{
|
|
955
|
+
name:"SIGSTKFLT",
|
|
956
|
+
number:16,
|
|
957
|
+
action:"terminate",
|
|
958
|
+
description:"Stack is empty or overflowed",
|
|
959
|
+
standard:"other"},
|
|
960
|
+
|
|
961
|
+
{
|
|
962
|
+
name:"SIGCHLD",
|
|
963
|
+
number:17,
|
|
964
|
+
action:"ignore",
|
|
965
|
+
description:"Child process terminated, paused or unpaused",
|
|
966
|
+
standard:"posix"},
|
|
967
|
+
|
|
968
|
+
{
|
|
969
|
+
name:"SIGCLD",
|
|
970
|
+
number:17,
|
|
971
|
+
action:"ignore",
|
|
972
|
+
description:"Child process terminated, paused or unpaused",
|
|
973
|
+
standard:"other"},
|
|
974
|
+
|
|
975
|
+
{
|
|
976
|
+
name:"SIGCONT",
|
|
977
|
+
number:18,
|
|
978
|
+
action:"unpause",
|
|
979
|
+
description:"Unpaused",
|
|
980
|
+
standard:"posix",
|
|
981
|
+
forced:true},
|
|
982
|
+
|
|
983
|
+
{
|
|
984
|
+
name:"SIGSTOP",
|
|
985
|
+
number:19,
|
|
986
|
+
action:"pause",
|
|
987
|
+
description:"Paused",
|
|
988
|
+
standard:"posix",
|
|
989
|
+
forced:true},
|
|
990
|
+
|
|
991
|
+
{
|
|
992
|
+
name:"SIGTSTP",
|
|
993
|
+
number:20,
|
|
994
|
+
action:"pause",
|
|
995
|
+
description:"Paused using CTRL-Z or \"suspend\"",
|
|
996
|
+
standard:"posix"},
|
|
997
|
+
|
|
998
|
+
{
|
|
999
|
+
name:"SIGTTIN",
|
|
1000
|
+
number:21,
|
|
1001
|
+
action:"pause",
|
|
1002
|
+
description:"Background process cannot read terminal input",
|
|
1003
|
+
standard:"posix"},
|
|
1004
|
+
|
|
1005
|
+
{
|
|
1006
|
+
name:"SIGBREAK",
|
|
1007
|
+
number:21,
|
|
1008
|
+
action:"terminate",
|
|
1009
|
+
description:"User interruption with CTRL-BREAK",
|
|
1010
|
+
standard:"other"},
|
|
1011
|
+
|
|
1012
|
+
{
|
|
1013
|
+
name:"SIGTTOU",
|
|
1014
|
+
number:22,
|
|
1015
|
+
action:"pause",
|
|
1016
|
+
description:"Background process cannot write to terminal output",
|
|
1017
|
+
standard:"posix"},
|
|
1018
|
+
|
|
1019
|
+
{
|
|
1020
|
+
name:"SIGURG",
|
|
1021
|
+
number:23,
|
|
1022
|
+
action:"ignore",
|
|
1023
|
+
description:"Socket received out-of-band data",
|
|
1024
|
+
standard:"bsd"},
|
|
1025
|
+
|
|
1026
|
+
{
|
|
1027
|
+
name:"SIGXCPU",
|
|
1028
|
+
number:24,
|
|
1029
|
+
action:"core",
|
|
1030
|
+
description:"Process timed out",
|
|
1031
|
+
standard:"bsd"},
|
|
1032
|
+
|
|
1033
|
+
{
|
|
1034
|
+
name:"SIGXFSZ",
|
|
1035
|
+
number:25,
|
|
1036
|
+
action:"core",
|
|
1037
|
+
description:"File too big",
|
|
1038
|
+
standard:"bsd"},
|
|
1039
|
+
|
|
1040
|
+
{
|
|
1041
|
+
name:"SIGVTALRM",
|
|
1042
|
+
number:26,
|
|
1043
|
+
action:"terminate",
|
|
1044
|
+
description:"Timeout or timer",
|
|
1045
|
+
standard:"bsd"},
|
|
1046
|
+
|
|
1047
|
+
{
|
|
1048
|
+
name:"SIGPROF",
|
|
1049
|
+
number:27,
|
|
1050
|
+
action:"terminate",
|
|
1051
|
+
description:"Timeout or timer",
|
|
1052
|
+
standard:"bsd"},
|
|
1053
|
+
|
|
1054
|
+
{
|
|
1055
|
+
name:"SIGWINCH",
|
|
1056
|
+
number:28,
|
|
1057
|
+
action:"ignore",
|
|
1058
|
+
description:"Terminal window size changed",
|
|
1059
|
+
standard:"bsd"},
|
|
1060
|
+
|
|
1061
|
+
{
|
|
1062
|
+
name:"SIGIO",
|
|
1063
|
+
number:29,
|
|
1064
|
+
action:"terminate",
|
|
1065
|
+
description:"I/O is available",
|
|
1066
|
+
standard:"other"},
|
|
1067
|
+
|
|
1068
|
+
{
|
|
1069
|
+
name:"SIGPOLL",
|
|
1070
|
+
number:29,
|
|
1071
|
+
action:"terminate",
|
|
1072
|
+
description:"Watched event",
|
|
1073
|
+
standard:"other"},
|
|
1074
|
+
|
|
1075
|
+
{
|
|
1076
|
+
name:"SIGINFO",
|
|
1077
|
+
number:29,
|
|
1078
|
+
action:"ignore",
|
|
1079
|
+
description:"Request for process information",
|
|
1080
|
+
standard:"other"},
|
|
1081
|
+
|
|
1082
|
+
{
|
|
1083
|
+
name:"SIGPWR",
|
|
1084
|
+
number:30,
|
|
1085
|
+
action:"terminate",
|
|
1086
|
+
description:"Device running out of power",
|
|
1087
|
+
standard:"systemv"},
|
|
1088
|
+
|
|
1089
|
+
{
|
|
1090
|
+
name:"SIGSYS",
|
|
1091
|
+
number:31,
|
|
1092
|
+
action:"core",
|
|
1093
|
+
description:"Invalid system call",
|
|
1094
|
+
standard:"other"},
|
|
1095
|
+
|
|
1096
|
+
{
|
|
1097
|
+
name:"SIGUNUSED",
|
|
1098
|
+
number:31,
|
|
1099
|
+
action:"terminate",
|
|
1100
|
+
description:"Invalid system call",
|
|
1101
|
+
standard:"other"}];
|
|
1102
|
+
|
|
1103
|
+
const getSignals=function(){
|
|
1104
|
+
const realtimeSignals=getRealtimeSignals();
|
|
1105
|
+
const signals=[...SIGNALS,...realtimeSignals].map(normalizeSignal);
|
|
1106
|
+
return signals;
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
const normalizeSignal=function({
|
|
1116
|
+
name,
|
|
1117
|
+
number:defaultNumber,
|
|
1118
|
+
description,
|
|
1119
|
+
action,
|
|
1120
|
+
forced=false,
|
|
1121
|
+
standard})
|
|
1122
|
+
{
|
|
1123
|
+
const{
|
|
1124
|
+
signals:{[name]:constantSignal}}=
|
|
1125
|
+
constants;
|
|
1126
|
+
const supported=constantSignal!==undefined;
|
|
1127
|
+
const number=supported?constantSignal:defaultNumber;
|
|
1128
|
+
return {name,number,description,supported,action,forced,standard};
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
const getSignalsByName=function(){
|
|
1132
|
+
const signals=getSignals();
|
|
1133
|
+
return signals.reduce(getSignalByName,{});
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
const getSignalByName=function(
|
|
1137
|
+
signalByNameMemo,
|
|
1138
|
+
{name,number,description,supported,action,forced,standard})
|
|
1139
|
+
{
|
|
1140
|
+
return {
|
|
1141
|
+
...signalByNameMemo,
|
|
1142
|
+
[name]:{name,number,description,supported,action,forced,standard}};
|
|
1143
|
+
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
const signalsByName=getSignalsByName();
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
const getSignalsByNumber=function(){
|
|
1152
|
+
const signals=getSignals();
|
|
1153
|
+
const length=SIGRTMAX+1;
|
|
1154
|
+
const signalsA=Array.from({length},(value,number)=>
|
|
1155
|
+
getSignalByNumber(number,signals));
|
|
1156
|
+
|
|
1157
|
+
return Object.assign({},...signalsA);
|
|
1158
|
+
};
|
|
1159
|
+
|
|
1160
|
+
const getSignalByNumber=function(number,signals){
|
|
1161
|
+
const signal=findSignalByNumber(number,signals);
|
|
1162
|
+
|
|
1163
|
+
if(signal===undefined){
|
|
1164
|
+
return {};
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
const{name,description,supported,action,forced,standard}=signal;
|
|
1168
|
+
return {
|
|
1169
|
+
[number]:{
|
|
1170
|
+
name,
|
|
1171
|
+
number,
|
|
1172
|
+
description,
|
|
1173
|
+
supported,
|
|
1174
|
+
action,
|
|
1175
|
+
forced,
|
|
1176
|
+
standard}};
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
const findSignalByNumber=function(number,signals){
|
|
1184
|
+
const signal=signals.find(({name})=>constants.signals[name]===number);
|
|
1185
|
+
|
|
1186
|
+
if(signal!==undefined){
|
|
1187
|
+
return signal;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
return signals.find((signalA)=>signalA.number===number);
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
getSignalsByNumber();
|
|
1194
|
+
|
|
1195
|
+
const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {
|
|
1196
|
+
if (timedOut) {
|
|
1197
|
+
return `timed out after ${timeout} milliseconds`;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
if (isCanceled) {
|
|
1201
|
+
return 'was canceled';
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
if (errorCode !== undefined) {
|
|
1205
|
+
return `failed with ${errorCode}`;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
if (signal !== undefined) {
|
|
1209
|
+
return `was killed with ${signal} (${signalDescription})`;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
if (exitCode !== undefined) {
|
|
1213
|
+
return `failed with exit code ${exitCode}`;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
return 'failed';
|
|
1217
|
+
};
|
|
1218
|
+
|
|
1219
|
+
const makeError = ({
|
|
1220
|
+
stdout,
|
|
1221
|
+
stderr,
|
|
1222
|
+
all,
|
|
1223
|
+
error,
|
|
1224
|
+
signal,
|
|
1225
|
+
exitCode,
|
|
1226
|
+
command,
|
|
1227
|
+
escapedCommand,
|
|
1228
|
+
timedOut,
|
|
1229
|
+
isCanceled,
|
|
1230
|
+
killed,
|
|
1231
|
+
parsed: {options: {timeout}},
|
|
1232
|
+
}) => {
|
|
1233
|
+
// `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
|
|
1234
|
+
// We normalize them to `undefined`
|
|
1235
|
+
exitCode = exitCode === null ? undefined : exitCode;
|
|
1236
|
+
signal = signal === null ? undefined : signal;
|
|
1237
|
+
const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;
|
|
1238
|
+
|
|
1239
|
+
const errorCode = error && error.code;
|
|
1240
|
+
|
|
1241
|
+
const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
|
|
1242
|
+
const execaMessage = `Command ${prefix}: ${command}`;
|
|
1243
|
+
const isError = Object.prototype.toString.call(error) === '[object Error]';
|
|
1244
|
+
const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
|
|
1245
|
+
const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');
|
|
1246
|
+
|
|
1247
|
+
if (isError) {
|
|
1248
|
+
error.originalMessage = error.message;
|
|
1249
|
+
error.message = message;
|
|
1250
|
+
} else {
|
|
1251
|
+
error = new Error(message);
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
error.shortMessage = shortMessage;
|
|
1255
|
+
error.command = command;
|
|
1256
|
+
error.escapedCommand = escapedCommand;
|
|
1257
|
+
error.exitCode = exitCode;
|
|
1258
|
+
error.signal = signal;
|
|
1259
|
+
error.signalDescription = signalDescription;
|
|
1260
|
+
error.stdout = stdout;
|
|
1261
|
+
error.stderr = stderr;
|
|
1262
|
+
|
|
1263
|
+
if (all !== undefined) {
|
|
1264
|
+
error.all = all;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
if ('bufferedData' in error) {
|
|
1268
|
+
delete error.bufferedData;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
error.failed = true;
|
|
1272
|
+
error.timedOut = Boolean(timedOut);
|
|
1273
|
+
error.isCanceled = isCanceled;
|
|
1274
|
+
error.killed = killed && !timedOut;
|
|
1275
|
+
|
|
1276
|
+
return error;
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
const aliases = ['stdin', 'stdout', 'stderr'];
|
|
1280
|
+
|
|
1281
|
+
const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
|
|
1282
|
+
|
|
1283
|
+
const normalizeStdio = options => {
|
|
1284
|
+
if (!options) {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
const {stdio} = options;
|
|
1289
|
+
|
|
1290
|
+
if (stdio === undefined) {
|
|
1291
|
+
return aliases.map(alias => options[alias]);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
if (hasAlias(options)) {
|
|
1295
|
+
throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
if (typeof stdio === 'string') {
|
|
1299
|
+
return stdio;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
if (!Array.isArray(stdio)) {
|
|
1303
|
+
throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
const length = Math.max(stdio.length, aliases.length);
|
|
1307
|
+
return Array.from({length}, (value, index) => stdio[index]);
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1310
|
+
const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
|
|
1311
|
+
|
|
1312
|
+
// Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
|
|
1313
|
+
const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => {
|
|
1314
|
+
const killResult = kill(signal);
|
|
1315
|
+
setKillTimeout(kill, signal, options, killResult);
|
|
1316
|
+
return killResult;
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
const setKillTimeout = (kill, signal, options, killResult) => {
|
|
1320
|
+
if (!shouldForceKill(signal, options, killResult)) {
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
const timeout = getForceKillAfterTimeout(options);
|
|
1325
|
+
const t = setTimeout(() => {
|
|
1326
|
+
kill('SIGKILL');
|
|
1327
|
+
}, timeout);
|
|
1328
|
+
|
|
1329
|
+
// Guarded because there's no `.unref()` when `execa` is used in the renderer
|
|
1330
|
+
// process in Electron. This cannot be tested since we don't run tests in
|
|
1331
|
+
// Electron.
|
|
1332
|
+
// istanbul ignore else
|
|
1333
|
+
if (t.unref) {
|
|
1334
|
+
t.unref();
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
|
|
1339
|
+
|
|
1340
|
+
const isSigterm = signal => signal === require$$0.constants.signals.SIGTERM
|
|
1341
|
+
|| (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
|
|
1342
|
+
|
|
1343
|
+
const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {
|
|
1344
|
+
if (forceKillAfterTimeout === true) {
|
|
1345
|
+
return DEFAULT_FORCE_KILL_TIMEOUT;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
|
|
1349
|
+
throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
return forceKillAfterTimeout;
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
// `childProcess.cancel()`
|
|
1356
|
+
const spawnedCancel = (spawned, context) => {
|
|
1357
|
+
const killResult = spawned.kill();
|
|
1358
|
+
|
|
1359
|
+
if (killResult) {
|
|
1360
|
+
context.isCanceled = true;
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
const timeoutKill = (spawned, signal, reject) => {
|
|
1365
|
+
spawned.kill(signal);
|
|
1366
|
+
reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));
|
|
1367
|
+
};
|
|
1368
|
+
|
|
1369
|
+
// `timeout` option handling
|
|
1370
|
+
const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => {
|
|
1371
|
+
if (timeout === 0 || timeout === undefined) {
|
|
1372
|
+
return spawnedPromise;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
let timeoutId;
|
|
1376
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
1377
|
+
timeoutId = setTimeout(() => {
|
|
1378
|
+
timeoutKill(spawned, killSignal, reject);
|
|
1379
|
+
}, timeout);
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
const safeSpawnedPromise = spawnedPromise.finally(() => {
|
|
1383
|
+
clearTimeout(timeoutId);
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
return Promise.race([timeoutPromise, safeSpawnedPromise]);
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
const validateTimeout = ({timeout}) => {
|
|
1390
|
+
if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
|
|
1391
|
+
throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
// `cleanup` option handling
|
|
1396
|
+
const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => {
|
|
1397
|
+
if (!cleanup || detached) {
|
|
1398
|
+
return timedPromise;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
const removeExitHandler = signalExit(() => {
|
|
1402
|
+
spawned.kill();
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
return timedPromise.finally(() => {
|
|
1406
|
+
removeExitHandler();
|
|
1407
|
+
});
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
function isStream(stream) {
|
|
1411
|
+
return stream !== null
|
|
1412
|
+
&& typeof stream === 'object'
|
|
1413
|
+
&& typeof stream.pipe === 'function';
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// `input` option
|
|
1417
|
+
const handleInput = (spawned, input) => {
|
|
1418
|
+
// Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
|
|
1419
|
+
// @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
|
|
1420
|
+
if (input === undefined || spawned.stdin === undefined) {
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
if (isStream(input)) {
|
|
1425
|
+
input.pipe(spawned.stdin);
|
|
1426
|
+
} else {
|
|
1427
|
+
spawned.stdin.end(input);
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// `all` interleaves `stdout` and `stderr`
|
|
1432
|
+
const makeAllStream = (spawned, {all}) => {
|
|
1433
|
+
if (!all || (!spawned.stdout && !spawned.stderr)) {
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
const mixed = mergeStream();
|
|
1438
|
+
|
|
1439
|
+
if (spawned.stdout) {
|
|
1440
|
+
mixed.add(spawned.stdout);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
if (spawned.stderr) {
|
|
1444
|
+
mixed.add(spawned.stderr);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
return mixed;
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
// On failure, `result.stdout|stderr|all` should contain the currently buffered stream
|
|
1451
|
+
const getBufferedData = async (stream, streamPromise) => {
|
|
1452
|
+
if (!stream) {
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
stream.destroy();
|
|
1457
|
+
|
|
1458
|
+
try {
|
|
1459
|
+
return await streamPromise;
|
|
1460
|
+
} catch (error) {
|
|
1461
|
+
return error.bufferedData;
|
|
1462
|
+
}
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1465
|
+
const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
|
|
1466
|
+
if (!stream || !buffer) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
if (encoding) {
|
|
1471
|
+
return getStream(stream, {encoding, maxBuffer});
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
return getStream.buffer(stream, {maxBuffer});
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
// Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)
|
|
1478
|
+
const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {
|
|
1479
|
+
const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});
|
|
1480
|
+
const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});
|
|
1481
|
+
const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});
|
|
1482
|
+
|
|
1483
|
+
try {
|
|
1484
|
+
return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
|
|
1485
|
+
} catch (error) {
|
|
1486
|
+
return Promise.all([
|
|
1487
|
+
{error, signal: error.signal, timedOut: error.timedOut},
|
|
1488
|
+
getBufferedData(stdout, stdoutPromise),
|
|
1489
|
+
getBufferedData(stderr, stderrPromise),
|
|
1490
|
+
getBufferedData(all, allPromise),
|
|
1491
|
+
]);
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
|
|
1495
|
+
const nativePromisePrototype = (async () => {})().constructor.prototype;
|
|
1496
|
+
const descriptors = ['then', 'catch', 'finally'].map(property => [
|
|
1497
|
+
property,
|
|
1498
|
+
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
|
|
1499
|
+
]);
|
|
1500
|
+
|
|
1501
|
+
// The return value is a mixin of `childProcess` and `Promise`
|
|
1502
|
+
const mergePromise = (spawned, promise) => {
|
|
1503
|
+
for (const [property, descriptor] of descriptors) {
|
|
1504
|
+
// Starting the main `promise` is deferred to avoid consuming streams
|
|
1505
|
+
const value = typeof promise === 'function'
|
|
1506
|
+
? (...args) => Reflect.apply(descriptor.value, promise(), args)
|
|
1507
|
+
: descriptor.value.bind(promise);
|
|
1508
|
+
|
|
1509
|
+
Reflect.defineProperty(spawned, property, {...descriptor, value});
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
return spawned;
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
// Use promises instead of `child_process` events
|
|
1516
|
+
const getSpawnedPromise = spawned => new Promise((resolve, reject) => {
|
|
1517
|
+
spawned.on('exit', (exitCode, signal) => {
|
|
1518
|
+
resolve({exitCode, signal});
|
|
1519
|
+
});
|
|
1520
|
+
|
|
1521
|
+
spawned.on('error', error => {
|
|
1522
|
+
reject(error);
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
if (spawned.stdin) {
|
|
1526
|
+
spawned.stdin.on('error', error => {
|
|
1527
|
+
reject(error);
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
const normalizeArgs = (file, args = []) => {
|
|
1533
|
+
if (!Array.isArray(args)) {
|
|
1534
|
+
return [file];
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
return [file, ...args];
|
|
1538
|
+
};
|
|
1539
|
+
|
|
1540
|
+
const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
|
|
1541
|
+
const DOUBLE_QUOTES_REGEXP = /"/g;
|
|
1542
|
+
|
|
1543
|
+
const escapeArg = arg => {
|
|
1544
|
+
if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
|
|
1545
|
+
return arg;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`;
|
|
1549
|
+
};
|
|
1550
|
+
|
|
1551
|
+
const joinCommand = (file, args) => normalizeArgs(file, args).join(' ');
|
|
1552
|
+
|
|
1553
|
+
const getEscapedCommand = (file, args) => normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' ');
|
|
1554
|
+
|
|
1555
|
+
const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
|
|
1556
|
+
|
|
1557
|
+
const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => {
|
|
1558
|
+
const env = extendEnv ? {...process$1.env, ...envOption} : envOption;
|
|
1559
|
+
|
|
1560
|
+
if (preferLocal) {
|
|
1561
|
+
return npmRunPathEnv({env, cwd: localDir, execPath});
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
return env;
|
|
1565
|
+
};
|
|
1566
|
+
|
|
1567
|
+
const handleArguments = (file, args, options = {}) => {
|
|
1568
|
+
const parsed = crossSpawn._parse(file, args, options);
|
|
1569
|
+
file = parsed.command;
|
|
1570
|
+
args = parsed.args;
|
|
1571
|
+
options = parsed.options;
|
|
1572
|
+
|
|
1573
|
+
options = {
|
|
1574
|
+
maxBuffer: DEFAULT_MAX_BUFFER,
|
|
1575
|
+
buffer: true,
|
|
1576
|
+
stripFinalNewline: true,
|
|
1577
|
+
extendEnv: true,
|
|
1578
|
+
preferLocal: false,
|
|
1579
|
+
localDir: options.cwd || process$1.cwd(),
|
|
1580
|
+
execPath: process$1.execPath,
|
|
1581
|
+
encoding: 'utf8',
|
|
1582
|
+
reject: true,
|
|
1583
|
+
cleanup: true,
|
|
1584
|
+
all: false,
|
|
1585
|
+
windowsHide: true,
|
|
1586
|
+
...options,
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
options.env = getEnv(options);
|
|
1590
|
+
|
|
1591
|
+
options.stdio = normalizeStdio(options);
|
|
1592
|
+
|
|
1593
|
+
if (process$1.platform === 'win32' && path.basename(file, '.exe') === 'cmd') {
|
|
1594
|
+
// #116
|
|
1595
|
+
args.unshift('/q');
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
return {file, args, options, parsed};
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
const handleOutput = (options, value, error) => {
|
|
1602
|
+
if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
|
|
1603
|
+
// When `execaSync()` errors, we normalize it to '' to mimic `execa()`
|
|
1604
|
+
return error === undefined ? undefined : '';
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
if (options.stripFinalNewline) {
|
|
1608
|
+
return stripFinalNewline(value);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
return value;
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
function execa(file, args, options) {
|
|
1615
|
+
const parsed = handleArguments(file, args, options);
|
|
1616
|
+
const command = joinCommand(file, args);
|
|
1617
|
+
const escapedCommand = getEscapedCommand(file, args);
|
|
1618
|
+
|
|
1619
|
+
validateTimeout(parsed.options);
|
|
1620
|
+
|
|
1621
|
+
let spawned;
|
|
1622
|
+
try {
|
|
1623
|
+
spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
|
|
1624
|
+
} catch (error) {
|
|
1625
|
+
// Ensure the returned error is always both a promise and a child process
|
|
1626
|
+
const dummySpawned = new childProcess.ChildProcess();
|
|
1627
|
+
const errorPromise = Promise.reject(makeError({
|
|
1628
|
+
error,
|
|
1629
|
+
stdout: '',
|
|
1630
|
+
stderr: '',
|
|
1631
|
+
all: '',
|
|
1632
|
+
command,
|
|
1633
|
+
escapedCommand,
|
|
1634
|
+
parsed,
|
|
1635
|
+
timedOut: false,
|
|
1636
|
+
isCanceled: false,
|
|
1637
|
+
killed: false,
|
|
1638
|
+
}));
|
|
1639
|
+
return mergePromise(dummySpawned, errorPromise);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
const spawnedPromise = getSpawnedPromise(spawned);
|
|
1643
|
+
const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
|
|
1644
|
+
const processDone = setExitHandler(spawned, parsed.options, timedPromise);
|
|
1645
|
+
|
|
1646
|
+
const context = {isCanceled: false};
|
|
1647
|
+
|
|
1648
|
+
spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
|
|
1649
|
+
spawned.cancel = spawnedCancel.bind(null, spawned, context);
|
|
1650
|
+
|
|
1651
|
+
const handlePromise = async () => {
|
|
1652
|
+
const [{error, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
|
|
1653
|
+
const stdout = handleOutput(parsed.options, stdoutResult);
|
|
1654
|
+
const stderr = handleOutput(parsed.options, stderrResult);
|
|
1655
|
+
const all = handleOutput(parsed.options, allResult);
|
|
1656
|
+
|
|
1657
|
+
if (error || exitCode !== 0 || signal !== null) {
|
|
1658
|
+
const returnedError = makeError({
|
|
1659
|
+
error,
|
|
1660
|
+
exitCode,
|
|
1661
|
+
signal,
|
|
1662
|
+
stdout,
|
|
1663
|
+
stderr,
|
|
1664
|
+
all,
|
|
1665
|
+
command,
|
|
1666
|
+
escapedCommand,
|
|
1667
|
+
parsed,
|
|
1668
|
+
timedOut,
|
|
1669
|
+
isCanceled: context.isCanceled,
|
|
1670
|
+
killed: spawned.killed,
|
|
1671
|
+
});
|
|
1672
|
+
|
|
1673
|
+
if (!parsed.options.reject) {
|
|
1674
|
+
return returnedError;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
throw returnedError;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
return {
|
|
1681
|
+
command,
|
|
1682
|
+
escapedCommand,
|
|
1683
|
+
exitCode: 0,
|
|
1684
|
+
stdout,
|
|
1685
|
+
stderr,
|
|
1686
|
+
all,
|
|
1687
|
+
failed: false,
|
|
1688
|
+
timedOut: false,
|
|
1689
|
+
isCanceled: false,
|
|
1690
|
+
killed: false,
|
|
1691
|
+
};
|
|
1692
|
+
};
|
|
1693
|
+
|
|
1694
|
+
const handlePromiseOnce = onetime(handlePromise);
|
|
1695
|
+
|
|
1696
|
+
handleInput(spawned, parsed.options.input);
|
|
1697
|
+
|
|
1698
|
+
spawned.all = makeAllStream(spawned, parsed.options);
|
|
1699
|
+
|
|
1700
|
+
return mergePromise(spawned, handlePromiseOnce);
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
var version = "0.0.115";
|
|
640
1704
|
|
|
641
1705
|
const cli = cac("vitest");
|
|
642
1706
|
cli.version(version).option("-r, --root <path>", "root path").option("-c, --config <path>", "path to config file").option("-u, --update", "update snapshot").option("-w, --watch", "watch mode").option("-o, --open", "open Vitest UI").option("--api", "listen to port and serve API").option("--threads", "enabled threads", { default: true }).option("--silent", "silent console.log output from tests").option("--reporter <name>", "reporter").option("--coverage", "use c8 for coverage").option("--run", "do not watch").option("--global", "inject apis globally").option("--dom", "mock browser api with happy-dom").option("--environment <env>", "runner environment", { default: "node" }).option("--passWithNoTests", "pass when no tests found").help();
|
|
@@ -647,19 +1711,33 @@ cli.command("[...filters]").action(dev);
|
|
|
647
1711
|
cli.parse();
|
|
648
1712
|
async function dev(cliFilters, argv) {
|
|
649
1713
|
if (argv.watch == null)
|
|
650
|
-
argv.watch = !process.env.CI && !
|
|
1714
|
+
argv.watch = !process.env.CI && !argv.run;
|
|
651
1715
|
await run(cliFilters, argv);
|
|
652
1716
|
}
|
|
653
1717
|
async function run(cliFilters, options) {
|
|
654
1718
|
process.env.VITEST = "true";
|
|
655
1719
|
process.env.NODE_ENV = "test";
|
|
1720
|
+
if (!await ensurePackageInstalled("vite"))
|
|
1721
|
+
process.exit(1);
|
|
1722
|
+
if (typeof options.coverage === "boolean")
|
|
1723
|
+
options.coverage = { enabled: options.coverage };
|
|
656
1724
|
const ctx = await createVitest(options);
|
|
657
|
-
|
|
658
|
-
|
|
1725
|
+
if (ctx.config.coverage.enabled) {
|
|
1726
|
+
if (!await ensurePackageInstalled("c8"))
|
|
1727
|
+
process.exit(1);
|
|
1728
|
+
if (!process.env.NODE_V8_COVERAGE) {
|
|
1729
|
+
process.env.NODE_V8_COVERAGE = ctx.config.coverage.tempDirectory;
|
|
1730
|
+
const { exitCode } = await execa(process.argv0, process.argv.slice(1), { stdio: "inherit" });
|
|
1731
|
+
process.exit(exitCode);
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
659
1734
|
if (ctx.config.environment && ctx.config.environment !== "node") {
|
|
660
1735
|
if (!await ensurePackageInstalled(ctx.config.environment))
|
|
661
1736
|
process.exit(1);
|
|
662
1737
|
}
|
|
1738
|
+
if (process.stdin.isTTY && ctx.config.watch)
|
|
1739
|
+
registerConsoleShortcuts(ctx);
|
|
1740
|
+
process.chdir(ctx.config.root);
|
|
663
1741
|
ctx.onServerRestarted(() => {
|
|
664
1742
|
ctx.start(cliFilters);
|
|
665
1743
|
});
|
|
@@ -676,16 +1754,14 @@ async function run(cliFilters, options) {
|
|
|
676
1754
|
process.exit();
|
|
677
1755
|
}
|
|
678
1756
|
function registerConsoleShortcuts(ctx) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
});
|
|
690
|
-
}
|
|
1757
|
+
require$$0$1.emitKeypressEvents(process.stdin);
|
|
1758
|
+
process.stdin.setRawMode(true);
|
|
1759
|
+
process.stdin.on("keypress", (str, key) => {
|
|
1760
|
+
if (str === "" || str === "" || key && key.ctrl && key.name === "c")
|
|
1761
|
+
process.exit();
|
|
1762
|
+
if (ctx.runningPromise)
|
|
1763
|
+
return;
|
|
1764
|
+
if (ctx.isFirstRun)
|
|
1765
|
+
process.exit();
|
|
1766
|
+
});
|
|
691
1767
|
}
|