vitest 0.27.0 → 0.27.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 +13 -12
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +9 -9
  4. package/dist/{chunk-api-setup.16ac28c0.js → chunk-api-setup.2be3cc38.js} +54 -30
  5. package/dist/{chunk-install-pkg.6dd2bae6.js → chunk-install-pkg.7b006b3e.js} +8 -8
  6. package/dist/{chunk-integrations-globals.3dfaeb99.js → chunk-integrations-globals.02f1259c.js} +6 -6
  7. package/dist/{chunk-mock-date.a1c85759.js → chunk-mock-date.149ed990.js} +11 -6
  8. package/dist/{chunk-node-git.543e964a.js → chunk-node-git.125c9008.js} +3 -3
  9. package/dist/{chunk-runtime-chain.6df5a66b.js → chunk-runtime-chain.4e2aa823.js} +6 -6
  10. package/dist/{chunk-runtime-error.fad2c32b.js → chunk-runtime-error.97854396.js} +1 -1
  11. package/dist/{chunk-runtime-mocker.a677dd28.js → chunk-runtime-mocker.4755840f.js} +4 -4
  12. package/dist/{chunk-runtime-rpc.7f83c8a9.js → chunk-runtime-rpc.25cc9413.js} +1 -1
  13. package/dist/{chunk-runtime-setup.731b2b04.js → chunk-runtime-setup.56d71d30.js} +11 -11
  14. package/dist/{chunk-snapshot-manager.700322bf.js → chunk-snapshot-manager.1a2dbf96.js} +70 -40
  15. package/dist/{chunk-utils-env.b861e3a0.js → chunk-utils-env.f4a39d2c.js} +7 -7
  16. package/dist/{chunk-utils-import.2baa69a9.js → chunk-utils-import.16d9fb0d.js} +3 -3
  17. package/dist/{chunk-utils-source-map.60562959.js → chunk-utils-source-map.4e9b891d.js} +2 -2
  18. package/dist/cli-wrapper.js +5 -5
  19. package/dist/cli.js +7 -7
  20. package/dist/config.d.ts +1 -1
  21. package/dist/entry.js +8 -8
  22. package/dist/environments.d.ts +1 -1
  23. package/dist/{index-2d10c3fd.d.ts → index-1cfc7f58.d.ts} +4 -2
  24. package/dist/index.d.ts +4 -4
  25. package/dist/index.js +7 -7
  26. package/dist/loader.js +8 -9
  27. package/dist/node.d.ts +2 -2
  28. package/dist/node.js +11 -9
  29. package/dist/suite.js +5 -5
  30. package/dist/{types-e1e1d1e5.d.ts → types-5617096e.d.ts} +9 -1
  31. package/dist/{vendor-index.b2fdde54.js → vendor-index.451e37bc.js} +1 -1
  32. package/dist/vendor-index.b0346fe4.js +395 -0
  33. package/dist/{vendor-index.7a2cebfe.js → vendor-index.e6c27006.js} +12 -12
  34. package/dist/worker.js +23 -18
  35. package/package.json +10 -9
  36. package/dist/vendor-index.2e96c50b.js +0 -215
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { s as spyOn, f as fn, M as MaybeMockedDeep, a as MaybeMocked, b as MaybePartiallyMocked, c as MaybePartiallyMockedDeep, E as EnhancedSpy } from './index-2d10c3fd.js';
2
- export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, g as bench, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-2d10c3fd.js';
3
- import { D as DoneCallback, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as File, T as TaskResultPack, b as ResolvedConfig, c as ModuleGraphData, d as Reporter } from './types-e1e1d1e5.js';
4
- export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ao as BaseCoverageOptions, au as BenchFunction, as as Benchmark, av as BenchmarkAPI, at as BenchmarkResult, ar as BenchmarkUserOptions, B as BuiltinEnvironment, j as CSSModuleScopeStrategy, C as CollectLineNumbers, g as CollectLines, ab as Constructable, i as Context, aq as CoverageC8Options, ap as CoverageIstanbulOptions, am as CoverageOptions, aj as CoverageProvider, ak as CoverageProviderModule, al as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ah as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, c as ModuleGraphData, aa as MutableArray, a5 as Nullable, ai as OnServerRestartHandler, O as OnTestFailedHandler, ag as ParsedStack, e as RawErrsMap, d as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, an as ResolvedCoverageOptions, h as RootAndTarget, m as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, q as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, o as TaskBase, p as TaskResult, T as TaskResultPack, n as TaskState, r as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, f as TscErrorInfo, l as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, k as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-e1e1d1e5.js';
1
+ import { s as spyOn, f as fn, M as MaybeMockedDeep, a as MaybeMocked, b as MaybePartiallyMocked, c as MaybePartiallyMockedDeep, E as EnhancedSpy } from './index-1cfc7f58.js';
2
+ export { A as AssertType, E as EnhancedSpy, q as ExpectTypeOf, x as Mock, y as MockContext, w as MockInstance, z as Mocked, B as MockedClass, u as MockedFunction, v as MockedObject, S as SpyInstance, j as afterAll, l as afterEach, r as assertType, h as beforeAll, k as beforeEach, g as bench, n as createExpect, e as describe, m as expect, p as expectTypeOf, i as it, o as onTestFailed, d as suite, t as test } from './index-1cfc7f58.js';
3
+ import { D as DoneCallback, F as FakeTimerInstallOpts, M as MockFactoryWithHelper, R as RuntimeConfig, a as File, T as TaskResultPack, b as ResolvedConfig, c as ModuleGraphData, d as Reporter } from './types-5617096e.js';
4
+ export { a1 as AfterSuiteRunMeta, A as ApiConfig, a7 as ArgumentsType, a6 as Arrayable, a4 as Awaitable, ao as BaseCoverageOptions, au as BenchFunction, as as Benchmark, av as BenchmarkAPI, at as BenchmarkResult, ar as BenchmarkUserOptions, B as BuiltinEnvironment, j as CSSModuleScopeStrategy, C as CollectLineNumbers, g as CollectLines, ab as Constructable, i as Context, aq as CoverageC8Options, ap as CoverageIstanbulOptions, am as CoverageOptions, aj as CoverageProvider, ak as CoverageProviderModule, al as CoverageReporter, a9 as DeepMerge, D as DoneCallback, ae as Environment, E as EnvironmentOptions, ad as EnvironmentReturn, ah as ErrorWithDiff, a as File, x as HookCleanupCallback, H as HookListener, I as InlineConfig, J as JSDOMOptions, a8 as MergeInsertions, ac as ModuleCache, c as ModuleGraphData, aa as MutableArray, a5 as Nullable, ai as OnServerRestartHandler, O as OnTestFailedHandler, ag as ParsedStack, e as RawErrsMap, d as Reporter, a0 as ResolveIdFunction, b as ResolvedConfig, an as ResolvedCoverageOptions, h as RootAndTarget, m as RunMode, R as RuntimeConfig, K as RuntimeContext, S as SequenceHooks, P as SnapshotData, X as SnapshotMatchOptions, Y as SnapshotResult, W as SnapshotStateOptions, _ as SnapshotSummary, Q as SnapshotUpdateState, q as Suite, w as SuiteAPI, z as SuiteCollector, G as SuiteFactory, y as SuiteHooks, s as Task, o as TaskBase, p as TaskResult, T as TaskResultPack, n as TaskState, r as Test, v as TestAPI, L as TestContext, t as TestFunction, u as TestOptions, f as TscErrorInfo, l as TypecheckConfig, Z as UncheckedSnapshot, U as UserConfig, af as UserConsoleLog, N as Vitest, V as VitestEnvironment, k as VitestRunMode, $ as WorkerContext, a3 as WorkerGlobalState, a2 as WorkerRPC } from './types-5617096e.js';
5
5
  import { TransformResult } from 'vite';
6
6
  import * as chai from 'chai';
7
7
  export { chai };
package/dist/index.js CHANGED
@@ -1,23 +1,23 @@
1
- export { b as bench, c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.6df5a66b.js';
2
- import { e as dist } from './chunk-utils-import.2baa69a9.js';
3
- export { a as afterAll, d as afterEach, f as assertType, b as beforeAll, c as beforeEach, k as getRunningMode, h as isFirstRun, l as isWatchMode, o as onTestFailed, g as runOnce, v as vi, j as vitest, w as withCallback } from './chunk-utils-import.2baa69a9.js';
1
+ export { b as bench, c as createExpect, d as describe, e as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.4e2aa823.js';
2
+ import { e as dist } from './chunk-utils-import.16d9fb0d.js';
3
+ export { a as afterAll, d as afterEach, f as assertType, b as beforeAll, c as beforeEach, k as getRunningMode, h as isFirstRun, l as isWatchMode, o as onTestFailed, g as runOnce, v as vi, j as vitest, w as withCallback } from './chunk-utils-import.16d9fb0d.js';
4
4
  import * as chai from 'chai';
5
5
  export { chai };
6
6
  export { assert, should } from 'chai';
7
7
  import 'util';
8
- import './chunk-mock-date.a1c85759.js';
8
+ import './chunk-mock-date.149ed990.js';
9
9
  import 'node:path';
10
10
  import 'picocolors';
11
11
  import 'local-pkg';
12
- import './chunk-utils-env.b861e3a0.js';
12
+ import './chunk-utils-env.f4a39d2c.js';
13
13
  import 'node:url';
14
14
  import 'path';
15
15
  import './vendor-_commonjsHelpers.addc3445.js';
16
16
  import './chunk-utils-timers.52534f96.js';
17
17
  import './vendor-index.723a074f.js';
18
18
  import 'tinyspy';
19
- import './chunk-utils-source-map.60562959.js';
20
- import './chunk-runtime-rpc.7f83c8a9.js';
19
+ import './chunk-utils-source-map.4e9b891d.js';
20
+ import './chunk-runtime-rpc.25cc9413.js';
21
21
  import 'node:fs';
22
22
  import 'fs';
23
23
 
package/dist/loader.js CHANGED
@@ -1,21 +1,20 @@
1
1
  import { pathToFileURL } from 'node:url';
2
2
  import { readFile } from 'node:fs/promises';
3
- import { i as isNodeBuiltin, h as hasCJSSyntax } from './vendor-index.2e96c50b.js';
3
+ import { i as isNodeBuiltin, h as hasCJSSyntax } from './vendor-index.b0346fe4.js';
4
4
  import { normalizeModuleId } from 'vite-node/utils';
5
- import { g as getWorkerState } from './chunk-mock-date.a1c85759.js';
5
+ import { g as getWorkerState } from './chunk-mock-date.149ed990.js';
6
6
  import 'acorn';
7
7
  import 'node:module';
8
8
  import 'node:fs';
9
- import 'url';
10
- import 'fs';
11
- import 'path';
12
- import 'module';
13
- import 'assert';
14
- import 'util';
9
+ import 'node:assert';
10
+ import 'node:process';
15
11
  import 'node:path';
12
+ import 'node:v8';
13
+ import 'node:util';
16
14
  import 'picocolors';
17
15
  import 'local-pkg';
18
- import './chunk-utils-env.b861e3a0.js';
16
+ import './chunk-utils-env.f4a39d2c.js';
17
+ import 'path';
19
18
 
20
19
  var ModuleFormat = /* @__PURE__ */ ((ModuleFormat2) => {
21
20
  ModuleFormat2["Builtin"] = "builtin";
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { k as VitestRunMode, U as UserConfig, N as Vitest, aw as MockFactory, ax as MockMap, ay as TestSequencer } from './types-e1e1d1e5.js';
2
- export { ay as TestSequencer, aA as TestSequencerConstructor, N as Vitest, az as startVitest } from './types-e1e1d1e5.js';
1
+ import { k as VitestRunMode, U as UserConfig, N as Vitest, aw as MockFactory, ax as MockMap, ay as TestSequencer } from './types-5617096e.js';
2
+ export { ay as TestSequencer, aA as TestSequencerConstructor, N as Vitest, az as startVitest } from './types-5617096e.js';
3
3
  import { UserConfig as UserConfig$1, Plugin } from 'vite';
4
4
  import { ViteNodeRunner } from 'vite-node/client';
5
5
  import { ViteNodeRunnerOptions } from 'vite-node';
package/dist/node.js CHANGED
@@ -1,13 +1,13 @@
1
- export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-snapshot-manager.700322bf.js';
2
- export { V as VitestRunner } from './chunk-runtime-mocker.a677dd28.js';
3
- import './chunk-utils-env.b861e3a0.js';
1
+ export { B as BaseSequencer, V as VitestPlugin, c as createVitest, s as startVitest } from './chunk-snapshot-manager.1a2dbf96.js';
2
+ export { V as VitestRunner } from './chunk-runtime-mocker.4755840f.js';
3
+ import './chunk-utils-env.f4a39d2c.js';
4
4
  import 'node:url';
5
5
  import 'path';
6
6
  import './chunk-integrations-coverage.44413252.js';
7
7
  import 'local-pkg';
8
8
  import './chunk-env-node.b3664da2.js';
9
9
  import 'node:console';
10
- import './chunk-mock-date.a1c85759.js';
10
+ import './chunk-mock-date.149ed990.js';
11
11
  import 'node:path';
12
12
  import 'picocolors';
13
13
  import 'vite';
@@ -22,10 +22,10 @@ import './vendor-_commonjsHelpers.addc3445.js';
22
22
  import 'vite-node/client';
23
23
  import 'vite-node/server';
24
24
  import 'node:fs/promises';
25
- import './vendor-index.b2fdde54.js';
25
+ import './vendor-index.451e37bc.js';
26
26
  import 'node:buffer';
27
27
  import 'node:child_process';
28
- import './vendor-index.7a2cebfe.js';
28
+ import './vendor-index.e6c27006.js';
29
29
  import 'child_process';
30
30
  import 'assert';
31
31
  import 'buffer';
@@ -38,7 +38,7 @@ import 'node:worker_threads';
38
38
  import 'tinypool';
39
39
  import './vendor-index.783e7f3e.js';
40
40
  import 'perf_hooks';
41
- import './chunk-utils-source-map.60562959.js';
41
+ import './chunk-utils-source-map.4e9b891d.js';
42
42
  import './chunk-utils-timers.52534f96.js';
43
43
  import 'crypto';
44
44
  import 'vite-node/utils';
@@ -48,6 +48,8 @@ import './chunk-magic-string.3a794426.js';
48
48
  import 'strip-literal';
49
49
  import 'readline';
50
50
  import './vendor-index.9f20a9be.js';
51
- import './vendor-index.2e96c50b.js';
51
+ import './vendor-index.b0346fe4.js';
52
52
  import 'node:module';
53
- import 'url';
53
+ import 'node:assert';
54
+ import 'node:v8';
55
+ import 'node:util';
package/dist/suite.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import 'util';
2
2
  import 'chai';
3
- import './chunk-mock-date.a1c85759.js';
4
- export { b as bench, f as clearCollectorContext, r as createSuiteHooks, h as defaultSuite, d as describe, g as getCurrentSuite, i as it, s as suite, t as test } from './chunk-runtime-chain.6df5a66b.js';
3
+ import './chunk-mock-date.149ed990.js';
4
+ export { b as bench, f as clearCollectorContext, r as createSuiteHooks, h as defaultSuite, d as describe, g as getCurrentSuite, i as it, s as suite, t as test } from './chunk-runtime-chain.4e2aa823.js';
5
5
  import 'node:path';
6
6
  import 'picocolors';
7
7
  import 'local-pkg';
8
- import './chunk-utils-env.b861e3a0.js';
8
+ import './chunk-utils-env.f4a39d2c.js';
9
9
  import 'node:url';
10
10
  import 'path';
11
11
  import './vendor-_commonjsHelpers.addc3445.js';
12
12
  import './chunk-utils-timers.52534f96.js';
13
13
  import './vendor-index.723a074f.js';
14
14
  import 'tinyspy';
15
- import './chunk-utils-source-map.60562959.js';
16
- import './chunk-runtime-rpc.7f83c8a9.js';
15
+ import './chunk-utils-source-map.4e9b891d.js';
16
+ import './chunk-runtime-rpc.25cc9413.js';
17
17
  import 'node:fs';
18
18
  import 'fs';
@@ -553,6 +553,12 @@ declare class TapFlatReporter extends TapReporter {
553
553
  onFinished(files?: File[]): Promise<void>;
554
554
  }
555
555
 
556
+ declare class HangingProcessReporter implements Reporter {
557
+ whyRunning: (() => void) | undefined;
558
+ onInit(): void;
559
+ onProcessTimeout(): void;
560
+ }
561
+
556
562
  declare class JsonReporter implements Reporter {
557
563
  start: number;
558
564
  ctx: Vitest;
@@ -606,6 +612,7 @@ declare const ReportersMap: {
606
612
  tap: typeof TapReporter;
607
613
  'tap-flat': typeof TapFlatReporter;
608
614
  junit: typeof JUnitReporter;
615
+ 'hanging-process': typeof HangingProcessReporter;
609
616
  };
610
617
  type BuiltinReporters = keyof typeof ReportersMap;
611
618
 
@@ -1166,7 +1173,7 @@ interface WorkerRPC {
1166
1173
  resolveId: ResolveIdFunction;
1167
1174
  getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
1168
1175
  onFinished: (files: File[], errors?: unknown[]) => void;
1169
- onWorkerExit: (code?: number) => void;
1176
+ onWorkerExit: (error: unknown, code?: number) => void;
1170
1177
  onPathsCollected: (paths: string[]) => void;
1171
1178
  onUserConsoleLog: (log: UserConsoleLog) => void;
1172
1179
  onUnhandledRejection: (err: unknown) => void;
@@ -1445,6 +1452,7 @@ interface Reporter {
1445
1452
  onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
1446
1453
  onServerRestart?: (reason?: string) => Awaitable<void>;
1447
1454
  onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
1455
+ onProcessTimeout?: () => Awaitable<void>;
1448
1456
  }
1449
1457
 
1450
1458
  type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime';
@@ -2,7 +2,7 @@ import { Buffer } from 'node:buffer';
2
2
  import path from 'node:path';
3
3
  import childProcess from 'node:child_process';
4
4
  import process$1 from 'node:process';
5
- import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.7a2cebfe.js';
5
+ import { s as signalExit, m as mergeStream, g as getStream, c as crossSpawn } from './vendor-index.e6c27006.js';
6
6
  import url from 'node:url';
7
7
  import { constants } from 'os';
8
8
  import os from 'node:os';
@@ -0,0 +1,395 @@
1
+ import 'acorn';
2
+ import { builtinModules } from 'node:module';
3
+ import 'node:fs';
4
+ import { pathToFileURL } from 'node:url';
5
+ import assert from 'node:assert';
6
+ import process$1 from 'node:process';
7
+ import 'node:path';
8
+ import v8 from 'node:v8';
9
+ import { format, inspect } from 'node:util';
10
+
11
+ const BUILTIN_MODULES = new Set(builtinModules);
12
+
13
+ /**
14
+ * @typedef ErrnoExceptionFields
15
+ * @property {number | undefined} [errnode]
16
+ * @property {string | undefined} [code]
17
+ * @property {string | undefined} [path]
18
+ * @property {string | undefined} [syscall]
19
+ * @property {string | undefined} [url]
20
+ *
21
+ * @typedef {Error & ErrnoExceptionFields} ErrnoException
22
+ */
23
+
24
+ const isWindows = process$1.platform === 'win32';
25
+
26
+ const own$1 = {}.hasOwnProperty;
27
+
28
+ /**
29
+ * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
30
+ * We cannot use Intl.ListFormat because it's not available in
31
+ * --without-intl builds.
32
+ *
33
+ * @param {Array<string>} array
34
+ * An array of strings.
35
+ * @param {string} [type]
36
+ * The list type to be inserted before the last element.
37
+ * @returns {string}
38
+ */
39
+ function formatList(array, type = 'and') {
40
+ return array.length < 3
41
+ ? array.join(` ${type} `)
42
+ : `${array.slice(0, -1).join(', ')}, ${type} ${array[array.length - 1]}`
43
+ }
44
+
45
+ /** @type {Map<string, MessageFunction|string>} */
46
+ const messages = new Map();
47
+ const nodeInternalPrefix = '__node_internal_';
48
+ /** @type {number} */
49
+ let userStackTraceLimit;
50
+
51
+ createError(
52
+ 'ERR_INVALID_MODULE_SPECIFIER',
53
+ /**
54
+ * @param {string} request
55
+ * @param {string} reason
56
+ * @param {string} [base]
57
+ */
58
+ (request, reason, base = undefined) => {
59
+ return `Invalid module "${request}" ${reason}${
60
+ base ? ` imported from ${base}` : ''
61
+ }`
62
+ },
63
+ TypeError
64
+ );
65
+
66
+ createError(
67
+ 'ERR_INVALID_PACKAGE_CONFIG',
68
+ /**
69
+ * @param {string} path
70
+ * @param {string} [base]
71
+ * @param {string} [message]
72
+ */
73
+ (path, base, message) => {
74
+ return `Invalid package config ${path}${
75
+ base ? ` while importing ${base}` : ''
76
+ }${message ? `. ${message}` : ''}`
77
+ },
78
+ Error
79
+ );
80
+
81
+ createError(
82
+ 'ERR_INVALID_PACKAGE_TARGET',
83
+ /**
84
+ * @param {string} pkgPath
85
+ * @param {string} key
86
+ * @param {unknown} target
87
+ * @param {boolean} [isImport=false]
88
+ * @param {string} [base]
89
+ */
90
+ (pkgPath, key, target, isImport = false, base = undefined) => {
91
+ const relError =
92
+ typeof target === 'string' &&
93
+ !isImport &&
94
+ target.length > 0 &&
95
+ !target.startsWith('./');
96
+ if (key === '.') {
97
+ assert(isImport === false);
98
+ return (
99
+ `Invalid "exports" main target ${JSON.stringify(target)} defined ` +
100
+ `in the package config ${pkgPath}package.json${
101
+ base ? ` imported from ${base}` : ''
102
+ }${relError ? '; targets must start with "./"' : ''}`
103
+ )
104
+ }
105
+
106
+ return `Invalid "${
107
+ isImport ? 'imports' : 'exports'
108
+ }" target ${JSON.stringify(
109
+ target
110
+ )} defined for '${key}' in the package config ${pkgPath}package.json${
111
+ base ? ` imported from ${base}` : ''
112
+ }${relError ? '; targets must start with "./"' : ''}`
113
+ },
114
+ Error
115
+ );
116
+
117
+ createError(
118
+ 'ERR_MODULE_NOT_FOUND',
119
+ /**
120
+ * @param {string} path
121
+ * @param {string} base
122
+ * @param {string} [type]
123
+ */
124
+ (path, base, type = 'package') => {
125
+ return `Cannot find ${type} '${path}' imported from ${base}`
126
+ },
127
+ Error
128
+ );
129
+
130
+ createError(
131
+ 'ERR_NETWORK_IMPORT_DISALLOWED',
132
+ "import of '%s' by %s is not supported: %s",
133
+ Error
134
+ );
135
+
136
+ createError(
137
+ 'ERR_PACKAGE_IMPORT_NOT_DEFINED',
138
+ /**
139
+ * @param {string} specifier
140
+ * @param {string} packagePath
141
+ * @param {string} base
142
+ */
143
+ (specifier, packagePath, base) => {
144
+ return `Package import specifier "${specifier}" is not defined${
145
+ packagePath ? ` in package ${packagePath}package.json` : ''
146
+ } imported from ${base}`
147
+ },
148
+ TypeError
149
+ );
150
+
151
+ createError(
152
+ 'ERR_PACKAGE_PATH_NOT_EXPORTED',
153
+ /**
154
+ * @param {string} pkgPath
155
+ * @param {string} subpath
156
+ * @param {string} [base]
157
+ */
158
+ (pkgPath, subpath, base = undefined) => {
159
+ if (subpath === '.')
160
+ return `No "exports" main defined in ${pkgPath}package.json${
161
+ base ? ` imported from ${base}` : ''
162
+ }`
163
+ return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${
164
+ base ? ` imported from ${base}` : ''
165
+ }`
166
+ },
167
+ Error
168
+ );
169
+
170
+ createError(
171
+ 'ERR_UNSUPPORTED_DIR_IMPORT',
172
+ "Directory import '%s' is not supported " +
173
+ 'resolving ES modules imported from %s',
174
+ Error
175
+ );
176
+
177
+ createError(
178
+ 'ERR_UNKNOWN_FILE_EXTENSION',
179
+ /**
180
+ * @param {string} ext
181
+ * @param {string} path
182
+ */
183
+ (ext, path) => {
184
+ return `Unknown file extension "${ext}" for ${path}`
185
+ },
186
+ TypeError
187
+ );
188
+
189
+ createError(
190
+ 'ERR_INVALID_ARG_VALUE',
191
+ /**
192
+ * @param {string} name
193
+ * @param {unknown} value
194
+ * @param {string} [reason='is invalid']
195
+ */
196
+ (name, value, reason = 'is invalid') => {
197
+ let inspected = inspect(value);
198
+
199
+ if (inspected.length > 128) {
200
+ inspected = `${inspected.slice(0, 128)}...`;
201
+ }
202
+
203
+ const type = name.includes('.') ? 'property' : 'argument';
204
+
205
+ return `The ${type} '${name}' ${reason}. Received ${inspected}`
206
+ },
207
+ TypeError
208
+ // Note: extra classes have been shaken out.
209
+ // , RangeError
210
+ );
211
+
212
+ createError(
213
+ 'ERR_UNSUPPORTED_ESM_URL_SCHEME',
214
+ /**
215
+ * @param {URL} url
216
+ * @param {Array<string>} supported
217
+ */
218
+ (url, supported) => {
219
+ let message = `Only URLs with a scheme in: ${formatList(
220
+ supported
221
+ )} are supported by the default ESM loader`;
222
+
223
+ if (isWindows && url.protocol.length === 2) {
224
+ message += '. On Windows, absolute paths must be valid file:// URLs';
225
+ }
226
+
227
+ message += `. Received protocol '${url.protocol}'`;
228
+ return message
229
+ },
230
+ Error
231
+ );
232
+
233
+ /**
234
+ * Utility function for registering the error codes. Only used here. Exported
235
+ * *only* to allow for testing.
236
+ * @param {string} sym
237
+ * @param {MessageFunction|string} value
238
+ * @param {ErrorConstructor} def
239
+ * @returns {new (...args: Array<any>) => Error}
240
+ */
241
+ function createError(sym, value, def) {
242
+ // Special case for SystemError that formats the error message differently
243
+ // The SystemErrors only have SystemError as their base classes.
244
+ messages.set(sym, value);
245
+
246
+ return makeNodeErrorWithCode(def, sym)
247
+ }
248
+
249
+ /**
250
+ * @param {ErrorConstructor} Base
251
+ * @param {string} key
252
+ * @returns {ErrorConstructor}
253
+ */
254
+ function makeNodeErrorWithCode(Base, key) {
255
+ // @ts-expect-error It’s a Node error.
256
+ return NodeError
257
+ /**
258
+ * @param {Array<unknown>} args
259
+ */
260
+ function NodeError(...args) {
261
+ const limit = Error.stackTraceLimit;
262
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
263
+ const error = new Base();
264
+ // Reset the limit and setting the name property.
265
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
266
+ const message = getMessage(key, args, error);
267
+ Object.defineProperties(error, {
268
+ // Note: no need to implement `kIsNodeError` symbol, would be hard,
269
+ // probably.
270
+ message: {
271
+ value: message,
272
+ enumerable: false,
273
+ writable: true,
274
+ configurable: true
275
+ },
276
+ toString: {
277
+ /** @this {Error} */
278
+ value() {
279
+ return `${this.name} [${key}]: ${this.message}`
280
+ },
281
+ enumerable: false,
282
+ writable: true,
283
+ configurable: true
284
+ }
285
+ });
286
+
287
+ captureLargerStackTrace(error);
288
+ // @ts-expect-error It’s a Node error.
289
+ error.code = key;
290
+ return error
291
+ }
292
+ }
293
+
294
+ /**
295
+ * @returns {boolean}
296
+ */
297
+ function isErrorStackTraceLimitWritable() {
298
+ // Do no touch Error.stackTraceLimit as V8 would attempt to install
299
+ // it again during deserialization.
300
+ try {
301
+ // @ts-expect-error: not in types?
302
+ if (v8.startupSnapshot.isBuildingSnapshot()) {
303
+ return false
304
+ }
305
+ } catch {}
306
+
307
+ const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit');
308
+ if (desc === undefined) {
309
+ return Object.isExtensible(Error)
310
+ }
311
+
312
+ return own$1.call(desc, 'writable') && desc.writable !== undefined
313
+ ? desc.writable
314
+ : desc.set !== undefined
315
+ }
316
+
317
+ /**
318
+ * This function removes unnecessary frames from Node.js core errors.
319
+ * @template {(...args: unknown[]) => unknown} T
320
+ * @param {T} fn
321
+ * @returns {T}
322
+ */
323
+ function hideStackFrames(fn) {
324
+ // We rename the functions that will be hidden to cut off the stacktrace
325
+ // at the outermost one
326
+ const hidden = nodeInternalPrefix + fn.name;
327
+ Object.defineProperty(fn, 'name', {value: hidden});
328
+ return fn
329
+ }
330
+
331
+ const captureLargerStackTrace = hideStackFrames(
332
+ /**
333
+ * @param {Error} error
334
+ * @returns {Error}
335
+ */
336
+ // @ts-expect-error: fine
337
+ function (error) {
338
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
339
+ if (stackTraceLimitIsWritable) {
340
+ userStackTraceLimit = Error.stackTraceLimit;
341
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
342
+ }
343
+
344
+ Error.captureStackTrace(error);
345
+
346
+ // Reset the limit
347
+ if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
348
+
349
+ return error
350
+ }
351
+ );
352
+
353
+ /**
354
+ * @param {string} key
355
+ * @param {Array<unknown>} args
356
+ * @param {Error} self
357
+ * @returns {string}
358
+ */
359
+ function getMessage(key, args, self) {
360
+ const message = messages.get(key);
361
+ assert(typeof message !== 'undefined', 'expected `message` to be found');
362
+
363
+ if (typeof message === 'function') {
364
+ assert(
365
+ message.length <= args.length, // Default options do not count.
366
+ `Code: ${key}; The provided arguments length (${args.length}) does not ` +
367
+ `match the required ones (${message.length}).`
368
+ );
369
+ return Reflect.apply(message, self, args)
370
+ }
371
+
372
+ const regex = /%[dfijoOs]/g;
373
+ let expectedLength = 0;
374
+ while (regex.exec(message) !== null) expectedLength++;
375
+ assert(
376
+ expectedLength === args.length,
377
+ `Code: ${key}; The provided arguments length (${args.length}) does not ` +
378
+ `match the required ones (${expectedLength}).`
379
+ );
380
+ if (args.length === 0) return message
381
+
382
+ args.unshift(message);
383
+ return Reflect.apply(format, null, args)
384
+ }
385
+ function isNodeBuiltin(id = "") {
386
+ id = id.replace(/^node:/, "").split("/")[0];
387
+ return BUILTIN_MODULES.has(id);
388
+ }
389
+ pathToFileURL(process.cwd());
390
+ const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
391
+ function hasCJSSyntax(code) {
392
+ return CJS_RE.test(code);
393
+ }
394
+
395
+ export { hasCJSSyntax as h, isNodeBuiltin as i };