vitest 0.0.91 → 0.0.95
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 +6 -2
- package/dist/cli.js +19 -12
- package/dist/entry.js +138 -13
- package/dist/{error-abd1f726.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-5cc247ff.js +331 -0
- package/dist/index-e7a421bb.js +2409 -0
- package/dist/index-ece64e3c.js +5539 -0
- package/dist/index-fa899e66.js +5707 -0
- package/dist/index.d.ts +40 -11
- package/dist/index.js +2 -2
- package/dist/middleware-bf0f818d.js +78 -0
- package/dist/node.js +8 -7
- package/dist/{utils-5d0cec8a.js → utils-576876dc.js} +20 -9
- package/dist/utils.js +2 -2
- package/dist/worker.js +1300 -336
- package/package.json +10 -7
- package/dist/index-25bef3dd.js +0 -1896
- package/dist/middleware-52c3b35a.js +0 -34
package/dist/worker.js
CHANGED
|
@@ -1,209 +1,16 @@
|
|
|
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
|
-
|
|
14
|
-
function normalizeWindowsPath$2(input = "") {
|
|
15
|
-
if (!input.includes("\\")) {
|
|
16
|
-
return input;
|
|
17
|
-
}
|
|
18
|
-
return input.replace(/\\/g, "/");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const _UNC_REGEX$2 = /^[/][/]/;
|
|
22
|
-
const _UNC_DRIVE_REGEX$2 = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
|
|
23
|
-
const _IS_ABSOLUTE_RE$2 = /^\/|^\\|^[a-zA-Z]:[/\\]/;
|
|
24
|
-
const sep$2 = "/";
|
|
25
|
-
const delimiter$2 = ":";
|
|
26
|
-
const normalize$2 = function(path2) {
|
|
27
|
-
if (path2.length === 0) {
|
|
28
|
-
return ".";
|
|
29
|
-
}
|
|
30
|
-
path2 = normalizeWindowsPath$2(path2);
|
|
31
|
-
const isUNCPath = path2.match(_UNC_REGEX$2);
|
|
32
|
-
const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX$2);
|
|
33
|
-
const isPathAbsolute = isAbsolute$2(path2);
|
|
34
|
-
const trailingSeparator = path2[path2.length - 1] === "/";
|
|
35
|
-
path2 = normalizeString$2(path2, !isPathAbsolute);
|
|
36
|
-
if (path2.length === 0) {
|
|
37
|
-
if (isPathAbsolute) {
|
|
38
|
-
return "/";
|
|
39
|
-
}
|
|
40
|
-
return trailingSeparator ? "./" : ".";
|
|
41
|
-
}
|
|
42
|
-
if (trailingSeparator) {
|
|
43
|
-
path2 += "/";
|
|
44
|
-
}
|
|
45
|
-
if (isUNCPath) {
|
|
46
|
-
if (hasUNCDrive) {
|
|
47
|
-
return `//./${path2}`;
|
|
48
|
-
}
|
|
49
|
-
return `//${path2}`;
|
|
50
|
-
}
|
|
51
|
-
return isPathAbsolute && !isAbsolute$2(path2) ? `/${path2}` : path2;
|
|
52
|
-
};
|
|
53
|
-
const join$2 = function(...args) {
|
|
54
|
-
if (args.length === 0) {
|
|
55
|
-
return ".";
|
|
56
|
-
}
|
|
57
|
-
let joined;
|
|
58
|
-
for (let i = 0; i < args.length; ++i) {
|
|
59
|
-
const arg = args[i];
|
|
60
|
-
if (arg.length > 0) {
|
|
61
|
-
if (joined === void 0) {
|
|
62
|
-
joined = arg;
|
|
63
|
-
} else {
|
|
64
|
-
joined += `/${arg}`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (joined === void 0) {
|
|
69
|
-
return ".";
|
|
70
|
-
}
|
|
71
|
-
return normalize$2(joined);
|
|
72
|
-
};
|
|
73
|
-
const resolve = function(...args) {
|
|
74
|
-
args = args.map((arg) => normalizeWindowsPath$2(arg));
|
|
75
|
-
let resolvedPath = "";
|
|
76
|
-
let resolvedAbsolute = false;
|
|
77
|
-
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
78
|
-
const path2 = i >= 0 ? args[i] : process.cwd();
|
|
79
|
-
if (path2.length === 0) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
resolvedPath = `${path2}/${resolvedPath}`;
|
|
83
|
-
resolvedAbsolute = isAbsolute$2(path2);
|
|
84
|
-
}
|
|
85
|
-
resolvedPath = normalizeString$2(resolvedPath, !resolvedAbsolute);
|
|
86
|
-
if (resolvedAbsolute && !isAbsolute$2(resolvedPath)) {
|
|
87
|
-
return `/${resolvedPath}`;
|
|
88
|
-
}
|
|
89
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
90
|
-
};
|
|
91
|
-
function normalizeString$2(path2, allowAboveRoot) {
|
|
92
|
-
let res = "";
|
|
93
|
-
let lastSegmentLength = 0;
|
|
94
|
-
let lastSlash = -1;
|
|
95
|
-
let dots = 0;
|
|
96
|
-
let char = null;
|
|
97
|
-
for (let i = 0; i <= path2.length; ++i) {
|
|
98
|
-
if (i < path2.length) {
|
|
99
|
-
char = path2[i];
|
|
100
|
-
} else if (char === "/") {
|
|
101
|
-
break;
|
|
102
|
-
} else {
|
|
103
|
-
char = "/";
|
|
104
|
-
}
|
|
105
|
-
if (char === "/") {
|
|
106
|
-
if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
|
|
107
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
108
|
-
if (res.length > 2) {
|
|
109
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
110
|
-
if (lastSlashIndex === -1) {
|
|
111
|
-
res = "";
|
|
112
|
-
lastSegmentLength = 0;
|
|
113
|
-
} else {
|
|
114
|
-
res = res.slice(0, lastSlashIndex);
|
|
115
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
116
|
-
}
|
|
117
|
-
lastSlash = i;
|
|
118
|
-
dots = 0;
|
|
119
|
-
continue;
|
|
120
|
-
} else if (res.length !== 0) {
|
|
121
|
-
res = "";
|
|
122
|
-
lastSegmentLength = 0;
|
|
123
|
-
lastSlash = i;
|
|
124
|
-
dots = 0;
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (allowAboveRoot) {
|
|
129
|
-
res += res.length > 0 ? "/.." : "..";
|
|
130
|
-
lastSegmentLength = 2;
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
if (res.length > 0) {
|
|
134
|
-
res += `/${path2.slice(lastSlash + 1, i)}`;
|
|
135
|
-
} else {
|
|
136
|
-
res = path2.slice(lastSlash + 1, i);
|
|
137
|
-
}
|
|
138
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
139
|
-
}
|
|
140
|
-
lastSlash = i;
|
|
141
|
-
dots = 0;
|
|
142
|
-
} else if (char === "." && dots !== -1) {
|
|
143
|
-
++dots;
|
|
144
|
-
} else {
|
|
145
|
-
dots = -1;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return res;
|
|
149
|
-
}
|
|
150
|
-
const isAbsolute$2 = function(p) {
|
|
151
|
-
return _IS_ABSOLUTE_RE$2.test(p);
|
|
152
|
-
};
|
|
153
|
-
const toNamespacedPath$2 = function(p) {
|
|
154
|
-
return normalizeWindowsPath$2(p);
|
|
155
|
-
};
|
|
156
|
-
const extname$2 = function(p) {
|
|
157
|
-
return path.posix.extname(normalizeWindowsPath$2(p));
|
|
158
|
-
};
|
|
159
|
-
const relative$2 = function(from, to) {
|
|
160
|
-
return path.posix.relative(normalizeWindowsPath$2(from), normalizeWindowsPath$2(to));
|
|
161
|
-
};
|
|
162
|
-
const dirname$2 = function(p) {
|
|
163
|
-
return path.posix.dirname(normalizeWindowsPath$2(p));
|
|
164
|
-
};
|
|
165
|
-
const format$2 = function(p) {
|
|
166
|
-
return normalizeWindowsPath$2(path.posix.format(p));
|
|
167
|
-
};
|
|
168
|
-
const basename$2 = function(p, ext) {
|
|
169
|
-
return path.posix.basename(normalizeWindowsPath$2(p), ext);
|
|
170
|
-
};
|
|
171
|
-
const parse$e = function(p) {
|
|
172
|
-
return path.posix.parse(normalizeWindowsPath$2(p));
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const _path$2 = /*#__PURE__*/Object.freeze({
|
|
176
|
-
__proto__: null,
|
|
177
|
-
sep: sep$2,
|
|
178
|
-
delimiter: delimiter$2,
|
|
179
|
-
normalize: normalize$2,
|
|
180
|
-
join: join$2,
|
|
181
|
-
resolve: resolve,
|
|
182
|
-
normalizeString: normalizeString$2,
|
|
183
|
-
isAbsolute: isAbsolute$2,
|
|
184
|
-
toNamespacedPath: toNamespacedPath$2,
|
|
185
|
-
extname: extname$2,
|
|
186
|
-
relative: relative$2,
|
|
187
|
-
dirname: dirname$2,
|
|
188
|
-
format: format$2,
|
|
189
|
-
basename: basename$2,
|
|
190
|
-
parse: parse$e
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
({
|
|
194
|
-
..._path$2
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
/*---------------------------------------------------------------------------------------------
|
|
198
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
199
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
200
|
-
*--------------------------------------------------------------------------------------------*/
|
|
201
|
-
var ParseOptions$1;
|
|
202
|
-
(function (ParseOptions) {
|
|
203
|
-
ParseOptions.DEFAULT = {
|
|
204
|
-
allowTrailingComma: false
|
|
205
|
-
};
|
|
206
|
-
})(ParseOptions$1 || (ParseOptions$1 = {}));
|
|
13
|
+
import 'local-pkg';
|
|
207
14
|
|
|
208
15
|
const BUILTIN_MODULES$1 = new Set(builtinModules);
|
|
209
16
|
function normalizeSlash$1(str) {
|
|
@@ -222,12 +29,17 @@ function perr$1(_err) {
|
|
|
222
29
|
Error.captureStackTrace(err, pcall$1);
|
|
223
30
|
return Promise.reject(err);
|
|
224
31
|
}
|
|
32
|
+
const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
|
|
33
|
+
function getProtocol(id) {
|
|
34
|
+
const proto = id.match(ProtocolRegex);
|
|
35
|
+
return proto ? proto.groups.proto : null;
|
|
36
|
+
}
|
|
225
37
|
|
|
226
38
|
function fileURLToPath$1(id) {
|
|
227
39
|
if (typeof id === "string" && !id.startsWith("file://")) {
|
|
228
40
|
return normalizeSlash$1(id);
|
|
229
41
|
}
|
|
230
|
-
return normalizeSlash$1(fileURLToPath(id));
|
|
42
|
+
return normalizeSlash$1(fileURLToPath$2(id));
|
|
231
43
|
}
|
|
232
44
|
function normalizeid$1(id) {
|
|
233
45
|
if (typeof id !== "string") {
|
|
@@ -3640,7 +3452,7 @@ function getMessage$1(key, args, self) {
|
|
|
3640
3452
|
if (args.length === 0) return message
|
|
3641
3453
|
|
|
3642
3454
|
args.unshift(message);
|
|
3643
|
-
return Reflect.apply(format$
|
|
3455
|
+
return Reflect.apply(format$2, null, args)
|
|
3644
3456
|
}
|
|
3645
3457
|
|
|
3646
3458
|
// Manually “tree shaken” from:
|
|
@@ -3684,7 +3496,7 @@ function defaultGetFormat$1(url) {
|
|
|
3684
3496
|
}
|
|
3685
3497
|
|
|
3686
3498
|
if (!format) {
|
|
3687
|
-
throw new ERR_UNKNOWN_FILE_EXTENSION$1(ext, fileURLToPath(url))
|
|
3499
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION$1(ext, fileURLToPath$2(url))
|
|
3688
3500
|
}
|
|
3689
3501
|
|
|
3690
3502
|
return {format: format || null}
|
|
@@ -3729,7 +3541,7 @@ const packageJsonCache$1 = new Map();
|
|
|
3729
3541
|
* @returns {void}
|
|
3730
3542
|
*/
|
|
3731
3543
|
function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
|
|
3732
|
-
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
3544
|
+
const pjsonPath = fileURLToPath$2(pjsonUrl);
|
|
3733
3545
|
|
|
3734
3546
|
if (emittedPackageWarnings$1.has(pjsonPath + '|' + match)) return
|
|
3735
3547
|
emittedPackageWarnings$1.add(pjsonPath + '|' + match);
|
|
@@ -3737,7 +3549,7 @@ function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
|
|
|
3737
3549
|
`Use of deprecated folder mapping "${match}" in the ${
|
|
3738
3550
|
isExports ? '"exports"' : '"imports"'
|
|
3739
3551
|
} field module resolution of the package at ${pjsonPath}${
|
|
3740
|
-
base ? ` imported from ${fileURLToPath(base)}` : ''
|
|
3552
|
+
base ? ` imported from ${fileURLToPath$2(base)}` : ''
|
|
3741
3553
|
}.\n` +
|
|
3742
3554
|
`Update this package.json to use a subpath pattern like "${match}*".`,
|
|
3743
3555
|
'DeprecationWarning',
|
|
@@ -3755,9 +3567,9 @@ function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
|
|
|
3755
3567
|
function emitLegacyIndexDeprecation$1(url, packageJsonUrl, base, main) {
|
|
3756
3568
|
const {format} = defaultGetFormat$1(url.href);
|
|
3757
3569
|
if (format !== 'module') return
|
|
3758
|
-
const path = fileURLToPath(url.href);
|
|
3759
|
-
const pkgPath = fileURLToPath(new URL$1('.', packageJsonUrl));
|
|
3760
|
-
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);
|
|
3761
3573
|
if (main)
|
|
3762
3574
|
process.emitWarning(
|
|
3763
3575
|
`Package ${pkgPath} has a "main" field set to ${JSON.stringify(main)}, ` +
|
|
@@ -3827,7 +3639,7 @@ function getPackageConfig$1(path, specifier, base) {
|
|
|
3827
3639
|
} catch (error) {
|
|
3828
3640
|
throw new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
3829
3641
|
path,
|
|
3830
|
-
(base ? `"${specifier}" from ` : '') + fileURLToPath(base || specifier),
|
|
3642
|
+
(base ? `"${specifier}" from ` : '') + fileURLToPath$2(base || specifier),
|
|
3831
3643
|
error.message
|
|
3832
3644
|
)
|
|
3833
3645
|
}
|
|
@@ -3863,7 +3675,7 @@ function getPackageScopeConfig$1(resolved) {
|
|
|
3863
3675
|
if (packageJsonPath.endsWith('node_modules/package.json')) break
|
|
3864
3676
|
|
|
3865
3677
|
const packageConfig = getPackageConfig$1(
|
|
3866
|
-
fileURLToPath(packageJsonUrl),
|
|
3678
|
+
fileURLToPath$2(packageJsonUrl),
|
|
3867
3679
|
resolved
|
|
3868
3680
|
);
|
|
3869
3681
|
if (packageConfig.exists) return packageConfig
|
|
@@ -3876,7 +3688,7 @@ function getPackageScopeConfig$1(resolved) {
|
|
|
3876
3688
|
if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) break
|
|
3877
3689
|
}
|
|
3878
3690
|
|
|
3879
|
-
const packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
3691
|
+
const packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
3880
3692
|
/** @type {PackageConfig} */
|
|
3881
3693
|
const packageConfig = {
|
|
3882
3694
|
pjsonPath: packageJsonPath,
|
|
@@ -3903,7 +3715,7 @@ function getPackageScopeConfig$1(resolved) {
|
|
|
3903
3715
|
* @returns {boolean}
|
|
3904
3716
|
*/
|
|
3905
3717
|
function fileExists$1(url) {
|
|
3906
|
-
return tryStatSync$1(fileURLToPath(url)).isFile()
|
|
3718
|
+
return tryStatSync$1(fileURLToPath$2(url)).isFile()
|
|
3907
3719
|
}
|
|
3908
3720
|
|
|
3909
3721
|
/**
|
|
@@ -3964,8 +3776,8 @@ function legacyMainResolve$1(packageJsonUrl, packageConfig, base) {
|
|
|
3964
3776
|
|
|
3965
3777
|
// Not found.
|
|
3966
3778
|
throw new ERR_MODULE_NOT_FOUND$1(
|
|
3967
|
-
fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
3968
|
-
fileURLToPath(base)
|
|
3779
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
3780
|
+
fileURLToPath$2(base)
|
|
3969
3781
|
)
|
|
3970
3782
|
}
|
|
3971
3783
|
|
|
@@ -3979,15 +3791,15 @@ function finalizeResolution$1(resolved, base) {
|
|
|
3979
3791
|
throw new ERR_INVALID_MODULE_SPECIFIER$1(
|
|
3980
3792
|
resolved.pathname,
|
|
3981
3793
|
'must not include encoded "/" or "\\" characters',
|
|
3982
|
-
fileURLToPath(base)
|
|
3794
|
+
fileURLToPath$2(base)
|
|
3983
3795
|
)
|
|
3984
3796
|
|
|
3985
|
-
const path = fileURLToPath(resolved);
|
|
3797
|
+
const path = fileURLToPath$2(resolved);
|
|
3986
3798
|
|
|
3987
3799
|
const stats = tryStatSync$1(path.endsWith('/') ? path.slice(-1) : path);
|
|
3988
3800
|
|
|
3989
3801
|
if (stats.isDirectory()) {
|
|
3990
|
-
const error = new ERR_UNSUPPORTED_DIR_IMPORT$1(path, fileURLToPath(base));
|
|
3802
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT$1(path, fileURLToPath$2(base));
|
|
3991
3803
|
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
3992
3804
|
error.url = String(resolved);
|
|
3993
3805
|
throw error
|
|
@@ -3996,7 +3808,7 @@ function finalizeResolution$1(resolved, base) {
|
|
|
3996
3808
|
if (!stats.isFile()) {
|
|
3997
3809
|
throw new ERR_MODULE_NOT_FOUND$1(
|
|
3998
3810
|
path || resolved.pathname,
|
|
3999
|
-
base && fileURLToPath(base),
|
|
3811
|
+
base && fileURLToPath$2(base),
|
|
4000
3812
|
'module'
|
|
4001
3813
|
)
|
|
4002
3814
|
}
|
|
@@ -4013,8 +3825,8 @@ function finalizeResolution$1(resolved, base) {
|
|
|
4013
3825
|
function throwImportNotDefined$1(specifier, packageJsonUrl, base) {
|
|
4014
3826
|
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED$1(
|
|
4015
3827
|
specifier,
|
|
4016
|
-
packageJsonUrl && fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
4017
|
-
fileURLToPath(base)
|
|
3828
|
+
packageJsonUrl && fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
3829
|
+
fileURLToPath$2(base)
|
|
4018
3830
|
)
|
|
4019
3831
|
}
|
|
4020
3832
|
|
|
@@ -4026,9 +3838,9 @@ function throwImportNotDefined$1(specifier, packageJsonUrl, base) {
|
|
|
4026
3838
|
*/
|
|
4027
3839
|
function throwExportsNotFound$1(subpath, packageJsonUrl, base) {
|
|
4028
3840
|
throw new ERR_PACKAGE_PATH_NOT_EXPORTED$1(
|
|
4029
|
-
fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
3841
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
4030
3842
|
subpath,
|
|
4031
|
-
base && fileURLToPath(base)
|
|
3843
|
+
base && fileURLToPath$2(base)
|
|
4032
3844
|
)
|
|
4033
3845
|
}
|
|
4034
3846
|
|
|
@@ -4042,12 +3854,12 @@ function throwExportsNotFound$1(subpath, packageJsonUrl, base) {
|
|
|
4042
3854
|
function throwInvalidSubpath$1(subpath, packageJsonUrl, internal, base) {
|
|
4043
3855
|
const reason = `request is not a valid subpath for the "${
|
|
4044
3856
|
internal ? 'imports' : 'exports'
|
|
4045
|
-
}" resolution of ${fileURLToPath(packageJsonUrl)}`;
|
|
3857
|
+
}" resolution of ${fileURLToPath$2(packageJsonUrl)}`;
|
|
4046
3858
|
|
|
4047
3859
|
throw new ERR_INVALID_MODULE_SPECIFIER$1(
|
|
4048
3860
|
subpath,
|
|
4049
3861
|
reason,
|
|
4050
|
-
base && fileURLToPath(base)
|
|
3862
|
+
base && fileURLToPath$2(base)
|
|
4051
3863
|
)
|
|
4052
3864
|
}
|
|
4053
3865
|
|
|
@@ -4072,11 +3884,11 @@ function throwInvalidPackageTarget$1(
|
|
|
4072
3884
|
: `${target}`;
|
|
4073
3885
|
|
|
4074
3886
|
throw new ERR_INVALID_PACKAGE_TARGET$1(
|
|
4075
|
-
fileURLToPath(new URL$1('.', packageJsonUrl)),
|
|
3887
|
+
fileURLToPath$2(new URL$1('.', packageJsonUrl)),
|
|
4076
3888
|
subpath,
|
|
4077
3889
|
target,
|
|
4078
3890
|
internal,
|
|
4079
|
-
base && fileURLToPath(base)
|
|
3891
|
+
base && fileURLToPath$2(base)
|
|
4080
3892
|
)
|
|
4081
3893
|
}
|
|
4082
3894
|
|
|
@@ -4245,7 +4057,7 @@ function resolvePackageTarget$1(
|
|
|
4245
4057
|
const key = keys[i];
|
|
4246
4058
|
if (isArrayIndex$1(key)) {
|
|
4247
4059
|
throw new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
4248
|
-
fileURLToPath(packageJsonUrl),
|
|
4060
|
+
fileURLToPath$2(packageJsonUrl),
|
|
4249
4061
|
base,
|
|
4250
4062
|
'"exports" cannot contain numeric property keys.'
|
|
4251
4063
|
)
|
|
@@ -4311,7 +4123,7 @@ function isConditionalExportsMainSugar$1(exports, packageJsonUrl, base) {
|
|
|
4311
4123
|
isConditionalSugar = curIsConditionalSugar;
|
|
4312
4124
|
} else if (isConditionalSugar !== curIsConditionalSugar) {
|
|
4313
4125
|
throw new ERR_INVALID_PACKAGE_CONFIG$1(
|
|
4314
|
-
fileURLToPath(packageJsonUrl),
|
|
4126
|
+
fileURLToPath$2(packageJsonUrl),
|
|
4315
4127
|
base,
|
|
4316
4128
|
'"exports" cannot contain some keys starting with \'.\' and some not.' +
|
|
4317
4129
|
' The exports object must either be an object of package subpath keys' +
|
|
@@ -4414,7 +4226,7 @@ function packageExportsResolve$1(
|
|
|
4414
4226
|
function packageImportsResolve$1(name, base, conditions) {
|
|
4415
4227
|
if (name === '#' || name.startsWith('#/')) {
|
|
4416
4228
|
const reason = 'is not a valid internal imports specifier name';
|
|
4417
|
-
throw new ERR_INVALID_MODULE_SPECIFIER$1(name, reason, fileURLToPath(base))
|
|
4229
|
+
throw new ERR_INVALID_MODULE_SPECIFIER$1(name, reason, fileURLToPath$2(base))
|
|
4418
4230
|
}
|
|
4419
4231
|
|
|
4420
4232
|
/** @type {URL} */
|
|
@@ -4532,7 +4344,7 @@ function parsePackageName$1(specifier, base) {
|
|
|
4532
4344
|
throw new ERR_INVALID_MODULE_SPECIFIER$1(
|
|
4533
4345
|
specifier,
|
|
4534
4346
|
'is not a valid package name',
|
|
4535
|
-
fileURLToPath(base)
|
|
4347
|
+
fileURLToPath$2(base)
|
|
4536
4348
|
)
|
|
4537
4349
|
}
|
|
4538
4350
|
|
|
@@ -4580,7 +4392,7 @@ function packageResolve$1(specifier, base, conditions) {
|
|
|
4580
4392
|
'./node_modules/' + packageName + '/package.json',
|
|
4581
4393
|
base
|
|
4582
4394
|
);
|
|
4583
|
-
let packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
4395
|
+
let packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
4584
4396
|
/** @type {string} */
|
|
4585
4397
|
let lastPath;
|
|
4586
4398
|
do {
|
|
@@ -4593,7 +4405,7 @@ function packageResolve$1(specifier, base, conditions) {
|
|
|
4593
4405
|
'/package.json',
|
|
4594
4406
|
packageJsonUrl
|
|
4595
4407
|
);
|
|
4596
|
-
packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
4408
|
+
packageJsonPath = fileURLToPath$2(packageJsonUrl);
|
|
4597
4409
|
continue
|
|
4598
4410
|
}
|
|
4599
4411
|
|
|
@@ -4613,7 +4425,7 @@ function packageResolve$1(specifier, base, conditions) {
|
|
|
4613
4425
|
// Cross-platform root check.
|
|
4614
4426
|
} while (packageJsonPath.length !== lastPath.length)
|
|
4615
4427
|
|
|
4616
|
-
throw new ERR_MODULE_NOT_FOUND$1(packageName, fileURLToPath(base))
|
|
4428
|
+
throw new ERR_MODULE_NOT_FOUND$1(packageName, fileURLToPath$2(base))
|
|
4617
4429
|
}
|
|
4618
4430
|
|
|
4619
4431
|
/**
|
|
@@ -4760,6 +4572,43 @@ var ParseOptions;
|
|
|
4760
4572
|
};
|
|
4761
4573
|
})(ParseOptions || (ParseOptions = {}));
|
|
4762
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
|
+
|
|
4763
4612
|
function normalizeWindowsPath(input = "") {
|
|
4764
4613
|
if (!input.includes("\\")) {
|
|
4765
4614
|
return input;
|
|
@@ -7775,10 +7624,49 @@ var builtins = function ({
|
|
|
7775
7624
|
|
|
7776
7625
|
// Manually “tree shaken” from:
|
|
7777
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
|
+
|
|
7778
7664
|
const isWindows$2 = process.platform === 'win32';
|
|
7779
7665
|
|
|
7780
7666
|
const own$1 = {}.hasOwnProperty;
|
|
7781
7667
|
|
|
7668
|
+
const codes = {};
|
|
7669
|
+
|
|
7782
7670
|
/**
|
|
7783
7671
|
* @typedef {(...args: unknown[]) => string} MessageFunction
|
|
7784
7672
|
*/
|
|
@@ -7789,7 +7677,7 @@ const nodeInternalPrefix = '__node_internal_';
|
|
|
7789
7677
|
/** @type {number} */
|
|
7790
7678
|
let userStackTraceLimit;
|
|
7791
7679
|
|
|
7792
|
-
createError(
|
|
7680
|
+
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
7793
7681
|
'ERR_INVALID_MODULE_SPECIFIER',
|
|
7794
7682
|
/**
|
|
7795
7683
|
* @param {string} request
|
|
@@ -7804,7 +7692,7 @@ createError(
|
|
|
7804
7692
|
TypeError
|
|
7805
7693
|
);
|
|
7806
7694
|
|
|
7807
|
-
createError(
|
|
7695
|
+
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
7808
7696
|
'ERR_INVALID_PACKAGE_CONFIG',
|
|
7809
7697
|
/**
|
|
7810
7698
|
* @param {string} path
|
|
@@ -7819,7 +7707,7 @@ createError(
|
|
|
7819
7707
|
Error
|
|
7820
7708
|
);
|
|
7821
7709
|
|
|
7822
|
-
createError(
|
|
7710
|
+
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
7823
7711
|
'ERR_INVALID_PACKAGE_TARGET',
|
|
7824
7712
|
/**
|
|
7825
7713
|
* @param {string} pkgPath
|
|
@@ -7855,7 +7743,7 @@ createError(
|
|
|
7855
7743
|
Error
|
|
7856
7744
|
);
|
|
7857
7745
|
|
|
7858
|
-
createError(
|
|
7746
|
+
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
7859
7747
|
'ERR_MODULE_NOT_FOUND',
|
|
7860
7748
|
/**
|
|
7861
7749
|
* @param {string} path
|
|
@@ -7868,7 +7756,7 @@ createError(
|
|
|
7868
7756
|
Error
|
|
7869
7757
|
);
|
|
7870
7758
|
|
|
7871
|
-
createError(
|
|
7759
|
+
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
7872
7760
|
'ERR_PACKAGE_IMPORT_NOT_DEFINED',
|
|
7873
7761
|
/**
|
|
7874
7762
|
* @param {string} specifier
|
|
@@ -7883,7 +7771,7 @@ createError(
|
|
|
7883
7771
|
TypeError
|
|
7884
7772
|
);
|
|
7885
7773
|
|
|
7886
|
-
createError(
|
|
7774
|
+
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
7887
7775
|
'ERR_PACKAGE_PATH_NOT_EXPORTED',
|
|
7888
7776
|
/**
|
|
7889
7777
|
* @param {string} pkgPath
|
|
@@ -7902,20 +7790,20 @@ createError(
|
|
|
7902
7790
|
Error
|
|
7903
7791
|
);
|
|
7904
7792
|
|
|
7905
|
-
createError(
|
|
7793
|
+
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
|
|
7906
7794
|
'ERR_UNSUPPORTED_DIR_IMPORT',
|
|
7907
7795
|
"Directory import '%s' is not supported " +
|
|
7908
7796
|
'resolving ES modules imported from %s',
|
|
7909
7797
|
Error
|
|
7910
7798
|
);
|
|
7911
7799
|
|
|
7912
|
-
createError(
|
|
7800
|
+
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
7913
7801
|
'ERR_UNKNOWN_FILE_EXTENSION',
|
|
7914
7802
|
'Unknown file extension "%s" for %s',
|
|
7915
7803
|
TypeError
|
|
7916
7804
|
);
|
|
7917
7805
|
|
|
7918
|
-
createError(
|
|
7806
|
+
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
7919
7807
|
'ERR_INVALID_ARG_VALUE',
|
|
7920
7808
|
/**
|
|
7921
7809
|
* @param {string} name
|
|
@@ -7938,7 +7826,7 @@ createError(
|
|
|
7938
7826
|
// , RangeError
|
|
7939
7827
|
);
|
|
7940
7828
|
|
|
7941
|
-
createError(
|
|
7829
|
+
codes.ERR_UNSUPPORTED_ESM_URL_SCHEME = createError(
|
|
7942
7830
|
'ERR_UNSUPPORTED_ESM_URL_SCHEME',
|
|
7943
7831
|
/**
|
|
7944
7832
|
* @param {URL} url
|
|
@@ -8115,112 +8003,1196 @@ function getMessage(key, args, self) {
|
|
|
8115
8003
|
if (args.length === 0) return message
|
|
8116
8004
|
|
|
8117
8005
|
args.unshift(message);
|
|
8118
|
-
return Reflect.apply(format$
|
|
8006
|
+
return Reflect.apply(format$2, null, args)
|
|
8119
8007
|
}
|
|
8120
8008
|
|
|
8121
8009
|
// Manually “tree shaken” from:
|
|
8122
8010
|
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
Object.freeze(['node', 'import']);
|
|
8126
|
-
pathToFileURL(process.cwd());
|
|
8127
|
-
const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
|
|
8128
|
-
function hasCJSSyntax(code) {
|
|
8129
|
-
return CJS_RE.test(code);
|
|
8130
|
-
}
|
|
8011
|
+
const {ERR_UNKNOWN_FILE_EXTENSION} = codes;
|
|
8131
8012
|
|
|
8132
|
-
const
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
if (statSync(filePath).isFile()) {
|
|
8138
|
-
return true;
|
|
8139
|
-
}
|
|
8140
|
-
} catch {
|
|
8141
|
-
}
|
|
8142
|
-
return null;
|
|
8143
|
-
}
|
|
8013
|
+
const extensionFormatMap = {
|
|
8014
|
+
__proto__: null,
|
|
8015
|
+
'.cjs': 'commonjs',
|
|
8016
|
+
'.js': 'module',
|
|
8017
|
+
'.mjs': 'module'
|
|
8144
8018
|
};
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
let root = segments.findIndex((r) => r.match(options.rootPattern));
|
|
8154
|
-
if (root === -1)
|
|
8155
|
-
root = 0;
|
|
8156
|
-
for (let i = segments.length; i > root; i--) {
|
|
8157
|
-
const filePath = join$2(...segments.slice(0, i), filename);
|
|
8158
|
-
if (await options.test(filePath)) {
|
|
8159
|
-
return filePath;
|
|
8160
|
-
}
|
|
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'}
|
|
8161
8027
|
}
|
|
8162
|
-
throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
|
|
8163
|
-
}
|
|
8164
|
-
async function readPackageJSON(id, opts = {}) {
|
|
8165
|
-
const resolvedPath = await resolvePackageJSON(id, opts);
|
|
8166
|
-
const blob = await promises.readFile(resolvedPath, "utf-8");
|
|
8167
|
-
return JSON.parse(blob);
|
|
8168
|
-
}
|
|
8169
|
-
async function resolvePackageJSON(id = process.cwd(), opts = {}) {
|
|
8170
|
-
const resolvedPath = isAbsolute$2(id) ? id : await resolvePath$1(id, opts);
|
|
8171
|
-
return findNearestFile("package.json", { startingFrom: resolvedPath, ...opts });
|
|
8172
|
-
}
|
|
8173
8028
|
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
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
|
|
8194
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
|
+
|
|
8195
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;
|
|
8196
|
-
const BUILTIN_EXTENSIONS =
|
|
9158
|
+
const BUILTIN_EXTENSIONS = new Set([".mjs", ".cjs", ".node", ".wasm"]);
|
|
8197
9159
|
function hasESMSyntax(code) {
|
|
8198
9160
|
return ESM_RE.test(code);
|
|
8199
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
|
+
}
|
|
8200
9166
|
const validNodeImportDefaults = {
|
|
8201
9167
|
allowedProtocols: ["node", "file", "data"]
|
|
8202
9168
|
};
|
|
8203
9169
|
async function isValidNodeImport(id, _opts = {}) {
|
|
8204
|
-
|
|
8205
|
-
if (isNodeBuiltin(id))
|
|
9170
|
+
if (isNodeBuiltin(id)) {
|
|
8206
9171
|
return true;
|
|
8207
|
-
|
|
9172
|
+
}
|
|
9173
|
+
const opts = { ...validNodeImportDefaults, ..._opts };
|
|
8208
9174
|
const proto = getProtocol(id);
|
|
8209
|
-
if (proto && !
|
|
9175
|
+
if (proto && !opts.allowedProtocols.includes(proto)) {
|
|
8210
9176
|
return false;
|
|
8211
|
-
|
|
9177
|
+
}
|
|
9178
|
+
if (proto === "data") {
|
|
8212
9179
|
return true;
|
|
9180
|
+
}
|
|
8213
9181
|
const resolvedPath = await resolvePath$1(id, opts);
|
|
8214
|
-
const extension = extname$
|
|
8215
|
-
if (BUILTIN_EXTENSIONS.has(extension))
|
|
9182
|
+
const extension = extname$1(resolvedPath);
|
|
9183
|
+
if (BUILTIN_EXTENSIONS.has(extension)) {
|
|
8216
9184
|
return true;
|
|
8217
|
-
|
|
9185
|
+
}
|
|
9186
|
+
if (extension !== ".js") {
|
|
8218
9187
|
return false;
|
|
8219
|
-
|
|
9188
|
+
}
|
|
9189
|
+
if (resolvedPath.match(/\.(\w+-)?esm?(-\w+)?\.js$/)) {
|
|
8220
9190
|
return false;
|
|
9191
|
+
}
|
|
8221
9192
|
const pkg = await readPackageJSON(resolvedPath).catch(() => null);
|
|
8222
|
-
if (
|
|
9193
|
+
if (pkg?.type === "module") {
|
|
8223
9194
|
return true;
|
|
9195
|
+
}
|
|
8224
9196
|
const code = opts.code || await promises.readFile(resolvedPath, "utf-8").catch(() => null) || "";
|
|
8225
9197
|
return hasCJSSyntax(code) || !hasESMSyntax(code);
|
|
8226
9198
|
}
|
|
@@ -8275,7 +9247,7 @@ async function executeInViteNode(options) {
|
|
|
8275
9247
|
builtinModules.forEach((m) => externalCache.set(m, true));
|
|
8276
9248
|
const result = [];
|
|
8277
9249
|
for (const file of files)
|
|
8278
|
-
result.push(await cachedRequest(`/@fs/${slash(resolve
|
|
9250
|
+
result.push(await cachedRequest(`/@fs/${slash(resolve(file))}`, []));
|
|
8279
9251
|
return result;
|
|
8280
9252
|
async function directRequest(id, fsPath, callstack) {
|
|
8281
9253
|
callstack = [...callstack, id];
|
|
@@ -8299,7 +9271,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
8299
9271
|
const url = pathToFileURL(fsPath).href;
|
|
8300
9272
|
const exports = {};
|
|
8301
9273
|
setCache(fsPath, { code: transformed, exports });
|
|
8302
|
-
const __filename = fileURLToPath(url);
|
|
9274
|
+
const __filename = fileURLToPath$2(url);
|
|
8303
9275
|
const moduleProxy = {
|
|
8304
9276
|
set exports(value) {
|
|
8305
9277
|
exportAll(exports, value);
|
|
@@ -8319,7 +9291,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
8319
9291
|
exports,
|
|
8320
9292
|
module: moduleProxy,
|
|
8321
9293
|
__filename,
|
|
8322
|
-
__dirname: dirname$
|
|
9294
|
+
__dirname: dirname$2(__filename)
|
|
8323
9295
|
};
|
|
8324
9296
|
const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{${transformed}
|
|
8325
9297
|
}`, {
|
|
@@ -8370,15 +9342,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
|
|
|
8370
9342
|
}
|
|
8371
9343
|
}
|
|
8372
9344
|
function normalizeId(id) {
|
|
8373
|
-
|
|
8374
|
-
id = `\0${id.slice("/@id/__x00__".length)}`;
|
|
8375
|
-
if (id && id.startsWith("/@id/"))
|
|
8376
|
-
id = id.slice("/@id/".length);
|
|
8377
|
-
if (id.startsWith("__vite-browser-external:"))
|
|
8378
|
-
id = id.slice("__vite-browser-external:".length);
|
|
8379
|
-
if (id.startsWith("node:"))
|
|
8380
|
-
id = id.slice("node:".length);
|
|
8381
|
-
return id;
|
|
9345
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^node:/, "").replace(/[?&]v=\w+/, "?").replace(/\?$/, "");
|
|
8382
9346
|
}
|
|
8383
9347
|
async function shouldExternalize(id, config) {
|
|
8384
9348
|
if (matchExternalizePattern(id, config.inline))
|
|
@@ -8392,10 +9356,10 @@ async function shouldExternalize(id, config) {
|
|
|
8392
9356
|
return id.includes("/node_modules/") && await isValidNodeImport(id);
|
|
8393
9357
|
}
|
|
8394
9358
|
function toFilePath(id, root) {
|
|
8395
|
-
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;
|
|
8396
9360
|
if (absolute.startsWith("//"))
|
|
8397
9361
|
absolute = absolute.slice(1);
|
|
8398
|
-
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
9362
|
+
return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
8399
9363
|
}
|
|
8400
9364
|
function matchExternalizePattern(id, patterns) {
|
|
8401
9365
|
for (const ex of patterns) {
|
|
@@ -8433,7 +9397,7 @@ async function startViteNode(ctx) {
|
|
|
8433
9397
|
const { run: run2, collect: collect2 } = (await executeInViteNode({
|
|
8434
9398
|
root: config.root,
|
|
8435
9399
|
files: [
|
|
8436
|
-
resolve
|
|
9400
|
+
resolve(distDir, "entry.js")
|
|
8437
9401
|
],
|
|
8438
9402
|
fetch(id) {
|
|
8439
9403
|
return process.__vitest_worker__.rpc("fetch", id);
|