nitro-nightly 3.0.1-20260106-202835-5325b208 → 3.0.1-20260106-205209-b085a480

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 (86) hide show
  1. package/dist/_build/common.mjs +24899 -0
  2. package/dist/_build/rolldown.mjs +6 -9
  3. package/dist/_build/rollup.mjs +6 -8
  4. package/dist/_build/vite.build.mjs +1 -1
  5. package/dist/{_dev.mjs → _chunks/dev.mjs} +4 -7
  6. package/dist/{_nitro.mjs → _chunks/nitro.mjs} +16 -195
  7. package/dist/_chunks/nitro2.mjs +101 -0
  8. package/dist/_chunks/utils.mjs +278 -0
  9. package/dist/_libs/@hiogawa/vite-plugin-fullstack.mjs +32 -4
  10. package/dist/_libs/@jridgewell/gen-mapping.mjs +304 -2
  11. package/dist/_libs/@jridgewell/remapping.mjs +1 -2
  12. package/dist/_libs/@rollup/plugin-commonjs.mjs +75 -31
  13. package/dist/_libs/@rollup/plugin-inject.mjs +1 -3
  14. package/dist/_libs/@rollup/plugin-json.mjs +1 -1
  15. package/dist/_libs/@rollup/plugin-node-resolve.mjs +1111 -7
  16. package/dist/_libs/c12.mjs +597 -41
  17. package/dist/_libs/chokidar.mjs +235 -2
  18. package/dist/_libs/confbox.mjs +454 -1476
  19. package/dist/_libs/estree-walker.mjs +1 -144
  20. package/dist/_libs/giget.mjs +2235 -1377
  21. package/dist/_libs/httpxy.mjs +1 -1
  22. package/dist/_libs/unimport.mjs +1547 -1772
  23. package/dist/_presets.mjs +3 -9
  24. package/dist/builder.mjs +7 -12
  25. package/dist/cli/_chunks/{build2.mjs → build.mjs} +1 -1
  26. package/dist/cli/_chunks/dev.mjs +3 -5
  27. package/dist/cli/_chunks/list.mjs +1 -1
  28. package/dist/cli/_chunks/prepare.mjs +1 -1
  29. package/dist/cli/_chunks/run.mjs +1 -1
  30. package/dist/cli/index.mjs +1 -1
  31. package/dist/vite.mjs +14 -1128
  32. package/package.json +1 -1
  33. package/dist/_build/rollup2.mjs +0 -56
  34. package/dist/_build/shared.mjs +0 -60
  35. package/dist/_build/shared2.mjs +0 -40
  36. package/dist/_build/shared3.mjs +0 -68
  37. package/dist/_libs/@jridgewell/resolve-uri.mjs +0 -166
  38. package/dist/_libs/@jridgewell/sourcemap-codec.mjs +0 -167
  39. package/dist/_libs/@jridgewell/trace-mapping.mjs +0 -141
  40. package/dist/_libs/@rolldown/pluginutils.mjs +0 -31
  41. package/dist/_libs/@rollup/plugin-replace.mjs +0 -104
  42. package/dist/_libs/@rollup/pluginutils.mjs +0 -241
  43. package/dist/_libs/acorn.mjs +0 -5034
  44. package/dist/_libs/commondir.mjs +0 -22
  45. package/dist/_libs/deepmerge.mjs +0 -86
  46. package/dist/_libs/dot-prop.mjs +0 -138
  47. package/dist/_libs/dotenv.mjs +0 -345
  48. package/dist/_libs/duplexer.mjs +0 -71
  49. package/dist/_libs/etag.mjs +0 -80
  50. package/dist/_libs/exsolve.mjs +0 -1007
  51. package/dist/_libs/fdir.mjs +0 -514
  52. package/dist/_libs/function-bind.mjs +0 -63
  53. package/dist/_libs/gzip-size.mjs +0 -21
  54. package/dist/_libs/hasown.mjs +0 -14
  55. package/dist/_libs/is-core-module.mjs +0 -220
  56. package/dist/_libs/is-module.mjs +0 -13
  57. package/dist/_libs/is-reference.mjs +0 -33
  58. package/dist/_libs/js-tokens.mjs +0 -382
  59. package/dist/_libs/knitwork.mjs +0 -124
  60. package/dist/_libs/local-pkg.mjs +0 -125
  61. package/dist/_libs/magic-string.mjs +0 -939
  62. package/dist/_libs/mime.mjs +0 -1391
  63. package/dist/_libs/mlly.mjs +0 -1415
  64. package/dist/_libs/node-fetch-native.mjs +0 -7
  65. package/dist/_libs/nypm.mjs +0 -239
  66. package/dist/_libs/path-parse.mjs +0 -47
  67. package/dist/_libs/pathe.mjs +0 -202
  68. package/dist/_libs/perfect-debounce.mjs +0 -89
  69. package/dist/_libs/picomatch.mjs +0 -1673
  70. package/dist/_libs/pkg-types.mjs +0 -197
  71. package/dist/_libs/pretty-bytes.mjs +0 -116
  72. package/dist/_libs/quansync.mjs +0 -90
  73. package/dist/_libs/rc9.mjs +0 -136
  74. package/dist/_libs/readdirp.mjs +0 -237
  75. package/dist/_libs/resolve.mjs +0 -689
  76. package/dist/_libs/std-env.mjs +0 -158
  77. package/dist/_libs/strip-literal.mjs +0 -51
  78. package/dist/_libs/tinyexec.mjs +0 -627
  79. package/dist/_libs/tinyglobby.mjs +0 -292
  80. package/dist/_libs/unplugin-utils.mjs +0 -61
  81. package/dist/_libs/unplugin.mjs +0 -1225
  82. package/dist/_libs/untyped.mjs +0 -271
  83. package/dist/_libs/unwasm.mjs +0 -5895
  84. package/dist/_libs/webpack-virtual-modules.mjs +0 -272
  85. package/dist/_nitro2.mjs +0 -303
  86. /package/dist/{_rolldown.mjs → _common.mjs} +0 -0
@@ -1,1415 +0,0 @@
1
- import { a as isAbsolute$1, s as normalize$1 } from "./pathe.mjs";
2
- import { t as readPackageJSON } from "./pkg-types.mjs";
3
- import { r as tokenizer } from "./acorn.mjs";
4
- import { builtinModules, createRequire } from "node:module";
5
- import fs, { promises, realpathSync, statSync } from "node:fs";
6
- import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
7
- import path, { dirname } from "node:path";
8
- import assert from "node:assert";
9
- import process$1 from "node:process";
10
- import v8 from "node:v8";
11
- import { format, inspect } from "node:util";
12
- import { joinURL } from "ufo";
13
-
14
- //#region node_modules/.pnpm/mlly@1.8.0/node_modules/mlly/dist/index.mjs
15
- const BUILTIN_MODULES = new Set(builtinModules);
16
- function normalizeSlash(path$1) {
17
- return path$1.replace(/\\/g, "/");
18
- }
19
- function matchAll(regex, string, addition) {
20
- const matches = [];
21
- for (const match of string.matchAll(regex)) matches.push({
22
- ...addition,
23
- ...match.groups,
24
- code: match[0],
25
- start: match.index,
26
- end: (match.index || 0) + match[0].length
27
- });
28
- return matches;
29
- }
30
- function clearImports(imports) {
31
- return (imports || "").replace(/\/\/[^\n]*\n|\/\*.*\*\//g, "").replace(/\s+/g, " ");
32
- }
33
- function getImportNames(cleanedImports) {
34
- const topLevelImports = cleanedImports.replace(/{[^}]*}/, "");
35
- return {
36
- namespacedImport: topLevelImports.match(/\* as \s*(\S*)/)?.[1],
37
- defaultImport: topLevelImports.split(",").find((index) => !/[*{}]/.test(index))?.trim() || void 0
38
- };
39
- }
40
- /**
41
- * @typedef ErrnoExceptionFields
42
- * @property {number | undefined} [errnode]
43
- * @property {string | undefined} [code]
44
- * @property {string | undefined} [path]
45
- * @property {string | undefined} [syscall]
46
- * @property {string | undefined} [url]
47
- *
48
- * @typedef {Error & ErrnoExceptionFields} ErrnoException
49
- */
50
- const own$1 = {}.hasOwnProperty;
51
- const classRegExp = /^([A-Z][a-z\d]*)+$/;
52
- const kTypes = new Set([
53
- "string",
54
- "function",
55
- "number",
56
- "object",
57
- "Function",
58
- "Object",
59
- "boolean",
60
- "bigint",
61
- "symbol"
62
- ]);
63
- const codes = {};
64
- /**
65
- * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
66
- * We cannot use Intl.ListFormat because it's not available in
67
- * --without-intl builds.
68
- *
69
- * @param {Array<string>} array
70
- * An array of strings.
71
- * @param {string} [type]
72
- * The list type to be inserted before the last element.
73
- * @returns {string}
74
- */
75
- function formatList(array, type = "and") {
76
- return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array[array.length - 1]}`;
77
- }
78
- /** @type {Map<string, MessageFunction | string>} */
79
- const messages = /* @__PURE__ */ new Map();
80
- const nodeInternalPrefix = "__node_internal_";
81
- /** @type {number} */
82
- let userStackTraceLimit;
83
- codes.ERR_INVALID_ARG_TYPE = createError(
84
- "ERR_INVALID_ARG_TYPE",
85
- /**
86
- * @param {string} name
87
- * @param {Array<string> | string} expected
88
- * @param {unknown} actual
89
- */
90
- (name, expected, actual) => {
91
- assert(typeof name === "string", "'name' must be a string");
92
- if (!Array.isArray(expected)) expected = [expected];
93
- let message = "The ";
94
- if (name.endsWith(" argument")) message += `${name} `;
95
- else {
96
- const type = name.includes(".") ? "property" : "argument";
97
- message += `"${name}" ${type} `;
98
- }
99
- message += "must be ";
100
- /** @type {Array<string>} */
101
- const types = [];
102
- /** @type {Array<string>} */
103
- const instances = [];
104
- /** @type {Array<string>} */
105
- const other = [];
106
- for (const value of expected) {
107
- assert(typeof value === "string", "All expected entries have to be of type string");
108
- if (kTypes.has(value)) types.push(value.toLowerCase());
109
- else if (classRegExp.exec(value) === null) {
110
- assert(value !== "object", "The value \"object\" should be written as \"Object\"");
111
- other.push(value);
112
- } else instances.push(value);
113
- }
114
- if (instances.length > 0) {
115
- const pos = types.indexOf("object");
116
- if (pos !== -1) {
117
- types.slice(pos, 1);
118
- instances.push("Object");
119
- }
120
- }
121
- if (types.length > 0) {
122
- message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(types, "or")}`;
123
- if (instances.length > 0 || other.length > 0) message += " or ";
124
- }
125
- if (instances.length > 0) {
126
- message += `an instance of ${formatList(instances, "or")}`;
127
- if (other.length > 0) message += " or ";
128
- }
129
- if (other.length > 0) if (other.length > 1) message += `one of ${formatList(other, "or")}`;
130
- else {
131
- if (other[0].toLowerCase() !== other[0]) message += "an ";
132
- message += `${other[0]}`;
133
- }
134
- message += `. Received ${determineSpecificType(actual)}`;
135
- return message;
136
- },
137
- TypeError
138
- );
139
- codes.ERR_INVALID_MODULE_SPECIFIER = createError(
140
- "ERR_INVALID_MODULE_SPECIFIER",
141
- /**
142
- * @param {string} request
143
- * @param {string} reason
144
- * @param {string} [base]
145
- */
146
- (request, reason, base = void 0) => {
147
- return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
148
- },
149
- TypeError
150
- );
151
- codes.ERR_INVALID_PACKAGE_CONFIG = createError(
152
- "ERR_INVALID_PACKAGE_CONFIG",
153
- /**
154
- * @param {string} path
155
- * @param {string} [base]
156
- * @param {string} [message]
157
- */
158
- (path$1, base, message) => {
159
- return `Invalid package config ${path$1}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
160
- },
161
- Error
162
- );
163
- codes.ERR_INVALID_PACKAGE_TARGET = createError(
164
- "ERR_INVALID_PACKAGE_TARGET",
165
- /**
166
- * @param {string} packagePath
167
- * @param {string} key
168
- * @param {unknown} target
169
- * @param {boolean} [isImport=false]
170
- * @param {string} [base]
171
- */
172
- (packagePath, key, target, isImport = false, base = void 0) => {
173
- const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
174
- if (key === ".") {
175
- assert(isImport === false);
176
- 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 \"./\"" : ""}`;
177
- }
178
- return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(target)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? "; targets must start with \"./\"" : ""}`;
179
- },
180
- Error
181
- );
182
- codes.ERR_MODULE_NOT_FOUND = createError(
183
- "ERR_MODULE_NOT_FOUND",
184
- /**
185
- * @param {string} path
186
- * @param {string} base
187
- * @param {boolean} [exactUrl]
188
- */
189
- (path$1, base, exactUrl = false) => {
190
- return `Cannot find ${exactUrl ? "module" : "package"} '${path$1}' imported from ${base}`;
191
- },
192
- Error
193
- );
194
- codes.ERR_NETWORK_IMPORT_DISALLOWED = createError("ERR_NETWORK_IMPORT_DISALLOWED", "import of '%s' by %s is not supported: %s", Error);
195
- codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
196
- "ERR_PACKAGE_IMPORT_NOT_DEFINED",
197
- /**
198
- * @param {string} specifier
199
- * @param {string} packagePath
200
- * @param {string} base
201
- */
202
- (specifier, packagePath, base) => {
203
- return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
204
- },
205
- TypeError
206
- );
207
- codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
208
- "ERR_PACKAGE_PATH_NOT_EXPORTED",
209
- /**
210
- * @param {string} packagePath
211
- * @param {string} subpath
212
- * @param {string} [base]
213
- */
214
- (packagePath, subpath, base = void 0) => {
215
- if (subpath === ".") return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
216
- return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
217
- },
218
- Error
219
- );
220
- codes.ERR_UNSUPPORTED_DIR_IMPORT = createError("ERR_UNSUPPORTED_DIR_IMPORT", "Directory import '%s' is not supported resolving ES modules imported from %s", Error);
221
- codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError("ERR_UNSUPPORTED_RESOLVE_REQUEST", "Failed to resolve module specifier \"%s\" from \"%s\": Invalid relative URL or base scheme is not hierarchical.", TypeError);
222
- codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
223
- "ERR_UNKNOWN_FILE_EXTENSION",
224
- /**
225
- * @param {string} extension
226
- * @param {string} path
227
- */
228
- (extension, path$1) => {
229
- return `Unknown file extension "${extension}" for ${path$1}`;
230
- },
231
- TypeError
232
- );
233
- codes.ERR_INVALID_ARG_VALUE = createError(
234
- "ERR_INVALID_ARG_VALUE",
235
- /**
236
- * @param {string} name
237
- * @param {unknown} value
238
- * @param {string} [reason='is invalid']
239
- */
240
- (name, value, reason = "is invalid") => {
241
- let inspected = inspect(value);
242
- if (inspected.length > 128) inspected = `${inspected.slice(0, 128)}...`;
243
- return `The ${name.includes(".") ? "property" : "argument"} '${name}' ${reason}. Received ${inspected}`;
244
- },
245
- TypeError
246
- );
247
- /**
248
- * Utility function for registering the error codes. Only used here. Exported
249
- * *only* to allow for testing.
250
- * @param {string} sym
251
- * @param {MessageFunction | string} value
252
- * @param {ErrorConstructor} constructor
253
- * @returns {new (...parameters: Array<any>) => Error}
254
- */
255
- function createError(sym, value, constructor) {
256
- messages.set(sym, value);
257
- return makeNodeErrorWithCode(constructor, sym);
258
- }
259
- /**
260
- * @param {ErrorConstructor} Base
261
- * @param {string} key
262
- * @returns {ErrorConstructor}
263
- */
264
- function makeNodeErrorWithCode(Base, key) {
265
- return NodeError;
266
- /**
267
- * @param {Array<unknown>} parameters
268
- */
269
- function NodeError(...parameters) {
270
- const limit = Error.stackTraceLimit;
271
- if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
272
- const error = new Base();
273
- if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
274
- const message = getMessage(key, parameters, error);
275
- Object.defineProperties(error, {
276
- message: {
277
- value: message,
278
- enumerable: false,
279
- writable: true,
280
- configurable: true
281
- },
282
- toString: {
283
- value() {
284
- return `${this.name} [${key}]: ${this.message}`;
285
- },
286
- enumerable: false,
287
- writable: true,
288
- configurable: true
289
- }
290
- });
291
- captureLargerStackTrace(error);
292
- error.code = key;
293
- return error;
294
- }
295
- }
296
- /**
297
- * @returns {boolean}
298
- */
299
- function isErrorStackTraceLimitWritable() {
300
- try {
301
- if (v8.startupSnapshot.isBuildingSnapshot()) return false;
302
- } catch {}
303
- const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
304
- if (desc === void 0) return Object.isExtensible(Error);
305
- return own$1.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
306
- }
307
- /**
308
- * This function removes unnecessary frames from Node.js core errors.
309
- * @template {(...parameters: unknown[]) => unknown} T
310
- * @param {T} wrappedFunction
311
- * @returns {T}
312
- */
313
- function hideStackFrames(wrappedFunction) {
314
- const hidden = nodeInternalPrefix + wrappedFunction.name;
315
- Object.defineProperty(wrappedFunction, "name", { value: hidden });
316
- return wrappedFunction;
317
- }
318
- const captureLargerStackTrace = hideStackFrames(
319
- /**
320
- * @param {Error} error
321
- * @returns {Error}
322
- */
323
- function(error) {
324
- const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
325
- if (stackTraceLimitIsWritable) {
326
- userStackTraceLimit = Error.stackTraceLimit;
327
- Error.stackTraceLimit = Number.POSITIVE_INFINITY;
328
- }
329
- Error.captureStackTrace(error);
330
- if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
331
- return error;
332
- }
333
- );
334
- /**
335
- * @param {string} key
336
- * @param {Array<unknown>} parameters
337
- * @param {Error} self
338
- * @returns {string}
339
- */
340
- function getMessage(key, parameters, self) {
341
- const message = messages.get(key);
342
- assert(message !== void 0, "expected `message` to be found");
343
- if (typeof message === "function") {
344
- assert(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`);
345
- return Reflect.apply(message, self, parameters);
346
- }
347
- const regex = /%[dfijoOs]/g;
348
- let expectedLength = 0;
349
- while (regex.exec(message) !== null) expectedLength++;
350
- assert(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`);
351
- if (parameters.length === 0) return message;
352
- parameters.unshift(message);
353
- return Reflect.apply(format, null, parameters);
354
- }
355
- /**
356
- * Determine the specific type of a value for type-mismatch errors.
357
- * @param {unknown} value
358
- * @returns {string}
359
- */
360
- function determineSpecificType(value) {
361
- if (value === null || value === void 0) return String(value);
362
- if (typeof value === "function" && value.name) return `function ${value.name}`;
363
- if (typeof value === "object") {
364
- if (value.constructor && value.constructor.name) return `an instance of ${value.constructor.name}`;
365
- return `${inspect(value, { depth: -1 })}`;
366
- }
367
- let inspected = inspect(value, { colors: false });
368
- if (inspected.length > 28) inspected = `${inspected.slice(0, 25)}...`;
369
- return `type ${typeof value} (${inspected})`;
370
- }
371
- const hasOwnProperty$1 = {}.hasOwnProperty;
372
- const { ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG$1 } = codes;
373
- /** @type {Map<string, PackageConfig>} */
374
- const cache = /* @__PURE__ */ new Map();
375
- /**
376
- * @param {string} jsonPath
377
- * @param {{specifier: URL | string, base?: URL}} options
378
- * @returns {PackageConfig}
379
- */
380
- function read(jsonPath, { base, specifier }) {
381
- const existing = cache.get(jsonPath);
382
- if (existing) return existing;
383
- /** @type {string | undefined} */
384
- let string;
385
- try {
386
- string = fs.readFileSync(path.toNamespacedPath(jsonPath), "utf8");
387
- } catch (error) {
388
- const exception = error;
389
- if (exception.code !== "ENOENT") throw exception;
390
- }
391
- /** @type {PackageConfig} */
392
- const result = {
393
- exists: false,
394
- pjsonPath: jsonPath,
395
- main: void 0,
396
- name: void 0,
397
- type: "none",
398
- exports: void 0,
399
- imports: void 0
400
- };
401
- if (string !== void 0) {
402
- /** @type {Record<string, unknown>} */
403
- let parsed;
404
- try {
405
- parsed = JSON.parse(string);
406
- } catch (error_) {
407
- const cause = error_;
408
- const error = new ERR_INVALID_PACKAGE_CONFIG$1(jsonPath, (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier), cause.message);
409
- error.cause = cause;
410
- throw error;
411
- }
412
- result.exists = true;
413
- if (hasOwnProperty$1.call(parsed, "name") && typeof parsed.name === "string") result.name = parsed.name;
414
- if (hasOwnProperty$1.call(parsed, "main") && typeof parsed.main === "string") result.main = parsed.main;
415
- if (hasOwnProperty$1.call(parsed, "exports")) result.exports = parsed.exports;
416
- if (hasOwnProperty$1.call(parsed, "imports")) result.imports = parsed.imports;
417
- if (hasOwnProperty$1.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) result.type = parsed.type;
418
- }
419
- cache.set(jsonPath, result);
420
- return result;
421
- }
422
- /**
423
- * @param {URL | string} resolved
424
- * @returns {PackageConfig}
425
- */
426
- function getPackageScopeConfig(resolved) {
427
- let packageJSONUrl = new URL("package.json", resolved);
428
- while (true) {
429
- if (packageJSONUrl.pathname.endsWith("node_modules/package.json")) break;
430
- const packageConfig = read(fileURLToPath(packageJSONUrl), { specifier: resolved });
431
- if (packageConfig.exists) return packageConfig;
432
- const lastPackageJSONUrl = packageJSONUrl;
433
- packageJSONUrl = new URL("../package.json", packageJSONUrl);
434
- if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) break;
435
- }
436
- return {
437
- pjsonPath: fileURLToPath(packageJSONUrl),
438
- exists: false,
439
- type: "none"
440
- };
441
- }
442
- /**
443
- * Returns the package type for a given URL.
444
- * @param {URL} url - The URL to get the package type for.
445
- * @returns {PackageType}
446
- */
447
- function getPackageType(url) {
448
- return getPackageScopeConfig(url).type;
449
- }
450
- const { ERR_UNKNOWN_FILE_EXTENSION } = codes;
451
- const hasOwnProperty = {}.hasOwnProperty;
452
- /** @type {Record<string, string>} */
453
- const extensionFormatMap = {
454
- __proto__: null,
455
- ".cjs": "commonjs",
456
- ".js": "module",
457
- ".json": "json",
458
- ".mjs": "module"
459
- };
460
- /**
461
- * @param {string | null} mime
462
- * @returns {string | null}
463
- */
464
- function mimeToFormat(mime) {
465
- if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return "module";
466
- if (mime === "application/json") return "json";
467
- return null;
468
- }
469
- /**
470
- * @callback ProtocolHandler
471
- * @param {URL} parsed
472
- * @param {{parentURL: string, source?: Buffer}} context
473
- * @param {boolean} ignoreErrors
474
- * @returns {string | null | void}
475
- */
476
- /**
477
- * @type {Record<string, ProtocolHandler>}
478
- */
479
- const protocolHandlers = {
480
- __proto__: null,
481
- "data:": getDataProtocolModuleFormat,
482
- "file:": getFileProtocolModuleFormat,
483
- "http:": getHttpProtocolModuleFormat,
484
- "https:": getHttpProtocolModuleFormat,
485
- "node:"() {
486
- return "builtin";
487
- }
488
- };
489
- /**
490
- * @param {URL} parsed
491
- */
492
- function getDataProtocolModuleFormat(parsed) {
493
- const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
494
- null,
495
- null,
496
- null
497
- ];
498
- return mimeToFormat(mime);
499
- }
500
- /**
501
- * Returns the file extension from a URL.
502
- *
503
- * Should give similar result to
504
- * `require('node:path').extname(require('node:url').fileURLToPath(url))`
505
- * when used with a `file:` URL.
506
- *
507
- * @param {URL} url
508
- * @returns {string}
509
- */
510
- function extname$1(url) {
511
- const pathname = url.pathname;
512
- let index = pathname.length;
513
- while (index--) {
514
- const code = pathname.codePointAt(index);
515
- if (code === 47) return "";
516
- if (code === 46) return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
517
- }
518
- return "";
519
- }
520
- /**
521
- * @type {ProtocolHandler}
522
- */
523
- function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
524
- const value = extname$1(url);
525
- if (value === ".js") {
526
- const packageType = getPackageType(url);
527
- if (packageType !== "none") return packageType;
528
- return "commonjs";
529
- }
530
- if (value === "") {
531
- const packageType = getPackageType(url);
532
- if (packageType === "none" || packageType === "commonjs") return "commonjs";
533
- return "module";
534
- }
535
- const format$1 = extensionFormatMap[value];
536
- if (format$1) return format$1;
537
- if (ignoreErrors) return;
538
- throw new ERR_UNKNOWN_FILE_EXTENSION(value, fileURLToPath(url));
539
- }
540
- function getHttpProtocolModuleFormat() {}
541
- /**
542
- * @param {URL} url
543
- * @param {{parentURL: string}} context
544
- * @returns {string | null}
545
- */
546
- function defaultGetFormatWithoutErrors(url, context) {
547
- const protocol = url.protocol;
548
- if (!hasOwnProperty.call(protocolHandlers, protocol)) return null;
549
- return protocolHandlers[protocol](url, context, true) || null;
550
- }
551
- const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
552
- const { ERR_INVALID_MODULE_SPECIFIER, ERR_INVALID_PACKAGE_CONFIG, ERR_INVALID_PACKAGE_TARGET, ERR_MODULE_NOT_FOUND, ERR_PACKAGE_IMPORT_NOT_DEFINED, ERR_PACKAGE_PATH_NOT_EXPORTED, ERR_UNSUPPORTED_DIR_IMPORT, ERR_UNSUPPORTED_RESOLVE_REQUEST } = codes;
553
- const own = {}.hasOwnProperty;
554
- const 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;
555
- const 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;
556
- const invalidPackageNameRegEx = /^\.|%|\\/;
557
- const patternRegEx = /\*/g;
558
- const encodedSeparatorRegEx = /%2f|%5c/i;
559
- /** @type {Set<string>} */
560
- const emittedPackageWarnings = /* @__PURE__ */ new Set();
561
- const doubleSlashRegEx = /[/\\]{2}/;
562
- /**
563
- *
564
- * @param {string} target
565
- * @param {string} request
566
- * @param {string} match
567
- * @param {URL} packageJsonUrl
568
- * @param {boolean} internal
569
- * @param {URL} base
570
- * @param {boolean} isTarget
571
- */
572
- function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
573
- if (process$1.noDeprecation) return;
574
- const pjsonPath = fileURLToPath(packageJsonUrl);
575
- const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
576
- process$1.emitWarning(`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)}` : ""}.`, "DeprecationWarning", "DEP0166");
577
- }
578
- /**
579
- * @param {URL} url
580
- * @param {URL} packageJsonUrl
581
- * @param {URL} base
582
- * @param {string} [main]
583
- * @returns {void}
584
- */
585
- function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
586
- if (process$1.noDeprecation) return;
587
- if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module") return;
588
- const urlPath = fileURLToPath(url.href);
589
- const packagePath = fileURLToPath(new URL$1(".", packageJsonUrl));
590
- const basePath = fileURLToPath(base);
591
- if (!main) process$1.emitWarning(`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
592
- else if (path.resolve(packagePath, main) !== urlPath) process$1.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
593
- }
594
- /**
595
- * @param {string} path
596
- * @returns {Stats | undefined}
597
- */
598
- function tryStatSync(path$1) {
599
- try {
600
- return statSync(path$1);
601
- } catch {}
602
- }
603
- /**
604
- * Legacy CommonJS main resolution:
605
- * 1. let M = pkg_url + (json main field)
606
- * 2. TRY(M, M.js, M.json, M.node)
607
- * 3. TRY(M/index.js, M/index.json, M/index.node)
608
- * 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
609
- * 5. NOT_FOUND
610
- *
611
- * @param {URL} url
612
- * @returns {boolean}
613
- */
614
- function fileExists(url) {
615
- const stats = statSync(url, { throwIfNoEntry: false });
616
- const isFile = stats ? stats.isFile() : void 0;
617
- return isFile === null || isFile === void 0 ? false : isFile;
618
- }
619
- /**
620
- * @param {URL} packageJsonUrl
621
- * @param {PackageConfig} packageConfig
622
- * @param {URL} base
623
- * @returns {URL}
624
- */
625
- function legacyMainResolve(packageJsonUrl, packageConfig, base) {
626
- /** @type {URL | undefined} */
627
- let guess;
628
- if (packageConfig.main !== void 0) {
629
- guess = new URL$1(packageConfig.main, packageJsonUrl);
630
- if (fileExists(guess)) return guess;
631
- const tries$1 = [
632
- `./${packageConfig.main}.js`,
633
- `./${packageConfig.main}.json`,
634
- `./${packageConfig.main}.node`,
635
- `./${packageConfig.main}/index.js`,
636
- `./${packageConfig.main}/index.json`,
637
- `./${packageConfig.main}/index.node`
638
- ];
639
- let i$1 = -1;
640
- while (++i$1 < tries$1.length) {
641
- guess = new URL$1(tries$1[i$1], packageJsonUrl);
642
- if (fileExists(guess)) break;
643
- guess = void 0;
644
- }
645
- if (guess) {
646
- emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
647
- return guess;
648
- }
649
- }
650
- const tries = [
651
- "./index.js",
652
- "./index.json",
653
- "./index.node"
654
- ];
655
- let i = -1;
656
- while (++i < tries.length) {
657
- guess = new URL$1(tries[i], packageJsonUrl);
658
- if (fileExists(guess)) break;
659
- guess = void 0;
660
- }
661
- if (guess) {
662
- emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
663
- return guess;
664
- }
665
- throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL$1(".", packageJsonUrl)), fileURLToPath(base));
666
- }
667
- /**
668
- * @param {URL} resolved
669
- * @param {URL} base
670
- * @param {boolean} [preserveSymlinks]
671
- * @returns {URL}
672
- */
673
- function finalizeResolution(resolved, base, preserveSymlinks) {
674
- if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, "must not include encoded \"/\" or \"\\\" characters", fileURLToPath(base));
675
- /** @type {string} */
676
- let filePath;
677
- try {
678
- filePath = fileURLToPath(resolved);
679
- } catch (error) {
680
- const cause = error;
681
- Object.defineProperty(cause, "input", { value: String(resolved) });
682
- Object.defineProperty(cause, "module", { value: String(base) });
683
- throw cause;
684
- }
685
- const stats = tryStatSync(filePath.endsWith("/") ? filePath.slice(-1) : filePath);
686
- if (stats && stats.isDirectory()) {
687
- const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath(base));
688
- error.url = String(resolved);
689
- throw error;
690
- }
691
- if (!stats || !stats.isFile()) {
692
- const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && fileURLToPath(base), true);
693
- error.url = String(resolved);
694
- throw error;
695
- }
696
- {
697
- const real = realpathSync(filePath);
698
- const { search, hash } = resolved;
699
- resolved = pathToFileURL(real + (filePath.endsWith(path.sep) ? "/" : ""));
700
- resolved.search = search;
701
- resolved.hash = hash;
702
- }
703
- return resolved;
704
- }
705
- /**
706
- * @param {string} specifier
707
- * @param {URL | undefined} packageJsonUrl
708
- * @param {URL} base
709
- * @returns {Error}
710
- */
711
- function importNotDefined(specifier, packageJsonUrl, base) {
712
- return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && fileURLToPath(new URL$1(".", packageJsonUrl)), fileURLToPath(base));
713
- }
714
- /**
715
- * @param {string} subpath
716
- * @param {URL} packageJsonUrl
717
- * @param {URL} base
718
- * @returns {Error}
719
- */
720
- function exportsNotFound(subpath, packageJsonUrl, base) {
721
- return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL$1(".", packageJsonUrl)), subpath, base && fileURLToPath(base));
722
- }
723
- /**
724
- * @param {string} request
725
- * @param {string} match
726
- * @param {URL} packageJsonUrl
727
- * @param {boolean} internal
728
- * @param {URL} [base]
729
- * @returns {never}
730
- */
731
- function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
732
- throw new ERR_INVALID_MODULE_SPECIFIER(request, `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJsonUrl)}`, base && fileURLToPath(base));
733
- }
734
- /**
735
- * @param {string} subpath
736
- * @param {unknown} target
737
- * @param {URL} packageJsonUrl
738
- * @param {boolean} internal
739
- * @param {URL} [base]
740
- * @returns {Error}
741
- */
742
- function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
743
- target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
744
- return new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL$1(".", packageJsonUrl)), subpath, target, internal, base && fileURLToPath(base));
745
- }
746
- /**
747
- * @param {string} target
748
- * @param {string} subpath
749
- * @param {string} match
750
- * @param {URL} packageJsonUrl
751
- * @param {URL} base
752
- * @param {boolean} pattern
753
- * @param {boolean} internal
754
- * @param {boolean} isPathMap
755
- * @param {Set<string> | undefined} conditions
756
- * @returns {URL}
757
- */
758
- function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
759
- if (subpath !== "" && !pattern && target[target.length - 1] !== "/") throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
760
- if (!target.startsWith("./")) {
761
- if (internal && !target.startsWith("../") && !target.startsWith("/")) {
762
- let isURL = false;
763
- try {
764
- new URL$1(target);
765
- isURL = true;
766
- } catch {}
767
- if (!isURL) return packageResolve(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath, packageJsonUrl, conditions);
768
- }
769
- throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
770
- }
771
- if (invalidSegmentRegEx.exec(target.slice(2)) !== null) if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
772
- if (!isPathMap) {
773
- const request = pattern ? match.replace("*", () => subpath) : match + subpath;
774
- emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, true);
775
- }
776
- } else throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
777
- const resolved = new URL$1(target, packageJsonUrl);
778
- const resolvedPath = resolved.pathname;
779
- const packagePath = new URL$1(".", packageJsonUrl).pathname;
780
- if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
781
- if (subpath === "") return resolved;
782
- if (invalidSegmentRegEx.exec(subpath) !== null) {
783
- const request = pattern ? match.replace("*", () => subpath) : match + subpath;
784
- if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
785
- if (!isPathMap) emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, false);
786
- } else throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
787
- }
788
- if (pattern) return new URL$1(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
789
- return new URL$1(subpath, resolved);
790
- }
791
- /**
792
- * @param {string} key
793
- * @returns {boolean}
794
- */
795
- function isArrayIndex(key) {
796
- const keyNumber = Number(key);
797
- if (`${keyNumber}` !== key) return false;
798
- return keyNumber >= 0 && keyNumber < 4294967295;
799
- }
800
- /**
801
- * @param {URL} packageJsonUrl
802
- * @param {unknown} target
803
- * @param {string} subpath
804
- * @param {string} packageSubpath
805
- * @param {URL} base
806
- * @param {boolean} pattern
807
- * @param {boolean} internal
808
- * @param {boolean} isPathMap
809
- * @param {Set<string> | undefined} conditions
810
- * @returns {URL | null}
811
- */
812
- function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
813
- if (typeof target === "string") return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
814
- if (Array.isArray(target)) {
815
- /** @type {Array<unknown>} */
816
- const targetList = target;
817
- if (targetList.length === 0) return null;
818
- /** @type {ErrnoException | null | undefined} */
819
- let lastException;
820
- let i = -1;
821
- while (++i < targetList.length) {
822
- const targetItem = targetList[i];
823
- /** @type {URL | null} */
824
- let resolveResult;
825
- try {
826
- resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
827
- } catch (error) {
828
- const exception = error;
829
- lastException = exception;
830
- if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
831
- throw error;
832
- }
833
- if (resolveResult === void 0) continue;
834
- if (resolveResult === null) {
835
- lastException = null;
836
- continue;
837
- }
838
- return resolveResult;
839
- }
840
- if (lastException === void 0 || lastException === null) return null;
841
- throw lastException;
842
- }
843
- if (typeof target === "object" && target !== null) {
844
- const keys = Object.getOwnPropertyNames(target);
845
- let i = -1;
846
- while (++i < keys.length) {
847
- const key = keys[i];
848
- if (isArrayIndex(key)) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), base, "\"exports\" cannot contain numeric property keys.");
849
- }
850
- i = -1;
851
- while (++i < keys.length) {
852
- const key = keys[i];
853
- if (key === "default" || conditions && conditions.has(key)) {
854
- const conditionalTarget = target[key];
855
- const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
856
- if (resolveResult === void 0) continue;
857
- return resolveResult;
858
- }
859
- }
860
- return null;
861
- }
862
- if (target === null) return null;
863
- throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
864
- }
865
- /**
866
- * @param {unknown} exports
867
- * @param {URL} packageJsonUrl
868
- * @param {URL} base
869
- * @returns {boolean}
870
- */
871
- function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
872
- if (typeof exports === "string" || Array.isArray(exports)) return true;
873
- if (typeof exports !== "object" || exports === null) return false;
874
- const keys = Object.getOwnPropertyNames(exports);
875
- let isConditionalSugar = false;
876
- let i = 0;
877
- let keyIndex = -1;
878
- while (++keyIndex < keys.length) {
879
- const key = keys[keyIndex];
880
- const currentIsConditionalSugar = key === "" || key[0] !== ".";
881
- if (i++ === 0) isConditionalSugar = currentIsConditionalSugar;
882
- else if (isConditionalSugar !== currentIsConditionalSugar) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), base, "\"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.");
883
- }
884
- return isConditionalSugar;
885
- }
886
- /**
887
- * @param {string} match
888
- * @param {URL} pjsonUrl
889
- * @param {URL} base
890
- */
891
- function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
892
- if (process$1.noDeprecation) return;
893
- const pjsonPath = fileURLToPath(pjsonUrl);
894
- if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
895
- emittedPackageWarnings.add(pjsonPath + "|" + match);
896
- process$1.emitWarning(`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.`, "DeprecationWarning", "DEP0155");
897
- }
898
- /**
899
- * @param {URL} packageJsonUrl
900
- * @param {string} packageSubpath
901
- * @param {Record<string, unknown>} packageConfig
902
- * @param {URL} base
903
- * @param {Set<string> | undefined} conditions
904
- * @returns {URL}
905
- */
906
- function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
907
- let exports = packageConfig.exports;
908
- if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) exports = { ".": exports };
909
- if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
910
- const target = exports[packageSubpath];
911
- const resolveResult = resolvePackageTarget(packageJsonUrl, target, "", packageSubpath, base, false, false, false, conditions);
912
- if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
913
- return resolveResult;
914
- }
915
- let bestMatch = "";
916
- let bestMatchSubpath = "";
917
- const keys = Object.getOwnPropertyNames(exports);
918
- let i = -1;
919
- while (++i < keys.length) {
920
- const key = keys[i];
921
- const patternIndex = key.indexOf("*");
922
- if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
923
- if (packageSubpath.endsWith("/")) emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
924
- const patternTrailer = key.slice(patternIndex + 1);
925
- if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
926
- bestMatch = key;
927
- bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
928
- }
929
- }
930
- }
931
- if (bestMatch) {
932
- const target = exports[bestMatch];
933
- const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith("/"), conditions);
934
- if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
935
- return resolveResult;
936
- }
937
- throw exportsNotFound(packageSubpath, packageJsonUrl, base);
938
- }
939
- /**
940
- * @param {string} a
941
- * @param {string} b
942
- */
943
- function patternKeyCompare(a, b) {
944
- const aPatternIndex = a.indexOf("*");
945
- const bPatternIndex = b.indexOf("*");
946
- const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
947
- const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
948
- if (baseLengthA > baseLengthB) return -1;
949
- if (baseLengthB > baseLengthA) return 1;
950
- if (aPatternIndex === -1) return 1;
951
- if (bPatternIndex === -1) return -1;
952
- if (a.length > b.length) return -1;
953
- if (b.length > a.length) return 1;
954
- return 0;
955
- }
956
- /**
957
- * @param {string} name
958
- * @param {URL} base
959
- * @param {Set<string>} [conditions]
960
- * @returns {URL}
961
- */
962
- function packageImportsResolve(name, base, conditions) {
963
- if (name === "#" || name.startsWith("#/") || name.endsWith("/")) throw new ERR_INVALID_MODULE_SPECIFIER(name, "is not a valid internal imports specifier name", fileURLToPath(base));
964
- /** @type {URL | undefined} */
965
- let packageJsonUrl;
966
- const packageConfig = getPackageScopeConfig(base);
967
- if (packageConfig.exists) {
968
- packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
969
- const imports = packageConfig.imports;
970
- if (imports) if (own.call(imports, name) && !name.includes("*")) {
971
- const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], "", name, base, false, true, false, conditions);
972
- if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
973
- } else {
974
- let bestMatch = "";
975
- let bestMatchSubpath = "";
976
- const keys = Object.getOwnPropertyNames(imports);
977
- let i = -1;
978
- while (++i < keys.length) {
979
- const key = keys[i];
980
- const patternIndex = key.indexOf("*");
981
- if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
982
- const patternTrailer = key.slice(patternIndex + 1);
983
- if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
984
- bestMatch = key;
985
- bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
986
- }
987
- }
988
- }
989
- if (bestMatch) {
990
- const target = imports[bestMatch];
991
- const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
992
- if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
993
- }
994
- }
995
- }
996
- throw importNotDefined(name, packageJsonUrl, base);
997
- }
998
- /**
999
- * @param {string} specifier
1000
- * @param {URL} base
1001
- */
1002
- function parsePackageName(specifier, base) {
1003
- let separatorIndex = specifier.indexOf("/");
1004
- let validPackageName = true;
1005
- let isScoped = false;
1006
- if (specifier[0] === "@") {
1007
- isScoped = true;
1008
- if (separatorIndex === -1 || specifier.length === 0) validPackageName = false;
1009
- else separatorIndex = specifier.indexOf("/", separatorIndex + 1);
1010
- }
1011
- const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
1012
- if (invalidPackageNameRegEx.exec(packageName) !== null) validPackageName = false;
1013
- if (!validPackageName) throw new ERR_INVALID_MODULE_SPECIFIER(specifier, "is not a valid package name", fileURLToPath(base));
1014
- return {
1015
- packageName,
1016
- packageSubpath: "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex)),
1017
- isScoped
1018
- };
1019
- }
1020
- /**
1021
- * @param {string} specifier
1022
- * @param {URL} base
1023
- * @param {Set<string> | undefined} conditions
1024
- * @returns {URL}
1025
- */
1026
- function packageResolve(specifier, base, conditions) {
1027
- if (builtinModules.includes(specifier)) return new URL$1("node:" + specifier);
1028
- const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
1029
- const packageConfig = getPackageScopeConfig(base);
1030
- /* c8 ignore next 16 */
1031
- if (packageConfig.exists) {
1032
- const packageJsonUrl$1 = pathToFileURL(packageConfig.pjsonPath);
1033
- if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(packageJsonUrl$1, packageSubpath, packageConfig, base, conditions);
1034
- }
1035
- let packageJsonUrl = new URL$1("./node_modules/" + packageName + "/package.json", base);
1036
- let packageJsonPath = fileURLToPath(packageJsonUrl);
1037
- /** @type {string} */
1038
- let lastPath;
1039
- do {
1040
- const stat$1 = tryStatSync(packageJsonPath.slice(0, -13));
1041
- if (!stat$1 || !stat$1.isDirectory()) {
1042
- lastPath = packageJsonPath;
1043
- packageJsonUrl = new URL$1((isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json", packageJsonUrl);
1044
- packageJsonPath = fileURLToPath(packageJsonUrl);
1045
- continue;
1046
- }
1047
- const packageConfig$1 = read(packageJsonPath, {
1048
- base,
1049
- specifier
1050
- });
1051
- if (packageConfig$1.exports !== void 0 && packageConfig$1.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig$1, base, conditions);
1052
- if (packageSubpath === ".") return legacyMainResolve(packageJsonUrl, packageConfig$1, base);
1053
- return new URL$1(packageSubpath, packageJsonUrl);
1054
- } while (packageJsonPath.length !== lastPath.length);
1055
- throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), false);
1056
- }
1057
- /**
1058
- * @param {string} specifier
1059
- * @returns {boolean}
1060
- */
1061
- function isRelativeSpecifier(specifier) {
1062
- if (specifier[0] === ".") {
1063
- if (specifier.length === 1 || specifier[1] === "/") return true;
1064
- if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) return true;
1065
- }
1066
- return false;
1067
- }
1068
- /**
1069
- * @param {string} specifier
1070
- * @returns {boolean}
1071
- */
1072
- function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
1073
- if (specifier === "") return false;
1074
- if (specifier[0] === "/") return true;
1075
- return isRelativeSpecifier(specifier);
1076
- }
1077
- /**
1078
- * The “Resolver Algorithm Specification” as detailed in the Node docs (which is
1079
- * sync and slightly lower-level than `resolve`).
1080
- *
1081
- * @param {string} specifier
1082
- * `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
1083
- * @param {URL} base
1084
- * Full URL (to a file) that `specifier` is resolved relative from.
1085
- * @param {Set<string>} [conditions]
1086
- * Conditions.
1087
- * @param {boolean} [preserveSymlinks]
1088
- * Keep symlinks instead of resolving them.
1089
- * @returns {URL}
1090
- * A URL object to the found thing.
1091
- */
1092
- function moduleResolve(specifier, base, conditions, preserveSymlinks) {
1093
- const protocol = base.protocol;
1094
- const isRemote = protocol === "data:" || protocol === "http:" || protocol === "https:";
1095
- /** @type {URL | undefined} */
1096
- let resolved;
1097
- if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) try {
1098
- resolved = new URL$1(specifier, base);
1099
- } catch (error_) {
1100
- const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
1101
- error.cause = error_;
1102
- throw error;
1103
- }
1104
- else if (protocol === "file:" && specifier[0] === "#") resolved = packageImportsResolve(specifier, base, conditions);
1105
- else try {
1106
- resolved = new URL$1(specifier);
1107
- } catch (error_) {
1108
- if (isRemote && !builtinModules.includes(specifier)) {
1109
- const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
1110
- error.cause = error_;
1111
- throw error;
1112
- }
1113
- resolved = packageResolve(specifier, base, conditions);
1114
- }
1115
- assert(resolved !== void 0, "expected to be defined");
1116
- if (resolved.protocol !== "file:") return resolved;
1117
- return finalizeResolution(resolved, base);
1118
- }
1119
- function fileURLToPath$1(id) {
1120
- if (typeof id === "string" && !id.startsWith("file://")) return normalizeSlash(id);
1121
- return normalizeSlash(fileURLToPath(id));
1122
- }
1123
- function pathToFileURL$1(id) {
1124
- return pathToFileURL(fileURLToPath$1(id)).toString();
1125
- }
1126
- function normalizeid(id) {
1127
- if (typeof id !== "string") id = id.toString();
1128
- if (/(?:node|data|http|https|file):/.test(id)) return id;
1129
- if (BUILTIN_MODULES.has(id)) return "node:" + id;
1130
- return "file://" + encodeURI(normalizeSlash(id));
1131
- }
1132
- async function loadURL(url) {
1133
- return await promises.readFile(fileURLToPath$1(url), "utf8");
1134
- }
1135
- const DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
1136
- const DEFAULT_EXTENSIONS = [
1137
- ".mjs",
1138
- ".cjs",
1139
- ".js",
1140
- ".json"
1141
- ];
1142
- const NOT_FOUND_ERRORS = /* @__PURE__ */ new Set([
1143
- "ERR_MODULE_NOT_FOUND",
1144
- "ERR_UNSUPPORTED_DIR_IMPORT",
1145
- "MODULE_NOT_FOUND",
1146
- "ERR_PACKAGE_PATH_NOT_EXPORTED"
1147
- ]);
1148
- function _tryModuleResolve(id, url, conditions) {
1149
- try {
1150
- return moduleResolve(id, url, conditions);
1151
- } catch (error) {
1152
- if (!NOT_FOUND_ERRORS.has(error?.code)) throw error;
1153
- }
1154
- }
1155
- function _resolve(id, options = {}) {
1156
- if (typeof id !== "string") if (id instanceof URL) id = fileURLToPath$1(id);
1157
- else throw new TypeError("input must be a `string` or `URL`");
1158
- if (/(?:node|data|http|https):/.test(id)) return id;
1159
- if (BUILTIN_MODULES.has(id)) return "node:" + id;
1160
- if (id.startsWith("file://")) id = fileURLToPath$1(id);
1161
- if (isAbsolute$1(id)) try {
1162
- if (statSync(id).isFile()) return pathToFileURL$1(id);
1163
- } catch (error) {
1164
- if (error?.code !== "ENOENT") throw error;
1165
- }
1166
- const conditionsSet = options.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
1167
- const _urls = (Array.isArray(options.url) ? options.url : [options.url]).filter(Boolean).map((url) => new URL(normalizeid(url.toString())));
1168
- if (_urls.length === 0) _urls.push(new URL(pathToFileURL$1(process.cwd())));
1169
- const urls = [..._urls];
1170
- for (const url of _urls) if (url.protocol === "file:") urls.push(new URL("./", url), new URL(joinURL(url.pathname, "_index.js"), url), new URL("node_modules", url));
1171
- let resolved;
1172
- for (const url of urls) {
1173
- resolved = _tryModuleResolve(id, url, conditionsSet);
1174
- if (resolved) break;
1175
- for (const prefix of ["", "/index"]) {
1176
- for (const extension of options.extensions || DEFAULT_EXTENSIONS) {
1177
- resolved = _tryModuleResolve(joinURL(id, prefix) + extension, url, conditionsSet);
1178
- if (resolved) break;
1179
- }
1180
- if (resolved) break;
1181
- }
1182
- if (resolved) break;
1183
- }
1184
- if (!resolved) {
1185
- const error = /* @__PURE__ */ new Error(`Cannot find module ${id} imported from ${urls.join(", ")}`);
1186
- error.code = "ERR_MODULE_NOT_FOUND";
1187
- throw error;
1188
- }
1189
- return pathToFileURL$1(resolved);
1190
- }
1191
- function resolveSync(id, options) {
1192
- return _resolve(id, options);
1193
- }
1194
- function resolve$1(id, options) {
1195
- try {
1196
- return Promise.resolve(resolveSync(id, options));
1197
- } catch (error) {
1198
- return Promise.reject(error);
1199
- }
1200
- }
1201
- function resolvePathSync(id, options) {
1202
- return fileURLToPath$1(resolveSync(id, options));
1203
- }
1204
- function resolvePath(id, options) {
1205
- try {
1206
- return Promise.resolve(resolvePathSync(id, options));
1207
- } catch (error) {
1208
- return Promise.reject(error);
1209
- }
1210
- }
1211
- const NODE_MODULES_RE = /^(.+\/node_modules\/)([^/@]+|@[^/]+\/[^/]+)(\/?.*?)?$/;
1212
- function parseNodeModulePath(path$1) {
1213
- if (!path$1) return {};
1214
- path$1 = normalize$1(fileURLToPath$1(path$1));
1215
- const match = NODE_MODULES_RE.exec(path$1);
1216
- if (!match) return {};
1217
- const [, dir, name, subpath] = match;
1218
- return {
1219
- dir,
1220
- name,
1221
- subpath: subpath ? `.${subpath}` : void 0
1222
- };
1223
- }
1224
- async function lookupNodeModuleSubpath(path$1) {
1225
- path$1 = normalize$1(fileURLToPath$1(path$1));
1226
- const { name, subpath } = parseNodeModulePath(path$1);
1227
- if (!name || !subpath) return subpath;
1228
- const { exports } = await readPackageJSON(path$1).catch(() => {}) || {};
1229
- if (exports) {
1230
- const resolvedSubpath = _findSubpath(subpath, exports);
1231
- if (resolvedSubpath) return resolvedSubpath;
1232
- }
1233
- return subpath;
1234
- }
1235
- function _findSubpath(subpath, exports) {
1236
- if (typeof exports === "string") exports = { ".": exports };
1237
- if (!subpath.startsWith(".")) subpath = subpath.startsWith("/") ? `.${subpath}` : `./${subpath}`;
1238
- if (subpath in (exports || {})) return subpath;
1239
- return _flattenExports(exports).find((p) => p.fsPath === subpath)?.subpath;
1240
- }
1241
- function _flattenExports(exports = {}, parentSubpath = "./") {
1242
- return Object.entries(exports).flatMap(([key, value]) => {
1243
- const [subpath, condition] = key.startsWith(".") ? [key.slice(1), void 0] : ["", key];
1244
- const _subPath = joinURL(parentSubpath, subpath);
1245
- if (typeof value === "string") return [{
1246
- subpath: _subPath,
1247
- fsPath: value,
1248
- condition
1249
- }];
1250
- else return _flattenExports(value, _subPath);
1251
- });
1252
- }
1253
- const ESM_STATIC_IMPORT_RE = /(?<=\s|^|;|\})import\s*(?:[\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
1254
- const EXPORT_DECAL_RE = /\bexport\s+(?<declaration>(?:async function\s*\*?|function\s*\*?|let|const enum|const|enum|var|class))\s+\*?(?<name>[\w$]+)(?<extraNames>.*,\s*[\s\w:[\]{}]*[\w$\]}]+)*/g;
1255
- const EXPORT_DECAL_TYPE_RE = /\bexport\s+(?<declaration>(?:interface|type|declare (?:async function|function|let|const enum|const|enum|var|class)))\s+(?<name>[\w$]+)/g;
1256
- const EXPORT_NAMED_RE = /\bexport\s*{(?<exports>[^}]+?)[\s,]*}(?:\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][^\n;]*)?/g;
1257
- const EXPORT_NAMED_TYPE_RE = /\bexport\s+type\s*{(?<exports>[^}]+?)[\s,]*}(?:\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][^\n;]*)?/g;
1258
- const EXPORT_NAMED_DESTRUCT = /\bexport\s+(?:let|var|const)\s+(?:{(?<exports1>[^}]+?)[\s,]*}|\[(?<exports2>[^\]]+?)[\s,]*])\s+=/gm;
1259
- const EXPORT_STAR_RE = /\bexport\s*\*(?:\s*as\s+(?<name>[\w$]+)\s+)?\s*(?:\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][^\n;]*)?/g;
1260
- const EXPORT_DEFAULT_RE = /\bexport\s+default\s+(async function|function|class|true|false|\W|\d)|\bexport\s+default\s+(?<defaultName>.*)/g;
1261
- const EXPORT_DEFAULT_CLASS_RE = /\bexport\s+default\s+(?<declaration>class)\s+(?<name>[\w$]+)/g;
1262
- const TYPE_RE = /^\s*?type\s/;
1263
- function findStaticImports(code) {
1264
- return _filterStatement(_tryGetLocations(code, "import"), matchAll(ESM_STATIC_IMPORT_RE, code, { type: "static" }));
1265
- }
1266
- function parseStaticImport(matched) {
1267
- const cleanedImports = clearImports(matched.imports);
1268
- const namedImports = {};
1269
- const _matches = cleanedImports.match(/{([^}]*)}/)?.[1]?.split(",") || [];
1270
- for (const namedImport of _matches) {
1271
- const _match = namedImport.match(/^\s*(\S*) as (\S*)\s*$/);
1272
- const source = _match?.[1] || namedImport.trim();
1273
- const importName = _match?.[2] || source;
1274
- if (source && !TYPE_RE.test(source)) namedImports[source] = importName;
1275
- }
1276
- const { namespacedImport, defaultImport } = getImportNames(cleanedImports);
1277
- return {
1278
- ...matched,
1279
- defaultImport,
1280
- namespacedImport,
1281
- namedImports
1282
- };
1283
- }
1284
- function findExports(code) {
1285
- const declaredExports = matchAll(EXPORT_DECAL_RE, code, { type: "declaration" });
1286
- for (const declaredExport of declaredExports) {
1287
- if (/^export\s+(?:async\s+)?function/.test(declaredExport.code)) continue;
1288
- const extraNamesStr = declaredExport.extraNames;
1289
- if (extraNamesStr) {
1290
- const extraNames = matchAll(/({.*?})|(\[.*?])|(,\s*(?<name>\w+))/g, extraNamesStr, {}).map((m) => m.name).filter(Boolean);
1291
- declaredExport.names = [declaredExport.name, ...extraNames];
1292
- }
1293
- delete declaredExport.extraNames;
1294
- }
1295
- const namedExports = normalizeNamedExports(matchAll(EXPORT_NAMED_RE, code, { type: "named" }));
1296
- const destructuredExports = matchAll(EXPORT_NAMED_DESTRUCT, code, { type: "named" });
1297
- for (const namedExport of destructuredExports) {
1298
- namedExport.exports = namedExport.exports1 || namedExport.exports2;
1299
- namedExport.names = namedExport.exports.replace(/^\r?\n?/, "").split(/\s*,\s*/g).filter((name) => !TYPE_RE.test(name)).map((name) => name.replace(/^.*?\s*:\s*/, "").replace(/\s*=\s*.*$/, "").trim());
1300
- }
1301
- const defaultExport = matchAll(EXPORT_DEFAULT_RE, code, {
1302
- type: "default",
1303
- name: "default"
1304
- });
1305
- const defaultClassExports = matchAll(EXPORT_DEFAULT_CLASS_RE, code, { type: "declaration" });
1306
- const starExports = matchAll(EXPORT_STAR_RE, code, { type: "star" });
1307
- const exports = normalizeExports([
1308
- ...declaredExports,
1309
- ...namedExports,
1310
- ...destructuredExports,
1311
- ...defaultExport,
1312
- ...defaultClassExports,
1313
- ...starExports
1314
- ]);
1315
- if (exports.length === 0) return [];
1316
- const exportLocations = _tryGetLocations(code, "export");
1317
- if (exportLocations && exportLocations.length === 0) return [];
1318
- return _filterStatement(exportLocations, exports).filter((exp, index, exports2) => {
1319
- const nextExport = exports2[index + 1];
1320
- return !nextExport || exp.type !== nextExport.type || !exp.name || exp.name !== nextExport.name;
1321
- });
1322
- }
1323
- function findTypeExports(code) {
1324
- const declaredExports = matchAll(EXPORT_DECAL_TYPE_RE, code, { type: "declaration" });
1325
- const namedExports = normalizeNamedExports(matchAll(EXPORT_NAMED_TYPE_RE, code, { type: "named" }));
1326
- const exports = normalizeExports([...declaredExports, ...namedExports]);
1327
- if (exports.length === 0) return [];
1328
- const exportLocations = _tryGetLocations(code, "export");
1329
- if (exportLocations && exportLocations.length === 0) return [];
1330
- return _filterStatement(exportLocations, exports).filter((exp, index, exports2) => {
1331
- const nextExport = exports2[index + 1];
1332
- return !nextExport || exp.type !== nextExport.type || !exp.name || exp.name !== nextExport.name;
1333
- });
1334
- }
1335
- function normalizeExports(exports) {
1336
- for (const exp of exports) {
1337
- if (!exp.name && exp.names && exp.names.length === 1) exp.name = exp.names[0];
1338
- if (exp.name === "default" && exp.type !== "default") {
1339
- exp._type = exp.type;
1340
- exp.type = "default";
1341
- }
1342
- if (!exp.names && exp.name) exp.names = [exp.name];
1343
- if (exp.type === "declaration" && exp.declaration) exp.declarationType = exp.declaration.replace(/^declare\s*/, "");
1344
- }
1345
- return exports;
1346
- }
1347
- function normalizeNamedExports(namedExports) {
1348
- for (const namedExport of namedExports) namedExport.names = namedExport.exports.replace(/^\r?\n?/, "").split(/\s*,\s*/g).filter((name) => !TYPE_RE.test(name)).map((name) => name.replace(/^.*?\sas\s/, "").trim());
1349
- return namedExports;
1350
- }
1351
- async function resolveModuleExportNames(id, options) {
1352
- const url = await resolvePath(id, options);
1353
- const exports = findExports(await loadURL(url));
1354
- const exportNames = new Set(exports.flatMap((exp) => exp.names).filter(Boolean));
1355
- for (const exp of exports) {
1356
- if (exp.type !== "star" || !exp.specifier) continue;
1357
- const subExports = await resolveModuleExportNames(exp.specifier, {
1358
- ...options,
1359
- url
1360
- });
1361
- for (const subExport of subExports) exportNames.add(subExport);
1362
- }
1363
- return [...exportNames];
1364
- }
1365
- function _filterStatement(locations, statements) {
1366
- return statements.filter((exp) => {
1367
- return !locations || locations.some((location) => {
1368
- return exp.start <= location.start && exp.end >= location.end;
1369
- });
1370
- });
1371
- }
1372
- function _tryGetLocations(code, label) {
1373
- try {
1374
- return _getLocations(code, label);
1375
- } catch {}
1376
- }
1377
- function _getLocations(code, label) {
1378
- const tokens = tokenizer(code, {
1379
- ecmaVersion: "latest",
1380
- sourceType: "module",
1381
- allowHashBang: true,
1382
- allowAwaitOutsideFunction: true,
1383
- allowImportExportEverywhere: true
1384
- });
1385
- const locations = [];
1386
- for (const token of tokens) if (token.type.label === label) locations.push({
1387
- start: token.start,
1388
- end: token.end
1389
- });
1390
- return locations;
1391
- }
1392
- const ESM_RE = /(?:[\s;]|^)(?:import[\s\w*,{}]*from|import\s*["'*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
1393
- const CJS_RE = /(?:[\s;]|^)(?:module\.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
1394
- const COMMENT_RE = /\/\*.+?\*\/|\/\/.*(?=[nr])/g;
1395
- function hasESMSyntax(code, opts = {}) {
1396
- if (opts.stripComments) code = code.replace(COMMENT_RE, "");
1397
- return ESM_RE.test(code);
1398
- }
1399
- function hasCJSSyntax(code, opts = {}) {
1400
- if (opts.stripComments) code = code.replace(COMMENT_RE, "");
1401
- return CJS_RE.test(code);
1402
- }
1403
- function detectSyntax(code, opts = {}) {
1404
- if (opts.stripComments) code = code.replace(COMMENT_RE, "");
1405
- const hasESM = hasESMSyntax(code, {});
1406
- const hasCJS = hasCJSSyntax(code, {});
1407
- return {
1408
- hasESM,
1409
- hasCJS,
1410
- isMixed: hasESM && hasCJS
1411
- };
1412
- }
1413
-
1414
- //#endregion
1415
- export { lookupNodeModuleSubpath as a, resolve$1 as c, resolvePathSync as d, findTypeExports as i, resolveModuleExportNames as l, findExports as n, parseNodeModulePath as o, findStaticImports as r, parseStaticImport as s, detectSyntax as t, resolvePath as u };