vitest 0.18.0 → 0.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/LICENSE.md +6 -6
  2. package/dist/browser.d.ts +1850 -0
  3. package/dist/browser.mjs +20 -0
  4. package/dist/{chunk-api-setup.63babd7c.mjs → chunk-api-setup.0cf2c96a.mjs} +37 -11
  5. package/dist/{chunk-constants.8eb2ed35.mjs → chunk-constants.38b43a44.mjs} +3 -3
  6. package/dist/{chunk-env-node.26c72624.mjs → chunk-defaults.ed196a9a.mjs} +458 -455
  7. package/dist/{chunk-install-pkg.2dcb2c04.mjs → chunk-install-pkg.6c6dc0c2.mjs} +11 -10
  8. package/dist/chunk-integrations-globals.1018e651.mjs +24 -0
  9. package/dist/chunk-node-git.9058b82a.mjs +1139 -0
  10. package/dist/chunk-runtime-chain.f2e00f4c.mjs +2039 -0
  11. package/dist/{vendor-entry.78de67ab.mjs → chunk-runtime-error.606e0393.mjs} +167 -183
  12. package/dist/{chunk-runtime-chain.eb764dff.mjs → chunk-runtime-hooks.d4cadf47.mjs} +33 -2012
  13. package/dist/{chunk-runtime-mocker.79ccc3de.mjs → chunk-runtime-mocker.dfdfd57b.mjs} +70 -22
  14. package/dist/{chunk-runtime-rpc.cc6a06a2.mjs → chunk-runtime-rpc.45d8ee19.mjs} +1 -1
  15. package/dist/{chunk-utils-global.1b22c4fd.mjs → chunk-utils-global.2aa95025.mjs} +11 -6
  16. package/dist/{chunk-utils-source-map.957e7756.mjs → chunk-utils-source-map.8b066ce2.mjs} +2 -2
  17. package/dist/{chunk-vite-node-externalize.0791f2ed.mjs → chunk-vite-node-externalize.e9af6472.mjs} +105 -1174
  18. package/dist/chunk-vite-node-utils.ad73f2ab.mjs +1433 -0
  19. package/dist/cli.mjs +9 -11
  20. package/dist/config.cjs +4 -1
  21. package/dist/config.d.ts +1 -0
  22. package/dist/config.mjs +4 -1
  23. package/dist/entry.mjs +54 -10
  24. package/dist/index.d.ts +56 -27
  25. package/dist/index.mjs +12 -9
  26. package/dist/node.d.ts +37 -18
  27. package/dist/node.mjs +10 -12
  28. package/dist/spy.mjs +102 -2
  29. package/dist/suite.mjs +13 -0
  30. package/dist/vendor-index.61438b77.mjs +335 -0
  31. package/dist/{vendor-index.4bf9c627.mjs → vendor-index.62ce5c33.mjs} +11 -343
  32. package/dist/worker.mjs +6 -6
  33. package/package.json +20 -12
  34. package/dist/chunk-integrations-globals.61e4d6ae.mjs +0 -26
  35. package/dist/chunk-integrations-spy.674b628e.mjs +0 -102
  36. package/dist/chunk-vite-node-utils.af8ead96.mjs +0 -9195
@@ -1,32 +1,30 @@
1
- import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, e as envPackageNames } from './chunk-env-node.26c72624.mjs';
2
- import { j as join, o as basename, d as dirname, q as resolve, A as AggregateErrorPonyfill, p as picocolors, s as slash$2, t as isAbsolute, u as relative, v as isNode, x as getTests, e as getFullName, y as hasFailed, z as hasFailedSnapshot, B as safeSetInterval, C as safeClearInterval, D as getSuites, f as safeSetTimeout, E as shuffle, F as toArray$1, G as normalize, n as noop$1, h as safeClearTimeout, H as deepMerge, I as toNamespacedPath, g as getCallLastIndex, l as notNullish, J as ensurePackageInstalled, K as stdout } from './chunk-utils-global.1b22c4fd.mjs';
1
+ import { j as join, D as basename, d as dirname, C as resolve, E as AggregateErrorPonyfill, p as picocolors, F as isAbsolute, G as relative, c as slash$2, t as isNode, v as relativePath, H as getTests, h as getFullName, B as hasFailed, I as hasFailedSnapshot, J as safeSetInterval, K as safeClearInterval, L as getSuites, s as safeSetTimeout, z as shuffle, u as toArray$1, M as normalize, n as noop$1, k as safeClearTimeout, N as deepMerge, O as toNamespacedPath, b as getCallLastIndex, l as notNullish, P as ensurePackageInstalled, Q as stdout } from './chunk-utils-global.2aa95025.mjs';
2
+ import { p as pLimit, c as configDefaults, r as resolveC8Options, a as cleanCoverage, b as reportCoverage, d as envPackageNames } from './chunk-defaults.ed196a9a.mjs';
3
3
  import { loadConfigFromFile, createServer, mergeConfig } from 'vite';
4
4
  import path$a from 'path';
5
- import url, { fileURLToPath, pathToFileURL } from 'url';
5
+ import _url, { fileURLToPath } from 'url';
6
6
  import process$1 from 'process';
7
7
  import fs$8, { promises, existsSync, readFileSync } from 'fs';
8
- import { d as distDir, c as configFiles, a as defaultPort } from './chunk-constants.8eb2ed35.mjs';
9
- import require$$0, { cpus, hostname, constants as constants$5 } from 'os';
10
- import require$$0$1 from 'util';
11
- import require$$0$2 from 'stream';
8
+ import { d as distDir, c as configFiles, a as defaultPort } from './chunk-constants.38b43a44.mjs';
9
+ import require$$0, { cpus, hostname } from 'os';
10
+ import util$2 from 'util';
11
+ import require$$0$1 from 'stream';
12
12
  import require$$2 from 'events';
13
13
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
14
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.af8ead96.mjs';
14
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap, c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-utils.ad73f2ab.mjs';
15
15
  import createDebug from 'debug';
16
16
  import { MessageChannel } from 'worker_threads';
17
17
  import { Tinypool } from 'tinypool';
18
18
  import { performance } from 'perf_hooks';
19
- import { c as stripAnsi, d as cliTruncate, b as parseStacktrace, e as stringWidth, h as ansiStyles, i as sliceAnsi, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, a as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.957e7756.mjs';
19
+ import { c as stripAnsi, d as cliTruncate, p as parseStacktrace, e as stringWidth, h as ansiStyles, i as sliceAnsi, j as interpretSourcePos, s as stringify$5, u as unifiedDiff, b as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.8b066ce2.mjs';
20
20
  import { resolveModule } from 'local-pkg';
21
21
  import { createHash } from 'crypto';
22
- import { Buffer } from 'buffer';
23
- import childProcess from 'child_process';
24
- import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn, o as onetime$1 } from './vendor-index.4bf9c627.mjs';
22
+ import { o as onetime, s as signalExit } from './vendor-index.61438b77.mjs';
25
23
  import MagicString from './chunk-magic-string.efe26975.mjs';
26
- import require$$0$3 from 'readline';
24
+ import require$$0$2 from 'readline';
27
25
  import { p as prompts } from './vendor-index.de788b6a.mjs';
28
26
 
29
- var version$1 = "0.18.0";
27
+ var version$1 = "0.19.1";
30
28
 
31
29
  class EndError extends Error {
32
30
  constructor(value) {
@@ -935,7 +933,7 @@ var toRegexRange_1 = toRegexRange$1;
935
933
  * Licensed under the MIT License.
936
934
  */
937
935
 
938
- const util$1 = require$$0$1;
936
+ const util$1 = util$2;
939
937
  const toRegexRange = toRegexRange_1;
940
938
 
941
939
  const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
@@ -3972,7 +3970,7 @@ var picomatch_1 = picomatch$1;
3972
3970
  module.exports = picomatch_1;
3973
3971
  } (picomatch$2));
3974
3972
 
3975
- const util = require$$0$1;
3973
+ const util = util$2;
3976
3974
  const braces = braces_1;
3977
3975
  const picomatch = picomatch$2.exports;
3978
3976
  const utils$b = utils$f;
@@ -4616,7 +4614,7 @@ var stream$4 = {};
4616
4614
  * Copyright (c) 2014-2020 Teambition
4617
4615
  * Licensed under the MIT license.
4618
4616
  */
4619
- const Stream = require$$0$2;
4617
+ const Stream = require$$0$1;
4620
4618
  const PassThrough = Stream.PassThrough;
4621
4619
  const slice = Array.prototype.slice;
4622
4620
 
@@ -5900,7 +5898,7 @@ function callSuccessCallback(callback, entries) {
5900
5898
  var stream$1 = {};
5901
5899
 
5902
5900
  Object.defineProperty(stream$1, "__esModule", { value: true });
5903
- const stream_1$5 = require$$0$2;
5901
+ const stream_1$5 = require$$0$1;
5904
5902
  const async_1$2 = async$2;
5905
5903
  class StreamProvider {
5906
5904
  constructor(_root, _settings) {
@@ -6108,7 +6106,7 @@ class Reader {
6108
6106
  reader.default = Reader;
6109
6107
 
6110
6108
  Object.defineProperty(stream$2, "__esModule", { value: true });
6111
- const stream_1$3 = require$$0$2;
6109
+ const stream_1$3 = require$$0$1;
6112
6110
  const fsStat$1 = out$3;
6113
6111
  const fsWalk$1 = out$2;
6114
6112
  const reader_1$1 = reader;
@@ -6506,7 +6504,7 @@ async$6.default = ProviderAsync;
6506
6504
  var stream = {};
6507
6505
 
6508
6506
  Object.defineProperty(stream, "__esModule", { value: true });
6509
- const stream_1$1 = require$$0$2;
6507
+ const stream_1$1 = require$$0$1;
6510
6508
  const stream_2 = stream$2;
6511
6509
  const provider_1$1 = provider;
6512
6510
  class ProviderStream extends provider_1$1.default {
@@ -6736,10 +6734,10 @@ function assertPatternsInput(input) {
6736
6734
  var out = FastGlob;
6737
6735
 
6738
6736
  const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
6739
- const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
6737
+ const ESM_FOLDER_RE = /\/(es|esm)\/(.*\.js)$/;
6740
6738
  const defaultInline = [
6741
6739
  /virtual:/,
6742
- /\.ts$/
6740
+ /\.[mc]?ts$/
6743
6741
  ];
6744
6742
  const depsExternal = [
6745
6743
  /\.cjs\.js$/,
@@ -6761,6 +6759,7 @@ function guessCJSversion(id) {
6761
6759
  for (const i of [
6762
6760
  id.replace(ESM_FOLDER_RE, "/umd/$1"),
6763
6761
  id.replace(ESM_FOLDER_RE, "/cjs/$1"),
6762
+ id.replace(ESM_FOLDER_RE, "/lib/$1"),
6764
6763
  id.replace(ESM_FOLDER_RE, "/$1")
6765
6764
  ]) {
6766
6765
  if (existsSync(i))
@@ -6979,7 +6978,7 @@ function addSnapshotResult(summary, result) {
6979
6978
  summary.total += result.added + result.matched + result.unmatched + result.updated;
6980
6979
  }
6981
6980
 
6982
- const workerPath = pathToFileURL(resolve(distDir, "./worker.mjs")).href;
6981
+ const workerPath = _url.pathToFileURL(resolve(distDir, "./worker.mjs")).href;
6983
6982
  function createPool(ctx) {
6984
6983
  var _a;
6985
6984
  const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
@@ -7083,6 +7082,10 @@ function createChannel(ctx) {
7083
7082
  resolveId(id, importer) {
7084
7083
  return ctx.vitenode.resolveId(id, importer);
7085
7084
  },
7085
+ onPathsCollected(paths) {
7086
+ ctx.state.collectPaths(paths);
7087
+ ctx.report("onPathsCollected", paths);
7088
+ },
7086
7089
  onCollected(files) {
7087
7090
  ctx.state.collectFiles(files);
7088
7091
  ctx.report("onCollected", files);
@@ -7286,7 +7289,7 @@ class BaseReporter {
7286
7289
  this.start = performance.now();
7287
7290
  }
7288
7291
  relative(path) {
7289
- return relative(this.ctx.config.root, path);
7292
+ return relativePath(this.ctx.config.root, path);
7290
7293
  }
7291
7294
  async onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
7292
7295
  this.end = performance.now();
@@ -7816,7 +7819,8 @@ class JsonReporter {
7816
7819
  status: StatusMap[((_a2 = t.result) == null ? void 0 : _a2.state) || t.mode] || "skipped",
7817
7820
  title: t.name,
7818
7821
  duration: (_b2 = t.result) == null ? void 0 : _b2.duration,
7819
- failureMessages: ((_d = (_c = t.result) == null ? void 0 : _c.error) == null ? void 0 : _d.message) == null ? [] : [t.result.error.message]
7822
+ failureMessages: ((_d = (_c = t.result) == null ? void 0 : _c.error) == null ? void 0 : _d.message) == null ? [] : [t.result.error.message],
7823
+ location: this.getFailureLocation(t)
7820
7824
  };
7821
7825
  });
7822
7826
  if (tests2.some((t) => {
@@ -7869,6 +7873,18 @@ class JsonReporter {
7869
7873
  this.ctx.logger.log(report);
7870
7874
  }
7871
7875
  }
7876
+ getFailureLocation(test) {
7877
+ var _a;
7878
+ const error = (_a = test.result) == null ? void 0 : _a.error;
7879
+ if (!error)
7880
+ return;
7881
+ const stack = parseStacktrace(error);
7882
+ const frame = stack[stack.length - 1];
7883
+ if (!frame)
7884
+ return;
7885
+ const pos = frame.sourcePos || frame;
7886
+ return { line: pos.line, column: pos.column };
7887
+ }
7872
7888
  }
7873
7889
 
7874
7890
  class VerboseReporter extends DefaultReporter {
@@ -8195,6 +8211,7 @@ function createReporters(reporterReferences, runner) {
8195
8211
  class StateManager {
8196
8212
  constructor() {
8197
8213
  this.filesMap = /* @__PURE__ */ new Map();
8214
+ this.pathsSet = /* @__PURE__ */ new Set();
8198
8215
  this.idMap = /* @__PURE__ */ new Map();
8199
8216
  this.taskFileMap = /* @__PURE__ */ new WeakMap();
8200
8217
  this.errorsSet = /* @__PURE__ */ new Set();
@@ -8209,6 +8226,9 @@ class StateManager {
8209
8226
  getUnhandledErrors() {
8210
8227
  return Array.from(this.errorsSet.values());
8211
8228
  }
8229
+ getPaths() {
8230
+ return Array.from(this.pathsSet);
8231
+ }
8212
8232
  getFiles(keys) {
8213
8233
  if (keys)
8214
8234
  return keys.map((key) => this.filesMap.get(key)).filter(Boolean);
@@ -8223,6 +8243,11 @@ class StateManager {
8223
8243
  return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
8224
8244
  }).map((i) => i.filepath);
8225
8245
  }
8246
+ collectPaths(paths = []) {
8247
+ paths.forEach((path) => {
8248
+ this.pathsSet.add(path);
8249
+ });
8250
+ }
8226
8251
  collectFiles(files = []) {
8227
8252
  files.forEach((file) => {
8228
8253
  this.filesMap.set(file.filepath, file);
@@ -8429,7 +8454,7 @@ const extraInlineDeps = [
8429
8454
  ];
8430
8455
  function resolveApiConfig(options) {
8431
8456
  let api;
8432
- if (options.ui && !options.api)
8457
+ if ((options.ui || options.browser) && !options.api)
8433
8458
  api = { port: defaultPort };
8434
8459
  else if (options.api === true)
8435
8460
  api = { port: defaultPort };
@@ -8530,1126 +8555,6 @@ function resolveConfig(options, viteConfig) {
8530
8555
  return resolved;
8531
8556
  }
8532
8557
 
8533
- function stripFinalNewline(input) {
8534
- const LF = typeof input === 'string' ? '\n' : '\n'.charCodeAt();
8535
- const CR = typeof input === 'string' ? '\r' : '\r'.charCodeAt();
8536
-
8537
- if (input[input.length - 1] === LF) {
8538
- input = input.slice(0, -1);
8539
- }
8540
-
8541
- if (input[input.length - 1] === CR) {
8542
- input = input.slice(0, -1);
8543
- }
8544
-
8545
- return input;
8546
- }
8547
-
8548
- function pathKey(options = {}) {
8549
- const {
8550
- env = process.env,
8551
- platform = process.platform
8552
- } = options;
8553
-
8554
- if (platform !== 'win32') {
8555
- return 'PATH';
8556
- }
8557
-
8558
- return Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path';
8559
- }
8560
-
8561
- function npmRunPath(options = {}) {
8562
- const {
8563
- cwd = process$1.cwd(),
8564
- path: path_ = process$1.env[pathKey()],
8565
- execPath = process$1.execPath,
8566
- } = options;
8567
-
8568
- let previous;
8569
- const cwdString = cwd instanceof URL ? url.fileURLToPath(cwd) : cwd;
8570
- let cwdPath = path$a.resolve(cwdString);
8571
- const result = [];
8572
-
8573
- while (previous !== cwdPath) {
8574
- result.push(path$a.join(cwdPath, 'node_modules/.bin'));
8575
- previous = cwdPath;
8576
- cwdPath = path$a.resolve(cwdPath, '..');
8577
- }
8578
-
8579
- // Ensure the running `node` binary is used.
8580
- result.push(path$a.resolve(cwdString, execPath, '..'));
8581
-
8582
- return [...result, path_].join(path$a.delimiter);
8583
- }
8584
-
8585
- function npmRunPathEnv({env = process$1.env, ...options} = {}) {
8586
- env = {...env};
8587
-
8588
- const path = pathKey({env});
8589
- options.path = env[path];
8590
- env[path] = npmRunPath(options);
8591
-
8592
- return env;
8593
- }
8594
-
8595
- const copyProperty = (to, from, property, ignoreNonConfigurable) => {
8596
- // `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
8597
- // `Function#prototype` is non-writable and non-configurable so can never be modified.
8598
- if (property === 'length' || property === 'prototype') {
8599
- return;
8600
- }
8601
-
8602
- // `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.
8603
- if (property === 'arguments' || property === 'caller') {
8604
- return;
8605
- }
8606
-
8607
- const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
8608
- const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
8609
-
8610
- if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
8611
- return;
8612
- }
8613
-
8614
- Object.defineProperty(to, property, fromDescriptor);
8615
- };
8616
-
8617
- // `Object.defineProperty()` throws if the property exists, is not configurable and either:
8618
- // - one its descriptors is changed
8619
- // - it is non-writable and its value is changed
8620
- const canCopyProperty = function (toDescriptor, fromDescriptor) {
8621
- return toDescriptor === undefined || toDescriptor.configurable || (
8622
- toDescriptor.writable === fromDescriptor.writable &&
8623
- toDescriptor.enumerable === fromDescriptor.enumerable &&
8624
- toDescriptor.configurable === fromDescriptor.configurable &&
8625
- (toDescriptor.writable || toDescriptor.value === fromDescriptor.value)
8626
- );
8627
- };
8628
-
8629
- const changePrototype = (to, from) => {
8630
- const fromPrototype = Object.getPrototypeOf(from);
8631
- if (fromPrototype === Object.getPrototypeOf(to)) {
8632
- return;
8633
- }
8634
-
8635
- Object.setPrototypeOf(to, fromPrototype);
8636
- };
8637
-
8638
- const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
8639
-
8640
- const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, 'toString');
8641
- const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, 'name');
8642
-
8643
- // We call `from.toString()` early (not lazily) to ensure `from` can be garbage collected.
8644
- // We use `bind()` instead of a closure for the same reason.
8645
- // Calling `from.toString()` early also allows caching it in case `to.toString()` is called several times.
8646
- const changeToString = (to, from, name) => {
8647
- const withName = name === '' ? '' : `with ${name.trim()}() `;
8648
- const newToString = wrappedToString.bind(null, withName, from.toString());
8649
- // Ensure `to.toString.toString` is non-enumerable and has the same `same`
8650
- Object.defineProperty(newToString, 'name', toStringName);
8651
- Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString});
8652
- };
8653
-
8654
- function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {
8655
- const {name} = to;
8656
-
8657
- for (const property of Reflect.ownKeys(from)) {
8658
- copyProperty(to, from, property, ignoreNonConfigurable);
8659
- }
8660
-
8661
- changePrototype(to, from);
8662
- changeToString(to, from, name);
8663
-
8664
- return to;
8665
- }
8666
-
8667
- const calledFunctions = new WeakMap();
8668
-
8669
- const onetime = (function_, options = {}) => {
8670
- if (typeof function_ !== 'function') {
8671
- throw new TypeError('Expected a function');
8672
- }
8673
-
8674
- let returnValue;
8675
- let callCount = 0;
8676
- const functionName = function_.displayName || function_.name || '<anonymous>';
8677
-
8678
- const onetime = function (...arguments_) {
8679
- calledFunctions.set(onetime, ++callCount);
8680
-
8681
- if (callCount === 1) {
8682
- returnValue = function_.apply(this, arguments_);
8683
- function_ = null;
8684
- } else if (options.throw === true) {
8685
- throw new Error(`Function \`${functionName}\` can only be called once`);
8686
- }
8687
-
8688
- return returnValue;
8689
- };
8690
-
8691
- mimicFunction(onetime, function_);
8692
- calledFunctions.set(onetime, callCount);
8693
-
8694
- return onetime;
8695
- };
8696
-
8697
- onetime.callCount = function_ => {
8698
- if (!calledFunctions.has(function_)) {
8699
- throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
8700
- }
8701
-
8702
- return calledFunctions.get(function_);
8703
- };
8704
-
8705
- const getRealtimeSignals=function(){
8706
- const length=SIGRTMAX-SIGRTMIN+1;
8707
- return Array.from({length},getRealtimeSignal);
8708
- };
8709
-
8710
- const getRealtimeSignal=function(value,index){
8711
- return {
8712
- name:`SIGRT${index+1}`,
8713
- number:SIGRTMIN+index,
8714
- action:"terminate",
8715
- description:"Application-specific signal (realtime)",
8716
- standard:"posix"};
8717
-
8718
- };
8719
-
8720
- const SIGRTMIN=34;
8721
- const SIGRTMAX=64;
8722
-
8723
- const SIGNALS=[
8724
- {
8725
- name:"SIGHUP",
8726
- number:1,
8727
- action:"terminate",
8728
- description:"Terminal closed",
8729
- standard:"posix"},
8730
-
8731
- {
8732
- name:"SIGINT",
8733
- number:2,
8734
- action:"terminate",
8735
- description:"User interruption with CTRL-C",
8736
- standard:"ansi"},
8737
-
8738
- {
8739
- name:"SIGQUIT",
8740
- number:3,
8741
- action:"core",
8742
- description:"User interruption with CTRL-\\",
8743
- standard:"posix"},
8744
-
8745
- {
8746
- name:"SIGILL",
8747
- number:4,
8748
- action:"core",
8749
- description:"Invalid machine instruction",
8750
- standard:"ansi"},
8751
-
8752
- {
8753
- name:"SIGTRAP",
8754
- number:5,
8755
- action:"core",
8756
- description:"Debugger breakpoint",
8757
- standard:"posix"},
8758
-
8759
- {
8760
- name:"SIGABRT",
8761
- number:6,
8762
- action:"core",
8763
- description:"Aborted",
8764
- standard:"ansi"},
8765
-
8766
- {
8767
- name:"SIGIOT",
8768
- number:6,
8769
- action:"core",
8770
- description:"Aborted",
8771
- standard:"bsd"},
8772
-
8773
- {
8774
- name:"SIGBUS",
8775
- number:7,
8776
- action:"core",
8777
- description:
8778
- "Bus error due to misaligned, non-existing address or paging error",
8779
- standard:"bsd"},
8780
-
8781
- {
8782
- name:"SIGEMT",
8783
- number:7,
8784
- action:"terminate",
8785
- description:"Command should be emulated but is not implemented",
8786
- standard:"other"},
8787
-
8788
- {
8789
- name:"SIGFPE",
8790
- number:8,
8791
- action:"core",
8792
- description:"Floating point arithmetic error",
8793
- standard:"ansi"},
8794
-
8795
- {
8796
- name:"SIGKILL",
8797
- number:9,
8798
- action:"terminate",
8799
- description:"Forced termination",
8800
- standard:"posix",
8801
- forced:true},
8802
-
8803
- {
8804
- name:"SIGUSR1",
8805
- number:10,
8806
- action:"terminate",
8807
- description:"Application-specific signal",
8808
- standard:"posix"},
8809
-
8810
- {
8811
- name:"SIGSEGV",
8812
- number:11,
8813
- action:"core",
8814
- description:"Segmentation fault",
8815
- standard:"ansi"},
8816
-
8817
- {
8818
- name:"SIGUSR2",
8819
- number:12,
8820
- action:"terminate",
8821
- description:"Application-specific signal",
8822
- standard:"posix"},
8823
-
8824
- {
8825
- name:"SIGPIPE",
8826
- number:13,
8827
- action:"terminate",
8828
- description:"Broken pipe or socket",
8829
- standard:"posix"},
8830
-
8831
- {
8832
- name:"SIGALRM",
8833
- number:14,
8834
- action:"terminate",
8835
- description:"Timeout or timer",
8836
- standard:"posix"},
8837
-
8838
- {
8839
- name:"SIGTERM",
8840
- number:15,
8841
- action:"terminate",
8842
- description:"Termination",
8843
- standard:"ansi"},
8844
-
8845
- {
8846
- name:"SIGSTKFLT",
8847
- number:16,
8848
- action:"terminate",
8849
- description:"Stack is empty or overflowed",
8850
- standard:"other"},
8851
-
8852
- {
8853
- name:"SIGCHLD",
8854
- number:17,
8855
- action:"ignore",
8856
- description:"Child process terminated, paused or unpaused",
8857
- standard:"posix"},
8858
-
8859
- {
8860
- name:"SIGCLD",
8861
- number:17,
8862
- action:"ignore",
8863
- description:"Child process terminated, paused or unpaused",
8864
- standard:"other"},
8865
-
8866
- {
8867
- name:"SIGCONT",
8868
- number:18,
8869
- action:"unpause",
8870
- description:"Unpaused",
8871
- standard:"posix",
8872
- forced:true},
8873
-
8874
- {
8875
- name:"SIGSTOP",
8876
- number:19,
8877
- action:"pause",
8878
- description:"Paused",
8879
- standard:"posix",
8880
- forced:true},
8881
-
8882
- {
8883
- name:"SIGTSTP",
8884
- number:20,
8885
- action:"pause",
8886
- description:"Paused using CTRL-Z or \"suspend\"",
8887
- standard:"posix"},
8888
-
8889
- {
8890
- name:"SIGTTIN",
8891
- number:21,
8892
- action:"pause",
8893
- description:"Background process cannot read terminal input",
8894
- standard:"posix"},
8895
-
8896
- {
8897
- name:"SIGBREAK",
8898
- number:21,
8899
- action:"terminate",
8900
- description:"User interruption with CTRL-BREAK",
8901
- standard:"other"},
8902
-
8903
- {
8904
- name:"SIGTTOU",
8905
- number:22,
8906
- action:"pause",
8907
- description:"Background process cannot write to terminal output",
8908
- standard:"posix"},
8909
-
8910
- {
8911
- name:"SIGURG",
8912
- number:23,
8913
- action:"ignore",
8914
- description:"Socket received out-of-band data",
8915
- standard:"bsd"},
8916
-
8917
- {
8918
- name:"SIGXCPU",
8919
- number:24,
8920
- action:"core",
8921
- description:"Process timed out",
8922
- standard:"bsd"},
8923
-
8924
- {
8925
- name:"SIGXFSZ",
8926
- number:25,
8927
- action:"core",
8928
- description:"File too big",
8929
- standard:"bsd"},
8930
-
8931
- {
8932
- name:"SIGVTALRM",
8933
- number:26,
8934
- action:"terminate",
8935
- description:"Timeout or timer",
8936
- standard:"bsd"},
8937
-
8938
- {
8939
- name:"SIGPROF",
8940
- number:27,
8941
- action:"terminate",
8942
- description:"Timeout or timer",
8943
- standard:"bsd"},
8944
-
8945
- {
8946
- name:"SIGWINCH",
8947
- number:28,
8948
- action:"ignore",
8949
- description:"Terminal window size changed",
8950
- standard:"bsd"},
8951
-
8952
- {
8953
- name:"SIGIO",
8954
- number:29,
8955
- action:"terminate",
8956
- description:"I/O is available",
8957
- standard:"other"},
8958
-
8959
- {
8960
- name:"SIGPOLL",
8961
- number:29,
8962
- action:"terminate",
8963
- description:"Watched event",
8964
- standard:"other"},
8965
-
8966
- {
8967
- name:"SIGINFO",
8968
- number:29,
8969
- action:"ignore",
8970
- description:"Request for process information",
8971
- standard:"other"},
8972
-
8973
- {
8974
- name:"SIGPWR",
8975
- number:30,
8976
- action:"terminate",
8977
- description:"Device running out of power",
8978
- standard:"systemv"},
8979
-
8980
- {
8981
- name:"SIGSYS",
8982
- number:31,
8983
- action:"core",
8984
- description:"Invalid system call",
8985
- standard:"other"},
8986
-
8987
- {
8988
- name:"SIGUNUSED",
8989
- number:31,
8990
- action:"terminate",
8991
- description:"Invalid system call",
8992
- standard:"other"}];
8993
-
8994
- const getSignals=function(){
8995
- const realtimeSignals=getRealtimeSignals();
8996
- const signals=[...SIGNALS,...realtimeSignals].map(normalizeSignal);
8997
- return signals;
8998
- };
8999
-
9000
-
9001
-
9002
-
9003
-
9004
-
9005
-
9006
- const normalizeSignal=function({
9007
- name,
9008
- number:defaultNumber,
9009
- description,
9010
- action,
9011
- forced=false,
9012
- standard})
9013
- {
9014
- const{
9015
- signals:{[name]:constantSignal}}=
9016
- constants$5;
9017
- const supported=constantSignal!==undefined;
9018
- const number=supported?constantSignal:defaultNumber;
9019
- return {name,number,description,supported,action,forced,standard};
9020
- };
9021
-
9022
- const getSignalsByName=function(){
9023
- const signals=getSignals();
9024
- return signals.reduce(getSignalByName,{});
9025
- };
9026
-
9027
- const getSignalByName=function(
9028
- signalByNameMemo,
9029
- {name,number,description,supported,action,forced,standard})
9030
- {
9031
- return {
9032
- ...signalByNameMemo,
9033
- [name]:{name,number,description,supported,action,forced,standard}};
9034
-
9035
- };
9036
-
9037
- const signalsByName=getSignalsByName();
9038
-
9039
-
9040
-
9041
-
9042
- const getSignalsByNumber=function(){
9043
- const signals=getSignals();
9044
- const length=SIGRTMAX+1;
9045
- const signalsA=Array.from({length},(value,number)=>
9046
- getSignalByNumber(number,signals));
9047
-
9048
- return Object.assign({},...signalsA);
9049
- };
9050
-
9051
- const getSignalByNumber=function(number,signals){
9052
- const signal=findSignalByNumber(number,signals);
9053
-
9054
- if(signal===undefined){
9055
- return {};
9056
- }
9057
-
9058
- const{name,description,supported,action,forced,standard}=signal;
9059
- return {
9060
- [number]:{
9061
- name,
9062
- number,
9063
- description,
9064
- supported,
9065
- action,
9066
- forced,
9067
- standard}};
9068
-
9069
-
9070
- };
9071
-
9072
-
9073
-
9074
- const findSignalByNumber=function(number,signals){
9075
- const signal=signals.find(({name})=>constants$5.signals[name]===number);
9076
-
9077
- if(signal!==undefined){
9078
- return signal;
9079
- }
9080
-
9081
- return signals.find((signalA)=>signalA.number===number);
9082
- };
9083
-
9084
- getSignalsByNumber();
9085
-
9086
- const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => {
9087
- if (timedOut) {
9088
- return `timed out after ${timeout} milliseconds`;
9089
- }
9090
-
9091
- if (isCanceled) {
9092
- return 'was canceled';
9093
- }
9094
-
9095
- if (errorCode !== undefined) {
9096
- return `failed with ${errorCode}`;
9097
- }
9098
-
9099
- if (signal !== undefined) {
9100
- return `was killed with ${signal} (${signalDescription})`;
9101
- }
9102
-
9103
- if (exitCode !== undefined) {
9104
- return `failed with exit code ${exitCode}`;
9105
- }
9106
-
9107
- return 'failed';
9108
- };
9109
-
9110
- const makeError = ({
9111
- stdout,
9112
- stderr,
9113
- all,
9114
- error,
9115
- signal,
9116
- exitCode,
9117
- command,
9118
- escapedCommand,
9119
- timedOut,
9120
- isCanceled,
9121
- killed,
9122
- parsed: {options: {timeout}},
9123
- }) => {
9124
- // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`.
9125
- // We normalize them to `undefined`
9126
- exitCode = exitCode === null ? undefined : exitCode;
9127
- signal = signal === null ? undefined : signal;
9128
- const signalDescription = signal === undefined ? undefined : signalsByName[signal].description;
9129
-
9130
- const errorCode = error && error.code;
9131
-
9132
- const prefix = getErrorPrefix({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled});
9133
- const execaMessage = `Command ${prefix}: ${command}`;
9134
- const isError = Object.prototype.toString.call(error) === '[object Error]';
9135
- const shortMessage = isError ? `${execaMessage}\n${error.message}` : execaMessage;
9136
- const message = [shortMessage, stderr, stdout].filter(Boolean).join('\n');
9137
-
9138
- if (isError) {
9139
- error.originalMessage = error.message;
9140
- error.message = message;
9141
- } else {
9142
- error = new Error(message);
9143
- }
9144
-
9145
- error.shortMessage = shortMessage;
9146
- error.command = command;
9147
- error.escapedCommand = escapedCommand;
9148
- error.exitCode = exitCode;
9149
- error.signal = signal;
9150
- error.signalDescription = signalDescription;
9151
- error.stdout = stdout;
9152
- error.stderr = stderr;
9153
-
9154
- if (all !== undefined) {
9155
- error.all = all;
9156
- }
9157
-
9158
- if ('bufferedData' in error) {
9159
- delete error.bufferedData;
9160
- }
9161
-
9162
- error.failed = true;
9163
- error.timedOut = Boolean(timedOut);
9164
- error.isCanceled = isCanceled;
9165
- error.killed = killed && !timedOut;
9166
-
9167
- return error;
9168
- };
9169
-
9170
- const aliases = ['stdin', 'stdout', 'stderr'];
9171
-
9172
- const hasAlias = options => aliases.some(alias => options[alias] !== undefined);
9173
-
9174
- const normalizeStdio = options => {
9175
- if (!options) {
9176
- return;
9177
- }
9178
-
9179
- const {stdio} = options;
9180
-
9181
- if (stdio === undefined) {
9182
- return aliases.map(alias => options[alias]);
9183
- }
9184
-
9185
- if (hasAlias(options)) {
9186
- throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map(alias => `\`${alias}\``).join(', ')}`);
9187
- }
9188
-
9189
- if (typeof stdio === 'string') {
9190
- return stdio;
9191
- }
9192
-
9193
- if (!Array.isArray(stdio)) {
9194
- throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
9195
- }
9196
-
9197
- const length = Math.max(stdio.length, aliases.length);
9198
- return Array.from({length}, (value, index) => stdio[index]);
9199
- };
9200
-
9201
- const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;
9202
-
9203
- // Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior
9204
- const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => {
9205
- const killResult = kill(signal);
9206
- setKillTimeout(kill, signal, options, killResult);
9207
- return killResult;
9208
- };
9209
-
9210
- const setKillTimeout = (kill, signal, options, killResult) => {
9211
- if (!shouldForceKill(signal, options, killResult)) {
9212
- return;
9213
- }
9214
-
9215
- const timeout = getForceKillAfterTimeout(options);
9216
- const t = setTimeout(() => {
9217
- kill('SIGKILL');
9218
- }, timeout);
9219
-
9220
- // Guarded because there's no `.unref()` when `execa` is used in the renderer
9221
- // process in Electron. This cannot be tested since we don't run tests in
9222
- // Electron.
9223
- // istanbul ignore else
9224
- if (t.unref) {
9225
- t.unref();
9226
- }
9227
- };
9228
-
9229
- const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
9230
-
9231
- const isSigterm = signal => signal === require$$0.constants.signals.SIGTERM
9232
- || (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM');
9233
-
9234
- const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => {
9235
- if (forceKillAfterTimeout === true) {
9236
- return DEFAULT_FORCE_KILL_TIMEOUT;
9237
- }
9238
-
9239
- if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
9240
- throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
9241
- }
9242
-
9243
- return forceKillAfterTimeout;
9244
- };
9245
-
9246
- // `childProcess.cancel()`
9247
- const spawnedCancel = (spawned, context) => {
9248
- const killResult = spawned.kill();
9249
-
9250
- if (killResult) {
9251
- context.isCanceled = true;
9252
- }
9253
- };
9254
-
9255
- const timeoutKill = (spawned, signal, reject) => {
9256
- spawned.kill(signal);
9257
- reject(Object.assign(new Error('Timed out'), {timedOut: true, signal}));
9258
- };
9259
-
9260
- // `timeout` option handling
9261
- const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => {
9262
- if (timeout === 0 || timeout === undefined) {
9263
- return spawnedPromise;
9264
- }
9265
-
9266
- let timeoutId;
9267
- const timeoutPromise = new Promise((resolve, reject) => {
9268
- timeoutId = setTimeout(() => {
9269
- timeoutKill(spawned, killSignal, reject);
9270
- }, timeout);
9271
- });
9272
-
9273
- const safeSpawnedPromise = spawnedPromise.finally(() => {
9274
- clearTimeout(timeoutId);
9275
- });
9276
-
9277
- return Promise.race([timeoutPromise, safeSpawnedPromise]);
9278
- };
9279
-
9280
- const validateTimeout = ({timeout}) => {
9281
- if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {
9282
- throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
9283
- }
9284
- };
9285
-
9286
- // `cleanup` option handling
9287
- const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => {
9288
- if (!cleanup || detached) {
9289
- return timedPromise;
9290
- }
9291
-
9292
- const removeExitHandler = signalExit.exports(() => {
9293
- spawned.kill();
9294
- });
9295
-
9296
- return timedPromise.finally(() => {
9297
- removeExitHandler();
9298
- });
9299
- };
9300
-
9301
- function isStream(stream) {
9302
- return stream !== null
9303
- && typeof stream === 'object'
9304
- && typeof stream.pipe === 'function';
9305
- }
9306
-
9307
- // `input` option
9308
- const handleInput = (spawned, input) => {
9309
- // Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852
9310
- // @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0
9311
- if (input === undefined || spawned.stdin === undefined) {
9312
- return;
9313
- }
9314
-
9315
- if (isStream(input)) {
9316
- input.pipe(spawned.stdin);
9317
- } else {
9318
- spawned.stdin.end(input);
9319
- }
9320
- };
9321
-
9322
- // `all` interleaves `stdout` and `stderr`
9323
- const makeAllStream = (spawned, {all}) => {
9324
- if (!all || (!spawned.stdout && !spawned.stderr)) {
9325
- return;
9326
- }
9327
-
9328
- const mixed = mergeStream();
9329
-
9330
- if (spawned.stdout) {
9331
- mixed.add(spawned.stdout);
9332
- }
9333
-
9334
- if (spawned.stderr) {
9335
- mixed.add(spawned.stderr);
9336
- }
9337
-
9338
- return mixed;
9339
- };
9340
-
9341
- // On failure, `result.stdout|stderr|all` should contain the currently buffered stream
9342
- const getBufferedData = async (stream, streamPromise) => {
9343
- if (!stream) {
9344
- return;
9345
- }
9346
-
9347
- stream.destroy();
9348
-
9349
- try {
9350
- return await streamPromise;
9351
- } catch (error) {
9352
- return error.bufferedData;
9353
- }
9354
- };
9355
-
9356
- const getStreamPromise = (stream, {encoding, buffer, maxBuffer}) => {
9357
- if (!stream || !buffer) {
9358
- return;
9359
- }
9360
-
9361
- if (encoding) {
9362
- return getStream.exports(stream, {encoding, maxBuffer});
9363
- }
9364
-
9365
- return getStream.exports.buffer(stream, {maxBuffer});
9366
- };
9367
-
9368
- // Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)
9369
- const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => {
9370
- const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer});
9371
- const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer});
9372
- const allPromise = getStreamPromise(all, {encoding, buffer, maxBuffer: maxBuffer * 2});
9373
-
9374
- try {
9375
- return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
9376
- } catch (error) {
9377
- return Promise.all([
9378
- {error, signal: error.signal, timedOut: error.timedOut},
9379
- getBufferedData(stdout, stdoutPromise),
9380
- getBufferedData(stderr, stderrPromise),
9381
- getBufferedData(all, allPromise),
9382
- ]);
9383
- }
9384
- };
9385
-
9386
- const nativePromisePrototype = (async () => {})().constructor.prototype;
9387
- const descriptors = ['then', 'catch', 'finally'].map(property => [
9388
- property,
9389
- Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
9390
- ]);
9391
-
9392
- // The return value is a mixin of `childProcess` and `Promise`
9393
- const mergePromise = (spawned, promise) => {
9394
- for (const [property, descriptor] of descriptors) {
9395
- // Starting the main `promise` is deferred to avoid consuming streams
9396
- const value = typeof promise === 'function'
9397
- ? (...args) => Reflect.apply(descriptor.value, promise(), args)
9398
- : descriptor.value.bind(promise);
9399
-
9400
- Reflect.defineProperty(spawned, property, {...descriptor, value});
9401
- }
9402
-
9403
- return spawned;
9404
- };
9405
-
9406
- // Use promises instead of `child_process` events
9407
- const getSpawnedPromise = spawned => new Promise((resolve, reject) => {
9408
- spawned.on('exit', (exitCode, signal) => {
9409
- resolve({exitCode, signal});
9410
- });
9411
-
9412
- spawned.on('error', error => {
9413
- reject(error);
9414
- });
9415
-
9416
- if (spawned.stdin) {
9417
- spawned.stdin.on('error', error => {
9418
- reject(error);
9419
- });
9420
- }
9421
- });
9422
-
9423
- const normalizeArgs = (file, args = []) => {
9424
- if (!Array.isArray(args)) {
9425
- return [file];
9426
- }
9427
-
9428
- return [file, ...args];
9429
- };
9430
-
9431
- const NO_ESCAPE_REGEXP = /^[\w.-]+$/;
9432
- const DOUBLE_QUOTES_REGEXP = /"/g;
9433
-
9434
- const escapeArg = arg => {
9435
- if (typeof arg !== 'string' || NO_ESCAPE_REGEXP.test(arg)) {
9436
- return arg;
9437
- }
9438
-
9439
- return `"${arg.replace(DOUBLE_QUOTES_REGEXP, '\\"')}"`;
9440
- };
9441
-
9442
- const joinCommand = (file, args) => normalizeArgs(file, args).join(' ');
9443
-
9444
- const getEscapedCommand = (file, args) => normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' ');
9445
-
9446
- const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100;
9447
-
9448
- const getEnv = ({env: envOption, extendEnv, preferLocal, localDir, execPath}) => {
9449
- const env = extendEnv ? {...process$1.env, ...envOption} : envOption;
9450
-
9451
- if (preferLocal) {
9452
- return npmRunPathEnv({env, cwd: localDir, execPath});
9453
- }
9454
-
9455
- return env;
9456
- };
9457
-
9458
- const handleArguments = (file, args, options = {}) => {
9459
- const parsed = crossSpawn.exports._parse(file, args, options);
9460
- file = parsed.command;
9461
- args = parsed.args;
9462
- options = parsed.options;
9463
-
9464
- options = {
9465
- maxBuffer: DEFAULT_MAX_BUFFER,
9466
- buffer: true,
9467
- stripFinalNewline: true,
9468
- extendEnv: true,
9469
- preferLocal: false,
9470
- localDir: options.cwd || process$1.cwd(),
9471
- execPath: process$1.execPath,
9472
- encoding: 'utf8',
9473
- reject: true,
9474
- cleanup: true,
9475
- all: false,
9476
- windowsHide: true,
9477
- ...options,
9478
- };
9479
-
9480
- options.env = getEnv(options);
9481
-
9482
- options.stdio = normalizeStdio(options);
9483
-
9484
- if (process$1.platform === 'win32' && path$a.basename(file, '.exe') === 'cmd') {
9485
- // #116
9486
- args.unshift('/q');
9487
- }
9488
-
9489
- return {file, args, options, parsed};
9490
- };
9491
-
9492
- const handleOutput = (options, value, error) => {
9493
- if (typeof value !== 'string' && !Buffer.isBuffer(value)) {
9494
- // When `execaSync()` errors, we normalize it to '' to mimic `execa()`
9495
- return error === undefined ? undefined : '';
9496
- }
9497
-
9498
- if (options.stripFinalNewline) {
9499
- return stripFinalNewline(value);
9500
- }
9501
-
9502
- return value;
9503
- };
9504
-
9505
- function execa(file, args, options) {
9506
- const parsed = handleArguments(file, args, options);
9507
- const command = joinCommand(file, args);
9508
- const escapedCommand = getEscapedCommand(file, args);
9509
-
9510
- validateTimeout(parsed.options);
9511
-
9512
- let spawned;
9513
- try {
9514
- spawned = childProcess.spawn(parsed.file, parsed.args, parsed.options);
9515
- } catch (error) {
9516
- // Ensure the returned error is always both a promise and a child process
9517
- const dummySpawned = new childProcess.ChildProcess();
9518
- const errorPromise = Promise.reject(makeError({
9519
- error,
9520
- stdout: '',
9521
- stderr: '',
9522
- all: '',
9523
- command,
9524
- escapedCommand,
9525
- parsed,
9526
- timedOut: false,
9527
- isCanceled: false,
9528
- killed: false,
9529
- }));
9530
- return mergePromise(dummySpawned, errorPromise);
9531
- }
9532
-
9533
- const spawnedPromise = getSpawnedPromise(spawned);
9534
- const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
9535
- const processDone = setExitHandler(spawned, parsed.options, timedPromise);
9536
-
9537
- const context = {isCanceled: false};
9538
-
9539
- spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
9540
- spawned.cancel = spawnedCancel.bind(null, spawned, context);
9541
-
9542
- const handlePromise = async () => {
9543
- const [{error, exitCode, signal, timedOut}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
9544
- const stdout = handleOutput(parsed.options, stdoutResult);
9545
- const stderr = handleOutput(parsed.options, stderrResult);
9546
- const all = handleOutput(parsed.options, allResult);
9547
-
9548
- if (error || exitCode !== 0 || signal !== null) {
9549
- const returnedError = makeError({
9550
- error,
9551
- exitCode,
9552
- signal,
9553
- stdout,
9554
- stderr,
9555
- all,
9556
- command,
9557
- escapedCommand,
9558
- parsed,
9559
- timedOut,
9560
- isCanceled: context.isCanceled || (parsed.options.signal ? parsed.options.signal.aborted : false),
9561
- killed: spawned.killed,
9562
- });
9563
-
9564
- if (!parsed.options.reject) {
9565
- return returnedError;
9566
- }
9567
-
9568
- throw returnedError;
9569
- }
9570
-
9571
- return {
9572
- command,
9573
- escapedCommand,
9574
- exitCode: 0,
9575
- stdout,
9576
- stderr,
9577
- all,
9578
- failed: false,
9579
- timedOut: false,
9580
- isCanceled: false,
9581
- killed: false,
9582
- };
9583
- };
9584
-
9585
- const handlePromiseOnce = onetime(handlePromise);
9586
-
9587
- handleInput(spawned, parsed.options.input);
9588
-
9589
- spawned.all = makeAllStream(spawned, parsed.options);
9590
-
9591
- return mergePromise(spawned, handlePromiseOnce);
9592
- }
9593
-
9594
- class VitestGit {
9595
- constructor(cwd) {
9596
- this.cwd = cwd;
9597
- }
9598
- async resolveFilesWithGitCommand(args) {
9599
- let result;
9600
- try {
9601
- result = await execa("git", args, { cwd: this.root });
9602
- } catch (e) {
9603
- e.message = e.stderr;
9604
- throw e;
9605
- }
9606
- return result.stdout.split("\n").filter((s) => s !== "").map((changedPath) => resolve(this.root, changedPath));
9607
- }
9608
- async findChangedFiles(options) {
9609
- const root = await this.getRoot(this.cwd);
9610
- if (!root)
9611
- return null;
9612
- this.root = root;
9613
- const changedSince = options.changedSince;
9614
- if (typeof changedSince === "string") {
9615
- const [committed, staged2, unstaged2] = await Promise.all([
9616
- this.getFilesSince(changedSince),
9617
- this.getStagedFiles(),
9618
- this.getUnstagedFiles()
9619
- ]);
9620
- return [...committed, ...staged2, ...unstaged2];
9621
- }
9622
- const [staged, unstaged] = await Promise.all([
9623
- this.getStagedFiles(),
9624
- this.getUnstagedFiles()
9625
- ]);
9626
- return [...staged, ...unstaged];
9627
- }
9628
- getFilesSince(hash) {
9629
- return this.resolveFilesWithGitCommand(["diff", "--name-only", `${hash}...HEAD`]);
9630
- }
9631
- getStagedFiles() {
9632
- return this.resolveFilesWithGitCommand(["diff", "--cached", "--name-only"]);
9633
- }
9634
- getUnstagedFiles() {
9635
- return this.resolveFilesWithGitCommand([
9636
- "ls-files",
9637
- "--other",
9638
- "--modified",
9639
- "--exclude-standard"
9640
- ]);
9641
- }
9642
- async getRoot(cwd) {
9643
- const options = ["rev-parse", "--show-cdup"];
9644
- try {
9645
- const result = await execa("git", options, { cwd });
9646
- return resolve(cwd, result.stdout);
9647
- } catch {
9648
- return null;
9649
- }
9650
- }
9651
- }
9652
-
9653
8558
  const ESC = '\u001B[';
9654
8559
  const OSC = '\u001B]';
9655
8560
  const BEL = '\u0007';
@@ -9805,7 +8710,7 @@ ansiEscapes.iTerm = {
9805
8710
  }
9806
8711
  };
9807
8712
 
9808
- const restoreCursor = onetime$1.exports(() => {
8713
+ const restoreCursor = onetime.exports(() => {
9809
8714
  signalExit.exports(() => {
9810
8715
  process$1.stderr.write('\u001B[?25h');
9811
8716
  }, {alwaysLast: true});
@@ -10136,7 +9041,7 @@ createLogUpdate(process$1.stdout);
10136
9041
 
10137
9042
  createLogUpdate(process$1.stderr);
10138
9043
 
10139
- var version = "0.18.0";
9044
+ var version = "0.19.1";
10140
9045
 
10141
9046
  function fileFromParsedStack(stack) {
10142
9047
  var _a, _b;
@@ -10287,7 +9192,7 @@ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
10287
9192
  const lineLength = lines[j].length;
10288
9193
  if (lineLength > 200)
10289
9194
  return "";
10290
- res.push(lineNo(j + 1) + cliTruncate(lines[j], columns - 5 - indent));
9195
+ res.push(lineNo(j + 1) + cliTruncate(lines[j].replace(/\t/g, " "), columns - 5 - indent));
10291
9196
  if (j === i) {
10292
9197
  const pad = start - (count - lineLength);
10293
9198
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
@@ -10368,15 +9273,17 @@ class Logger {
10368
9273
  this.error(picocolors.exports.red("\nNo test files found, exiting with code 1"));
10369
9274
  }
10370
9275
  printBanner() {
10371
- var _a, _b;
9276
+ var _a, _b, _c;
10372
9277
  this.log();
10373
9278
  const versionTest = this.ctx.config.watch ? picocolors.exports.blue(`v${version}`) : picocolors.exports.cyan(`v${version}`);
10374
9279
  const mode = this.ctx.config.watch ? picocolors.exports.blue(" DEV ") : picocolors.exports.cyan(" RUN ");
10375
9280
  this.log(`${picocolors.exports.inverse(picocolors.exports.bold(mode))} ${versionTest} ${picocolors.exports.gray(this.ctx.config.root)}`);
10376
- if (this.ctx.config.ui)
10377
- this.log(picocolors.exports.dim(picocolors.exports.green(` UI started at http://${((_a = this.ctx.config.api) == null ? void 0 : _a.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`)));
9281
+ if (this.ctx.config.browser)
9282
+ this.log(picocolors.exports.dim(picocolors.exports.green(` Browser runner started at http://${((_a = this.ctx.config.api) == null ? void 0 : _a.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.server.config.server.port}`)}`)));
9283
+ else if (this.ctx.config.ui)
9284
+ this.log(picocolors.exports.dim(picocolors.exports.green(` UI started at http://${((_b = this.ctx.config.api) == null ? void 0 : _b.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`)));
10378
9285
  else if (this.ctx.config.api)
10379
- this.log(picocolors.exports.dim(picocolors.exports.green(` API started at http://${((_b = this.ctx.config.api) == null ? void 0 : _b.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.config.api.port}`)}`)));
9286
+ this.log(picocolors.exports.dim(picocolors.exports.green(` API started at http://${((_c = this.ctx.config.api) == null ? void 0 : _c.host) || "localhost"}:${picocolors.exports.bold(`${this.ctx.config.api.port}`)}`)));
10380
9287
  this.log();
10381
9288
  }
10382
9289
  async printUnhandledErrors(errors) {
@@ -10393,7 +9300,6 @@ Please, resolve all the errors to make sure your tests are not affected.`));
10393
9300
  }
10394
9301
 
10395
9302
  const WATCHER_DEBOUNCE = 100;
10396
- const CLOSE_TIMEOUT = 1e3;
10397
9303
  class Vitest {
10398
9304
  constructor() {
10399
9305
  this.config = void 0;
@@ -10478,7 +9384,7 @@ class Vitest {
10478
9384
  await this.runFiles(files);
10479
9385
  if (this.config.coverage.enabled)
10480
9386
  await reportCoverage(this);
10481
- if (this.config.watch)
9387
+ if (this.config.watch && !this.config.browser)
10482
9388
  await this.report("onWatcherStart");
10483
9389
  }
10484
9390
  async getTestDependencies(filepath) {
@@ -10502,6 +9408,7 @@ class Vitest {
10502
9408
  }
10503
9409
  async filterTestsBySource(tests) {
10504
9410
  if (this.config.changed && !this.config.related) {
9411
+ const { VitestGit } = await import('./chunk-node-git.9058b82a.mjs');
10505
9412
  const vitestGit = new VitestGit(this.config.root);
10506
9413
  const related2 = await vitestGit.findChangedFiles({
10507
9414
  changedSince: this.config.changed
@@ -10548,7 +9455,8 @@ class Vitest {
10548
9455
  const files = this.state.getFiles();
10549
9456
  if (hasFailed(files))
10550
9457
  process.exitCode = 1;
10551
- await this.report("onFinished", files, this.state.getUnhandledErrors());
9458
+ if (!this.config.browser)
9459
+ await this.report("onFinished", files, this.state.getUnhandledErrors());
10552
9460
  this.cache.results.updateResults(files);
10553
9461
  await this.cache.results.writeToCache();
10554
9462
  })().finally(() => {
@@ -10559,7 +9467,8 @@ class Vitest {
10559
9467
  async rerunFiles(files = this.state.getFilepaths(), trigger) {
10560
9468
  await this.report("onWatcherRerun", files, trigger);
10561
9469
  await this.runFiles(files);
10562
- await this.report("onWatcherStart");
9470
+ if (!this.config.browser)
9471
+ await this.report("onWatcherStart");
10563
9472
  }
10564
9473
  async changeNamePattern(pattern, files = this.state.getFilepaths(), trigger) {
10565
9474
  this.config.testNamePattern = pattern ? new RegExp(pattern) : void 0;
@@ -10608,7 +9517,8 @@ class Vitest {
10608
9517
  await this.runFiles(files);
10609
9518
  if (this.config.coverage.enabled)
10610
9519
  await reportCoverage(this);
10611
- await this.report("onWatcherStart");
9520
+ if (!this.config.browser)
9521
+ await this.report("onWatcherStart");
10612
9522
  }, WATCHER_DEBOUNCE);
10613
9523
  }
10614
9524
  registerWatcher() {
@@ -10692,9 +9602,9 @@ class Vitest {
10692
9602
  }
10693
9603
  async exit(force = false) {
10694
9604
  safeSetTimeout(() => {
10695
- console.warn(`close timed out after ${CLOSE_TIMEOUT}ms`);
9605
+ console.warn(`close timed out after ${this.config.teardownTimeout}ms`);
10696
9606
  process.exit();
10697
- }, CLOSE_TIMEOUT).unref();
9607
+ }, this.config.teardownTimeout).unref();
10698
9608
  await this.close();
10699
9609
  if (force)
10700
9610
  process.exit();
@@ -10985,9 +9895,15 @@ function CSSEnablerPlugin(ctx) {
10985
9895
  async function VitestPlugin(options = {}, ctx = new Vitest()) {
10986
9896
  let haveStarted = false;
10987
9897
  async function UIPlugin() {
10988
- await ensurePackageInstalled("@vitest/ui");
9898
+ var _a;
9899
+ await ensurePackageInstalled("@vitest/ui", ((_a = ctx.config) == null ? void 0 : _a.root) || options.root || process.cwd());
10989
9900
  return (await import('@vitest/ui')).default(options.uiBase);
10990
9901
  }
9902
+ async function BrowserPlugin() {
9903
+ var _a;
9904
+ await ensurePackageInstalled("@vitest/browser", ((_a = ctx.config) == null ? void 0 : _a.root) || options.root || process.cwd());
9905
+ return (await import('@vitest/browser')).default("/");
9906
+ }
10991
9907
  return [
10992
9908
  {
10993
9909
  name: "vitest",
@@ -11022,10 +9938,15 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
11022
9938
  }
11023
9939
  }
11024
9940
  options.defines = defines;
11025
- const open = preOptions.ui && preOptions.open ? preOptions.uiBase ?? "/__vitest__/" : void 0;
9941
+ let open;
9942
+ if (preOptions.ui && preOptions.open)
9943
+ open = preOptions.uiBase ?? "/__vitest__/";
9944
+ else if (preOptions.browser)
9945
+ open = "/";
11026
9946
  const config = {
11027
9947
  resolve: {
11028
- mainFields: []
9948
+ mainFields: [],
9949
+ alias: preOptions.alias
11029
9950
  },
11030
9951
  server: {
11031
9952
  ...preOptions.api,
@@ -11035,13 +9956,17 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
11035
9956
  open,
11036
9957
  hmr: false,
11037
9958
  preTransformRequests: false
11038
- },
11039
- cacheDir: void 0,
11040
- optimizeDeps: {
11041
- disabled: true,
11042
- entries: []
11043
9959
  }
11044
9960
  };
9961
+ if (!options.browser) {
9962
+ Object.assign(config, {
9963
+ cacheDir: void 0,
9964
+ optimizeDeps: {
9965
+ disabled: true,
9966
+ entries: []
9967
+ }
9968
+ });
9969
+ }
11045
9970
  return config;
11046
9971
  },
11047
9972
  async configResolved(viteConfig) {
@@ -11049,6 +9974,8 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
11049
9974
  const viteConfigTest = viteConfig.test || {};
11050
9975
  if (viteConfigTest.watch === false)
11051
9976
  viteConfigTest.run = true;
9977
+ if ("alias" in viteConfigTest)
9978
+ delete viteConfigTest.alias;
11052
9979
  options = deepMerge({}, configDefaults, viteConfigTest, options);
11053
9980
  options.api = resolveApiConfig(options);
11054
9981
  const { PROD, DEV, ...envs } = viteConfig.env;
@@ -11065,7 +9992,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
11065
9992
  await ctx.setServer(options, server);
11066
9993
  haveStarted = true;
11067
9994
  if (options.api && options.watch)
11068
- (await import('./chunk-api-setup.63babd7c.mjs')).setup(ctx);
9995
+ (await import('./chunk-api-setup.0cf2c96a.mjs')).setup(ctx);
11069
9996
  } catch (err) {
11070
9997
  ctx.logger.printError(err, true);
11071
9998
  process.exit(1);
@@ -11077,6 +10004,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
11077
10004
  EnvReplacerPlugin(),
11078
10005
  MocksPlugin(),
11079
10006
  GlobalSetupPlugin(ctx),
10007
+ ...options.browser ? await BrowserPlugin() : [],
11080
10008
  CSSEnablerPlugin(ctx),
11081
10009
  options.ui ? await UIPlugin() : null
11082
10010
  ].filter(notNullish);
@@ -11151,8 +10079,8 @@ function registerConsoleShortcuts(ctx) {
11151
10079
  let rl;
11152
10080
  function on() {
11153
10081
  off();
11154
- rl = require$$0$3.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
11155
- require$$0$3.emitKeypressEvents(process.stdin, rl);
10082
+ rl = require$$0$2.createInterface({ input: process.stdin, escapeCodeTimeout: 50 });
10083
+ require$$0$2.emitKeypressEvents(process.stdin, rl);
11156
10084
  if (process.stdin.isTTY)
11157
10085
  process.stdin.setRawMode(true);
11158
10086
  process.stdin.on("keypress", keypressHandler);
@@ -11174,7 +10102,10 @@ async function startVitest(cliFilters, options, viteOverrides) {
11174
10102
  (_a = process.env).NODE_ENV ?? (_a.NODE_ENV = options.mode || "test");
11175
10103
  if (options.run)
11176
10104
  options.watch = false;
11177
- if (!await ensurePackageInstalled("vite")) {
10105
+ if (options.browser)
10106
+ options.threads = false;
10107
+ const root = resolve(options.root || process.cwd());
10108
+ if (!await ensurePackageInstalled("vite", root)) {
11178
10109
  process.exitCode = 1;
11179
10110
  return false;
11180
10111
  }
@@ -11182,14 +10113,14 @@ async function startVitest(cliFilters, options, viteOverrides) {
11182
10113
  options.coverage = { enabled: options.coverage };
11183
10114
  const ctx = await createVitest(options, viteOverrides);
11184
10115
  if (ctx.config.coverage.enabled) {
11185
- if (!await ensurePackageInstalled("c8")) {
10116
+ if (!await ensurePackageInstalled("c8", root)) {
11186
10117
  process.exitCode = 1;
11187
10118
  return false;
11188
10119
  }
11189
10120
  }
11190
10121
  if (ctx.config.environment && ctx.config.environment !== "node") {
11191
10122
  const packageName = envPackageNames[ctx.config.environment];
11192
- if (!await ensurePackageInstalled(packageName)) {
10123
+ if (!await ensurePackageInstalled(packageName, root)) {
11193
10124
  process.exitCode = 1;
11194
10125
  return false;
11195
10126
  }