@powerlines/plugin-automd 0.1.341 → 0.1.342

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