vitest 0.25.7 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +29 -171
- package/dist/browser.d.ts +6 -3
- package/dist/browser.js +9 -10
- package/dist/{chunk-api-setup.5669c9a4.js → chunk-api-setup.08f3b356.js} +39 -42
- package/dist/{chunk-integrations-globals.57158eb5.js → chunk-integrations-globals.cab94a09.js} +5 -5
- package/dist/{chunk-magic-string.ffe2b171.js → chunk-magic-string.3a794426.js} +75 -39
- package/dist/{chunk-runtime-chain.dd978482.js → chunk-runtime-chain.e655f6cc.js} +5 -6
- package/dist/{chunk-runtime-error.616e92ca.js → chunk-runtime-error.dfbbf9be.js} +5 -5
- package/dist/{chunk-runtime-mocker.bf08ae09.js → chunk-runtime-mocker.35fabb8b.js} +65 -64
- package/dist/{chunk-runtime-rpc.42aebbb9.js → chunk-runtime-rpc.7959fc79.js} +1 -1
- package/dist/{chunk-runtime-setup.bd2deed4.js → chunk-runtime-setup.4c1b529e.js} +16 -29
- package/dist/{chunk-vite-node-externalize.5a3e0bdc.js → chunk-snapshot-manager.7d978f79.js} +41 -326
- package/dist/{chunk-typecheck-constants.ed987901.js → chunk-typecheck-constants.3f865d14.js} +5 -4
- package/dist/{chunk-runtime-test-state.0037e2e0.js → chunk-utils-import.ca62c9d7.js} +49 -18
- package/dist/{chunk-utils-source-map.29ff1088.js → chunk-utils-source-map.5bbb50cd.js} +6 -4
- package/dist/cli.js +13 -14
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +6 -3
- package/dist/config.js +1 -1
- package/dist/entry.js +9 -9
- package/dist/environments.d.ts +4 -1
- package/dist/{index-fde81ec3.d.ts → index-c3f83a58.d.ts} +20 -20
- package/dist/index.d.ts +28 -10
- package/dist/index.js +6 -6
- package/dist/loader.js +7 -6
- package/dist/node.d.ts +19 -19
- package/dist/node.js +15 -15
- package/dist/suite.js +4 -4
- package/dist/{types-c441ef31.d.ts → types-56bcd6c3.d.ts} +71 -328
- package/dist/vendor-index.783e7f3e.js +71 -0
- package/dist/vendor-index.96e022fd.js +211 -0
- package/dist/worker.js +12 -14
- package/package.json +15 -15
- package/dist/chunk-vite-node-source-map.2b1f492a.js +0 -445
- package/dist/chunk-vite-node-utils.0e4a6a88.js +0 -1385
- package/dist/vendor-source-map-support.1ce17397.js +0 -707
|
@@ -1,1385 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL, fileURLToPath as fileURLToPath$1, URL as URL$1 } from 'url';
|
|
2
|
-
import fs, { promises, statSync, existsSync, realpathSync, Stats } from 'fs';
|
|
3
|
-
import { b as resolve$1, r as relative } from './chunk-utils-env.03f840f2.js';
|
|
4
|
-
import 'acorn';
|
|
5
|
-
import { builtinModules } from 'module';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
import assert from 'assert';
|
|
8
|
-
import { format, inspect } from 'util';
|
|
9
|
-
|
|
10
|
-
const TRAILING_SLASH_RE = /\/$|\/\?/;
|
|
11
|
-
function hasTrailingSlash(input = "", queryParameters = false) {
|
|
12
|
-
if (!queryParameters) {
|
|
13
|
-
return input.endsWith("/");
|
|
14
|
-
}
|
|
15
|
-
return TRAILING_SLASH_RE.test(input);
|
|
16
|
-
}
|
|
17
|
-
function withTrailingSlash(input = "", queryParameters = false) {
|
|
18
|
-
if (!queryParameters) {
|
|
19
|
-
return input.endsWith("/") ? input : input + "/";
|
|
20
|
-
}
|
|
21
|
-
if (hasTrailingSlash(input, true)) {
|
|
22
|
-
return input || "/";
|
|
23
|
-
}
|
|
24
|
-
const [s0, ...s] = input.split("?");
|
|
25
|
-
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
|
|
26
|
-
}
|
|
27
|
-
function hasLeadingSlash(input = "") {
|
|
28
|
-
return input.startsWith("/");
|
|
29
|
-
}
|
|
30
|
-
function withoutLeadingSlash(input = "") {
|
|
31
|
-
return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
|
|
32
|
-
}
|
|
33
|
-
function isNonEmptyURL(url) {
|
|
34
|
-
return url && url !== "/";
|
|
35
|
-
}
|
|
36
|
-
function joinURL(base, ...input) {
|
|
37
|
-
let url = base || "";
|
|
38
|
-
for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
|
|
39
|
-
url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
|
|
40
|
-
}
|
|
41
|
-
return url;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function normalizeWindowsPath(input = "") {
|
|
45
|
-
if (!input || !input.includes("\\")) {
|
|
46
|
-
return input;
|
|
47
|
-
}
|
|
48
|
-
return input.replace(/\\/g, "/");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const _UNC_REGEX = /^[/\\]{2}/;
|
|
52
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
53
|
-
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
54
|
-
const normalize = function(path) {
|
|
55
|
-
if (path.length === 0) {
|
|
56
|
-
return ".";
|
|
57
|
-
}
|
|
58
|
-
path = normalizeWindowsPath(path);
|
|
59
|
-
const isUNCPath = path.match(_UNC_REGEX);
|
|
60
|
-
const isPathAbsolute = isAbsolute(path);
|
|
61
|
-
const trailingSeparator = path[path.length - 1] === "/";
|
|
62
|
-
path = normalizeString(path, !isPathAbsolute);
|
|
63
|
-
if (path.length === 0) {
|
|
64
|
-
if (isPathAbsolute) {
|
|
65
|
-
return "/";
|
|
66
|
-
}
|
|
67
|
-
return trailingSeparator ? "./" : ".";
|
|
68
|
-
}
|
|
69
|
-
if (trailingSeparator) {
|
|
70
|
-
path += "/";
|
|
71
|
-
}
|
|
72
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
73
|
-
path += "/";
|
|
74
|
-
}
|
|
75
|
-
if (isUNCPath) {
|
|
76
|
-
if (!isPathAbsolute) {
|
|
77
|
-
return `//./${path}`;
|
|
78
|
-
}
|
|
79
|
-
return `//${path}`;
|
|
80
|
-
}
|
|
81
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
82
|
-
};
|
|
83
|
-
const join = function(...arguments_) {
|
|
84
|
-
if (arguments_.length === 0) {
|
|
85
|
-
return ".";
|
|
86
|
-
}
|
|
87
|
-
let joined;
|
|
88
|
-
for (const argument of arguments_) {
|
|
89
|
-
if (argument && argument.length > 0) {
|
|
90
|
-
if (joined === void 0) {
|
|
91
|
-
joined = argument;
|
|
92
|
-
} else {
|
|
93
|
-
joined += `/${argument}`;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (joined === void 0) {
|
|
98
|
-
return ".";
|
|
99
|
-
}
|
|
100
|
-
return normalize(joined.replace(/\/\/+/g, "/"));
|
|
101
|
-
};
|
|
102
|
-
const resolve = function(...arguments_) {
|
|
103
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
104
|
-
let resolvedPath = "";
|
|
105
|
-
let resolvedAbsolute = false;
|
|
106
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
107
|
-
const path = index >= 0 ? arguments_[index] : process.cwd().replace(/\\/g, "/");
|
|
108
|
-
if (!path || path.length === 0) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
112
|
-
resolvedAbsolute = isAbsolute(path);
|
|
113
|
-
}
|
|
114
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
115
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
116
|
-
return `/${resolvedPath}`;
|
|
117
|
-
}
|
|
118
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
119
|
-
};
|
|
120
|
-
function normalizeString(path, allowAboveRoot) {
|
|
121
|
-
let res = "";
|
|
122
|
-
let lastSegmentLength = 0;
|
|
123
|
-
let lastSlash = -1;
|
|
124
|
-
let dots = 0;
|
|
125
|
-
let char = null;
|
|
126
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
127
|
-
if (index < path.length) {
|
|
128
|
-
char = path[index];
|
|
129
|
-
} else if (char === "/") {
|
|
130
|
-
break;
|
|
131
|
-
} else {
|
|
132
|
-
char = "/";
|
|
133
|
-
}
|
|
134
|
-
if (char === "/") {
|
|
135
|
-
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
|
136
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
137
|
-
if (res.length > 2) {
|
|
138
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
139
|
-
if (lastSlashIndex === -1) {
|
|
140
|
-
res = "";
|
|
141
|
-
lastSegmentLength = 0;
|
|
142
|
-
} else {
|
|
143
|
-
res = res.slice(0, lastSlashIndex);
|
|
144
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
145
|
-
}
|
|
146
|
-
lastSlash = index;
|
|
147
|
-
dots = 0;
|
|
148
|
-
continue;
|
|
149
|
-
} else if (res.length > 0) {
|
|
150
|
-
res = "";
|
|
151
|
-
lastSegmentLength = 0;
|
|
152
|
-
lastSlash = index;
|
|
153
|
-
dots = 0;
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (allowAboveRoot) {
|
|
158
|
-
res += res.length > 0 ? "/.." : "..";
|
|
159
|
-
lastSegmentLength = 2;
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
if (res.length > 0) {
|
|
163
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
164
|
-
} else {
|
|
165
|
-
res = path.slice(lastSlash + 1, index);
|
|
166
|
-
}
|
|
167
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
168
|
-
}
|
|
169
|
-
lastSlash = index;
|
|
170
|
-
dots = 0;
|
|
171
|
-
} else if (char === "." && dots !== -1) {
|
|
172
|
-
++dots;
|
|
173
|
-
} else {
|
|
174
|
-
dots = -1;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return res;
|
|
178
|
-
}
|
|
179
|
-
const isAbsolute = function(p) {
|
|
180
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
181
|
-
};
|
|
182
|
-
const _EXTNAME_RE = /.(\.[^./]+)$/;
|
|
183
|
-
const extname = function(p) {
|
|
184
|
-
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
185
|
-
return match && match[1] || "";
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const defaultFindOptions = {
|
|
189
|
-
startingFrom: ".",
|
|
190
|
-
rootPattern: /^node_modules$/,
|
|
191
|
-
reverse: false,
|
|
192
|
-
test: (filePath) => {
|
|
193
|
-
try {
|
|
194
|
-
if (statSync(filePath).isFile()) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
} catch {
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
async function findFile(filename, _options = {}) {
|
|
202
|
-
const options = { ...defaultFindOptions, ..._options };
|
|
203
|
-
const basePath = resolve(options.startingFrom);
|
|
204
|
-
const leadingSlash = basePath[0] === "/";
|
|
205
|
-
const segments = basePath.split("/").filter(Boolean);
|
|
206
|
-
if (leadingSlash) {
|
|
207
|
-
segments[0] = "/" + segments[0];
|
|
208
|
-
}
|
|
209
|
-
let root = segments.findIndex((r) => r.match(options.rootPattern));
|
|
210
|
-
if (root === -1) {
|
|
211
|
-
root = 0;
|
|
212
|
-
}
|
|
213
|
-
if (!options.reverse) {
|
|
214
|
-
for (let index = segments.length; index > root; index--) {
|
|
215
|
-
const filePath = join(...segments.slice(0, index), filename);
|
|
216
|
-
if (await options.test(filePath)) {
|
|
217
|
-
return filePath;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
for (let index = root + 1; index <= segments.length; index++) {
|
|
222
|
-
const filePath = join(...segments.slice(0, index), filename);
|
|
223
|
-
if (await options.test(filePath)) {
|
|
224
|
-
return filePath;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
|
|
229
|
-
}
|
|
230
|
-
function findNearestFile(filename, _options = {}) {
|
|
231
|
-
return findFile(filename, _options);
|
|
232
|
-
}
|
|
233
|
-
const FileCache = /* @__PURE__ */ new Map();
|
|
234
|
-
async function readPackageJSON(id, options = {}) {
|
|
235
|
-
const resolvedPath = await resolvePackageJSON(id, options);
|
|
236
|
-
const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : FileCache;
|
|
237
|
-
if (options.cache && cache.has(resolvedPath)) {
|
|
238
|
-
return cache.get(resolvedPath);
|
|
239
|
-
}
|
|
240
|
-
const blob = await promises.readFile(resolvedPath, "utf8");
|
|
241
|
-
const parsed = JSON.parse(blob);
|
|
242
|
-
cache.set(resolvedPath, parsed);
|
|
243
|
-
return parsed;
|
|
244
|
-
}
|
|
245
|
-
async function resolvePackageJSON(id = process.cwd(), options = {}) {
|
|
246
|
-
const resolvedPath = isAbsolute(id) ? id : await resolvePath(id, options);
|
|
247
|
-
return findNearestFile("package.json", { startingFrom: resolvedPath, ...options });
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const BUILTIN_MODULES = new Set(builtinModules);
|
|
251
|
-
function normalizeSlash(string_) {
|
|
252
|
-
return string_.replace(/\\/g, "/");
|
|
253
|
-
}
|
|
254
|
-
function pcall(function_, ...arguments_) {
|
|
255
|
-
try {
|
|
256
|
-
return Promise.resolve(function_(...arguments_)).catch((error) => perr(error));
|
|
257
|
-
} catch (error) {
|
|
258
|
-
return perr(error);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function perr(_error) {
|
|
262
|
-
const error = new Error(_error);
|
|
263
|
-
error.code = _error.code;
|
|
264
|
-
Error.captureStackTrace(error, pcall);
|
|
265
|
-
return Promise.reject(error);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const reader = { read };
|
|
269
|
-
const packageJsonReader = reader;
|
|
270
|
-
function read(jsonPath) {
|
|
271
|
-
return find(path.dirname(jsonPath));
|
|
272
|
-
}
|
|
273
|
-
function find(dir) {
|
|
274
|
-
try {
|
|
275
|
-
const string = fs.readFileSync(
|
|
276
|
-
path.toNamespacedPath(path.join(dir, "package.json")),
|
|
277
|
-
"utf8"
|
|
278
|
-
);
|
|
279
|
-
return { string };
|
|
280
|
-
} catch (error) {
|
|
281
|
-
if (error.code === "ENOENT") {
|
|
282
|
-
const parent = path.dirname(dir);
|
|
283
|
-
if (dir !== parent) {
|
|
284
|
-
return find(parent);
|
|
285
|
-
}
|
|
286
|
-
return { string: void 0 };
|
|
287
|
-
}
|
|
288
|
-
throw error;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const isWindows$1 = process.platform === "win32";
|
|
293
|
-
const own$1 = {}.hasOwnProperty;
|
|
294
|
-
const codes = {};
|
|
295
|
-
const messages = /* @__PURE__ */ new Map();
|
|
296
|
-
const nodeInternalPrefix = "__node_internal_";
|
|
297
|
-
let userStackTraceLimit;
|
|
298
|
-
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
299
|
-
"ERR_INVALID_MODULE_SPECIFIER",
|
|
300
|
-
(request, reason, base = void 0) => {
|
|
301
|
-
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
|
|
302
|
-
},
|
|
303
|
-
TypeError
|
|
304
|
-
);
|
|
305
|
-
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
306
|
-
"ERR_INVALID_PACKAGE_CONFIG",
|
|
307
|
-
(path, base, message) => {
|
|
308
|
-
return `Invalid package config ${path}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
309
|
-
},
|
|
310
|
-
Error
|
|
311
|
-
);
|
|
312
|
-
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
313
|
-
"ERR_INVALID_PACKAGE_TARGET",
|
|
314
|
-
(pkgPath, key, target, isImport = false, base = void 0) => {
|
|
315
|
-
const relError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
316
|
-
if (key === ".") {
|
|
317
|
-
assert(isImport === false);
|
|
318
|
-
return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ""}${relError ? '; targets must start with "./"' : ""}`;
|
|
319
|
-
}
|
|
320
|
-
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
|
|
321
|
-
target
|
|
322
|
-
)} defined for '${key}' in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ""}${relError ? '; targets must start with "./"' : ""}`;
|
|
323
|
-
},
|
|
324
|
-
Error
|
|
325
|
-
);
|
|
326
|
-
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
327
|
-
"ERR_MODULE_NOT_FOUND",
|
|
328
|
-
(path, base, type = "package") => {
|
|
329
|
-
return `Cannot find ${type} '${path}' imported from ${base}`;
|
|
330
|
-
},
|
|
331
|
-
Error
|
|
332
|
-
);
|
|
333
|
-
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
334
|
-
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
|
|
335
|
-
(specifier, packagePath, base) => {
|
|
336
|
-
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
|
|
337
|
-
},
|
|
338
|
-
TypeError
|
|
339
|
-
);
|
|
340
|
-
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
341
|
-
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
342
|
-
(pkgPath, subpath, base = void 0) => {
|
|
343
|
-
if (subpath === ".") {
|
|
344
|
-
return `No "exports" main defined in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
345
|
-
}
|
|
346
|
-
return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
347
|
-
},
|
|
348
|
-
Error
|
|
349
|
-
);
|
|
350
|
-
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
|
|
351
|
-
"ERR_UNSUPPORTED_DIR_IMPORT",
|
|
352
|
-
"Directory import '%s' is not supported resolving ES modules imported from %s",
|
|
353
|
-
Error
|
|
354
|
-
);
|
|
355
|
-
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
356
|
-
"ERR_UNKNOWN_FILE_EXTENSION",
|
|
357
|
-
'Unknown file extension "%s" for %s',
|
|
358
|
-
TypeError
|
|
359
|
-
);
|
|
360
|
-
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
361
|
-
"ERR_INVALID_ARG_VALUE",
|
|
362
|
-
(name, value, reason = "is invalid") => {
|
|
363
|
-
let inspected = inspect(value);
|
|
364
|
-
if (inspected.length > 128) {
|
|
365
|
-
inspected = `${inspected.slice(0, 128)}...`;
|
|
366
|
-
}
|
|
367
|
-
const type = name.includes(".") ? "property" : "argument";
|
|
368
|
-
return `The ${type} '${name}' ${reason}. Received ${inspected}`;
|
|
369
|
-
},
|
|
370
|
-
TypeError
|
|
371
|
-
);
|
|
372
|
-
codes.ERR_UNSUPPORTED_ESM_URL_SCHEME = createError(
|
|
373
|
-
"ERR_UNSUPPORTED_ESM_URL_SCHEME",
|
|
374
|
-
(url) => {
|
|
375
|
-
let message = "Only file and data URLs are supported by the default ESM loader";
|
|
376
|
-
if (isWindows$1 && url.protocol.length === 2) {
|
|
377
|
-
message += ". On Windows, absolute paths must be valid file:// URLs";
|
|
378
|
-
}
|
|
379
|
-
message += `. Received protocol '${url.protocol}'`;
|
|
380
|
-
return message;
|
|
381
|
-
},
|
|
382
|
-
Error
|
|
383
|
-
);
|
|
384
|
-
function createError(sym, value, def) {
|
|
385
|
-
messages.set(sym, value);
|
|
386
|
-
return makeNodeErrorWithCode(def, sym);
|
|
387
|
-
}
|
|
388
|
-
function makeNodeErrorWithCode(Base, key) {
|
|
389
|
-
return NodeError;
|
|
390
|
-
function NodeError(...args) {
|
|
391
|
-
const limit = Error.stackTraceLimit;
|
|
392
|
-
if (isErrorStackTraceLimitWritable()) {
|
|
393
|
-
Error.stackTraceLimit = 0;
|
|
394
|
-
}
|
|
395
|
-
const error = new Base();
|
|
396
|
-
if (isErrorStackTraceLimitWritable()) {
|
|
397
|
-
Error.stackTraceLimit = limit;
|
|
398
|
-
}
|
|
399
|
-
const message = getMessage(key, args, error);
|
|
400
|
-
Object.defineProperty(error, "message", {
|
|
401
|
-
value: message,
|
|
402
|
-
enumerable: false,
|
|
403
|
-
writable: true,
|
|
404
|
-
configurable: true
|
|
405
|
-
});
|
|
406
|
-
Object.defineProperty(error, "toString", {
|
|
407
|
-
value() {
|
|
408
|
-
return `${this.name} [${key}]: ${this.message}`;
|
|
409
|
-
},
|
|
410
|
-
enumerable: false,
|
|
411
|
-
writable: true,
|
|
412
|
-
configurable: true
|
|
413
|
-
});
|
|
414
|
-
addCodeToName(error, Base.name, key);
|
|
415
|
-
error.code = key;
|
|
416
|
-
return error;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
const addCodeToName = hideStackFrames(
|
|
420
|
-
function(error, name, code) {
|
|
421
|
-
error = captureLargerStackTrace(error);
|
|
422
|
-
error.name = `${name} [${code}]`;
|
|
423
|
-
error.stack;
|
|
424
|
-
if (name === "SystemError") {
|
|
425
|
-
Object.defineProperty(error, "name", {
|
|
426
|
-
value: name,
|
|
427
|
-
enumerable: false,
|
|
428
|
-
writable: true,
|
|
429
|
-
configurable: true
|
|
430
|
-
});
|
|
431
|
-
} else {
|
|
432
|
-
delete error.name;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
);
|
|
436
|
-
function isErrorStackTraceLimitWritable() {
|
|
437
|
-
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
438
|
-
if (desc === void 0) {
|
|
439
|
-
return Object.isExtensible(Error);
|
|
440
|
-
}
|
|
441
|
-
return own$1.call(desc, "writable") ? desc.writable : desc.set !== void 0;
|
|
442
|
-
}
|
|
443
|
-
function hideStackFrames(fn) {
|
|
444
|
-
const hidden = nodeInternalPrefix + fn.name;
|
|
445
|
-
Object.defineProperty(fn, "name", { value: hidden });
|
|
446
|
-
return fn;
|
|
447
|
-
}
|
|
448
|
-
const captureLargerStackTrace = hideStackFrames(
|
|
449
|
-
function(error) {
|
|
450
|
-
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
451
|
-
if (stackTraceLimitIsWritable) {
|
|
452
|
-
userStackTraceLimit = Error.stackTraceLimit;
|
|
453
|
-
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
454
|
-
}
|
|
455
|
-
Error.captureStackTrace(error);
|
|
456
|
-
if (stackTraceLimitIsWritable) {
|
|
457
|
-
Error.stackTraceLimit = userStackTraceLimit;
|
|
458
|
-
}
|
|
459
|
-
return error;
|
|
460
|
-
}
|
|
461
|
-
);
|
|
462
|
-
function getMessage(key, args, self) {
|
|
463
|
-
const message = messages.get(key);
|
|
464
|
-
if (typeof message === "function") {
|
|
465
|
-
assert(
|
|
466
|
-
message.length <= args.length,
|
|
467
|
-
`Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${message.length}).`
|
|
468
|
-
);
|
|
469
|
-
return Reflect.apply(message, self, args);
|
|
470
|
-
}
|
|
471
|
-
const expectedLength = (message.match(/%[dfijoOs]/g) || []).length;
|
|
472
|
-
assert(
|
|
473
|
-
expectedLength === args.length,
|
|
474
|
-
`Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${expectedLength}).`
|
|
475
|
-
);
|
|
476
|
-
if (args.length === 0) {
|
|
477
|
-
return message;
|
|
478
|
-
}
|
|
479
|
-
args.unshift(message);
|
|
480
|
-
return Reflect.apply(format, null, args);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
const { ERR_UNKNOWN_FILE_EXTENSION } = codes;
|
|
484
|
-
const extensionFormatMap = {
|
|
485
|
-
__proto__: null,
|
|
486
|
-
".cjs": "commonjs",
|
|
487
|
-
".js": "module",
|
|
488
|
-
".mjs": "module"
|
|
489
|
-
};
|
|
490
|
-
function defaultGetFormat(url) {
|
|
491
|
-
if (url.startsWith("node:")) {
|
|
492
|
-
return { format: "builtin" };
|
|
493
|
-
}
|
|
494
|
-
const parsed = new URL$1(url);
|
|
495
|
-
if (parsed.protocol === "data:") {
|
|
496
|
-
const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
|
|
497
|
-
parsed.pathname
|
|
498
|
-
) || [null, null];
|
|
499
|
-
const format = mime === "text/javascript" ? "module" : null;
|
|
500
|
-
return { format };
|
|
501
|
-
}
|
|
502
|
-
if (parsed.protocol === "file:") {
|
|
503
|
-
const ext = path.extname(parsed.pathname);
|
|
504
|
-
let format;
|
|
505
|
-
if (ext === ".js") {
|
|
506
|
-
format = getPackageType(parsed.href) === "module" ? "module" : "commonjs";
|
|
507
|
-
} else {
|
|
508
|
-
format = extensionFormatMap[ext];
|
|
509
|
-
}
|
|
510
|
-
if (!format) {
|
|
511
|
-
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, fileURLToPath$1(url));
|
|
512
|
-
}
|
|
513
|
-
return { format: format || null };
|
|
514
|
-
}
|
|
515
|
-
return { format: null };
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
const {
|
|
519
|
-
ERR_INVALID_MODULE_SPECIFIER,
|
|
520
|
-
ERR_INVALID_PACKAGE_CONFIG,
|
|
521
|
-
ERR_INVALID_PACKAGE_TARGET,
|
|
522
|
-
ERR_MODULE_NOT_FOUND,
|
|
523
|
-
ERR_PACKAGE_IMPORT_NOT_DEFINED,
|
|
524
|
-
ERR_PACKAGE_PATH_NOT_EXPORTED,
|
|
525
|
-
ERR_UNSUPPORTED_DIR_IMPORT,
|
|
526
|
-
ERR_UNSUPPORTED_ESM_URL_SCHEME,
|
|
527
|
-
ERR_INVALID_ARG_VALUE
|
|
528
|
-
} = codes;
|
|
529
|
-
const own = {}.hasOwnProperty;
|
|
530
|
-
Object.freeze(["node", "import"]);
|
|
531
|
-
const invalidSegmentRegEx = /(^|\\|\/)(\.\.?|node_modules)(\\|\/|$)/;
|
|
532
|
-
const patternRegEx = /\*/g;
|
|
533
|
-
const encodedSepRegEx = /%2f|%2c/i;
|
|
534
|
-
const emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
535
|
-
const packageJsonCache = /* @__PURE__ */ new Map();
|
|
536
|
-
function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) {
|
|
537
|
-
const pjsonPath = fileURLToPath$1(pjsonUrl);
|
|
538
|
-
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
542
|
-
process.emitWarning(
|
|
543
|
-
`Use of deprecated folder mapping "${match}" in the ${isExports ? '"exports"' : '"imports"'} field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath$1(base)}` : ""}.
|
|
544
|
-
Update this package.json to use a subpath pattern like "${match}*".`,
|
|
545
|
-
"DeprecationWarning",
|
|
546
|
-
"DEP0148"
|
|
547
|
-
);
|
|
548
|
-
}
|
|
549
|
-
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
550
|
-
const { format } = defaultGetFormat(url.href);
|
|
551
|
-
if (format !== "module") {
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
const path2 = fileURLToPath$1(url.href);
|
|
555
|
-
const pkgPath = fileURLToPath$1(new URL(".", packageJsonUrl));
|
|
556
|
-
const basePath = fileURLToPath$1(base);
|
|
557
|
-
if (main) {
|
|
558
|
-
process.emitWarning(
|
|
559
|
-
`Package ${pkgPath} has a "main" field set to ${JSON.stringify(main)}, excluding the full filename and extension to the resolved file at "${path2.slice(
|
|
560
|
-
pkgPath.length
|
|
561
|
-
)}", imported from ${basePath}.
|
|
562
|
-
Automatic extension resolution of the "main" field isdeprecated for ES modules.`,
|
|
563
|
-
"DeprecationWarning",
|
|
564
|
-
"DEP0151"
|
|
565
|
-
);
|
|
566
|
-
} else {
|
|
567
|
-
process.emitWarning(
|
|
568
|
-
`No "main" or "exports" field defined in the package.json for ${pkgPath} resolving the main entry point "${path2.slice(
|
|
569
|
-
pkgPath.length
|
|
570
|
-
)}", imported from ${basePath}.
|
|
571
|
-
Default "index" lookups for the main are deprecated for ES modules.`,
|
|
572
|
-
"DeprecationWarning",
|
|
573
|
-
"DEP0151"
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
function tryStatSync(path2) {
|
|
578
|
-
try {
|
|
579
|
-
return statSync(path2);
|
|
580
|
-
} catch {
|
|
581
|
-
return new Stats();
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function getPackageConfig(path2, specifier, base) {
|
|
585
|
-
const existing = packageJsonCache.get(path2);
|
|
586
|
-
if (existing !== void 0) {
|
|
587
|
-
return existing;
|
|
588
|
-
}
|
|
589
|
-
const source = packageJsonReader.read(path2).string;
|
|
590
|
-
if (source === void 0) {
|
|
591
|
-
const packageConfig2 = {
|
|
592
|
-
pjsonPath: path2,
|
|
593
|
-
exists: false,
|
|
594
|
-
main: void 0,
|
|
595
|
-
name: void 0,
|
|
596
|
-
type: "none",
|
|
597
|
-
exports: void 0,
|
|
598
|
-
imports: void 0
|
|
599
|
-
};
|
|
600
|
-
packageJsonCache.set(path2, packageConfig2);
|
|
601
|
-
return packageConfig2;
|
|
602
|
-
}
|
|
603
|
-
let packageJson;
|
|
604
|
-
try {
|
|
605
|
-
packageJson = JSON.parse(source);
|
|
606
|
-
} catch (error) {
|
|
607
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
608
|
-
path2,
|
|
609
|
-
(base ? `"${specifier}" from ` : "") + fileURLToPath$1(base || specifier),
|
|
610
|
-
error.message
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
const { exports, imports, main, name, type } = packageJson;
|
|
614
|
-
const packageConfig = {
|
|
615
|
-
pjsonPath: path2,
|
|
616
|
-
exists: true,
|
|
617
|
-
main: typeof main === "string" ? main : void 0,
|
|
618
|
-
name: typeof name === "string" ? name : void 0,
|
|
619
|
-
type: type === "module" || type === "commonjs" ? type : "none",
|
|
620
|
-
exports,
|
|
621
|
-
imports: imports && typeof imports === "object" ? imports : void 0
|
|
622
|
-
};
|
|
623
|
-
packageJsonCache.set(path2, packageConfig);
|
|
624
|
-
return packageConfig;
|
|
625
|
-
}
|
|
626
|
-
function getPackageScopeConfig(resolved) {
|
|
627
|
-
let packageJsonUrl = new URL("./package.json", resolved);
|
|
628
|
-
while (true) {
|
|
629
|
-
const packageJsonPath2 = packageJsonUrl.pathname;
|
|
630
|
-
if (packageJsonPath2.endsWith("node_modules/package.json")) {
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
const packageConfig2 = getPackageConfig(
|
|
634
|
-
fileURLToPath$1(packageJsonUrl),
|
|
635
|
-
resolved
|
|
636
|
-
);
|
|
637
|
-
if (packageConfig2.exists) {
|
|
638
|
-
return packageConfig2;
|
|
639
|
-
}
|
|
640
|
-
const lastPackageJsonUrl = packageJsonUrl;
|
|
641
|
-
packageJsonUrl = new URL("../package.json", packageJsonUrl);
|
|
642
|
-
if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) {
|
|
643
|
-
break;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
const packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
647
|
-
const packageConfig = {
|
|
648
|
-
pjsonPath: packageJsonPath,
|
|
649
|
-
exists: false,
|
|
650
|
-
main: void 0,
|
|
651
|
-
name: void 0,
|
|
652
|
-
type: "none",
|
|
653
|
-
exports: void 0,
|
|
654
|
-
imports: void 0
|
|
655
|
-
};
|
|
656
|
-
packageJsonCache.set(packageJsonPath, packageConfig);
|
|
657
|
-
return packageConfig;
|
|
658
|
-
}
|
|
659
|
-
function fileExists(url) {
|
|
660
|
-
return tryStatSync(fileURLToPath$1(url)).isFile();
|
|
661
|
-
}
|
|
662
|
-
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
663
|
-
let guess;
|
|
664
|
-
if (packageConfig.main !== void 0) {
|
|
665
|
-
guess = new URL(`./${packageConfig.main}`, packageJsonUrl);
|
|
666
|
-
if (fileExists(guess)) {
|
|
667
|
-
return guess;
|
|
668
|
-
}
|
|
669
|
-
const tries2 = [
|
|
670
|
-
`./${packageConfig.main}.js`,
|
|
671
|
-
`./${packageConfig.main}.json`,
|
|
672
|
-
`./${packageConfig.main}.node`,
|
|
673
|
-
`./${packageConfig.main}/index.js`,
|
|
674
|
-
`./${packageConfig.main}/index.json`,
|
|
675
|
-
`./${packageConfig.main}/index.node`
|
|
676
|
-
];
|
|
677
|
-
let i2 = -1;
|
|
678
|
-
while (++i2 < tries2.length) {
|
|
679
|
-
guess = new URL(tries2[i2], packageJsonUrl);
|
|
680
|
-
if (fileExists(guess)) {
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
guess = void 0;
|
|
684
|
-
}
|
|
685
|
-
if (guess) {
|
|
686
|
-
emitLegacyIndexDeprecation(
|
|
687
|
-
guess,
|
|
688
|
-
packageJsonUrl,
|
|
689
|
-
base,
|
|
690
|
-
packageConfig.main
|
|
691
|
-
);
|
|
692
|
-
return guess;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
const tries = ["./index.js", "./index.json", "./index.node"];
|
|
696
|
-
let i = -1;
|
|
697
|
-
while (++i < tries.length) {
|
|
698
|
-
guess = new URL(tries[i], packageJsonUrl);
|
|
699
|
-
if (fileExists(guess)) {
|
|
700
|
-
break;
|
|
701
|
-
}
|
|
702
|
-
guess = void 0;
|
|
703
|
-
}
|
|
704
|
-
if (guess) {
|
|
705
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
706
|
-
return guess;
|
|
707
|
-
}
|
|
708
|
-
throw new ERR_MODULE_NOT_FOUND(
|
|
709
|
-
fileURLToPath$1(new URL(".", packageJsonUrl)),
|
|
710
|
-
fileURLToPath$1(base)
|
|
711
|
-
);
|
|
712
|
-
}
|
|
713
|
-
function finalizeResolution(resolved, base) {
|
|
714
|
-
if (encodedSepRegEx.test(resolved.pathname)) {
|
|
715
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
716
|
-
resolved.pathname,
|
|
717
|
-
'must not include encoded "/" or "\\" characters',
|
|
718
|
-
fileURLToPath$1(base)
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
const path2 = fileURLToPath$1(resolved);
|
|
722
|
-
const stats = tryStatSync(path2.endsWith("/") ? path2.slice(-1) : path2);
|
|
723
|
-
if (stats.isDirectory()) {
|
|
724
|
-
const error = new ERR_UNSUPPORTED_DIR_IMPORT(path2, fileURLToPath$1(base));
|
|
725
|
-
error.url = String(resolved);
|
|
726
|
-
throw error;
|
|
727
|
-
}
|
|
728
|
-
if (!stats.isFile()) {
|
|
729
|
-
throw new ERR_MODULE_NOT_FOUND(
|
|
730
|
-
path2 || resolved.pathname,
|
|
731
|
-
base && fileURLToPath$1(base),
|
|
732
|
-
"module"
|
|
733
|
-
);
|
|
734
|
-
}
|
|
735
|
-
return resolved;
|
|
736
|
-
}
|
|
737
|
-
function throwImportNotDefined(specifier, packageJsonUrl, base) {
|
|
738
|
-
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
739
|
-
specifier,
|
|
740
|
-
packageJsonUrl && fileURLToPath$1(new URL(".", packageJsonUrl)),
|
|
741
|
-
fileURLToPath$1(base)
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
function throwExportsNotFound(subpath, packageJsonUrl, base) {
|
|
745
|
-
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
746
|
-
fileURLToPath$1(new URL(".", packageJsonUrl)),
|
|
747
|
-
subpath,
|
|
748
|
-
base && fileURLToPath$1(base)
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
function throwInvalidSubpath(subpath, packageJsonUrl, internal, base) {
|
|
752
|
-
const reason = `request is not a valid subpath for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath$1(packageJsonUrl)}`;
|
|
753
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
754
|
-
subpath,
|
|
755
|
-
reason,
|
|
756
|
-
base && fileURLToPath$1(base)
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
function throwInvalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
760
|
-
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
761
|
-
throw new ERR_INVALID_PACKAGE_TARGET(
|
|
762
|
-
fileURLToPath$1(new URL(".", packageJsonUrl)),
|
|
763
|
-
subpath,
|
|
764
|
-
target,
|
|
765
|
-
internal,
|
|
766
|
-
base && fileURLToPath$1(base)
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, conditions) {
|
|
770
|
-
if (subpath !== "" && !pattern && target[target.length - 1] !== "/") {
|
|
771
|
-
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
772
|
-
}
|
|
773
|
-
if (!target.startsWith("./")) {
|
|
774
|
-
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
775
|
-
let isURL = false;
|
|
776
|
-
try {
|
|
777
|
-
new URL(target);
|
|
778
|
-
isURL = true;
|
|
779
|
-
} catch {
|
|
780
|
-
}
|
|
781
|
-
if (!isURL) {
|
|
782
|
-
const exportTarget = pattern ? target.replace(patternRegEx, subpath) : target + subpath;
|
|
783
|
-
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
787
|
-
}
|
|
788
|
-
if (invalidSegmentRegEx.test(target.slice(2))) {
|
|
789
|
-
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
790
|
-
}
|
|
791
|
-
const resolved = new URL(target, packageJsonUrl);
|
|
792
|
-
const resolvedPath = resolved.pathname;
|
|
793
|
-
const packagePath = new URL(".", packageJsonUrl).pathname;
|
|
794
|
-
if (!resolvedPath.startsWith(packagePath)) {
|
|
795
|
-
throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
796
|
-
}
|
|
797
|
-
if (subpath === "") {
|
|
798
|
-
return resolved;
|
|
799
|
-
}
|
|
800
|
-
if (invalidSegmentRegEx.test(subpath)) {
|
|
801
|
-
throwInvalidSubpath(match + subpath, packageJsonUrl, internal, base);
|
|
802
|
-
}
|
|
803
|
-
if (pattern) {
|
|
804
|
-
return new URL(resolved.href.replace(patternRegEx, subpath));
|
|
805
|
-
}
|
|
806
|
-
return new URL(subpath, resolved);
|
|
807
|
-
}
|
|
808
|
-
function isArrayIndex(key) {
|
|
809
|
-
const keyNumber = Number(key);
|
|
810
|
-
if (`${keyNumber}` !== key) {
|
|
811
|
-
return false;
|
|
812
|
-
}
|
|
813
|
-
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
814
|
-
}
|
|
815
|
-
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, conditions) {
|
|
816
|
-
if (typeof target === "string") {
|
|
817
|
-
return resolvePackageTargetString(
|
|
818
|
-
target,
|
|
819
|
-
subpath,
|
|
820
|
-
packageSubpath,
|
|
821
|
-
packageJsonUrl,
|
|
822
|
-
base,
|
|
823
|
-
pattern,
|
|
824
|
-
internal,
|
|
825
|
-
conditions
|
|
826
|
-
);
|
|
827
|
-
}
|
|
828
|
-
if (Array.isArray(target)) {
|
|
829
|
-
const targetList = target;
|
|
830
|
-
if (targetList.length === 0) {
|
|
831
|
-
return null;
|
|
832
|
-
}
|
|
833
|
-
let lastException;
|
|
834
|
-
let i = -1;
|
|
835
|
-
while (++i < targetList.length) {
|
|
836
|
-
const targetItem = targetList[i];
|
|
837
|
-
let resolved;
|
|
838
|
-
try {
|
|
839
|
-
resolved = resolvePackageTarget(
|
|
840
|
-
packageJsonUrl,
|
|
841
|
-
targetItem,
|
|
842
|
-
subpath,
|
|
843
|
-
packageSubpath,
|
|
844
|
-
base,
|
|
845
|
-
pattern,
|
|
846
|
-
internal,
|
|
847
|
-
conditions
|
|
848
|
-
);
|
|
849
|
-
} catch (error) {
|
|
850
|
-
lastException = error;
|
|
851
|
-
if (error.code === "ERR_INVALID_PACKAGE_TARGET") {
|
|
852
|
-
continue;
|
|
853
|
-
}
|
|
854
|
-
throw error;
|
|
855
|
-
}
|
|
856
|
-
if (resolved === void 0) {
|
|
857
|
-
continue;
|
|
858
|
-
}
|
|
859
|
-
if (resolved === null) {
|
|
860
|
-
lastException = null;
|
|
861
|
-
continue;
|
|
862
|
-
}
|
|
863
|
-
return resolved;
|
|
864
|
-
}
|
|
865
|
-
if (lastException === void 0 || lastException === null) {
|
|
866
|
-
return lastException;
|
|
867
|
-
}
|
|
868
|
-
throw lastException;
|
|
869
|
-
}
|
|
870
|
-
if (typeof target === "object" && target !== null) {
|
|
871
|
-
const keys = Object.getOwnPropertyNames(target);
|
|
872
|
-
let i = -1;
|
|
873
|
-
while (++i < keys.length) {
|
|
874
|
-
const key = keys[i];
|
|
875
|
-
if (isArrayIndex(key)) {
|
|
876
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
877
|
-
fileURLToPath$1(packageJsonUrl),
|
|
878
|
-
base,
|
|
879
|
-
'"exports" cannot contain numeric property keys.'
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
i = -1;
|
|
884
|
-
while (++i < keys.length) {
|
|
885
|
-
const key = keys[i];
|
|
886
|
-
if (key === "default" || conditions && conditions.has(key)) {
|
|
887
|
-
const conditionalTarget = target[key];
|
|
888
|
-
const resolved = resolvePackageTarget(
|
|
889
|
-
packageJsonUrl,
|
|
890
|
-
conditionalTarget,
|
|
891
|
-
subpath,
|
|
892
|
-
packageSubpath,
|
|
893
|
-
base,
|
|
894
|
-
pattern,
|
|
895
|
-
internal,
|
|
896
|
-
conditions
|
|
897
|
-
);
|
|
898
|
-
if (resolved === void 0) {
|
|
899
|
-
continue;
|
|
900
|
-
}
|
|
901
|
-
return resolved;
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
return void 0;
|
|
905
|
-
}
|
|
906
|
-
if (target === null) {
|
|
907
|
-
return null;
|
|
908
|
-
}
|
|
909
|
-
throwInvalidPackageTarget(
|
|
910
|
-
packageSubpath,
|
|
911
|
-
target,
|
|
912
|
-
packageJsonUrl,
|
|
913
|
-
internal,
|
|
914
|
-
base
|
|
915
|
-
);
|
|
916
|
-
}
|
|
917
|
-
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
918
|
-
if (typeof exports === "string" || Array.isArray(exports)) {
|
|
919
|
-
return true;
|
|
920
|
-
}
|
|
921
|
-
if (typeof exports !== "object" || exports === null) {
|
|
922
|
-
return false;
|
|
923
|
-
}
|
|
924
|
-
const keys = Object.getOwnPropertyNames(exports);
|
|
925
|
-
let isConditionalSugar = false;
|
|
926
|
-
let i = 0;
|
|
927
|
-
let j = -1;
|
|
928
|
-
while (++j < keys.length) {
|
|
929
|
-
const key = keys[j];
|
|
930
|
-
const curIsConditionalSugar = key === "" || key[0] !== ".";
|
|
931
|
-
if (i++ === 0) {
|
|
932
|
-
isConditionalSugar = curIsConditionalSugar;
|
|
933
|
-
} else if (isConditionalSugar !== curIsConditionalSugar) {
|
|
934
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(
|
|
935
|
-
fileURLToPath$1(packageJsonUrl),
|
|
936
|
-
base,
|
|
937
|
-
`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`
|
|
938
|
-
);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
return isConditionalSugar;
|
|
942
|
-
}
|
|
943
|
-
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
944
|
-
let exports = packageConfig.exports;
|
|
945
|
-
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
|
|
946
|
-
exports = { ".": exports };
|
|
947
|
-
}
|
|
948
|
-
if (own.call(exports, packageSubpath)) {
|
|
949
|
-
const target = exports[packageSubpath];
|
|
950
|
-
const resolved = resolvePackageTarget(
|
|
951
|
-
packageJsonUrl,
|
|
952
|
-
target,
|
|
953
|
-
"",
|
|
954
|
-
packageSubpath,
|
|
955
|
-
base,
|
|
956
|
-
false,
|
|
957
|
-
false,
|
|
958
|
-
conditions
|
|
959
|
-
);
|
|
960
|
-
if (resolved === null || resolved === void 0) {
|
|
961
|
-
throwExportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
962
|
-
}
|
|
963
|
-
return { resolved, exact: true };
|
|
964
|
-
}
|
|
965
|
-
let bestMatch = "";
|
|
966
|
-
const keys = Object.getOwnPropertyNames(exports);
|
|
967
|
-
let i = -1;
|
|
968
|
-
while (++i < keys.length) {
|
|
969
|
-
const key = keys[i];
|
|
970
|
-
if (key[key.length - 1] === "*" && packageSubpath.startsWith(key.slice(0, -1)) && packageSubpath.length >= key.length && key.length > bestMatch.length) {
|
|
971
|
-
bestMatch = key;
|
|
972
|
-
} else if (key[key.length - 1] === "/" && packageSubpath.startsWith(key) && key.length > bestMatch.length) {
|
|
973
|
-
bestMatch = key;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
if (bestMatch) {
|
|
977
|
-
const target = exports[bestMatch];
|
|
978
|
-
const pattern = bestMatch[bestMatch.length - 1] === "*";
|
|
979
|
-
const subpath = packageSubpath.slice(bestMatch.length - (pattern ? 1 : 0));
|
|
980
|
-
const resolved = resolvePackageTarget(
|
|
981
|
-
packageJsonUrl,
|
|
982
|
-
target,
|
|
983
|
-
subpath,
|
|
984
|
-
bestMatch,
|
|
985
|
-
base,
|
|
986
|
-
pattern,
|
|
987
|
-
false,
|
|
988
|
-
conditions
|
|
989
|
-
);
|
|
990
|
-
if (resolved === null || resolved === void 0) {
|
|
991
|
-
throwExportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
992
|
-
}
|
|
993
|
-
if (!pattern) {
|
|
994
|
-
emitFolderMapDeprecation(bestMatch, packageJsonUrl, true, base);
|
|
995
|
-
}
|
|
996
|
-
return { resolved, exact: pattern };
|
|
997
|
-
}
|
|
998
|
-
throwExportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
999
|
-
}
|
|
1000
|
-
function packageImportsResolve(name, base, conditions) {
|
|
1001
|
-
if (name === "#" || name.startsWith("#/")) {
|
|
1002
|
-
const reason = "is not a valid internal imports specifier name";
|
|
1003
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath$1(base));
|
|
1004
|
-
}
|
|
1005
|
-
let packageJsonUrl;
|
|
1006
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
1007
|
-
if (packageConfig.exists) {
|
|
1008
|
-
packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
1009
|
-
const imports = packageConfig.imports;
|
|
1010
|
-
if (imports) {
|
|
1011
|
-
if (own.call(imports, name)) {
|
|
1012
|
-
const resolved = resolvePackageTarget(
|
|
1013
|
-
packageJsonUrl,
|
|
1014
|
-
imports[name],
|
|
1015
|
-
"",
|
|
1016
|
-
name,
|
|
1017
|
-
base,
|
|
1018
|
-
false,
|
|
1019
|
-
true,
|
|
1020
|
-
conditions
|
|
1021
|
-
);
|
|
1022
|
-
if (resolved !== null) {
|
|
1023
|
-
return { resolved, exact: true };
|
|
1024
|
-
}
|
|
1025
|
-
} else {
|
|
1026
|
-
let bestMatch = "";
|
|
1027
|
-
const keys = Object.getOwnPropertyNames(imports);
|
|
1028
|
-
let i = -1;
|
|
1029
|
-
while (++i < keys.length) {
|
|
1030
|
-
const key = keys[i];
|
|
1031
|
-
if (key[key.length - 1] === "*" && name.startsWith(key.slice(0, -1)) && name.length >= key.length && key.length > bestMatch.length) {
|
|
1032
|
-
bestMatch = key;
|
|
1033
|
-
} else if (key[key.length - 1] === "/" && name.startsWith(key) && key.length > bestMatch.length) {
|
|
1034
|
-
bestMatch = key;
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
if (bestMatch) {
|
|
1038
|
-
const target = imports[bestMatch];
|
|
1039
|
-
const pattern = bestMatch[bestMatch.length - 1] === "*";
|
|
1040
|
-
const subpath = name.slice(bestMatch.length - (pattern ? 1 : 0));
|
|
1041
|
-
const resolved = resolvePackageTarget(
|
|
1042
|
-
packageJsonUrl,
|
|
1043
|
-
target,
|
|
1044
|
-
subpath,
|
|
1045
|
-
bestMatch,
|
|
1046
|
-
base,
|
|
1047
|
-
pattern,
|
|
1048
|
-
true,
|
|
1049
|
-
conditions
|
|
1050
|
-
);
|
|
1051
|
-
if (resolved !== null) {
|
|
1052
|
-
if (!pattern) {
|
|
1053
|
-
emitFolderMapDeprecation(bestMatch, packageJsonUrl, false, base);
|
|
1054
|
-
}
|
|
1055
|
-
return { resolved, exact: pattern };
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
throwImportNotDefined(name, packageJsonUrl, base);
|
|
1062
|
-
}
|
|
1063
|
-
function getPackageType(url) {
|
|
1064
|
-
const packageConfig = getPackageScopeConfig(url);
|
|
1065
|
-
return packageConfig.type;
|
|
1066
|
-
}
|
|
1067
|
-
function parsePackageName(specifier, base) {
|
|
1068
|
-
let separatorIndex = specifier.indexOf("/");
|
|
1069
|
-
let validPackageName = true;
|
|
1070
|
-
let isScoped = false;
|
|
1071
|
-
if (specifier[0] === "@") {
|
|
1072
|
-
isScoped = true;
|
|
1073
|
-
if (separatorIndex === -1 || specifier.length === 0) {
|
|
1074
|
-
validPackageName = false;
|
|
1075
|
-
} else {
|
|
1076
|
-
separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
1080
|
-
let i = -1;
|
|
1081
|
-
while (++i < packageName.length) {
|
|
1082
|
-
if (packageName[i] === "%" || packageName[i] === "\\") {
|
|
1083
|
-
validPackageName = false;
|
|
1084
|
-
break;
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
if (!validPackageName) {
|
|
1088
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(
|
|
1089
|
-
specifier,
|
|
1090
|
-
"is not a valid package name",
|
|
1091
|
-
fileURLToPath$1(base)
|
|
1092
|
-
);
|
|
1093
|
-
}
|
|
1094
|
-
const packageSubpath = "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex));
|
|
1095
|
-
return { packageName, packageSubpath, isScoped };
|
|
1096
|
-
}
|
|
1097
|
-
function packageResolve(specifier, base, conditions) {
|
|
1098
|
-
const { packageName, packageSubpath, isScoped } = parsePackageName(
|
|
1099
|
-
specifier,
|
|
1100
|
-
base
|
|
1101
|
-
);
|
|
1102
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
1103
|
-
if (packageConfig.exists) {
|
|
1104
|
-
const packageJsonUrl2 = pathToFileURL(packageConfig.pjsonPath);
|
|
1105
|
-
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
|
|
1106
|
-
return packageExportsResolve(
|
|
1107
|
-
packageJsonUrl2,
|
|
1108
|
-
packageSubpath,
|
|
1109
|
-
packageConfig,
|
|
1110
|
-
base,
|
|
1111
|
-
conditions
|
|
1112
|
-
).resolved;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
let packageJsonUrl = new URL(
|
|
1116
|
-
"./node_modules/" + packageName + "/package.json",
|
|
1117
|
-
base
|
|
1118
|
-
);
|
|
1119
|
-
let packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
1120
|
-
let lastPath;
|
|
1121
|
-
do {
|
|
1122
|
-
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
1123
|
-
if (!stat.isDirectory()) {
|
|
1124
|
-
lastPath = packageJsonPath;
|
|
1125
|
-
packageJsonUrl = new URL(
|
|
1126
|
-
(isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
|
|
1127
|
-
packageJsonUrl
|
|
1128
|
-
);
|
|
1129
|
-
packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
1130
|
-
continue;
|
|
1131
|
-
}
|
|
1132
|
-
const packageConfig2 = getPackageConfig(packageJsonPath, specifier, base);
|
|
1133
|
-
if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
|
|
1134
|
-
return packageExportsResolve(
|
|
1135
|
-
packageJsonUrl,
|
|
1136
|
-
packageSubpath,
|
|
1137
|
-
packageConfig2,
|
|
1138
|
-
base,
|
|
1139
|
-
conditions
|
|
1140
|
-
).resolved;
|
|
1141
|
-
}
|
|
1142
|
-
if (packageSubpath === ".") {
|
|
1143
|
-
return legacyMainResolve(packageJsonUrl, packageConfig2, base);
|
|
1144
|
-
}
|
|
1145
|
-
return new URL(packageSubpath, packageJsonUrl);
|
|
1146
|
-
} while (packageJsonPath.length !== lastPath.length);
|
|
1147
|
-
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath$1(base));
|
|
1148
|
-
}
|
|
1149
|
-
function isRelativeSpecifier(specifier) {
|
|
1150
|
-
if (specifier[0] === ".") {
|
|
1151
|
-
if (specifier.length === 1 || specifier[1] === "/") {
|
|
1152
|
-
return true;
|
|
1153
|
-
}
|
|
1154
|
-
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) {
|
|
1155
|
-
return true;
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
return false;
|
|
1159
|
-
}
|
|
1160
|
-
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
1161
|
-
if (specifier === "") {
|
|
1162
|
-
return false;
|
|
1163
|
-
}
|
|
1164
|
-
if (specifier[0] === "/") {
|
|
1165
|
-
return true;
|
|
1166
|
-
}
|
|
1167
|
-
return isRelativeSpecifier(specifier);
|
|
1168
|
-
}
|
|
1169
|
-
function moduleResolve(specifier, base, conditions) {
|
|
1170
|
-
let resolved;
|
|
1171
|
-
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
1172
|
-
resolved = new URL(specifier, base);
|
|
1173
|
-
} else if (specifier[0] === "#") {
|
|
1174
|
-
({ resolved } = packageImportsResolve(specifier, base, conditions));
|
|
1175
|
-
} else {
|
|
1176
|
-
try {
|
|
1177
|
-
resolved = new URL(specifier);
|
|
1178
|
-
} catch {
|
|
1179
|
-
resolved = packageResolve(specifier, base, conditions);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
return finalizeResolution(resolved, base);
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
function fileURLToPath(id) {
|
|
1186
|
-
if (typeof id === "string" && !id.startsWith("file://")) {
|
|
1187
|
-
return normalizeSlash(id);
|
|
1188
|
-
}
|
|
1189
|
-
return normalizeSlash(fileURLToPath$1(id));
|
|
1190
|
-
}
|
|
1191
|
-
function normalizeid(id) {
|
|
1192
|
-
if (typeof id !== "string") {
|
|
1193
|
-
id = id.toString();
|
|
1194
|
-
}
|
|
1195
|
-
if (/(node|data|http|https|file):/.test(id)) {
|
|
1196
|
-
return id;
|
|
1197
|
-
}
|
|
1198
|
-
if (BUILTIN_MODULES.has(id)) {
|
|
1199
|
-
return "node:" + id;
|
|
1200
|
-
}
|
|
1201
|
-
return "file://" + encodeURI(normalizeSlash(id));
|
|
1202
|
-
}
|
|
1203
|
-
function isNodeBuiltin(id = "") {
|
|
1204
|
-
id = id.replace(/^node:/, "").split("/")[0];
|
|
1205
|
-
return BUILTIN_MODULES.has(id);
|
|
1206
|
-
}
|
|
1207
|
-
const ProtocolRegex = /^(?<proto>.{2,}?):.+$/;
|
|
1208
|
-
function getProtocol(id) {
|
|
1209
|
-
const proto = id.match(ProtocolRegex);
|
|
1210
|
-
return proto ? proto.groups.proto : void 0;
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
const DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
|
|
1214
|
-
const DEFAULT_URL = pathToFileURL(process.cwd());
|
|
1215
|
-
const DEFAULT_EXTENSIONS = [".mjs", ".cjs", ".js", ".json"];
|
|
1216
|
-
const NOT_FOUND_ERRORS = /* @__PURE__ */ new Set(["ERR_MODULE_NOT_FOUND", "ERR_UNSUPPORTED_DIR_IMPORT", "MODULE_NOT_FOUND", "ERR_PACKAGE_PATH_NOT_EXPORTED"]);
|
|
1217
|
-
function _tryModuleResolve(id, url, conditions) {
|
|
1218
|
-
try {
|
|
1219
|
-
return moduleResolve(id, url, conditions);
|
|
1220
|
-
} catch (error) {
|
|
1221
|
-
if (!NOT_FOUND_ERRORS.has(error.code)) {
|
|
1222
|
-
throw error;
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
function _resolve(id, options = {}) {
|
|
1227
|
-
if (/(node|data|http|https):/.test(id)) {
|
|
1228
|
-
return id;
|
|
1229
|
-
}
|
|
1230
|
-
if (BUILTIN_MODULES.has(id)) {
|
|
1231
|
-
return "node:" + id;
|
|
1232
|
-
}
|
|
1233
|
-
if (isAbsolute(id) && existsSync(id)) {
|
|
1234
|
-
const realPath2 = realpathSync(fileURLToPath(id));
|
|
1235
|
-
return pathToFileURL(realPath2).toString();
|
|
1236
|
-
}
|
|
1237
|
-
const conditionsSet = options.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
|
|
1238
|
-
const _urls = (Array.isArray(options.url) ? options.url : [options.url]).filter(Boolean).map((u) => new URL(normalizeid(u.toString())));
|
|
1239
|
-
if (_urls.length === 0) {
|
|
1240
|
-
_urls.push(DEFAULT_URL);
|
|
1241
|
-
}
|
|
1242
|
-
const urls = [..._urls];
|
|
1243
|
-
for (const url of _urls) {
|
|
1244
|
-
if (url.protocol === "file:") {
|
|
1245
|
-
urls.push(
|
|
1246
|
-
new URL("./", url),
|
|
1247
|
-
new URL(joinURL(url.pathname, "_index.js"), url),
|
|
1248
|
-
new URL("node_modules", url)
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
let resolved;
|
|
1253
|
-
for (const url of urls) {
|
|
1254
|
-
resolved = _tryModuleResolve(id, url, conditionsSet);
|
|
1255
|
-
if (resolved) {
|
|
1256
|
-
break;
|
|
1257
|
-
}
|
|
1258
|
-
for (const prefix of ["", "/index"]) {
|
|
1259
|
-
for (const extension of options.extensions || DEFAULT_EXTENSIONS) {
|
|
1260
|
-
resolved = _tryModuleResolve(id + prefix + extension, url, conditionsSet);
|
|
1261
|
-
if (resolved) {
|
|
1262
|
-
break;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
if (resolved) {
|
|
1266
|
-
break;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
if (!resolved) {
|
|
1271
|
-
const error = new Error(`Cannot find module ${id} imported from ${urls.join(", ")}`);
|
|
1272
|
-
error.code = "ERR_MODULE_NOT_FOUND";
|
|
1273
|
-
throw error;
|
|
1274
|
-
}
|
|
1275
|
-
const realPath = realpathSync(fileURLToPath(resolved));
|
|
1276
|
-
return pathToFileURL(realPath).toString();
|
|
1277
|
-
}
|
|
1278
|
-
function resolveSync(id, options) {
|
|
1279
|
-
return _resolve(id, options);
|
|
1280
|
-
}
|
|
1281
|
-
function resolvePathSync(id, options) {
|
|
1282
|
-
return fileURLToPath(resolveSync(id, options));
|
|
1283
|
-
}
|
|
1284
|
-
function resolvePath(id, options) {
|
|
1285
|
-
return pcall(resolvePathSync, id, options);
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
const ESM_RE = /([\s;]|^)(import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
|
|
1289
|
-
const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
|
|
1290
|
-
function hasESMSyntax(code) {
|
|
1291
|
-
return ESM_RE.test(code);
|
|
1292
|
-
}
|
|
1293
|
-
const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
|
|
1294
|
-
function hasCJSSyntax(code) {
|
|
1295
|
-
return CJS_RE.test(code);
|
|
1296
|
-
}
|
|
1297
|
-
const validNodeImportDefaults = {
|
|
1298
|
-
allowedProtocols: ["node", "file", "data"]
|
|
1299
|
-
};
|
|
1300
|
-
async function isValidNodeImport(id, _options = {}) {
|
|
1301
|
-
if (isNodeBuiltin(id)) {
|
|
1302
|
-
return true;
|
|
1303
|
-
}
|
|
1304
|
-
const options = { ...validNodeImportDefaults, ..._options };
|
|
1305
|
-
const proto = getProtocol(id);
|
|
1306
|
-
if (proto && !options.allowedProtocols.includes(proto)) {
|
|
1307
|
-
return false;
|
|
1308
|
-
}
|
|
1309
|
-
if (proto === "data") {
|
|
1310
|
-
return true;
|
|
1311
|
-
}
|
|
1312
|
-
const resolvedPath = await resolvePath(id, options);
|
|
1313
|
-
const extension = extname(resolvedPath);
|
|
1314
|
-
if (BUILTIN_EXTENSIONS.has(extension)) {
|
|
1315
|
-
return true;
|
|
1316
|
-
}
|
|
1317
|
-
if (extension !== ".js") {
|
|
1318
|
-
return false;
|
|
1319
|
-
}
|
|
1320
|
-
const package_ = await readPackageJSON(resolvedPath).catch(() => {
|
|
1321
|
-
});
|
|
1322
|
-
if (package_?.type === "module") {
|
|
1323
|
-
return true;
|
|
1324
|
-
}
|
|
1325
|
-
if (/\.(\w+-)?esm?(-\w+)?\.js$|\/(esm?)\//.test(resolvedPath)) {
|
|
1326
|
-
return false;
|
|
1327
|
-
}
|
|
1328
|
-
const code = options.code || await promises.readFile(resolvedPath, "utf8").catch(() => {
|
|
1329
|
-
}) || "";
|
|
1330
|
-
return hasCJSSyntax(code) || !hasESMSyntax(code);
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
const isWindows = process.platform === "win32";
|
|
1334
|
-
function slash(str) {
|
|
1335
|
-
return str.replace(/\\/g, "/");
|
|
1336
|
-
}
|
|
1337
|
-
function normalizeRequestId(id, base) {
|
|
1338
|
-
if (base && id.startsWith(base))
|
|
1339
|
-
id = `/${id.slice(base.length)}`;
|
|
1340
|
-
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
1341
|
-
}
|
|
1342
|
-
const queryRE = /\?.*$/s;
|
|
1343
|
-
const hashRE = /#.*$/s;
|
|
1344
|
-
const cleanUrl = (url) => url.replace(hashRE, "").replace(queryRE, "");
|
|
1345
|
-
function normalizeModuleId(id) {
|
|
1346
|
-
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
1347
|
-
}
|
|
1348
|
-
function isPrimitive(v) {
|
|
1349
|
-
return v !== Object(v);
|
|
1350
|
-
}
|
|
1351
|
-
function pathFromRoot(root, filename) {
|
|
1352
|
-
if (isNodeBuiltin(filename))
|
|
1353
|
-
return filename;
|
|
1354
|
-
filename = filename.replace(/^\/@fs\//, isWindows ? "" : "/");
|
|
1355
|
-
if (!filename.startsWith(root))
|
|
1356
|
-
return filename;
|
|
1357
|
-
const relativePath = relative(root, filename);
|
|
1358
|
-
const segments = relativePath.split("/");
|
|
1359
|
-
const startIndex = segments.findIndex((segment) => segment !== ".." && segment !== ".");
|
|
1360
|
-
return `/${segments.slice(startIndex).join("/")}`;
|
|
1361
|
-
}
|
|
1362
|
-
function toFilePath(id, root) {
|
|
1363
|
-
let absolute = (() => {
|
|
1364
|
-
if (id.startsWith("/@fs/"))
|
|
1365
|
-
return id.slice(4);
|
|
1366
|
-
if (!id.startsWith(root) && id.startsWith("/")) {
|
|
1367
|
-
const resolved = resolve$1(root, id.slice(1));
|
|
1368
|
-
if (existsSync(resolved.replace(/\?.*$/, "")))
|
|
1369
|
-
return resolved;
|
|
1370
|
-
}
|
|
1371
|
-
return id;
|
|
1372
|
-
})();
|
|
1373
|
-
if (absolute.startsWith("//"))
|
|
1374
|
-
absolute = absolute.slice(1);
|
|
1375
|
-
return isWindows && absolute.startsWith("/") ? slash(fileURLToPath$1(pathToFileURL(absolute.slice(1)).href)) : absolute;
|
|
1376
|
-
}
|
|
1377
|
-
function toArray(array) {
|
|
1378
|
-
if (array === null || array === void 0)
|
|
1379
|
-
array = [];
|
|
1380
|
-
if (Array.isArray(array))
|
|
1381
|
-
return array;
|
|
1382
|
-
return [array];
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
export { isValidNodeImport as a, toFilePath as b, normalizeRequestId as c, cleanUrl as d, isPrimitive as e, hasCJSSyntax as h, isNodeBuiltin as i, normalizeModuleId as n, pathFromRoot as p, slash as s, toArray as t };
|