storybook 10.0.0-beta.2 → 10.0.0-beta.3

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 (70) hide show
  1. package/dist/_node-chunks/{builder-manager-KCNW2J74.js → builder-manager-DXAEQZJB.js} +16 -16
  2. package/dist/_node-chunks/{camelcase-FH5EGUIB.js → camelcase-CMMT6PHY.js} +7 -7
  3. package/dist/_node-chunks/{chunk-FXPYWCQE.js → chunk-3SUJKLRV.js} +7 -7
  4. package/dist/_node-chunks/{chunk-6B3CXS7K.js → chunk-4TGAX5W7.js} +7 -7
  5. package/dist/_node-chunks/{chunk-NWTLWMJN.js → chunk-5XVEWBRA.js} +143 -15
  6. package/dist/_node-chunks/{chunk-CIIY3F53.js → chunk-6Z44ODDR.js} +7 -7
  7. package/dist/_node-chunks/{chunk-KDKM7KMS.js → chunk-7EGB7ALG.js} +7 -7
  8. package/dist/_node-chunks/{chunk-B7L5A4BQ.js → chunk-AKW5OJ2T.js} +9 -9
  9. package/dist/_node-chunks/chunk-ALWVSNSK.js +62 -0
  10. package/dist/_node-chunks/{chunk-JZ7ZEAK6.js → chunk-BV4J7FF6.js} +7 -7
  11. package/dist/_node-chunks/{chunk-2E5IZBC2.js → chunk-CNKVQCQJ.js} +7 -7
  12. package/dist/_node-chunks/{chunk-MX77OTGN.js → chunk-DNOOZ2LS.js} +58 -47
  13. package/dist/_node-chunks/{chunk-HSI4BG2J.js → chunk-EI44VA3U.js} +8 -8
  14. package/dist/_node-chunks/{chunk-6A2WP6N7.js → chunk-EVY6P65U.js} +7 -7
  15. package/dist/_node-chunks/{chunk-HSS67Y6T.js → chunk-IA7M33LK.js} +7 -7
  16. package/dist/_node-chunks/{chunk-NTXIDMDM.js → chunk-ICETGZAR.js} +7 -7
  17. package/dist/_node-chunks/chunk-ICFGNVW7.js +1476 -0
  18. package/dist/_node-chunks/{chunk-RSG3AEWL.js → chunk-KQXC7XVZ.js} +16 -16
  19. package/dist/_node-chunks/{chunk-CGY2ITTD.js → chunk-LRQFELIZ.js} +8 -8
  20. package/dist/_node-chunks/{chunk-IBC4BVDB.js → chunk-MHNUEOON.js} +7 -7
  21. package/dist/_node-chunks/{chunk-63VGATS4.js → chunk-MVPVYHBT.js} +7 -7
  22. package/dist/_node-chunks/{chunk-NUODGCJN.js → chunk-PA26PSV2.js} +7 -7
  23. package/dist/_node-chunks/{chunk-2VOEBWNF.js → chunk-PAZJQ2GH.js} +7 -7
  24. package/dist/_node-chunks/{chunk-JWFNAC5N.js → chunk-PK6SVDYW.js} +7 -7
  25. package/dist/_node-chunks/{chunk-CMFB2H3U.js → chunk-QI3AVWUV.js} +12 -12
  26. package/dist/_node-chunks/{chunk-7DWWXKIE.js → chunk-R6TLLF24.js} +6 -6
  27. package/dist/_node-chunks/{chunk-XWJNZVOR.js → chunk-RUCPXDO3.js} +8 -8
  28. package/dist/_node-chunks/{chunk-ZF6AXYHM.js → chunk-SHXAIHPO.js} +7 -7
  29. package/dist/_node-chunks/{chunk-WBRWBEAS.js → chunk-TL5RNPZW.js} +10 -10
  30. package/dist/_node-chunks/{chunk-6FPFMFFH.js → chunk-VDFQYNPZ.js} +8 -8
  31. package/dist/_node-chunks/{chunk-TLM4ECJN.js → chunk-WELIADWR.js} +9 -9
  32. package/dist/_node-chunks/{chunk-DPF2NDLD.js → chunk-WRSYICUI.js} +7 -7
  33. package/dist/_node-chunks/{chunk-PTT3CRNJ.js → chunk-XRAB2RZN.js} +6 -6
  34. package/dist/_node-chunks/chunk-YRXKNGPR.js +18 -0
  35. package/dist/_node-chunks/{default-browser-id-YRAH7IMC.js → default-browser-id-2X5XLPPS.js} +7 -7
  36. package/dist/_node-chunks/{dist-G5THJIW5.js → dist-JSBOOVQK.js} +9 -9
  37. package/dist/_node-chunks/{globby-FGF2JG5Z.js → globby-YYTLHNUO.js} +9 -9
  38. package/dist/_node-chunks/{lib-OPOVJQIO.js → lib-DJHADRPZ.js} +11 -11
  39. package/dist/_node-chunks/{mdx-N42X6CFJ-N5MJA4NM.js → mdx-N42X6CFJ-WT6XCDU6.js} +8 -8
  40. package/dist/_node-chunks/{p-limit-JNDYEQZX.js → p-limit-HTXI4SGX.js} +8 -8
  41. package/dist/_node-chunks/{plugin-ZL4ZLDWE.js → plugin-NNRMQ2YK.js} +10 -10
  42. package/dist/_node-chunks/{plugin-6GW4GYGS.js → plugin-W22F3FQV.js} +10 -10
  43. package/dist/_node-chunks/{webpack-inject-mocker-runtime-plugin-F6BXWV4R.js → webpack-inject-mocker-runtime-plugin-VFNVWMAM.js} +10 -10
  44. package/dist/_node-chunks/{webpack-mock-plugin-5QNP4V3B.js → webpack-mock-plugin-Q4ED2M25.js} +9 -9
  45. package/dist/babel/index.js +11 -11
  46. package/dist/bin/core.js +11 -11
  47. package/dist/bin/dispatcher.js +11 -11
  48. package/dist/bin/loader.js +8 -8
  49. package/dist/cli/index.js +20 -20
  50. package/dist/common/index.js +22 -22
  51. package/dist/core-server/index.js +36 -36
  52. package/dist/core-server/presets/common-override-preset.js +9 -9
  53. package/dist/core-server/presets/common-preset.js +22 -22
  54. package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +9 -9
  55. package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +10 -10
  56. package/dist/csf/index.js +7 -1
  57. package/dist/csf-tools/index.d.ts +34 -0
  58. package/dist/csf-tools/index.js +9 -9
  59. package/dist/manager/globals-runtime.js +3 -2
  60. package/dist/manager-api/index.d.ts +1 -1
  61. package/dist/manager-api/index.js +1 -1
  62. package/dist/node-logger/index.js +14 -14
  63. package/dist/preview/runtime.js +9 -2
  64. package/dist/server-errors.js +10 -10
  65. package/dist/telemetry/index.js +25 -25
  66. package/dist/test/index.js +2 -1
  67. package/package.json +2 -2
  68. package/dist/_node-chunks/chunk-2VH25RMB.js +0 -9845
  69. package/dist/_node-chunks/chunk-IAAPNJG4.js +0 -62
  70. package/dist/_node-chunks/chunk-NNJMYLJM.js +0 -18
@@ -0,0 +1,1476 @@
1
+ import CJS_COMPAT_NODE_URL_6q9nmfaplv7 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6q9nmfaplv7 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6q9nmfaplv7 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_6q9nmfaplv7.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6q9nmfaplv7.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6q9nmfaplv7.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ __name
14
+ } from "./chunk-XRAB2RZN.js";
15
+
16
+ // ../node_modules/exsolve/dist/index.mjs
17
+ import fs, { realpathSync, statSync, lstatSync } from "node:fs";
18
+ import { fileURLToPath, URL as URL$1, pathToFileURL } from "node:url";
19
+ import path, { isAbsolute } from "node:path";
20
+ import assert from "node:assert";
21
+ import process$1 from "node:process";
22
+ import v8 from "node:v8";
23
+ import { format, inspect } from "node:util";
24
+ var nodeBuiltins = [
25
+ "_http_agent",
26
+ "_http_client",
27
+ "_http_common",
28
+ "_http_incoming",
29
+ "_http_outgoing",
30
+ "_http_server",
31
+ "_stream_duplex",
32
+ "_stream_passthrough",
33
+ "_stream_readable",
34
+ "_stream_transform",
35
+ "_stream_wrap",
36
+ "_stream_writable",
37
+ "_tls_common",
38
+ "_tls_wrap",
39
+ "assert",
40
+ "assert/strict",
41
+ "async_hooks",
42
+ "buffer",
43
+ "child_process",
44
+ "cluster",
45
+ "console",
46
+ "constants",
47
+ "crypto",
48
+ "dgram",
49
+ "diagnostics_channel",
50
+ "dns",
51
+ "dns/promises",
52
+ "domain",
53
+ "events",
54
+ "fs",
55
+ "fs/promises",
56
+ "http",
57
+ "http2",
58
+ "https",
59
+ "inspector",
60
+ "inspector/promises",
61
+ "module",
62
+ "net",
63
+ "os",
64
+ "path",
65
+ "path/posix",
66
+ "path/win32",
67
+ "perf_hooks",
68
+ "process",
69
+ "punycode",
70
+ "querystring",
71
+ "readline",
72
+ "readline/promises",
73
+ "repl",
74
+ "stream",
75
+ "stream/consumers",
76
+ "stream/promises",
77
+ "stream/web",
78
+ "string_decoder",
79
+ "sys",
80
+ "timers",
81
+ "timers/promises",
82
+ "tls",
83
+ "trace_events",
84
+ "tty",
85
+ "url",
86
+ "util",
87
+ "util/types",
88
+ "v8",
89
+ "vm",
90
+ "wasi",
91
+ "worker_threads",
92
+ "zlib"
93
+ ];
94
+ var own$1 = {}.hasOwnProperty;
95
+ var classRegExp = /^([A-Z][a-z\d]*)+$/;
96
+ var kTypes = /* @__PURE__ */ new Set([
97
+ "string",
98
+ "function",
99
+ "number",
100
+ "object",
101
+ // Accept 'Function' and 'Object' as alternative to the lower cased version.
102
+ "Function",
103
+ "Object",
104
+ "boolean",
105
+ "bigint",
106
+ "symbol"
107
+ ]);
108
+ var messages = /* @__PURE__ */ new Map();
109
+ var nodeInternalPrefix = "__node_internal_";
110
+ var userStackTraceLimit;
111
+ function formatList(array, type = "and") {
112
+ return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array.at(-1)}`;
113
+ }
114
+ __name(formatList, "formatList");
115
+ function createError(sym, value, constructor) {
116
+ messages.set(sym, value);
117
+ return makeNodeErrorWithCode(constructor, sym);
118
+ }
119
+ __name(createError, "createError");
120
+ function makeNodeErrorWithCode(Base, key) {
121
+ return /* @__PURE__ */ __name(function NodeError(...parameters) {
122
+ const limit = Error.stackTraceLimit;
123
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
124
+ const error = new Base();
125
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
126
+ const message = getMessage(key, parameters, error);
127
+ Object.defineProperties(error, {
128
+ // Note: no need to implement `kIsNodeError` symbol, would be hard,
129
+ // probably.
130
+ message: {
131
+ value: message,
132
+ enumerable: false,
133
+ writable: true,
134
+ configurable: true
135
+ },
136
+ toString: {
137
+ /** @this {Error} */
138
+ value() {
139
+ return `${this.name} [${key}]: ${this.message}`;
140
+ },
141
+ enumerable: false,
142
+ writable: true,
143
+ configurable: true
144
+ }
145
+ });
146
+ captureLargerStackTrace(error);
147
+ error.code = key;
148
+ return error;
149
+ }, "NodeError");
150
+ }
151
+ __name(makeNodeErrorWithCode, "makeNodeErrorWithCode");
152
+ function isErrorStackTraceLimitWritable() {
153
+ try {
154
+ if (v8.startupSnapshot.isBuildingSnapshot()) {
155
+ return false;
156
+ }
157
+ } catch {
158
+ }
159
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
160
+ if (desc === void 0) {
161
+ return Object.isExtensible(Error);
162
+ }
163
+ return own$1.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
164
+ }
165
+ __name(isErrorStackTraceLimitWritable, "isErrorStackTraceLimitWritable");
166
+ function hideStackFrames(wrappedFunction) {
167
+ const hidden = nodeInternalPrefix + wrappedFunction.name;
168
+ Object.defineProperty(wrappedFunction, "name", { value: hidden });
169
+ return wrappedFunction;
170
+ }
171
+ __name(hideStackFrames, "hideStackFrames");
172
+ var captureLargerStackTrace = hideStackFrames(function(error) {
173
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
174
+ if (stackTraceLimitIsWritable) {
175
+ userStackTraceLimit = Error.stackTraceLimit;
176
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
177
+ }
178
+ Error.captureStackTrace(error);
179
+ if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
180
+ return error;
181
+ });
182
+ function getMessage(key, parameters, self) {
183
+ const message = messages.get(key);
184
+ assert(message !== void 0, "expected `message` to be found");
185
+ if (typeof message === "function") {
186
+ assert(
187
+ message.length <= parameters.length,
188
+ // Default options do not count.
189
+ `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
190
+ );
191
+ return Reflect.apply(message, self, parameters);
192
+ }
193
+ const regex = /%[dfijoOs]/g;
194
+ let expectedLength = 0;
195
+ while (regex.exec(message) !== null) expectedLength++;
196
+ assert(
197
+ expectedLength === parameters.length,
198
+ `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
199
+ );
200
+ if (parameters.length === 0) return message;
201
+ parameters.unshift(message);
202
+ return Reflect.apply(format, null, parameters);
203
+ }
204
+ __name(getMessage, "getMessage");
205
+ function determineSpecificType(value) {
206
+ if (value === null || value === void 0) {
207
+ return String(value);
208
+ }
209
+ if (typeof value === "function" && value.name) {
210
+ return `function ${value.name}`;
211
+ }
212
+ if (typeof value === "object") {
213
+ if (value.constructor && value.constructor.name) {
214
+ return `an instance of ${value.constructor.name}`;
215
+ }
216
+ return `${inspect(value, { depth: -1 })}`;
217
+ }
218
+ let inspected = inspect(value, { colors: false });
219
+ if (inspected.length > 28) {
220
+ inspected = `${inspected.slice(0, 25)}...`;
221
+ }
222
+ return `type ${typeof value} (${inspected})`;
223
+ }
224
+ __name(determineSpecificType, "determineSpecificType");
225
+ createError(
226
+ "ERR_INVALID_ARG_TYPE",
227
+ (name, expected, actual) => {
228
+ assert(typeof name === "string", "'name' must be a string");
229
+ if (!Array.isArray(expected)) {
230
+ expected = [expected];
231
+ }
232
+ let message = "The ";
233
+ if (name.endsWith(" argument")) {
234
+ message += `${name} `;
235
+ } else {
236
+ const type = name.includes(".") ? "property" : "argument";
237
+ message += `"${name}" ${type} `;
238
+ }
239
+ message += "must be ";
240
+ const types = [];
241
+ const instances = [];
242
+ const other = [];
243
+ for (const value of expected) {
244
+ assert(
245
+ typeof value === "string",
246
+ "All expected entries have to be of type string"
247
+ );
248
+ if (kTypes.has(value)) {
249
+ types.push(value.toLowerCase());
250
+ } else if (classRegExp.exec(value) === null) {
251
+ assert(
252
+ value !== "object",
253
+ 'The value "object" should be written as "Object"'
254
+ );
255
+ other.push(value);
256
+ } else {
257
+ instances.push(value);
258
+ }
259
+ }
260
+ if (instances.length > 0) {
261
+ const pos = types.indexOf("object");
262
+ if (pos !== -1) {
263
+ types.slice(pos, 1);
264
+ instances.push("Object");
265
+ }
266
+ }
267
+ if (types.length > 0) {
268
+ message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(
269
+ types,
270
+ "or"
271
+ )}`;
272
+ if (instances.length > 0 || other.length > 0) message += " or ";
273
+ }
274
+ if (instances.length > 0) {
275
+ message += `an instance of ${formatList(instances, "or")}`;
276
+ if (other.length > 0) message += " or ";
277
+ }
278
+ if (other.length > 0) {
279
+ if (other.length > 1) {
280
+ message += `one of ${formatList(other, "or")}`;
281
+ } else {
282
+ if (other[0]?.toLowerCase() !== other[0]) message += "an ";
283
+ message += `${other[0]}`;
284
+ }
285
+ }
286
+ message += `. Received ${determineSpecificType(actual)}`;
287
+ return message;
288
+ },
289
+ TypeError
290
+ );
291
+ var ERR_INVALID_MODULE_SPECIFIER = createError(
292
+ "ERR_INVALID_MODULE_SPECIFIER",
293
+ /**
294
+ * @param {string} request
295
+ * @param {string} reason
296
+ * @param {string} [base]
297
+ */
298
+ (request, reason, base) => {
299
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
300
+ },
301
+ TypeError
302
+ );
303
+ var ERR_INVALID_PACKAGE_CONFIG = createError(
304
+ "ERR_INVALID_PACKAGE_CONFIG",
305
+ (path2, base, message) => {
306
+ return `Invalid package config ${path2}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
307
+ },
308
+ Error
309
+ );
310
+ var ERR_INVALID_PACKAGE_TARGET = createError(
311
+ "ERR_INVALID_PACKAGE_TARGET",
312
+ (packagePath, key, target, isImport = false, base) => {
313
+ const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
314
+ if (key === ".") {
315
+ assert(isImport === false);
316
+ return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
317
+ }
318
+ return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
319
+ target
320
+ )} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
321
+ },
322
+ Error
323
+ );
324
+ var ERR_MODULE_NOT_FOUND = createError(
325
+ "ERR_MODULE_NOT_FOUND",
326
+ (path2, base, exactUrl = false) => {
327
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path2}' imported from ${base}`;
328
+ },
329
+ Error
330
+ );
331
+ createError(
332
+ "ERR_NETWORK_IMPORT_DISALLOWED",
333
+ "import of '%s' by %s is not supported: %s",
334
+ Error
335
+ );
336
+ var ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
337
+ "ERR_PACKAGE_IMPORT_NOT_DEFINED",
338
+ (specifier, packagePath, base) => {
339
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath || ""}package.json` : ""} imported from ${base}`;
340
+ },
341
+ TypeError
342
+ );
343
+ var ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
344
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
345
+ /**
346
+ * @param {string} packagePath
347
+ * @param {string} subpath
348
+ * @param {string} [base]
349
+ */
350
+ (packagePath, subpath, base) => {
351
+ if (subpath === ".")
352
+ return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
353
+ return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
354
+ },
355
+ Error
356
+ );
357
+ var ERR_UNSUPPORTED_DIR_IMPORT = createError(
358
+ "ERR_UNSUPPORTED_DIR_IMPORT",
359
+ "Directory import '%s' is not supported resolving ES modules imported from %s",
360
+ Error
361
+ );
362
+ var ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(
363
+ "ERR_UNSUPPORTED_RESOLVE_REQUEST",
364
+ 'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.',
365
+ TypeError
366
+ );
367
+ var ERR_UNKNOWN_FILE_EXTENSION = createError(
368
+ "ERR_UNKNOWN_FILE_EXTENSION",
369
+ (extension, path2) => {
370
+ return `Unknown file extension "${extension}" for ${path2}`;
371
+ },
372
+ TypeError
373
+ );
374
+ createError(
375
+ "ERR_INVALID_ARG_VALUE",
376
+ (name, value, reason = "is invalid") => {
377
+ let inspected = inspect(value);
378
+ if (inspected.length > 128) {
379
+ inspected = `${inspected.slice(0, 128)}...`;
380
+ }
381
+ const type = name.includes(".") ? "property" : "argument";
382
+ return `The ${type} '${name}' ${reason}. Received ${inspected}`;
383
+ },
384
+ TypeError
385
+ // Note: extra classes have been shaken out.
386
+ // , RangeError
387
+ );
388
+ var hasOwnProperty$1 = {}.hasOwnProperty;
389
+ var cache = /* @__PURE__ */ new Map();
390
+ function read(jsonPath, { base, specifier }) {
391
+ const existing = cache.get(jsonPath);
392
+ if (existing) {
393
+ return existing;
394
+ }
395
+ let string;
396
+ try {
397
+ string = fs.readFileSync(path.toNamespacedPath(jsonPath), "utf8");
398
+ } catch (error) {
399
+ const exception = error;
400
+ if (exception.code !== "ENOENT") {
401
+ throw exception;
402
+ }
403
+ }
404
+ const result = {
405
+ exists: false,
406
+ pjsonPath: jsonPath,
407
+ main: void 0,
408
+ name: void 0,
409
+ type: "none",
410
+ // Ignore unknown types for forwards compatibility
411
+ exports: void 0,
412
+ imports: void 0
413
+ };
414
+ if (string !== void 0) {
415
+ let parsed;
416
+ try {
417
+ parsed = JSON.parse(string);
418
+ } catch (error_) {
419
+ const error = new ERR_INVALID_PACKAGE_CONFIG(
420
+ jsonPath,
421
+ (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier),
422
+ error_.message
423
+ );
424
+ error.cause = error_;
425
+ throw error;
426
+ }
427
+ result.exists = true;
428
+ if (hasOwnProperty$1.call(parsed, "name") && typeof parsed.name === "string") {
429
+ result.name = parsed.name;
430
+ }
431
+ if (hasOwnProperty$1.call(parsed, "main") && typeof parsed.main === "string") {
432
+ result.main = parsed.main;
433
+ }
434
+ if (hasOwnProperty$1.call(parsed, "exports")) {
435
+ result.exports = parsed.exports;
436
+ }
437
+ if (hasOwnProperty$1.call(parsed, "imports")) {
438
+ result.imports = parsed.imports;
439
+ }
440
+ if (hasOwnProperty$1.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) {
441
+ result.type = parsed.type;
442
+ }
443
+ }
444
+ cache.set(jsonPath, result);
445
+ return result;
446
+ }
447
+ __name(read, "read");
448
+ function getPackageScopeConfig(resolved) {
449
+ let packageJSONUrl = new URL("package.json", resolved);
450
+ while (true) {
451
+ const packageJSONPath2 = packageJSONUrl.pathname;
452
+ if (packageJSONPath2.endsWith("node_modules/package.json")) {
453
+ break;
454
+ }
455
+ const packageConfig = read(fileURLToPath(packageJSONUrl), {
456
+ specifier: resolved
457
+ });
458
+ if (packageConfig.exists) {
459
+ return packageConfig;
460
+ }
461
+ const lastPackageJSONUrl = packageJSONUrl;
462
+ packageJSONUrl = new URL("../package.json", packageJSONUrl);
463
+ if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
464
+ break;
465
+ }
466
+ }
467
+ const packageJSONPath = fileURLToPath(packageJSONUrl);
468
+ return {
469
+ pjsonPath: packageJSONPath,
470
+ exists: false,
471
+ type: "none"
472
+ };
473
+ }
474
+ __name(getPackageScopeConfig, "getPackageScopeConfig");
475
+ var hasOwnProperty = {}.hasOwnProperty;
476
+ var extensionFormatMap = {
477
+ __proto__: null,
478
+ ".json": "json",
479
+ ".cjs": "commonjs",
480
+ ".cts": "commonjs",
481
+ ".js": "module",
482
+ ".ts": "module",
483
+ ".mts": "module",
484
+ ".mjs": "module"
485
+ };
486
+ var protocolHandlers = {
487
+ __proto__: null,
488
+ "data:": getDataProtocolModuleFormat,
489
+ "file:": getFileProtocolModuleFormat,
490
+ "node:": /* @__PURE__ */ __name(() => "builtin", "node:")
491
+ };
492
+ function mimeToFormat(mime) {
493
+ if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime))
494
+ return "module";
495
+ if (mime === "application/json") return "json";
496
+ return null;
497
+ }
498
+ __name(mimeToFormat, "mimeToFormat");
499
+ function getDataProtocolModuleFormat(parsed) {
500
+ const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
501
+ parsed.pathname
502
+ ) || [null, null, null];
503
+ return mimeToFormat(mime);
504
+ }
505
+ __name(getDataProtocolModuleFormat, "getDataProtocolModuleFormat");
506
+ function extname(url) {
507
+ const pathname = url.pathname;
508
+ let index = pathname.length;
509
+ while (index--) {
510
+ const code = pathname.codePointAt(index);
511
+ if (code === 47) {
512
+ return "";
513
+ }
514
+ if (code === 46) {
515
+ return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
516
+ }
517
+ }
518
+ return "";
519
+ }
520
+ __name(extname, "extname");
521
+ function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
522
+ const ext = extname(url);
523
+ if (ext === ".js") {
524
+ const { type: packageType } = getPackageScopeConfig(url);
525
+ if (packageType !== "none") {
526
+ return packageType;
527
+ }
528
+ return "commonjs";
529
+ }
530
+ if (ext === "") {
531
+ const { type: packageType } = getPackageScopeConfig(url);
532
+ if (packageType === "none" || packageType === "commonjs") {
533
+ return "commonjs";
534
+ }
535
+ return "module";
536
+ }
537
+ const format2 = extensionFormatMap[ext];
538
+ if (format2) return format2;
539
+ if (ignoreErrors) {
540
+ return void 0;
541
+ }
542
+ const filepath = fileURLToPath(url);
543
+ throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath);
544
+ }
545
+ __name(getFileProtocolModuleFormat, "getFileProtocolModuleFormat");
546
+ function defaultGetFormatWithoutErrors(url, context) {
547
+ const protocol = url.protocol;
548
+ if (!hasOwnProperty.call(protocolHandlers, protocol)) {
549
+ return null;
550
+ }
551
+ return protocolHandlers[protocol](url, context, true) || null;
552
+ }
553
+ __name(defaultGetFormatWithoutErrors, "defaultGetFormatWithoutErrors");
554
+ var RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
555
+ var own = {}.hasOwnProperty;
556
+ var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
557
+ var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
558
+ var invalidPackageNameRegEx = /^\.|%|\\/;
559
+ var patternRegEx = /\*/g;
560
+ var encodedSeparatorRegEx = /%2f|%5c/i;
561
+ var emittedPackageWarnings = /* @__PURE__ */ new Set();
562
+ var doubleSlashRegEx = /[/\\]{2}/;
563
+ function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
564
+ if (process$1.noDeprecation) {
565
+ return;
566
+ }
567
+ const pjsonPath = fileURLToPath(packageJsonUrl);
568
+ const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
569
+ process$1.emitWarning(
570
+ `Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}.`,
571
+ "DeprecationWarning",
572
+ "DEP0166"
573
+ );
574
+ }
575
+ __name(emitInvalidSegmentDeprecation, "emitInvalidSegmentDeprecation");
576
+ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
577
+ if (process$1.noDeprecation) {
578
+ return;
579
+ }
580
+ const format2 = defaultGetFormatWithoutErrors(url, { parentURL: base.href });
581
+ if (format2 !== "module") return;
582
+ const urlPath = fileURLToPath(url.href);
583
+ const packagePath = fileURLToPath(new URL$1(".", packageJsonUrl));
584
+ const basePath = fileURLToPath(base);
585
+ if (!main) {
586
+ process$1.emitWarning(
587
+ `No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(
588
+ packagePath.length
589
+ )}", imported from ${basePath}.
590
+ Default "index" lookups for the main are deprecated for ES modules.`,
591
+ "DeprecationWarning",
592
+ "DEP0151"
593
+ );
594
+ } else if (path.resolve(packagePath, main) !== urlPath) {
595
+ process$1.emitWarning(
596
+ `Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
597
+ packagePath.length
598
+ )}", imported from ${basePath}.
599
+ Automatic extension resolution of the "main" field is deprecated for ES modules.`,
600
+ "DeprecationWarning",
601
+ "DEP0151"
602
+ );
603
+ }
604
+ }
605
+ __name(emitLegacyIndexDeprecation, "emitLegacyIndexDeprecation");
606
+ function tryStatSync(path2) {
607
+ try {
608
+ return statSync(path2);
609
+ } catch {
610
+ }
611
+ }
612
+ __name(tryStatSync, "tryStatSync");
613
+ function fileExists(url) {
614
+ const stats = statSync(url, { throwIfNoEntry: false });
615
+ const isFile = stats ? stats.isFile() : void 0;
616
+ return isFile === null || isFile === void 0 ? false : isFile;
617
+ }
618
+ __name(fileExists, "fileExists");
619
+ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
620
+ let guess;
621
+ if (packageConfig.main !== void 0) {
622
+ guess = new URL$1(packageConfig.main, packageJsonUrl);
623
+ if (fileExists(guess)) return guess;
624
+ const tries2 = [
625
+ `./${packageConfig.main}.js`,
626
+ `./${packageConfig.main}.json`,
627
+ `./${packageConfig.main}.node`,
628
+ `./${packageConfig.main}/index.js`,
629
+ `./${packageConfig.main}/index.json`,
630
+ `./${packageConfig.main}/index.node`
631
+ ];
632
+ let i2 = -1;
633
+ while (++i2 < tries2.length) {
634
+ guess = new URL$1(tries2[i2], packageJsonUrl);
635
+ if (fileExists(guess)) break;
636
+ guess = void 0;
637
+ }
638
+ if (guess) {
639
+ emitLegacyIndexDeprecation(
640
+ guess,
641
+ packageJsonUrl,
642
+ base,
643
+ packageConfig.main
644
+ );
645
+ return guess;
646
+ }
647
+ }
648
+ const tries = ["./index.js", "./index.json", "./index.node"];
649
+ let i = -1;
650
+ while (++i < tries.length) {
651
+ guess = new URL$1(tries[i], packageJsonUrl);
652
+ if (fileExists(guess)) break;
653
+ guess = void 0;
654
+ }
655
+ if (guess) {
656
+ emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
657
+ return guess;
658
+ }
659
+ throw new ERR_MODULE_NOT_FOUND(
660
+ fileURLToPath(new URL$1(".", packageJsonUrl)),
661
+ fileURLToPath(base)
662
+ );
663
+ }
664
+ __name(legacyMainResolve, "legacyMainResolve");
665
+ function finalizeResolution(resolved, base, preserveSymlinks) {
666
+ if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
667
+ throw new ERR_INVALID_MODULE_SPECIFIER(
668
+ resolved.pathname,
669
+ String.raw`must not include encoded "/" or "\" characters`,
670
+ fileURLToPath(base)
671
+ );
672
+ }
673
+ let filePath;
674
+ try {
675
+ filePath = fileURLToPath(resolved);
676
+ } catch (error) {
677
+ Object.defineProperty(error, "input", { value: String(resolved) });
678
+ Object.defineProperty(error, "module", { value: String(base) });
679
+ throw error;
680
+ }
681
+ const stats = tryStatSync(
682
+ filePath.endsWith("/") ? filePath.slice(-1) : filePath
683
+ );
684
+ if (stats && stats.isDirectory()) {
685
+ const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath(base));
686
+ error.url = String(resolved);
687
+ throw error;
688
+ }
689
+ if (!stats || !stats.isFile()) {
690
+ const error = new ERR_MODULE_NOT_FOUND(
691
+ filePath || resolved.pathname,
692
+ base && fileURLToPath(base),
693
+ true
694
+ );
695
+ error.url = String(resolved);
696
+ throw error;
697
+ }
698
+ {
699
+ const real = realpathSync(filePath);
700
+ const { search, hash } = resolved;
701
+ resolved = pathToFileURL(real + (filePath.endsWith(path.sep) ? "/" : ""));
702
+ resolved.search = search;
703
+ resolved.hash = hash;
704
+ }
705
+ return resolved;
706
+ }
707
+ __name(finalizeResolution, "finalizeResolution");
708
+ function importNotDefined(specifier, packageJsonUrl, base) {
709
+ return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
710
+ specifier,
711
+ packageJsonUrl && fileURLToPath(new URL$1(".", packageJsonUrl)),
712
+ fileURLToPath(base)
713
+ );
714
+ }
715
+ __name(importNotDefined, "importNotDefined");
716
+ function exportsNotFound(subpath, packageJsonUrl, base) {
717
+ return new ERR_PACKAGE_PATH_NOT_EXPORTED(
718
+ fileURLToPath(new URL$1(".", packageJsonUrl)),
719
+ subpath,
720
+ base && fileURLToPath(base)
721
+ );
722
+ }
723
+ __name(exportsNotFound, "exportsNotFound");
724
+ function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
725
+ const reason = `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJsonUrl)}`;
726
+ throw new ERR_INVALID_MODULE_SPECIFIER(
727
+ request,
728
+ reason,
729
+ base && fileURLToPath(base)
730
+ );
731
+ }
732
+ __name(throwInvalidSubpath, "throwInvalidSubpath");
733
+ function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
734
+ target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
735
+ return new ERR_INVALID_PACKAGE_TARGET(
736
+ fileURLToPath(new URL$1(".", packageJsonUrl)),
737
+ subpath,
738
+ target,
739
+ internal,
740
+ base && fileURLToPath(base)
741
+ );
742
+ }
743
+ __name(invalidPackageTarget, "invalidPackageTarget");
744
+ function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
745
+ if (subpath !== "" && !pattern && target.at(-1) !== "/")
746
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
747
+ if (!target.startsWith("./")) {
748
+ if (internal && !target.startsWith("../") && !target.startsWith("/")) {
749
+ let isURL = false;
750
+ try {
751
+ new URL$1(target);
752
+ isURL = true;
753
+ } catch {
754
+ }
755
+ if (!isURL) {
756
+ const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
757
+ patternRegEx,
758
+ target,
759
+ () => subpath
760
+ ) : target + subpath;
761
+ return packageResolve(exportTarget, packageJsonUrl, conditions);
762
+ }
763
+ }
764
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
765
+ }
766
+ if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
767
+ if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
768
+ if (!isPathMap) {
769
+ const request = pattern ? match.replace("*", () => subpath) : match + subpath;
770
+ const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
771
+ patternRegEx,
772
+ target,
773
+ () => subpath
774
+ ) : target;
775
+ emitInvalidSegmentDeprecation(
776
+ resolvedTarget,
777
+ request,
778
+ match,
779
+ packageJsonUrl,
780
+ internal,
781
+ base,
782
+ true
783
+ );
784
+ }
785
+ } else {
786
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
787
+ }
788
+ }
789
+ const resolved = new URL$1(target, packageJsonUrl);
790
+ const resolvedPath = resolved.pathname;
791
+ const packagePath = new URL$1(".", packageJsonUrl).pathname;
792
+ if (!resolvedPath.startsWith(packagePath))
793
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
794
+ if (subpath === "") return resolved;
795
+ if (invalidSegmentRegEx.exec(subpath) !== null) {
796
+ const request = pattern ? match.replace("*", () => subpath) : match + subpath;
797
+ if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
798
+ if (!isPathMap) {
799
+ const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
800
+ patternRegEx,
801
+ target,
802
+ () => subpath
803
+ ) : target;
804
+ emitInvalidSegmentDeprecation(
805
+ resolvedTarget,
806
+ request,
807
+ match,
808
+ packageJsonUrl,
809
+ internal,
810
+ base,
811
+ false
812
+ );
813
+ }
814
+ } else {
815
+ throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
816
+ }
817
+ }
818
+ if (pattern) {
819
+ return new URL$1(
820
+ RegExpPrototypeSymbolReplace.call(
821
+ patternRegEx,
822
+ resolved.href,
823
+ () => subpath
824
+ )
825
+ );
826
+ }
827
+ return new URL$1(subpath, resolved);
828
+ }
829
+ __name(resolvePackageTargetString, "resolvePackageTargetString");
830
+ function isArrayIndex(key) {
831
+ const keyNumber = Number(key);
832
+ if (`${keyNumber}` !== key) return false;
833
+ return keyNumber >= 0 && keyNumber < 4294967295;
834
+ }
835
+ __name(isArrayIndex, "isArrayIndex");
836
+ function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
837
+ if (typeof target === "string") {
838
+ return resolvePackageTargetString(
839
+ target,
840
+ subpath,
841
+ packageSubpath,
842
+ packageJsonUrl,
843
+ base,
844
+ pattern,
845
+ internal,
846
+ isPathMap,
847
+ conditions
848
+ );
849
+ }
850
+ if (Array.isArray(target)) {
851
+ const targetList = target;
852
+ if (targetList.length === 0) return null;
853
+ let lastException;
854
+ let i = -1;
855
+ while (++i < targetList.length) {
856
+ const targetItem = targetList[i];
857
+ let resolveResult;
858
+ try {
859
+ resolveResult = resolvePackageTarget(
860
+ packageJsonUrl,
861
+ targetItem,
862
+ subpath,
863
+ packageSubpath,
864
+ base,
865
+ pattern,
866
+ internal,
867
+ isPathMap,
868
+ conditions
869
+ );
870
+ } catch (error) {
871
+ const exception = error;
872
+ lastException = exception;
873
+ if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
874
+ throw error;
875
+ }
876
+ if (resolveResult === void 0) continue;
877
+ if (resolveResult === null) {
878
+ lastException = null;
879
+ continue;
880
+ }
881
+ return resolveResult;
882
+ }
883
+ if (lastException === void 0 || lastException === null) {
884
+ return null;
885
+ }
886
+ throw lastException;
887
+ }
888
+ if (typeof target === "object" && target !== null) {
889
+ const keys = Object.getOwnPropertyNames(target);
890
+ let i = -1;
891
+ while (++i < keys.length) {
892
+ const key = keys[i];
893
+ if (isArrayIndex(key)) {
894
+ throw new ERR_INVALID_PACKAGE_CONFIG(
895
+ fileURLToPath(packageJsonUrl),
896
+ fileURLToPath(base),
897
+ '"exports" cannot contain numeric property keys.'
898
+ );
899
+ }
900
+ }
901
+ i = -1;
902
+ while (++i < keys.length) {
903
+ const key = keys[i];
904
+ if (key === "default" || conditions && conditions.has(key)) {
905
+ const conditionalTarget = target[key];
906
+ const resolveResult = resolvePackageTarget(
907
+ packageJsonUrl,
908
+ conditionalTarget,
909
+ subpath,
910
+ packageSubpath,
911
+ base,
912
+ pattern,
913
+ internal,
914
+ isPathMap,
915
+ conditions
916
+ );
917
+ if (resolveResult === void 0) continue;
918
+ return resolveResult;
919
+ }
920
+ }
921
+ return null;
922
+ }
923
+ if (target === null) {
924
+ return null;
925
+ }
926
+ throw invalidPackageTarget(
927
+ packageSubpath,
928
+ target,
929
+ packageJsonUrl,
930
+ internal,
931
+ base
932
+ );
933
+ }
934
+ __name(resolvePackageTarget, "resolvePackageTarget");
935
+ function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
936
+ if (typeof exports === "string" || Array.isArray(exports)) return true;
937
+ if (typeof exports !== "object" || exports === null) return false;
938
+ const keys = Object.getOwnPropertyNames(exports);
939
+ let isConditionalSugar = false;
940
+ let i = 0;
941
+ let keyIndex = -1;
942
+ while (++keyIndex < keys.length) {
943
+ const key = keys[keyIndex];
944
+ const currentIsConditionalSugar = key === "" || key[0] !== ".";
945
+ if (i++ === 0) {
946
+ isConditionalSugar = currentIsConditionalSugar;
947
+ } else if (isConditionalSugar !== currentIsConditionalSugar) {
948
+ throw new ERR_INVALID_PACKAGE_CONFIG(
949
+ fileURLToPath(packageJsonUrl),
950
+ fileURLToPath(base),
951
+ `"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.`
952
+ );
953
+ }
954
+ }
955
+ return isConditionalSugar;
956
+ }
957
+ __name(isConditionalExportsMainSugar, "isConditionalExportsMainSugar");
958
+ function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
959
+ if (process$1.noDeprecation) {
960
+ return;
961
+ }
962
+ const pjsonPath = fileURLToPath(pjsonUrl);
963
+ if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
964
+ emittedPackageWarnings.add(pjsonPath + "|" + match);
965
+ process$1.emitWarning(
966
+ `Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`,
967
+ "DeprecationWarning",
968
+ "DEP0155"
969
+ );
970
+ }
971
+ __name(emitTrailingSlashPatternDeprecation, "emitTrailingSlashPatternDeprecation");
972
+ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
973
+ let exports = packageConfig.exports;
974
+ if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
975
+ exports = { ".": exports };
976
+ }
977
+ if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
978
+ const target = exports[packageSubpath];
979
+ const resolveResult = resolvePackageTarget(
980
+ packageJsonUrl,
981
+ target,
982
+ "",
983
+ packageSubpath,
984
+ base,
985
+ false,
986
+ false,
987
+ false,
988
+ conditions
989
+ );
990
+ if (resolveResult === null || resolveResult === void 0) {
991
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
992
+ }
993
+ return resolveResult;
994
+ }
995
+ let bestMatch = "";
996
+ let bestMatchSubpath = "";
997
+ const keys = Object.getOwnPropertyNames(exports);
998
+ let i = -1;
999
+ while (++i < keys.length) {
1000
+ const key = keys[i];
1001
+ const patternIndex = key.indexOf("*");
1002
+ if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
1003
+ if (packageSubpath.endsWith("/")) {
1004
+ emitTrailingSlashPatternDeprecation(
1005
+ packageSubpath,
1006
+ packageJsonUrl,
1007
+ base
1008
+ );
1009
+ }
1010
+ const patternTrailer = key.slice(patternIndex + 1);
1011
+ if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
1012
+ bestMatch = key;
1013
+ bestMatchSubpath = packageSubpath.slice(
1014
+ patternIndex,
1015
+ packageSubpath.length - patternTrailer.length
1016
+ );
1017
+ }
1018
+ }
1019
+ }
1020
+ if (bestMatch) {
1021
+ const target = exports[bestMatch];
1022
+ const resolveResult = resolvePackageTarget(
1023
+ packageJsonUrl,
1024
+ target,
1025
+ bestMatchSubpath,
1026
+ bestMatch,
1027
+ base,
1028
+ true,
1029
+ false,
1030
+ packageSubpath.endsWith("/"),
1031
+ conditions
1032
+ );
1033
+ if (resolveResult === null || resolveResult === void 0) {
1034
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
1035
+ }
1036
+ return resolveResult;
1037
+ }
1038
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
1039
+ }
1040
+ __name(packageExportsResolve, "packageExportsResolve");
1041
+ function patternKeyCompare(a, b) {
1042
+ const aPatternIndex = a.indexOf("*");
1043
+ const bPatternIndex = b.indexOf("*");
1044
+ const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
1045
+ const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
1046
+ if (baseLengthA > baseLengthB) return -1;
1047
+ if (baseLengthB > baseLengthA) return 1;
1048
+ if (aPatternIndex === -1) return 1;
1049
+ if (bPatternIndex === -1) return -1;
1050
+ if (a.length > b.length) return -1;
1051
+ if (b.length > a.length) return 1;
1052
+ return 0;
1053
+ }
1054
+ __name(patternKeyCompare, "patternKeyCompare");
1055
+ function packageImportsResolve(name, base, conditions) {
1056
+ if (name === "#" || name.startsWith("#/") || name.endsWith("/")) {
1057
+ const reason = "is not a valid internal imports specifier name";
1058
+ throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath(base));
1059
+ }
1060
+ let packageJsonUrl;
1061
+ const packageConfig = getPackageScopeConfig(base);
1062
+ if (packageConfig.exists) {
1063
+ packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
1064
+ const imports = packageConfig.imports;
1065
+ if (imports) {
1066
+ if (own.call(imports, name) && !name.includes("*")) {
1067
+ const resolveResult = resolvePackageTarget(
1068
+ packageJsonUrl,
1069
+ imports[name],
1070
+ "",
1071
+ name,
1072
+ base,
1073
+ false,
1074
+ true,
1075
+ false,
1076
+ conditions
1077
+ );
1078
+ if (resolveResult !== null && resolveResult !== void 0) {
1079
+ return resolveResult;
1080
+ }
1081
+ } else {
1082
+ let bestMatch = "";
1083
+ let bestMatchSubpath = "";
1084
+ const keys = Object.getOwnPropertyNames(imports);
1085
+ let i = -1;
1086
+ while (++i < keys.length) {
1087
+ const key = keys[i];
1088
+ const patternIndex = key.indexOf("*");
1089
+ if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
1090
+ const patternTrailer = key.slice(patternIndex + 1);
1091
+ if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
1092
+ bestMatch = key;
1093
+ bestMatchSubpath = name.slice(
1094
+ patternIndex,
1095
+ name.length - patternTrailer.length
1096
+ );
1097
+ }
1098
+ }
1099
+ }
1100
+ if (bestMatch) {
1101
+ const target = imports[bestMatch];
1102
+ const resolveResult = resolvePackageTarget(
1103
+ packageJsonUrl,
1104
+ target,
1105
+ bestMatchSubpath,
1106
+ bestMatch,
1107
+ base,
1108
+ true,
1109
+ true,
1110
+ false,
1111
+ conditions
1112
+ );
1113
+ if (resolveResult !== null && resolveResult !== void 0) {
1114
+ return resolveResult;
1115
+ }
1116
+ }
1117
+ }
1118
+ }
1119
+ }
1120
+ throw importNotDefined(name, packageJsonUrl, base);
1121
+ }
1122
+ __name(packageImportsResolve, "packageImportsResolve");
1123
+ function parsePackageName(specifier, base) {
1124
+ let separatorIndex = specifier.indexOf("/");
1125
+ let validPackageName = true;
1126
+ let isScoped = false;
1127
+ if (specifier[0] === "@") {
1128
+ isScoped = true;
1129
+ if (separatorIndex === -1 || specifier.length === 0) {
1130
+ validPackageName = false;
1131
+ } else {
1132
+ separatorIndex = specifier.indexOf("/", separatorIndex + 1);
1133
+ }
1134
+ }
1135
+ const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
1136
+ if (invalidPackageNameRegEx.exec(packageName) !== null) {
1137
+ validPackageName = false;
1138
+ }
1139
+ if (!validPackageName) {
1140
+ throw new ERR_INVALID_MODULE_SPECIFIER(
1141
+ specifier,
1142
+ "is not a valid package name",
1143
+ fileURLToPath(base)
1144
+ );
1145
+ }
1146
+ const packageSubpath = "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex));
1147
+ return { packageName, packageSubpath, isScoped };
1148
+ }
1149
+ __name(parsePackageName, "parsePackageName");
1150
+ function packageResolve(specifier, base, conditions) {
1151
+ if (nodeBuiltins.includes(specifier)) {
1152
+ return new URL$1("node:" + specifier);
1153
+ }
1154
+ const { packageName, packageSubpath, isScoped } = parsePackageName(
1155
+ specifier,
1156
+ base
1157
+ );
1158
+ const packageConfig = getPackageScopeConfig(base);
1159
+ if (packageConfig.exists && packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
1160
+ const packageJsonUrl2 = pathToFileURL(packageConfig.pjsonPath);
1161
+ return packageExportsResolve(
1162
+ packageJsonUrl2,
1163
+ packageSubpath,
1164
+ packageConfig,
1165
+ base,
1166
+ conditions
1167
+ );
1168
+ }
1169
+ let packageJsonUrl = new URL$1(
1170
+ "./node_modules/" + packageName + "/package.json",
1171
+ base
1172
+ );
1173
+ let packageJsonPath = fileURLToPath(packageJsonUrl);
1174
+ let lastPath;
1175
+ do {
1176
+ const stat = tryStatSync(packageJsonPath.slice(0, -13));
1177
+ if (!stat || !stat.isDirectory()) {
1178
+ lastPath = packageJsonPath;
1179
+ packageJsonUrl = new URL$1(
1180
+ (isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
1181
+ packageJsonUrl
1182
+ );
1183
+ packageJsonPath = fileURLToPath(packageJsonUrl);
1184
+ continue;
1185
+ }
1186
+ const packageConfig2 = read(packageJsonPath, { base, specifier });
1187
+ if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
1188
+ return packageExportsResolve(
1189
+ packageJsonUrl,
1190
+ packageSubpath,
1191
+ packageConfig2,
1192
+ base,
1193
+ conditions
1194
+ );
1195
+ }
1196
+ if (packageSubpath === ".") {
1197
+ return legacyMainResolve(packageJsonUrl, packageConfig2, base);
1198
+ }
1199
+ return new URL$1(packageSubpath, packageJsonUrl);
1200
+ } while (packageJsonPath.length !== lastPath.length);
1201
+ throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), false);
1202
+ }
1203
+ __name(packageResolve, "packageResolve");
1204
+ function isRelativeSpecifier(specifier) {
1205
+ if (specifier[0] === ".") {
1206
+ if (specifier.length === 1 || specifier[1] === "/") return true;
1207
+ if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) {
1208
+ return true;
1209
+ }
1210
+ }
1211
+ return false;
1212
+ }
1213
+ __name(isRelativeSpecifier, "isRelativeSpecifier");
1214
+ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
1215
+ if (specifier === "") return false;
1216
+ if (specifier[0] === "/") return true;
1217
+ return isRelativeSpecifier(specifier);
1218
+ }
1219
+ __name(shouldBeTreatedAsRelativeOrAbsolutePath, "shouldBeTreatedAsRelativeOrAbsolutePath");
1220
+ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
1221
+ const protocol = base.protocol;
1222
+ const isData = protocol === "data:";
1223
+ let resolved;
1224
+ if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
1225
+ try {
1226
+ resolved = new URL$1(specifier, base);
1227
+ } catch (error_) {
1228
+ const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
1229
+ error.cause = error_;
1230
+ throw error;
1231
+ }
1232
+ } else if (protocol === "file:" && specifier[0] === "#") {
1233
+ resolved = packageImportsResolve(specifier, base, conditions);
1234
+ } else {
1235
+ try {
1236
+ resolved = new URL$1(specifier);
1237
+ } catch (error_) {
1238
+ if (isData && !nodeBuiltins.includes(specifier)) {
1239
+ const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
1240
+ error.cause = error_;
1241
+ throw error;
1242
+ }
1243
+ resolved = packageResolve(specifier, base, conditions);
1244
+ }
1245
+ }
1246
+ assert(resolved !== void 0, "expected to be defined");
1247
+ if (resolved.protocol !== "file:") {
1248
+ return resolved;
1249
+ }
1250
+ return finalizeResolution(resolved, base);
1251
+ }
1252
+ __name(moduleResolve, "moduleResolve");
1253
+ var DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
1254
+ var isWindows = (() => process.platform === "win32")();
1255
+ var NOT_FOUND_ERRORS = /* @__PURE__ */ new Set([
1256
+ "ERR_MODULE_NOT_FOUND",
1257
+ "ERR_UNSUPPORTED_DIR_IMPORT",
1258
+ "MODULE_NOT_FOUND",
1259
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
1260
+ "ERR_PACKAGE_IMPORT_NOT_DEFINED"
1261
+ ]);
1262
+ var globalCache = (() => (
1263
+ // eslint-disable-next-line unicorn/no-unreadable-iife
1264
+ globalThis["__EXSOLVE_CACHE__"] ||= /* @__PURE__ */ new Map()
1265
+ ))();
1266
+ function resolveModuleURL(input, options) {
1267
+ const parsedInput = _parseInput(input);
1268
+ if ("external" in parsedInput) {
1269
+ return parsedInput.external;
1270
+ }
1271
+ const specifier = parsedInput.specifier;
1272
+ let url = parsedInput.url;
1273
+ let absolutePath = parsedInput.absolutePath;
1274
+ let cacheKey;
1275
+ let cacheObj;
1276
+ if (options?.cache !== false) {
1277
+ cacheKey = _cacheKey(absolutePath || specifier, options);
1278
+ cacheObj = options?.cache && typeof options?.cache === "object" ? options.cache : globalCache;
1279
+ }
1280
+ if (cacheObj) {
1281
+ const cached = cacheObj.get(cacheKey);
1282
+ if (typeof cached === "string") {
1283
+ return cached;
1284
+ }
1285
+ if (cached instanceof Error) {
1286
+ if (options?.try) {
1287
+ return void 0;
1288
+ }
1289
+ throw cached;
1290
+ }
1291
+ }
1292
+ if (absolutePath) {
1293
+ try {
1294
+ const stat = lstatSync(absolutePath);
1295
+ if (stat.isSymbolicLink()) {
1296
+ absolutePath = realpathSync(absolutePath);
1297
+ url = pathToFileURL(absolutePath);
1298
+ }
1299
+ if (stat.isFile()) {
1300
+ if (cacheObj) {
1301
+ cacheObj.set(cacheKey, url.href);
1302
+ }
1303
+ return url.href;
1304
+ }
1305
+ } catch (error) {
1306
+ if (error?.code !== "ENOENT") {
1307
+ if (cacheObj) {
1308
+ cacheObj.set(cacheKey, error);
1309
+ }
1310
+ throw error;
1311
+ }
1312
+ }
1313
+ }
1314
+ const conditionsSet = options?.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
1315
+ const target = specifier || url.href;
1316
+ const bases = _normalizeBases(options?.from);
1317
+ const suffixes = options?.suffixes || [""];
1318
+ const extensions = options?.extensions ? ["", ...options.extensions] : [""];
1319
+ let resolved;
1320
+ for (const base of bases) {
1321
+ for (const suffix of suffixes) {
1322
+ let name = _join(target, suffix);
1323
+ if (name === ".") {
1324
+ name += "/.";
1325
+ }
1326
+ for (const extension of extensions) {
1327
+ resolved = _tryModuleResolve(name + extension, base, conditionsSet);
1328
+ if (resolved) {
1329
+ break;
1330
+ }
1331
+ }
1332
+ if (resolved) {
1333
+ break;
1334
+ }
1335
+ }
1336
+ if (resolved) {
1337
+ break;
1338
+ }
1339
+ }
1340
+ if (!resolved) {
1341
+ const error = new Error(
1342
+ `Cannot resolve module "${input}" (from: ${bases.map((u) => _fmtPath(u)).join(", ")})`
1343
+ );
1344
+ error.code = "ERR_MODULE_NOT_FOUND";
1345
+ if (cacheObj) {
1346
+ cacheObj.set(cacheKey, error);
1347
+ }
1348
+ if (options?.try) {
1349
+ return void 0;
1350
+ }
1351
+ throw error;
1352
+ }
1353
+ if (cacheObj) {
1354
+ cacheObj.set(cacheKey, resolved.href);
1355
+ }
1356
+ return resolved.href;
1357
+ }
1358
+ __name(resolveModuleURL, "resolveModuleURL");
1359
+ function resolveModulePath(id, options) {
1360
+ const resolved = resolveModuleURL(id, options);
1361
+ if (!resolved) {
1362
+ return void 0;
1363
+ }
1364
+ if (!resolved.startsWith("file://") && options?.try) {
1365
+ return void 0;
1366
+ }
1367
+ const absolutePath = fileURLToPath(resolved);
1368
+ return isWindows ? _normalizeWinPath(absolutePath) : absolutePath;
1369
+ }
1370
+ __name(resolveModulePath, "resolveModulePath");
1371
+ function _tryModuleResolve(specifier, base, conditions) {
1372
+ try {
1373
+ return moduleResolve(specifier, base, conditions);
1374
+ } catch (error) {
1375
+ if (!NOT_FOUND_ERRORS.has(error?.code)) {
1376
+ throw error;
1377
+ }
1378
+ }
1379
+ }
1380
+ __name(_tryModuleResolve, "_tryModuleResolve");
1381
+ function _normalizeBases(inputs) {
1382
+ const urls = (Array.isArray(inputs) ? inputs : [inputs]).flatMap(
1383
+ (input) => _normalizeBase(input)
1384
+ );
1385
+ if (urls.length === 0) {
1386
+ return [pathToFileURL("./")];
1387
+ }
1388
+ return urls;
1389
+ }
1390
+ __name(_normalizeBases, "_normalizeBases");
1391
+ function _normalizeBase(input) {
1392
+ if (!input) {
1393
+ return [];
1394
+ }
1395
+ if (_isURL(input)) {
1396
+ return [input];
1397
+ }
1398
+ if (typeof input !== "string") {
1399
+ return [];
1400
+ }
1401
+ if (/^(?:node|data|http|https|file):/.test(input)) {
1402
+ return new URL(input);
1403
+ }
1404
+ try {
1405
+ if (input.endsWith("/") || statSync(input).isDirectory()) {
1406
+ return pathToFileURL(input + "/");
1407
+ }
1408
+ return pathToFileURL(input);
1409
+ } catch {
1410
+ return [pathToFileURL(input + "/"), pathToFileURL(input)];
1411
+ }
1412
+ }
1413
+ __name(_normalizeBase, "_normalizeBase");
1414
+ function _fmtPath(input) {
1415
+ try {
1416
+ return fileURLToPath(input);
1417
+ } catch {
1418
+ return input;
1419
+ }
1420
+ }
1421
+ __name(_fmtPath, "_fmtPath");
1422
+ function _cacheKey(id, opts) {
1423
+ return JSON.stringify([
1424
+ id,
1425
+ (opts?.conditions || ["node", "import"]).sort(),
1426
+ opts?.extensions,
1427
+ opts?.from,
1428
+ opts?.suffixes
1429
+ ]);
1430
+ }
1431
+ __name(_cacheKey, "_cacheKey");
1432
+ function _join(a, b) {
1433
+ if (!a || !b || b === "/") {
1434
+ return a;
1435
+ }
1436
+ return (a.endsWith("/") ? a : a + "/") + (b.startsWith("/") ? b.slice(1) : b);
1437
+ }
1438
+ __name(_join, "_join");
1439
+ function _normalizeWinPath(path2) {
1440
+ return path2.replace(/\\/g, "/").replace(/^[a-z]:\//, (r) => r.toUpperCase());
1441
+ }
1442
+ __name(_normalizeWinPath, "_normalizeWinPath");
1443
+ function _isURL(input) {
1444
+ return input instanceof URL || input?.constructor?.name === "URL";
1445
+ }
1446
+ __name(_isURL, "_isURL");
1447
+ function _parseInput(input) {
1448
+ if (typeof input === "string") {
1449
+ if (input.startsWith("file:")) {
1450
+ const url = new URL(input);
1451
+ return { url, absolutePath: fileURLToPath(url) };
1452
+ }
1453
+ if (isAbsolute(input)) {
1454
+ return { url: pathToFileURL(input), absolutePath: input };
1455
+ }
1456
+ if (/^(?:node|data|http|https):/.test(input)) {
1457
+ return { external: input };
1458
+ }
1459
+ if (nodeBuiltins.includes(input) && !input.includes(":")) {
1460
+ return { external: `node:${input}` };
1461
+ }
1462
+ return { specifier: input };
1463
+ }
1464
+ if (_isURL(input)) {
1465
+ if (input.protocol === "file:") {
1466
+ return { url: input, absolutePath: fileURLToPath(input) };
1467
+ }
1468
+ return { external: input.href };
1469
+ }
1470
+ throw new TypeError("id must be a `string` or `URL`");
1471
+ }
1472
+ __name(_parseInput, "_parseInput");
1473
+
1474
+ export {
1475
+ resolveModulePath
1476
+ };