vitest 1.6.0 → 2.0.0-beta.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.
- package/LICENSE.md +172 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +4 -4
- package/dist/chunks/{environments-node.vcoXCoKs.js → environments-node.39w4gmlF.js} +2 -2
- package/dist/chunks/{install-pkg.LE8oaA1t.js → install-pkg.DNUmWFkO.js} +2 -2
- package/dist/chunks/integrations-globals.B5Jl0grA.js +31 -0
- package/dist/chunks/{runtime-console.EO5ha7qv.js → runtime-console.CUES-L8X.js} +9 -9
- package/dist/chunks/{runtime-runBaseTests.oAvMKtQC.js → runtime-runBaseTests._dXkRAZc.js} +18 -18
- package/dist/cli.js +3 -3
- package/dist/config.cjs +1 -2
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -2
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +2 -2
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +2 -1
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +769 -21
- package/dist/index.js +12 -12
- package/dist/node.d.ts +2 -2
- package/dist/node.js +20 -21
- package/dist/{reporters-yx5ZTtEV.d.ts → reporters-MGvT5U9f.d.ts} +28 -31
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +10 -11
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +17 -18
- package/dist/snapshot.js +3 -3
- package/dist/{suite-IbNSsUWN.d.ts → suite-8WAe-urM.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +4 -4
- package/dist/vendor/{base.Ybri3C14.js → base.VFkIJ66g.js} +3 -3
- package/dist/vendor/{base.5NT-gWu5.js → base._gnK9Slw.js} +1 -2
- package/dist/vendor/{benchmark.yGkUTKnC.js → benchmark.BNLebNi5.js} +1 -1
- package/dist/vendor/{cac.EdDItJD-.js → cac.DzKZaJu2.js} +5 -6
- package/dist/vendor/{cli-api.E07AF1Yq.js → cli-api.DTeni0Qq.js} +3060 -361
- package/dist/vendor/{execute.fL3szUAI.js → execute.CLLNVNnK.js} +1 -1
- package/dist/vendor/{index.DpVgvm2P.js → index.BfoZyXD1.js} +5 -5
- package/dist/vendor/{index.8bPxjt7g.js → index.BpSiYbpB.js} +5 -1
- package/dist/vendor/{index.Q04MCqDO.js → index.CRxYS9H3.js} +414 -113
- package/dist/vendor/{index.dI9lHwVn.js → index.CmILuxzC.js} +8 -6
- package/dist/vendor/{index.xL8XjTLv.js → index.DP-km6lF.js} +1 -1
- package/dist/vendor/{index.SMVOaj7F.js → index._7XLd8Kd.js} +2 -2
- package/dist/vendor/{rpc.joBhAkyK.js → rpc.DRDE9Pu1.js} +2 -2
- package/dist/vendor/{run-once.Olz_Zkd8.js → run-once.DLomgGUH.js} +1 -1
- package/dist/vendor/{setup-common.8nJLd4ay.js → setup-common.XeoZAW8t.js} +2 -2
- package/dist/vendor/{tasks.IknbGB2n.js → tasks.WC7M-K-v.js} +4 -1
- package/dist/vendor/{utils.dEtNIEgr.js → utils.D5gGkwyH.js} +1 -1
- package/dist/vendor/{vi.YFlodzP_.js → vi.ClD3hi7L.js} +23 -10
- package/dist/vendor/{vm.QEE48c0T.js → vm.Bi3bljci.js} +47 -59
- package/dist/worker.js +6 -6
- package/dist/workers/forks.js +5 -5
- package/dist/workers/runVmTests.js +17 -17
- package/dist/workers/threads.js +5 -5
- package/dist/workers/vmForks.js +8 -8
- package/dist/workers/vmThreads.js +8 -8
- package/dist/workers.d.ts +1 -1
- package/dist/workers.js +13 -13
- package/package.json +29 -29
- package/vitest.mjs +1 -1
- package/dist/chunks/integrations-globals.kw4co3rx.js +0 -31
- package/dist/cli-wrapper.js +0 -119
- /package/dist/chunks/{node-git.Hw101KjS.js → node-git.CCI8evVZ.js} +0 -0
- /package/dist/vendor/{_commonjsHelpers.jjO7Zipk.js → _commonjsHelpers.BFTU3MAI.js} +0 -0
- /package/dist/vendor/{constants.5J7I254_.js → constants.5SOfHUj0.js} +0 -0
- /package/dist/vendor/{coverage.E7sG1b3r.js → coverage.ChSqD-qS.js} +0 -0
- /package/dist/vendor/{date.Ns1pGd_X.js → date.BKM1wewY.js} +0 -0
- /package/dist/vendor/{env.AtSIuHFg.js → env.bmJgw1qP.js} +0 -0
- /package/dist/vendor/{global.CkGT_TMy.js → global.7bFbnyXl.js} +0 -0
- /package/dist/vendor/{index.GVFv9dZ0.js → index.DeR1hhfY.js} +0 -0
- /package/dist/vendor/{inspector.IgLX3ur5.js → inspector.hPQncR7V.js} +0 -0
- /package/dist/vendor/{utils.0uYuCbzo.js → utils.CUjzkRH7.js} +0 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { dirname, join, resolve, relative, normalize, basename, toNamespacedPath
|
|
2
|
-
import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.
|
|
3
|
-
import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.
|
|
4
|
-
import { g as getEnvPackageName } from './index.
|
|
5
|
-
import { isFileServingAllowed, searchForWorkspaceRoot, version
|
|
6
|
-
import path$8 from 'node:path';
|
|
7
|
-
import url, { fileURLToPath } from 'node:url';
|
|
1
|
+
import { dirname, join, resolve, relative, isAbsolute, normalize, basename, toNamespacedPath } from 'pathe';
|
|
2
|
+
import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.5SOfHUj0.js';
|
|
3
|
+
import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.ChSqD-qS.js';
|
|
4
|
+
import { g as getEnvPackageName } from './index.DeR1hhfY.js';
|
|
5
|
+
import { isFileServingAllowed, searchForWorkspaceRoot, version, createServer, mergeConfig } from 'vite';
|
|
6
|
+
import path$8, { win32 } from 'node:path';
|
|
7
|
+
import url, { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$2 } from 'node:url';
|
|
8
8
|
import process$1 from 'node:process';
|
|
9
|
-
import fs$8, { promises as promises$1, existsSync, readFileSync } from 'node:fs';
|
|
9
|
+
import fs$8, { promises as promises$1, existsSync, statSync as statSync$1, realpathSync, readFileSync } from 'node:fs';
|
|
10
10
|
import { MessageChannel, isMainThread } from 'node:worker_threads';
|
|
11
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.
|
|
11
|
+
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
12
12
|
import require$$0 from 'os';
|
|
13
13
|
import p from 'path';
|
|
14
|
-
import { a as micromatch_1, m as mm } from './index.
|
|
14
|
+
import { a as micromatch_1, m as mm } from './index.DP-km6lF.js';
|
|
15
15
|
import require$$0$1 from 'stream';
|
|
16
16
|
import require$$0$3 from 'events';
|
|
17
17
|
import require$$0$2 from 'fs';
|
|
@@ -19,12 +19,13 @@ import c from 'picocolors';
|
|
|
19
19
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
20
20
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
21
21
|
import { ViteNodeServer } from 'vite-node/server';
|
|
22
|
+
import { v as version$1 } from './cac.DzKZaJu2.js';
|
|
22
23
|
import { hasFailed, getTasks, getTests } from '@vitest/runner/utils';
|
|
23
|
-
import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base.
|
|
24
|
+
import { n as noop$2, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base._gnK9Slw.js';
|
|
24
25
|
import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
|
|
25
|
-
import { a as isWindows } from './env.
|
|
26
|
+
import { a as isWindows } from './env.bmJgw1qP.js';
|
|
26
27
|
import { rootDir } from '../path.js';
|
|
27
|
-
import { c as createBirpc } from './index.
|
|
28
|
+
import { c as createBirpc } from './index.BpSiYbpB.js';
|
|
28
29
|
import require$$0$4 from 'zlib';
|
|
29
30
|
import require$$0$5 from 'buffer';
|
|
30
31
|
import require$$1 from 'crypto';
|
|
@@ -39,20 +40,18 @@ import * as nodeos from 'node:os';
|
|
|
39
40
|
import nodeos__default, { tmpdir } from 'node:os';
|
|
40
41
|
import EventEmitter$2 from 'node:events';
|
|
41
42
|
import Tinypool$1, { Tinypool } from 'tinypool';
|
|
42
|
-
import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as
|
|
43
|
+
import { w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as findNodeAround, i as generateCodeFrame, j as highlightCode, L as Logger } from './index.CRxYS9H3.js';
|
|
43
44
|
import crypto, { createHash as createHash$2 } from 'node:crypto';
|
|
44
45
|
import { mkdir, writeFile, rm } from 'node:fs/promises';
|
|
45
|
-
import {
|
|
46
|
+
import { builtinModules, createRequire } from 'node:module';
|
|
47
|
+
import assert from 'node:assert';
|
|
48
|
+
import { format as format$2, inspect } from 'node:util';
|
|
46
49
|
import { isCI, provider as provider$1 } from 'std-env';
|
|
47
|
-
import { v as version } from './cac.EdDItJD-.js';
|
|
48
50
|
import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
|
|
49
51
|
import MagicString from 'magic-string';
|
|
50
|
-
import { findNodeAround } from 'acorn-walk';
|
|
51
52
|
import { esmWalker } from '@vitest/utils/ast';
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import { createRequire } from 'node:module';
|
|
55
|
-
import { a as removeUndefinedValues } from './index.SMVOaj7F.js';
|
|
53
|
+
import { d as divider, s as stripAnsi } from './utils.D5gGkwyH.js';
|
|
54
|
+
import { a as removeUndefinedValues } from './index._7XLd8Kd.js';
|
|
56
55
|
import readline from 'node:readline';
|
|
57
56
|
import require$$0$6 from 'readline';
|
|
58
57
|
|
|
@@ -315,7 +314,7 @@ function checkType(type) {
|
|
|
315
314
|
|
|
316
315
|
const matchType = (type, stat) => stat[typeMappings[type]]();
|
|
317
316
|
|
|
318
|
-
const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
317
|
+
const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath$1(urlOrPath) : urlOrPath;
|
|
319
318
|
|
|
320
319
|
async function locatePath(
|
|
321
320
|
paths,
|
|
@@ -342,7 +341,7 @@ async function locatePath(
|
|
|
342
341
|
}, {concurrency, preserveOrder});
|
|
343
342
|
}
|
|
344
343
|
|
|
345
|
-
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
344
|
+
const toPath = urlOrPath => urlOrPath instanceof URL ? fileURLToPath$1(urlOrPath) : urlOrPath;
|
|
346
345
|
|
|
347
346
|
const findUpStop = Symbol('findUpStop');
|
|
348
347
|
|
|
@@ -1249,7 +1248,7 @@ var async$2 = {};
|
|
|
1249
1248
|
|
|
1250
1249
|
Object.defineProperty(async$2, "__esModule", { value: true });
|
|
1251
1250
|
async$2.read = void 0;
|
|
1252
|
-
function read$
|
|
1251
|
+
function read$4(path, settings, callback) {
|
|
1253
1252
|
settings.fs.lstat(path, (lstatError, lstat) => {
|
|
1254
1253
|
if (lstatError !== null) {
|
|
1255
1254
|
callFailureCallback$2(callback, lstatError);
|
|
@@ -1275,7 +1274,7 @@ function read$3(path, settings, callback) {
|
|
|
1275
1274
|
});
|
|
1276
1275
|
});
|
|
1277
1276
|
}
|
|
1278
|
-
async$2.read = read$
|
|
1277
|
+
async$2.read = read$4;
|
|
1279
1278
|
function callFailureCallback$2(callback, error) {
|
|
1280
1279
|
callback(error);
|
|
1281
1280
|
}
|
|
@@ -1287,7 +1286,7 @@ var sync$7 = {};
|
|
|
1287
1286
|
|
|
1288
1287
|
Object.defineProperty(sync$7, "__esModule", { value: true });
|
|
1289
1288
|
sync$7.read = void 0;
|
|
1290
|
-
function read$
|
|
1289
|
+
function read$3(path, settings) {
|
|
1291
1290
|
const lstat = settings.fs.lstatSync(path);
|
|
1292
1291
|
if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
|
|
1293
1292
|
return lstat;
|
|
@@ -1306,7 +1305,7 @@ function read$2(path, settings) {
|
|
|
1306
1305
|
throw error;
|
|
1307
1306
|
}
|
|
1308
1307
|
}
|
|
1309
|
-
sync$7.read = read$
|
|
1308
|
+
sync$7.read = read$3;
|
|
1310
1309
|
|
|
1311
1310
|
var settings$3 = {};
|
|
1312
1311
|
|
|
@@ -1375,12 +1374,12 @@ function getSettings$2(settingsOrOptions = {}) {
|
|
|
1375
1374
|
|
|
1376
1375
|
/*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
1377
1376
|
|
|
1378
|
-
let promise
|
|
1377
|
+
let promise;
|
|
1379
1378
|
|
|
1380
1379
|
var queueMicrotask_1 = typeof queueMicrotask === 'function'
|
|
1381
1380
|
? queueMicrotask.bind(typeof window !== 'undefined' ? window : commonjsGlobal)
|
|
1382
1381
|
// reuse resolved promise, and allocate it lazily
|
|
1383
|
-
: cb => (promise
|
|
1382
|
+
: cb => (promise || (promise = Promise.resolve()))
|
|
1384
1383
|
.then(cb)
|
|
1385
1384
|
.catch(err => setTimeout(() => { throw err }, 0));
|
|
1386
1385
|
|
|
@@ -1506,14 +1505,14 @@ const rpl = runParallel_1;
|
|
|
1506
1505
|
const constants_1$1 = constants$1;
|
|
1507
1506
|
const utils$8 = utils$9;
|
|
1508
1507
|
const common$5 = common$6;
|
|
1509
|
-
function read$
|
|
1508
|
+
function read$2(directory, settings, callback) {
|
|
1510
1509
|
if (!settings.stats && constants_1$1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
|
|
1511
1510
|
readdirWithFileTypes$1(directory, settings, callback);
|
|
1512
1511
|
return;
|
|
1513
1512
|
}
|
|
1514
1513
|
readdir$1(directory, settings, callback);
|
|
1515
1514
|
}
|
|
1516
|
-
async$3.read = read$
|
|
1515
|
+
async$3.read = read$2;
|
|
1517
1516
|
function readdirWithFileTypes$1(directory, settings, callback) {
|
|
1518
1517
|
settings.fs.readdir(directory, { withFileTypes: true }, (readdirError, dirents) => {
|
|
1519
1518
|
if (readdirError !== null) {
|
|
@@ -1611,13 +1610,13 @@ const fsStat$4 = out$1;
|
|
|
1611
1610
|
const constants_1 = constants$1;
|
|
1612
1611
|
const utils$7 = utils$9;
|
|
1613
1612
|
const common$4 = common$6;
|
|
1614
|
-
function read(directory, settings) {
|
|
1613
|
+
function read$1(directory, settings) {
|
|
1615
1614
|
if (!settings.stats && constants_1.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
|
|
1616
1615
|
return readdirWithFileTypes(directory, settings);
|
|
1617
1616
|
}
|
|
1618
1617
|
return readdir(directory, settings);
|
|
1619
1618
|
}
|
|
1620
|
-
sync$5.read = read;
|
|
1619
|
+
sync$5.read = read$1;
|
|
1621
1620
|
function readdirWithFileTypes(directory, settings) {
|
|
1622
1621
|
const dirents = settings.fs.readdirSync(directory, { withFileTypes: true });
|
|
1623
1622
|
return dirents.map((dirent) => {
|
|
@@ -2745,9 +2744,9 @@ class EntryFilter {
|
|
|
2745
2744
|
}
|
|
2746
2745
|
entry$1.default = EntryFilter;
|
|
2747
2746
|
|
|
2748
|
-
var error
|
|
2747
|
+
var error = {};
|
|
2749
2748
|
|
|
2750
|
-
Object.defineProperty(error
|
|
2749
|
+
Object.defineProperty(error, "__esModule", { value: true });
|
|
2751
2750
|
const utils$2 = utils$b;
|
|
2752
2751
|
class ErrorFilter {
|
|
2753
2752
|
constructor(_settings) {
|
|
@@ -2760,7 +2759,7 @@ class ErrorFilter {
|
|
|
2760
2759
|
return utils$2.errno.isEnoentCodeError(error) || this._settings.suppressErrors;
|
|
2761
2760
|
}
|
|
2762
2761
|
}
|
|
2763
|
-
error
|
|
2762
|
+
error.default = ErrorFilter;
|
|
2764
2763
|
|
|
2765
2764
|
var entry = {};
|
|
2766
2765
|
|
|
@@ -2794,7 +2793,7 @@ Object.defineProperty(provider, "__esModule", { value: true });
|
|
|
2794
2793
|
const path = p;
|
|
2795
2794
|
const deep_1 = deep;
|
|
2796
2795
|
const entry_1 = entry$1;
|
|
2797
|
-
const error_1 = error
|
|
2796
|
+
const error_1 = error;
|
|
2798
2797
|
const entry_2 = entry;
|
|
2799
2798
|
class Provider {
|
|
2800
2799
|
constructor(_settings) {
|
|
@@ -3129,7 +3128,9 @@ var out = FastGlob;
|
|
|
3129
3128
|
|
|
3130
3129
|
var fg = /*@__PURE__*/getDefaultExportFromCjs(out);
|
|
3131
3130
|
|
|
3132
|
-
|
|
3131
|
+
/// <reference types="../types/index.d.ts" />
|
|
3132
|
+
|
|
3133
|
+
// (c) 2020-present Andrea Giammarchi
|
|
3133
3134
|
|
|
3134
3135
|
const {parse: $parse, stringify: $stringify} = JSON;
|
|
3135
3136
|
const {keys: keys$1} = Object;
|
|
@@ -3181,6 +3182,12 @@ const set = (known, input, value) => {
|
|
|
3181
3182
|
return index;
|
|
3182
3183
|
};
|
|
3183
3184
|
|
|
3185
|
+
/**
|
|
3186
|
+
* Converts a specialized flatted string into a JS value.
|
|
3187
|
+
* @param {string} text
|
|
3188
|
+
* @param {(this: any, key: string, value: any) => any} [reviver]
|
|
3189
|
+
* @returns {any}
|
|
3190
|
+
*/
|
|
3184
3191
|
const parse$3 = (text, reviver) => {
|
|
3185
3192
|
const input = $parse(text, Primitives).map(primitives);
|
|
3186
3193
|
const value = input[0];
|
|
@@ -3191,6 +3198,13 @@ const parse$3 = (text, reviver) => {
|
|
|
3191
3198
|
return $.call({'': tmp}, '', tmp);
|
|
3192
3199
|
};
|
|
3193
3200
|
|
|
3201
|
+
/**
|
|
3202
|
+
* Converts a JS value into a specialized flatted string.
|
|
3203
|
+
* @param {any} value
|
|
3204
|
+
* @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer]
|
|
3205
|
+
* @param {string | number | undefined} [space]
|
|
3206
|
+
* @returns {string}
|
|
3207
|
+
*/
|
|
3194
3208
|
const stringify = (value, replacer, space) => {
|
|
3195
3209
|
const $ = replacer && typeof replacer === object ?
|
|
3196
3210
|
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
|
|
@@ -4084,13 +4098,6 @@ const { concat, toArrayBuffer, unmask } = bufferUtilExports;
|
|
|
4084
4098
|
const { isValidStatusCode: isValidStatusCode$1, isValidUTF8 } = validationExports;
|
|
4085
4099
|
|
|
4086
4100
|
const FastBuffer = Buffer[Symbol.species];
|
|
4087
|
-
const promise = Promise.resolve();
|
|
4088
|
-
|
|
4089
|
-
//
|
|
4090
|
-
// `queueMicrotask()` is not available in Node.js < 11.
|
|
4091
|
-
//
|
|
4092
|
-
const queueTask =
|
|
4093
|
-
typeof queueMicrotask === 'function' ? queueMicrotask : queueMicrotaskShim;
|
|
4094
4101
|
|
|
4095
4102
|
const GET_INFO = 0;
|
|
4096
4103
|
const GET_PAYLOAD_LENGTH_16 = 1;
|
|
@@ -4098,7 +4105,7 @@ const GET_PAYLOAD_LENGTH_64 = 2;
|
|
|
4098
4105
|
const GET_MASK = 3;
|
|
4099
4106
|
const GET_DATA = 4;
|
|
4100
4107
|
const INFLATING = 5;
|
|
4101
|
-
const
|
|
4108
|
+
const DEFER_EVENT = 6;
|
|
4102
4109
|
|
|
4103
4110
|
/**
|
|
4104
4111
|
* HyBi Receiver implementation.
|
|
@@ -4110,6 +4117,9 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4110
4117
|
* Creates a Receiver instance.
|
|
4111
4118
|
*
|
|
4112
4119
|
* @param {Object} [options] Options object
|
|
4120
|
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
4121
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
4122
|
+
* multiple times in the same tick
|
|
4113
4123
|
* @param {String} [options.binaryType=nodebuffer] The type for binary data
|
|
4114
4124
|
* @param {Object} [options.extensions] An object containing the negotiated
|
|
4115
4125
|
* extensions
|
|
@@ -4122,6 +4132,10 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4122
4132
|
constructor(options = {}) {
|
|
4123
4133
|
super();
|
|
4124
4134
|
|
|
4135
|
+
this._allowSynchronousEvents =
|
|
4136
|
+
options.allowSynchronousEvents !== undefined
|
|
4137
|
+
? options.allowSynchronousEvents
|
|
4138
|
+
: true;
|
|
4125
4139
|
this._binaryType = options.binaryType || BINARY_TYPES$1[0];
|
|
4126
4140
|
this._extensions = options.extensions || {};
|
|
4127
4141
|
this._isServer = !!options.isServer;
|
|
@@ -4144,8 +4158,9 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4144
4158
|
this._messageLength = 0;
|
|
4145
4159
|
this._fragments = [];
|
|
4146
4160
|
|
|
4147
|
-
this.
|
|
4161
|
+
this._errored = false;
|
|
4148
4162
|
this._loop = false;
|
|
4163
|
+
this._state = GET_INFO;
|
|
4149
4164
|
}
|
|
4150
4165
|
|
|
4151
4166
|
/**
|
|
@@ -4217,53 +4232,42 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4217
4232
|
* @private
|
|
4218
4233
|
*/
|
|
4219
4234
|
startLoop(cb) {
|
|
4220
|
-
let err;
|
|
4221
4235
|
this._loop = true;
|
|
4222
4236
|
|
|
4223
4237
|
do {
|
|
4224
4238
|
switch (this._state) {
|
|
4225
4239
|
case GET_INFO:
|
|
4226
|
-
|
|
4240
|
+
this.getInfo(cb);
|
|
4227
4241
|
break;
|
|
4228
4242
|
case GET_PAYLOAD_LENGTH_16:
|
|
4229
|
-
|
|
4243
|
+
this.getPayloadLength16(cb);
|
|
4230
4244
|
break;
|
|
4231
4245
|
case GET_PAYLOAD_LENGTH_64:
|
|
4232
|
-
|
|
4246
|
+
this.getPayloadLength64(cb);
|
|
4233
4247
|
break;
|
|
4234
4248
|
case GET_MASK:
|
|
4235
4249
|
this.getMask();
|
|
4236
4250
|
break;
|
|
4237
4251
|
case GET_DATA:
|
|
4238
|
-
|
|
4252
|
+
this.getData(cb);
|
|
4239
4253
|
break;
|
|
4240
4254
|
case INFLATING:
|
|
4255
|
+
case DEFER_EVENT:
|
|
4241
4256
|
this._loop = false;
|
|
4242
4257
|
return;
|
|
4243
|
-
default:
|
|
4244
|
-
//
|
|
4245
|
-
// `WAIT_MICROTASK`.
|
|
4246
|
-
//
|
|
4247
|
-
this._loop = false;
|
|
4248
|
-
|
|
4249
|
-
queueTask(() => {
|
|
4250
|
-
this._state = GET_INFO;
|
|
4251
|
-
this.startLoop(cb);
|
|
4252
|
-
});
|
|
4253
|
-
return;
|
|
4254
4258
|
}
|
|
4255
4259
|
} while (this._loop);
|
|
4256
4260
|
|
|
4257
|
-
cb(
|
|
4261
|
+
if (!this._errored) cb();
|
|
4258
4262
|
}
|
|
4259
4263
|
|
|
4260
4264
|
/**
|
|
4261
4265
|
* Reads the first two bytes of a frame.
|
|
4262
4266
|
*
|
|
4263
|
-
* @
|
|
4267
|
+
* @param {Function} cb Callback
|
|
4264
4268
|
* @private
|
|
4265
4269
|
*/
|
|
4266
|
-
getInfo() {
|
|
4270
|
+
getInfo(cb) {
|
|
4267
4271
|
if (this._bufferedBytes < 2) {
|
|
4268
4272
|
this._loop = false;
|
|
4269
4273
|
return;
|
|
@@ -4272,27 +4276,31 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4272
4276
|
const buf = this.consume(2);
|
|
4273
4277
|
|
|
4274
4278
|
if ((buf[0] & 0x30) !== 0x00) {
|
|
4275
|
-
|
|
4276
|
-
return error(
|
|
4279
|
+
const error = this.createError(
|
|
4277
4280
|
RangeError,
|
|
4278
4281
|
'RSV2 and RSV3 must be clear',
|
|
4279
4282
|
true,
|
|
4280
4283
|
1002,
|
|
4281
4284
|
'WS_ERR_UNEXPECTED_RSV_2_3'
|
|
4282
4285
|
);
|
|
4286
|
+
|
|
4287
|
+
cb(error);
|
|
4288
|
+
return;
|
|
4283
4289
|
}
|
|
4284
4290
|
|
|
4285
4291
|
const compressed = (buf[0] & 0x40) === 0x40;
|
|
4286
4292
|
|
|
4287
4293
|
if (compressed && !this._extensions[PerMessageDeflate$3.extensionName]) {
|
|
4288
|
-
|
|
4289
|
-
return error(
|
|
4294
|
+
const error = this.createError(
|
|
4290
4295
|
RangeError,
|
|
4291
4296
|
'RSV1 must be clear',
|
|
4292
4297
|
true,
|
|
4293
4298
|
1002,
|
|
4294
4299
|
'WS_ERR_UNEXPECTED_RSV_1'
|
|
4295
4300
|
);
|
|
4301
|
+
|
|
4302
|
+
cb(error);
|
|
4303
|
+
return;
|
|
4296
4304
|
}
|
|
4297
4305
|
|
|
4298
4306
|
this._fin = (buf[0] & 0x80) === 0x80;
|
|
@@ -4301,86 +4309,100 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4301
4309
|
|
|
4302
4310
|
if (this._opcode === 0x00) {
|
|
4303
4311
|
if (compressed) {
|
|
4304
|
-
|
|
4305
|
-
return error(
|
|
4312
|
+
const error = this.createError(
|
|
4306
4313
|
RangeError,
|
|
4307
4314
|
'RSV1 must be clear',
|
|
4308
4315
|
true,
|
|
4309
4316
|
1002,
|
|
4310
4317
|
'WS_ERR_UNEXPECTED_RSV_1'
|
|
4311
4318
|
);
|
|
4319
|
+
|
|
4320
|
+
cb(error);
|
|
4321
|
+
return;
|
|
4312
4322
|
}
|
|
4313
4323
|
|
|
4314
4324
|
if (!this._fragmented) {
|
|
4315
|
-
|
|
4316
|
-
return error(
|
|
4325
|
+
const error = this.createError(
|
|
4317
4326
|
RangeError,
|
|
4318
4327
|
'invalid opcode 0',
|
|
4319
4328
|
true,
|
|
4320
4329
|
1002,
|
|
4321
4330
|
'WS_ERR_INVALID_OPCODE'
|
|
4322
4331
|
);
|
|
4332
|
+
|
|
4333
|
+
cb(error);
|
|
4334
|
+
return;
|
|
4323
4335
|
}
|
|
4324
4336
|
|
|
4325
4337
|
this._opcode = this._fragmented;
|
|
4326
4338
|
} else if (this._opcode === 0x01 || this._opcode === 0x02) {
|
|
4327
4339
|
if (this._fragmented) {
|
|
4328
|
-
|
|
4329
|
-
return error(
|
|
4340
|
+
const error = this.createError(
|
|
4330
4341
|
RangeError,
|
|
4331
4342
|
`invalid opcode ${this._opcode}`,
|
|
4332
4343
|
true,
|
|
4333
4344
|
1002,
|
|
4334
4345
|
'WS_ERR_INVALID_OPCODE'
|
|
4335
4346
|
);
|
|
4347
|
+
|
|
4348
|
+
cb(error);
|
|
4349
|
+
return;
|
|
4336
4350
|
}
|
|
4337
4351
|
|
|
4338
4352
|
this._compressed = compressed;
|
|
4339
4353
|
} else if (this._opcode > 0x07 && this._opcode < 0x0b) {
|
|
4340
4354
|
if (!this._fin) {
|
|
4341
|
-
|
|
4342
|
-
return error(
|
|
4355
|
+
const error = this.createError(
|
|
4343
4356
|
RangeError,
|
|
4344
4357
|
'FIN must be set',
|
|
4345
4358
|
true,
|
|
4346
4359
|
1002,
|
|
4347
4360
|
'WS_ERR_EXPECTED_FIN'
|
|
4348
4361
|
);
|
|
4362
|
+
|
|
4363
|
+
cb(error);
|
|
4364
|
+
return;
|
|
4349
4365
|
}
|
|
4350
4366
|
|
|
4351
4367
|
if (compressed) {
|
|
4352
|
-
|
|
4353
|
-
return error(
|
|
4368
|
+
const error = this.createError(
|
|
4354
4369
|
RangeError,
|
|
4355
4370
|
'RSV1 must be clear',
|
|
4356
4371
|
true,
|
|
4357
4372
|
1002,
|
|
4358
4373
|
'WS_ERR_UNEXPECTED_RSV_1'
|
|
4359
4374
|
);
|
|
4375
|
+
|
|
4376
|
+
cb(error);
|
|
4377
|
+
return;
|
|
4360
4378
|
}
|
|
4361
4379
|
|
|
4362
4380
|
if (
|
|
4363
4381
|
this._payloadLength > 0x7d ||
|
|
4364
4382
|
(this._opcode === 0x08 && this._payloadLength === 1)
|
|
4365
4383
|
) {
|
|
4366
|
-
|
|
4367
|
-
return error(
|
|
4384
|
+
const error = this.createError(
|
|
4368
4385
|
RangeError,
|
|
4369
4386
|
`invalid payload length ${this._payloadLength}`,
|
|
4370
4387
|
true,
|
|
4371
4388
|
1002,
|
|
4372
4389
|
'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
|
|
4373
4390
|
);
|
|
4391
|
+
|
|
4392
|
+
cb(error);
|
|
4393
|
+
return;
|
|
4374
4394
|
}
|
|
4375
4395
|
} else {
|
|
4376
|
-
|
|
4377
|
-
return error(
|
|
4396
|
+
const error = this.createError(
|
|
4378
4397
|
RangeError,
|
|
4379
4398
|
`invalid opcode ${this._opcode}`,
|
|
4380
4399
|
true,
|
|
4381
4400
|
1002,
|
|
4382
4401
|
'WS_ERR_INVALID_OPCODE'
|
|
4383
4402
|
);
|
|
4403
|
+
|
|
4404
|
+
cb(error);
|
|
4405
|
+
return;
|
|
4384
4406
|
}
|
|
4385
4407
|
|
|
4386
4408
|
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
@@ -4388,54 +4410,58 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4388
4410
|
|
|
4389
4411
|
if (this._isServer) {
|
|
4390
4412
|
if (!this._masked) {
|
|
4391
|
-
|
|
4392
|
-
return error(
|
|
4413
|
+
const error = this.createError(
|
|
4393
4414
|
RangeError,
|
|
4394
4415
|
'MASK must be set',
|
|
4395
4416
|
true,
|
|
4396
4417
|
1002,
|
|
4397
4418
|
'WS_ERR_EXPECTED_MASK'
|
|
4398
4419
|
);
|
|
4420
|
+
|
|
4421
|
+
cb(error);
|
|
4422
|
+
return;
|
|
4399
4423
|
}
|
|
4400
4424
|
} else if (this._masked) {
|
|
4401
|
-
|
|
4402
|
-
return error(
|
|
4425
|
+
const error = this.createError(
|
|
4403
4426
|
RangeError,
|
|
4404
4427
|
'MASK must be clear',
|
|
4405
4428
|
true,
|
|
4406
4429
|
1002,
|
|
4407
4430
|
'WS_ERR_UNEXPECTED_MASK'
|
|
4408
4431
|
);
|
|
4432
|
+
|
|
4433
|
+
cb(error);
|
|
4434
|
+
return;
|
|
4409
4435
|
}
|
|
4410
4436
|
|
|
4411
4437
|
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
4412
4438
|
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
4413
|
-
else
|
|
4439
|
+
else this.haveLength(cb);
|
|
4414
4440
|
}
|
|
4415
4441
|
|
|
4416
4442
|
/**
|
|
4417
4443
|
* Gets extended payload length (7+16).
|
|
4418
4444
|
*
|
|
4419
|
-
* @
|
|
4445
|
+
* @param {Function} cb Callback
|
|
4420
4446
|
* @private
|
|
4421
4447
|
*/
|
|
4422
|
-
getPayloadLength16() {
|
|
4448
|
+
getPayloadLength16(cb) {
|
|
4423
4449
|
if (this._bufferedBytes < 2) {
|
|
4424
4450
|
this._loop = false;
|
|
4425
4451
|
return;
|
|
4426
4452
|
}
|
|
4427
4453
|
|
|
4428
4454
|
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
4429
|
-
|
|
4455
|
+
this.haveLength(cb);
|
|
4430
4456
|
}
|
|
4431
4457
|
|
|
4432
4458
|
/**
|
|
4433
4459
|
* Gets extended payload length (7+64).
|
|
4434
4460
|
*
|
|
4435
|
-
* @
|
|
4461
|
+
* @param {Function} cb Callback
|
|
4436
4462
|
* @private
|
|
4437
4463
|
*/
|
|
4438
|
-
getPayloadLength64() {
|
|
4464
|
+
getPayloadLength64(cb) {
|
|
4439
4465
|
if (this._bufferedBytes < 8) {
|
|
4440
4466
|
this._loop = false;
|
|
4441
4467
|
return;
|
|
@@ -4449,38 +4475,42 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4449
4475
|
// if payload length is greater than this number.
|
|
4450
4476
|
//
|
|
4451
4477
|
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
4452
|
-
|
|
4453
|
-
return error(
|
|
4478
|
+
const error = this.createError(
|
|
4454
4479
|
RangeError,
|
|
4455
4480
|
'Unsupported WebSocket frame: payload length > 2^53 - 1',
|
|
4456
4481
|
false,
|
|
4457
4482
|
1009,
|
|
4458
4483
|
'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
|
|
4459
4484
|
);
|
|
4485
|
+
|
|
4486
|
+
cb(error);
|
|
4487
|
+
return;
|
|
4460
4488
|
}
|
|
4461
4489
|
|
|
4462
4490
|
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
4463
|
-
|
|
4491
|
+
this.haveLength(cb);
|
|
4464
4492
|
}
|
|
4465
4493
|
|
|
4466
4494
|
/**
|
|
4467
4495
|
* Payload length has been read.
|
|
4468
4496
|
*
|
|
4469
|
-
* @
|
|
4497
|
+
* @param {Function} cb Callback
|
|
4470
4498
|
* @private
|
|
4471
4499
|
*/
|
|
4472
|
-
haveLength() {
|
|
4500
|
+
haveLength(cb) {
|
|
4473
4501
|
if (this._payloadLength && this._opcode < 0x08) {
|
|
4474
4502
|
this._totalPayloadLength += this._payloadLength;
|
|
4475
4503
|
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
4476
|
-
|
|
4477
|
-
return error(
|
|
4504
|
+
const error = this.createError(
|
|
4478
4505
|
RangeError,
|
|
4479
4506
|
'Max payload size exceeded',
|
|
4480
4507
|
false,
|
|
4481
4508
|
1009,
|
|
4482
4509
|
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
|
4483
4510
|
);
|
|
4511
|
+
|
|
4512
|
+
cb(error);
|
|
4513
|
+
return;
|
|
4484
4514
|
}
|
|
4485
4515
|
}
|
|
4486
4516
|
|
|
@@ -4507,7 +4537,6 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4507
4537
|
* Reads data bytes.
|
|
4508
4538
|
*
|
|
4509
4539
|
* @param {Function} cb Callback
|
|
4510
|
-
* @return {(Error|RangeError|undefined)} A possible error
|
|
4511
4540
|
* @private
|
|
4512
4541
|
*/
|
|
4513
4542
|
getData(cb) {
|
|
@@ -4529,7 +4558,10 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4529
4558
|
}
|
|
4530
4559
|
}
|
|
4531
4560
|
|
|
4532
|
-
if (this._opcode > 0x07)
|
|
4561
|
+
if (this._opcode > 0x07) {
|
|
4562
|
+
this.controlMessage(data, cb);
|
|
4563
|
+
return;
|
|
4564
|
+
}
|
|
4533
4565
|
|
|
4534
4566
|
if (this._compressed) {
|
|
4535
4567
|
this._state = INFLATING;
|
|
@@ -4546,7 +4578,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4546
4578
|
this._fragments.push(data);
|
|
4547
4579
|
}
|
|
4548
4580
|
|
|
4549
|
-
|
|
4581
|
+
this.dataMessage(cb);
|
|
4550
4582
|
}
|
|
4551
4583
|
|
|
4552
4584
|
/**
|
|
@@ -4565,74 +4597,96 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4565
4597
|
if (buf.length) {
|
|
4566
4598
|
this._messageLength += buf.length;
|
|
4567
4599
|
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
|
4575
|
-
)
|
|
4600
|
+
const error = this.createError(
|
|
4601
|
+
RangeError,
|
|
4602
|
+
'Max payload size exceeded',
|
|
4603
|
+
false,
|
|
4604
|
+
1009,
|
|
4605
|
+
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
|
4576
4606
|
);
|
|
4607
|
+
|
|
4608
|
+
cb(error);
|
|
4609
|
+
return;
|
|
4577
4610
|
}
|
|
4578
4611
|
|
|
4579
4612
|
this._fragments.push(buf);
|
|
4580
4613
|
}
|
|
4581
4614
|
|
|
4582
|
-
|
|
4583
|
-
if (
|
|
4584
|
-
|
|
4585
|
-
this.startLoop(cb);
|
|
4615
|
+
this.dataMessage(cb);
|
|
4616
|
+
if (this._state === GET_INFO) this.startLoop(cb);
|
|
4586
4617
|
});
|
|
4587
4618
|
}
|
|
4588
4619
|
|
|
4589
4620
|
/**
|
|
4590
4621
|
* Handles a data message.
|
|
4591
4622
|
*
|
|
4592
|
-
* @
|
|
4623
|
+
* @param {Function} cb Callback
|
|
4593
4624
|
* @private
|
|
4594
4625
|
*/
|
|
4595
|
-
dataMessage() {
|
|
4596
|
-
if (this._fin) {
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4626
|
+
dataMessage(cb) {
|
|
4627
|
+
if (!this._fin) {
|
|
4628
|
+
this._state = GET_INFO;
|
|
4629
|
+
return;
|
|
4630
|
+
}
|
|
4631
|
+
|
|
4632
|
+
const messageLength = this._messageLength;
|
|
4633
|
+
const fragments = this._fragments;
|
|
4634
|
+
|
|
4635
|
+
this._totalPayloadLength = 0;
|
|
4636
|
+
this._messageLength = 0;
|
|
4637
|
+
this._fragmented = 0;
|
|
4638
|
+
this._fragments = [];
|
|
4639
|
+
|
|
4640
|
+
if (this._opcode === 2) {
|
|
4641
|
+
let data;
|
|
4642
|
+
|
|
4643
|
+
if (this._binaryType === 'nodebuffer') {
|
|
4644
|
+
data = concat(fragments, messageLength);
|
|
4645
|
+
} else if (this._binaryType === 'arraybuffer') {
|
|
4646
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
4647
|
+
} else {
|
|
4648
|
+
data = fragments;
|
|
4649
|
+
}
|
|
4615
4650
|
|
|
4651
|
+
if (this._allowSynchronousEvents) {
|
|
4616
4652
|
this.emit('message', data, true);
|
|
4653
|
+
this._state = GET_INFO;
|
|
4617
4654
|
} else {
|
|
4618
|
-
|
|
4655
|
+
this._state = DEFER_EVENT;
|
|
4656
|
+
setImmediate(() => {
|
|
4657
|
+
this.emit('message', data, true);
|
|
4658
|
+
this._state = GET_INFO;
|
|
4659
|
+
this.startLoop(cb);
|
|
4660
|
+
});
|
|
4661
|
+
}
|
|
4662
|
+
} else {
|
|
4663
|
+
const buf = concat(fragments, messageLength);
|
|
4619
4664
|
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4665
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
4666
|
+
const error = this.createError(
|
|
4667
|
+
Error,
|
|
4668
|
+
'invalid UTF-8 sequence',
|
|
4669
|
+
true,
|
|
4670
|
+
1007,
|
|
4671
|
+
'WS_ERR_INVALID_UTF8'
|
|
4672
|
+
);
|
|
4673
|
+
|
|
4674
|
+
cb(error);
|
|
4675
|
+
return;
|
|
4676
|
+
}
|
|
4630
4677
|
|
|
4678
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
4631
4679
|
this.emit('message', buf, false);
|
|
4680
|
+
this._state = GET_INFO;
|
|
4681
|
+
} else {
|
|
4682
|
+
this._state = DEFER_EVENT;
|
|
4683
|
+
setImmediate(() => {
|
|
4684
|
+
this.emit('message', buf, false);
|
|
4685
|
+
this._state = GET_INFO;
|
|
4686
|
+
this.startLoop(cb);
|
|
4687
|
+
});
|
|
4632
4688
|
}
|
|
4633
4689
|
}
|
|
4634
|
-
|
|
4635
|
-
this._state = WAIT_MICROTASK;
|
|
4636
4690
|
}
|
|
4637
4691
|
|
|
4638
4692
|
/**
|
|
@@ -4642,26 +4696,26 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4642
4696
|
* @return {(Error|RangeError|undefined)} A possible error
|
|
4643
4697
|
* @private
|
|
4644
4698
|
*/
|
|
4645
|
-
controlMessage(data) {
|
|
4699
|
+
controlMessage(data, cb) {
|
|
4646
4700
|
if (this._opcode === 0x08) {
|
|
4647
|
-
this._loop = false;
|
|
4648
|
-
|
|
4649
4701
|
if (data.length === 0) {
|
|
4702
|
+
this._loop = false;
|
|
4650
4703
|
this.emit('conclude', 1005, EMPTY_BUFFER$2);
|
|
4651
4704
|
this.end();
|
|
4652
|
-
|
|
4653
|
-
this._state = GET_INFO;
|
|
4654
4705
|
} else {
|
|
4655
4706
|
const code = data.readUInt16BE(0);
|
|
4656
4707
|
|
|
4657
4708
|
if (!isValidStatusCode$1(code)) {
|
|
4658
|
-
|
|
4709
|
+
const error = this.createError(
|
|
4659
4710
|
RangeError,
|
|
4660
4711
|
`invalid status code ${code}`,
|
|
4661
4712
|
true,
|
|
4662
4713
|
1002,
|
|
4663
4714
|
'WS_ERR_INVALID_CLOSE_CODE'
|
|
4664
4715
|
);
|
|
4716
|
+
|
|
4717
|
+
cb(error);
|
|
4718
|
+
return;
|
|
4665
4719
|
}
|
|
4666
4720
|
|
|
4667
4721
|
const buf = new FastBuffer(
|
|
@@ -4671,83 +4725,68 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
4671
4725
|
);
|
|
4672
4726
|
|
|
4673
4727
|
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
4674
|
-
|
|
4728
|
+
const error = this.createError(
|
|
4675
4729
|
Error,
|
|
4676
4730
|
'invalid UTF-8 sequence',
|
|
4677
4731
|
true,
|
|
4678
4732
|
1007,
|
|
4679
4733
|
'WS_ERR_INVALID_UTF8'
|
|
4680
4734
|
);
|
|
4735
|
+
|
|
4736
|
+
cb(error);
|
|
4737
|
+
return;
|
|
4681
4738
|
}
|
|
4682
4739
|
|
|
4740
|
+
this._loop = false;
|
|
4683
4741
|
this.emit('conclude', code, buf);
|
|
4684
4742
|
this.end();
|
|
4685
|
-
|
|
4686
|
-
this._state = GET_INFO;
|
|
4687
4743
|
}
|
|
4688
|
-
|
|
4689
|
-
this.
|
|
4690
|
-
|
|
4744
|
+
|
|
4745
|
+
this._state = GET_INFO;
|
|
4746
|
+
return;
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
if (this._allowSynchronousEvents) {
|
|
4750
|
+
this.emit(this._opcode === 0x09 ? 'ping' : 'pong', data);
|
|
4751
|
+
this._state = GET_INFO;
|
|
4691
4752
|
} else {
|
|
4692
|
-
this.
|
|
4693
|
-
|
|
4753
|
+
this._state = DEFER_EVENT;
|
|
4754
|
+
setImmediate(() => {
|
|
4755
|
+
this.emit(this._opcode === 0x09 ? 'ping' : 'pong', data);
|
|
4756
|
+
this._state = GET_INFO;
|
|
4757
|
+
this.startLoop(cb);
|
|
4758
|
+
});
|
|
4694
4759
|
}
|
|
4695
4760
|
}
|
|
4696
|
-
};
|
|
4697
|
-
|
|
4698
|
-
var receiver = Receiver$1;
|
|
4699
|
-
|
|
4700
|
-
/**
|
|
4701
|
-
* Builds an error object.
|
|
4702
|
-
*
|
|
4703
|
-
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
4704
|
-
* @param {String} message The error message
|
|
4705
|
-
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
4706
|
-
* `message`
|
|
4707
|
-
* @param {Number} statusCode The status code
|
|
4708
|
-
* @param {String} errorCode The exposed error code
|
|
4709
|
-
* @return {(Error|RangeError)} The error
|
|
4710
|
-
* @private
|
|
4711
|
-
*/
|
|
4712
|
-
function error(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
4713
|
-
const err = new ErrorCtor(
|
|
4714
|
-
prefix ? `Invalid WebSocket frame: ${message}` : message
|
|
4715
|
-
);
|
|
4716
4761
|
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
}
|
|
4762
|
+
/**
|
|
4763
|
+
* Builds an error object.
|
|
4764
|
+
*
|
|
4765
|
+
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
4766
|
+
* @param {String} message The error message
|
|
4767
|
+
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
4768
|
+
* `message`
|
|
4769
|
+
* @param {Number} statusCode The status code
|
|
4770
|
+
* @param {String} errorCode The exposed error code
|
|
4771
|
+
* @return {(Error|RangeError)} The error
|
|
4772
|
+
* @private
|
|
4773
|
+
*/
|
|
4774
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
4775
|
+
this._loop = false;
|
|
4776
|
+
this._errored = true;
|
|
4722
4777
|
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
* @param {Function} cb Callback
|
|
4727
|
-
*/
|
|
4728
|
-
function queueMicrotaskShim(cb) {
|
|
4729
|
-
promise.then(cb).catch(throwErrorNextTick);
|
|
4730
|
-
}
|
|
4778
|
+
const err = new ErrorCtor(
|
|
4779
|
+
prefix ? `Invalid WebSocket frame: ${message}` : message
|
|
4780
|
+
);
|
|
4731
4781
|
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
function throwError(err) {
|
|
4739
|
-
throw err;
|
|
4740
|
-
}
|
|
4782
|
+
Error.captureStackTrace(err, this.createError);
|
|
4783
|
+
err.code = errorCode;
|
|
4784
|
+
err[kStatusCode$1] = statusCode;
|
|
4785
|
+
return err;
|
|
4786
|
+
}
|
|
4787
|
+
};
|
|
4741
4788
|
|
|
4742
|
-
|
|
4743
|
-
* Throws an error in the next tick.
|
|
4744
|
-
*
|
|
4745
|
-
* @param {Error} err The error to throw
|
|
4746
|
-
* @private
|
|
4747
|
-
*/
|
|
4748
|
-
function throwErrorNextTick(err) {
|
|
4749
|
-
process.nextTick(throwError, err);
|
|
4750
|
-
}
|
|
4789
|
+
var receiver = Receiver$1;
|
|
4751
4790
|
|
|
4752
4791
|
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex" }] */
|
|
4753
4792
|
const { randomFillSync } = require$$1;
|
|
@@ -5716,7 +5755,7 @@ function format$1(extensions) {
|
|
|
5716
5755
|
|
|
5717
5756
|
var extension$1 = { format: format$1, parse: parse$2 };
|
|
5718
5757
|
|
|
5719
|
-
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex|Readable$" }] */
|
|
5758
|
+
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex|Readable$", "caughtErrors": "none" }] */
|
|
5720
5759
|
|
|
5721
5760
|
const EventEmitter$1 = require$$0$3;
|
|
5722
5761
|
const https = require$$1$1;
|
|
@@ -5799,6 +5838,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
5799
5838
|
|
|
5800
5839
|
initAsClient(this, address, protocols, options);
|
|
5801
5840
|
} else {
|
|
5841
|
+
this._autoPong = options.autoPong;
|
|
5802
5842
|
this._isServer = true;
|
|
5803
5843
|
}
|
|
5804
5844
|
}
|
|
@@ -5907,6 +5947,9 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
5907
5947
|
* @param {Duplex} socket The network socket between the server and client
|
|
5908
5948
|
* @param {Buffer} head The first packet of the upgraded stream
|
|
5909
5949
|
* @param {Object} options Options object
|
|
5950
|
+
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
|
|
5951
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
5952
|
+
* multiple times in the same tick
|
|
5910
5953
|
* @param {Function} [options.generateMask] The function used to generate the
|
|
5911
5954
|
* masking key
|
|
5912
5955
|
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
|
@@ -5916,6 +5959,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
5916
5959
|
*/
|
|
5917
5960
|
setSocket(socket, head, options) {
|
|
5918
5961
|
const receiver = new Receiver({
|
|
5962
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
5919
5963
|
binaryType: this.binaryType,
|
|
5920
5964
|
extensions: this._extensions,
|
|
5921
5965
|
isServer: this._isServer,
|
|
@@ -6333,6 +6377,13 @@ var websocket = WebSocket$1;
|
|
|
6333
6377
|
* @param {(String|URL)} address The URL to which to connect
|
|
6334
6378
|
* @param {Array} protocols The subprotocols
|
|
6335
6379
|
* @param {Object} [options] Connection options
|
|
6380
|
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether any
|
|
6381
|
+
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
|
|
6382
|
+
* times in the same tick
|
|
6383
|
+
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
6384
|
+
* automatically send a pong in response to a ping
|
|
6385
|
+
* @param {Function} [options.finishRequest] A function which can be used to
|
|
6386
|
+
* customize the headers of each http request before it is sent
|
|
6336
6387
|
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
|
|
6337
6388
|
* redirects
|
|
6338
6389
|
* @param {Function} [options.generateMask] The function used to generate the
|
|
@@ -6355,6 +6406,8 @@ var websocket = WebSocket$1;
|
|
|
6355
6406
|
*/
|
|
6356
6407
|
function initAsClient(websocket, address, protocols, options) {
|
|
6357
6408
|
const opts = {
|
|
6409
|
+
allowSynchronousEvents: true,
|
|
6410
|
+
autoPong: true,
|
|
6358
6411
|
protocolVersion: protocolVersions[1],
|
|
6359
6412
|
maxPayload: 100 * 1024 * 1024,
|
|
6360
6413
|
skipUTF8Validation: false,
|
|
@@ -6362,7 +6415,6 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
6362
6415
|
followRedirects: false,
|
|
6363
6416
|
maxRedirects: 10,
|
|
6364
6417
|
...options,
|
|
6365
|
-
createConnection: undefined,
|
|
6366
6418
|
socketPath: undefined,
|
|
6367
6419
|
hostname: undefined,
|
|
6368
6420
|
protocol: undefined,
|
|
@@ -6373,6 +6425,8 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
6373
6425
|
port: undefined
|
|
6374
6426
|
};
|
|
6375
6427
|
|
|
6428
|
+
websocket._autoPong = opts.autoPong;
|
|
6429
|
+
|
|
6376
6430
|
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
6377
6431
|
throw new RangeError(
|
|
6378
6432
|
`Unsupported protocol version: ${opts.protocolVersion} ` +
|
|
@@ -6431,7 +6485,8 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
6431
6485
|
const protocolSet = new Set();
|
|
6432
6486
|
let perMessageDeflate;
|
|
6433
6487
|
|
|
6434
|
-
opts.createConnection =
|
|
6488
|
+
opts.createConnection =
|
|
6489
|
+
opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
6435
6490
|
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
6436
6491
|
opts.port = parsedUrl.port || defaultPort;
|
|
6437
6492
|
opts.host = parsedUrl.hostname.startsWith('[')
|
|
@@ -6521,8 +6576,8 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
6521
6576
|
? opts.socketPath === websocket._originalHostOrSocketPath
|
|
6522
6577
|
: false
|
|
6523
6578
|
: websocket._originalIpc
|
|
6524
|
-
|
|
6525
|
-
|
|
6579
|
+
? false
|
|
6580
|
+
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
6526
6581
|
|
|
6527
6582
|
if (!isSameHost || (websocket._originalSecure && !isSecure)) {
|
|
6528
6583
|
//
|
|
@@ -6706,6 +6761,7 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
6706
6761
|
}
|
|
6707
6762
|
|
|
6708
6763
|
websocket.setSocket(socket, head, {
|
|
6764
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
6709
6765
|
generateMask: opts.generateMask,
|
|
6710
6766
|
maxPayload: opts.maxPayload,
|
|
6711
6767
|
skipUTF8Validation: opts.skipUTF8Validation
|
|
@@ -6916,7 +6972,7 @@ function receiverOnMessage(data, isBinary) {
|
|
|
6916
6972
|
function receiverOnPing(data) {
|
|
6917
6973
|
const websocket = this[kWebSocket$1];
|
|
6918
6974
|
|
|
6919
|
-
websocket.pong(data, !
|
|
6975
|
+
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
|
6920
6976
|
websocket.emit('ping', data);
|
|
6921
6977
|
}
|
|
6922
6978
|
|
|
@@ -7094,7 +7150,7 @@ function parse(header) {
|
|
|
7094
7150
|
|
|
7095
7151
|
var subprotocol$1 = { parse };
|
|
7096
7152
|
|
|
7097
|
-
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex$" }] */
|
|
7153
|
+
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex$", "caughtErrors": "none" }] */
|
|
7098
7154
|
|
|
7099
7155
|
const EventEmitter = require$$0$3;
|
|
7100
7156
|
const http = require$$2;
|
|
@@ -7122,6 +7178,11 @@ class WebSocketServer extends EventEmitter {
|
|
|
7122
7178
|
* Create a `WebSocketServer` instance.
|
|
7123
7179
|
*
|
|
7124
7180
|
* @param {Object} options Configuration options
|
|
7181
|
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
7182
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
7183
|
+
* multiple times in the same tick
|
|
7184
|
+
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
7185
|
+
* automatically send a pong in response to a ping
|
|
7125
7186
|
* @param {Number} [options.backlog=511] The maximum length of the queue of
|
|
7126
7187
|
* pending connections
|
|
7127
7188
|
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
|
@@ -7148,6 +7209,8 @@ class WebSocketServer extends EventEmitter {
|
|
|
7148
7209
|
super();
|
|
7149
7210
|
|
|
7150
7211
|
options = {
|
|
7212
|
+
allowSynchronousEvents: true,
|
|
7213
|
+
autoPong: true,
|
|
7151
7214
|
maxPayload: 100 * 1024 * 1024,
|
|
7152
7215
|
skipUTF8Validation: false,
|
|
7153
7216
|
perMessageDeflate: false,
|
|
@@ -7468,7 +7531,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
7468
7531
|
`Sec-WebSocket-Accept: ${digest}`
|
|
7469
7532
|
];
|
|
7470
7533
|
|
|
7471
|
-
const ws = new this.options.WebSocket(null);
|
|
7534
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
7472
7535
|
|
|
7473
7536
|
if (protocols.size) {
|
|
7474
7537
|
//
|
|
@@ -7502,6 +7565,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
7502
7565
|
socket.removeListener('error', socketOnError);
|
|
7503
7566
|
|
|
7504
7567
|
ws.setSocket(socket, head, {
|
|
7568
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
7505
7569
|
maxPayload: this.options.maxPayload,
|
|
7506
7570
|
skipUTF8Validation: this.options.skipUTF8Validation
|
|
7507
7571
|
});
|
|
@@ -9059,119 +9123,2230 @@ class StateManager {
|
|
|
9059
9123
|
}).length;
|
|
9060
9124
|
}
|
|
9061
9125
|
cancelFiles(files, root, projectName) {
|
|
9062
|
-
this.collectFiles(files.map((filepath) =>
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
|
|
9075
|
-
|
|
9126
|
+
this.collectFiles(files.map((filepath) => {
|
|
9127
|
+
const file = {
|
|
9128
|
+
filepath,
|
|
9129
|
+
name: relative(root, filepath),
|
|
9130
|
+
id: filepath,
|
|
9131
|
+
mode: "skip",
|
|
9132
|
+
type: "suite",
|
|
9133
|
+
result: {
|
|
9134
|
+
state: "skip"
|
|
9135
|
+
},
|
|
9136
|
+
meta: {},
|
|
9137
|
+
// Cancelled files have not yet collected tests
|
|
9138
|
+
tasks: [],
|
|
9139
|
+
projectName,
|
|
9140
|
+
file: null
|
|
9141
|
+
};
|
|
9142
|
+
file.file = file;
|
|
9143
|
+
return file;
|
|
9144
|
+
}));
|
|
9076
9145
|
}
|
|
9077
9146
|
}
|
|
9078
9147
|
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
}
|
|
9088
|
-
|
|
9089
|
-
"
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9115
|
-
|
|
9116
|
-
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9140
|
-
|
|
9141
|
-
|
|
9142
|
-
|
|
9143
|
-
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9152
|
-
|
|
9153
|
-
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9148
|
+
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
9149
|
+
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
9150
|
+
{
|
|
9151
|
+
return input.endsWith("/") ? input : input + "/";
|
|
9152
|
+
}
|
|
9153
|
+
}
|
|
9154
|
+
function isNonEmptyURL(url) {
|
|
9155
|
+
return url && url !== "/";
|
|
9156
|
+
}
|
|
9157
|
+
function joinURL(base, ...input) {
|
|
9158
|
+
let url = base || "";
|
|
9159
|
+
for (const segment of input.filter((url2) => isNonEmptyURL(url2))) {
|
|
9160
|
+
if (url) {
|
|
9161
|
+
const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
|
|
9162
|
+
url = withTrailingSlash(url) + _segment;
|
|
9163
|
+
} else {
|
|
9164
|
+
url = segment;
|
|
9165
|
+
}
|
|
9166
|
+
}
|
|
9167
|
+
return url;
|
|
9168
|
+
}
|
|
9169
|
+
|
|
9170
|
+
const BUILTIN_MODULES = new Set(builtinModules);
|
|
9171
|
+
function normalizeSlash(path) {
|
|
9172
|
+
return path.replace(/\\/g, "/");
|
|
9173
|
+
}
|
|
9174
|
+
|
|
9175
|
+
/**
|
|
9176
|
+
* @typedef ErrnoExceptionFields
|
|
9177
|
+
* @property {number | undefined} [errnode]
|
|
9178
|
+
* @property {string | undefined} [code]
|
|
9179
|
+
* @property {string | undefined} [path]
|
|
9180
|
+
* @property {string | undefined} [syscall]
|
|
9181
|
+
* @property {string | undefined} [url]
|
|
9182
|
+
*
|
|
9183
|
+
* @typedef {Error & ErrnoExceptionFields} ErrnoException
|
|
9184
|
+
*/
|
|
9185
|
+
|
|
9186
|
+
|
|
9187
|
+
const own$1 = {}.hasOwnProperty;
|
|
9188
|
+
|
|
9189
|
+
const classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
9190
|
+
// Sorted by a rough estimate on most frequently used entries.
|
|
9191
|
+
const kTypes = new Set([
|
|
9192
|
+
'string',
|
|
9193
|
+
'function',
|
|
9194
|
+
'number',
|
|
9195
|
+
'object',
|
|
9196
|
+
// Accept 'Function' and 'Object' as alternative to the lower cased version.
|
|
9197
|
+
'Function',
|
|
9198
|
+
'Object',
|
|
9199
|
+
'boolean',
|
|
9200
|
+
'bigint',
|
|
9201
|
+
'symbol'
|
|
9202
|
+
]);
|
|
9203
|
+
|
|
9204
|
+
const codes = {};
|
|
9205
|
+
|
|
9206
|
+
/**
|
|
9207
|
+
* Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
|
|
9208
|
+
* We cannot use Intl.ListFormat because it's not available in
|
|
9209
|
+
* --without-intl builds.
|
|
9210
|
+
*
|
|
9211
|
+
* @param {Array<string>} array
|
|
9212
|
+
* An array of strings.
|
|
9213
|
+
* @param {string} [type]
|
|
9214
|
+
* The list type to be inserted before the last element.
|
|
9215
|
+
* @returns {string}
|
|
9216
|
+
*/
|
|
9217
|
+
function formatList(array, type = 'and') {
|
|
9218
|
+
return array.length < 3
|
|
9219
|
+
? array.join(` ${type} `)
|
|
9220
|
+
: `${array.slice(0, -1).join(', ')}, ${type} ${array[array.length - 1]}`
|
|
9221
|
+
}
|
|
9222
|
+
|
|
9223
|
+
/** @type {Map<string, MessageFunction | string>} */
|
|
9224
|
+
const messages = new Map();
|
|
9225
|
+
const nodeInternalPrefix = '__node_internal_';
|
|
9226
|
+
/** @type {number} */
|
|
9227
|
+
let userStackTraceLimit;
|
|
9228
|
+
|
|
9229
|
+
codes.ERR_INVALID_ARG_TYPE = createError(
|
|
9230
|
+
'ERR_INVALID_ARG_TYPE',
|
|
9231
|
+
/**
|
|
9232
|
+
* @param {string} name
|
|
9233
|
+
* @param {Array<string> | string} expected
|
|
9234
|
+
* @param {unknown} actual
|
|
9235
|
+
*/
|
|
9236
|
+
(name, expected, actual) => {
|
|
9237
|
+
assert(typeof name === 'string', "'name' must be a string");
|
|
9238
|
+
if (!Array.isArray(expected)) {
|
|
9239
|
+
expected = [expected];
|
|
9240
|
+
}
|
|
9241
|
+
|
|
9242
|
+
let message = 'The ';
|
|
9243
|
+
if (name.endsWith(' argument')) {
|
|
9244
|
+
// For cases like 'first argument'
|
|
9245
|
+
message += `${name} `;
|
|
9246
|
+
} else {
|
|
9247
|
+
const type = name.includes('.') ? 'property' : 'argument';
|
|
9248
|
+
message += `"${name}" ${type} `;
|
|
9249
|
+
}
|
|
9250
|
+
|
|
9251
|
+
message += 'must be ';
|
|
9252
|
+
|
|
9253
|
+
/** @type {Array<string>} */
|
|
9254
|
+
const types = [];
|
|
9255
|
+
/** @type {Array<string>} */
|
|
9256
|
+
const instances = [];
|
|
9257
|
+
/** @type {Array<string>} */
|
|
9258
|
+
const other = [];
|
|
9259
|
+
|
|
9260
|
+
for (const value of expected) {
|
|
9261
|
+
assert(
|
|
9262
|
+
typeof value === 'string',
|
|
9263
|
+
'All expected entries have to be of type string'
|
|
9264
|
+
);
|
|
9265
|
+
|
|
9266
|
+
if (kTypes.has(value)) {
|
|
9267
|
+
types.push(value.toLowerCase());
|
|
9268
|
+
} else if (classRegExp.exec(value) === null) {
|
|
9269
|
+
assert(
|
|
9270
|
+
value !== 'object',
|
|
9271
|
+
'The value "object" should be written as "Object"'
|
|
9272
|
+
);
|
|
9273
|
+
other.push(value);
|
|
9274
|
+
} else {
|
|
9275
|
+
instances.push(value);
|
|
9276
|
+
}
|
|
9277
|
+
}
|
|
9278
|
+
|
|
9279
|
+
// Special handle `object` in case other instances are allowed to outline
|
|
9280
|
+
// the differences between each other.
|
|
9281
|
+
if (instances.length > 0) {
|
|
9282
|
+
const pos = types.indexOf('object');
|
|
9283
|
+
if (pos !== -1) {
|
|
9284
|
+
types.slice(pos, 1);
|
|
9285
|
+
instances.push('Object');
|
|
9286
|
+
}
|
|
9287
|
+
}
|
|
9288
|
+
|
|
9289
|
+
if (types.length > 0) {
|
|
9290
|
+
message += `${types.length > 1 ? 'one of type' : 'of type'} ${formatList(
|
|
9291
|
+
types,
|
|
9292
|
+
'or'
|
|
9293
|
+
)}`;
|
|
9294
|
+
if (instances.length > 0 || other.length > 0) message += ' or ';
|
|
9295
|
+
}
|
|
9296
|
+
|
|
9297
|
+
if (instances.length > 0) {
|
|
9298
|
+
message += `an instance of ${formatList(instances, 'or')}`;
|
|
9299
|
+
if (other.length > 0) message += ' or ';
|
|
9300
|
+
}
|
|
9301
|
+
|
|
9302
|
+
if (other.length > 0) {
|
|
9303
|
+
if (other.length > 1) {
|
|
9304
|
+
message += `one of ${formatList(other, 'or')}`;
|
|
9305
|
+
} else {
|
|
9306
|
+
if (other[0].toLowerCase() !== other[0]) message += 'an ';
|
|
9307
|
+
message += `${other[0]}`;
|
|
9308
|
+
}
|
|
9309
|
+
}
|
|
9310
|
+
|
|
9311
|
+
message += `. Received ${determineSpecificType(actual)}`;
|
|
9312
|
+
|
|
9313
|
+
return message
|
|
9314
|
+
},
|
|
9315
|
+
TypeError
|
|
9316
|
+
);
|
|
9317
|
+
|
|
9318
|
+
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
9319
|
+
'ERR_INVALID_MODULE_SPECIFIER',
|
|
9320
|
+
/**
|
|
9321
|
+
* @param {string} request
|
|
9322
|
+
* @param {string} reason
|
|
9323
|
+
* @param {string} [base]
|
|
9324
|
+
*/
|
|
9325
|
+
(request, reason, base = undefined) => {
|
|
9326
|
+
return `Invalid module "${request}" ${reason}${
|
|
9327
|
+
base ? ` imported from ${base}` : ''
|
|
9328
|
+
}`
|
|
9329
|
+
},
|
|
9330
|
+
TypeError
|
|
9331
|
+
);
|
|
9332
|
+
|
|
9333
|
+
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
9334
|
+
'ERR_INVALID_PACKAGE_CONFIG',
|
|
9335
|
+
/**
|
|
9336
|
+
* @param {string} path
|
|
9337
|
+
* @param {string} [base]
|
|
9338
|
+
* @param {string} [message]
|
|
9339
|
+
*/
|
|
9340
|
+
(path, base, message) => {
|
|
9341
|
+
return `Invalid package config ${path}${
|
|
9342
|
+
base ? ` while importing ${base}` : ''
|
|
9343
|
+
}${message ? `. ${message}` : ''}`
|
|
9344
|
+
},
|
|
9345
|
+
Error
|
|
9346
|
+
);
|
|
9347
|
+
|
|
9348
|
+
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
9349
|
+
'ERR_INVALID_PACKAGE_TARGET',
|
|
9350
|
+
/**
|
|
9351
|
+
* @param {string} packagePath
|
|
9352
|
+
* @param {string} key
|
|
9353
|
+
* @param {unknown} target
|
|
9354
|
+
* @param {boolean} [isImport=false]
|
|
9355
|
+
* @param {string} [base]
|
|
9356
|
+
*/
|
|
9357
|
+
(packagePath, key, target, isImport = false, base = undefined) => {
|
|
9358
|
+
const relatedError =
|
|
9359
|
+
typeof target === 'string' &&
|
|
9360
|
+
!isImport &&
|
|
9361
|
+
target.length > 0 &&
|
|
9362
|
+
!target.startsWith('./');
|
|
9363
|
+
if (key === '.') {
|
|
9364
|
+
assert(isImport === false);
|
|
9365
|
+
return (
|
|
9366
|
+
`Invalid "exports" main target ${JSON.stringify(target)} defined ` +
|
|
9367
|
+
`in the package config ${packagePath}package.json${
|
|
9368
|
+
base ? ` imported from ${base}` : ''
|
|
9369
|
+
}${relatedError ? '; targets must start with "./"' : ''}`
|
|
9370
|
+
)
|
|
9371
|
+
}
|
|
9372
|
+
|
|
9373
|
+
return `Invalid "${
|
|
9374
|
+
isImport ? 'imports' : 'exports'
|
|
9375
|
+
}" target ${JSON.stringify(
|
|
9376
|
+
target
|
|
9377
|
+
)} defined for '${key}' in the package config ${packagePath}package.json${
|
|
9378
|
+
base ? ` imported from ${base}` : ''
|
|
9379
|
+
}${relatedError ? '; targets must start with "./"' : ''}`
|
|
9380
|
+
},
|
|
9381
|
+
Error
|
|
9382
|
+
);
|
|
9383
|
+
|
|
9384
|
+
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
9385
|
+
'ERR_MODULE_NOT_FOUND',
|
|
9386
|
+
/**
|
|
9387
|
+
* @param {string} path
|
|
9388
|
+
* @param {string} base
|
|
9389
|
+
* @param {boolean} [exactUrl]
|
|
9390
|
+
*/
|
|
9391
|
+
(path, base, exactUrl = false) => {
|
|
9392
|
+
return `Cannot find ${
|
|
9393
|
+
exactUrl ? 'module' : 'package'
|
|
9394
|
+
} '${path}' imported from ${base}`
|
|
9395
|
+
},
|
|
9396
|
+
Error
|
|
9397
|
+
);
|
|
9398
|
+
|
|
9399
|
+
codes.ERR_NETWORK_IMPORT_DISALLOWED = createError(
|
|
9400
|
+
'ERR_NETWORK_IMPORT_DISALLOWED',
|
|
9401
|
+
"import of '%s' by %s is not supported: %s",
|
|
9402
|
+
Error
|
|
9403
|
+
);
|
|
9404
|
+
|
|
9405
|
+
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
9406
|
+
'ERR_PACKAGE_IMPORT_NOT_DEFINED',
|
|
9407
|
+
/**
|
|
9408
|
+
* @param {string} specifier
|
|
9409
|
+
* @param {string} packagePath
|
|
9410
|
+
* @param {string} base
|
|
9411
|
+
*/
|
|
9412
|
+
(specifier, packagePath, base) => {
|
|
9413
|
+
return `Package import specifier "${specifier}" is not defined${
|
|
9414
|
+
packagePath ? ` in package ${packagePath}package.json` : ''
|
|
9415
|
+
} imported from ${base}`
|
|
9416
|
+
},
|
|
9417
|
+
TypeError
|
|
9418
|
+
);
|
|
9419
|
+
|
|
9420
|
+
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
9421
|
+
'ERR_PACKAGE_PATH_NOT_EXPORTED',
|
|
9422
|
+
/**
|
|
9423
|
+
* @param {string} packagePath
|
|
9424
|
+
* @param {string} subpath
|
|
9425
|
+
* @param {string} [base]
|
|
9426
|
+
*/
|
|
9427
|
+
(packagePath, subpath, base = undefined) => {
|
|
9428
|
+
if (subpath === '.')
|
|
9429
|
+
return `No "exports" main defined in ${packagePath}package.json${
|
|
9430
|
+
base ? ` imported from ${base}` : ''
|
|
9431
|
+
}`
|
|
9432
|
+
return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${
|
|
9433
|
+
base ? ` imported from ${base}` : ''
|
|
9434
|
+
}`
|
|
9435
|
+
},
|
|
9436
|
+
Error
|
|
9437
|
+
);
|
|
9438
|
+
|
|
9439
|
+
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
|
|
9440
|
+
'ERR_UNSUPPORTED_DIR_IMPORT',
|
|
9441
|
+
"Directory import '%s' is not supported " +
|
|
9442
|
+
'resolving ES modules imported from %s',
|
|
9443
|
+
Error
|
|
9444
|
+
);
|
|
9445
|
+
|
|
9446
|
+
codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(
|
|
9447
|
+
'ERR_UNSUPPORTED_RESOLVE_REQUEST',
|
|
9448
|
+
'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.',
|
|
9449
|
+
TypeError
|
|
9450
|
+
);
|
|
9451
|
+
|
|
9452
|
+
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
9453
|
+
'ERR_UNKNOWN_FILE_EXTENSION',
|
|
9454
|
+
/**
|
|
9455
|
+
* @param {string} extension
|
|
9456
|
+
* @param {string} path
|
|
9457
|
+
*/
|
|
9458
|
+
(extension, path) => {
|
|
9459
|
+
return `Unknown file extension "${extension}" for ${path}`
|
|
9460
|
+
},
|
|
9461
|
+
TypeError
|
|
9462
|
+
);
|
|
9463
|
+
|
|
9464
|
+
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
9465
|
+
'ERR_INVALID_ARG_VALUE',
|
|
9466
|
+
/**
|
|
9467
|
+
* @param {string} name
|
|
9468
|
+
* @param {unknown} value
|
|
9469
|
+
* @param {string} [reason='is invalid']
|
|
9470
|
+
*/
|
|
9471
|
+
(name, value, reason = 'is invalid') => {
|
|
9472
|
+
let inspected = inspect(value);
|
|
9473
|
+
|
|
9474
|
+
if (inspected.length > 128) {
|
|
9475
|
+
inspected = `${inspected.slice(0, 128)}...`;
|
|
9476
|
+
}
|
|
9477
|
+
|
|
9478
|
+
const type = name.includes('.') ? 'property' : 'argument';
|
|
9479
|
+
|
|
9480
|
+
return `The ${type} '${name}' ${reason}. Received ${inspected}`
|
|
9481
|
+
},
|
|
9482
|
+
TypeError
|
|
9483
|
+
// Note: extra classes have been shaken out.
|
|
9484
|
+
// , RangeError
|
|
9485
|
+
);
|
|
9486
|
+
|
|
9487
|
+
/**
|
|
9488
|
+
* Utility function for registering the error codes. Only used here. Exported
|
|
9489
|
+
* *only* to allow for testing.
|
|
9490
|
+
* @param {string} sym
|
|
9491
|
+
* @param {MessageFunction | string} value
|
|
9492
|
+
* @param {ErrorConstructor} constructor
|
|
9493
|
+
* @returns {new (...parameters: Array<any>) => Error}
|
|
9494
|
+
*/
|
|
9495
|
+
function createError(sym, value, constructor) {
|
|
9496
|
+
// Special case for SystemError that formats the error message differently
|
|
9497
|
+
// The SystemErrors only have SystemError as their base classes.
|
|
9498
|
+
messages.set(sym, value);
|
|
9499
|
+
|
|
9500
|
+
return makeNodeErrorWithCode(constructor, sym)
|
|
9501
|
+
}
|
|
9502
|
+
|
|
9503
|
+
/**
|
|
9504
|
+
* @param {ErrorConstructor} Base
|
|
9505
|
+
* @param {string} key
|
|
9506
|
+
* @returns {ErrorConstructor}
|
|
9507
|
+
*/
|
|
9508
|
+
function makeNodeErrorWithCode(Base, key) {
|
|
9509
|
+
// @ts-expect-error It’s a Node error.
|
|
9510
|
+
return NodeError
|
|
9511
|
+
/**
|
|
9512
|
+
* @param {Array<unknown>} parameters
|
|
9513
|
+
*/
|
|
9514
|
+
function NodeError(...parameters) {
|
|
9515
|
+
const limit = Error.stackTraceLimit;
|
|
9516
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
9517
|
+
const error = new Base();
|
|
9518
|
+
// Reset the limit and setting the name property.
|
|
9519
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
9520
|
+
const message = getMessage(key, parameters, error);
|
|
9521
|
+
Object.defineProperties(error, {
|
|
9522
|
+
// Note: no need to implement `kIsNodeError` symbol, would be hard,
|
|
9523
|
+
// probably.
|
|
9524
|
+
message: {
|
|
9525
|
+
value: message,
|
|
9526
|
+
enumerable: false,
|
|
9527
|
+
writable: true,
|
|
9528
|
+
configurable: true
|
|
9529
|
+
},
|
|
9530
|
+
toString: {
|
|
9531
|
+
/** @this {Error} */
|
|
9532
|
+
value() {
|
|
9533
|
+
return `${this.name} [${key}]: ${this.message}`
|
|
9534
|
+
},
|
|
9535
|
+
enumerable: false,
|
|
9536
|
+
writable: true,
|
|
9537
|
+
configurable: true
|
|
9538
|
+
}
|
|
9539
|
+
});
|
|
9540
|
+
|
|
9541
|
+
captureLargerStackTrace(error);
|
|
9542
|
+
// @ts-expect-error It’s a Node error.
|
|
9543
|
+
error.code = key;
|
|
9544
|
+
return error
|
|
9545
|
+
}
|
|
9546
|
+
}
|
|
9547
|
+
|
|
9548
|
+
/**
|
|
9549
|
+
* @returns {boolean}
|
|
9550
|
+
*/
|
|
9551
|
+
function isErrorStackTraceLimitWritable() {
|
|
9552
|
+
// Do no touch Error.stackTraceLimit as V8 would attempt to install
|
|
9553
|
+
// it again during deserialization.
|
|
9554
|
+
try {
|
|
9555
|
+
if (v8.startupSnapshot.isBuildingSnapshot()) {
|
|
9556
|
+
return false
|
|
9557
|
+
}
|
|
9558
|
+
} catch {}
|
|
9559
|
+
|
|
9560
|
+
const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit');
|
|
9561
|
+
if (desc === undefined) {
|
|
9562
|
+
return Object.isExtensible(Error)
|
|
9563
|
+
}
|
|
9564
|
+
|
|
9565
|
+
return own$1.call(desc, 'writable') && desc.writable !== undefined
|
|
9566
|
+
? desc.writable
|
|
9567
|
+
: desc.set !== undefined
|
|
9568
|
+
}
|
|
9569
|
+
|
|
9570
|
+
/**
|
|
9571
|
+
* This function removes unnecessary frames from Node.js core errors.
|
|
9572
|
+
* @template {(...parameters: unknown[]) => unknown} T
|
|
9573
|
+
* @param {T} wrappedFunction
|
|
9574
|
+
* @returns {T}
|
|
9575
|
+
*/
|
|
9576
|
+
function hideStackFrames(wrappedFunction) {
|
|
9577
|
+
// We rename the functions that will be hidden to cut off the stacktrace
|
|
9578
|
+
// at the outermost one
|
|
9579
|
+
const hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
9580
|
+
Object.defineProperty(wrappedFunction, 'name', {value: hidden});
|
|
9581
|
+
return wrappedFunction
|
|
9582
|
+
}
|
|
9583
|
+
|
|
9584
|
+
const captureLargerStackTrace = hideStackFrames(
|
|
9585
|
+
/**
|
|
9586
|
+
* @param {Error} error
|
|
9587
|
+
* @returns {Error}
|
|
9588
|
+
*/
|
|
9589
|
+
// @ts-expect-error: fine
|
|
9590
|
+
function (error) {
|
|
9591
|
+
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
9592
|
+
if (stackTraceLimitIsWritable) {
|
|
9593
|
+
userStackTraceLimit = Error.stackTraceLimit;
|
|
9594
|
+
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
9595
|
+
}
|
|
9596
|
+
|
|
9597
|
+
Error.captureStackTrace(error);
|
|
9598
|
+
|
|
9599
|
+
// Reset the limit
|
|
9600
|
+
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
9601
|
+
|
|
9602
|
+
return error
|
|
9603
|
+
}
|
|
9604
|
+
);
|
|
9605
|
+
|
|
9606
|
+
/**
|
|
9607
|
+
* @param {string} key
|
|
9608
|
+
* @param {Array<unknown>} parameters
|
|
9609
|
+
* @param {Error} self
|
|
9610
|
+
* @returns {string}
|
|
9611
|
+
*/
|
|
9612
|
+
function getMessage(key, parameters, self) {
|
|
9613
|
+
const message = messages.get(key);
|
|
9614
|
+
assert(message !== undefined, 'expected `message` to be found');
|
|
9615
|
+
|
|
9616
|
+
if (typeof message === 'function') {
|
|
9617
|
+
assert(
|
|
9618
|
+
message.length <= parameters.length, // Default options do not count.
|
|
9619
|
+
`Code: ${key}; The provided arguments length (${parameters.length}) does not ` +
|
|
9620
|
+
`match the required ones (${message.length}).`
|
|
9621
|
+
);
|
|
9622
|
+
return Reflect.apply(message, self, parameters)
|
|
9623
|
+
}
|
|
9624
|
+
|
|
9625
|
+
const regex = /%[dfijoOs]/g;
|
|
9626
|
+
let expectedLength = 0;
|
|
9627
|
+
while (regex.exec(message) !== null) expectedLength++;
|
|
9628
|
+
assert(
|
|
9629
|
+
expectedLength === parameters.length,
|
|
9630
|
+
`Code: ${key}; The provided arguments length (${parameters.length}) does not ` +
|
|
9631
|
+
`match the required ones (${expectedLength}).`
|
|
9632
|
+
);
|
|
9633
|
+
if (parameters.length === 0) return message
|
|
9634
|
+
|
|
9635
|
+
parameters.unshift(message);
|
|
9636
|
+
return Reflect.apply(format$2, null, parameters)
|
|
9637
|
+
}
|
|
9638
|
+
|
|
9639
|
+
/**
|
|
9640
|
+
* Determine the specific type of a value for type-mismatch errors.
|
|
9641
|
+
* @param {unknown} value
|
|
9642
|
+
* @returns {string}
|
|
9643
|
+
*/
|
|
9644
|
+
function determineSpecificType(value) {
|
|
9645
|
+
if (value === null || value === undefined) {
|
|
9646
|
+
return String(value)
|
|
9647
|
+
}
|
|
9648
|
+
|
|
9649
|
+
if (typeof value === 'function' && value.name) {
|
|
9650
|
+
return `function ${value.name}`
|
|
9651
|
+
}
|
|
9652
|
+
|
|
9653
|
+
if (typeof value === 'object') {
|
|
9654
|
+
if (value.constructor && value.constructor.name) {
|
|
9655
|
+
return `an instance of ${value.constructor.name}`
|
|
9656
|
+
}
|
|
9657
|
+
|
|
9658
|
+
return `${inspect(value, {depth: -1})}`
|
|
9659
|
+
}
|
|
9660
|
+
|
|
9661
|
+
let inspected = inspect(value, {colors: false});
|
|
9662
|
+
|
|
9663
|
+
if (inspected.length > 28) {
|
|
9664
|
+
inspected = `${inspected.slice(0, 25)}...`;
|
|
9665
|
+
}
|
|
9666
|
+
|
|
9667
|
+
return `type ${typeof value} (${inspected})`
|
|
9668
|
+
}
|
|
9669
|
+
|
|
9670
|
+
// Manually “tree shaken” from:
|
|
9671
|
+
// <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/package_json_reader.js>
|
|
9672
|
+
// Last checked on: Apr 29, 2023.
|
|
9673
|
+
// Removed the native dependency.
|
|
9674
|
+
// Also: no need to cache, we do that in resolve already.
|
|
9675
|
+
|
|
9676
|
+
|
|
9677
|
+
const hasOwnProperty$1 = {}.hasOwnProperty;
|
|
9678
|
+
|
|
9679
|
+
const {ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG$1} = codes;
|
|
9680
|
+
|
|
9681
|
+
/** @type {Map<string, PackageConfig>} */
|
|
9682
|
+
const cache = new Map();
|
|
9683
|
+
|
|
9684
|
+
/**
|
|
9685
|
+
* @param {string} jsonPath
|
|
9686
|
+
* @param {{specifier: URL | string, base?: URL}} options
|
|
9687
|
+
* @returns {PackageConfig}
|
|
9688
|
+
*/
|
|
9689
|
+
function read(jsonPath, {base, specifier}) {
|
|
9690
|
+
const existing = cache.get(jsonPath);
|
|
9691
|
+
|
|
9692
|
+
if (existing) {
|
|
9693
|
+
return existing
|
|
9694
|
+
}
|
|
9695
|
+
|
|
9696
|
+
/** @type {string | undefined} */
|
|
9697
|
+
let string;
|
|
9698
|
+
|
|
9699
|
+
try {
|
|
9700
|
+
string = fs$8.readFileSync(path$8.toNamespacedPath(jsonPath), 'utf8');
|
|
9701
|
+
} catch (error) {
|
|
9702
|
+
const exception = /** @type {ErrnoException} */ (error);
|
|
9703
|
+
|
|
9704
|
+
if (exception.code !== 'ENOENT') {
|
|
9705
|
+
throw exception
|
|
9706
|
+
}
|
|
9707
|
+
}
|
|
9708
|
+
|
|
9709
|
+
/** @type {PackageConfig} */
|
|
9710
|
+
const result = {
|
|
9711
|
+
exists: false,
|
|
9712
|
+
pjsonPath: jsonPath,
|
|
9713
|
+
main: undefined,
|
|
9714
|
+
name: undefined,
|
|
9715
|
+
type: 'none', // Ignore unknown types for forwards compatibility
|
|
9716
|
+
exports: undefined,
|
|
9717
|
+
imports: undefined
|
|
9718
|
+
};
|
|
9719
|
+
|
|
9720
|
+
if (string !== undefined) {
|
|
9721
|
+
/** @type {Record<string, unknown>} */
|
|
9722
|
+
let parsed;
|
|
9723
|
+
|
|
9724
|
+
try {
|
|
9725
|
+
parsed = JSON.parse(string);
|
|
9726
|
+
} catch (error_) {
|
|
9727
|
+
const cause = /** @type {ErrnoException} */ (error_);
|
|
9728
|
+
const error = new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
9729
|
+
jsonPath,
|
|
9730
|
+
(base ? `"${specifier}" from ` : '') + fileURLToPath$1(base || specifier),
|
|
9731
|
+
cause.message
|
|
9732
|
+
);
|
|
9733
|
+
error.cause = cause;
|
|
9734
|
+
throw error
|
|
9735
|
+
}
|
|
9736
|
+
|
|
9737
|
+
result.exists = true;
|
|
9738
|
+
|
|
9739
|
+
if (
|
|
9740
|
+
hasOwnProperty$1.call(parsed, 'name') &&
|
|
9741
|
+
typeof parsed.name === 'string'
|
|
9742
|
+
) {
|
|
9743
|
+
result.name = parsed.name;
|
|
9744
|
+
}
|
|
9745
|
+
|
|
9746
|
+
if (
|
|
9747
|
+
hasOwnProperty$1.call(parsed, 'main') &&
|
|
9748
|
+
typeof parsed.main === 'string'
|
|
9749
|
+
) {
|
|
9750
|
+
result.main = parsed.main;
|
|
9751
|
+
}
|
|
9752
|
+
|
|
9753
|
+
if (hasOwnProperty$1.call(parsed, 'exports')) {
|
|
9754
|
+
// @ts-expect-error: assume valid.
|
|
9755
|
+
result.exports = parsed.exports;
|
|
9756
|
+
}
|
|
9757
|
+
|
|
9758
|
+
if (hasOwnProperty$1.call(parsed, 'imports')) {
|
|
9759
|
+
// @ts-expect-error: assume valid.
|
|
9760
|
+
result.imports = parsed.imports;
|
|
9761
|
+
}
|
|
9762
|
+
|
|
9763
|
+
// Ignore unknown types for forwards compatibility
|
|
9764
|
+
if (
|
|
9765
|
+
hasOwnProperty$1.call(parsed, 'type') &&
|
|
9766
|
+
(parsed.type === 'commonjs' || parsed.type === 'module')
|
|
9767
|
+
) {
|
|
9768
|
+
result.type = parsed.type;
|
|
9769
|
+
}
|
|
9770
|
+
}
|
|
9771
|
+
|
|
9772
|
+
cache.set(jsonPath, result);
|
|
9773
|
+
|
|
9774
|
+
return result
|
|
9775
|
+
}
|
|
9776
|
+
|
|
9777
|
+
/**
|
|
9778
|
+
* @param {URL | string} resolved
|
|
9779
|
+
* @returns {PackageConfig}
|
|
9780
|
+
*/
|
|
9781
|
+
function getPackageScopeConfig(resolved) {
|
|
9782
|
+
// Note: in Node, this is now a native module.
|
|
9783
|
+
let packageJSONUrl = new URL('package.json', resolved);
|
|
9784
|
+
|
|
9785
|
+
while (true) {
|
|
9786
|
+
const packageJSONPath = packageJSONUrl.pathname;
|
|
9787
|
+
if (packageJSONPath.endsWith('node_modules/package.json')) {
|
|
9788
|
+
break
|
|
9789
|
+
}
|
|
9790
|
+
|
|
9791
|
+
const packageConfig = read(fileURLToPath$1(packageJSONUrl), {
|
|
9792
|
+
specifier: resolved
|
|
9793
|
+
});
|
|
9794
|
+
|
|
9795
|
+
if (packageConfig.exists) {
|
|
9796
|
+
return packageConfig
|
|
9797
|
+
}
|
|
9798
|
+
|
|
9799
|
+
const lastPackageJSONUrl = packageJSONUrl;
|
|
9800
|
+
packageJSONUrl = new URL('../package.json', packageJSONUrl);
|
|
9801
|
+
|
|
9802
|
+
// Terminates at root where ../package.json equals ../../package.json
|
|
9803
|
+
// (can't just check "/package.json" for Windows support).
|
|
9804
|
+
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
|
|
9805
|
+
break
|
|
9806
|
+
}
|
|
9807
|
+
}
|
|
9808
|
+
|
|
9809
|
+
const packageJSONPath = fileURLToPath$1(packageJSONUrl);
|
|
9810
|
+
// ^^ Note: in Node, this is now a native module.
|
|
9811
|
+
|
|
9812
|
+
return {
|
|
9813
|
+
pjsonPath: packageJSONPath,
|
|
9814
|
+
exists: false,
|
|
9815
|
+
type: 'none'
|
|
9816
|
+
}
|
|
9817
|
+
}
|
|
9818
|
+
|
|
9819
|
+
/**
|
|
9820
|
+
* Returns the package type for a given URL.
|
|
9821
|
+
* @param {URL} url - The URL to get the package type for.
|
|
9822
|
+
* @returns {PackageType}
|
|
9823
|
+
*/
|
|
9824
|
+
function getPackageType(url) {
|
|
9825
|
+
// To do @anonrig: Write a C++ function that returns only "type".
|
|
9826
|
+
return getPackageScopeConfig(url).type
|
|
9827
|
+
}
|
|
9828
|
+
|
|
9829
|
+
// Manually “tree shaken” from:
|
|
9830
|
+
// <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/esm/get_format.js>
|
|
9831
|
+
// Last checked on: Apr 29, 2023.
|
|
9832
|
+
|
|
9833
|
+
|
|
9834
|
+
const {ERR_UNKNOWN_FILE_EXTENSION} = codes;
|
|
9835
|
+
|
|
9836
|
+
const hasOwnProperty = {}.hasOwnProperty;
|
|
9837
|
+
|
|
9838
|
+
/** @type {Record<string, string>} */
|
|
9839
|
+
const extensionFormatMap = {
|
|
9840
|
+
// @ts-expect-error: hush.
|
|
9841
|
+
__proto__: null,
|
|
9842
|
+
'.cjs': 'commonjs',
|
|
9843
|
+
'.js': 'module',
|
|
9844
|
+
'.json': 'json',
|
|
9845
|
+
'.mjs': 'module'
|
|
9846
|
+
};
|
|
9847
|
+
|
|
9848
|
+
/**
|
|
9849
|
+
* @param {string | null} mime
|
|
9850
|
+
* @returns {string | null}
|
|
9851
|
+
*/
|
|
9852
|
+
function mimeToFormat(mime) {
|
|
9853
|
+
if (
|
|
9854
|
+
mime &&
|
|
9855
|
+
/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)
|
|
9856
|
+
)
|
|
9857
|
+
return 'module'
|
|
9858
|
+
if (mime === 'application/json') return 'json'
|
|
9859
|
+
return null
|
|
9860
|
+
}
|
|
9861
|
+
|
|
9862
|
+
/**
|
|
9863
|
+
* @callback ProtocolHandler
|
|
9864
|
+
* @param {URL} parsed
|
|
9865
|
+
* @param {{parentURL: string, source?: Buffer}} context
|
|
9866
|
+
* @param {boolean} ignoreErrors
|
|
9867
|
+
* @returns {string | null | void}
|
|
9868
|
+
*/
|
|
9869
|
+
|
|
9870
|
+
/**
|
|
9871
|
+
* @type {Record<string, ProtocolHandler>}
|
|
9872
|
+
*/
|
|
9873
|
+
const protocolHandlers = {
|
|
9874
|
+
// @ts-expect-error: hush.
|
|
9875
|
+
__proto__: null,
|
|
9876
|
+
'data:': getDataProtocolModuleFormat,
|
|
9877
|
+
'file:': getFileProtocolModuleFormat,
|
|
9878
|
+
'http:': getHttpProtocolModuleFormat,
|
|
9879
|
+
'https:': getHttpProtocolModuleFormat,
|
|
9880
|
+
'node:'() {
|
|
9881
|
+
return 'builtin'
|
|
9882
|
+
}
|
|
9883
|
+
};
|
|
9884
|
+
|
|
9885
|
+
/**
|
|
9886
|
+
* @param {URL} parsed
|
|
9887
|
+
*/
|
|
9888
|
+
function getDataProtocolModuleFormat(parsed) {
|
|
9889
|
+
const {1: mime} = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
|
|
9890
|
+
parsed.pathname
|
|
9891
|
+
) || [null, null, null];
|
|
9892
|
+
return mimeToFormat(mime)
|
|
9893
|
+
}
|
|
9894
|
+
|
|
9895
|
+
/**
|
|
9896
|
+
* Returns the file extension from a URL.
|
|
9897
|
+
*
|
|
9898
|
+
* Should give similar result to
|
|
9899
|
+
* `require('node:path').extname(require('node:url').fileURLToPath(url))`
|
|
9900
|
+
* when used with a `file:` URL.
|
|
9901
|
+
*
|
|
9902
|
+
* @param {URL} url
|
|
9903
|
+
* @returns {string}
|
|
9904
|
+
*/
|
|
9905
|
+
function extname(url) {
|
|
9906
|
+
const pathname = url.pathname;
|
|
9907
|
+
let index = pathname.length;
|
|
9908
|
+
|
|
9909
|
+
while (index--) {
|
|
9910
|
+
const code = pathname.codePointAt(index);
|
|
9911
|
+
|
|
9912
|
+
if (code === 47 /* `/` */) {
|
|
9913
|
+
return ''
|
|
9914
|
+
}
|
|
9915
|
+
|
|
9916
|
+
if (code === 46 /* `.` */) {
|
|
9917
|
+
return pathname.codePointAt(index - 1) === 47 /* `/` */
|
|
9918
|
+
? ''
|
|
9919
|
+
: pathname.slice(index)
|
|
9920
|
+
}
|
|
9921
|
+
}
|
|
9922
|
+
|
|
9923
|
+
return ''
|
|
9924
|
+
}
|
|
9925
|
+
|
|
9926
|
+
/**
|
|
9927
|
+
* @type {ProtocolHandler}
|
|
9928
|
+
*/
|
|
9929
|
+
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
9930
|
+
const value = extname(url);
|
|
9931
|
+
|
|
9932
|
+
if (value === '.js') {
|
|
9933
|
+
const packageType = getPackageType(url);
|
|
9934
|
+
|
|
9935
|
+
if (packageType !== 'none') {
|
|
9936
|
+
return packageType
|
|
9937
|
+
}
|
|
9938
|
+
|
|
9939
|
+
return 'commonjs'
|
|
9940
|
+
}
|
|
9941
|
+
|
|
9942
|
+
if (value === '') {
|
|
9943
|
+
const packageType = getPackageType(url);
|
|
9944
|
+
|
|
9945
|
+
// Legacy behavior
|
|
9946
|
+
if (packageType === 'none' || packageType === 'commonjs') {
|
|
9947
|
+
return 'commonjs'
|
|
9948
|
+
}
|
|
9949
|
+
|
|
9950
|
+
// Note: we don’t implement WASM, so we don’t need
|
|
9951
|
+
// `getFormatOfExtensionlessFile` from `formats`.
|
|
9952
|
+
return 'module'
|
|
9953
|
+
}
|
|
9954
|
+
|
|
9955
|
+
const format = extensionFormatMap[value];
|
|
9956
|
+
if (format) return format
|
|
9957
|
+
|
|
9958
|
+
// Explicit undefined return indicates load hook should rerun format check
|
|
9959
|
+
if (ignoreErrors) {
|
|
9960
|
+
return undefined
|
|
9961
|
+
}
|
|
9962
|
+
|
|
9963
|
+
const filepath = fileURLToPath$1(url);
|
|
9964
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath)
|
|
9965
|
+
}
|
|
9966
|
+
|
|
9967
|
+
function getHttpProtocolModuleFormat() {
|
|
9968
|
+
// To do: HTTPS imports.
|
|
9969
|
+
}
|
|
9970
|
+
|
|
9971
|
+
/**
|
|
9972
|
+
* @param {URL} url
|
|
9973
|
+
* @param {{parentURL: string}} context
|
|
9974
|
+
* @returns {string | null}
|
|
9975
|
+
*/
|
|
9976
|
+
function defaultGetFormatWithoutErrors(url, context) {
|
|
9977
|
+
const protocol = url.protocol;
|
|
9978
|
+
|
|
9979
|
+
if (!hasOwnProperty.call(protocolHandlers, protocol)) {
|
|
9980
|
+
return null
|
|
9981
|
+
}
|
|
9982
|
+
|
|
9983
|
+
return protocolHandlers[protocol](url, context, true) || null
|
|
9984
|
+
}
|
|
9985
|
+
|
|
9986
|
+
// Manually “tree shaken” from:
|
|
9987
|
+
// <https://github.com/nodejs/node/blob/81a9a97/lib/internal/modules/esm/resolve.js>
|
|
9988
|
+
// Last checked on: Apr 29, 2023.
|
|
9989
|
+
|
|
9990
|
+
|
|
9991
|
+
const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
9992
|
+
|
|
9993
|
+
const {
|
|
9994
|
+
ERR_NETWORK_IMPORT_DISALLOWED,
|
|
9995
|
+
ERR_INVALID_MODULE_SPECIFIER,
|
|
9996
|
+
ERR_INVALID_PACKAGE_CONFIG,
|
|
9997
|
+
ERR_INVALID_PACKAGE_TARGET,
|
|
9998
|
+
ERR_MODULE_NOT_FOUND,
|
|
9999
|
+
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
10000
|
+
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
10001
|
+
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
10002
|
+
ERR_UNSUPPORTED_RESOLVE_REQUEST
|
|
10003
|
+
} = codes;
|
|
10004
|
+
|
|
10005
|
+
const own = {}.hasOwnProperty;
|
|
10006
|
+
|
|
10007
|
+
const invalidSegmentRegEx =
|
|
10008
|
+
/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
10009
|
+
const deprecatedInvalidSegmentRegEx =
|
|
10010
|
+
/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
10011
|
+
const invalidPackageNameRegEx = /^\.|%|\\/;
|
|
10012
|
+
const patternRegEx = /\*/g;
|
|
10013
|
+
const encodedSeparatorRegEx = /%2f|%5c/i;
|
|
10014
|
+
/** @type {Set<string>} */
|
|
10015
|
+
const emittedPackageWarnings = new Set();
|
|
10016
|
+
|
|
10017
|
+
const doubleSlashRegEx = /[/\\]{2}/;
|
|
10018
|
+
|
|
10019
|
+
/**
|
|
10020
|
+
*
|
|
10021
|
+
* @param {string} target
|
|
10022
|
+
* @param {string} request
|
|
10023
|
+
* @param {string} match
|
|
10024
|
+
* @param {URL} packageJsonUrl
|
|
10025
|
+
* @param {boolean} internal
|
|
10026
|
+
* @param {URL} base
|
|
10027
|
+
* @param {boolean} isTarget
|
|
10028
|
+
*/
|
|
10029
|
+
function emitInvalidSegmentDeprecation(
|
|
10030
|
+
target,
|
|
10031
|
+
request,
|
|
10032
|
+
match,
|
|
10033
|
+
packageJsonUrl,
|
|
10034
|
+
internal,
|
|
10035
|
+
base,
|
|
10036
|
+
isTarget
|
|
10037
|
+
) {
|
|
10038
|
+
// @ts-expect-error: apparently it does exist, TS.
|
|
10039
|
+
if (process$1.noDeprecation) {
|
|
10040
|
+
return
|
|
10041
|
+
}
|
|
10042
|
+
|
|
10043
|
+
const pjsonPath = fileURLToPath$1(packageJsonUrl);
|
|
10044
|
+
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
10045
|
+
process$1.emitWarning(
|
|
10046
|
+
`Use of deprecated ${
|
|
10047
|
+
double ? 'double slash' : 'leading or trailing slash matching'
|
|
10048
|
+
} resolving "${target}" for module ` +
|
|
10049
|
+
`request "${request}" ${
|
|
10050
|
+
request === match ? '' : `matched to "${match}" `
|
|
10051
|
+
}in the "${
|
|
10052
|
+
internal ? 'imports' : 'exports'
|
|
10053
|
+
}" field module resolution of the package at ${pjsonPath}${
|
|
10054
|
+
base ? ` imported from ${fileURLToPath$1(base)}` : ''
|
|
10055
|
+
}.`,
|
|
10056
|
+
'DeprecationWarning',
|
|
10057
|
+
'DEP0166'
|
|
10058
|
+
);
|
|
10059
|
+
}
|
|
10060
|
+
|
|
10061
|
+
/**
|
|
10062
|
+
* @param {URL} url
|
|
10063
|
+
* @param {URL} packageJsonUrl
|
|
10064
|
+
* @param {URL} base
|
|
10065
|
+
* @param {string} [main]
|
|
10066
|
+
* @returns {void}
|
|
10067
|
+
*/
|
|
10068
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
10069
|
+
// @ts-expect-error: apparently it does exist, TS.
|
|
10070
|
+
if (process$1.noDeprecation) {
|
|
10071
|
+
return
|
|
10072
|
+
}
|
|
10073
|
+
|
|
10074
|
+
const format = defaultGetFormatWithoutErrors(url, {parentURL: base.href});
|
|
10075
|
+
if (format !== 'module') return
|
|
10076
|
+
const urlPath = fileURLToPath$1(url.href);
|
|
10077
|
+
const packagePath = fileURLToPath$1(new URL$2('.', packageJsonUrl));
|
|
10078
|
+
const basePath = fileURLToPath$1(base);
|
|
10079
|
+
if (!main) {
|
|
10080
|
+
process$1.emitWarning(
|
|
10081
|
+
`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(
|
|
10082
|
+
packagePath.length
|
|
10083
|
+
)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`,
|
|
10084
|
+
'DeprecationWarning',
|
|
10085
|
+
'DEP0151'
|
|
10086
|
+
);
|
|
10087
|
+
} else if (path$8.resolve(packagePath, main) !== urlPath) {
|
|
10088
|
+
process$1.emitWarning(
|
|
10089
|
+
`Package ${packagePath} has a "main" field set to "${main}", ` +
|
|
10090
|
+
`excluding the full filename and extension to the resolved file at "${urlPath.slice(
|
|
10091
|
+
packagePath.length
|
|
10092
|
+
)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is ` +
|
|
10093
|
+
'deprecated for ES modules.',
|
|
10094
|
+
'DeprecationWarning',
|
|
10095
|
+
'DEP0151'
|
|
10096
|
+
);
|
|
10097
|
+
}
|
|
10098
|
+
}
|
|
10099
|
+
|
|
10100
|
+
/**
|
|
10101
|
+
* @param {string} path
|
|
10102
|
+
* @returns {Stats | undefined}
|
|
10103
|
+
*/
|
|
10104
|
+
function tryStatSync(path) {
|
|
10105
|
+
// Note: from Node 15 onwards we can use `throwIfNoEntry: false` instead.
|
|
10106
|
+
try {
|
|
10107
|
+
return statSync$1(path)
|
|
10108
|
+
} catch {
|
|
10109
|
+
// Note: in Node code this returns `new Stats`,
|
|
10110
|
+
// but in Node 22 that’s marked as a deprecated internal API.
|
|
10111
|
+
// Which, well, we kinda are, but still to prevent that warning,
|
|
10112
|
+
// just yield `undefined`.
|
|
10113
|
+
}
|
|
10114
|
+
}
|
|
10115
|
+
|
|
10116
|
+
/**
|
|
10117
|
+
* Legacy CommonJS main resolution:
|
|
10118
|
+
* 1. let M = pkg_url + (json main field)
|
|
10119
|
+
* 2. TRY(M, M.js, M.json, M.node)
|
|
10120
|
+
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
10121
|
+
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
10122
|
+
* 5. NOT_FOUND
|
|
10123
|
+
*
|
|
10124
|
+
* @param {URL} url
|
|
10125
|
+
* @returns {boolean}
|
|
10126
|
+
*/
|
|
10127
|
+
function fileExists(url) {
|
|
10128
|
+
const stats = statSync$1(url, {throwIfNoEntry: false});
|
|
10129
|
+
const isFile = stats ? stats.isFile() : undefined;
|
|
10130
|
+
return isFile === null || isFile === undefined ? false : isFile
|
|
10131
|
+
}
|
|
10132
|
+
|
|
10133
|
+
/**
|
|
10134
|
+
* @param {URL} packageJsonUrl
|
|
10135
|
+
* @param {PackageConfig} packageConfig
|
|
10136
|
+
* @param {URL} base
|
|
10137
|
+
* @returns {URL}
|
|
10138
|
+
*/
|
|
10139
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
10140
|
+
/** @type {URL | undefined} */
|
|
10141
|
+
let guess;
|
|
10142
|
+
if (packageConfig.main !== undefined) {
|
|
10143
|
+
guess = new URL$2(packageConfig.main, packageJsonUrl);
|
|
10144
|
+
// Note: fs check redundances will be handled by Descriptor cache here.
|
|
10145
|
+
if (fileExists(guess)) return guess
|
|
10146
|
+
|
|
10147
|
+
const tries = [
|
|
10148
|
+
`./${packageConfig.main}.js`,
|
|
10149
|
+
`./${packageConfig.main}.json`,
|
|
10150
|
+
`./${packageConfig.main}.node`,
|
|
10151
|
+
`./${packageConfig.main}/index.js`,
|
|
10152
|
+
`./${packageConfig.main}/index.json`,
|
|
10153
|
+
`./${packageConfig.main}/index.node`
|
|
10154
|
+
];
|
|
10155
|
+
let i = -1;
|
|
10156
|
+
|
|
10157
|
+
while (++i < tries.length) {
|
|
10158
|
+
guess = new URL$2(tries[i], packageJsonUrl);
|
|
10159
|
+
if (fileExists(guess)) break
|
|
10160
|
+
guess = undefined;
|
|
10161
|
+
}
|
|
10162
|
+
|
|
10163
|
+
if (guess) {
|
|
10164
|
+
emitLegacyIndexDeprecation(
|
|
10165
|
+
guess,
|
|
10166
|
+
packageJsonUrl,
|
|
10167
|
+
base,
|
|
10168
|
+
packageConfig.main
|
|
10169
|
+
);
|
|
10170
|
+
return guess
|
|
10171
|
+
}
|
|
10172
|
+
// Fallthrough.
|
|
10173
|
+
}
|
|
10174
|
+
|
|
10175
|
+
const tries = ['./index.js', './index.json', './index.node'];
|
|
10176
|
+
let i = -1;
|
|
10177
|
+
|
|
10178
|
+
while (++i < tries.length) {
|
|
10179
|
+
guess = new URL$2(tries[i], packageJsonUrl);
|
|
10180
|
+
if (fileExists(guess)) break
|
|
10181
|
+
guess = undefined;
|
|
10182
|
+
}
|
|
10183
|
+
|
|
10184
|
+
if (guess) {
|
|
10185
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
10186
|
+
return guess
|
|
10187
|
+
}
|
|
10188
|
+
|
|
10189
|
+
// Not found.
|
|
10190
|
+
throw new ERR_MODULE_NOT_FOUND(
|
|
10191
|
+
fileURLToPath$1(new URL$2('.', packageJsonUrl)),
|
|
10192
|
+
fileURLToPath$1(base)
|
|
10193
|
+
)
|
|
10194
|
+
}
|
|
10195
|
+
|
|
10196
|
+
/**
|
|
10197
|
+
* @param {URL} resolved
|
|
10198
|
+
* @param {URL} base
|
|
10199
|
+
* @param {boolean} [preserveSymlinks]
|
|
10200
|
+
* @returns {URL}
|
|
10201
|
+
*/
|
|
10202
|
+
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
10203
|
+
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
|
|
10204
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
10205
|
+
resolved.pathname,
|
|
10206
|
+
'must not include encoded "/" or "\\" characters',
|
|
10207
|
+
fileURLToPath$1(base)
|
|
10208
|
+
)
|
|
10209
|
+
}
|
|
10210
|
+
|
|
10211
|
+
/** @type {string} */
|
|
10212
|
+
let filePath;
|
|
10213
|
+
|
|
10214
|
+
try {
|
|
10215
|
+
filePath = fileURLToPath$1(resolved);
|
|
10216
|
+
} catch (error) {
|
|
10217
|
+
const cause = /** @type {ErrnoException} */ (error);
|
|
10218
|
+
Object.defineProperty(cause, 'input', {value: String(resolved)});
|
|
10219
|
+
Object.defineProperty(cause, 'module', {value: String(base)});
|
|
10220
|
+
throw cause
|
|
10221
|
+
}
|
|
10222
|
+
|
|
10223
|
+
const stats = tryStatSync(
|
|
10224
|
+
filePath.endsWith('/') ? filePath.slice(-1) : filePath
|
|
10225
|
+
);
|
|
10226
|
+
|
|
10227
|
+
if (stats && stats.isDirectory()) {
|
|
10228
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath$1(base));
|
|
10229
|
+
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
10230
|
+
error.url = String(resolved);
|
|
10231
|
+
throw error
|
|
10232
|
+
}
|
|
10233
|
+
|
|
10234
|
+
if (!stats || !stats.isFile()) {
|
|
10235
|
+
const error = new ERR_MODULE_NOT_FOUND(
|
|
10236
|
+
filePath || resolved.pathname,
|
|
10237
|
+
base && fileURLToPath$1(base),
|
|
10238
|
+
true
|
|
10239
|
+
);
|
|
10240
|
+
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
10241
|
+
error.url = String(resolved);
|
|
10242
|
+
throw error
|
|
10243
|
+
}
|
|
10244
|
+
|
|
10245
|
+
{
|
|
10246
|
+
const real = realpathSync(filePath);
|
|
10247
|
+
const {search, hash} = resolved;
|
|
10248
|
+
resolved = pathToFileURL$1(real + (filePath.endsWith(path$8.sep) ? '/' : ''));
|
|
10249
|
+
resolved.search = search;
|
|
10250
|
+
resolved.hash = hash;
|
|
10251
|
+
}
|
|
10252
|
+
|
|
10253
|
+
return resolved
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10256
|
+
/**
|
|
10257
|
+
* @param {string} specifier
|
|
10258
|
+
* @param {URL | undefined} packageJsonUrl
|
|
10259
|
+
* @param {URL} base
|
|
10260
|
+
* @returns {Error}
|
|
10261
|
+
*/
|
|
10262
|
+
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
10263
|
+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
10264
|
+
specifier,
|
|
10265
|
+
packageJsonUrl && fileURLToPath$1(new URL$2('.', packageJsonUrl)),
|
|
10266
|
+
fileURLToPath$1(base)
|
|
10267
|
+
)
|
|
10268
|
+
}
|
|
10269
|
+
|
|
10270
|
+
/**
|
|
10271
|
+
* @param {string} subpath
|
|
10272
|
+
* @param {URL} packageJsonUrl
|
|
10273
|
+
* @param {URL} base
|
|
10274
|
+
* @returns {Error}
|
|
10275
|
+
*/
|
|
10276
|
+
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
10277
|
+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
10278
|
+
fileURLToPath$1(new URL$2('.', packageJsonUrl)),
|
|
10279
|
+
subpath,
|
|
10280
|
+
base && fileURLToPath$1(base)
|
|
10281
|
+
)
|
|
10282
|
+
}
|
|
10283
|
+
|
|
10284
|
+
/**
|
|
10285
|
+
* @param {string} request
|
|
10286
|
+
* @param {string} match
|
|
10287
|
+
* @param {URL} packageJsonUrl
|
|
10288
|
+
* @param {boolean} internal
|
|
10289
|
+
* @param {URL} [base]
|
|
10290
|
+
* @returns {never}
|
|
10291
|
+
*/
|
|
10292
|
+
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
10293
|
+
const reason = `request is not a valid match in pattern "${match}" for the "${
|
|
10294
|
+
internal ? 'imports' : 'exports'
|
|
10295
|
+
}" resolution of ${fileURLToPath$1(packageJsonUrl)}`;
|
|
10296
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
10297
|
+
request,
|
|
10298
|
+
reason,
|
|
10299
|
+
base && fileURLToPath$1(base)
|
|
10300
|
+
)
|
|
10301
|
+
}
|
|
10302
|
+
|
|
10303
|
+
/**
|
|
10304
|
+
* @param {string} subpath
|
|
10305
|
+
* @param {unknown} target
|
|
10306
|
+
* @param {URL} packageJsonUrl
|
|
10307
|
+
* @param {boolean} internal
|
|
10308
|
+
* @param {URL} [base]
|
|
10309
|
+
* @returns {Error}
|
|
10310
|
+
*/
|
|
10311
|
+
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
10312
|
+
target =
|
|
10313
|
+
typeof target === 'object' && target !== null
|
|
10314
|
+
? JSON.stringify(target, null, '')
|
|
10315
|
+
: `${target}`;
|
|
10316
|
+
|
|
10317
|
+
return new ERR_INVALID_PACKAGE_TARGET(
|
|
10318
|
+
fileURLToPath$1(new URL$2('.', packageJsonUrl)),
|
|
10319
|
+
subpath,
|
|
10320
|
+
target,
|
|
10321
|
+
internal,
|
|
10322
|
+
base && fileURLToPath$1(base)
|
|
10323
|
+
)
|
|
10324
|
+
}
|
|
10325
|
+
|
|
10326
|
+
/**
|
|
10327
|
+
* @param {string} target
|
|
10328
|
+
* @param {string} subpath
|
|
10329
|
+
* @param {string} match
|
|
10330
|
+
* @param {URL} packageJsonUrl
|
|
10331
|
+
* @param {URL} base
|
|
10332
|
+
* @param {boolean} pattern
|
|
10333
|
+
* @param {boolean} internal
|
|
10334
|
+
* @param {boolean} isPathMap
|
|
10335
|
+
* @param {Set<string> | undefined} conditions
|
|
10336
|
+
* @returns {URL}
|
|
10337
|
+
*/
|
|
10338
|
+
function resolvePackageTargetString(
|
|
10339
|
+
target,
|
|
10340
|
+
subpath,
|
|
10341
|
+
match,
|
|
10342
|
+
packageJsonUrl,
|
|
10343
|
+
base,
|
|
10344
|
+
pattern,
|
|
10345
|
+
internal,
|
|
10346
|
+
isPathMap,
|
|
10347
|
+
conditions
|
|
10348
|
+
) {
|
|
10349
|
+
if (subpath !== '' && !pattern && target[target.length - 1] !== '/')
|
|
10350
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base)
|
|
10351
|
+
|
|
10352
|
+
if (!target.startsWith('./')) {
|
|
10353
|
+
if (internal && !target.startsWith('../') && !target.startsWith('/')) {
|
|
10354
|
+
let isURL = false;
|
|
10355
|
+
|
|
10356
|
+
try {
|
|
10357
|
+
new URL$2(target);
|
|
10358
|
+
isURL = true;
|
|
10359
|
+
} catch {
|
|
10360
|
+
// Continue regardless of error.
|
|
10361
|
+
}
|
|
10362
|
+
|
|
10363
|
+
if (!isURL) {
|
|
10364
|
+
const exportTarget = pattern
|
|
10365
|
+
? RegExpPrototypeSymbolReplace.call(
|
|
10366
|
+
patternRegEx,
|
|
10367
|
+
target,
|
|
10368
|
+
() => subpath
|
|
10369
|
+
)
|
|
10370
|
+
: target + subpath;
|
|
10371
|
+
|
|
10372
|
+
return packageResolve(exportTarget, packageJsonUrl, conditions)
|
|
10373
|
+
}
|
|
10374
|
+
}
|
|
10375
|
+
|
|
10376
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base)
|
|
10377
|
+
}
|
|
10378
|
+
|
|
10379
|
+
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
|
|
10380
|
+
if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
10381
|
+
if (!isPathMap) {
|
|
10382
|
+
const request = pattern
|
|
10383
|
+
? match.replace('*', () => subpath)
|
|
10384
|
+
: match + subpath;
|
|
10385
|
+
const resolvedTarget = pattern
|
|
10386
|
+
? RegExpPrototypeSymbolReplace.call(
|
|
10387
|
+
patternRegEx,
|
|
10388
|
+
target,
|
|
10389
|
+
() => subpath
|
|
10390
|
+
)
|
|
10391
|
+
: target;
|
|
10392
|
+
emitInvalidSegmentDeprecation(
|
|
10393
|
+
resolvedTarget,
|
|
10394
|
+
request,
|
|
10395
|
+
match,
|
|
10396
|
+
packageJsonUrl,
|
|
10397
|
+
internal,
|
|
10398
|
+
base,
|
|
10399
|
+
true
|
|
10400
|
+
);
|
|
10401
|
+
}
|
|
10402
|
+
} else {
|
|
10403
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base)
|
|
10404
|
+
}
|
|
10405
|
+
}
|
|
10406
|
+
|
|
10407
|
+
const resolved = new URL$2(target, packageJsonUrl);
|
|
10408
|
+
const resolvedPath = resolved.pathname;
|
|
10409
|
+
const packagePath = new URL$2('.', packageJsonUrl).pathname;
|
|
10410
|
+
|
|
10411
|
+
if (!resolvedPath.startsWith(packagePath))
|
|
10412
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base)
|
|
10413
|
+
|
|
10414
|
+
if (subpath === '') return resolved
|
|
10415
|
+
|
|
10416
|
+
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
10417
|
+
const request = pattern
|
|
10418
|
+
? match.replace('*', () => subpath)
|
|
10419
|
+
: match + subpath;
|
|
10420
|
+
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
10421
|
+
if (!isPathMap) {
|
|
10422
|
+
const resolvedTarget = pattern
|
|
10423
|
+
? RegExpPrototypeSymbolReplace.call(
|
|
10424
|
+
patternRegEx,
|
|
10425
|
+
target,
|
|
10426
|
+
() => subpath
|
|
10427
|
+
)
|
|
10428
|
+
: target;
|
|
10429
|
+
emitInvalidSegmentDeprecation(
|
|
10430
|
+
resolvedTarget,
|
|
10431
|
+
request,
|
|
10432
|
+
match,
|
|
10433
|
+
packageJsonUrl,
|
|
10434
|
+
internal,
|
|
10435
|
+
base,
|
|
10436
|
+
false
|
|
10437
|
+
);
|
|
10438
|
+
}
|
|
10439
|
+
} else {
|
|
10440
|
+
throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
10441
|
+
}
|
|
10442
|
+
}
|
|
10443
|
+
|
|
10444
|
+
if (pattern) {
|
|
10445
|
+
return new URL$2(
|
|
10446
|
+
RegExpPrototypeSymbolReplace.call(
|
|
10447
|
+
patternRegEx,
|
|
10448
|
+
resolved.href,
|
|
10449
|
+
() => subpath
|
|
10450
|
+
)
|
|
10451
|
+
)
|
|
10452
|
+
}
|
|
10453
|
+
|
|
10454
|
+
return new URL$2(subpath, resolved)
|
|
10455
|
+
}
|
|
10456
|
+
|
|
10457
|
+
/**
|
|
10458
|
+
* @param {string} key
|
|
10459
|
+
* @returns {boolean}
|
|
10460
|
+
*/
|
|
10461
|
+
function isArrayIndex(key) {
|
|
10462
|
+
const keyNumber = Number(key);
|
|
10463
|
+
if (`${keyNumber}` !== key) return false
|
|
10464
|
+
return keyNumber >= 0 && keyNumber < 0xff_ff_ff_ff
|
|
10465
|
+
}
|
|
10466
|
+
|
|
10467
|
+
/**
|
|
10468
|
+
* @param {URL} packageJsonUrl
|
|
10469
|
+
* @param {unknown} target
|
|
10470
|
+
* @param {string} subpath
|
|
10471
|
+
* @param {string} packageSubpath
|
|
10472
|
+
* @param {URL} base
|
|
10473
|
+
* @param {boolean} pattern
|
|
10474
|
+
* @param {boolean} internal
|
|
10475
|
+
* @param {boolean} isPathMap
|
|
10476
|
+
* @param {Set<string> | undefined} conditions
|
|
10477
|
+
* @returns {URL | null}
|
|
10478
|
+
*/
|
|
10479
|
+
function resolvePackageTarget(
|
|
10480
|
+
packageJsonUrl,
|
|
10481
|
+
target,
|
|
10482
|
+
subpath,
|
|
10483
|
+
packageSubpath,
|
|
10484
|
+
base,
|
|
10485
|
+
pattern,
|
|
10486
|
+
internal,
|
|
10487
|
+
isPathMap,
|
|
10488
|
+
conditions
|
|
10489
|
+
) {
|
|
10490
|
+
if (typeof target === 'string') {
|
|
10491
|
+
return resolvePackageTargetString(
|
|
10492
|
+
target,
|
|
10493
|
+
subpath,
|
|
10494
|
+
packageSubpath,
|
|
10495
|
+
packageJsonUrl,
|
|
10496
|
+
base,
|
|
10497
|
+
pattern,
|
|
10498
|
+
internal,
|
|
10499
|
+
isPathMap,
|
|
10500
|
+
conditions
|
|
10501
|
+
)
|
|
10502
|
+
}
|
|
10503
|
+
|
|
10504
|
+
if (Array.isArray(target)) {
|
|
10505
|
+
/** @type {Array<unknown>} */
|
|
10506
|
+
const targetList = target;
|
|
10507
|
+
if (targetList.length === 0) return null
|
|
10508
|
+
|
|
10509
|
+
/** @type {ErrnoException | null | undefined} */
|
|
10510
|
+
let lastException;
|
|
10511
|
+
let i = -1;
|
|
10512
|
+
|
|
10513
|
+
while (++i < targetList.length) {
|
|
10514
|
+
const targetItem = targetList[i];
|
|
10515
|
+
/** @type {URL | null} */
|
|
10516
|
+
let resolveResult;
|
|
10517
|
+
try {
|
|
10518
|
+
resolveResult = resolvePackageTarget(
|
|
10519
|
+
packageJsonUrl,
|
|
10520
|
+
targetItem,
|
|
10521
|
+
subpath,
|
|
10522
|
+
packageSubpath,
|
|
10523
|
+
base,
|
|
10524
|
+
pattern,
|
|
10525
|
+
internal,
|
|
10526
|
+
isPathMap,
|
|
10527
|
+
conditions
|
|
10528
|
+
);
|
|
10529
|
+
} catch (error) {
|
|
10530
|
+
const exception = /** @type {ErrnoException} */ (error);
|
|
10531
|
+
lastException = exception;
|
|
10532
|
+
if (exception.code === 'ERR_INVALID_PACKAGE_TARGET') continue
|
|
10533
|
+
throw error
|
|
10534
|
+
}
|
|
10535
|
+
|
|
10536
|
+
if (resolveResult === undefined) continue
|
|
10537
|
+
|
|
10538
|
+
if (resolveResult === null) {
|
|
10539
|
+
lastException = null;
|
|
10540
|
+
continue
|
|
10541
|
+
}
|
|
10542
|
+
|
|
10543
|
+
return resolveResult
|
|
10544
|
+
}
|
|
10545
|
+
|
|
10546
|
+
if (lastException === undefined || lastException === null) {
|
|
10547
|
+
return null
|
|
10548
|
+
}
|
|
10549
|
+
|
|
10550
|
+
throw lastException
|
|
10551
|
+
}
|
|
10552
|
+
|
|
10553
|
+
if (typeof target === 'object' && target !== null) {
|
|
10554
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
10555
|
+
let i = -1;
|
|
10556
|
+
|
|
10557
|
+
while (++i < keys.length) {
|
|
10558
|
+
const key = keys[i];
|
|
10559
|
+
if (isArrayIndex(key)) {
|
|
10560
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
10561
|
+
fileURLToPath$1(packageJsonUrl),
|
|
10562
|
+
base,
|
|
10563
|
+
'"exports" cannot contain numeric property keys.'
|
|
10564
|
+
)
|
|
10565
|
+
}
|
|
10566
|
+
}
|
|
10567
|
+
|
|
10568
|
+
i = -1;
|
|
10569
|
+
|
|
10570
|
+
while (++i < keys.length) {
|
|
10571
|
+
const key = keys[i];
|
|
10572
|
+
if (key === 'default' || (conditions && conditions.has(key))) {
|
|
10573
|
+
// @ts-expect-error: indexable.
|
|
10574
|
+
const conditionalTarget = /** @type {unknown} */ (target[key]);
|
|
10575
|
+
const resolveResult = resolvePackageTarget(
|
|
10576
|
+
packageJsonUrl,
|
|
10577
|
+
conditionalTarget,
|
|
10578
|
+
subpath,
|
|
10579
|
+
packageSubpath,
|
|
10580
|
+
base,
|
|
10581
|
+
pattern,
|
|
10582
|
+
internal,
|
|
10583
|
+
isPathMap,
|
|
10584
|
+
conditions
|
|
10585
|
+
);
|
|
10586
|
+
if (resolveResult === undefined) continue
|
|
10587
|
+
return resolveResult
|
|
10588
|
+
}
|
|
10589
|
+
}
|
|
10590
|
+
|
|
10591
|
+
return null
|
|
10592
|
+
}
|
|
10593
|
+
|
|
10594
|
+
if (target === null) {
|
|
10595
|
+
return null
|
|
10596
|
+
}
|
|
10597
|
+
|
|
10598
|
+
throw invalidPackageTarget(
|
|
10599
|
+
packageSubpath,
|
|
10600
|
+
target,
|
|
10601
|
+
packageJsonUrl,
|
|
10602
|
+
internal,
|
|
10603
|
+
base
|
|
10604
|
+
)
|
|
10605
|
+
}
|
|
10606
|
+
|
|
10607
|
+
/**
|
|
10608
|
+
* @param {unknown} exports
|
|
10609
|
+
* @param {URL} packageJsonUrl
|
|
10610
|
+
* @param {URL} base
|
|
10611
|
+
* @returns {boolean}
|
|
10612
|
+
*/
|
|
10613
|
+
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
10614
|
+
if (typeof exports === 'string' || Array.isArray(exports)) return true
|
|
10615
|
+
if (typeof exports !== 'object' || exports === null) return false
|
|
10616
|
+
|
|
10617
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
10618
|
+
let isConditionalSugar = false;
|
|
10619
|
+
let i = 0;
|
|
10620
|
+
let keyIndex = -1;
|
|
10621
|
+
while (++keyIndex < keys.length) {
|
|
10622
|
+
const key = keys[keyIndex];
|
|
10623
|
+
const currentIsConditionalSugar = key === '' || key[0] !== '.';
|
|
10624
|
+
if (i++ === 0) {
|
|
10625
|
+
isConditionalSugar = currentIsConditionalSugar;
|
|
10626
|
+
} else if (isConditionalSugar !== currentIsConditionalSugar) {
|
|
10627
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
10628
|
+
fileURLToPath$1(packageJsonUrl),
|
|
10629
|
+
base,
|
|
10630
|
+
'"exports" cannot contain some keys starting with \'.\' and some not.' +
|
|
10631
|
+
' The exports object must either be an object of package subpath keys' +
|
|
10632
|
+
' or an object of main entry condition name keys only.'
|
|
10633
|
+
)
|
|
10634
|
+
}
|
|
10635
|
+
}
|
|
10636
|
+
|
|
10637
|
+
return isConditionalSugar
|
|
10638
|
+
}
|
|
10639
|
+
|
|
10640
|
+
/**
|
|
10641
|
+
* @param {string} match
|
|
10642
|
+
* @param {URL} pjsonUrl
|
|
10643
|
+
* @param {URL} base
|
|
10644
|
+
*/
|
|
10645
|
+
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
10646
|
+
// @ts-expect-error: apparently it does exist, TS.
|
|
10647
|
+
if (process$1.noDeprecation) {
|
|
10648
|
+
return
|
|
10649
|
+
}
|
|
10650
|
+
|
|
10651
|
+
const pjsonPath = fileURLToPath$1(pjsonUrl);
|
|
10652
|
+
if (emittedPackageWarnings.has(pjsonPath + '|' + match)) return
|
|
10653
|
+
emittedPackageWarnings.add(pjsonPath + '|' + match);
|
|
10654
|
+
process$1.emitWarning(
|
|
10655
|
+
`Use of deprecated trailing slash pattern mapping "${match}" in the ` +
|
|
10656
|
+
`"exports" field module resolution of the package at ${pjsonPath}${
|
|
10657
|
+
base ? ` imported from ${fileURLToPath$1(base)}` : ''
|
|
10658
|
+
}. Mapping specifiers ending in "/" is no longer supported.`,
|
|
10659
|
+
'DeprecationWarning',
|
|
10660
|
+
'DEP0155'
|
|
10661
|
+
);
|
|
10662
|
+
}
|
|
10663
|
+
|
|
10664
|
+
/**
|
|
10665
|
+
* @param {URL} packageJsonUrl
|
|
10666
|
+
* @param {string} packageSubpath
|
|
10667
|
+
* @param {Record<string, unknown>} packageConfig
|
|
10668
|
+
* @param {URL} base
|
|
10669
|
+
* @param {Set<string> | undefined} conditions
|
|
10670
|
+
* @returns {URL}
|
|
10671
|
+
*/
|
|
10672
|
+
function packageExportsResolve(
|
|
10673
|
+
packageJsonUrl,
|
|
10674
|
+
packageSubpath,
|
|
10675
|
+
packageConfig,
|
|
10676
|
+
base,
|
|
10677
|
+
conditions
|
|
10678
|
+
) {
|
|
10679
|
+
let exports = packageConfig.exports;
|
|
10680
|
+
|
|
10681
|
+
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
|
|
10682
|
+
exports = {'.': exports};
|
|
10683
|
+
}
|
|
10684
|
+
|
|
10685
|
+
if (
|
|
10686
|
+
own.call(exports, packageSubpath) &&
|
|
10687
|
+
!packageSubpath.includes('*') &&
|
|
10688
|
+
!packageSubpath.endsWith('/')
|
|
10689
|
+
) {
|
|
10690
|
+
// @ts-expect-error: indexable.
|
|
10691
|
+
const target = exports[packageSubpath];
|
|
10692
|
+
const resolveResult = resolvePackageTarget(
|
|
10693
|
+
packageJsonUrl,
|
|
10694
|
+
target,
|
|
10695
|
+
'',
|
|
10696
|
+
packageSubpath,
|
|
10697
|
+
base,
|
|
10698
|
+
false,
|
|
10699
|
+
false,
|
|
10700
|
+
false,
|
|
10701
|
+
conditions
|
|
10702
|
+
);
|
|
10703
|
+
if (resolveResult === null || resolveResult === undefined) {
|
|
10704
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base)
|
|
10705
|
+
}
|
|
10706
|
+
|
|
10707
|
+
return resolveResult
|
|
10708
|
+
}
|
|
10709
|
+
|
|
10710
|
+
let bestMatch = '';
|
|
10711
|
+
let bestMatchSubpath = '';
|
|
10712
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
10713
|
+
let i = -1;
|
|
10714
|
+
|
|
10715
|
+
while (++i < keys.length) {
|
|
10716
|
+
const key = keys[i];
|
|
10717
|
+
const patternIndex = key.indexOf('*');
|
|
10718
|
+
|
|
10719
|
+
if (
|
|
10720
|
+
patternIndex !== -1 &&
|
|
10721
|
+
packageSubpath.startsWith(key.slice(0, patternIndex))
|
|
10722
|
+
) {
|
|
10723
|
+
// When this reaches EOL, this can throw at the top of the whole function:
|
|
10724
|
+
//
|
|
10725
|
+
// if (StringPrototypeEndsWith(packageSubpath, '/'))
|
|
10726
|
+
// throwInvalidSubpath(packageSubpath)
|
|
10727
|
+
//
|
|
10728
|
+
// To match "imports" and the spec.
|
|
10729
|
+
if (packageSubpath.endsWith('/')) {
|
|
10730
|
+
emitTrailingSlashPatternDeprecation(
|
|
10731
|
+
packageSubpath,
|
|
10732
|
+
packageJsonUrl,
|
|
10733
|
+
base
|
|
10734
|
+
);
|
|
10735
|
+
}
|
|
10736
|
+
|
|
10737
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
10738
|
+
|
|
10739
|
+
if (
|
|
10740
|
+
packageSubpath.length >= key.length &&
|
|
10741
|
+
packageSubpath.endsWith(patternTrailer) &&
|
|
10742
|
+
patternKeyCompare(bestMatch, key) === 1 &&
|
|
10743
|
+
key.lastIndexOf('*') === patternIndex
|
|
10744
|
+
) {
|
|
10745
|
+
bestMatch = key;
|
|
10746
|
+
bestMatchSubpath = packageSubpath.slice(
|
|
10747
|
+
patternIndex,
|
|
10748
|
+
packageSubpath.length - patternTrailer.length
|
|
10749
|
+
);
|
|
10750
|
+
}
|
|
10751
|
+
}
|
|
10752
|
+
}
|
|
10753
|
+
|
|
10754
|
+
if (bestMatch) {
|
|
10755
|
+
// @ts-expect-error: indexable.
|
|
10756
|
+
const target = /** @type {unknown} */ (exports[bestMatch]);
|
|
10757
|
+
const resolveResult = resolvePackageTarget(
|
|
10758
|
+
packageJsonUrl,
|
|
10759
|
+
target,
|
|
10760
|
+
bestMatchSubpath,
|
|
10761
|
+
bestMatch,
|
|
10762
|
+
base,
|
|
10763
|
+
true,
|
|
10764
|
+
false,
|
|
10765
|
+
packageSubpath.endsWith('/'),
|
|
10766
|
+
conditions
|
|
10767
|
+
);
|
|
10768
|
+
|
|
10769
|
+
if (resolveResult === null || resolveResult === undefined) {
|
|
10770
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base)
|
|
10771
|
+
}
|
|
10772
|
+
|
|
10773
|
+
return resolveResult
|
|
10774
|
+
}
|
|
10775
|
+
|
|
10776
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base)
|
|
10777
|
+
}
|
|
10778
|
+
|
|
10779
|
+
/**
|
|
10780
|
+
* @param {string} a
|
|
10781
|
+
* @param {string} b
|
|
10782
|
+
*/
|
|
10783
|
+
function patternKeyCompare(a, b) {
|
|
10784
|
+
const aPatternIndex = a.indexOf('*');
|
|
10785
|
+
const bPatternIndex = b.indexOf('*');
|
|
10786
|
+
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
10787
|
+
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
10788
|
+
if (baseLengthA > baseLengthB) return -1
|
|
10789
|
+
if (baseLengthB > baseLengthA) return 1
|
|
10790
|
+
if (aPatternIndex === -1) return 1
|
|
10791
|
+
if (bPatternIndex === -1) return -1
|
|
10792
|
+
if (a.length > b.length) return -1
|
|
10793
|
+
if (b.length > a.length) return 1
|
|
10794
|
+
return 0
|
|
10795
|
+
}
|
|
10796
|
+
|
|
10797
|
+
/**
|
|
10798
|
+
* @param {string} name
|
|
10799
|
+
* @param {URL} base
|
|
10800
|
+
* @param {Set<string>} [conditions]
|
|
10801
|
+
* @returns {URL}
|
|
10802
|
+
*/
|
|
10803
|
+
function packageImportsResolve(name, base, conditions) {
|
|
10804
|
+
if (name === '#' || name.startsWith('#/') || name.endsWith('/')) {
|
|
10805
|
+
const reason = 'is not a valid internal imports specifier name';
|
|
10806
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath$1(base))
|
|
10807
|
+
}
|
|
10808
|
+
|
|
10809
|
+
/** @type {URL | undefined} */
|
|
10810
|
+
let packageJsonUrl;
|
|
10811
|
+
|
|
10812
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
10813
|
+
|
|
10814
|
+
if (packageConfig.exists) {
|
|
10815
|
+
packageJsonUrl = pathToFileURL$1(packageConfig.pjsonPath);
|
|
10816
|
+
const imports = packageConfig.imports;
|
|
10817
|
+
if (imports) {
|
|
10818
|
+
if (own.call(imports, name) && !name.includes('*')) {
|
|
10819
|
+
const resolveResult = resolvePackageTarget(
|
|
10820
|
+
packageJsonUrl,
|
|
10821
|
+
imports[name],
|
|
10822
|
+
'',
|
|
10823
|
+
name,
|
|
10824
|
+
base,
|
|
10825
|
+
false,
|
|
10826
|
+
true,
|
|
10827
|
+
false,
|
|
10828
|
+
conditions
|
|
10829
|
+
);
|
|
10830
|
+
if (resolveResult !== null && resolveResult !== undefined) {
|
|
10831
|
+
return resolveResult
|
|
10832
|
+
}
|
|
10833
|
+
} else {
|
|
10834
|
+
let bestMatch = '';
|
|
10835
|
+
let bestMatchSubpath = '';
|
|
10836
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
10837
|
+
let i = -1;
|
|
10838
|
+
|
|
10839
|
+
while (++i < keys.length) {
|
|
10840
|
+
const key = keys[i];
|
|
10841
|
+
const patternIndex = key.indexOf('*');
|
|
10842
|
+
|
|
10843
|
+
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
10844
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
10845
|
+
if (
|
|
10846
|
+
name.length >= key.length &&
|
|
10847
|
+
name.endsWith(patternTrailer) &&
|
|
10848
|
+
patternKeyCompare(bestMatch, key) === 1 &&
|
|
10849
|
+
key.lastIndexOf('*') === patternIndex
|
|
10850
|
+
) {
|
|
10851
|
+
bestMatch = key;
|
|
10852
|
+
bestMatchSubpath = name.slice(
|
|
10853
|
+
patternIndex,
|
|
10854
|
+
name.length - patternTrailer.length
|
|
10855
|
+
);
|
|
10856
|
+
}
|
|
10857
|
+
}
|
|
10858
|
+
}
|
|
10859
|
+
|
|
10860
|
+
if (bestMatch) {
|
|
10861
|
+
const target = imports[bestMatch];
|
|
10862
|
+
const resolveResult = resolvePackageTarget(
|
|
10863
|
+
packageJsonUrl,
|
|
10864
|
+
target,
|
|
10865
|
+
bestMatchSubpath,
|
|
10866
|
+
bestMatch,
|
|
10867
|
+
base,
|
|
10868
|
+
true,
|
|
10869
|
+
true,
|
|
10870
|
+
false,
|
|
10871
|
+
conditions
|
|
10872
|
+
);
|
|
10873
|
+
|
|
10874
|
+
if (resolveResult !== null && resolveResult !== undefined) {
|
|
10875
|
+
return resolveResult
|
|
10876
|
+
}
|
|
10877
|
+
}
|
|
10878
|
+
}
|
|
10879
|
+
}
|
|
10880
|
+
}
|
|
10881
|
+
|
|
10882
|
+
throw importNotDefined(name, packageJsonUrl, base)
|
|
10883
|
+
}
|
|
10884
|
+
|
|
10885
|
+
/**
|
|
10886
|
+
* @param {string} specifier
|
|
10887
|
+
* @param {URL} base
|
|
10888
|
+
*/
|
|
10889
|
+
function parsePackageName(specifier, base) {
|
|
10890
|
+
let separatorIndex = specifier.indexOf('/');
|
|
10891
|
+
let validPackageName = true;
|
|
10892
|
+
let isScoped = false;
|
|
10893
|
+
if (specifier[0] === '@') {
|
|
10894
|
+
isScoped = true;
|
|
10895
|
+
if (separatorIndex === -1 || specifier.length === 0) {
|
|
10896
|
+
validPackageName = false;
|
|
10897
|
+
} else {
|
|
10898
|
+
separatorIndex = specifier.indexOf('/', separatorIndex + 1);
|
|
10899
|
+
}
|
|
10900
|
+
}
|
|
10901
|
+
|
|
10902
|
+
const packageName =
|
|
10903
|
+
separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
10904
|
+
|
|
10905
|
+
// Package name cannot have leading . and cannot have percent-encoding or
|
|
10906
|
+
// \\ separators.
|
|
10907
|
+
if (invalidPackageNameRegEx.exec(packageName) !== null) {
|
|
10908
|
+
validPackageName = false;
|
|
10909
|
+
}
|
|
10910
|
+
|
|
10911
|
+
if (!validPackageName) {
|
|
10912
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
10913
|
+
specifier,
|
|
10914
|
+
'is not a valid package name',
|
|
10915
|
+
fileURLToPath$1(base)
|
|
10916
|
+
)
|
|
10917
|
+
}
|
|
10918
|
+
|
|
10919
|
+
const packageSubpath =
|
|
10920
|
+
'.' + (separatorIndex === -1 ? '' : specifier.slice(separatorIndex));
|
|
10921
|
+
|
|
10922
|
+
return {packageName, packageSubpath, isScoped}
|
|
10923
|
+
}
|
|
10924
|
+
|
|
10925
|
+
/**
|
|
10926
|
+
* @param {string} specifier
|
|
10927
|
+
* @param {URL} base
|
|
10928
|
+
* @param {Set<string> | undefined} conditions
|
|
10929
|
+
* @returns {URL}
|
|
10930
|
+
*/
|
|
10931
|
+
function packageResolve(specifier, base, conditions) {
|
|
10932
|
+
if (builtinModules.includes(specifier)) {
|
|
10933
|
+
return new URL$2('node:' + specifier)
|
|
10934
|
+
}
|
|
10935
|
+
|
|
10936
|
+
const {packageName, packageSubpath, isScoped} = parsePackageName(
|
|
10937
|
+
specifier,
|
|
10938
|
+
base
|
|
10939
|
+
);
|
|
10940
|
+
|
|
10941
|
+
// ResolveSelf
|
|
10942
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
10943
|
+
|
|
10944
|
+
// Can’t test.
|
|
10945
|
+
/* c8 ignore next 16 */
|
|
10946
|
+
if (packageConfig.exists) {
|
|
10947
|
+
const packageJsonUrl = pathToFileURL$1(packageConfig.pjsonPath);
|
|
10948
|
+
if (
|
|
10949
|
+
packageConfig.name === packageName &&
|
|
10950
|
+
packageConfig.exports !== undefined &&
|
|
10951
|
+
packageConfig.exports !== null
|
|
10952
|
+
) {
|
|
10953
|
+
return packageExportsResolve(
|
|
10954
|
+
packageJsonUrl,
|
|
10955
|
+
packageSubpath,
|
|
10956
|
+
packageConfig,
|
|
10957
|
+
base,
|
|
10958
|
+
conditions
|
|
10959
|
+
)
|
|
10960
|
+
}
|
|
10961
|
+
}
|
|
10962
|
+
|
|
10963
|
+
let packageJsonUrl = new URL$2(
|
|
10964
|
+
'./node_modules/' + packageName + '/package.json',
|
|
10965
|
+
base
|
|
10966
|
+
);
|
|
10967
|
+
let packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
10968
|
+
/** @type {string} */
|
|
10969
|
+
let lastPath;
|
|
10970
|
+
do {
|
|
10971
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
10972
|
+
if (!stat || !stat.isDirectory()) {
|
|
10973
|
+
lastPath = packageJsonPath;
|
|
10974
|
+
packageJsonUrl = new URL$2(
|
|
10975
|
+
(isScoped ? '../../../../node_modules/' : '../../../node_modules/') +
|
|
10976
|
+
packageName +
|
|
10977
|
+
'/package.json',
|
|
10978
|
+
packageJsonUrl
|
|
10979
|
+
);
|
|
10980
|
+
packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
10981
|
+
continue
|
|
10982
|
+
}
|
|
10983
|
+
|
|
10984
|
+
// Package match.
|
|
10985
|
+
const packageConfig = read(packageJsonPath, {base, specifier});
|
|
10986
|
+
if (packageConfig.exports !== undefined && packageConfig.exports !== null) {
|
|
10987
|
+
return packageExportsResolve(
|
|
10988
|
+
packageJsonUrl,
|
|
10989
|
+
packageSubpath,
|
|
10990
|
+
packageConfig,
|
|
10991
|
+
base,
|
|
10992
|
+
conditions
|
|
10993
|
+
)
|
|
10994
|
+
}
|
|
10995
|
+
|
|
10996
|
+
if (packageSubpath === '.') {
|
|
10997
|
+
return legacyMainResolve(packageJsonUrl, packageConfig, base)
|
|
10998
|
+
}
|
|
10999
|
+
|
|
11000
|
+
return new URL$2(packageSubpath, packageJsonUrl)
|
|
11001
|
+
// Cross-platform root check.
|
|
11002
|
+
} while (packageJsonPath.length !== lastPath.length)
|
|
11003
|
+
|
|
11004
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath$1(base), false)
|
|
11005
|
+
}
|
|
11006
|
+
|
|
11007
|
+
/**
|
|
11008
|
+
* @param {string} specifier
|
|
11009
|
+
* @returns {boolean}
|
|
11010
|
+
*/
|
|
11011
|
+
function isRelativeSpecifier(specifier) {
|
|
11012
|
+
if (specifier[0] === '.') {
|
|
11013
|
+
if (specifier.length === 1 || specifier[1] === '/') return true
|
|
11014
|
+
if (
|
|
11015
|
+
specifier[1] === '.' &&
|
|
11016
|
+
(specifier.length === 2 || specifier[2] === '/')
|
|
11017
|
+
) {
|
|
11018
|
+
return true
|
|
11019
|
+
}
|
|
11020
|
+
}
|
|
11021
|
+
|
|
11022
|
+
return false
|
|
11023
|
+
}
|
|
11024
|
+
|
|
11025
|
+
/**
|
|
11026
|
+
* @param {string} specifier
|
|
11027
|
+
* @returns {boolean}
|
|
11028
|
+
*/
|
|
11029
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
11030
|
+
if (specifier === '') return false
|
|
11031
|
+
if (specifier[0] === '/') return true
|
|
11032
|
+
return isRelativeSpecifier(specifier)
|
|
11033
|
+
}
|
|
11034
|
+
|
|
11035
|
+
/**
|
|
11036
|
+
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
11037
|
+
* sync and slightly lower-level than `resolve`).
|
|
11038
|
+
*
|
|
11039
|
+
* @param {string} specifier
|
|
11040
|
+
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
|
|
11041
|
+
* @param {URL} base
|
|
11042
|
+
* Full URL (to a file) that `specifier` is resolved relative from.
|
|
11043
|
+
* @param {Set<string>} [conditions]
|
|
11044
|
+
* Conditions.
|
|
11045
|
+
* @param {boolean} [preserveSymlinks]
|
|
11046
|
+
* Keep symlinks instead of resolving them.
|
|
11047
|
+
* @returns {URL}
|
|
11048
|
+
* A URL object to the found thing.
|
|
11049
|
+
*/
|
|
11050
|
+
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
11051
|
+
// Note: The Node code supports `base` as a string (in this internal API) too,
|
|
11052
|
+
// we don’t.
|
|
11053
|
+
const protocol = base.protocol;
|
|
11054
|
+
const isData = protocol === 'data:';
|
|
11055
|
+
const isRemote = isData || protocol === 'http:' || protocol === 'https:';
|
|
11056
|
+
// Order swapped from spec for minor perf gain.
|
|
11057
|
+
// Ok since relative URLs cannot parse as URLs.
|
|
11058
|
+
/** @type {URL | undefined} */
|
|
11059
|
+
let resolved;
|
|
11060
|
+
|
|
11061
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
11062
|
+
try {
|
|
11063
|
+
resolved = new URL$2(specifier, base);
|
|
11064
|
+
} catch (error_) {
|
|
11065
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
11066
|
+
error.cause = error_;
|
|
11067
|
+
throw error
|
|
11068
|
+
}
|
|
11069
|
+
} else if (protocol === 'file:' && specifier[0] === '#') {
|
|
11070
|
+
resolved = packageImportsResolve(specifier, base, conditions);
|
|
11071
|
+
} else {
|
|
11072
|
+
try {
|
|
11073
|
+
resolved = new URL$2(specifier);
|
|
11074
|
+
} catch (error_) {
|
|
11075
|
+
// Note: actual code uses `canBeRequiredWithoutScheme`.
|
|
11076
|
+
if (isRemote && !builtinModules.includes(specifier)) {
|
|
11077
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
11078
|
+
error.cause = error_;
|
|
11079
|
+
throw error
|
|
11080
|
+
}
|
|
11081
|
+
|
|
11082
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
11083
|
+
}
|
|
11084
|
+
}
|
|
11085
|
+
|
|
11086
|
+
assert(resolved !== undefined, 'expected to be defined');
|
|
11087
|
+
|
|
11088
|
+
if (resolved.protocol !== 'file:') {
|
|
11089
|
+
return resolved
|
|
11090
|
+
}
|
|
11091
|
+
|
|
11092
|
+
return finalizeResolution(resolved, base)
|
|
11093
|
+
}
|
|
11094
|
+
|
|
11095
|
+
function fileURLToPath(id) {
|
|
11096
|
+
if (typeof id === "string" && !id.startsWith("file://")) {
|
|
11097
|
+
return normalizeSlash(id);
|
|
11098
|
+
}
|
|
11099
|
+
return normalizeSlash(fileURLToPath$1(id));
|
|
11100
|
+
}
|
|
11101
|
+
function pathToFileURL(id) {
|
|
11102
|
+
return pathToFileURL$1(fileURLToPath(id)).toString();
|
|
11103
|
+
}
|
|
11104
|
+
function normalizeid(id) {
|
|
11105
|
+
if (typeof id !== "string") {
|
|
11106
|
+
id = id.toString();
|
|
11107
|
+
}
|
|
11108
|
+
if (/(node|data|http|https|file):/.test(id)) {
|
|
11109
|
+
return id;
|
|
11110
|
+
}
|
|
11111
|
+
if (BUILTIN_MODULES.has(id)) {
|
|
11112
|
+
return "node:" + id;
|
|
11113
|
+
}
|
|
11114
|
+
return "file://" + encodeURI(normalizeSlash(id));
|
|
11115
|
+
}
|
|
11116
|
+
|
|
11117
|
+
const DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
|
|
11118
|
+
const DEFAULT_EXTENSIONS = [".mjs", ".cjs", ".js", ".json"];
|
|
11119
|
+
const NOT_FOUND_ERRORS = /* @__PURE__ */ new Set([
|
|
11120
|
+
"ERR_MODULE_NOT_FOUND",
|
|
11121
|
+
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
11122
|
+
"MODULE_NOT_FOUND",
|
|
11123
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED"
|
|
11124
|
+
]);
|
|
11125
|
+
function _tryModuleResolve(id, url, conditions) {
|
|
11126
|
+
try {
|
|
11127
|
+
return moduleResolve(id, url, conditions);
|
|
11128
|
+
} catch (error) {
|
|
11129
|
+
if (!NOT_FOUND_ERRORS.has(error?.code)) {
|
|
11130
|
+
throw error;
|
|
11131
|
+
}
|
|
11132
|
+
}
|
|
11133
|
+
}
|
|
11134
|
+
function _resolve$1(id, options = {}) {
|
|
11135
|
+
if (typeof id !== "string") {
|
|
11136
|
+
if (id instanceof URL) {
|
|
11137
|
+
id = fileURLToPath(id);
|
|
11138
|
+
} else {
|
|
11139
|
+
throw new TypeError("input must be a `string` or `URL`");
|
|
11140
|
+
}
|
|
11141
|
+
}
|
|
11142
|
+
if (/(node|data|http|https):/.test(id)) {
|
|
11143
|
+
return id;
|
|
11144
|
+
}
|
|
11145
|
+
if (BUILTIN_MODULES.has(id)) {
|
|
11146
|
+
return "node:" + id;
|
|
11147
|
+
}
|
|
11148
|
+
if (id.startsWith("file://")) {
|
|
11149
|
+
id = fileURLToPath(id);
|
|
11150
|
+
}
|
|
11151
|
+
if (isAbsolute(id)) {
|
|
11152
|
+
try {
|
|
11153
|
+
const stat = statSync$1(id);
|
|
11154
|
+
if (stat.isFile()) {
|
|
11155
|
+
return pathToFileURL(id);
|
|
11156
|
+
}
|
|
11157
|
+
} catch (error) {
|
|
11158
|
+
if (error?.code !== "ENOENT") {
|
|
11159
|
+
throw error;
|
|
11160
|
+
}
|
|
11161
|
+
}
|
|
11162
|
+
}
|
|
11163
|
+
const conditionsSet = options.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
|
|
11164
|
+
const _urls = (Array.isArray(options.url) ? options.url : [options.url]).filter(Boolean).map((url) => new URL(normalizeid(url.toString())));
|
|
11165
|
+
if (_urls.length === 0) {
|
|
11166
|
+
_urls.push(new URL(pathToFileURL(process.cwd())));
|
|
11167
|
+
}
|
|
11168
|
+
const urls = [..._urls];
|
|
11169
|
+
for (const url of _urls) {
|
|
11170
|
+
if (url.protocol === "file:") {
|
|
11171
|
+
urls.push(
|
|
11172
|
+
new URL("./", url),
|
|
11173
|
+
// If url is directory
|
|
11174
|
+
new URL(joinURL(url.pathname, "_index.js"), url),
|
|
11175
|
+
// TODO: Remove in next major version?
|
|
11176
|
+
new URL("node_modules", url)
|
|
11177
|
+
);
|
|
11178
|
+
}
|
|
11179
|
+
}
|
|
11180
|
+
let resolved;
|
|
11181
|
+
for (const url of urls) {
|
|
11182
|
+
resolved = _tryModuleResolve(id, url, conditionsSet);
|
|
11183
|
+
if (resolved) {
|
|
11184
|
+
break;
|
|
11185
|
+
}
|
|
11186
|
+
for (const prefix of ["", "/index"]) {
|
|
11187
|
+
for (const extension of options.extensions || DEFAULT_EXTENSIONS) {
|
|
11188
|
+
resolved = _tryModuleResolve(
|
|
11189
|
+
id + prefix + extension,
|
|
11190
|
+
url,
|
|
11191
|
+
conditionsSet
|
|
11192
|
+
);
|
|
11193
|
+
if (resolved) {
|
|
11194
|
+
break;
|
|
11195
|
+
}
|
|
11196
|
+
}
|
|
11197
|
+
if (resolved) {
|
|
11198
|
+
break;
|
|
11199
|
+
}
|
|
11200
|
+
}
|
|
11201
|
+
if (resolved) {
|
|
11202
|
+
break;
|
|
11203
|
+
}
|
|
11204
|
+
}
|
|
11205
|
+
if (!resolved) {
|
|
11206
|
+
const error = new Error(
|
|
11207
|
+
`Cannot find module ${id} imported from ${urls.join(", ")}`
|
|
11208
|
+
);
|
|
11209
|
+
error.code = "ERR_MODULE_NOT_FOUND";
|
|
11210
|
+
throw error;
|
|
11211
|
+
}
|
|
11212
|
+
return pathToFileURL(resolved);
|
|
11213
|
+
}
|
|
11214
|
+
function resolveSync(id, options) {
|
|
11215
|
+
return _resolve$1(id, options);
|
|
11216
|
+
}
|
|
11217
|
+
function resolvePathSync(id, options) {
|
|
11218
|
+
return fileURLToPath(resolveSync(id, options));
|
|
11219
|
+
}
|
|
11220
|
+
|
|
11221
|
+
function _resolve(path, options = {}) {
|
|
11222
|
+
if (options.platform === "auto" || !options.platform)
|
|
11223
|
+
options.platform = process$1.platform === "win32" ? "win32" : "posix";
|
|
11224
|
+
const modulePath = resolvePathSync(path, {
|
|
11225
|
+
url: options.paths
|
|
11226
|
+
});
|
|
11227
|
+
if (options.platform === "win32")
|
|
11228
|
+
return win32.normalize(modulePath);
|
|
11229
|
+
return modulePath;
|
|
11230
|
+
}
|
|
11231
|
+
function resolveModule(name, options = {}) {
|
|
11232
|
+
try {
|
|
11233
|
+
return _resolve(name, options);
|
|
11234
|
+
} catch (e) {
|
|
11235
|
+
return void 0;
|
|
11236
|
+
}
|
|
11237
|
+
}
|
|
11238
|
+
function isPackageExists(name, options = {}) {
|
|
11239
|
+
return !!resolvePackage(name, options);
|
|
11240
|
+
}
|
|
11241
|
+
function resolvePackage(name, options = {}) {
|
|
11242
|
+
try {
|
|
11243
|
+
return _resolve(`${name}/package.json`, options);
|
|
11244
|
+
} catch {
|
|
11245
|
+
}
|
|
11246
|
+
try {
|
|
11247
|
+
return _resolve(name, options);
|
|
11248
|
+
} catch (e) {
|
|
11249
|
+
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "ERR_MODULE_NOT_FOUND")
|
|
11250
|
+
console.error(e);
|
|
11251
|
+
return false;
|
|
11252
|
+
}
|
|
11253
|
+
}
|
|
11254
|
+
|
|
11255
|
+
var _a, _b;
|
|
11256
|
+
const defaultInclude = ["**/*.{test,spec}.?(c|m)[jt]s?(x)"];
|
|
11257
|
+
const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**", "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*"];
|
|
11258
|
+
const benchmarkConfigDefaults = {
|
|
11259
|
+
include: ["**/*.{bench,benchmark}.?(c|m)[jt]s?(x)"],
|
|
11260
|
+
exclude: defaultExclude,
|
|
11261
|
+
includeSource: [],
|
|
11262
|
+
reporters: ["default"]
|
|
11263
|
+
};
|
|
11264
|
+
const defaultCoverageExcludes = [
|
|
11265
|
+
"coverage/**",
|
|
11266
|
+
"dist/**",
|
|
11267
|
+
"**/[.]**",
|
|
11268
|
+
"packages/*/test?(s)/**",
|
|
11269
|
+
"**/*.d.ts",
|
|
11270
|
+
"**/virtual:*",
|
|
11271
|
+
"**/__x00__*",
|
|
11272
|
+
"**/\0*",
|
|
11273
|
+
"cypress/**",
|
|
11274
|
+
"test?(s)/**",
|
|
11275
|
+
"test?(-*).?(c|m)[jt]s?(x)",
|
|
11276
|
+
"**/*{.,-}{test,spec}?(-d).?(c|m)[jt]s?(x)",
|
|
11277
|
+
"**/__tests__/**",
|
|
11278
|
+
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*",
|
|
11279
|
+
"**/vitest.{workspace,projects}.[jt]s?(on)",
|
|
11280
|
+
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}"
|
|
11281
|
+
];
|
|
11282
|
+
const coverageConfigDefaults = {
|
|
11283
|
+
provider: "v8",
|
|
11284
|
+
enabled: false,
|
|
11285
|
+
all: true,
|
|
11286
|
+
clean: true,
|
|
11287
|
+
cleanOnRerun: true,
|
|
11288
|
+
reportsDirectory: "./coverage",
|
|
11289
|
+
exclude: defaultCoverageExcludes,
|
|
11290
|
+
reportOnFailure: false,
|
|
11291
|
+
reporter: [["text", {}], ["html", {}], ["clover", {}], ["json", {}]],
|
|
11292
|
+
extension: [".js", ".cjs", ".mjs", ".ts", ".mts", ".cts", ".tsx", ".jsx", ".vue", ".svelte", ".marko"],
|
|
11293
|
+
allowExternal: false,
|
|
11294
|
+
ignoreEmptyLines: true,
|
|
11295
|
+
processingConcurrency: Math.min(20, ((_b = (_a = nodeos__default).availableParallelism) == null ? void 0 : _b.call(_a)) ?? nodeos__default.cpus().length)
|
|
11296
|
+
};
|
|
11297
|
+
const fakeTimersDefaults = {
|
|
11298
|
+
loopLimit: 1e4,
|
|
11299
|
+
shouldClearNativeTimers: true,
|
|
11300
|
+
toFake: [
|
|
11301
|
+
"setTimeout",
|
|
11302
|
+
"clearTimeout",
|
|
11303
|
+
"setInterval",
|
|
11304
|
+
"clearInterval",
|
|
11305
|
+
"setImmediate",
|
|
11306
|
+
"clearImmediate",
|
|
11307
|
+
"Date"
|
|
11308
|
+
]
|
|
11309
|
+
};
|
|
11310
|
+
const config = {
|
|
11311
|
+
allowOnly: !isCI,
|
|
11312
|
+
isolate: true,
|
|
11313
|
+
watch: !isCI,
|
|
11314
|
+
globals: false,
|
|
11315
|
+
environment: "node",
|
|
11316
|
+
pool: "threads",
|
|
11317
|
+
clearMocks: false,
|
|
11318
|
+
restoreMocks: false,
|
|
11319
|
+
mockReset: false,
|
|
11320
|
+
include: defaultInclude,
|
|
11321
|
+
exclude: defaultExclude,
|
|
11322
|
+
testTimeout: 5e3,
|
|
11323
|
+
hookTimeout: 1e4,
|
|
11324
|
+
teardownTimeout: 1e4,
|
|
11325
|
+
forceRerunTriggers: [
|
|
11326
|
+
"**/package.json/**",
|
|
11327
|
+
"**/{vitest,vite}.config.*/**"
|
|
11328
|
+
],
|
|
11329
|
+
update: false,
|
|
11330
|
+
reporters: [],
|
|
11331
|
+
silent: false,
|
|
11332
|
+
hideSkippedTests: false,
|
|
11333
|
+
api: false,
|
|
11334
|
+
ui: false,
|
|
11335
|
+
uiBase: "/__vitest__/",
|
|
11336
|
+
open: !isCI,
|
|
11337
|
+
css: {
|
|
11338
|
+
include: []
|
|
11339
|
+
},
|
|
11340
|
+
coverage: coverageConfigDefaults,
|
|
11341
|
+
fakeTimers: fakeTimersDefaults,
|
|
11342
|
+
maxConcurrency: 5,
|
|
11343
|
+
dangerouslyIgnoreUnhandledErrors: false,
|
|
11344
|
+
typecheck: {
|
|
11345
|
+
checker: "tsc",
|
|
11346
|
+
include: ["**/*.{test,spec}-d.?(c|m)[jt]s?(x)"],
|
|
11347
|
+
exclude: defaultExclude
|
|
11348
|
+
},
|
|
11349
|
+
slowTestThreshold: 300,
|
|
9175
11350
|
disableConsoleIntercept: false
|
|
9176
11351
|
};
|
|
9177
11352
|
const configDefaults = Object.freeze(config);
|
|
@@ -9206,8 +11381,11 @@ class ResultsCache {
|
|
|
9206
11381
|
cache = /* @__PURE__ */ new Map();
|
|
9207
11382
|
workspacesKeyMap = /* @__PURE__ */ new Map();
|
|
9208
11383
|
cachePath = null;
|
|
9209
|
-
version
|
|
11384
|
+
version;
|
|
9210
11385
|
root = "/";
|
|
11386
|
+
constructor(version) {
|
|
11387
|
+
this.version = version;
|
|
11388
|
+
}
|
|
9211
11389
|
getCachePath() {
|
|
9212
11390
|
return this.cachePath;
|
|
9213
11391
|
}
|
|
@@ -9225,10 +11403,10 @@ class ResultsCache {
|
|
|
9225
11403
|
if (!fs$8.existsSync(this.cachePath))
|
|
9226
11404
|
return;
|
|
9227
11405
|
const resultsCache = await fs$8.promises.readFile(this.cachePath, "utf8");
|
|
9228
|
-
const { results, version
|
|
9229
|
-
if (Number(
|
|
11406
|
+
const { results, version } = JSON.parse(resultsCache || "[]");
|
|
11407
|
+
if (Number(version.split(".")[1]) >= 30) {
|
|
9230
11408
|
this.cache = new Map(results);
|
|
9231
|
-
this.version =
|
|
11409
|
+
this.version = version;
|
|
9232
11410
|
results.forEach(([spec]) => {
|
|
9233
11411
|
const [projectName, relativePath] = spec.split(":");
|
|
9234
11412
|
const keyMap = this.workspacesKeyMap.get(relativePath) || [];
|
|
@@ -9272,8 +11450,11 @@ class ResultsCache {
|
|
|
9272
11450
|
}
|
|
9273
11451
|
|
|
9274
11452
|
class VitestCache {
|
|
9275
|
-
results
|
|
11453
|
+
results;
|
|
9276
11454
|
stats = new FilesStatsCache();
|
|
11455
|
+
constructor(version) {
|
|
11456
|
+
this.results = new ResultsCache(version);
|
|
11457
|
+
}
|
|
9277
11458
|
getFileTestResults(key) {
|
|
9278
11459
|
return this.results.getResults(key);
|
|
9279
11460
|
}
|
|
@@ -9288,7 +11469,7 @@ class VitestCache {
|
|
|
9288
11469
|
|
|
9289
11470
|
function resolvePath(path, root) {
|
|
9290
11471
|
return normalize(
|
|
9291
|
-
resolveModule(path, { paths: [root] }) ?? resolve(root, path)
|
|
11472
|
+
/* @__PURE__ */ resolveModule(path, { paths: [root] }) ?? resolve(root, path)
|
|
9292
11473
|
);
|
|
9293
11474
|
}
|
|
9294
11475
|
function parseInspector(inspect) {
|
|
@@ -9644,7 +11825,7 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
9644
11825
|
if (!((_F = resolved.sequence) == null ? void 0 : _F.sequencer)) {
|
|
9645
11826
|
resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
|
|
9646
11827
|
}
|
|
9647
|
-
(_G = resolved.sequence).hooks ?? (_G.hooks = "
|
|
11828
|
+
(_G = resolved.sequence).hooks ?? (_G.hooks = "stack");
|
|
9648
11829
|
if (resolved.sequence.sequencer === RandomSequencer)
|
|
9649
11830
|
(_H = resolved.sequence).seed ?? (_H.seed = Date.now());
|
|
9650
11831
|
resolved.typecheck = {
|
|
@@ -9720,7 +11901,7 @@ function getBetterEnd(code, node) {
|
|
|
9720
11901
|
end += 1;
|
|
9721
11902
|
return end;
|
|
9722
11903
|
}
|
|
9723
|
-
const regexpHoistable = /\b(vi|vitest)\s*\.\s*(mock|unmock|hoisted)\(/;
|
|
11904
|
+
const regexpHoistable = /\b(vi|vitest)\s*\.\s*(mock|unmock|hoisted|doMock|doUnmock)\(/;
|
|
9724
11905
|
const hashbangRE = /^#!.*\n/;
|
|
9725
11906
|
function hoistMocks(code, id, parse, colors) {
|
|
9726
11907
|
var _a;
|
|
@@ -9795,7 +11976,7 @@ ${err.message}`);
|
|
|
9795
11976
|
name: "SyntaxError",
|
|
9796
11977
|
message: _error.message,
|
|
9797
11978
|
stack: _error.stack,
|
|
9798
|
-
frame: generateCodeFrame(highlightCode(id, code
|
|
11979
|
+
frame: generateCodeFrame(highlightCode(id, code), 4, node.start + 1)
|
|
9799
11980
|
};
|
|
9800
11981
|
}
|
|
9801
11982
|
function assertNotDefaultExport(node, error) {
|
|
@@ -9850,6 +12031,21 @@ ${err.message}`);
|
|
|
9850
12031
|
assertNotNamedExport(declarationNode, `Cannot export the result of "${method}". Remove export declaration because "${method}" doesn't return anything.`);
|
|
9851
12032
|
hoistedNodes.push(node);
|
|
9852
12033
|
}
|
|
12034
|
+
if (methodName === "doMock" || methodName === "doUnmock") {
|
|
12035
|
+
const moduleInfo = node.arguments[0];
|
|
12036
|
+
let source = null;
|
|
12037
|
+
if (moduleInfo.type === "ImportExpression")
|
|
12038
|
+
source = moduleInfo.source;
|
|
12039
|
+
if (moduleInfo.type === "AwaitExpression" && moduleInfo.argument.type === "ImportExpression")
|
|
12040
|
+
source = moduleInfo.argument.source;
|
|
12041
|
+
if (source) {
|
|
12042
|
+
s.overwrite(
|
|
12043
|
+
moduleInfo.start,
|
|
12044
|
+
moduleInfo.end,
|
|
12045
|
+
s.slice(source.start, source.end)
|
|
12046
|
+
);
|
|
12047
|
+
}
|
|
12048
|
+
}
|
|
9853
12049
|
if (methodName === "hoisted") {
|
|
9854
12050
|
assertNotDefaultExport(node, "Cannot export hoisted variable. You can control hoisting behavior by placing the import from this file first.");
|
|
9855
12051
|
const declarationNode = getVariableDeclaration(node);
|
|
@@ -9894,6 +12090,13 @@ ${err.message}`);
|
|
|
9894
12090
|
`Cannot call ${getNodeName(insideCall)} inside ${getNodeName(outsideCall)}: both methods are hoisted to the top of the file and not actually called inside each other.`
|
|
9895
12091
|
);
|
|
9896
12092
|
}
|
|
12093
|
+
function rewriteMockDynamicImport(nodeCode, moduleInfo, expressionStart, expressionEnd, mockStart) {
|
|
12094
|
+
const source = moduleInfo.source;
|
|
12095
|
+
const importPath = s.slice(source.start, source.end);
|
|
12096
|
+
const nodeCodeStart = expressionStart - mockStart;
|
|
12097
|
+
const nodeCodeEnd = expressionEnd - mockStart;
|
|
12098
|
+
return nodeCode.slice(0, nodeCodeStart) + importPath + nodeCode.slice(nodeCodeEnd);
|
|
12099
|
+
}
|
|
9897
12100
|
for (let i = 0; i < hoistedNodes.length; i++) {
|
|
9898
12101
|
const node = hoistedNodes[i];
|
|
9899
12102
|
for (let j = i + 1; j < hoistedNodes.length; j++) {
|
|
@@ -9906,7 +12109,28 @@ ${err.message}`);
|
|
|
9906
12109
|
}
|
|
9907
12110
|
const hoistedCode = hoistedNodes.map((node) => {
|
|
9908
12111
|
const end = getBetterEnd(code, node);
|
|
9909
|
-
|
|
12112
|
+
let nodeCode = s.slice(node.start, end);
|
|
12113
|
+
if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && (node.callee.property.name === "mock" || node.callee.property.name === "unmock")) {
|
|
12114
|
+
const moduleInfo = node.arguments[0];
|
|
12115
|
+
if (moduleInfo.type === "ImportExpression") {
|
|
12116
|
+
nodeCode = rewriteMockDynamicImport(
|
|
12117
|
+
nodeCode,
|
|
12118
|
+
moduleInfo,
|
|
12119
|
+
moduleInfo.start,
|
|
12120
|
+
moduleInfo.end,
|
|
12121
|
+
node.start
|
|
12122
|
+
);
|
|
12123
|
+
}
|
|
12124
|
+
if (moduleInfo.type === "AwaitExpression" && moduleInfo.argument.type === "ImportExpression") {
|
|
12125
|
+
nodeCode = rewriteMockDynamicImport(
|
|
12126
|
+
nodeCode,
|
|
12127
|
+
moduleInfo.argument,
|
|
12128
|
+
moduleInfo.start,
|
|
12129
|
+
moduleInfo.end,
|
|
12130
|
+
node.start
|
|
12131
|
+
);
|
|
12132
|
+
}
|
|
12133
|
+
}
|
|
9910
12134
|
s.remove(node.start, end);
|
|
9911
12135
|
return `${nodeCode}${nodeCode.endsWith("\n") ? "" : "\n"}`;
|
|
9912
12136
|
}).join("");
|
|
@@ -9936,10 +12160,10 @@ function resolveOptimizerConfig(_testOptions, viteOptions, testConfig) {
|
|
|
9936
12160
|
var _a;
|
|
9937
12161
|
const testOptions = _testOptions || {};
|
|
9938
12162
|
const newConfig = {};
|
|
9939
|
-
const [major, minor, fix] = version
|
|
12163
|
+
const [major, minor, fix] = version.split(".").map(Number);
|
|
9940
12164
|
const allowed = major >= 5 || major === 4 && minor >= 4 || major === 4 && minor === 3 && fix >= 2;
|
|
9941
12165
|
if (!allowed && (testOptions == null ? void 0 : testOptions.enabled) === true)
|
|
9942
|
-
console.warn(`Vitest: "deps.optimizer" is only available in Vite >= 4.3.2, current Vite version: ${version
|
|
12166
|
+
console.warn(`Vitest: "deps.optimizer" is only available in Vite >= 4.3.2, current Vite version: ${version}`);
|
|
9943
12167
|
else
|
|
9944
12168
|
testOptions.enabled ?? (testOptions.enabled = false);
|
|
9945
12169
|
if (!allowed || (testOptions == null ? void 0 : testOptions.enabled) !== true) {
|
|
@@ -10185,6 +12409,481 @@ function CSSEnablerPlugin(ctx) {
|
|
|
10185
12409
|
];
|
|
10186
12410
|
}
|
|
10187
12411
|
|
|
12412
|
+
// Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
|
|
12413
|
+
// License: MIT.
|
|
12414
|
+
var HashbangComment, Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
|
|
12415
|
+
RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:[^\]\\\n\r\u2028\u2029]+|\\.)*\]|[^\/\\\n\r\u2028\u2029]+|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
|
|
12416
|
+
Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
|
|
12417
|
+
Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]+|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
|
|
12418
|
+
StringLiteral = /(['"])(?:[^'"\\\n\r]+|(?!\1)['"]|\\(?:\r\n|[^]))*(\1)?/y;
|
|
12419
|
+
NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
|
|
12420
|
+
Template = /[`}](?:[^`\\$]+|\\[^]|\$(?!\{))*(`|\$\{)?/y;
|
|
12421
|
+
WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
|
|
12422
|
+
LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
|
|
12423
|
+
MultiLineComment = /\/\*(?:[^*]+|\*(?!\/))*(\*\/)?/y;
|
|
12424
|
+
SingleLineComment = /\/\/.*/y;
|
|
12425
|
+
HashbangComment = /^#!.*/;
|
|
12426
|
+
JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
|
|
12427
|
+
JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
|
|
12428
|
+
JSXString = /(['"])(?:[^'"]+|(?!\1)['"])*(\1)?/y;
|
|
12429
|
+
JSXText = /[^<>{}]+/y;
|
|
12430
|
+
TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
|
|
12431
|
+
TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
|
|
12432
|
+
KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
|
|
12433
|
+
KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
|
|
12434
|
+
Newline = RegExp(LineTerminatorSequence.source);
|
|
12435
|
+
var jsTokens_1 = function*(input, {jsx = false} = {}) {
|
|
12436
|
+
var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
|
|
12437
|
+
({length} = input);
|
|
12438
|
+
lastIndex = 0;
|
|
12439
|
+
lastSignificantToken = "";
|
|
12440
|
+
stack = [
|
|
12441
|
+
{tag: "JS"}
|
|
12442
|
+
];
|
|
12443
|
+
braces = [];
|
|
12444
|
+
parenNesting = 0;
|
|
12445
|
+
postfixIncDec = false;
|
|
12446
|
+
if (match = HashbangComment.exec(input)) {
|
|
12447
|
+
yield ({
|
|
12448
|
+
type: "HashbangComment",
|
|
12449
|
+
value: match[0]
|
|
12450
|
+
});
|
|
12451
|
+
lastIndex = match[0].length;
|
|
12452
|
+
}
|
|
12453
|
+
while (lastIndex < length) {
|
|
12454
|
+
mode = stack[stack.length - 1];
|
|
12455
|
+
switch (mode.tag) {
|
|
12456
|
+
case "JS":
|
|
12457
|
+
case "JSNonExpressionParen":
|
|
12458
|
+
case "InterpolationInTemplate":
|
|
12459
|
+
case "InterpolationInJSX":
|
|
12460
|
+
if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
12461
|
+
RegularExpressionLiteral.lastIndex = lastIndex;
|
|
12462
|
+
if (match = RegularExpressionLiteral.exec(input)) {
|
|
12463
|
+
lastIndex = RegularExpressionLiteral.lastIndex;
|
|
12464
|
+
lastSignificantToken = match[0];
|
|
12465
|
+
postfixIncDec = true;
|
|
12466
|
+
yield ({
|
|
12467
|
+
type: "RegularExpressionLiteral",
|
|
12468
|
+
value: match[0],
|
|
12469
|
+
closed: match[1] !== void 0 && match[1] !== "\\"
|
|
12470
|
+
});
|
|
12471
|
+
continue;
|
|
12472
|
+
}
|
|
12473
|
+
}
|
|
12474
|
+
Punctuator.lastIndex = lastIndex;
|
|
12475
|
+
if (match = Punctuator.exec(input)) {
|
|
12476
|
+
punctuator = match[0];
|
|
12477
|
+
nextLastIndex = Punctuator.lastIndex;
|
|
12478
|
+
nextLastSignificantToken = punctuator;
|
|
12479
|
+
switch (punctuator) {
|
|
12480
|
+
case "(":
|
|
12481
|
+
if (lastSignificantToken === "?NonExpressionParenKeyword") {
|
|
12482
|
+
stack.push({
|
|
12483
|
+
tag: "JSNonExpressionParen",
|
|
12484
|
+
nesting: parenNesting
|
|
12485
|
+
});
|
|
12486
|
+
}
|
|
12487
|
+
parenNesting++;
|
|
12488
|
+
postfixIncDec = false;
|
|
12489
|
+
break;
|
|
12490
|
+
case ")":
|
|
12491
|
+
parenNesting--;
|
|
12492
|
+
postfixIncDec = true;
|
|
12493
|
+
if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
|
|
12494
|
+
stack.pop();
|
|
12495
|
+
nextLastSignificantToken = "?NonExpressionParenEnd";
|
|
12496
|
+
postfixIncDec = false;
|
|
12497
|
+
}
|
|
12498
|
+
break;
|
|
12499
|
+
case "{":
|
|
12500
|
+
Punctuator.lastIndex = 0;
|
|
12501
|
+
isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
|
|
12502
|
+
braces.push(isExpression);
|
|
12503
|
+
postfixIncDec = false;
|
|
12504
|
+
break;
|
|
12505
|
+
case "}":
|
|
12506
|
+
switch (mode.tag) {
|
|
12507
|
+
case "InterpolationInTemplate":
|
|
12508
|
+
if (braces.length === mode.nesting) {
|
|
12509
|
+
Template.lastIndex = lastIndex;
|
|
12510
|
+
match = Template.exec(input);
|
|
12511
|
+
lastIndex = Template.lastIndex;
|
|
12512
|
+
lastSignificantToken = match[0];
|
|
12513
|
+
if (match[1] === "${") {
|
|
12514
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
|
12515
|
+
postfixIncDec = false;
|
|
12516
|
+
yield ({
|
|
12517
|
+
type: "TemplateMiddle",
|
|
12518
|
+
value: match[0]
|
|
12519
|
+
});
|
|
12520
|
+
} else {
|
|
12521
|
+
stack.pop();
|
|
12522
|
+
postfixIncDec = true;
|
|
12523
|
+
yield ({
|
|
12524
|
+
type: "TemplateTail",
|
|
12525
|
+
value: match[0],
|
|
12526
|
+
closed: match[1] === "`"
|
|
12527
|
+
});
|
|
12528
|
+
}
|
|
12529
|
+
continue;
|
|
12530
|
+
}
|
|
12531
|
+
break;
|
|
12532
|
+
case "InterpolationInJSX":
|
|
12533
|
+
if (braces.length === mode.nesting) {
|
|
12534
|
+
stack.pop();
|
|
12535
|
+
lastIndex += 1;
|
|
12536
|
+
lastSignificantToken = "}";
|
|
12537
|
+
yield ({
|
|
12538
|
+
type: "JSXPunctuator",
|
|
12539
|
+
value: "}"
|
|
12540
|
+
});
|
|
12541
|
+
continue;
|
|
12542
|
+
}
|
|
12543
|
+
}
|
|
12544
|
+
postfixIncDec = braces.pop();
|
|
12545
|
+
nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
|
|
12546
|
+
break;
|
|
12547
|
+
case "]":
|
|
12548
|
+
postfixIncDec = true;
|
|
12549
|
+
break;
|
|
12550
|
+
case "++":
|
|
12551
|
+
case "--":
|
|
12552
|
+
nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
|
|
12553
|
+
break;
|
|
12554
|
+
case "<":
|
|
12555
|
+
if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
12556
|
+
stack.push({tag: "JSXTag"});
|
|
12557
|
+
lastIndex += 1;
|
|
12558
|
+
lastSignificantToken = "<";
|
|
12559
|
+
yield ({
|
|
12560
|
+
type: "JSXPunctuator",
|
|
12561
|
+
value: punctuator
|
|
12562
|
+
});
|
|
12563
|
+
continue;
|
|
12564
|
+
}
|
|
12565
|
+
postfixIncDec = false;
|
|
12566
|
+
break;
|
|
12567
|
+
default:
|
|
12568
|
+
postfixIncDec = false;
|
|
12569
|
+
}
|
|
12570
|
+
lastIndex = nextLastIndex;
|
|
12571
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
12572
|
+
yield ({
|
|
12573
|
+
type: "Punctuator",
|
|
12574
|
+
value: punctuator
|
|
12575
|
+
});
|
|
12576
|
+
continue;
|
|
12577
|
+
}
|
|
12578
|
+
Identifier.lastIndex = lastIndex;
|
|
12579
|
+
if (match = Identifier.exec(input)) {
|
|
12580
|
+
lastIndex = Identifier.lastIndex;
|
|
12581
|
+
nextLastSignificantToken = match[0];
|
|
12582
|
+
switch (match[0]) {
|
|
12583
|
+
case "for":
|
|
12584
|
+
case "if":
|
|
12585
|
+
case "while":
|
|
12586
|
+
case "with":
|
|
12587
|
+
if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
|
|
12588
|
+
nextLastSignificantToken = "?NonExpressionParenKeyword";
|
|
12589
|
+
}
|
|
12590
|
+
}
|
|
12591
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
12592
|
+
postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
|
|
12593
|
+
yield ({
|
|
12594
|
+
type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
|
|
12595
|
+
value: match[0]
|
|
12596
|
+
});
|
|
12597
|
+
continue;
|
|
12598
|
+
}
|
|
12599
|
+
StringLiteral.lastIndex = lastIndex;
|
|
12600
|
+
if (match = StringLiteral.exec(input)) {
|
|
12601
|
+
lastIndex = StringLiteral.lastIndex;
|
|
12602
|
+
lastSignificantToken = match[0];
|
|
12603
|
+
postfixIncDec = true;
|
|
12604
|
+
yield ({
|
|
12605
|
+
type: "StringLiteral",
|
|
12606
|
+
value: match[0],
|
|
12607
|
+
closed: match[2] !== void 0
|
|
12608
|
+
});
|
|
12609
|
+
continue;
|
|
12610
|
+
}
|
|
12611
|
+
NumericLiteral.lastIndex = lastIndex;
|
|
12612
|
+
if (match = NumericLiteral.exec(input)) {
|
|
12613
|
+
lastIndex = NumericLiteral.lastIndex;
|
|
12614
|
+
lastSignificantToken = match[0];
|
|
12615
|
+
postfixIncDec = true;
|
|
12616
|
+
yield ({
|
|
12617
|
+
type: "NumericLiteral",
|
|
12618
|
+
value: match[0]
|
|
12619
|
+
});
|
|
12620
|
+
continue;
|
|
12621
|
+
}
|
|
12622
|
+
Template.lastIndex = lastIndex;
|
|
12623
|
+
if (match = Template.exec(input)) {
|
|
12624
|
+
lastIndex = Template.lastIndex;
|
|
12625
|
+
lastSignificantToken = match[0];
|
|
12626
|
+
if (match[1] === "${") {
|
|
12627
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
|
12628
|
+
stack.push({
|
|
12629
|
+
tag: "InterpolationInTemplate",
|
|
12630
|
+
nesting: braces.length
|
|
12631
|
+
});
|
|
12632
|
+
postfixIncDec = false;
|
|
12633
|
+
yield ({
|
|
12634
|
+
type: "TemplateHead",
|
|
12635
|
+
value: match[0]
|
|
12636
|
+
});
|
|
12637
|
+
} else {
|
|
12638
|
+
postfixIncDec = true;
|
|
12639
|
+
yield ({
|
|
12640
|
+
type: "NoSubstitutionTemplate",
|
|
12641
|
+
value: match[0],
|
|
12642
|
+
closed: match[1] === "`"
|
|
12643
|
+
});
|
|
12644
|
+
}
|
|
12645
|
+
continue;
|
|
12646
|
+
}
|
|
12647
|
+
break;
|
|
12648
|
+
case "JSXTag":
|
|
12649
|
+
case "JSXTagEnd":
|
|
12650
|
+
JSXPunctuator.lastIndex = lastIndex;
|
|
12651
|
+
if (match = JSXPunctuator.exec(input)) {
|
|
12652
|
+
lastIndex = JSXPunctuator.lastIndex;
|
|
12653
|
+
nextLastSignificantToken = match[0];
|
|
12654
|
+
switch (match[0]) {
|
|
12655
|
+
case "<":
|
|
12656
|
+
stack.push({tag: "JSXTag"});
|
|
12657
|
+
break;
|
|
12658
|
+
case ">":
|
|
12659
|
+
stack.pop();
|
|
12660
|
+
if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
|
|
12661
|
+
nextLastSignificantToken = "?JSX";
|
|
12662
|
+
postfixIncDec = true;
|
|
12663
|
+
} else {
|
|
12664
|
+
stack.push({tag: "JSXChildren"});
|
|
12665
|
+
}
|
|
12666
|
+
break;
|
|
12667
|
+
case "{":
|
|
12668
|
+
stack.push({
|
|
12669
|
+
tag: "InterpolationInJSX",
|
|
12670
|
+
nesting: braces.length
|
|
12671
|
+
});
|
|
12672
|
+
nextLastSignificantToken = "?InterpolationInJSX";
|
|
12673
|
+
postfixIncDec = false;
|
|
12674
|
+
break;
|
|
12675
|
+
case "/":
|
|
12676
|
+
if (lastSignificantToken === "<") {
|
|
12677
|
+
stack.pop();
|
|
12678
|
+
if (stack[stack.length - 1].tag === "JSXChildren") {
|
|
12679
|
+
stack.pop();
|
|
12680
|
+
}
|
|
12681
|
+
stack.push({tag: "JSXTagEnd"});
|
|
12682
|
+
}
|
|
12683
|
+
}
|
|
12684
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
12685
|
+
yield ({
|
|
12686
|
+
type: "JSXPunctuator",
|
|
12687
|
+
value: match[0]
|
|
12688
|
+
});
|
|
12689
|
+
continue;
|
|
12690
|
+
}
|
|
12691
|
+
JSXIdentifier.lastIndex = lastIndex;
|
|
12692
|
+
if (match = JSXIdentifier.exec(input)) {
|
|
12693
|
+
lastIndex = JSXIdentifier.lastIndex;
|
|
12694
|
+
lastSignificantToken = match[0];
|
|
12695
|
+
yield ({
|
|
12696
|
+
type: "JSXIdentifier",
|
|
12697
|
+
value: match[0]
|
|
12698
|
+
});
|
|
12699
|
+
continue;
|
|
12700
|
+
}
|
|
12701
|
+
JSXString.lastIndex = lastIndex;
|
|
12702
|
+
if (match = JSXString.exec(input)) {
|
|
12703
|
+
lastIndex = JSXString.lastIndex;
|
|
12704
|
+
lastSignificantToken = match[0];
|
|
12705
|
+
yield ({
|
|
12706
|
+
type: "JSXString",
|
|
12707
|
+
value: match[0],
|
|
12708
|
+
closed: match[2] !== void 0
|
|
12709
|
+
});
|
|
12710
|
+
continue;
|
|
12711
|
+
}
|
|
12712
|
+
break;
|
|
12713
|
+
case "JSXChildren":
|
|
12714
|
+
JSXText.lastIndex = lastIndex;
|
|
12715
|
+
if (match = JSXText.exec(input)) {
|
|
12716
|
+
lastIndex = JSXText.lastIndex;
|
|
12717
|
+
lastSignificantToken = match[0];
|
|
12718
|
+
yield ({
|
|
12719
|
+
type: "JSXText",
|
|
12720
|
+
value: match[0]
|
|
12721
|
+
});
|
|
12722
|
+
continue;
|
|
12723
|
+
}
|
|
12724
|
+
switch (input[lastIndex]) {
|
|
12725
|
+
case "<":
|
|
12726
|
+
stack.push({tag: "JSXTag"});
|
|
12727
|
+
lastIndex++;
|
|
12728
|
+
lastSignificantToken = "<";
|
|
12729
|
+
yield ({
|
|
12730
|
+
type: "JSXPunctuator",
|
|
12731
|
+
value: "<"
|
|
12732
|
+
});
|
|
12733
|
+
continue;
|
|
12734
|
+
case "{":
|
|
12735
|
+
stack.push({
|
|
12736
|
+
tag: "InterpolationInJSX",
|
|
12737
|
+
nesting: braces.length
|
|
12738
|
+
});
|
|
12739
|
+
lastIndex++;
|
|
12740
|
+
lastSignificantToken = "?InterpolationInJSX";
|
|
12741
|
+
postfixIncDec = false;
|
|
12742
|
+
yield ({
|
|
12743
|
+
type: "JSXPunctuator",
|
|
12744
|
+
value: "{"
|
|
12745
|
+
});
|
|
12746
|
+
continue;
|
|
12747
|
+
}
|
|
12748
|
+
}
|
|
12749
|
+
WhiteSpace.lastIndex = lastIndex;
|
|
12750
|
+
if (match = WhiteSpace.exec(input)) {
|
|
12751
|
+
lastIndex = WhiteSpace.lastIndex;
|
|
12752
|
+
yield ({
|
|
12753
|
+
type: "WhiteSpace",
|
|
12754
|
+
value: match[0]
|
|
12755
|
+
});
|
|
12756
|
+
continue;
|
|
12757
|
+
}
|
|
12758
|
+
LineTerminatorSequence.lastIndex = lastIndex;
|
|
12759
|
+
if (match = LineTerminatorSequence.exec(input)) {
|
|
12760
|
+
lastIndex = LineTerminatorSequence.lastIndex;
|
|
12761
|
+
postfixIncDec = false;
|
|
12762
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
12763
|
+
lastSignificantToken = "?NoLineTerminatorHere";
|
|
12764
|
+
}
|
|
12765
|
+
yield ({
|
|
12766
|
+
type: "LineTerminatorSequence",
|
|
12767
|
+
value: match[0]
|
|
12768
|
+
});
|
|
12769
|
+
continue;
|
|
12770
|
+
}
|
|
12771
|
+
MultiLineComment.lastIndex = lastIndex;
|
|
12772
|
+
if (match = MultiLineComment.exec(input)) {
|
|
12773
|
+
lastIndex = MultiLineComment.lastIndex;
|
|
12774
|
+
if (Newline.test(match[0])) {
|
|
12775
|
+
postfixIncDec = false;
|
|
12776
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
12777
|
+
lastSignificantToken = "?NoLineTerminatorHere";
|
|
12778
|
+
}
|
|
12779
|
+
}
|
|
12780
|
+
yield ({
|
|
12781
|
+
type: "MultiLineComment",
|
|
12782
|
+
value: match[0],
|
|
12783
|
+
closed: match[1] !== void 0
|
|
12784
|
+
});
|
|
12785
|
+
continue;
|
|
12786
|
+
}
|
|
12787
|
+
SingleLineComment.lastIndex = lastIndex;
|
|
12788
|
+
if (match = SingleLineComment.exec(input)) {
|
|
12789
|
+
lastIndex = SingleLineComment.lastIndex;
|
|
12790
|
+
postfixIncDec = false;
|
|
12791
|
+
yield ({
|
|
12792
|
+
type: "SingleLineComment",
|
|
12793
|
+
value: match[0]
|
|
12794
|
+
});
|
|
12795
|
+
continue;
|
|
12796
|
+
}
|
|
12797
|
+
firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
|
|
12798
|
+
lastIndex += firstCodePoint.length;
|
|
12799
|
+
lastSignificantToken = firstCodePoint;
|
|
12800
|
+
postfixIncDec = false;
|
|
12801
|
+
yield ({
|
|
12802
|
+
type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
|
|
12803
|
+
value: firstCodePoint
|
|
12804
|
+
});
|
|
12805
|
+
}
|
|
12806
|
+
return void 0;
|
|
12807
|
+
};
|
|
12808
|
+
|
|
12809
|
+
var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokens_1);
|
|
12810
|
+
|
|
12811
|
+
function stripLiteralJsTokens(code, options) {
|
|
12812
|
+
const FILL = " ";
|
|
12813
|
+
const FILL_COMMENT = " ";
|
|
12814
|
+
let result = "";
|
|
12815
|
+
const tokens = [];
|
|
12816
|
+
for (const token of jsTokens(code, { jsx: false })) {
|
|
12817
|
+
tokens.push(token);
|
|
12818
|
+
if (token.type === "SingleLineComment") {
|
|
12819
|
+
result += FILL_COMMENT.repeat(token.value.length);
|
|
12820
|
+
continue;
|
|
12821
|
+
}
|
|
12822
|
+
if (token.type === "MultiLineComment") {
|
|
12823
|
+
result += token.value.replace(/[^\n]/g, FILL_COMMENT);
|
|
12824
|
+
continue;
|
|
12825
|
+
}
|
|
12826
|
+
if (token.type === "StringLiteral") {
|
|
12827
|
+
if (!token.closed) {
|
|
12828
|
+
result += token.value;
|
|
12829
|
+
continue;
|
|
12830
|
+
}
|
|
12831
|
+
const body = token.value.slice(1, -1);
|
|
12832
|
+
{
|
|
12833
|
+
result += token.value[0] + FILL.repeat(body.length) + token.value[token.value.length - 1];
|
|
12834
|
+
continue;
|
|
12835
|
+
}
|
|
12836
|
+
}
|
|
12837
|
+
if (token.type === "NoSubstitutionTemplate") {
|
|
12838
|
+
const body = token.value.slice(1, -1);
|
|
12839
|
+
{
|
|
12840
|
+
result += `\`${body.replace(/[^\n]/g, FILL)}\``;
|
|
12841
|
+
continue;
|
|
12842
|
+
}
|
|
12843
|
+
}
|
|
12844
|
+
if (token.type === "RegularExpressionLiteral") {
|
|
12845
|
+
const body = token.value;
|
|
12846
|
+
{
|
|
12847
|
+
result += body.replace(/\/(.*)\/(\w?)$/g, (_, $1, $2) => `/${FILL.repeat($1.length)}/${$2}`);
|
|
12848
|
+
continue;
|
|
12849
|
+
}
|
|
12850
|
+
}
|
|
12851
|
+
if (token.type === "TemplateHead") {
|
|
12852
|
+
const body = token.value.slice(1, -2);
|
|
12853
|
+
{
|
|
12854
|
+
result += `\`${body.replace(/[^\n]/g, FILL)}\${`;
|
|
12855
|
+
continue;
|
|
12856
|
+
}
|
|
12857
|
+
}
|
|
12858
|
+
if (token.type === "TemplateTail") {
|
|
12859
|
+
const body = token.value.slice(0, -2);
|
|
12860
|
+
{
|
|
12861
|
+
result += `}${body.replace(/[^\n]/g, FILL)}\``;
|
|
12862
|
+
continue;
|
|
12863
|
+
}
|
|
12864
|
+
}
|
|
12865
|
+
if (token.type === "TemplateMiddle") {
|
|
12866
|
+
const body = token.value.slice(1, -2);
|
|
12867
|
+
{
|
|
12868
|
+
result += `}${body.replace(/[^\n]/g, FILL)}\${`;
|
|
12869
|
+
continue;
|
|
12870
|
+
}
|
|
12871
|
+
}
|
|
12872
|
+
result += token.value;
|
|
12873
|
+
}
|
|
12874
|
+
return {
|
|
12875
|
+
result,
|
|
12876
|
+
tokens
|
|
12877
|
+
};
|
|
12878
|
+
}
|
|
12879
|
+
|
|
12880
|
+
function stripLiteral(code, options) {
|
|
12881
|
+
return stripLiteralDetailed(code).result;
|
|
12882
|
+
}
|
|
12883
|
+
function stripLiteralDetailed(code, options) {
|
|
12884
|
+
return stripLiteralJsTokens(code);
|
|
12885
|
+
}
|
|
12886
|
+
|
|
10188
12887
|
function SsrReplacerPlugin() {
|
|
10189
12888
|
return {
|
|
10190
12889
|
name: "vitest:ssr-replacer",
|
|
@@ -10362,7 +13061,7 @@ function WorkspaceVitestPlugin(project, options) {
|
|
|
10362
13061
|
);
|
|
10363
13062
|
await project.setServer(options2, server);
|
|
10364
13063
|
} catch (err) {
|
|
10365
|
-
|
|
13064
|
+
project.ctx.logger.printError(err, { fullStack: true });
|
|
10366
13065
|
process.exit(1);
|
|
10367
13066
|
}
|
|
10368
13067
|
await server.watcher.close();
|
|
@@ -10501,7 +13200,7 @@ class WorkspaceProject {
|
|
|
10501
13200
|
} catch (e) {
|
|
10502
13201
|
this.logger.error(`
|
|
10503
13202
|
${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
10504
|
-
|
|
13203
|
+
this.logger.printError(e);
|
|
10505
13204
|
process.exit(1);
|
|
10506
13205
|
}
|
|
10507
13206
|
}
|
|
@@ -10514,7 +13213,7 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
10514
13213
|
await ((_a = globalSetupFile.teardown) == null ? void 0 : _a.call(globalSetupFile));
|
|
10515
13214
|
} catch (error) {
|
|
10516
13215
|
this.logger.error(`error during global teardown of ${globalSetupFile.file}`, error);
|
|
10517
|
-
|
|
13216
|
+
this.logger.printError(error);
|
|
10518
13217
|
process.exitCode = 1;
|
|
10519
13218
|
}
|
|
10520
13219
|
}
|
|
@@ -10772,7 +13471,7 @@ class VitestPackageInstaller {
|
|
|
10772
13471
|
} catch (error) {
|
|
10773
13472
|
}
|
|
10774
13473
|
}
|
|
10775
|
-
if (isPackageExists(dependency, { paths: [root, __dirname] }))
|
|
13474
|
+
if (/* @__PURE__ */ isPackageExists(dependency, { paths: [root, __dirname] }))
|
|
10776
13475
|
return true;
|
|
10777
13476
|
const promptInstall = !isCI && process.stdout.isTTY;
|
|
10778
13477
|
process.stderr.write(c.red(`${c.inverse(c.red(" MISSING DEPENDENCY "))} Cannot find dependency '${dependency}'
|
|
@@ -10787,7 +13486,7 @@ class VitestPackageInstaller {
|
|
|
10787
13486
|
message: c.reset(`Do you want to install ${c.green(dependency)}?`)
|
|
10788
13487
|
});
|
|
10789
13488
|
if (install) {
|
|
10790
|
-
await (await import('../chunks/install-pkg.
|
|
13489
|
+
await (await import('../chunks/install-pkg.DNUmWFkO.js')).installPackage(dependency, { dev: true });
|
|
10791
13490
|
process.stderr.write(c.yellow(`
|
|
10792
13491
|
Package ${dependency} installed, re-run the command to start.
|
|
10793
13492
|
`));
|
|
@@ -10805,6 +13504,7 @@ class Vitest {
|
|
|
10805
13504
|
this.logger = new Logger(this, options.stdout, options.stderr);
|
|
10806
13505
|
this.packageInstaller = options.packageInstaller || new VitestPackageInstaller();
|
|
10807
13506
|
}
|
|
13507
|
+
version = version$1;
|
|
10808
13508
|
config = void 0;
|
|
10809
13509
|
configOverride = {};
|
|
10810
13510
|
server = void 0;
|
|
@@ -10851,7 +13551,7 @@ class Vitest {
|
|
|
10851
13551
|
this.server = server;
|
|
10852
13552
|
this.config = resolved;
|
|
10853
13553
|
this.state = new StateManager();
|
|
10854
|
-
this.cache = new VitestCache();
|
|
13554
|
+
this.cache = new VitestCache(this.version);
|
|
10855
13555
|
this.snapshot = new SnapshotManager({ ...resolved.snapshotOptions });
|
|
10856
13556
|
if (this.config.watch)
|
|
10857
13557
|
this.registerWatcher();
|
|
@@ -11131,7 +13831,7 @@ class Vitest {
|
|
|
11131
13831
|
}
|
|
11132
13832
|
async filterTestsBySource(specs) {
|
|
11133
13833
|
if (this.config.changed && !this.config.related) {
|
|
11134
|
-
const { VitestGit } = await import('../chunks/node-git.
|
|
13834
|
+
const { VitestGit } = await import('../chunks/node-git.CCI8evVZ.js');
|
|
11135
13835
|
const vitestGit = new VitestGit(this.config.root);
|
|
11136
13836
|
const related2 = await vitestGit.findChangedFiles({
|
|
11137
13837
|
changedSince: this.config.changed
|
|
@@ -11394,7 +14094,6 @@ class Vitest {
|
|
|
11394
14094
|
const watcher = this.server.watcher;
|
|
11395
14095
|
if (this.config.forceRerunTriggers.length)
|
|
11396
14096
|
watcher.add(this.config.forceRerunTriggers);
|
|
11397
|
-
watcher.unwatch(this.config.watchExclude);
|
|
11398
14097
|
watcher.on("change", onChange);
|
|
11399
14098
|
watcher.on("unlink", onUnlink);
|
|
11400
14099
|
watcher.on("add", onAdd);
|
|
@@ -11608,9 +14307,6 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
11608
14307
|
},
|
|
11609
14308
|
server: {
|
|
11610
14309
|
...testConfig.api,
|
|
11611
|
-
watch: {
|
|
11612
|
-
ignored: testConfig.watchExclude
|
|
11613
|
-
},
|
|
11614
14310
|
open,
|
|
11615
14311
|
hmr: false,
|
|
11616
14312
|
preTransformRequests: false,
|
|
@@ -11652,8 +14348,11 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
11652
14348
|
}
|
|
11653
14349
|
}
|
|
11654
14350
|
if (process.platform === "darwin" && process.env.VITE_TEST_WATCHER_DEBUG) {
|
|
11655
|
-
config.server.watch
|
|
11656
|
-
|
|
14351
|
+
const watch = config.server.watch;
|
|
14352
|
+
if (watch) {
|
|
14353
|
+
watch.useFsEvents = false;
|
|
14354
|
+
watch.usePolling = false;
|
|
14355
|
+
}
|
|
11657
14356
|
}
|
|
11658
14357
|
const classNameStrategy = typeof testConfig.css !== "boolean" && ((_q = (_p = testConfig.css) == null ? void 0 : _p.modules) == null ? void 0 : _q.classNameStrategy) || "stable";
|
|
11659
14358
|
if (classNameStrategy !== "scoped") {
|
|
@@ -11702,7 +14401,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
11702
14401
|
if (options.api && options.watch)
|
|
11703
14402
|
(await Promise.resolve().then(function () { return setup$1; })).setup(ctx);
|
|
11704
14403
|
} catch (err) {
|
|
11705
|
-
|
|
14404
|
+
ctx.logger.printError(err, { fullStack: true });
|
|
11706
14405
|
process.exit(1);
|
|
11707
14406
|
}
|
|
11708
14407
|
if (!options.watch)
|
|
@@ -11987,7 +14686,7 @@ function requireClear$1 () {
|
|
|
11987
14686
|
if (hasRequiredClear$1) return clear$1;
|
|
11988
14687
|
hasRequiredClear$1 = 1;
|
|
11989
14688
|
|
|
11990
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike
|
|
14689
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike ) { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11991
14690
|
|
|
11992
14691
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11993
14692
|
|
|
@@ -14946,7 +17645,7 @@ function requireDist () {
|
|
|
14946
17645
|
|
|
14947
17646
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14948
17647
|
|
|
14949
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike
|
|
17648
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike ) { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
14950
17649
|
|
|
14951
17650
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14952
17651
|
|