vitest 0.24.5 → 0.25.1

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