vitest 0.0.92 → 0.0.96
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/bin/vitest.mjs +3 -0
- package/dist/cli.js +9 -7
- package/dist/entry.js +127 -8
- package/dist/{error-4b0c4b4b.js → error-81292c96.js} +11 -11
- package/dist/{global-c40aeb86.js → global-473089f7.js} +1 -1
- package/dist/{index-708135df.js → index-368448f4.js} +24 -5
- package/dist/{index-40ecbcb4.js → index-ece64e3c.js} +63 -39
- package/dist/index.d.ts +38 -10
- package/dist/index.js +2 -2
- package/dist/{middleware-b1884a99.js → middleware-bf0f818d.js} +1 -2
- package/dist/node.js +4 -4
- package/dist/{utils-860e5f7e.js → utils-576876dc.js} +4 -2
- package/dist/utils.js +1 -1
- package/dist/worker.js +1301 -338
- package/package.json +8 -8
package/dist/worker.js
CHANGED
|
@@ -1,211 +1,17 @@
|
|
|
1
|
-
import path, { resolve
|
|
1
|
+
import path, { resolve, dirname as dirname$2 } from 'path';
|
|
2
2
|
import { n as nanoid } from './index-9e71c815.js';
|
|
3
3
|
import { c as distDir } from './constants-9cfa4d7b.js';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
|
-
import { pathToFileURL, fileURLToPath, URL as URL$1 } from 'url';
|
|
5
|
+
import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
|
|
6
6
|
import vm from 'vm';
|
|
7
|
-
import {
|
|
8
|
-
import fs, { realpathSync, statSync, Stats, promises } from 'fs';
|
|
7
|
+
import fs, { promises, realpathSync, statSync, Stats } from 'fs';
|
|
9
8
|
import assert from 'assert';
|
|
10
|
-
import { format as format$
|
|
9
|
+
import { format as format$2, inspect } from 'util';
|
|
10
|
+
import { s as slash } from './utils-576876dc.js';
|
|
11
11
|
import { s as send } from './rpc-7de86f29.js';
|
|
12
12
|
import 'tty';
|
|
13
13
|
import 'local-pkg';
|
|
14
14
|
|
|
15
|
-
function normalizeWindowsPath$2(input = "") {
|
|
16
|
-
if (!input.includes("\\")) {
|
|
17
|
-
return input;
|
|
18
|
-
}
|
|
19
|
-
return input.replace(/\\/g, "/");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const _UNC_REGEX$2 = /^[/][/]/;
|
|
23
|
-
const _UNC_DRIVE_REGEX$2 = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
|
|
24
|
-
const _IS_ABSOLUTE_RE$2 = /^\/|^\\|^[a-zA-Z]:[/\\]/;
|
|
25
|
-
const sep$2 = "/";
|
|
26
|
-
const delimiter$2 = ":";
|
|
27
|
-
const normalize$2 = function(path2) {
|
|
28
|
-
if (path2.length === 0) {
|
|
29
|
-
return ".";
|
|
30
|
-
}
|
|
31
|
-
path2 = normalizeWindowsPath$2(path2);
|
|
32
|
-
const isUNCPath = path2.match(_UNC_REGEX$2);
|
|
33
|
-
const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX$2);
|
|
34
|
-
const isPathAbsolute = isAbsolute$2(path2);
|
|
35
|
-
const trailingSeparator = path2[path2.length - 1] === "/";
|
|
36
|
-
path2 = normalizeString$2(path2, !isPathAbsolute);
|
|
37
|
-
if (path2.length === 0) {
|
|
38
|
-
if (isPathAbsolute) {
|
|
39
|
-
return "/";
|
|
40
|
-
}
|
|
41
|
-
return trailingSeparator ? "./" : ".";
|
|
42
|
-
}
|
|
43
|
-
if (trailingSeparator) {
|
|
44
|
-
path2 += "/";
|
|
45
|
-
}
|
|
46
|
-
if (isUNCPath) {
|
|
47
|
-
if (hasUNCDrive) {
|
|
48
|
-
return `//./${path2}`;
|
|
49
|
-
}
|
|
50
|
-
return `//${path2}`;
|
|
51
|
-
}
|
|
52
|
-
return isPathAbsolute && !isAbsolute$2(path2) ? `/${path2}` : path2;
|
|
53
|
-
};
|
|
54
|
-
const join$2 = function(...args) {
|
|
55
|
-
if (args.length === 0) {
|
|
56
|
-
return ".";
|
|
57
|
-
}
|
|
58
|
-
let joined;
|
|
59
|
-
for (let i = 0; i < args.length; ++i) {
|
|
60
|
-
const arg = args[i];
|
|
61
|
-
if (arg.length > 0) {
|
|
62
|
-
if (joined === void 0) {
|
|
63
|
-
joined = arg;
|
|
64
|
-
} else {
|
|
65
|
-
joined += `/${arg}`;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (joined === void 0) {
|
|
70
|
-
return ".";
|
|
71
|
-
}
|
|
72
|
-
return normalize$2(joined);
|
|
73
|
-
};
|
|
74
|
-
const resolve = function(...args) {
|
|
75
|
-
args = args.map((arg) => normalizeWindowsPath$2(arg));
|
|
76
|
-
let resolvedPath = "";
|
|
77
|
-
let resolvedAbsolute = false;
|
|
78
|
-
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
79
|
-
const path2 = i >= 0 ? args[i] : process.cwd();
|
|
80
|
-
if (path2.length === 0) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
resolvedPath = `${path2}/${resolvedPath}`;
|
|
84
|
-
resolvedAbsolute = isAbsolute$2(path2);
|
|
85
|
-
}
|
|
86
|
-
resolvedPath = normalizeString$2(resolvedPath, !resolvedAbsolute);
|
|
87
|
-
if (resolvedAbsolute && !isAbsolute$2(resolvedPath)) {
|
|
88
|
-
return `/${resolvedPath}`;
|
|
89
|
-
}
|
|
90
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
91
|
-
};
|
|
92
|
-
function normalizeString$2(path2, allowAboveRoot) {
|
|
93
|
-
let res = "";
|
|
94
|
-
let lastSegmentLength = 0;
|
|
95
|
-
let lastSlash = -1;
|
|
96
|
-
let dots = 0;
|
|
97
|
-
let char = null;
|
|
98
|
-
for (let i = 0; i <= path2.length; ++i) {
|
|
99
|
-
if (i < path2.length) {
|
|
100
|
-
char = path2[i];
|
|
101
|
-
} else if (char === "/") {
|
|
102
|
-
break;
|
|
103
|
-
} else {
|
|
104
|
-
char = "/";
|
|
105
|
-
}
|
|
106
|
-
if (char === "/") {
|
|
107
|
-
if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
|
|
108
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
109
|
-
if (res.length > 2) {
|
|
110
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
111
|
-
if (lastSlashIndex === -1) {
|
|
112
|
-
res = "";
|
|
113
|
-
lastSegmentLength = 0;
|
|
114
|
-
} else {
|
|
115
|
-
res = res.slice(0, lastSlashIndex);
|
|
116
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
117
|
-
}
|
|
118
|
-
lastSlash = i;
|
|
119
|
-
dots = 0;
|
|
120
|
-
continue;
|
|
121
|
-
} else if (res.length !== 0) {
|
|
122
|
-
res = "";
|
|
123
|
-
lastSegmentLength = 0;
|
|
124
|
-
lastSlash = i;
|
|
125
|
-
dots = 0;
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (allowAboveRoot) {
|
|
130
|
-
res += res.length > 0 ? "/.." : "..";
|
|
131
|
-
lastSegmentLength = 2;
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
if (res.length > 0) {
|
|
135
|
-
res += `/${path2.slice(lastSlash + 1, i)}`;
|
|
136
|
-
} else {
|
|
137
|
-
res = path2.slice(lastSlash + 1, i);
|
|
138
|
-
}
|
|
139
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
140
|
-
}
|
|
141
|
-
lastSlash = i;
|
|
142
|
-
dots = 0;
|
|
143
|
-
} else if (char === "." && dots !== -1) {
|
|
144
|
-
++dots;
|
|
145
|
-
} else {
|
|
146
|
-
dots = -1;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return res;
|
|
150
|
-
}
|
|
151
|
-
const isAbsolute$2 = function(p) {
|
|
152
|
-
return _IS_ABSOLUTE_RE$2.test(p);
|
|
153
|
-
};
|
|
154
|
-
const toNamespacedPath$2 = function(p) {
|
|
155
|
-
return normalizeWindowsPath$2(p);
|
|
156
|
-
};
|
|
157
|
-
const extname$2 = function(p) {
|
|
158
|
-
return path.posix.extname(normalizeWindowsPath$2(p));
|
|
159
|
-
};
|
|
160
|
-
const relative$2 = function(from, to) {
|
|
161
|
-
return path.posix.relative(normalizeWindowsPath$2(from), normalizeWindowsPath$2(to));
|
|
162
|
-
};
|
|
163
|
-
const dirname$2 = function(p) {
|
|
164
|
-
return path.posix.dirname(normalizeWindowsPath$2(p));
|
|
165
|
-
};
|
|
166
|
-
const format$2 = function(p) {
|
|
167
|
-
return normalizeWindowsPath$2(path.posix.format(p));
|
|
168
|
-
};
|
|
169
|
-
const basename$2 = function(p, ext) {
|
|
170
|
-
return path.posix.basename(normalizeWindowsPath$2(p), ext);
|
|
171
|
-
};
|
|
172
|
-
const parse$e = function(p) {
|
|
173
|
-
return path.posix.parse(normalizeWindowsPath$2(p));
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const _path$2 = /*#__PURE__*/Object.freeze({
|
|
177
|
-
__proto__: null,
|
|
178
|
-
sep: sep$2,
|
|
179
|
-
delimiter: delimiter$2,
|
|
180
|
-
normalize: normalize$2,
|
|
181
|
-
join: join$2,
|
|
182
|
-
resolve: resolve,
|
|
183
|
-
normalizeString: normalizeString$2,
|
|
184
|
-
isAbsolute: isAbsolute$2,
|
|
185
|
-
toNamespacedPath: toNamespacedPath$2,
|
|
186
|
-
extname: extname$2,
|
|
187
|
-
relative: relative$2,
|
|
188
|
-
dirname: dirname$2,
|
|
189
|
-
format: format$2,
|
|
190
|
-
basename: basename$2,
|
|
191
|
-
parse: parse$e
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
({
|
|
195
|
-
..._path$2
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
/*---------------------------------------------------------------------------------------------
|
|
199
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
200
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
201
|
-
*--------------------------------------------------------------------------------------------*/
|
|
202
|
-
var ParseOptions$1;
|
|
203
|
-
(function (ParseOptions) {
|
|
204
|
-
ParseOptions.DEFAULT = {
|
|
205
|
-
allowTrailingComma: false
|
|
206
|
-
};
|
|
207
|
-
})(ParseOptions$1 || (ParseOptions$1 = {}));
|
|
208
|
-
|
|
209
15
|
const BUILTIN_MODULES$1 = new Set(builtinModules);
|
|
210
16
|
function normalizeSlash$1(str) {
|
|
211
17
|
return str.replace(/\\/g, "/");
|
|
@@ -223,12 +29,17 @@ function perr$1(_err) {
|
|
|
223
29
|
Error.captureStackTrace(err, pcall$1);
|
|
224
30
|
return Promise.reject(err);
|
|
225
31
|
}
|
|
32
|
+
const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
|
|
33
|
+
function getProtocol(id) {
|
|
34
|
+
const proto = id.match(ProtocolRegex);
|
|
35
|
+
return proto ? proto.groups.proto : null;
|
|
36
|
+
}
|
|
226
37
|
|
|
227
38
|
function fileURLToPath$1(id) {
|
|
228
39
|
if (typeof id === "string" && !id.startsWith("file://")) {
|
|
229
40
|
return normalizeSlash$1(id);
|
|
230
41
|
}
|
|
231
|
-
return normalizeSlash$1(fileURLToPath(id));
|
|
42
|
+
return normalizeSlash$1(fileURLToPath$2(id));
|
|
232
43
|
}
|
|
233
44
|
function normalizeid$1(id) {
|
|
234
45
|
if (typeof id !== "string") {
|
|
@@ -3641,7 +3452,7 @@ function getMessage$1(key, args, self) {
|
|
|
3641
3452
|
if (args.length === 0) return message
|
|
3642
3453
|
|
|
3643
3454
|
args.unshift(message);
|
|
3644
|
-
return Reflect.apply(format$
|
|
3455
|
+
return Reflect.apply(format$2, null, args)
|
|
3645
3456
|
}
|
|
3646
3457
|
|
|
3647
3458
|
// Manually “tree shaken” from:
|
|
@@ -3685,7 +3496,7 @@ function defaultGetFormat$1(url) {
|
|
|
3685
3496
|
}
|
|
3686
3497
|
|
|
3687
3498
|
if (!format) {
|
|
3688
|
-
throw new ERR_UNKNOWN_FILE_EXTENSION$1(ext, fileURLToPath(url))
|
|
3499
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION$1(ext, fileURLToPath$2(url))
|
|
3689
3500
|
}
|
|
3690
3501
|
|
|
3691
3502
|
return {format: format || null}
|
|
@@ -3730,7 +3541,7 @@ const packageJsonCache$1 = new Map();
|
|
|
3730
3541
|
* @returns {void}
|
|
3731
3542
|
*/
|
|
3732
3543
|
function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
|
|
3733
|
-
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
3544
|
+
const pjsonPath = fileURLToPath$2(pjsonUrl);
|
|
3734
3545
|
|
|
3735
3546
|
if (emittedPackageWarnings$1.has(pjsonPath + '|' + match)) return
|
|
3736
3547
|
emittedPackageWarnings$1.add(pjsonPath + '|' + match);
|
|
@@ -3738,7 +3549,7 @@ function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
|
|
|
3738
3549
|
`Use of deprecated folder mapping "${match}" in the ${
|
|
3739
3550
|
isExports ? '"exports"' : '"imports"'
|
|
3740
3551
|
} field module resolution of the package at ${pjsonPath}${
|
|
3741
|
-
base ? ` imported from ${fileURLToPath(base)}` : ''
|
|
3552
|
+
base ? ` imported from ${fileURLToPath$2(base)}` : ''
|
|
3742
3553
|
}.\n` +
|
|
3743
3554
|
`Update this package.json to use a subpath pattern like "${match}*".`,
|
|
3744
3555
|
'DeprecationWarning',
|
|
@@ -3756,9 +3567,9 @@ function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
|
|
|
3756
3567
|
function emitLegacyIndexDeprecation$1(url, packageJsonUrl, base, main) {
|
|
3757
3568
|
const {format} = defaultGetFormat$1(url.href);
|
|
3758
3569
|
if (format !== 'module') return
|
|
3759
|
-
const path = fileURLToPath(url.href);
|
|
3760
|
-
const pkgPath = fileURLToPath(new URL$1('.', packageJsonUrl));
|
|
3761
|
-
const basePath = fileURLToPath(base);
|
|
3570
|
+
const path = fileURLToPath$2(url.href);
|
|
3571
|
+
const pkgPath = fileURLToPath$2(new URL$1('.', packageJsonUrl));
|
|
3572
|
+
const basePath = fileURLToPath$2(base);
|
|
3762
3573
|
if (main)
|
|
3763
3574
|
process.emitWarning(
|
|
3764
3575
|
`Package ${pkgPath} has a "main" field set to ${JSON.stringify(main)}, ` +
|
|
@@ -3828,7 +3639,7 @@ function getPackageConfig$1(path, specifier, base) {
|
|
|
3828
3639
|
} catch (error) {
|
|
3829
3640
|
throw new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
3830
3641
|
path,
|
|
3831
|
-
(base ? `"${specifier}" from ` : '') + fileURLToPath(base || specifier),
|
|
3642
|
+
(base ? `"${specifier}" from ` : '') + fileURLToPath$2(base || specifier),
|
|
3832
3643
|
error.message
|
|
3833
3644
|
)
|
|
3834
3645
|
}
|
|
@@ -3864,7 +3675,7 @@ function getPackageScopeConfig$1(resolved) {
|
|
|
3864
3675
|
if (packageJsonPath.endsWith('node_modules/package.json')) break
|
|
3865
3676
|
|
|
3866
3677
|
const packageConfig = getPackageConfig$1(
|
|
3867
|
-
fileURLToPath(packageJsonUrl),
|
|
3678
|
+
fileURLToPath$2(packageJsonUrl),
|
|
3868
3679
|
resolved
|
|
3869
3680
|
);
|
|
3870
3681
|
if (packageConfig.exists) return packageConfig
|
|
@@ -3877,7 +3688,7 @@ function getPackageScopeConfig$1(resolved) {
|
|
|
3877
3688
|
if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) break
|
|
3878
3689
|
}
|
|
3879
3690
|
|
|
3880
|
-
const packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
3691
|
+
const packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
3881
3692
|
/** @type {PackageConfig} */
|
|
3882
3693
|
const packageConfig = {
|
|
3883
3694
|
pjsonPath: packageJsonPath,
|
|
@@ -3904,7 +3715,7 @@ function getPackageScopeConfig$1(resolved) {
|
|
|
3904
3715
|
* @returns {boolean}
|
|
3905
3716
|
*/
|
|
3906
3717
|
function fileExists$1(url) {
|
|
3907
|
-
return tryStatSync$1(fileURLToPath(url)).isFile()
|
|
3718
|
+
return tryStatSync$1(fileURLToPath$2(url)).isFile()
|
|
3908
3719
|
}
|
|
3909
3720
|
|
|
3910
3721
|
/**
|
|
@@ -3965,8 +3776,8 @@ function legacyMainResolve$1(packageJsonUrl, packageConfig, base) {
|
|
|
3965
3776
|
|
|
3966
3777
|
// Not found.
|
|
3967
3778
|
throw new ERR_MODULE_NOT_FOUND$1(
|
|
3968
|
-
fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
3969
|
-
fileURLToPath(base)
|
|
3779
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
3780
|
+
fileURLToPath$2(base)
|
|
3970
3781
|
)
|
|
3971
3782
|
}
|
|
3972
3783
|
|
|
@@ -3980,15 +3791,15 @@ function finalizeResolution$1(resolved, base) {
|
|
|
3980
3791
|
throw new ERR_INVALID_MODULE_SPECIFIER$1(
|
|
3981
3792
|
resolved.pathname,
|
|
3982
3793
|
'must not include encoded "/" or "\\" characters',
|
|
3983
|
-
fileURLToPath(base)
|
|
3794
|
+
fileURLToPath$2(base)
|
|
3984
3795
|
)
|
|
3985
3796
|
|
|
3986
|
-
const path = fileURLToPath(resolved);
|
|
3797
|
+
const path = fileURLToPath$2(resolved);
|
|
3987
3798
|
|
|
3988
3799
|
const stats = tryStatSync$1(path.endsWith('/') ? path.slice(-1) : path);
|
|
3989
3800
|
|
|
3990
3801
|
if (stats.isDirectory()) {
|
|
3991
|
-
const error = new ERR_UNSUPPORTED_DIR_IMPORT$1(path, fileURLToPath(base));
|
|
3802
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT$1(path, fileURLToPath$2(base));
|
|
3992
3803
|
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
3993
3804
|
error.url = String(resolved);
|
|
3994
3805
|
throw error
|
|
@@ -3997,7 +3808,7 @@ function finalizeResolution$1(resolved, base) {
|
|
|
3997
3808
|
if (!stats.isFile()) {
|
|
3998
3809
|
throw new ERR_MODULE_NOT_FOUND$1(
|
|
3999
3810
|
path || resolved.pathname,
|
|
4000
|
-
base && fileURLToPath(base),
|
|
3811
|
+
base && fileURLToPath$2(base),
|
|
4001
3812
|
'module'
|
|
4002
3813
|
)
|
|
4003
3814
|
}
|
|
@@ -4014,8 +3825,8 @@ function finalizeResolution$1(resolved, base) {
|
|
|
4014
3825
|
function throwImportNotDefined$1(specifier, packageJsonUrl, base) {
|
|
4015
3826
|
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED$1(
|
|
4016
3827
|
specifier,
|
|
4017
|
-
packageJsonUrl && fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
4018
|
-
fileURLToPath(base)
|
|
3828
|
+
packageJsonUrl && fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
3829
|
+
fileURLToPath$2(base)
|
|
4019
3830
|
)
|
|
4020
3831
|
}
|
|
4021
3832
|
|
|
@@ -4027,9 +3838,9 @@ function throwImportNotDefined$1(specifier, packageJsonUrl, base) {
|
|
|
4027
3838
|
*/
|
|
4028
3839
|
function throwExportsNotFound$1(subpath, packageJsonUrl, base) {
|
|
4029
3840
|
throw new ERR_PACKAGE_PATH_NOT_EXPORTED$1(
|
|
4030
|
-
fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
3841
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
4031
3842
|
subpath,
|
|
4032
|
-
base && fileURLToPath(base)
|
|
3843
|
+
base && fileURLToPath$2(base)
|
|
4033
3844
|
)
|
|
4034
3845
|
}
|
|
4035
3846
|
|
|
@@ -4043,12 +3854,12 @@ function throwExportsNotFound$1(subpath, packageJsonUrl, base) {
|
|
|
4043
3854
|
function throwInvalidSubpath$1(subpath, packageJsonUrl, internal, base) {
|
|
4044
3855
|
const reason = `request is not a valid subpath for the "${
|
|
4045
3856
|
internal ? 'imports' : 'exports'
|
|
4046
|
-
}" resolution of ${fileURLToPath(packageJsonUrl)}`;
|
|
3857
|
+
}" resolution of ${fileURLToPath$2(packageJsonUrl)}`;
|
|
4047
3858
|
|
|
4048
3859
|
throw new ERR_INVALID_MODULE_SPECIFIER$1(
|
|
4049
3860
|
subpath,
|
|
4050
3861
|
reason,
|
|
4051
|
-
base && fileURLToPath(base)
|
|
3862
|
+
base && fileURLToPath$2(base)
|
|
4052
3863
|
)
|
|
4053
3864
|
}
|
|
4054
3865
|
|
|
@@ -4073,11 +3884,11 @@ function throwInvalidPackageTarget$1(
|
|
|
4073
3884
|
: `${target}`;
|
|
4074
3885
|
|
|
4075
3886
|
throw new ERR_INVALID_PACKAGE_TARGET$1(
|
|
4076
|
-
fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
3887
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
4077
3888
|
subpath,
|
|
4078
3889
|
target,
|
|
4079
3890
|
internal,
|
|
4080
|
-
base && fileURLToPath(base)
|
|
3891
|
+
base && fileURLToPath$2(base)
|
|
4081
3892
|
)
|
|
4082
3893
|
}
|
|
4083
3894
|
|
|
@@ -4246,7 +4057,7 @@ function resolvePackageTarget$1(
|
|
|
4246
4057
|
const key = keys[i];
|
|
4247
4058
|
if (isArrayIndex$1(key)) {
|
|
4248
4059
|
throw new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
4249
|
-
fileURLToPath(packageJsonUrl),
|
|
4060
|
+
fileURLToPath$2(packageJsonUrl),
|
|
4250
4061
|
base,
|
|
4251
4062
|
'"exports" cannot contain numeric property keys.'
|
|
4252
4063
|
)
|
|
@@ -4312,7 +4123,7 @@ function isConditionalExportsMainSugar$1(exports, packageJsonUrl, base) {
|
|
|
4312
4123
|
isConditionalSugar = curIsConditionalSugar;
|
|
4313
4124
|
} else if (isConditionalSugar !== curIsConditionalSugar) {
|
|
4314
4125
|
throw new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
4315
|
-
fileURLToPath(packageJsonUrl),
|
|
4126
|
+
fileURLToPath$2(packageJsonUrl),
|
|
4316
4127
|
base,
|
|
4317
4128
|
'"exports" cannot contain some keys starting with \'.\' and some not.' +
|
|
4318
4129
|
' The exports object must either be an object of package subpath keys' +
|
|
@@ -4415,7 +4226,7 @@ function packageExportsResolve$1(
|
|
|
4415
4226
|
function packageImportsResolve$1(name, base, conditions) {
|
|
4416
4227
|
if (name === '#' || name.startsWith('#/')) {
|
|
4417
4228
|
const reason = 'is not a valid internal imports specifier name';
|
|
4418
|
-
throw new ERR_INVALID_MODULE_SPECIFIER$1(name, reason, fileURLToPath(base))
|
|
4229
|
+
throw new ERR_INVALID_MODULE_SPECIFIER$1(name, reason, fileURLToPath$2(base))
|
|
4419
4230
|
}
|
|
4420
4231
|
|
|
4421
4232
|
/** @type {URL} */
|
|
@@ -4533,7 +4344,7 @@ function parsePackageName$1(specifier, base) {
|
|
|
4533
4344
|
throw new ERR_INVALID_MODULE_SPECIFIER$1(
|
|
4534
4345
|
specifier,
|
|
4535
4346
|
'is not a valid package name',
|
|
4536
|
-
fileURLToPath(base)
|
|
4347
|
+
fileURLToPath$2(base)
|
|
4537
4348
|
)
|
|
4538
4349
|
}
|
|
4539
4350
|
|
|
@@ -4581,7 +4392,7 @@ function packageResolve$1(specifier, base, conditions) {
|
|
|
4581
4392
|
'./node_modules/' + packageName + '/package.json',
|
|
4582
4393
|
base
|
|
4583
4394
|
);
|
|
4584
|
-
let packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
4395
|
+
let packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
4585
4396
|
/** @type {string} */
|
|
4586
4397
|
let lastPath;
|
|
4587
4398
|
do {
|
|
@@ -4594,7 +4405,7 @@ function packageResolve$1(specifier, base, conditions) {
|
|
|
4594
4405
|
'/package.json',
|
|
4595
4406
|
packageJsonUrl
|
|
4596
4407
|
);
|
|
4597
|
-
packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
4408
|
+
packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
4598
4409
|
continue
|
|
4599
4410
|
}
|
|
4600
4411
|
|
|
@@ -4614,7 +4425,7 @@ function packageResolve$1(specifier, base, conditions) {
|
|
|
4614
4425
|
// Cross-platform root check.
|
|
4615
4426
|
} while (packageJsonPath.length !== lastPath.length)
|
|
4616
4427
|
|
|
4617
|
-
throw new ERR_MODULE_NOT_FOUND$1(packageName, fileURLToPath(base))
|
|
4428
|
+
throw new ERR_MODULE_NOT_FOUND$1(packageName, fileURLToPath$2(base))
|
|
4618
4429
|
}
|
|
4619
4430
|
|
|
4620
4431
|
/**
|
|
@@ -4761,6 +4572,43 @@ var ParseOptions;
|
|
|
4761
4572
|
};
|
|
4762
4573
|
})(ParseOptions || (ParseOptions = {}));
|
|
4763
4574
|
|
|
4575
|
+
const BUILTIN_MODULES = new Set(builtinModules);
|
|
4576
|
+
function normalizeSlash(str) {
|
|
4577
|
+
return str.replace(/\\/g, "/");
|
|
4578
|
+
}
|
|
4579
|
+
function pcall(fn, ...args) {
|
|
4580
|
+
try {
|
|
4581
|
+
return Promise.resolve(fn(...args)).catch((err) => perr(err));
|
|
4582
|
+
} catch (err) {
|
|
4583
|
+
return perr(err);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
function perr(_err) {
|
|
4587
|
+
const err = new Error(_err);
|
|
4588
|
+
err.code = _err.code;
|
|
4589
|
+
Error.captureStackTrace(err, pcall);
|
|
4590
|
+
return Promise.reject(err);
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4593
|
+
function fileURLToPath(id) {
|
|
4594
|
+
if (typeof id === "string" && !id.startsWith("file://")) {
|
|
4595
|
+
return normalizeSlash(id);
|
|
4596
|
+
}
|
|
4597
|
+
return normalizeSlash(fileURLToPath$2(id));
|
|
4598
|
+
}
|
|
4599
|
+
function normalizeid(id) {
|
|
4600
|
+
if (typeof id !== "string") {
|
|
4601
|
+
id = id.toString();
|
|
4602
|
+
}
|
|
4603
|
+
if (/(node|data|http|https|file):/.test(id)) {
|
|
4604
|
+
return id;
|
|
4605
|
+
}
|
|
4606
|
+
if (BUILTIN_MODULES.has(id)) {
|
|
4607
|
+
return "node:" + id;
|
|
4608
|
+
}
|
|
4609
|
+
return "file://" + normalizeSlash(id);
|
|
4610
|
+
}
|
|
4611
|
+
|
|
4764
4612
|
function normalizeWindowsPath(input = "") {
|
|
4765
4613
|
if (!input.includes("\\")) {
|
|
4766
4614
|
return input;
|
|
@@ -7776,10 +7624,49 @@ var builtins = function ({
|
|
|
7776
7624
|
|
|
7777
7625
|
// Manually “tree shaken” from:
|
|
7778
7626
|
|
|
7627
|
+
const reader = {read};
|
|
7628
|
+
const packageJsonReader = reader;
|
|
7629
|
+
|
|
7630
|
+
/**
|
|
7631
|
+
* @param {string} jsonPath
|
|
7632
|
+
* @returns {{string: string}}
|
|
7633
|
+
*/
|
|
7634
|
+
function read(jsonPath) {
|
|
7635
|
+
return find(path.dirname(jsonPath))
|
|
7636
|
+
}
|
|
7637
|
+
|
|
7638
|
+
/**
|
|
7639
|
+
* @param {string} dir
|
|
7640
|
+
* @returns {{string: string}}
|
|
7641
|
+
*/
|
|
7642
|
+
function find(dir) {
|
|
7643
|
+
try {
|
|
7644
|
+
const string = fs.readFileSync(
|
|
7645
|
+
path.toNamespacedPath(path.join(dir, 'package.json')),
|
|
7646
|
+
'utf8'
|
|
7647
|
+
);
|
|
7648
|
+
return {string}
|
|
7649
|
+
} catch (error) {
|
|
7650
|
+
if (error.code === 'ENOENT') {
|
|
7651
|
+
const parent = path.dirname(dir);
|
|
7652
|
+
if (dir !== parent) return find(parent)
|
|
7653
|
+
return {string: undefined}
|
|
7654
|
+
// Throw all other errors.
|
|
7655
|
+
/* c8 ignore next 4 */
|
|
7656
|
+
}
|
|
7657
|
+
|
|
7658
|
+
throw error
|
|
7659
|
+
}
|
|
7660
|
+
}
|
|
7661
|
+
|
|
7662
|
+
// Manually “tree shaken” from:
|
|
7663
|
+
|
|
7779
7664
|
const isWindows$2 = process.platform === 'win32';
|
|
7780
7665
|
|
|
7781
7666
|
const own$1 = {}.hasOwnProperty;
|
|
7782
7667
|
|
|
7668
|
+
const codes = {};
|
|
7669
|
+
|
|
7783
7670
|
/**
|
|
7784
7671
|
* @typedef {(...args: unknown[]) => string} MessageFunction
|
|
7785
7672
|
*/
|
|
@@ -7790,7 +7677,7 @@ const nodeInternalPrefix = '__node_internal_';
|
|
|
7790
7677
|
/** @type {number} */
|
|
7791
7678
|
let userStackTraceLimit;
|
|
7792
7679
|
|
|
7793
|
-
createError(
|
|
7680
|
+
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
7794
7681
|
'ERR_INVALID_MODULE_SPECIFIER',
|
|
7795
7682
|
/**
|
|
7796
7683
|
* @param {string} request
|
|
@@ -7805,7 +7692,7 @@ createError(
|
|
|
7805
7692
|
TypeError
|
|
7806
7693
|
);
|
|
7807
7694
|
|
|
7808
|
-
createError(
|
|
7695
|
+
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
7809
7696
|
'ERR_INVALID_PACKAGE_CONFIG',
|
|
7810
7697
|
/**
|
|
7811
7698
|
* @param {string} path
|
|
@@ -7820,7 +7707,7 @@ createError(
|
|
|
7820
7707
|
Error
|
|
7821
7708
|
);
|
|
7822
7709
|
|
|
7823
|
-
createError(
|
|
7710
|
+
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
7824
7711
|
'ERR_INVALID_PACKAGE_TARGET',
|
|
7825
7712
|
/**
|
|
7826
7713
|
* @param {string} pkgPath
|
|
@@ -7856,7 +7743,7 @@ createError(
|
|
|
7856
7743
|
Error
|
|
7857
7744
|
);
|
|
7858
7745
|
|
|
7859
|
-
createError(
|
|
7746
|
+
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
7860
7747
|
'ERR_MODULE_NOT_FOUND',
|
|
7861
7748
|
/**
|
|
7862
7749
|
* @param {string} path
|
|
@@ -7869,7 +7756,7 @@ createError(
|
|
|
7869
7756
|
Error
|
|
7870
7757
|
);
|
|
7871
7758
|
|
|
7872
|
-
createError(
|
|
7759
|
+
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
7873
7760
|
'ERR_PACKAGE_IMPORT_NOT_DEFINED',
|
|
7874
7761
|
/**
|
|
7875
7762
|
* @param {string} specifier
|
|
@@ -7884,7 +7771,7 @@ createError(
|
|
|
7884
7771
|
TypeError
|
|
7885
7772
|
);
|
|
7886
7773
|
|
|
7887
|
-
createError(
|
|
7774
|
+
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
7888
7775
|
'ERR_PACKAGE_PATH_NOT_EXPORTED',
|
|
7889
7776
|
/**
|
|
7890
7777
|
* @param {string} pkgPath
|
|
@@ -7903,20 +7790,20 @@ createError(
|
|
|
7903
7790
|
Error
|
|
7904
7791
|
);
|
|
7905
7792
|
|
|
7906
|
-
createError(
|
|
7793
|
+
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
|
|
7907
7794
|
'ERR_UNSUPPORTED_DIR_IMPORT',
|
|
7908
7795
|
"Directory import '%s' is not supported " +
|
|
7909
7796
|
'resolving ES modules imported from %s',
|
|
7910
7797
|
Error
|
|
7911
7798
|
);
|
|
7912
7799
|
|
|
7913
|
-
createError(
|
|
7800
|
+
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
7914
7801
|
'ERR_UNKNOWN_FILE_EXTENSION',
|
|
7915
7802
|
'Unknown file extension "%s" for %s',
|
|
7916
7803
|
TypeError
|
|
7917
7804
|
);
|
|
7918
7805
|
|
|
7919
|
-
createError(
|
|
7806
|
+
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
7920
7807
|
'ERR_INVALID_ARG_VALUE',
|
|
7921
7808
|
/**
|
|
7922
7809
|
* @param {string} name
|
|
@@ -7939,7 +7826,7 @@ createError(
|
|
|
7939
7826
|
// , RangeError
|
|
7940
7827
|
);
|
|
7941
7828
|
|
|
7942
|
-
createError(
|
|
7829
|
+
codes.ERR_UNSUPPORTED_ESM_URL_SCHEME = createError(
|
|
7943
7830
|
'ERR_UNSUPPORTED_ESM_URL_SCHEME',
|
|
7944
7831
|
/**
|
|
7945
7832
|
* @param {URL} url
|
|
@@ -8116,112 +8003,1196 @@ function getMessage(key, args, self) {
|
|
|
8116
8003
|
if (args.length === 0) return message
|
|
8117
8004
|
|
|
8118
8005
|
args.unshift(message);
|
|
8119
|
-
return Reflect.apply(format$
|
|
8006
|
+
return Reflect.apply(format$2, null, args)
|
|
8120
8007
|
}
|
|
8121
8008
|
|
|
8122
8009
|
// Manually “tree shaken” from:
|
|
8123
8010
|
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
Object.freeze(['node', 'import']);
|
|
8127
|
-
pathToFileURL(process.cwd());
|
|
8128
|
-
const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
|
|
8129
|
-
function hasCJSSyntax(code) {
|
|
8130
|
-
return CJS_RE.test(code);
|
|
8131
|
-
}
|
|
8011
|
+
const {ERR_UNKNOWN_FILE_EXTENSION} = codes;
|
|
8132
8012
|
|
|
8133
|
-
const
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
if (statSync(filePath).isFile()) {
|
|
8139
|
-
return true;
|
|
8140
|
-
}
|
|
8141
|
-
} catch {
|
|
8142
|
-
}
|
|
8143
|
-
return null;
|
|
8144
|
-
}
|
|
8013
|
+
const extensionFormatMap = {
|
|
8014
|
+
__proto__: null,
|
|
8015
|
+
'.cjs': 'commonjs',
|
|
8016
|
+
'.js': 'module',
|
|
8017
|
+
'.mjs': 'module'
|
|
8145
8018
|
};
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
let root = segments.findIndex((r) => r.match(options.rootPattern));
|
|
8155
|
-
if (root === -1)
|
|
8156
|
-
root = 0;
|
|
8157
|
-
for (let i = segments.length; i > root; i--) {
|
|
8158
|
-
const filePath = join$2(...segments.slice(0, i), filename);
|
|
8159
|
-
if (await options.test(filePath)) {
|
|
8160
|
-
return filePath;
|
|
8161
|
-
}
|
|
8019
|
+
|
|
8020
|
+
/**
|
|
8021
|
+
* @param {string} url
|
|
8022
|
+
* @returns {{format: string|null}}
|
|
8023
|
+
*/
|
|
8024
|
+
function defaultGetFormat(url) {
|
|
8025
|
+
if (url.startsWith('node:')) {
|
|
8026
|
+
return {format: 'builtin'}
|
|
8162
8027
|
}
|
|
8163
|
-
throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
|
|
8164
|
-
}
|
|
8165
|
-
async function readPackageJSON(id, opts = {}) {
|
|
8166
|
-
const resolvedPath = await resolvePackageJSON(id, opts);
|
|
8167
|
-
const blob = await promises.readFile(resolvedPath, "utf-8");
|
|
8168
|
-
return JSON.parse(blob);
|
|
8169
|
-
}
|
|
8170
|
-
async function resolvePackageJSON(id = process.cwd(), opts = {}) {
|
|
8171
|
-
const resolvedPath = isAbsolute$2(id) ? id : await resolvePath$1(id, opts);
|
|
8172
|
-
return findNearestFile("package.json", { startingFrom: resolvedPath, ...opts });
|
|
8173
|
-
}
|
|
8174
8028
|
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8029
|
+
const parsed = new URL$1(url);
|
|
8030
|
+
|
|
8031
|
+
if (parsed.protocol === 'data:') {
|
|
8032
|
+
const {1: mime} = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
|
|
8033
|
+
parsed.pathname
|
|
8034
|
+
) || [null, null];
|
|
8035
|
+
const format = mime === 'text/javascript' ? 'module' : null;
|
|
8036
|
+
return {format}
|
|
8037
|
+
}
|
|
8038
|
+
|
|
8039
|
+
if (parsed.protocol === 'file:') {
|
|
8040
|
+
const ext = path.extname(parsed.pathname);
|
|
8041
|
+
/** @type {string} */
|
|
8042
|
+
let format;
|
|
8043
|
+
if (ext === '.js') {
|
|
8044
|
+
format = getPackageType(parsed.href) === 'module' ? 'module' : 'commonjs';
|
|
8045
|
+
} else {
|
|
8046
|
+
format = extensionFormatMap[ext];
|
|
8047
|
+
}
|
|
8048
|
+
|
|
8049
|
+
if (!format) {
|
|
8050
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, fileURLToPath$2(url))
|
|
8051
|
+
}
|
|
8052
|
+
|
|
8053
|
+
return {format: format || null}
|
|
8054
|
+
}
|
|
8055
|
+
|
|
8056
|
+
return {format: null}
|
|
8057
|
+
}
|
|
8058
|
+
|
|
8059
|
+
// Manually “tree shaken” from:
|
|
8060
|
+
|
|
8061
|
+
builtins();
|
|
8062
|
+
|
|
8063
|
+
const {
|
|
8064
|
+
ERR_INVALID_MODULE_SPECIFIER,
|
|
8065
|
+
ERR_INVALID_PACKAGE_CONFIG,
|
|
8066
|
+
ERR_INVALID_PACKAGE_TARGET,
|
|
8067
|
+
ERR_MODULE_NOT_FOUND,
|
|
8068
|
+
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
8069
|
+
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
8070
|
+
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
8071
|
+
ERR_UNSUPPORTED_ESM_URL_SCHEME,
|
|
8072
|
+
ERR_INVALID_ARG_VALUE
|
|
8073
|
+
} = codes;
|
|
8074
|
+
|
|
8075
|
+
const own = {}.hasOwnProperty;
|
|
8076
|
+
|
|
8077
|
+
Object.freeze(['node', 'import']);
|
|
8078
|
+
|
|
8079
|
+
const invalidSegmentRegEx = /(^|\\|\/)(\.\.?|node_modules)(\\|\/|$)/;
|
|
8080
|
+
const patternRegEx = /\*/g;
|
|
8081
|
+
const encodedSepRegEx = /%2f|%2c/i;
|
|
8082
|
+
/** @type {Set<string>} */
|
|
8083
|
+
const emittedPackageWarnings = new Set();
|
|
8084
|
+
/** @type {Map<string, PackageConfig>} */
|
|
8085
|
+
const packageJsonCache = new Map();
|
|
8086
|
+
|
|
8087
|
+
/**
|
|
8088
|
+
* @param {string} match
|
|
8089
|
+
* @param {URL} pjsonUrl
|
|
8090
|
+
* @param {boolean} isExports
|
|
8091
|
+
* @param {URL} base
|
|
8092
|
+
* @returns {void}
|
|
8093
|
+
*/
|
|
8094
|
+
function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) {
|
|
8095
|
+
const pjsonPath = fileURLToPath$2(pjsonUrl);
|
|
8096
|
+
|
|
8097
|
+
if (emittedPackageWarnings.has(pjsonPath + '|' + match)) return
|
|
8098
|
+
emittedPackageWarnings.add(pjsonPath + '|' + match);
|
|
8099
|
+
process.emitWarning(
|
|
8100
|
+
`Use of deprecated folder mapping "${match}" in the ${
|
|
8101
|
+
isExports ? '"exports"' : '"imports"'
|
|
8102
|
+
} field module resolution of the package at ${pjsonPath}${
|
|
8103
|
+
base ? ` imported from ${fileURLToPath$2(base)}` : ''
|
|
8104
|
+
}.\n` +
|
|
8105
|
+
`Update this package.json to use a subpath pattern like "${match}*".`,
|
|
8106
|
+
'DeprecationWarning',
|
|
8107
|
+
'DEP0148'
|
|
8108
|
+
);
|
|
8109
|
+
}
|
|
8110
|
+
|
|
8111
|
+
/**
|
|
8112
|
+
* @param {URL} url
|
|
8113
|
+
* @param {URL} packageJsonUrl
|
|
8114
|
+
* @param {URL} base
|
|
8115
|
+
* @param {unknown} [main]
|
|
8116
|
+
* @returns {void}
|
|
8117
|
+
*/
|
|
8118
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
8119
|
+
const {format} = defaultGetFormat(url.href);
|
|
8120
|
+
if (format !== 'module') return
|
|
8121
|
+
const path = fileURLToPath$2(url.href);
|
|
8122
|
+
const pkgPath = fileURLToPath$2(new URL$1('.', packageJsonUrl));
|
|
8123
|
+
const basePath = fileURLToPath$2(base);
|
|
8124
|
+
if (main)
|
|
8125
|
+
process.emitWarning(
|
|
8126
|
+
`Package ${pkgPath} has a "main" field set to ${JSON.stringify(main)}, ` +
|
|
8127
|
+
`excluding the full filename and extension to the resolved file at "${path.slice(
|
|
8128
|
+
pkgPath.length
|
|
8129
|
+
)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is` +
|
|
8130
|
+
'deprecated for ES modules.',
|
|
8131
|
+
'DeprecationWarning',
|
|
8132
|
+
'DEP0151'
|
|
8133
|
+
);
|
|
8134
|
+
else
|
|
8135
|
+
process.emitWarning(
|
|
8136
|
+
`No "main" or "exports" field defined in the package.json for ${pkgPath} resolving the main entry point "${path.slice(
|
|
8137
|
+
pkgPath.length
|
|
8138
|
+
)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`,
|
|
8139
|
+
'DeprecationWarning',
|
|
8140
|
+
'DEP0151'
|
|
8141
|
+
);
|
|
8142
|
+
}
|
|
8143
|
+
|
|
8144
|
+
/**
|
|
8145
|
+
* @param {string} path
|
|
8146
|
+
* @returns {Stats}
|
|
8147
|
+
*/
|
|
8148
|
+
function tryStatSync(path) {
|
|
8149
|
+
// Note: from Node 15 onwards we can use `throwIfNoEntry: false` instead.
|
|
8150
|
+
try {
|
|
8151
|
+
return statSync(path)
|
|
8152
|
+
} catch {
|
|
8153
|
+
return new Stats()
|
|
8154
|
+
}
|
|
8155
|
+
}
|
|
8156
|
+
|
|
8157
|
+
/**
|
|
8158
|
+
* @param {string} path
|
|
8159
|
+
* @param {string|URL} specifier Note: `specifier` is actually optional, not base.
|
|
8160
|
+
* @param {URL} [base]
|
|
8161
|
+
* @returns {PackageConfig}
|
|
8162
|
+
*/
|
|
8163
|
+
function getPackageConfig(path, specifier, base) {
|
|
8164
|
+
const existing = packageJsonCache.get(path);
|
|
8165
|
+
if (existing !== undefined) {
|
|
8166
|
+
return existing
|
|
8167
|
+
}
|
|
8168
|
+
|
|
8169
|
+
const source = packageJsonReader.read(path).string;
|
|
8170
|
+
|
|
8171
|
+
if (source === undefined) {
|
|
8172
|
+
/** @type {PackageConfig} */
|
|
8173
|
+
const packageConfig = {
|
|
8174
|
+
pjsonPath: path,
|
|
8175
|
+
exists: false,
|
|
8176
|
+
main: undefined,
|
|
8177
|
+
name: undefined,
|
|
8178
|
+
type: 'none',
|
|
8179
|
+
exports: undefined,
|
|
8180
|
+
imports: undefined
|
|
8181
|
+
};
|
|
8182
|
+
packageJsonCache.set(path, packageConfig);
|
|
8183
|
+
return packageConfig
|
|
8184
|
+
}
|
|
8185
|
+
|
|
8186
|
+
/** @type {Object.<string, unknown>} */
|
|
8187
|
+
let packageJson;
|
|
8188
|
+
try {
|
|
8189
|
+
packageJson = JSON.parse(source);
|
|
8190
|
+
} catch (error) {
|
|
8191
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
8192
|
+
path,
|
|
8193
|
+
(base ? `"${specifier}" from ` : '') + fileURLToPath$2(base || specifier),
|
|
8194
|
+
error.message
|
|
8195
|
+
)
|
|
8196
|
+
}
|
|
8197
|
+
|
|
8198
|
+
const {exports, imports, main, name, type} = packageJson;
|
|
8199
|
+
|
|
8200
|
+
/** @type {PackageConfig} */
|
|
8201
|
+
const packageConfig = {
|
|
8202
|
+
pjsonPath: path,
|
|
8203
|
+
exists: true,
|
|
8204
|
+
main: typeof main === 'string' ? main : undefined,
|
|
8205
|
+
name: typeof name === 'string' ? name : undefined,
|
|
8206
|
+
type: type === 'module' || type === 'commonjs' ? type : 'none',
|
|
8207
|
+
// @ts-expect-error Assume `Object.<string, unknown>`.
|
|
8208
|
+
exports,
|
|
8209
|
+
// @ts-expect-error Assume `Object.<string, unknown>`.
|
|
8210
|
+
imports: imports && typeof imports === 'object' ? imports : undefined
|
|
8211
|
+
};
|
|
8212
|
+
packageJsonCache.set(path, packageConfig);
|
|
8213
|
+
return packageConfig
|
|
8214
|
+
}
|
|
8215
|
+
|
|
8216
|
+
/**
|
|
8217
|
+
* @param {URL|string} resolved
|
|
8218
|
+
* @returns {PackageConfig}
|
|
8219
|
+
*/
|
|
8220
|
+
function getPackageScopeConfig(resolved) {
|
|
8221
|
+
let packageJsonUrl = new URL$1('./package.json', resolved);
|
|
8222
|
+
|
|
8223
|
+
while (true) {
|
|
8224
|
+
const packageJsonPath = packageJsonUrl.pathname;
|
|
8225
|
+
|
|
8226
|
+
if (packageJsonPath.endsWith('node_modules/package.json')) break
|
|
8227
|
+
|
|
8228
|
+
const packageConfig = getPackageConfig(
|
|
8229
|
+
fileURLToPath$2(packageJsonUrl),
|
|
8230
|
+
resolved
|
|
8231
|
+
);
|
|
8232
|
+
if (packageConfig.exists) return packageConfig
|
|
8233
|
+
|
|
8234
|
+
const lastPackageJsonUrl = packageJsonUrl;
|
|
8235
|
+
packageJsonUrl = new URL$1('../package.json', packageJsonUrl);
|
|
8236
|
+
|
|
8237
|
+
// Terminates at root where ../package.json equals ../../package.json
|
|
8238
|
+
// (can't just check "/package.json" for Windows support).
|
|
8239
|
+
if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) break
|
|
8240
|
+
}
|
|
8241
|
+
|
|
8242
|
+
const packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
8243
|
+
/** @type {PackageConfig} */
|
|
8244
|
+
const packageConfig = {
|
|
8245
|
+
pjsonPath: packageJsonPath,
|
|
8246
|
+
exists: false,
|
|
8247
|
+
main: undefined,
|
|
8248
|
+
name: undefined,
|
|
8249
|
+
type: 'none',
|
|
8250
|
+
exports: undefined,
|
|
8251
|
+
imports: undefined
|
|
8252
|
+
};
|
|
8253
|
+
packageJsonCache.set(packageJsonPath, packageConfig);
|
|
8254
|
+
return packageConfig
|
|
8255
|
+
}
|
|
8256
|
+
|
|
8257
|
+
/**
|
|
8258
|
+
* Legacy CommonJS main resolution:
|
|
8259
|
+
* 1. let M = pkg_url + (json main field)
|
|
8260
|
+
* 2. TRY(M, M.js, M.json, M.node)
|
|
8261
|
+
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
8262
|
+
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
8263
|
+
* 5. NOT_FOUND
|
|
8264
|
+
*
|
|
8265
|
+
* @param {URL} url
|
|
8266
|
+
* @returns {boolean}
|
|
8267
|
+
*/
|
|
8268
|
+
function fileExists(url) {
|
|
8269
|
+
return tryStatSync(fileURLToPath$2(url)).isFile()
|
|
8270
|
+
}
|
|
8271
|
+
|
|
8272
|
+
/**
|
|
8273
|
+
* @param {URL} packageJsonUrl
|
|
8274
|
+
* @param {PackageConfig} packageConfig
|
|
8275
|
+
* @param {URL} base
|
|
8276
|
+
* @returns {URL}
|
|
8277
|
+
*/
|
|
8278
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
8279
|
+
/** @type {URL} */
|
|
8280
|
+
let guess;
|
|
8281
|
+
if (packageConfig.main !== undefined) {
|
|
8282
|
+
guess = new URL$1(`./${packageConfig.main}`, packageJsonUrl);
|
|
8283
|
+
// Note: fs check redundances will be handled by Descriptor cache here.
|
|
8284
|
+
if (fileExists(guess)) return guess
|
|
8285
|
+
|
|
8286
|
+
const tries = [
|
|
8287
|
+
`./${packageConfig.main}.js`,
|
|
8288
|
+
`./${packageConfig.main}.json`,
|
|
8289
|
+
`./${packageConfig.main}.node`,
|
|
8290
|
+
`./${packageConfig.main}/index.js`,
|
|
8291
|
+
`./${packageConfig.main}/index.json`,
|
|
8292
|
+
`./${packageConfig.main}/index.node`
|
|
8293
|
+
];
|
|
8294
|
+
let i = -1;
|
|
8295
|
+
|
|
8296
|
+
while (++i < tries.length) {
|
|
8297
|
+
guess = new URL$1(tries[i], packageJsonUrl);
|
|
8298
|
+
if (fileExists(guess)) break
|
|
8299
|
+
guess = undefined;
|
|
8300
|
+
}
|
|
8301
|
+
|
|
8302
|
+
if (guess) {
|
|
8303
|
+
emitLegacyIndexDeprecation(
|
|
8304
|
+
guess,
|
|
8305
|
+
packageJsonUrl,
|
|
8306
|
+
base,
|
|
8307
|
+
packageConfig.main
|
|
8308
|
+
);
|
|
8309
|
+
return guess
|
|
8310
|
+
}
|
|
8311
|
+
// Fallthrough.
|
|
8312
|
+
}
|
|
8313
|
+
|
|
8314
|
+
const tries = ['./index.js', './index.json', './index.node'];
|
|
8315
|
+
let i = -1;
|
|
8316
|
+
|
|
8317
|
+
while (++i < tries.length) {
|
|
8318
|
+
guess = new URL$1(tries[i], packageJsonUrl);
|
|
8319
|
+
if (fileExists(guess)) break
|
|
8320
|
+
guess = undefined;
|
|
8321
|
+
}
|
|
8322
|
+
|
|
8323
|
+
if (guess) {
|
|
8324
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
8325
|
+
return guess
|
|
8326
|
+
}
|
|
8327
|
+
|
|
8328
|
+
// Not found.
|
|
8329
|
+
throw new ERR_MODULE_NOT_FOUND(
|
|
8330
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
8331
|
+
fileURLToPath$2(base)
|
|
8332
|
+
)
|
|
8333
|
+
}
|
|
8334
|
+
|
|
8335
|
+
/**
|
|
8336
|
+
* @param {URL} resolved
|
|
8337
|
+
* @param {URL} base
|
|
8338
|
+
* @returns {URL}
|
|
8339
|
+
*/
|
|
8340
|
+
function finalizeResolution(resolved, base) {
|
|
8341
|
+
if (encodedSepRegEx.test(resolved.pathname))
|
|
8342
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
8343
|
+
resolved.pathname,
|
|
8344
|
+
'must not include encoded "/" or "\\" characters',
|
|
8345
|
+
fileURLToPath$2(base)
|
|
8346
|
+
)
|
|
8347
|
+
|
|
8348
|
+
const path = fileURLToPath$2(resolved);
|
|
8349
|
+
|
|
8350
|
+
const stats = tryStatSync(path.endsWith('/') ? path.slice(-1) : path);
|
|
8351
|
+
|
|
8352
|
+
if (stats.isDirectory()) {
|
|
8353
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath$2(base));
|
|
8354
|
+
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
8355
|
+
error.url = String(resolved);
|
|
8356
|
+
throw error
|
|
8357
|
+
}
|
|
8358
|
+
|
|
8359
|
+
if (!stats.isFile()) {
|
|
8360
|
+
throw new ERR_MODULE_NOT_FOUND(
|
|
8361
|
+
path || resolved.pathname,
|
|
8362
|
+
base && fileURLToPath$2(base),
|
|
8363
|
+
'module'
|
|
8364
|
+
)
|
|
8365
|
+
}
|
|
8366
|
+
|
|
8367
|
+
return resolved
|
|
8368
|
+
}
|
|
8369
|
+
|
|
8370
|
+
/**
|
|
8371
|
+
* @param {string} specifier
|
|
8372
|
+
* @param {URL?} packageJsonUrl
|
|
8373
|
+
* @param {URL} base
|
|
8374
|
+
* @returns {never}
|
|
8375
|
+
*/
|
|
8376
|
+
function throwImportNotDefined(specifier, packageJsonUrl, base) {
|
|
8377
|
+
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
8378
|
+
specifier,
|
|
8379
|
+
packageJsonUrl && fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
8380
|
+
fileURLToPath$2(base)
|
|
8381
|
+
)
|
|
8382
|
+
}
|
|
8383
|
+
|
|
8384
|
+
/**
|
|
8385
|
+
* @param {string} subpath
|
|
8386
|
+
* @param {URL} packageJsonUrl
|
|
8387
|
+
* @param {URL} base
|
|
8388
|
+
* @returns {never}
|
|
8389
|
+
*/
|
|
8390
|
+
function throwExportsNotFound(subpath, packageJsonUrl, base) {
|
|
8391
|
+
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
8392
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
8393
|
+
subpath,
|
|
8394
|
+
base && fileURLToPath$2(base)
|
|
8395
|
+
)
|
|
8396
|
+
}
|
|
8397
|
+
|
|
8398
|
+
/**
|
|
8399
|
+
* @param {string} subpath
|
|
8400
|
+
* @param {URL} packageJsonUrl
|
|
8401
|
+
* @param {boolean} internal
|
|
8402
|
+
* @param {URL} [base]
|
|
8403
|
+
* @returns {never}
|
|
8404
|
+
*/
|
|
8405
|
+
function throwInvalidSubpath(subpath, packageJsonUrl, internal, base) {
|
|
8406
|
+
const reason = `request is not a valid subpath for the "${
|
|
8407
|
+
internal ? 'imports' : 'exports'
|
|
8408
|
+
}" resolution of ${fileURLToPath$2(packageJsonUrl)}`;
|
|
8409
|
+
|
|
8410
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
8411
|
+
subpath,
|
|
8412
|
+
reason,
|
|
8413
|
+
base && fileURLToPath$2(base)
|
|
8414
|
+
)
|
|
8415
|
+
}
|
|
8416
|
+
|
|
8417
|
+
/**
|
|
8418
|
+
* @param {string} subpath
|
|
8419
|
+
* @param {unknown} target
|
|
8420
|
+
* @param {URL} packageJsonUrl
|
|
8421
|
+
* @param {boolean} internal
|
|
8422
|
+
* @param {URL} [base]
|
|
8423
|
+
* @returns {never}
|
|
8424
|
+
*/
|
|
8425
|
+
function throwInvalidPackageTarget(
|
|
8426
|
+
subpath,
|
|
8427
|
+
target,
|
|
8428
|
+
packageJsonUrl,
|
|
8429
|
+
internal,
|
|
8430
|
+
base
|
|
8431
|
+
) {
|
|
8432
|
+
target =
|
|
8433
|
+
typeof target === 'object' && target !== null
|
|
8434
|
+
? JSON.stringify(target, null, '')
|
|
8435
|
+
: `${target}`;
|
|
8436
|
+
|
|
8437
|
+
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
8438
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
8439
|
+
subpath,
|
|
8440
|
+
target,
|
|
8441
|
+
internal,
|
|
8442
|
+
base && fileURLToPath$2(base)
|
|
8443
|
+
)
|
|
8444
|
+
}
|
|
8445
|
+
|
|
8446
|
+
/**
|
|
8447
|
+
* @param {string} target
|
|
8448
|
+
* @param {string} subpath
|
|
8449
|
+
* @param {string} match
|
|
8450
|
+
* @param {URL} packageJsonUrl
|
|
8451
|
+
* @param {URL} base
|
|
8452
|
+
* @param {boolean} pattern
|
|
8453
|
+
* @param {boolean} internal
|
|
8454
|
+
* @param {Set<string>} conditions
|
|
8455
|
+
* @returns {URL}
|
|
8456
|
+
*/
|
|
8457
|
+
function resolvePackageTargetString(
|
|
8458
|
+
target,
|
|
8459
|
+
subpath,
|
|
8460
|
+
match,
|
|
8461
|
+
packageJsonUrl,
|
|
8462
|
+
base,
|
|
8463
|
+
pattern,
|
|
8464
|
+
internal,
|
|
8465
|
+
conditions
|
|
8466
|
+
) {
|
|
8467
|
+
if (subpath !== '' && !pattern && target[target.length - 1] !== '/')
|
|
8468
|
+
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8469
|
+
|
|
8470
|
+
if (!target.startsWith('./')) {
|
|
8471
|
+
if (internal && !target.startsWith('../') && !target.startsWith('/')) {
|
|
8472
|
+
let isURL = false;
|
|
8473
|
+
|
|
8474
|
+
try {
|
|
8475
|
+
new URL$1(target);
|
|
8476
|
+
isURL = true;
|
|
8477
|
+
} catch {}
|
|
8478
|
+
|
|
8479
|
+
if (!isURL) {
|
|
8480
|
+
const exportTarget = pattern
|
|
8481
|
+
? target.replace(patternRegEx, subpath)
|
|
8482
|
+
: target + subpath;
|
|
8483
|
+
|
|
8484
|
+
return packageResolve(exportTarget, packageJsonUrl, conditions)
|
|
8485
|
+
}
|
|
8486
|
+
}
|
|
8487
|
+
|
|
8488
|
+
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8489
|
+
}
|
|
8490
|
+
|
|
8491
|
+
if (invalidSegmentRegEx.test(target.slice(2)))
|
|
8492
|
+
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8493
|
+
|
|
8494
|
+
const resolved = new URL$1(target, packageJsonUrl);
|
|
8495
|
+
const resolvedPath = resolved.pathname;
|
|
8496
|
+
const packagePath = new URL$1('.', packageJsonUrl).pathname;
|
|
8497
|
+
|
|
8498
|
+
if (!resolvedPath.startsWith(packagePath))
|
|
8499
|
+
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
8500
|
+
|
|
8501
|
+
if (subpath === '') return resolved
|
|
8502
|
+
|
|
8503
|
+
if (invalidSegmentRegEx.test(subpath))
|
|
8504
|
+
throwInvalidSubpath(match + subpath, packageJsonUrl, internal, base);
|
|
8505
|
+
|
|
8506
|
+
if (pattern) return new URL$1(resolved.href.replace(patternRegEx, subpath))
|
|
8507
|
+
return new URL$1(subpath, resolved)
|
|
8508
|
+
}
|
|
8509
|
+
|
|
8510
|
+
/**
|
|
8511
|
+
* @param {string} key
|
|
8512
|
+
* @returns {boolean}
|
|
8513
|
+
*/
|
|
8514
|
+
function isArrayIndex(key) {
|
|
8515
|
+
const keyNumber = Number(key);
|
|
8516
|
+
if (`${keyNumber}` !== key) return false
|
|
8517
|
+
return keyNumber >= 0 && keyNumber < 0xffff_ffff
|
|
8518
|
+
}
|
|
8519
|
+
|
|
8520
|
+
/**
|
|
8521
|
+
* @param {URL} packageJsonUrl
|
|
8522
|
+
* @param {unknown} target
|
|
8523
|
+
* @param {string} subpath
|
|
8524
|
+
* @param {string} packageSubpath
|
|
8525
|
+
* @param {URL} base
|
|
8526
|
+
* @param {boolean} pattern
|
|
8527
|
+
* @param {boolean} internal
|
|
8528
|
+
* @param {Set<string>} conditions
|
|
8529
|
+
* @returns {URL}
|
|
8530
|
+
*/
|
|
8531
|
+
function resolvePackageTarget(
|
|
8532
|
+
packageJsonUrl,
|
|
8533
|
+
target,
|
|
8534
|
+
subpath,
|
|
8535
|
+
packageSubpath,
|
|
8536
|
+
base,
|
|
8537
|
+
pattern,
|
|
8538
|
+
internal,
|
|
8539
|
+
conditions
|
|
8540
|
+
) {
|
|
8541
|
+
if (typeof target === 'string') {
|
|
8542
|
+
return resolvePackageTargetString(
|
|
8543
|
+
target,
|
|
8544
|
+
subpath,
|
|
8545
|
+
packageSubpath,
|
|
8546
|
+
packageJsonUrl,
|
|
8547
|
+
base,
|
|
8548
|
+
pattern,
|
|
8549
|
+
internal,
|
|
8550
|
+
conditions
|
|
8551
|
+
)
|
|
8552
|
+
}
|
|
8553
|
+
|
|
8554
|
+
if (Array.isArray(target)) {
|
|
8555
|
+
/** @type {unknown[]} */
|
|
8556
|
+
const targetList = target;
|
|
8557
|
+
if (targetList.length === 0) return null
|
|
8558
|
+
|
|
8559
|
+
/** @type {Error} */
|
|
8560
|
+
let lastException;
|
|
8561
|
+
let i = -1;
|
|
8562
|
+
|
|
8563
|
+
while (++i < targetList.length) {
|
|
8564
|
+
const targetItem = targetList[i];
|
|
8565
|
+
/** @type {URL} */
|
|
8566
|
+
let resolved;
|
|
8567
|
+
try {
|
|
8568
|
+
resolved = resolvePackageTarget(
|
|
8569
|
+
packageJsonUrl,
|
|
8570
|
+
targetItem,
|
|
8571
|
+
subpath,
|
|
8572
|
+
packageSubpath,
|
|
8573
|
+
base,
|
|
8574
|
+
pattern,
|
|
8575
|
+
internal,
|
|
8576
|
+
conditions
|
|
8577
|
+
);
|
|
8578
|
+
} catch (error) {
|
|
8579
|
+
lastException = error;
|
|
8580
|
+
if (error.code === 'ERR_INVALID_PACKAGE_TARGET') continue
|
|
8581
|
+
throw error
|
|
8582
|
+
}
|
|
8583
|
+
|
|
8584
|
+
if (resolved === undefined) continue
|
|
8585
|
+
|
|
8586
|
+
if (resolved === null) {
|
|
8587
|
+
lastException = null;
|
|
8588
|
+
continue
|
|
8589
|
+
}
|
|
8590
|
+
|
|
8591
|
+
return resolved
|
|
8592
|
+
}
|
|
8593
|
+
|
|
8594
|
+
if (lastException === undefined || lastException === null) {
|
|
8595
|
+
// @ts-expect-error The diff between `undefined` and `null` seems to be
|
|
8596
|
+
// intentional
|
|
8597
|
+
return lastException
|
|
8598
|
+
}
|
|
8599
|
+
|
|
8600
|
+
throw lastException
|
|
8601
|
+
}
|
|
8602
|
+
|
|
8603
|
+
if (typeof target === 'object' && target !== null) {
|
|
8604
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
8605
|
+
let i = -1;
|
|
8606
|
+
|
|
8607
|
+
while (++i < keys.length) {
|
|
8608
|
+
const key = keys[i];
|
|
8609
|
+
if (isArrayIndex(key)) {
|
|
8610
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
8611
|
+
fileURLToPath$2(packageJsonUrl),
|
|
8612
|
+
base,
|
|
8613
|
+
'"exports" cannot contain numeric property keys.'
|
|
8614
|
+
)
|
|
8615
|
+
}
|
|
8616
|
+
}
|
|
8617
|
+
|
|
8618
|
+
i = -1;
|
|
8619
|
+
|
|
8620
|
+
while (++i < keys.length) {
|
|
8621
|
+
const key = keys[i];
|
|
8622
|
+
if (key === 'default' || (conditions && conditions.has(key))) {
|
|
8623
|
+
/** @type {unknown} */
|
|
8624
|
+
const conditionalTarget = target[key];
|
|
8625
|
+
const resolved = resolvePackageTarget(
|
|
8626
|
+
packageJsonUrl,
|
|
8627
|
+
conditionalTarget,
|
|
8628
|
+
subpath,
|
|
8629
|
+
packageSubpath,
|
|
8630
|
+
base,
|
|
8631
|
+
pattern,
|
|
8632
|
+
internal,
|
|
8633
|
+
conditions
|
|
8634
|
+
);
|
|
8635
|
+
if (resolved === undefined) continue
|
|
8636
|
+
return resolved
|
|
8637
|
+
}
|
|
8638
|
+
}
|
|
8639
|
+
|
|
8640
|
+
return undefined
|
|
8641
|
+
}
|
|
8642
|
+
|
|
8643
|
+
if (target === null) {
|
|
8644
|
+
return null
|
|
8645
|
+
}
|
|
8646
|
+
|
|
8647
|
+
throwInvalidPackageTarget(
|
|
8648
|
+
packageSubpath,
|
|
8649
|
+
target,
|
|
8650
|
+
packageJsonUrl,
|
|
8651
|
+
internal,
|
|
8652
|
+
base
|
|
8653
|
+
);
|
|
8654
|
+
}
|
|
8655
|
+
|
|
8656
|
+
/**
|
|
8657
|
+
* @param {unknown} exports
|
|
8658
|
+
* @param {URL} packageJsonUrl
|
|
8659
|
+
* @param {URL} base
|
|
8660
|
+
* @returns {boolean}
|
|
8661
|
+
*/
|
|
8662
|
+
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
8663
|
+
if (typeof exports === 'string' || Array.isArray(exports)) return true
|
|
8664
|
+
if (typeof exports !== 'object' || exports === null) return false
|
|
8665
|
+
|
|
8666
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
8667
|
+
let isConditionalSugar = false;
|
|
8668
|
+
let i = 0;
|
|
8669
|
+
let j = -1;
|
|
8670
|
+
while (++j < keys.length) {
|
|
8671
|
+
const key = keys[j];
|
|
8672
|
+
const curIsConditionalSugar = key === '' || key[0] !== '.';
|
|
8673
|
+
if (i++ === 0) {
|
|
8674
|
+
isConditionalSugar = curIsConditionalSugar;
|
|
8675
|
+
} else if (isConditionalSugar !== curIsConditionalSugar) {
|
|
8676
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
8677
|
+
fileURLToPath$2(packageJsonUrl),
|
|
8678
|
+
base,
|
|
8679
|
+
'"exports" cannot contain some keys starting with \'.\' and some not.' +
|
|
8680
|
+
' The exports object must either be an object of package subpath keys' +
|
|
8681
|
+
' or an object of main entry condition name keys only.'
|
|
8682
|
+
)
|
|
8683
|
+
}
|
|
8684
|
+
}
|
|
8685
|
+
|
|
8686
|
+
return isConditionalSugar
|
|
8687
|
+
}
|
|
8688
|
+
|
|
8689
|
+
/**
|
|
8690
|
+
* @param {URL} packageJsonUrl
|
|
8691
|
+
* @param {string} packageSubpath
|
|
8692
|
+
* @param {Object.<string, unknown>} packageConfig
|
|
8693
|
+
* @param {URL} base
|
|
8694
|
+
* @param {Set<string>} conditions
|
|
8695
|
+
* @returns {ResolveObject}
|
|
8696
|
+
*/
|
|
8697
|
+
function packageExportsResolve(
|
|
8698
|
+
packageJsonUrl,
|
|
8699
|
+
packageSubpath,
|
|
8700
|
+
packageConfig,
|
|
8701
|
+
base,
|
|
8702
|
+
conditions
|
|
8703
|
+
) {
|
|
8704
|
+
let exports = packageConfig.exports;
|
|
8705
|
+
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base))
|
|
8706
|
+
exports = {'.': exports};
|
|
8707
|
+
|
|
8708
|
+
if (own.call(exports, packageSubpath)) {
|
|
8709
|
+
const target = exports[packageSubpath];
|
|
8710
|
+
const resolved = resolvePackageTarget(
|
|
8711
|
+
packageJsonUrl,
|
|
8712
|
+
target,
|
|
8713
|
+
'',
|
|
8714
|
+
packageSubpath,
|
|
8715
|
+
base,
|
|
8716
|
+
false,
|
|
8717
|
+
false,
|
|
8718
|
+
conditions
|
|
8719
|
+
);
|
|
8720
|
+
if (resolved === null || resolved === undefined)
|
|
8721
|
+
throwExportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
8722
|
+
return {resolved, exact: true}
|
|
8723
|
+
}
|
|
8724
|
+
|
|
8725
|
+
let bestMatch = '';
|
|
8726
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
8727
|
+
let i = -1;
|
|
8728
|
+
|
|
8729
|
+
while (++i < keys.length) {
|
|
8730
|
+
const key = keys[i];
|
|
8731
|
+
if (
|
|
8732
|
+
key[key.length - 1] === '*' &&
|
|
8733
|
+
packageSubpath.startsWith(key.slice(0, -1)) &&
|
|
8734
|
+
packageSubpath.length >= key.length &&
|
|
8735
|
+
key.length > bestMatch.length
|
|
8736
|
+
) {
|
|
8737
|
+
bestMatch = key;
|
|
8738
|
+
} else if (
|
|
8739
|
+
key[key.length - 1] === '/' &&
|
|
8740
|
+
packageSubpath.startsWith(key) &&
|
|
8741
|
+
key.length > bestMatch.length
|
|
8742
|
+
) {
|
|
8743
|
+
bestMatch = key;
|
|
8744
|
+
}
|
|
8745
|
+
}
|
|
8746
|
+
|
|
8747
|
+
if (bestMatch) {
|
|
8748
|
+
const target = exports[bestMatch];
|
|
8749
|
+
const pattern = bestMatch[bestMatch.length - 1] === '*';
|
|
8750
|
+
const subpath = packageSubpath.slice(bestMatch.length - (pattern ? 1 : 0));
|
|
8751
|
+
const resolved = resolvePackageTarget(
|
|
8752
|
+
packageJsonUrl,
|
|
8753
|
+
target,
|
|
8754
|
+
subpath,
|
|
8755
|
+
bestMatch,
|
|
8756
|
+
base,
|
|
8757
|
+
pattern,
|
|
8758
|
+
false,
|
|
8759
|
+
conditions
|
|
8760
|
+
);
|
|
8761
|
+
if (resolved === null || resolved === undefined)
|
|
8762
|
+
throwExportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
8763
|
+
if (!pattern)
|
|
8764
|
+
emitFolderMapDeprecation(bestMatch, packageJsonUrl, true, base);
|
|
8765
|
+
return {resolved, exact: pattern}
|
|
8766
|
+
}
|
|
8767
|
+
|
|
8768
|
+
throwExportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
8769
|
+
}
|
|
8770
|
+
|
|
8771
|
+
/**
|
|
8772
|
+
* @param {string} name
|
|
8773
|
+
* @param {URL} base
|
|
8774
|
+
* @param {Set<string>} [conditions]
|
|
8775
|
+
* @returns {ResolveObject}
|
|
8776
|
+
*/
|
|
8777
|
+
function packageImportsResolve(name, base, conditions) {
|
|
8778
|
+
if (name === '#' || name.startsWith('#/')) {
|
|
8779
|
+
const reason = 'is not a valid internal imports specifier name';
|
|
8780
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath$2(base))
|
|
8781
|
+
}
|
|
8782
|
+
|
|
8783
|
+
/** @type {URL} */
|
|
8784
|
+
let packageJsonUrl;
|
|
8785
|
+
|
|
8786
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
8787
|
+
|
|
8788
|
+
if (packageConfig.exists) {
|
|
8789
|
+
packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
8790
|
+
const imports = packageConfig.imports;
|
|
8791
|
+
if (imports) {
|
|
8792
|
+
if (own.call(imports, name)) {
|
|
8793
|
+
const resolved = resolvePackageTarget(
|
|
8794
|
+
packageJsonUrl,
|
|
8795
|
+
imports[name],
|
|
8796
|
+
'',
|
|
8797
|
+
name,
|
|
8798
|
+
base,
|
|
8799
|
+
false,
|
|
8800
|
+
true,
|
|
8801
|
+
conditions
|
|
8802
|
+
);
|
|
8803
|
+
if (resolved !== null) return {resolved, exact: true}
|
|
8804
|
+
} else {
|
|
8805
|
+
let bestMatch = '';
|
|
8806
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
8807
|
+
let i = -1;
|
|
8808
|
+
|
|
8809
|
+
while (++i < keys.length) {
|
|
8810
|
+
const key = keys[i];
|
|
8811
|
+
|
|
8812
|
+
if (
|
|
8813
|
+
key[key.length - 1] === '*' &&
|
|
8814
|
+
name.startsWith(key.slice(0, -1)) &&
|
|
8815
|
+
name.length >= key.length &&
|
|
8816
|
+
key.length > bestMatch.length
|
|
8817
|
+
) {
|
|
8818
|
+
bestMatch = key;
|
|
8819
|
+
} else if (
|
|
8820
|
+
key[key.length - 1] === '/' &&
|
|
8821
|
+
name.startsWith(key) &&
|
|
8822
|
+
key.length > bestMatch.length
|
|
8823
|
+
) {
|
|
8824
|
+
bestMatch = key;
|
|
8825
|
+
}
|
|
8826
|
+
}
|
|
8827
|
+
|
|
8828
|
+
if (bestMatch) {
|
|
8829
|
+
const target = imports[bestMatch];
|
|
8830
|
+
const pattern = bestMatch[bestMatch.length - 1] === '*';
|
|
8831
|
+
const subpath = name.slice(bestMatch.length - (pattern ? 1 : 0));
|
|
8832
|
+
const resolved = resolvePackageTarget(
|
|
8833
|
+
packageJsonUrl,
|
|
8834
|
+
target,
|
|
8835
|
+
subpath,
|
|
8836
|
+
bestMatch,
|
|
8837
|
+
base,
|
|
8838
|
+
pattern,
|
|
8839
|
+
true,
|
|
8840
|
+
conditions
|
|
8841
|
+
);
|
|
8842
|
+
if (resolved !== null) {
|
|
8843
|
+
if (!pattern)
|
|
8844
|
+
emitFolderMapDeprecation(bestMatch, packageJsonUrl, false, base);
|
|
8845
|
+
return {resolved, exact: pattern}
|
|
8846
|
+
}
|
|
8847
|
+
}
|
|
8848
|
+
}
|
|
8849
|
+
}
|
|
8850
|
+
}
|
|
8851
|
+
|
|
8852
|
+
throwImportNotDefined(name, packageJsonUrl, base);
|
|
8853
|
+
}
|
|
8854
|
+
|
|
8855
|
+
/**
|
|
8856
|
+
* @param {string} url
|
|
8857
|
+
* @returns {PackageType}
|
|
8858
|
+
*/
|
|
8859
|
+
function getPackageType(url) {
|
|
8860
|
+
const packageConfig = getPackageScopeConfig(url);
|
|
8861
|
+
return packageConfig.type
|
|
8195
8862
|
}
|
|
8863
|
+
|
|
8864
|
+
/**
|
|
8865
|
+
* @param {string} specifier
|
|
8866
|
+
* @param {URL} base
|
|
8867
|
+
*/
|
|
8868
|
+
function parsePackageName(specifier, base) {
|
|
8869
|
+
let separatorIndex = specifier.indexOf('/');
|
|
8870
|
+
let validPackageName = true;
|
|
8871
|
+
let isScoped = false;
|
|
8872
|
+
if (specifier[0] === '@') {
|
|
8873
|
+
isScoped = true;
|
|
8874
|
+
if (separatorIndex === -1 || specifier.length === 0) {
|
|
8875
|
+
validPackageName = false;
|
|
8876
|
+
} else {
|
|
8877
|
+
separatorIndex = specifier.indexOf('/', separatorIndex + 1);
|
|
8878
|
+
}
|
|
8879
|
+
}
|
|
8880
|
+
|
|
8881
|
+
const packageName =
|
|
8882
|
+
separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
8883
|
+
|
|
8884
|
+
// Package name cannot have leading . and cannot have percent-encoding or
|
|
8885
|
+
// separators.
|
|
8886
|
+
let i = -1;
|
|
8887
|
+
while (++i < packageName.length) {
|
|
8888
|
+
if (packageName[i] === '%' || packageName[i] === '\\') {
|
|
8889
|
+
validPackageName = false;
|
|
8890
|
+
break
|
|
8891
|
+
}
|
|
8892
|
+
}
|
|
8893
|
+
|
|
8894
|
+
if (!validPackageName) {
|
|
8895
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
8896
|
+
specifier,
|
|
8897
|
+
'is not a valid package name',
|
|
8898
|
+
fileURLToPath$2(base)
|
|
8899
|
+
)
|
|
8900
|
+
}
|
|
8901
|
+
|
|
8902
|
+
const packageSubpath =
|
|
8903
|
+
'.' + (separatorIndex === -1 ? '' : specifier.slice(separatorIndex));
|
|
8904
|
+
|
|
8905
|
+
return {packageName, packageSubpath, isScoped}
|
|
8906
|
+
}
|
|
8907
|
+
|
|
8908
|
+
/**
|
|
8909
|
+
* @param {string} specifier
|
|
8910
|
+
* @param {URL} base
|
|
8911
|
+
* @param {Set<string>} conditions
|
|
8912
|
+
* @returns {URL}
|
|
8913
|
+
*/
|
|
8914
|
+
function packageResolve(specifier, base, conditions) {
|
|
8915
|
+
const {packageName, packageSubpath, isScoped} = parsePackageName(
|
|
8916
|
+
specifier,
|
|
8917
|
+
base
|
|
8918
|
+
);
|
|
8919
|
+
|
|
8920
|
+
// ResolveSelf
|
|
8921
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
8922
|
+
|
|
8923
|
+
// Can’t test.
|
|
8924
|
+
/* c8 ignore next 16 */
|
|
8925
|
+
if (packageConfig.exists) {
|
|
8926
|
+
const packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
8927
|
+
if (
|
|
8928
|
+
packageConfig.name === packageName &&
|
|
8929
|
+
packageConfig.exports !== undefined &&
|
|
8930
|
+
packageConfig.exports !== null
|
|
8931
|
+
) {
|
|
8932
|
+
return packageExportsResolve(
|
|
8933
|
+
packageJsonUrl,
|
|
8934
|
+
packageSubpath,
|
|
8935
|
+
packageConfig,
|
|
8936
|
+
base,
|
|
8937
|
+
conditions
|
|
8938
|
+
).resolved
|
|
8939
|
+
}
|
|
8940
|
+
}
|
|
8941
|
+
|
|
8942
|
+
let packageJsonUrl = new URL$1(
|
|
8943
|
+
'./node_modules/' + packageName + '/package.json',
|
|
8944
|
+
base
|
|
8945
|
+
);
|
|
8946
|
+
let packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
8947
|
+
/** @type {string} */
|
|
8948
|
+
let lastPath;
|
|
8949
|
+
do {
|
|
8950
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
8951
|
+
if (!stat.isDirectory()) {
|
|
8952
|
+
lastPath = packageJsonPath;
|
|
8953
|
+
packageJsonUrl = new URL$1(
|
|
8954
|
+
(isScoped ? '../../../../node_modules/' : '../../../node_modules/') +
|
|
8955
|
+
packageName +
|
|
8956
|
+
'/package.json',
|
|
8957
|
+
packageJsonUrl
|
|
8958
|
+
);
|
|
8959
|
+
packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
8960
|
+
continue
|
|
8961
|
+
}
|
|
8962
|
+
|
|
8963
|
+
// Package match.
|
|
8964
|
+
const packageConfig = getPackageConfig(packageJsonPath, specifier, base);
|
|
8965
|
+
if (packageConfig.exports !== undefined && packageConfig.exports !== null)
|
|
8966
|
+
return packageExportsResolve(
|
|
8967
|
+
packageJsonUrl,
|
|
8968
|
+
packageSubpath,
|
|
8969
|
+
packageConfig,
|
|
8970
|
+
base,
|
|
8971
|
+
conditions
|
|
8972
|
+
).resolved
|
|
8973
|
+
if (packageSubpath === '.')
|
|
8974
|
+
return legacyMainResolve(packageJsonUrl, packageConfig, base)
|
|
8975
|
+
return new URL$1(packageSubpath, packageJsonUrl)
|
|
8976
|
+
// Cross-platform root check.
|
|
8977
|
+
} while (packageJsonPath.length !== lastPath.length)
|
|
8978
|
+
|
|
8979
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath$2(base))
|
|
8980
|
+
}
|
|
8981
|
+
|
|
8982
|
+
/**
|
|
8983
|
+
* @param {string} specifier
|
|
8984
|
+
* @returns {boolean}
|
|
8985
|
+
*/
|
|
8986
|
+
function isRelativeSpecifier(specifier) {
|
|
8987
|
+
if (specifier[0] === '.') {
|
|
8988
|
+
if (specifier.length === 1 || specifier[1] === '/') return true
|
|
8989
|
+
if (
|
|
8990
|
+
specifier[1] === '.' &&
|
|
8991
|
+
(specifier.length === 2 || specifier[2] === '/')
|
|
8992
|
+
) {
|
|
8993
|
+
return true
|
|
8994
|
+
}
|
|
8995
|
+
}
|
|
8996
|
+
|
|
8997
|
+
return false
|
|
8998
|
+
}
|
|
8999
|
+
|
|
9000
|
+
/**
|
|
9001
|
+
* @param {string} specifier
|
|
9002
|
+
* @returns {boolean}
|
|
9003
|
+
*/
|
|
9004
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
9005
|
+
if (specifier === '') return false
|
|
9006
|
+
if (specifier[0] === '/') return true
|
|
9007
|
+
return isRelativeSpecifier(specifier)
|
|
9008
|
+
}
|
|
9009
|
+
|
|
9010
|
+
/**
|
|
9011
|
+
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
9012
|
+
* sync and slightly lower-level than `resolve`).
|
|
9013
|
+
*
|
|
9014
|
+
*
|
|
9015
|
+
*
|
|
9016
|
+
* @param {string} specifier
|
|
9017
|
+
* @param {URL} base
|
|
9018
|
+
* @param {Set<string>} [conditions]
|
|
9019
|
+
* @returns {URL}
|
|
9020
|
+
*/
|
|
9021
|
+
function moduleResolve(specifier, base, conditions) {
|
|
9022
|
+
// Order swapped from spec for minor perf gain.
|
|
9023
|
+
// Ok since relative URLs cannot parse as URLs.
|
|
9024
|
+
/** @type {URL} */
|
|
9025
|
+
let resolved;
|
|
9026
|
+
|
|
9027
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
9028
|
+
resolved = new URL$1(specifier, base);
|
|
9029
|
+
} else if (specifier[0] === '#') {
|
|
9030
|
+
({resolved} = packageImportsResolve(specifier, base, conditions));
|
|
9031
|
+
} else {
|
|
9032
|
+
try {
|
|
9033
|
+
resolved = new URL$1(specifier);
|
|
9034
|
+
} catch {
|
|
9035
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
9036
|
+
}
|
|
9037
|
+
}
|
|
9038
|
+
|
|
9039
|
+
return finalizeResolution(resolved, base)
|
|
9040
|
+
}
|
|
9041
|
+
|
|
9042
|
+
const DEFAULT_CONDITIONS_SET = new Set(["node", "import"]);
|
|
9043
|
+
const DEFAULT_URL = pathToFileURL(process.cwd());
|
|
9044
|
+
const DEFAULT_EXTENSIONS = [".mjs", ".cjs", ".js", ".json"];
|
|
9045
|
+
const NOT_FOUND_ERRORS = new Set(["ERR_MODULE_NOT_FOUND", "ERR_UNSUPPORTED_DIR_IMPORT", "MODULE_NOT_FOUND"]);
|
|
9046
|
+
function _tryModuleResolve(id, url, conditions) {
|
|
9047
|
+
try {
|
|
9048
|
+
return moduleResolve(id, url, conditions);
|
|
9049
|
+
} catch (err) {
|
|
9050
|
+
if (!NOT_FOUND_ERRORS.has(err.code)) {
|
|
9051
|
+
throw err;
|
|
9052
|
+
}
|
|
9053
|
+
return null;
|
|
9054
|
+
}
|
|
9055
|
+
}
|
|
9056
|
+
function _resolve(id, opts = {}) {
|
|
9057
|
+
if (/(node|data|http|https):/.test(id)) {
|
|
9058
|
+
return id;
|
|
9059
|
+
}
|
|
9060
|
+
if (BUILTIN_MODULES.has(id)) {
|
|
9061
|
+
return "node:" + id;
|
|
9062
|
+
}
|
|
9063
|
+
if (isAbsolute(id)) {
|
|
9064
|
+
return id;
|
|
9065
|
+
}
|
|
9066
|
+
const conditionsSet = opts.conditions ? new Set(opts.conditions) : DEFAULT_CONDITIONS_SET;
|
|
9067
|
+
const _urls = (Array.isArray(opts.url) ? opts.url : [opts.url]).filter(Boolean).map((u) => new URL(normalizeid(u.toString())));
|
|
9068
|
+
if (!_urls.length) {
|
|
9069
|
+
_urls.push(DEFAULT_URL);
|
|
9070
|
+
}
|
|
9071
|
+
const urls = [..._urls];
|
|
9072
|
+
for (const url of _urls) {
|
|
9073
|
+
if (url.protocol === "file:" && !url.pathname.includes("node_modules")) {
|
|
9074
|
+
const newURL = new URL(url);
|
|
9075
|
+
newURL.pathname += "/node_modules";
|
|
9076
|
+
urls.push(newURL);
|
|
9077
|
+
}
|
|
9078
|
+
}
|
|
9079
|
+
let resolved;
|
|
9080
|
+
for (const url of urls) {
|
|
9081
|
+
resolved = _tryModuleResolve(id, url, conditionsSet);
|
|
9082
|
+
if (resolved) {
|
|
9083
|
+
break;
|
|
9084
|
+
}
|
|
9085
|
+
for (const prefix of ["", "/index"]) {
|
|
9086
|
+
for (const ext of opts.extensions || DEFAULT_EXTENSIONS) {
|
|
9087
|
+
resolved = _tryModuleResolve(id + prefix + ext, url, conditionsSet);
|
|
9088
|
+
if (resolved) {
|
|
9089
|
+
break;
|
|
9090
|
+
}
|
|
9091
|
+
}
|
|
9092
|
+
if (resolved) {
|
|
9093
|
+
break;
|
|
9094
|
+
}
|
|
9095
|
+
}
|
|
9096
|
+
}
|
|
9097
|
+
if (!resolved) {
|
|
9098
|
+
const err = new Error(`Cannot find module ${id} imported from ${urls.join(", ")}`);
|
|
9099
|
+
err.code = "ERR_MODULE_NOT_FOUND";
|
|
9100
|
+
throw err;
|
|
9101
|
+
}
|
|
9102
|
+
const realPath = realpathSync(fileURLToPath(resolved));
|
|
9103
|
+
return pathToFileURL(realPath).toString();
|
|
9104
|
+
}
|
|
9105
|
+
function resolveSync(id, opts) {
|
|
9106
|
+
return _resolve(id, opts);
|
|
9107
|
+
}
|
|
9108
|
+
function resolvePathSync(id, opts) {
|
|
9109
|
+
return fileURLToPath(resolveSync(id, opts));
|
|
9110
|
+
}
|
|
9111
|
+
function resolvePath(id, opts) {
|
|
9112
|
+
return pcall(resolvePathSync, id, opts);
|
|
9113
|
+
}
|
|
9114
|
+
|
|
9115
|
+
const defaultFindOptions = {
|
|
9116
|
+
startingFrom: ".",
|
|
9117
|
+
rootPattern: /^node_modules$/,
|
|
9118
|
+
test: (filePath) => {
|
|
9119
|
+
try {
|
|
9120
|
+
if (statSync(filePath).isFile()) {
|
|
9121
|
+
return true;
|
|
9122
|
+
}
|
|
9123
|
+
} catch {
|
|
9124
|
+
}
|
|
9125
|
+
return null;
|
|
9126
|
+
}
|
|
9127
|
+
};
|
|
9128
|
+
async function findNearestFile(filename, _options = {}) {
|
|
9129
|
+
const options = { ...defaultFindOptions, ..._options };
|
|
9130
|
+
const basePath = resolve$2(options.startingFrom);
|
|
9131
|
+
const leadingSlash = basePath[0] === "/";
|
|
9132
|
+
const segments = basePath.split("/").filter(Boolean);
|
|
9133
|
+
if (leadingSlash) {
|
|
9134
|
+
segments[0] = "/" + segments[0];
|
|
9135
|
+
}
|
|
9136
|
+
let root = segments.findIndex((r) => r.match(options.rootPattern));
|
|
9137
|
+
if (root === -1)
|
|
9138
|
+
root = 0;
|
|
9139
|
+
for (let i = segments.length; i > root; i--) {
|
|
9140
|
+
const filePath = join$1(...segments.slice(0, i), filename);
|
|
9141
|
+
if (await options.test(filePath)) {
|
|
9142
|
+
return filePath;
|
|
9143
|
+
}
|
|
9144
|
+
}
|
|
9145
|
+
throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
|
|
9146
|
+
}
|
|
9147
|
+
async function readPackageJSON(id, opts = {}) {
|
|
9148
|
+
const resolvedPath = await resolvePackageJSON(id, opts);
|
|
9149
|
+
const blob = await promises.readFile(resolvedPath, "utf-8");
|
|
9150
|
+
return JSON.parse(blob);
|
|
9151
|
+
}
|
|
9152
|
+
async function resolvePackageJSON(id = process.cwd(), opts = {}) {
|
|
9153
|
+
const resolvedPath = isAbsolute$1(id) ? id : await resolvePath(id, opts);
|
|
9154
|
+
return findNearestFile("package.json", { startingFrom: resolvedPath });
|
|
9155
|
+
}
|
|
9156
|
+
|
|
8196
9157
|
const ESM_RE = /([\s;]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*(?:[*{]|default|type|function|const|var|let|async function)|import\.meta\b)/m;
|
|
8197
|
-
const BUILTIN_EXTENSIONS =
|
|
9158
|
+
const BUILTIN_EXTENSIONS = new Set([".mjs", ".cjs", ".node", ".wasm"]);
|
|
8198
9159
|
function hasESMSyntax(code) {
|
|
8199
9160
|
return ESM_RE.test(code);
|
|
8200
9161
|
}
|
|
9162
|
+
const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
|
|
9163
|
+
function hasCJSSyntax(code) {
|
|
9164
|
+
return CJS_RE.test(code);
|
|
9165
|
+
}
|
|
8201
9166
|
const validNodeImportDefaults = {
|
|
8202
9167
|
allowedProtocols: ["node", "file", "data"]
|
|
8203
9168
|
};
|
|
8204
9169
|
async function isValidNodeImport(id, _opts = {}) {
|
|
8205
|
-
|
|
8206
|
-
if (isNodeBuiltin(id))
|
|
9170
|
+
if (isNodeBuiltin(id)) {
|
|
8207
9171
|
return true;
|
|
8208
|
-
|
|
9172
|
+
}
|
|
9173
|
+
const opts = { ...validNodeImportDefaults, ..._opts };
|
|
8209
9174
|
const proto = getProtocol(id);
|
|
8210
|
-
if (proto && !
|
|
9175
|
+
if (proto && !opts.allowedProtocols.includes(proto)) {
|
|
8211
9176
|
return false;
|
|
8212
|
-
|
|
9177
|
+
}
|
|
9178
|
+
if (proto === "data") {
|
|
8213
9179
|
return true;
|
|
9180
|
+
}
|
|
8214
9181
|
const resolvedPath = await resolvePath$1(id, opts);
|
|
8215
|
-
const extension = extname$
|
|
8216
|
-
if (BUILTIN_EXTENSIONS.has(extension))
|
|
9182
|
+
const extension = extname$1(resolvedPath);
|
|
9183
|
+
if (BUILTIN_EXTENSIONS.has(extension)) {
|
|
8217
9184
|
return true;
|
|
8218
|
-
|
|
9185
|
+
}
|
|
9186
|
+
if (extension !== ".js") {
|
|
8219
9187
|
return false;
|
|
8220
|
-
|
|
9188
|
+
}
|
|
9189
|
+
if (resolvedPath.match(/\.(\w+-)?esm?(-\w+)?\.js$/)) {
|
|
8221
9190
|
return false;
|
|
9191
|
+
}
|
|
8222
9192
|
const pkg = await readPackageJSON(resolvedPath).catch(() => null);
|
|
8223
|
-
if (
|
|
9193
|
+
if (pkg?.type === "module") {
|
|
8224
9194
|
return true;
|
|
9195
|
+
}
|
|
8225
9196
|
const code = opts.code || await promises.readFile(resolvedPath, "utf-8").catch(() => null) || "";
|
|
8226
9197
|
return hasCJSSyntax(code) || !hasESMSyntax(code);
|
|
8227
9198
|
}
|
|
@@ -8276,7 +9247,7 @@ async function executeInViteNode(options) {
|
|
|
8276
9247
|
builtinModules.forEach((m) => externalCache.set(m, true));
|
|
8277
9248
|
const result = [];
|
|
8278
9249
|
for (const file of files)
|
|
8279
|
-
result.push(await cachedRequest(`/@fs/${slash(resolve
|
|
9250
|
+
result.push(await cachedRequest(`/@fs/${slash(resolve(file))}`, []));
|
|
8280
9251
|
return result;
|
|
8281
9252
|
async function directRequest(id, fsPath, callstack) {
|
|
8282
9253
|
callstack = [...callstack, id];
|
|
@@ -8300,7 +9271,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
8300
9271
|
const url = pathToFileURL(fsPath).href;
|
|
8301
9272
|
const exports = {};
|
|
8302
9273
|
setCache(fsPath, { code: transformed, exports });
|
|
8303
|
-
const __filename = fileURLToPath(url);
|
|
9274
|
+
const __filename = fileURLToPath$2(url);
|
|
8304
9275
|
const moduleProxy = {
|
|
8305
9276
|
set exports(value) {
|
|
8306
9277
|
exportAll(exports, value);
|
|
@@ -8320,10 +9291,10 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
8320
9291
|
exports,
|
|
8321
9292
|
module: moduleProxy,
|
|
8322
9293
|
__filename,
|
|
8323
|
-
__dirname: dirname$
|
|
9294
|
+
__dirname: dirname$2(__filename)
|
|
8324
9295
|
};
|
|
8325
|
-
const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{${transformed}
|
|
8326
|
-
}`, {
|
|
9296
|
+
const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{{${transformed}
|
|
9297
|
+
}}`, {
|
|
8327
9298
|
filename: fsPath,
|
|
8328
9299
|
lineOffset: 0
|
|
8329
9300
|
});
|
|
@@ -8371,15 +9342,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
8371
9342
|
}
|
|
8372
9343
|
}
|
|
8373
9344
|
function normalizeId(id) {
|
|
8374
|
-
|
|
8375
|
-
id = `\0${id.slice("/@id/__x00__".length)}`;
|
|
8376
|
-
if (id && id.startsWith("/@id/"))
|
|
8377
|
-
id = id.slice("/@id/".length);
|
|
8378
|
-
if (id.startsWith("__vite-browser-external:"))
|
|
8379
|
-
id = id.slice("__vite-browser-external:".length);
|
|
8380
|
-
if (id.startsWith("node:"))
|
|
8381
|
-
id = id.slice("node:".length);
|
|
8382
|
-
return id;
|
|
9345
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^node:/, "").replace(/[?&]v=\w+/, "?").replace(/\?$/, "");
|
|
8383
9346
|
}
|
|
8384
9347
|
async function shouldExternalize(id, config) {
|
|
8385
9348
|
if (matchExternalizePattern(id, config.inline))
|
|
@@ -8393,10 +9356,10 @@ async function shouldExternalize(id, config) {
|
|
|
8393
9356
|
return id.includes("/node_modules/") && await isValidNodeImport(id);
|
|
8394
9357
|
}
|
|
8395
9358
|
function toFilePath(id, root) {
|
|
8396
|
-
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$
|
|
9359
|
+
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$2(root)) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
|
|
8397
9360
|
if (absolute.startsWith("//"))
|
|
8398
9361
|
absolute = absolute.slice(1);
|
|
8399
|
-
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
9362
|
+
return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
8400
9363
|
}
|
|
8401
9364
|
function matchExternalizePattern(id, patterns) {
|
|
8402
9365
|
for (const ex of patterns) {
|
|
@@ -8434,7 +9397,7 @@ async function startViteNode(ctx) {
|
|
|
8434
9397
|
const { run: run2, collect: collect2 } = (await executeInViteNode({
|
|
8435
9398
|
root: config.root,
|
|
8436
9399
|
files: [
|
|
8437
|
-
resolve
|
|
9400
|
+
resolve(distDir, "entry.js")
|
|
8438
9401
|
],
|
|
8439
9402
|
fetch(id) {
|
|
8440
9403
|
return process.__vitest_worker__.rpc("fetch", id);
|