nitro-nightly 3.0.1-20260106-182834-5019d347 → 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.
- package/dist/_build/common.mjs +24899 -0
- package/dist/_build/rolldown.mjs +5 -18
- package/dist/_build/rollup.mjs +5 -52
- package/dist/_build/vite.build.mjs +2 -21
- package/dist/{_dev.mjs → _chunks/dev.mjs} +4 -7
- package/dist/{_nitro.mjs → _chunks/nitro.mjs} +16 -195
- package/dist/_chunks/nitro2.mjs +101 -0
- package/dist/_chunks/utils.mjs +278 -0
- package/dist/_libs/@hiogawa/vite-plugin-fullstack.mjs +32 -4
- package/dist/_libs/@jridgewell/gen-mapping.mjs +304 -2
- package/dist/_libs/@jridgewell/remapping.mjs +1 -2
- package/dist/_libs/@rollup/plugin-commonjs.mjs +75 -31
- package/dist/_libs/@rollup/plugin-inject.mjs +1 -3
- package/dist/_libs/@rollup/plugin-json.mjs +1 -1
- package/dist/_libs/@rollup/plugin-node-resolve.mjs +1111 -7
- package/dist/_libs/c12.mjs +597 -41
- package/dist/_libs/chokidar.mjs +235 -2
- package/dist/_libs/confbox.mjs +454 -1476
- package/dist/_libs/estree-walker.mjs +1 -144
- package/dist/_libs/giget.mjs +2235 -1377
- package/dist/_libs/httpxy.mjs +1 -1
- package/dist/_libs/unimport.mjs +1547 -1772
- package/dist/_presets.mjs +3 -9
- package/dist/builder.mjs +7 -12
- package/dist/cli/_chunks/build.mjs +1 -1
- package/dist/cli/_chunks/dev.mjs +3 -5
- package/dist/cli/_chunks/list.mjs +1 -1
- package/dist/cli/_chunks/prepare.mjs +1 -1
- package/dist/cli/_chunks/run.mjs +1 -1
- package/dist/types/index.d.mts +4 -4
- package/dist/vite.mjs +14 -1128
- package/package.json +2 -2
- package/dist/_build/shared.mjs +0 -60
- package/dist/_build/shared2.mjs +0 -40
- package/dist/_build/shared3.mjs +0 -68
- package/dist/_libs/@jridgewell/resolve-uri.mjs +0 -166
- package/dist/_libs/@jridgewell/sourcemap-codec.mjs +0 -167
- package/dist/_libs/@jridgewell/trace-mapping.mjs +0 -141
- package/dist/_libs/@rolldown/pluginutils.mjs +0 -31
- package/dist/_libs/@rollup/plugin-replace.mjs +0 -104
- package/dist/_libs/@rollup/pluginutils.mjs +0 -241
- package/dist/_libs/acorn.mjs +0 -5034
- package/dist/_libs/commondir.mjs +0 -22
- package/dist/_libs/deepmerge.mjs +0 -86
- package/dist/_libs/dot-prop.mjs +0 -138
- package/dist/_libs/dotenv.mjs +0 -345
- package/dist/_libs/duplexer.mjs +0 -71
- package/dist/_libs/etag.mjs +0 -80
- package/dist/_libs/exsolve.mjs +0 -1007
- package/dist/_libs/fdir.mjs +0 -514
- package/dist/_libs/function-bind.mjs +0 -63
- package/dist/_libs/gzip-size.mjs +0 -21
- package/dist/_libs/hasown.mjs +0 -14
- package/dist/_libs/is-core-module.mjs +0 -220
- package/dist/_libs/is-module.mjs +0 -13
- package/dist/_libs/is-reference.mjs +0 -33
- package/dist/_libs/js-tokens.mjs +0 -382
- package/dist/_libs/knitwork.mjs +0 -124
- package/dist/_libs/local-pkg.mjs +0 -125
- package/dist/_libs/magic-string.mjs +0 -939
- package/dist/_libs/mime.mjs +0 -1391
- package/dist/_libs/mlly.mjs +0 -1415
- package/dist/_libs/node-fetch-native.mjs +0 -7
- package/dist/_libs/nypm.mjs +0 -239
- package/dist/_libs/path-parse.mjs +0 -47
- package/dist/_libs/pathe.mjs +0 -202
- package/dist/_libs/perfect-debounce.mjs +0 -89
- package/dist/_libs/picomatch.mjs +0 -1673
- package/dist/_libs/pkg-types.mjs +0 -197
- package/dist/_libs/pretty-bytes.mjs +0 -116
- package/dist/_libs/quansync.mjs +0 -90
- package/dist/_libs/rc9.mjs +0 -136
- package/dist/_libs/readdirp.mjs +0 -237
- package/dist/_libs/resolve.mjs +0 -689
- package/dist/_libs/std-env.mjs +0 -158
- package/dist/_libs/strip-literal.mjs +0 -51
- package/dist/_libs/tinyexec.mjs +0 -627
- package/dist/_libs/tinyglobby.mjs +0 -292
- package/dist/_libs/unplugin-utils.mjs +0 -61
- package/dist/_libs/unplugin.mjs +0 -1225
- package/dist/_libs/untyped.mjs +0 -271
- package/dist/_libs/unwasm.mjs +0 -5895
- package/dist/_libs/webpack-virtual-modules.mjs +0 -272
- package/dist/_nitro2.mjs +0 -303
- /package/dist/{_rolldown.mjs → _common.mjs} +0 -0
package/dist/_libs/exsolve.mjs
DELETED
|
@@ -1,1007 +0,0 @@
|
|
|
1
|
-
import fs, { lstatSync, realpathSync, statSync } from "node:fs";
|
|
2
|
-
import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
-
import path, { isAbsolute } from "node:path";
|
|
4
|
-
import assert from "node:assert";
|
|
5
|
-
import process$1 from "node:process";
|
|
6
|
-
import v8 from "node:v8";
|
|
7
|
-
import { format, inspect } from "node:util";
|
|
8
|
-
|
|
9
|
-
//#region node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs
|
|
10
|
-
const nodeBuiltins = [
|
|
11
|
-
"_http_agent",
|
|
12
|
-
"_http_client",
|
|
13
|
-
"_http_common",
|
|
14
|
-
"_http_incoming",
|
|
15
|
-
"_http_outgoing",
|
|
16
|
-
"_http_server",
|
|
17
|
-
"_stream_duplex",
|
|
18
|
-
"_stream_passthrough",
|
|
19
|
-
"_stream_readable",
|
|
20
|
-
"_stream_transform",
|
|
21
|
-
"_stream_wrap",
|
|
22
|
-
"_stream_writable",
|
|
23
|
-
"_tls_common",
|
|
24
|
-
"_tls_wrap",
|
|
25
|
-
"assert",
|
|
26
|
-
"assert/strict",
|
|
27
|
-
"async_hooks",
|
|
28
|
-
"buffer",
|
|
29
|
-
"child_process",
|
|
30
|
-
"cluster",
|
|
31
|
-
"console",
|
|
32
|
-
"constants",
|
|
33
|
-
"crypto",
|
|
34
|
-
"dgram",
|
|
35
|
-
"diagnostics_channel",
|
|
36
|
-
"dns",
|
|
37
|
-
"dns/promises",
|
|
38
|
-
"domain",
|
|
39
|
-
"events",
|
|
40
|
-
"fs",
|
|
41
|
-
"fs/promises",
|
|
42
|
-
"http",
|
|
43
|
-
"http2",
|
|
44
|
-
"https",
|
|
45
|
-
"inspector",
|
|
46
|
-
"inspector/promises",
|
|
47
|
-
"module",
|
|
48
|
-
"net",
|
|
49
|
-
"os",
|
|
50
|
-
"path",
|
|
51
|
-
"path/posix",
|
|
52
|
-
"path/win32",
|
|
53
|
-
"perf_hooks",
|
|
54
|
-
"process",
|
|
55
|
-
"punycode",
|
|
56
|
-
"querystring",
|
|
57
|
-
"readline",
|
|
58
|
-
"readline/promises",
|
|
59
|
-
"repl",
|
|
60
|
-
"stream",
|
|
61
|
-
"stream/consumers",
|
|
62
|
-
"stream/promises",
|
|
63
|
-
"stream/web",
|
|
64
|
-
"string_decoder",
|
|
65
|
-
"sys",
|
|
66
|
-
"timers",
|
|
67
|
-
"timers/promises",
|
|
68
|
-
"tls",
|
|
69
|
-
"trace_events",
|
|
70
|
-
"tty",
|
|
71
|
-
"url",
|
|
72
|
-
"util",
|
|
73
|
-
"util/types",
|
|
74
|
-
"v8",
|
|
75
|
-
"vm",
|
|
76
|
-
"wasi",
|
|
77
|
-
"worker_threads",
|
|
78
|
-
"zlib"
|
|
79
|
-
];
|
|
80
|
-
const own$1 = {}.hasOwnProperty;
|
|
81
|
-
const classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
82
|
-
const kTypes = new Set([
|
|
83
|
-
"string",
|
|
84
|
-
"function",
|
|
85
|
-
"number",
|
|
86
|
-
"object",
|
|
87
|
-
"Function",
|
|
88
|
-
"Object",
|
|
89
|
-
"boolean",
|
|
90
|
-
"bigint",
|
|
91
|
-
"symbol"
|
|
92
|
-
]);
|
|
93
|
-
const messages = /* @__PURE__ */ new Map();
|
|
94
|
-
const nodeInternalPrefix = "__node_internal_";
|
|
95
|
-
let userStackTraceLimit;
|
|
96
|
-
/**
|
|
97
|
-
* Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
|
|
98
|
-
* We cannot use Intl.ListFormat because it's not available in
|
|
99
|
-
* --without-intl builds.
|
|
100
|
-
*
|
|
101
|
-
* @param {Array<string>} array
|
|
102
|
-
* An array of strings.
|
|
103
|
-
* @param {string} [type]
|
|
104
|
-
* The list type to be inserted before the last element.
|
|
105
|
-
* @returns {string}
|
|
106
|
-
*/
|
|
107
|
-
function formatList(array, type = "and") {
|
|
108
|
-
return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array.at(-1)}`;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Utility function for registering the error codes.
|
|
112
|
-
*/
|
|
113
|
-
function createError(sym, value, constructor) {
|
|
114
|
-
messages.set(sym, value);
|
|
115
|
-
return makeNodeErrorWithCode(constructor, sym);
|
|
116
|
-
}
|
|
117
|
-
function makeNodeErrorWithCode(Base, key) {
|
|
118
|
-
return function NodeError(...parameters) {
|
|
119
|
-
const limit = Error.stackTraceLimit;
|
|
120
|
-
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
121
|
-
const error = new Base();
|
|
122
|
-
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
123
|
-
const message = getMessage(key, parameters, error);
|
|
124
|
-
Object.defineProperties(error, {
|
|
125
|
-
message: {
|
|
126
|
-
value: message,
|
|
127
|
-
enumerable: false,
|
|
128
|
-
writable: true,
|
|
129
|
-
configurable: true
|
|
130
|
-
},
|
|
131
|
-
toString: {
|
|
132
|
-
value() {
|
|
133
|
-
return `${this.name} [${key}]: ${this.message}`;
|
|
134
|
-
},
|
|
135
|
-
enumerable: false,
|
|
136
|
-
writable: true,
|
|
137
|
-
configurable: true
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
captureLargerStackTrace(error);
|
|
141
|
-
error.code = key;
|
|
142
|
-
return error;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function isErrorStackTraceLimitWritable() {
|
|
146
|
-
try {
|
|
147
|
-
if (v8.startupSnapshot.isBuildingSnapshot()) return false;
|
|
148
|
-
} catch {}
|
|
149
|
-
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
150
|
-
if (desc === void 0) return Object.isExtensible(Error);
|
|
151
|
-
return own$1.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* This function removes unnecessary frames from Node.js core errors.
|
|
155
|
-
*/
|
|
156
|
-
function hideStackFrames(wrappedFunction) {
|
|
157
|
-
const hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
158
|
-
Object.defineProperty(wrappedFunction, "name", { value: hidden });
|
|
159
|
-
return wrappedFunction;
|
|
160
|
-
}
|
|
161
|
-
const captureLargerStackTrace = hideStackFrames(function(error) {
|
|
162
|
-
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
163
|
-
if (stackTraceLimitIsWritable) {
|
|
164
|
-
userStackTraceLimit = Error.stackTraceLimit;
|
|
165
|
-
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
166
|
-
}
|
|
167
|
-
Error.captureStackTrace(error);
|
|
168
|
-
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
169
|
-
return error;
|
|
170
|
-
});
|
|
171
|
-
function getMessage(key, parameters, self) {
|
|
172
|
-
const message = messages.get(key);
|
|
173
|
-
assert.ok(message !== void 0, "expected `message` to be found");
|
|
174
|
-
if (typeof message === "function") {
|
|
175
|
-
assert.ok(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`);
|
|
176
|
-
return Reflect.apply(message, self, parameters);
|
|
177
|
-
}
|
|
178
|
-
const regex = /%[dfijoOs]/g;
|
|
179
|
-
let expectedLength = 0;
|
|
180
|
-
while (regex.exec(message) !== null) expectedLength++;
|
|
181
|
-
assert.ok(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`);
|
|
182
|
-
if (parameters.length === 0) return message;
|
|
183
|
-
parameters.unshift(message);
|
|
184
|
-
return Reflect.apply(format, null, parameters);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Determine the specific type of a value for type-mismatch errors.
|
|
188
|
-
*/
|
|
189
|
-
function determineSpecificType(value) {
|
|
190
|
-
if (value === null || value === void 0) return String(value);
|
|
191
|
-
if (typeof value === "function" && value.name) return `function ${value.name}`;
|
|
192
|
-
if (typeof value === "object") {
|
|
193
|
-
if (value.constructor && value.constructor.name) return `an instance of ${value.constructor.name}`;
|
|
194
|
-
return `${inspect(value, { depth: -1 })}`;
|
|
195
|
-
}
|
|
196
|
-
let inspected = inspect(value, { colors: false });
|
|
197
|
-
if (inspected.length > 28) inspected = `${inspected.slice(0, 25)}...`;
|
|
198
|
-
return `type ${typeof value} (${inspected})`;
|
|
199
|
-
}
|
|
200
|
-
createError("ERR_INVALID_ARG_TYPE", (name, expected, actual) => {
|
|
201
|
-
assert.ok(typeof name === "string", "'name' must be a string");
|
|
202
|
-
if (!Array.isArray(expected)) expected = [expected];
|
|
203
|
-
let message = "The ";
|
|
204
|
-
if (name.endsWith(" argument")) message += `${name} `;
|
|
205
|
-
else {
|
|
206
|
-
const type = name.includes(".") ? "property" : "argument";
|
|
207
|
-
message += `"${name}" ${type} `;
|
|
208
|
-
}
|
|
209
|
-
message += "must be ";
|
|
210
|
-
const types = [];
|
|
211
|
-
const instances = [];
|
|
212
|
-
const other = [];
|
|
213
|
-
for (const value of expected) {
|
|
214
|
-
assert.ok(typeof value === "string", "All expected entries have to be of type string");
|
|
215
|
-
if (kTypes.has(value)) types.push(value.toLowerCase());
|
|
216
|
-
else if (classRegExp.exec(value) === null) {
|
|
217
|
-
assert.ok(value !== "object", "The value \"object\" should be written as \"Object\"");
|
|
218
|
-
other.push(value);
|
|
219
|
-
} else instances.push(value);
|
|
220
|
-
}
|
|
221
|
-
if (instances.length > 0) {
|
|
222
|
-
const pos = types.indexOf("object");
|
|
223
|
-
if (pos !== -1) {
|
|
224
|
-
types.slice(pos, 1);
|
|
225
|
-
instances.push("Object");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (types.length > 0) {
|
|
229
|
-
message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(types, "or")}`;
|
|
230
|
-
if (instances.length > 0 || other.length > 0) message += " or ";
|
|
231
|
-
}
|
|
232
|
-
if (instances.length > 0) {
|
|
233
|
-
message += `an instance of ${formatList(instances, "or")}`;
|
|
234
|
-
if (other.length > 0) message += " or ";
|
|
235
|
-
}
|
|
236
|
-
if (other.length > 0) if (other.length > 1) message += `one of ${formatList(other, "or")}`;
|
|
237
|
-
else {
|
|
238
|
-
if (other[0]?.toLowerCase() !== other[0]) message += "an ";
|
|
239
|
-
message += `${other[0]}`;
|
|
240
|
-
}
|
|
241
|
-
message += `. Received ${determineSpecificType(actual)}`;
|
|
242
|
-
return message;
|
|
243
|
-
}, TypeError);
|
|
244
|
-
const ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
245
|
-
"ERR_INVALID_MODULE_SPECIFIER",
|
|
246
|
-
/**
|
|
247
|
-
* @param {string} request
|
|
248
|
-
* @param {string} reason
|
|
249
|
-
* @param {string} [base]
|
|
250
|
-
*/
|
|
251
|
-
(request, reason, base) => {
|
|
252
|
-
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
|
|
253
|
-
},
|
|
254
|
-
TypeError
|
|
255
|
-
);
|
|
256
|
-
const ERR_INVALID_PACKAGE_CONFIG = createError("ERR_INVALID_PACKAGE_CONFIG", (path$1, base, message) => {
|
|
257
|
-
return `Invalid package config ${path$1}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
258
|
-
}, Error);
|
|
259
|
-
const ERR_INVALID_PACKAGE_TARGET = createError("ERR_INVALID_PACKAGE_TARGET", (packagePath, key, target, isImport = false, base) => {
|
|
260
|
-
const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
261
|
-
if (key === ".") {
|
|
262
|
-
assert.ok(isImport === false);
|
|
263
|
-
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 \"./\"" : ""}`;
|
|
264
|
-
}
|
|
265
|
-
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 \"./\"" : ""}`;
|
|
266
|
-
}, Error);
|
|
267
|
-
const ERR_MODULE_NOT_FOUND = createError("ERR_MODULE_NOT_FOUND", (path$1, base, exactUrl = false) => {
|
|
268
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${path$1}' imported from ${base}`;
|
|
269
|
-
}, Error);
|
|
270
|
-
createError("ERR_NETWORK_IMPORT_DISALLOWED", "import of '%s' by %s is not supported: %s", Error);
|
|
271
|
-
const ERR_PACKAGE_IMPORT_NOT_DEFINED = createError("ERR_PACKAGE_IMPORT_NOT_DEFINED", (specifier, packagePath, base) => {
|
|
272
|
-
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath || ""}package.json` : ""} imported from ${base}`;
|
|
273
|
-
}, TypeError);
|
|
274
|
-
const ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
275
|
-
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
276
|
-
/**
|
|
277
|
-
* @param {string} packagePath
|
|
278
|
-
* @param {string} subpath
|
|
279
|
-
* @param {string} [base]
|
|
280
|
-
*/
|
|
281
|
-
(packagePath, subpath, base) => {
|
|
282
|
-
if (subpath === ".") return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
283
|
-
return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
284
|
-
},
|
|
285
|
-
Error
|
|
286
|
-
);
|
|
287
|
-
const ERR_UNSUPPORTED_DIR_IMPORT = createError("ERR_UNSUPPORTED_DIR_IMPORT", "Directory import '%s' is not supported resolving ES modules imported from %s", Error);
|
|
288
|
-
const 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);
|
|
289
|
-
const ERR_UNKNOWN_FILE_EXTENSION = createError("ERR_UNKNOWN_FILE_EXTENSION", (extension, path$1) => {
|
|
290
|
-
return `Unknown file extension "${extension}" for ${path$1}`;
|
|
291
|
-
}, TypeError);
|
|
292
|
-
createError("ERR_INVALID_ARG_VALUE", (name, value, reason = "is invalid") => {
|
|
293
|
-
let inspected = inspect(value);
|
|
294
|
-
if (inspected.length > 128) inspected = `${inspected.slice(0, 128)}...`;
|
|
295
|
-
return `The ${name.includes(".") ? "property" : "argument"} '${name}' ${reason}. Received ${inspected}`;
|
|
296
|
-
}, TypeError);
|
|
297
|
-
const hasOwnProperty$1 = {}.hasOwnProperty;
|
|
298
|
-
const cache = /* @__PURE__ */ new Map();
|
|
299
|
-
function read(jsonPath, { base, specifier }) {
|
|
300
|
-
const existing = cache.get(jsonPath);
|
|
301
|
-
if (existing) return existing;
|
|
302
|
-
let string;
|
|
303
|
-
try {
|
|
304
|
-
string = fs.readFileSync(path.toNamespacedPath(jsonPath), "utf8");
|
|
305
|
-
} catch (error) {
|
|
306
|
-
const exception = error;
|
|
307
|
-
if (exception.code !== "ENOENT") throw exception;
|
|
308
|
-
}
|
|
309
|
-
const result = {
|
|
310
|
-
exists: false,
|
|
311
|
-
pjsonPath: jsonPath,
|
|
312
|
-
main: void 0,
|
|
313
|
-
name: void 0,
|
|
314
|
-
type: "none",
|
|
315
|
-
exports: void 0,
|
|
316
|
-
imports: void 0
|
|
317
|
-
};
|
|
318
|
-
if (string !== void 0) {
|
|
319
|
-
let parsed;
|
|
320
|
-
try {
|
|
321
|
-
parsed = JSON.parse(string);
|
|
322
|
-
} catch (error_) {
|
|
323
|
-
const error = new ERR_INVALID_PACKAGE_CONFIG(jsonPath, (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier), error_.message);
|
|
324
|
-
error.cause = error_;
|
|
325
|
-
throw error;
|
|
326
|
-
}
|
|
327
|
-
result.exists = true;
|
|
328
|
-
if (hasOwnProperty$1.call(parsed, "name") && typeof parsed.name === "string") result.name = parsed.name;
|
|
329
|
-
if (hasOwnProperty$1.call(parsed, "main") && typeof parsed.main === "string") result.main = parsed.main;
|
|
330
|
-
if (hasOwnProperty$1.call(parsed, "exports")) result.exports = parsed.exports;
|
|
331
|
-
if (hasOwnProperty$1.call(parsed, "imports")) result.imports = parsed.imports;
|
|
332
|
-
if (hasOwnProperty$1.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) result.type = parsed.type;
|
|
333
|
-
}
|
|
334
|
-
cache.set(jsonPath, result);
|
|
335
|
-
return result;
|
|
336
|
-
}
|
|
337
|
-
function getPackageScopeConfig(resolved) {
|
|
338
|
-
let packageJSONUrl = new URL("package.json", resolved);
|
|
339
|
-
while (true) {
|
|
340
|
-
if (packageJSONUrl.pathname.endsWith("node_modules/package.json")) break;
|
|
341
|
-
const packageConfig = read(fileURLToPath(packageJSONUrl), { specifier: resolved });
|
|
342
|
-
if (packageConfig.exists) return packageConfig;
|
|
343
|
-
const lastPackageJSONUrl = packageJSONUrl;
|
|
344
|
-
packageJSONUrl = new URL("../package.json", packageJSONUrl);
|
|
345
|
-
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) break;
|
|
346
|
-
}
|
|
347
|
-
return {
|
|
348
|
-
pjsonPath: fileURLToPath(packageJSONUrl),
|
|
349
|
-
exists: false,
|
|
350
|
-
type: "none"
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
const hasOwnProperty = {}.hasOwnProperty;
|
|
354
|
-
const extensionFormatMap = {
|
|
355
|
-
__proto__: null,
|
|
356
|
-
".json": "json",
|
|
357
|
-
".cjs": "commonjs",
|
|
358
|
-
".cts": "commonjs",
|
|
359
|
-
".js": "module",
|
|
360
|
-
".ts": "module",
|
|
361
|
-
".mts": "module",
|
|
362
|
-
".mjs": "module"
|
|
363
|
-
};
|
|
364
|
-
const protocolHandlers = {
|
|
365
|
-
__proto__: null,
|
|
366
|
-
"data:": getDataProtocolModuleFormat,
|
|
367
|
-
"file:": getFileProtocolModuleFormat,
|
|
368
|
-
"node:": () => "builtin"
|
|
369
|
-
};
|
|
370
|
-
function mimeToFormat(mime) {
|
|
371
|
-
if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return "module";
|
|
372
|
-
if (mime === "application/json") return "json";
|
|
373
|
-
return null;
|
|
374
|
-
}
|
|
375
|
-
function getDataProtocolModuleFormat(parsed) {
|
|
376
|
-
const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
|
|
377
|
-
null,
|
|
378
|
-
null,
|
|
379
|
-
null
|
|
380
|
-
];
|
|
381
|
-
return mimeToFormat(mime);
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Returns the file extension from a URL.
|
|
385
|
-
*
|
|
386
|
-
* Should give similar result to
|
|
387
|
-
* `require('node:path').extname(require('node:url').fileURLToPath(url))`
|
|
388
|
-
* when used with a `file:` URL.
|
|
389
|
-
*
|
|
390
|
-
*/
|
|
391
|
-
function extname$1(url) {
|
|
392
|
-
const pathname = url.pathname;
|
|
393
|
-
let index = pathname.length;
|
|
394
|
-
while (index--) {
|
|
395
|
-
const code = pathname.codePointAt(index);
|
|
396
|
-
if (code === 47) return "";
|
|
397
|
-
if (code === 46) return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
|
|
398
|
-
}
|
|
399
|
-
return "";
|
|
400
|
-
}
|
|
401
|
-
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
402
|
-
const ext = extname$1(url);
|
|
403
|
-
if (ext === ".js") {
|
|
404
|
-
const { type: packageType } = getPackageScopeConfig(url);
|
|
405
|
-
if (packageType !== "none") return packageType;
|
|
406
|
-
return "commonjs";
|
|
407
|
-
}
|
|
408
|
-
if (ext === "") {
|
|
409
|
-
const { type: packageType } = getPackageScopeConfig(url);
|
|
410
|
-
if (packageType === "none" || packageType === "commonjs") return "commonjs";
|
|
411
|
-
return "module";
|
|
412
|
-
}
|
|
413
|
-
const format$1 = extensionFormatMap[ext];
|
|
414
|
-
if (format$1) return format$1;
|
|
415
|
-
if (ignoreErrors) return;
|
|
416
|
-
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, fileURLToPath(url));
|
|
417
|
-
}
|
|
418
|
-
function defaultGetFormatWithoutErrors(url, context) {
|
|
419
|
-
const protocol = url.protocol;
|
|
420
|
-
if (!hasOwnProperty.call(protocolHandlers, protocol)) return null;
|
|
421
|
-
return protocolHandlers[protocol](url, context, true) || null;
|
|
422
|
-
}
|
|
423
|
-
const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
424
|
-
const own = {}.hasOwnProperty;
|
|
425
|
-
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;
|
|
426
|
-
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;
|
|
427
|
-
const invalidPackageNameRegEx = /^\.|%|\\/;
|
|
428
|
-
const patternRegEx = /\*/g;
|
|
429
|
-
const encodedSeparatorRegEx = /%2f|%5c/i;
|
|
430
|
-
const emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
431
|
-
const doubleSlashRegEx = /[/\\]{2}/;
|
|
432
|
-
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
433
|
-
if (process$1.noDeprecation) return;
|
|
434
|
-
const pjsonPath = fileURLToPath(packageJsonUrl);
|
|
435
|
-
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
436
|
-
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");
|
|
437
|
-
}
|
|
438
|
-
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
439
|
-
if (process$1.noDeprecation) return;
|
|
440
|
-
if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module") return;
|
|
441
|
-
const urlPath = fileURLToPath(url.href);
|
|
442
|
-
const packagePath = fileURLToPath(new URL$1(".", packageJsonUrl));
|
|
443
|
-
const basePath = fileURLToPath(base);
|
|
444
|
-
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");
|
|
445
|
-
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");
|
|
446
|
-
}
|
|
447
|
-
function tryStatSync(path$1) {
|
|
448
|
-
try {
|
|
449
|
-
return statSync(path$1);
|
|
450
|
-
} catch {}
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Legacy CommonJS main resolution:
|
|
454
|
-
* 1. let M = pkg_url + (json main field)
|
|
455
|
-
* 2. TRY(M, M.js, M.json, M.node)
|
|
456
|
-
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
457
|
-
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
458
|
-
* 5. NOT_FOUND
|
|
459
|
-
*/
|
|
460
|
-
function fileExists(url) {
|
|
461
|
-
const stats = statSync(url, { throwIfNoEntry: false });
|
|
462
|
-
const isFile = stats ? stats.isFile() : void 0;
|
|
463
|
-
return isFile === null || isFile === void 0 ? false : isFile;
|
|
464
|
-
}
|
|
465
|
-
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
466
|
-
let guess;
|
|
467
|
-
if (packageConfig.main !== void 0) {
|
|
468
|
-
guess = new URL$1(packageConfig.main, packageJsonUrl);
|
|
469
|
-
if (fileExists(guess)) return guess;
|
|
470
|
-
const tries$1 = [
|
|
471
|
-
`./${packageConfig.main}.js`,
|
|
472
|
-
`./${packageConfig.main}.json`,
|
|
473
|
-
`./${packageConfig.main}.node`,
|
|
474
|
-
`./${packageConfig.main}/index.js`,
|
|
475
|
-
`./${packageConfig.main}/index.json`,
|
|
476
|
-
`./${packageConfig.main}/index.node`
|
|
477
|
-
];
|
|
478
|
-
let i$1 = -1;
|
|
479
|
-
while (++i$1 < tries$1.length) {
|
|
480
|
-
guess = new URL$1(tries$1[i$1], packageJsonUrl);
|
|
481
|
-
if (fileExists(guess)) break;
|
|
482
|
-
guess = void 0;
|
|
483
|
-
}
|
|
484
|
-
if (guess) {
|
|
485
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
486
|
-
return guess;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
const tries = [
|
|
490
|
-
"./index.js",
|
|
491
|
-
"./index.json",
|
|
492
|
-
"./index.node"
|
|
493
|
-
];
|
|
494
|
-
let i = -1;
|
|
495
|
-
while (++i < tries.length) {
|
|
496
|
-
guess = new URL$1(tries[i], packageJsonUrl);
|
|
497
|
-
if (fileExists(guess)) break;
|
|
498
|
-
guess = void 0;
|
|
499
|
-
}
|
|
500
|
-
if (guess) {
|
|
501
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
502
|
-
return guess;
|
|
503
|
-
}
|
|
504
|
-
throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL$1(".", packageJsonUrl)), fileURLToPath(base));
|
|
505
|
-
}
|
|
506
|
-
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
507
|
-
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, String.raw`must not include encoded "/" or "\" characters`, fileURLToPath(base));
|
|
508
|
-
let filePath;
|
|
509
|
-
try {
|
|
510
|
-
filePath = fileURLToPath(resolved);
|
|
511
|
-
} catch (error) {
|
|
512
|
-
Object.defineProperty(error, "input", { value: String(resolved) });
|
|
513
|
-
Object.defineProperty(error, "module", { value: String(base) });
|
|
514
|
-
throw error;
|
|
515
|
-
}
|
|
516
|
-
const stats = tryStatSync(filePath.endsWith("/") ? filePath.slice(-1) : filePath);
|
|
517
|
-
if (stats && stats.isDirectory()) {
|
|
518
|
-
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath(base));
|
|
519
|
-
error.url = String(resolved);
|
|
520
|
-
throw error;
|
|
521
|
-
}
|
|
522
|
-
if (!stats || !stats.isFile()) {
|
|
523
|
-
const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && fileURLToPath(base), true);
|
|
524
|
-
error.url = String(resolved);
|
|
525
|
-
throw error;
|
|
526
|
-
}
|
|
527
|
-
if (!preserveSymlinks) {
|
|
528
|
-
const real = realpathSync(filePath);
|
|
529
|
-
const { search, hash } = resolved;
|
|
530
|
-
resolved = pathToFileURL(real + (filePath.endsWith(path.sep) ? "/" : ""));
|
|
531
|
-
resolved.search = search;
|
|
532
|
-
resolved.hash = hash;
|
|
533
|
-
}
|
|
534
|
-
return resolved;
|
|
535
|
-
}
|
|
536
|
-
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
537
|
-
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && fileURLToPath(new URL$1(".", packageJsonUrl)), fileURLToPath(base));
|
|
538
|
-
}
|
|
539
|
-
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
540
|
-
return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL$1(".", packageJsonUrl)), subpath, base && fileURLToPath(base));
|
|
541
|
-
}
|
|
542
|
-
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
543
|
-
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));
|
|
544
|
-
}
|
|
545
|
-
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
546
|
-
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
547
|
-
return new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL$1(".", packageJsonUrl)), subpath, target, internal, base && fileURLToPath(base));
|
|
548
|
-
}
|
|
549
|
-
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
550
|
-
if (subpath !== "" && !pattern && target.at(-1) !== "/") throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
551
|
-
if (!target.startsWith("./")) {
|
|
552
|
-
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
553
|
-
let isURL = false;
|
|
554
|
-
try {
|
|
555
|
-
new URL$1(target);
|
|
556
|
-
isURL = true;
|
|
557
|
-
} catch {}
|
|
558
|
-
if (!isURL) return packageResolve(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath, packageJsonUrl, conditions);
|
|
559
|
-
}
|
|
560
|
-
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
561
|
-
}
|
|
562
|
-
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
563
|
-
if (!isPathMap) {
|
|
564
|
-
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
565
|
-
emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, true);
|
|
566
|
-
}
|
|
567
|
-
} else throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
568
|
-
const resolved = new URL$1(target, packageJsonUrl);
|
|
569
|
-
const resolvedPath = resolved.pathname;
|
|
570
|
-
const packagePath = new URL$1(".", packageJsonUrl).pathname;
|
|
571
|
-
if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
572
|
-
if (subpath === "") return resolved;
|
|
573
|
-
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
574
|
-
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
575
|
-
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
576
|
-
if (!isPathMap) emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, false);
|
|
577
|
-
} else throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
578
|
-
}
|
|
579
|
-
if (pattern) return new URL$1(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
|
|
580
|
-
return new URL$1(subpath, resolved);
|
|
581
|
-
}
|
|
582
|
-
function isArrayIndex(key) {
|
|
583
|
-
const keyNumber = Number(key);
|
|
584
|
-
if (`${keyNumber}` !== key) return false;
|
|
585
|
-
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
586
|
-
}
|
|
587
|
-
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
588
|
-
if (typeof target === "string") return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
|
|
589
|
-
if (Array.isArray(target)) {
|
|
590
|
-
const targetList = target;
|
|
591
|
-
if (targetList.length === 0) return null;
|
|
592
|
-
let lastException;
|
|
593
|
-
let i = -1;
|
|
594
|
-
while (++i < targetList.length) {
|
|
595
|
-
const targetItem = targetList[i];
|
|
596
|
-
let resolveResult;
|
|
597
|
-
try {
|
|
598
|
-
resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
599
|
-
} catch (error) {
|
|
600
|
-
const exception = error;
|
|
601
|
-
lastException = exception;
|
|
602
|
-
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
603
|
-
throw error;
|
|
604
|
-
}
|
|
605
|
-
if (resolveResult === void 0) continue;
|
|
606
|
-
if (resolveResult === null) {
|
|
607
|
-
lastException = null;
|
|
608
|
-
continue;
|
|
609
|
-
}
|
|
610
|
-
return resolveResult;
|
|
611
|
-
}
|
|
612
|
-
if (lastException === void 0 || lastException === null) return null;
|
|
613
|
-
throw lastException;
|
|
614
|
-
}
|
|
615
|
-
if (typeof target === "object" && target !== null) {
|
|
616
|
-
const keys = Object.getOwnPropertyNames(target);
|
|
617
|
-
let i = -1;
|
|
618
|
-
while (++i < keys.length) {
|
|
619
|
-
const key = keys[i];
|
|
620
|
-
if (isArrayIndex(key)) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), fileURLToPath(base), "\"exports\" cannot contain numeric property keys.");
|
|
621
|
-
}
|
|
622
|
-
i = -1;
|
|
623
|
-
while (++i < keys.length) {
|
|
624
|
-
const key = keys[i];
|
|
625
|
-
if (key === "default" || conditions && conditions.has(key)) {
|
|
626
|
-
const conditionalTarget = target[key];
|
|
627
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
628
|
-
if (resolveResult === void 0) continue;
|
|
629
|
-
return resolveResult;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
return null;
|
|
633
|
-
}
|
|
634
|
-
if (target === null) return null;
|
|
635
|
-
throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
|
|
636
|
-
}
|
|
637
|
-
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
638
|
-
if (typeof exports === "string" || Array.isArray(exports)) return true;
|
|
639
|
-
if (typeof exports !== "object" || exports === null) return false;
|
|
640
|
-
const keys = Object.getOwnPropertyNames(exports);
|
|
641
|
-
let isConditionalSugar = false;
|
|
642
|
-
let i = 0;
|
|
643
|
-
let keyIndex = -1;
|
|
644
|
-
while (++keyIndex < keys.length) {
|
|
645
|
-
const key = keys[keyIndex];
|
|
646
|
-
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
647
|
-
if (i++ === 0) isConditionalSugar = currentIsConditionalSugar;
|
|
648
|
-
else if (isConditionalSugar !== currentIsConditionalSugar) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), fileURLToPath(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.");
|
|
649
|
-
}
|
|
650
|
-
return isConditionalSugar;
|
|
651
|
-
}
|
|
652
|
-
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
653
|
-
if (process$1.noDeprecation) return;
|
|
654
|
-
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
655
|
-
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
656
|
-
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
657
|
-
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");
|
|
658
|
-
}
|
|
659
|
-
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
660
|
-
let exports = packageConfig.exports;
|
|
661
|
-
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) exports = { ".": exports };
|
|
662
|
-
if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
663
|
-
const target = exports[packageSubpath];
|
|
664
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, target, "", packageSubpath, base, false, false, false, conditions);
|
|
665
|
-
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
666
|
-
return resolveResult;
|
|
667
|
-
}
|
|
668
|
-
let bestMatch = "";
|
|
669
|
-
let bestMatchSubpath = "";
|
|
670
|
-
const keys = Object.getOwnPropertyNames(exports);
|
|
671
|
-
let i = -1;
|
|
672
|
-
while (++i < keys.length) {
|
|
673
|
-
const key = keys[i];
|
|
674
|
-
const patternIndex = key.indexOf("*");
|
|
675
|
-
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
676
|
-
if (packageSubpath.endsWith("/")) emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
|
|
677
|
-
const patternTrailer = key.slice(patternIndex + 1);
|
|
678
|
-
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
679
|
-
bestMatch = key;
|
|
680
|
-
bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
if (bestMatch) {
|
|
685
|
-
const target = exports[bestMatch];
|
|
686
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith("/"), conditions);
|
|
687
|
-
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
688
|
-
return resolveResult;
|
|
689
|
-
}
|
|
690
|
-
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
691
|
-
}
|
|
692
|
-
function patternKeyCompare(a, b) {
|
|
693
|
-
const aPatternIndex = a.indexOf("*");
|
|
694
|
-
const bPatternIndex = b.indexOf("*");
|
|
695
|
-
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
696
|
-
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
697
|
-
if (baseLengthA > baseLengthB) return -1;
|
|
698
|
-
if (baseLengthB > baseLengthA) return 1;
|
|
699
|
-
if (aPatternIndex === -1) return 1;
|
|
700
|
-
if (bPatternIndex === -1) return -1;
|
|
701
|
-
if (a.length > b.length) return -1;
|
|
702
|
-
if (b.length > a.length) return 1;
|
|
703
|
-
return 0;
|
|
704
|
-
}
|
|
705
|
-
function packageImportsResolve(name, base, conditions) {
|
|
706
|
-
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) throw new ERR_INVALID_MODULE_SPECIFIER(name, "is not a valid internal imports specifier name", fileURLToPath(base));
|
|
707
|
-
let packageJsonUrl;
|
|
708
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
709
|
-
if (packageConfig.exists) {
|
|
710
|
-
packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
711
|
-
const imports = packageConfig.imports;
|
|
712
|
-
if (imports) if (own.call(imports, name) && !name.includes("*")) {
|
|
713
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], "", name, base, false, true, false, conditions);
|
|
714
|
-
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
715
|
-
} else {
|
|
716
|
-
let bestMatch = "";
|
|
717
|
-
let bestMatchSubpath = "";
|
|
718
|
-
const keys = Object.getOwnPropertyNames(imports);
|
|
719
|
-
let i = -1;
|
|
720
|
-
while (++i < keys.length) {
|
|
721
|
-
const key = keys[i];
|
|
722
|
-
const patternIndex = key.indexOf("*");
|
|
723
|
-
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
724
|
-
const patternTrailer = key.slice(patternIndex + 1);
|
|
725
|
-
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
726
|
-
bestMatch = key;
|
|
727
|
-
bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
if (bestMatch) {
|
|
732
|
-
const target = imports[bestMatch];
|
|
733
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
|
|
734
|
-
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
throw importNotDefined(name, packageJsonUrl, base);
|
|
739
|
-
}
|
|
740
|
-
/**
|
|
741
|
-
* @param {string} specifier
|
|
742
|
-
* @param {URL} base
|
|
743
|
-
*/
|
|
744
|
-
function parsePackageName(specifier, base) {
|
|
745
|
-
let separatorIndex = specifier.indexOf("/");
|
|
746
|
-
let validPackageName = true;
|
|
747
|
-
let isScoped = false;
|
|
748
|
-
if (specifier[0] === "@") {
|
|
749
|
-
isScoped = true;
|
|
750
|
-
if (separatorIndex === -1 || specifier.length === 0) validPackageName = false;
|
|
751
|
-
else separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
752
|
-
}
|
|
753
|
-
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
754
|
-
if (invalidPackageNameRegEx.exec(packageName) !== null) validPackageName = false;
|
|
755
|
-
if (!validPackageName) throw new ERR_INVALID_MODULE_SPECIFIER(specifier, "is not a valid package name", fileURLToPath(base));
|
|
756
|
-
return {
|
|
757
|
-
packageName,
|
|
758
|
-
packageSubpath: "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex)),
|
|
759
|
-
isScoped
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
function packageResolve(specifier, base, conditions) {
|
|
763
|
-
if (nodeBuiltins.includes(specifier)) return new URL$1("node:" + specifier);
|
|
764
|
-
const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
|
|
765
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
766
|
-
if (packageConfig.exists && packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(pathToFileURL(packageConfig.pjsonPath), packageSubpath, packageConfig, base, conditions);
|
|
767
|
-
let packageJsonUrl = new URL$1("./node_modules/" + packageName + "/package.json", base);
|
|
768
|
-
let packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
769
|
-
let lastPath;
|
|
770
|
-
do {
|
|
771
|
-
const stat$1 = tryStatSync(packageJsonPath.slice(0, -13));
|
|
772
|
-
if (!stat$1 || !stat$1.isDirectory()) {
|
|
773
|
-
lastPath = packageJsonPath;
|
|
774
|
-
packageJsonUrl = new URL$1((isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json", packageJsonUrl);
|
|
775
|
-
packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
776
|
-
continue;
|
|
777
|
-
}
|
|
778
|
-
const packageConfig$1 = read(packageJsonPath, {
|
|
779
|
-
base,
|
|
780
|
-
specifier
|
|
781
|
-
});
|
|
782
|
-
if (packageConfig$1.exports !== void 0 && packageConfig$1.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig$1, base, conditions);
|
|
783
|
-
if (packageSubpath === ".") return legacyMainResolve(packageJsonUrl, packageConfig$1, base);
|
|
784
|
-
return new URL$1(packageSubpath, packageJsonUrl);
|
|
785
|
-
} while (packageJsonPath.length !== lastPath.length);
|
|
786
|
-
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), false);
|
|
787
|
-
}
|
|
788
|
-
function isRelativeSpecifier(specifier) {
|
|
789
|
-
if (specifier[0] === ".") {
|
|
790
|
-
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
791
|
-
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) return true;
|
|
792
|
-
}
|
|
793
|
-
return false;
|
|
794
|
-
}
|
|
795
|
-
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
796
|
-
if (specifier === "") return false;
|
|
797
|
-
if (specifier[0] === "/") return true;
|
|
798
|
-
return isRelativeSpecifier(specifier);
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
802
|
-
* sync and slightly lower-level than `resolve`).
|
|
803
|
-
*
|
|
804
|
-
* @param {string} specifier
|
|
805
|
-
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
|
|
806
|
-
* @param {URL} base
|
|
807
|
-
* Full URL (to a file) that `specifier` is resolved relative from.
|
|
808
|
-
* @param {Set<string>} [conditions]
|
|
809
|
-
* Conditions.
|
|
810
|
-
* @param {boolean} [preserveSymlinks]
|
|
811
|
-
* Keep symlinks instead of resolving them.
|
|
812
|
-
* @returns {URL}
|
|
813
|
-
* A URL object to the found thing.
|
|
814
|
-
*/
|
|
815
|
-
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
816
|
-
const protocol = base.protocol;
|
|
817
|
-
const isData = protocol === "data:";
|
|
818
|
-
let resolved;
|
|
819
|
-
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) try {
|
|
820
|
-
resolved = new URL$1(specifier, base);
|
|
821
|
-
} catch (error_) {
|
|
822
|
-
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
823
|
-
error.cause = error_;
|
|
824
|
-
throw error;
|
|
825
|
-
}
|
|
826
|
-
else if (protocol === "file:" && specifier[0] === "#") resolved = packageImportsResolve(specifier, base, conditions);
|
|
827
|
-
else try {
|
|
828
|
-
resolved = new URL$1(specifier);
|
|
829
|
-
} catch (error_) {
|
|
830
|
-
if (isData && !nodeBuiltins.includes(specifier)) {
|
|
831
|
-
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
832
|
-
error.cause = error_;
|
|
833
|
-
throw error;
|
|
834
|
-
}
|
|
835
|
-
resolved = packageResolve(specifier, base, conditions);
|
|
836
|
-
}
|
|
837
|
-
assert.ok(resolved !== void 0, "expected to be defined");
|
|
838
|
-
if (resolved.protocol !== "file:") return resolved;
|
|
839
|
-
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
840
|
-
}
|
|
841
|
-
const DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
|
|
842
|
-
const isWindows = process.platform === "win32";
|
|
843
|
-
const globalCache = globalThis["__EXSOLVE_CACHE__"] ||= /* @__PURE__ */ new Map();
|
|
844
|
-
/**
|
|
845
|
-
* Synchronously resolves a module url based on the options provided.
|
|
846
|
-
*
|
|
847
|
-
* @param {string} input - The identifier or path of the module to resolve.
|
|
848
|
-
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
|
|
849
|
-
* @returns {string} The resolved URL as a string.
|
|
850
|
-
*/
|
|
851
|
-
function resolveModuleURL(input, options) {
|
|
852
|
-
const parsedInput = _parseInput(input);
|
|
853
|
-
if ("external" in parsedInput) return parsedInput.external;
|
|
854
|
-
const specifier = parsedInput.specifier;
|
|
855
|
-
let url = parsedInput.url;
|
|
856
|
-
let absolutePath = parsedInput.absolutePath;
|
|
857
|
-
let cacheKey;
|
|
858
|
-
let cacheObj;
|
|
859
|
-
if (options?.cache !== false) {
|
|
860
|
-
cacheKey = _cacheKey(absolutePath || specifier, options);
|
|
861
|
-
cacheObj = options?.cache && typeof options?.cache === "object" ? options.cache : globalCache;
|
|
862
|
-
}
|
|
863
|
-
if (cacheObj) {
|
|
864
|
-
const cached = cacheObj.get(cacheKey);
|
|
865
|
-
if (typeof cached === "string") return cached;
|
|
866
|
-
if (cached instanceof Error) {
|
|
867
|
-
if (options?.try) return;
|
|
868
|
-
throw cached;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
if (absolutePath) try {
|
|
872
|
-
const stat$1 = lstatSync(absolutePath);
|
|
873
|
-
if (stat$1.isSymbolicLink()) {
|
|
874
|
-
absolutePath = realpathSync(absolutePath);
|
|
875
|
-
url = pathToFileURL(absolutePath);
|
|
876
|
-
}
|
|
877
|
-
if (stat$1.isFile()) {
|
|
878
|
-
if (cacheObj) cacheObj.set(cacheKey, url.href);
|
|
879
|
-
return url.href;
|
|
880
|
-
}
|
|
881
|
-
} catch (error) {
|
|
882
|
-
if (error?.code !== "ENOENT") {
|
|
883
|
-
if (cacheObj) cacheObj.set(cacheKey, error);
|
|
884
|
-
throw error;
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
const conditionsSet = options?.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
|
|
888
|
-
const target = specifier || url.href;
|
|
889
|
-
const bases = _normalizeBases(options?.from);
|
|
890
|
-
const suffixes = options?.suffixes || [""];
|
|
891
|
-
const extensions = options?.extensions ? ["", ...options.extensions] : [""];
|
|
892
|
-
let resolved;
|
|
893
|
-
for (const base of bases) {
|
|
894
|
-
for (const suffix of suffixes) {
|
|
895
|
-
let name = _join(target, suffix);
|
|
896
|
-
if (name === ".") name += "/.";
|
|
897
|
-
for (const extension of extensions) {
|
|
898
|
-
resolved = _tryModuleResolve(name + extension, base, conditionsSet);
|
|
899
|
-
if (resolved) break;
|
|
900
|
-
}
|
|
901
|
-
if (resolved) break;
|
|
902
|
-
}
|
|
903
|
-
if (resolved) break;
|
|
904
|
-
}
|
|
905
|
-
if (!resolved) {
|
|
906
|
-
const error = /* @__PURE__ */ new Error(`Cannot resolve module "${input}" (from: ${bases.map((u) => _fmtPath(u)).join(", ")})`);
|
|
907
|
-
error.code = "ERR_MODULE_NOT_FOUND";
|
|
908
|
-
if (cacheObj) cacheObj.set(cacheKey, error);
|
|
909
|
-
if (options?.try) return;
|
|
910
|
-
throw error;
|
|
911
|
-
}
|
|
912
|
-
if (cacheObj) cacheObj.set(cacheKey, resolved.href);
|
|
913
|
-
return resolved.href;
|
|
914
|
-
}
|
|
915
|
-
/**
|
|
916
|
-
* Synchronously resolves a module then converts it to a file path
|
|
917
|
-
*
|
|
918
|
-
* (throws error if reolved path is not file:// scheme)
|
|
919
|
-
*
|
|
920
|
-
* @param {string} id - The identifier or path of the module to resolve.
|
|
921
|
-
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
|
|
922
|
-
* @returns {string} The resolved URL as a string.
|
|
923
|
-
*/
|
|
924
|
-
function resolveModulePath(id, options) {
|
|
925
|
-
const resolved = resolveModuleURL(id, options);
|
|
926
|
-
if (!resolved) return;
|
|
927
|
-
if (!resolved.startsWith("file://") && options?.try) return;
|
|
928
|
-
const absolutePath = fileURLToPath(resolved);
|
|
929
|
-
return isWindows ? _normalizeWinPath(absolutePath) : absolutePath;
|
|
930
|
-
}
|
|
931
|
-
function _tryModuleResolve(specifier, base, conditions) {
|
|
932
|
-
try {
|
|
933
|
-
return moduleResolve(specifier, base, conditions);
|
|
934
|
-
} catch {}
|
|
935
|
-
}
|
|
936
|
-
function _normalizeBases(inputs) {
|
|
937
|
-
const urls = (Array.isArray(inputs) ? inputs : [inputs]).flatMap((input) => _normalizeBase(input));
|
|
938
|
-
if (urls.length === 0) return [pathToFileURL("./")];
|
|
939
|
-
return urls;
|
|
940
|
-
}
|
|
941
|
-
function _normalizeBase(input) {
|
|
942
|
-
if (!input) return [];
|
|
943
|
-
if (_isURL(input)) return [input];
|
|
944
|
-
if (typeof input !== "string") return [];
|
|
945
|
-
if (/^(?:node|data|http|https|file):/.test(input)) return new URL(input);
|
|
946
|
-
try {
|
|
947
|
-
if (input.endsWith("/") || statSync(input).isDirectory()) return pathToFileURL(input + "/");
|
|
948
|
-
return pathToFileURL(input);
|
|
949
|
-
} catch {
|
|
950
|
-
return [pathToFileURL(input + "/"), pathToFileURL(input)];
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
function _fmtPath(input) {
|
|
954
|
-
try {
|
|
955
|
-
return fileURLToPath(input);
|
|
956
|
-
} catch {
|
|
957
|
-
return input;
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
function _cacheKey(id, opts) {
|
|
961
|
-
return JSON.stringify([
|
|
962
|
-
id,
|
|
963
|
-
(opts?.conditions || ["node", "import"]).sort(),
|
|
964
|
-
opts?.extensions,
|
|
965
|
-
opts?.from,
|
|
966
|
-
opts?.suffixes
|
|
967
|
-
]);
|
|
968
|
-
}
|
|
969
|
-
function _join(a, b) {
|
|
970
|
-
if (!a || !b || b === "/") return a;
|
|
971
|
-
return (a.endsWith("/") ? a : a + "/") + (b.startsWith("/") ? b.slice(1) : b);
|
|
972
|
-
}
|
|
973
|
-
function _normalizeWinPath(path$1) {
|
|
974
|
-
return path$1.replace(/\\/g, "/").replace(/^[a-z]:\//, (r) => r.toUpperCase());
|
|
975
|
-
}
|
|
976
|
-
function _isURL(input) {
|
|
977
|
-
return input instanceof URL || input?.constructor?.name === "URL";
|
|
978
|
-
}
|
|
979
|
-
function _parseInput(input) {
|
|
980
|
-
if (typeof input === "string") {
|
|
981
|
-
if (input.startsWith("file:")) {
|
|
982
|
-
const url = new URL(input);
|
|
983
|
-
return {
|
|
984
|
-
url,
|
|
985
|
-
absolutePath: fileURLToPath(url)
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
if (isAbsolute(input)) return {
|
|
989
|
-
url: pathToFileURL(input),
|
|
990
|
-
absolutePath: input
|
|
991
|
-
};
|
|
992
|
-
if (/^(?:node|data|http|https):/.test(input)) return { external: input };
|
|
993
|
-
if (nodeBuiltins.includes(input) && !input.includes(":")) return { external: `node:${input}` };
|
|
994
|
-
return { specifier: input };
|
|
995
|
-
}
|
|
996
|
-
if (_isURL(input)) {
|
|
997
|
-
if (input.protocol === "file:") return {
|
|
998
|
-
url: input,
|
|
999
|
-
absolutePath: fileURLToPath(input)
|
|
1000
|
-
};
|
|
1001
|
-
return { external: input.href };
|
|
1002
|
-
}
|
|
1003
|
-
throw new TypeError("id must be a `string` or `URL`");
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
//#endregion
|
|
1007
|
-
export { resolveModuleURL as n, resolveModulePath as t };
|