muon-ui 0.20.0 → 0.22.0
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/README.md +27 -21
- package/dist/cli.cjs +29 -11
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/native/linux-amd64/muon-builder +0 -0
- package/dist/native/linux-amd64/muon-launcher +0 -0
- package/dist/native/linux-amd64/muon-plugin-inspector +0 -0
- package/dist/native/linux-amd64/muon-runtime-helper +0 -0
- package/dist/native/linux-arm64/muon-builder +0 -0
- package/dist/native/linux-arm64/muon-launcher +0 -0
- package/dist/native/linux-arm64/muon-plugin-inspector +0 -0
- package/dist/native/linux-arm64/muon-runtime-helper +0 -0
- package/dist/native/linux-armhf/muon-builder +0 -0
- package/dist/native/linux-armhf/muon-launcher +0 -0
- package/dist/native/linux-armhf/muon-plugin-inspector +0 -0
- package/dist/native/linux-armhf/muon-runtime-helper +0 -0
- package/dist/native/windows-amd64/muon-builder.exe +0 -0
- package/dist/native/windows-amd64/muon-launcher.exe +0 -0
- package/dist/native/windows-amd64/muon-plugin-inspector.exe +0 -0
- package/dist/native/windows-i686/muon-builder.exe +0 -0
- package/dist/native/windows-i686/muon-launcher.exe +0 -0
- package/dist/native/windows-i686/muon-plugin-inspector.exe +0 -0
- package/dist/runtime/linux-amd64/CREDITS.md +89 -0
- package/dist/runtime/linux-amd64/muon-core +0 -0
- package/dist/runtime/linux-amd64/muon-executor-supervisor +0 -0
- package/dist/runtime/linux-amd64/plugins/node-bridge.mjs +3013 -0
- package/dist/runtime/linux-amd64/plugins/node.so +0 -0
- package/dist/runtime/linux-arm64/CREDITS.md +89 -0
- package/dist/runtime/linux-arm64/muon-core +0 -0
- package/dist/runtime/linux-arm64/muon-executor-supervisor +0 -0
- package/dist/runtime/linux-arm64/plugins/node-bridge.mjs +3013 -0
- package/dist/runtime/linux-arm64/plugins/node.so +0 -0
- package/dist/runtime/linux-armhf/CREDITS.md +89 -0
- package/dist/runtime/linux-armhf/muon-core +0 -0
- package/dist/runtime/linux-armhf/muon-executor-supervisor +0 -0
- package/dist/runtime/linux-armhf/plugins/node-bridge.mjs +3013 -0
- package/dist/runtime/linux-armhf/plugins/node.so +0 -0
- package/dist/runtime/windows-amd64/CREDITS.md +89 -0
- package/dist/runtime/windows-amd64/libcardio.dll +0 -0
- package/dist/runtime/windows-amd64/libmuon-ui.dll +0 -0
- package/dist/runtime/windows-amd64/muon-core.exe +0 -0
- package/dist/runtime/windows-amd64/plugins/node-bridge.mjs +3013 -0
- package/dist/runtime/windows-amd64/plugins/node.dll +0 -0
- package/dist/runtime/windows-i686/CREDITS.md +89 -0
- package/dist/runtime/windows-i686/libcardio.dll +0 -0
- package/dist/runtime/windows-i686/libmuon-ui.dll +0 -0
- package/dist/runtime/windows-i686/muon-core.exe +0 -0
- package/dist/runtime/windows-i686/plugins/node-bridge.mjs +3013 -0
- package/dist/runtime/windows-i686/plugins/node.dll +0 -0
- package/dist/{vite-internals-DpXCyV08.cjs → vite-internals-BA4riWRd.cjs} +1259 -44
- package/dist/vite-internals-BA4riWRd.cjs.map +1 -0
- package/dist/vite.cjs +43 -14
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +1233 -47
- package/dist/vite.mjs.map +1 -1
- package/muon-virtual-modules.d.ts +10 -1
- package/muon.d.ts +163 -5
- package/package.json +9 -7
- package/vite.d.ts +1 -1
- package/dist/vite-internals-DpXCyV08.cjs.map +0 -1
|
@@ -0,0 +1,3013 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* name: muon-node
|
|
3
|
+
* version: 0.22.0
|
|
4
|
+
* description: Out-of-process Node.js bridge for muon.
|
|
5
|
+
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
|
+
* license: MIT
|
|
7
|
+
* repository.url: https://github.com/kekyo/muon-ui.git
|
|
8
|
+
* git.commit.hash: 5c8d38ea864ba1916f26e6beb6814a4af57479d7
|
|
9
|
+
*/
|
|
10
|
+
import { Socket, createConnection } from "node:net";
|
|
11
|
+
import { timingSafeEqual } from "node:crypto";
|
|
12
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
13
|
+
import { builtinModules, createRequire, isBuiltin } from "node:module";
|
|
14
|
+
import path, { dirname, extname, isAbsolute, join, parse, resolve, sep } from "node:path";
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
|
+
import assert from "node:assert";
|
|
17
|
+
import fs, { realpathSync, statSync } from "node:fs";
|
|
18
|
+
import process$1 from "node:process";
|
|
19
|
+
import v8 from "node:v8";
|
|
20
|
+
import { format, inspect } from "node:util";
|
|
21
|
+
//#region \0rolldown/runtime.js
|
|
22
|
+
var __create = Object.create;
|
|
23
|
+
var __defProp = Object.defineProperty;
|
|
24
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
25
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
26
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
27
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
28
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
31
|
+
key = keys[i];
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
33
|
+
get: ((k) => from[k]).bind(null, key),
|
|
34
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return to;
|
|
38
|
+
};
|
|
39
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
40
|
+
value: mod,
|
|
41
|
+
enumerable: true
|
|
42
|
+
}) : target, mod));
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../node_modules/import-meta-resolve/lib/errors.js
|
|
45
|
+
/**
|
|
46
|
+
* @typedef ErrnoExceptionFields
|
|
47
|
+
* @property {number | undefined} [errnode]
|
|
48
|
+
* @property {string | undefined} [code]
|
|
49
|
+
* @property {string | undefined} [path]
|
|
50
|
+
* @property {string | undefined} [syscall]
|
|
51
|
+
* @property {string | undefined} [url]
|
|
52
|
+
*
|
|
53
|
+
* @typedef {Error & ErrnoExceptionFields} ErrnoException
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {(...parameters: Array<any>) => string} MessageFunction
|
|
57
|
+
*/
|
|
58
|
+
var own$1 = {}.hasOwnProperty;
|
|
59
|
+
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
60
|
+
var kTypes = new Set([
|
|
61
|
+
"string",
|
|
62
|
+
"function",
|
|
63
|
+
"number",
|
|
64
|
+
"object",
|
|
65
|
+
"Function",
|
|
66
|
+
"Object",
|
|
67
|
+
"boolean",
|
|
68
|
+
"bigint",
|
|
69
|
+
"symbol"
|
|
70
|
+
]);
|
|
71
|
+
var codes = {};
|
|
72
|
+
/**
|
|
73
|
+
* Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
|
|
74
|
+
* We cannot use Intl.ListFormat because it's not available in
|
|
75
|
+
* --without-intl builds.
|
|
76
|
+
*
|
|
77
|
+
* @param {Array<string>} array
|
|
78
|
+
* An array of strings.
|
|
79
|
+
* @param {string} [type]
|
|
80
|
+
* The list type to be inserted before the last element.
|
|
81
|
+
* @returns {string}
|
|
82
|
+
*/
|
|
83
|
+
function formatList(array, type = "and") {
|
|
84
|
+
return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array[array.length - 1]}`;
|
|
85
|
+
}
|
|
86
|
+
/** @type {Map<string, MessageFunction | string>} */
|
|
87
|
+
var messages = /* @__PURE__ */ new Map();
|
|
88
|
+
var nodeInternalPrefix = "__node_internal_";
|
|
89
|
+
/** @type {number} */
|
|
90
|
+
var userStackTraceLimit;
|
|
91
|
+
codes.ERR_INVALID_ARG_TYPE = createError(
|
|
92
|
+
"ERR_INVALID_ARG_TYPE",
|
|
93
|
+
/**
|
|
94
|
+
* @param {string} name
|
|
95
|
+
* @param {Array<string> | string} expected
|
|
96
|
+
* @param {unknown} actual
|
|
97
|
+
*/
|
|
98
|
+
(name, expected, actual) => {
|
|
99
|
+
assert.ok(typeof name === "string", "'name' must be a string");
|
|
100
|
+
if (!Array.isArray(expected)) expected = [expected];
|
|
101
|
+
let message = "The ";
|
|
102
|
+
if (name.endsWith(" argument")) message += `${name} `;
|
|
103
|
+
else {
|
|
104
|
+
const type = name.includes(".") ? "property" : "argument";
|
|
105
|
+
message += `"${name}" ${type} `;
|
|
106
|
+
}
|
|
107
|
+
message += "must be ";
|
|
108
|
+
/** @type {Array<string>} */
|
|
109
|
+
const types = [];
|
|
110
|
+
/** @type {Array<string>} */
|
|
111
|
+
const instances = [];
|
|
112
|
+
/** @type {Array<string>} */
|
|
113
|
+
const other = [];
|
|
114
|
+
for (const value of expected) {
|
|
115
|
+
assert.ok(typeof value === "string", "All expected entries have to be of type string");
|
|
116
|
+
if (kTypes.has(value)) types.push(value.toLowerCase());
|
|
117
|
+
else if (classRegExp.exec(value) === null) {
|
|
118
|
+
assert.ok(value !== "object", "The value \"object\" should be written as \"Object\"");
|
|
119
|
+
other.push(value);
|
|
120
|
+
} else instances.push(value);
|
|
121
|
+
}
|
|
122
|
+
if (instances.length > 0) {
|
|
123
|
+
const pos = types.indexOf("object");
|
|
124
|
+
if (pos !== -1) {
|
|
125
|
+
types.slice(pos, 1);
|
|
126
|
+
instances.push("Object");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (types.length > 0) {
|
|
130
|
+
message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(types, "or")}`;
|
|
131
|
+
if (instances.length > 0 || other.length > 0) message += " or ";
|
|
132
|
+
}
|
|
133
|
+
if (instances.length > 0) {
|
|
134
|
+
message += `an instance of ${formatList(instances, "or")}`;
|
|
135
|
+
if (other.length > 0) message += " or ";
|
|
136
|
+
}
|
|
137
|
+
if (other.length > 0) if (other.length > 1) message += `one of ${formatList(other, "or")}`;
|
|
138
|
+
else {
|
|
139
|
+
if (other[0].toLowerCase() !== other[0]) message += "an ";
|
|
140
|
+
message += `${other[0]}`;
|
|
141
|
+
}
|
|
142
|
+
message += `. Received ${determineSpecificType(actual)}`;
|
|
143
|
+
return message;
|
|
144
|
+
},
|
|
145
|
+
TypeError
|
|
146
|
+
);
|
|
147
|
+
codes.ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
148
|
+
"ERR_INVALID_MODULE_SPECIFIER",
|
|
149
|
+
/**
|
|
150
|
+
* @param {string} request
|
|
151
|
+
* @param {string} reason
|
|
152
|
+
* @param {string} [base]
|
|
153
|
+
*/
|
|
154
|
+
(request, reason, base = void 0) => {
|
|
155
|
+
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
|
|
156
|
+
},
|
|
157
|
+
TypeError
|
|
158
|
+
);
|
|
159
|
+
codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
160
|
+
"ERR_INVALID_PACKAGE_CONFIG",
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} path
|
|
163
|
+
* @param {string} [base]
|
|
164
|
+
* @param {string} [message]
|
|
165
|
+
*/
|
|
166
|
+
(path, base, message) => {
|
|
167
|
+
return `Invalid package config ${path}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
168
|
+
},
|
|
169
|
+
Error
|
|
170
|
+
);
|
|
171
|
+
codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
172
|
+
"ERR_INVALID_PACKAGE_TARGET",
|
|
173
|
+
/**
|
|
174
|
+
* @param {string} packagePath
|
|
175
|
+
* @param {string} key
|
|
176
|
+
* @param {unknown} target
|
|
177
|
+
* @param {boolean} [isImport=false]
|
|
178
|
+
* @param {string} [base]
|
|
179
|
+
*/
|
|
180
|
+
(packagePath, key, target, isImport = false, base = void 0) => {
|
|
181
|
+
const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
182
|
+
if (key === ".") {
|
|
183
|
+
assert.ok(isImport === false);
|
|
184
|
+
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 \"./\"" : ""}`;
|
|
185
|
+
}
|
|
186
|
+
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 \"./\"" : ""}`;
|
|
187
|
+
},
|
|
188
|
+
Error
|
|
189
|
+
);
|
|
190
|
+
codes.ERR_MODULE_NOT_FOUND = createError(
|
|
191
|
+
"ERR_MODULE_NOT_FOUND",
|
|
192
|
+
/**
|
|
193
|
+
* @param {string} path
|
|
194
|
+
* @param {string} base
|
|
195
|
+
* @param {boolean} [exactUrl]
|
|
196
|
+
*/
|
|
197
|
+
(path, base, exactUrl = false) => {
|
|
198
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path}' imported from ${base}`;
|
|
199
|
+
},
|
|
200
|
+
Error
|
|
201
|
+
);
|
|
202
|
+
codes.ERR_NETWORK_IMPORT_DISALLOWED = createError("ERR_NETWORK_IMPORT_DISALLOWED", "import of '%s' by %s is not supported: %s", Error);
|
|
203
|
+
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
|
|
204
|
+
"ERR_PACKAGE_IMPORT_NOT_DEFINED",
|
|
205
|
+
/**
|
|
206
|
+
* @param {string} specifier
|
|
207
|
+
* @param {string} packagePath
|
|
208
|
+
* @param {string} base
|
|
209
|
+
*/
|
|
210
|
+
(specifier, packagePath, base) => {
|
|
211
|
+
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
|
|
212
|
+
},
|
|
213
|
+
TypeError
|
|
214
|
+
);
|
|
215
|
+
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
216
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
217
|
+
/**
|
|
218
|
+
* @param {string} packagePath
|
|
219
|
+
* @param {string} subpath
|
|
220
|
+
* @param {string} [base]
|
|
221
|
+
*/
|
|
222
|
+
(packagePath, subpath, base = void 0) => {
|
|
223
|
+
if (subpath === ".") return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
224
|
+
return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
225
|
+
},
|
|
226
|
+
Error
|
|
227
|
+
);
|
|
228
|
+
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError("ERR_UNSUPPORTED_DIR_IMPORT", "Directory import '%s' is not supported resolving ES modules imported from %s", Error);
|
|
229
|
+
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);
|
|
230
|
+
codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
231
|
+
"ERR_UNKNOWN_FILE_EXTENSION",
|
|
232
|
+
/**
|
|
233
|
+
* @param {string} extension
|
|
234
|
+
* @param {string} path
|
|
235
|
+
*/
|
|
236
|
+
(extension, path) => {
|
|
237
|
+
return `Unknown file extension "${extension}" for ${path}`;
|
|
238
|
+
},
|
|
239
|
+
TypeError
|
|
240
|
+
);
|
|
241
|
+
codes.ERR_INVALID_ARG_VALUE = createError(
|
|
242
|
+
"ERR_INVALID_ARG_VALUE",
|
|
243
|
+
/**
|
|
244
|
+
* @param {string} name
|
|
245
|
+
* @param {unknown} value
|
|
246
|
+
* @param {string} [reason='is invalid']
|
|
247
|
+
*/
|
|
248
|
+
(name, value, reason = "is invalid") => {
|
|
249
|
+
let inspected = inspect(value);
|
|
250
|
+
if (inspected.length > 128) inspected = `${inspected.slice(0, 128)}...`;
|
|
251
|
+
return `The ${name.includes(".") ? "property" : "argument"} '${name}' ${reason}. Received ${inspected}`;
|
|
252
|
+
},
|
|
253
|
+
TypeError
|
|
254
|
+
);
|
|
255
|
+
/**
|
|
256
|
+
* Utility function for registering the error codes. Only used here. Exported
|
|
257
|
+
* *only* to allow for testing.
|
|
258
|
+
* @param {string} sym
|
|
259
|
+
* @param {MessageFunction | string} value
|
|
260
|
+
* @param {ErrorConstructor} constructor
|
|
261
|
+
* @returns {new (...parameters: Array<any>) => Error}
|
|
262
|
+
*/
|
|
263
|
+
function createError(sym, value, constructor) {
|
|
264
|
+
messages.set(sym, value);
|
|
265
|
+
return makeNodeErrorWithCode(constructor, sym);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* @param {ErrorConstructor} Base
|
|
269
|
+
* @param {string} key
|
|
270
|
+
* @returns {ErrorConstructor}
|
|
271
|
+
*/
|
|
272
|
+
function makeNodeErrorWithCode(Base, key) {
|
|
273
|
+
return NodeError;
|
|
274
|
+
/**
|
|
275
|
+
* @param {Array<unknown>} parameters
|
|
276
|
+
*/
|
|
277
|
+
function NodeError(...parameters) {
|
|
278
|
+
const limit = Error.stackTraceLimit;
|
|
279
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
280
|
+
const error = new Base();
|
|
281
|
+
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
282
|
+
const message = getMessage(key, parameters, error);
|
|
283
|
+
Object.defineProperties(error, {
|
|
284
|
+
message: {
|
|
285
|
+
value: message,
|
|
286
|
+
enumerable: false,
|
|
287
|
+
writable: true,
|
|
288
|
+
configurable: true
|
|
289
|
+
},
|
|
290
|
+
toString: {
|
|
291
|
+
/** @this {Error} */
|
|
292
|
+
value() {
|
|
293
|
+
return `${this.name} [${key}]: ${this.message}`;
|
|
294
|
+
},
|
|
295
|
+
enumerable: false,
|
|
296
|
+
writable: true,
|
|
297
|
+
configurable: true
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
captureLargerStackTrace(error);
|
|
301
|
+
error.code = key;
|
|
302
|
+
return error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* @returns {boolean}
|
|
307
|
+
*/
|
|
308
|
+
function isErrorStackTraceLimitWritable() {
|
|
309
|
+
try {
|
|
310
|
+
if (v8.startupSnapshot.isBuildingSnapshot()) return false;
|
|
311
|
+
} catch {}
|
|
312
|
+
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
313
|
+
if (desc === void 0) return Object.isExtensible(Error);
|
|
314
|
+
return own$1.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* This function removes unnecessary frames from Node.js core errors.
|
|
318
|
+
* @template {(...parameters: unknown[]) => unknown} T
|
|
319
|
+
* @param {T} wrappedFunction
|
|
320
|
+
* @returns {T}
|
|
321
|
+
*/
|
|
322
|
+
function hideStackFrames(wrappedFunction) {
|
|
323
|
+
const hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
324
|
+
Object.defineProperty(wrappedFunction, "name", { value: hidden });
|
|
325
|
+
return wrappedFunction;
|
|
326
|
+
}
|
|
327
|
+
var captureLargerStackTrace = hideStackFrames(
|
|
328
|
+
/**
|
|
329
|
+
* @param {Error} error
|
|
330
|
+
* @returns {Error}
|
|
331
|
+
*/
|
|
332
|
+
function(error) {
|
|
333
|
+
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
334
|
+
if (stackTraceLimitIsWritable) {
|
|
335
|
+
userStackTraceLimit = Error.stackTraceLimit;
|
|
336
|
+
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
337
|
+
}
|
|
338
|
+
Error.captureStackTrace(error);
|
|
339
|
+
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
340
|
+
return error;
|
|
341
|
+
}
|
|
342
|
+
);
|
|
343
|
+
/**
|
|
344
|
+
* @param {string} key
|
|
345
|
+
* @param {Array<unknown>} parameters
|
|
346
|
+
* @param {Error} self
|
|
347
|
+
* @returns {string}
|
|
348
|
+
*/
|
|
349
|
+
function getMessage(key, parameters, self) {
|
|
350
|
+
const message = messages.get(key);
|
|
351
|
+
assert.ok(message !== void 0, "expected `message` to be found");
|
|
352
|
+
if (typeof message === "function") {
|
|
353
|
+
assert.ok(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`);
|
|
354
|
+
return Reflect.apply(message, self, parameters);
|
|
355
|
+
}
|
|
356
|
+
const regex = /%[dfijoOs]/g;
|
|
357
|
+
let expectedLength = 0;
|
|
358
|
+
while (regex.exec(message) !== null) expectedLength++;
|
|
359
|
+
assert.ok(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`);
|
|
360
|
+
if (parameters.length === 0) return message;
|
|
361
|
+
parameters.unshift(message);
|
|
362
|
+
return Reflect.apply(format, null, parameters);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Determine the specific type of a value for type-mismatch errors.
|
|
366
|
+
* @param {unknown} value
|
|
367
|
+
* @returns {string}
|
|
368
|
+
*/
|
|
369
|
+
function determineSpecificType(value) {
|
|
370
|
+
if (value === null || value === void 0) return String(value);
|
|
371
|
+
if (typeof value === "function" && value.name) return `function ${value.name}`;
|
|
372
|
+
if (typeof value === "object") {
|
|
373
|
+
if (value.constructor && value.constructor.name) return `an instance of ${value.constructor.name}`;
|
|
374
|
+
return `${inspect(value, { depth: -1 })}`;
|
|
375
|
+
}
|
|
376
|
+
let inspected = inspect(value, { colors: false });
|
|
377
|
+
if (inspected.length > 28) inspected = `${inspected.slice(0, 25)}...`;
|
|
378
|
+
return `type ${typeof value} (${inspected})`;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region ../node_modules/import-meta-resolve/lib/package-json-reader.js
|
|
382
|
+
/**
|
|
383
|
+
* @import {ErrnoException} from './errors.js'
|
|
384
|
+
*
|
|
385
|
+
* @typedef {'commonjs' | 'module' | 'none'} PackageType
|
|
386
|
+
*
|
|
387
|
+
* @typedef PackageConfig
|
|
388
|
+
* @property {string} pjsonPath
|
|
389
|
+
* @property {boolean} exists
|
|
390
|
+
* @property {string | undefined} [main]
|
|
391
|
+
* @property {string | undefined} [name]
|
|
392
|
+
* @property {PackageType} type
|
|
393
|
+
* @property {Record<string, unknown> | undefined} [exports]
|
|
394
|
+
* @property {Record<string, unknown> | undefined} [imports]
|
|
395
|
+
*/
|
|
396
|
+
var hasOwnProperty$1 = {}.hasOwnProperty;
|
|
397
|
+
var { ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG$1 } = codes;
|
|
398
|
+
/** @type {Map<string, PackageConfig>} */
|
|
399
|
+
var cache = /* @__PURE__ */ new Map();
|
|
400
|
+
/**
|
|
401
|
+
* @param {string} jsonPath
|
|
402
|
+
* @param {{specifier: URL | string, base?: URL}} options
|
|
403
|
+
* @returns {PackageConfig}
|
|
404
|
+
*/
|
|
405
|
+
function read(jsonPath, { base, specifier }) {
|
|
406
|
+
const existing = cache.get(jsonPath);
|
|
407
|
+
if (existing) return existing;
|
|
408
|
+
/** @type {string | undefined} */
|
|
409
|
+
let string;
|
|
410
|
+
try {
|
|
411
|
+
string = fs.readFileSync(path.toNamespacedPath(jsonPath), "utf8");
|
|
412
|
+
} catch (error) {
|
|
413
|
+
const exception = error;
|
|
414
|
+
if (exception.code !== "ENOENT") throw exception;
|
|
415
|
+
}
|
|
416
|
+
/** @type {PackageConfig} */
|
|
417
|
+
const result = {
|
|
418
|
+
exists: false,
|
|
419
|
+
pjsonPath: jsonPath,
|
|
420
|
+
main: void 0,
|
|
421
|
+
name: void 0,
|
|
422
|
+
type: "none",
|
|
423
|
+
exports: void 0,
|
|
424
|
+
imports: void 0
|
|
425
|
+
};
|
|
426
|
+
if (string !== void 0) {
|
|
427
|
+
/** @type {Record<string, unknown>} */
|
|
428
|
+
let parsed;
|
|
429
|
+
try {
|
|
430
|
+
parsed = JSON.parse(string);
|
|
431
|
+
} catch (error_) {
|
|
432
|
+
const cause = error_;
|
|
433
|
+
const error = new ERR_INVALID_PACKAGE_CONFIG$1(jsonPath, (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier), cause.message);
|
|
434
|
+
error.cause = cause;
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
result.exists = true;
|
|
438
|
+
if (hasOwnProperty$1.call(parsed, "name") && typeof parsed.name === "string") result.name = parsed.name;
|
|
439
|
+
if (hasOwnProperty$1.call(parsed, "main") && typeof parsed.main === "string") result.main = parsed.main;
|
|
440
|
+
if (hasOwnProperty$1.call(parsed, "exports")) result.exports = parsed.exports;
|
|
441
|
+
if (hasOwnProperty$1.call(parsed, "imports")) result.imports = parsed.imports;
|
|
442
|
+
if (hasOwnProperty$1.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) result.type = parsed.type;
|
|
443
|
+
}
|
|
444
|
+
cache.set(jsonPath, result);
|
|
445
|
+
return result;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* @param {URL | string} resolved
|
|
449
|
+
* @returns {PackageConfig}
|
|
450
|
+
*/
|
|
451
|
+
function getPackageScopeConfig(resolved) {
|
|
452
|
+
let packageJSONUrl = new URL("package.json", resolved);
|
|
453
|
+
while (true) {
|
|
454
|
+
if (packageJSONUrl.pathname.endsWith("node_modules/package.json")) break;
|
|
455
|
+
const packageConfig = read(fileURLToPath(packageJSONUrl), { specifier: resolved });
|
|
456
|
+
if (packageConfig.exists) return packageConfig;
|
|
457
|
+
const lastPackageJSONUrl = packageJSONUrl;
|
|
458
|
+
packageJSONUrl = new URL("../package.json", packageJSONUrl);
|
|
459
|
+
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) break;
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
pjsonPath: fileURLToPath(packageJSONUrl),
|
|
463
|
+
exists: false,
|
|
464
|
+
type: "none"
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Returns the package type for a given URL.
|
|
469
|
+
* @param {URL} url - The URL to get the package type for.
|
|
470
|
+
* @returns {PackageType}
|
|
471
|
+
*/
|
|
472
|
+
function getPackageType(url) {
|
|
473
|
+
return getPackageScopeConfig(url).type;
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region ../node_modules/import-meta-resolve/lib/get-format.js
|
|
477
|
+
var { ERR_UNKNOWN_FILE_EXTENSION } = codes;
|
|
478
|
+
var hasOwnProperty = {}.hasOwnProperty;
|
|
479
|
+
/** @type {Record<string, string>} */
|
|
480
|
+
var extensionFormatMap = {
|
|
481
|
+
__proto__: null,
|
|
482
|
+
".cjs": "commonjs",
|
|
483
|
+
".js": "module",
|
|
484
|
+
".json": "json",
|
|
485
|
+
".mjs": "module"
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* @param {string | null} mime
|
|
489
|
+
* @returns {string | null}
|
|
490
|
+
*/
|
|
491
|
+
function mimeToFormat(mime) {
|
|
492
|
+
if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return "module";
|
|
493
|
+
if (mime === "application/json") return "json";
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* @callback ProtocolHandler
|
|
498
|
+
* @param {URL} parsed
|
|
499
|
+
* @param {{parentURL: string, source?: Buffer}} context
|
|
500
|
+
* @param {boolean} ignoreErrors
|
|
501
|
+
* @returns {string | null | void}
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* @type {Record<string, ProtocolHandler>}
|
|
505
|
+
*/
|
|
506
|
+
var protocolHandlers = {
|
|
507
|
+
__proto__: null,
|
|
508
|
+
"data:": getDataProtocolModuleFormat,
|
|
509
|
+
"file:": getFileProtocolModuleFormat,
|
|
510
|
+
"http:": getHttpProtocolModuleFormat,
|
|
511
|
+
"https:": getHttpProtocolModuleFormat,
|
|
512
|
+
"node:"() {
|
|
513
|
+
return "builtin";
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
/**
|
|
517
|
+
* @param {URL} parsed
|
|
518
|
+
*/
|
|
519
|
+
function getDataProtocolModuleFormat(parsed) {
|
|
520
|
+
const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
|
|
521
|
+
null,
|
|
522
|
+
null,
|
|
523
|
+
null
|
|
524
|
+
];
|
|
525
|
+
return mimeToFormat(mime);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Returns the file extension from a URL.
|
|
529
|
+
*
|
|
530
|
+
* Should give similar result to
|
|
531
|
+
* `require('node:path').extname(require('node:url').fileURLToPath(url))`
|
|
532
|
+
* when used with a `file:` URL.
|
|
533
|
+
*
|
|
534
|
+
* @param {URL} url
|
|
535
|
+
* @returns {string}
|
|
536
|
+
*/
|
|
537
|
+
function extname$1(url) {
|
|
538
|
+
const pathname = url.pathname;
|
|
539
|
+
let index = pathname.length;
|
|
540
|
+
while (index--) {
|
|
541
|
+
const code = pathname.codePointAt(index);
|
|
542
|
+
if (code === 47) return "";
|
|
543
|
+
if (code === 46) return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
|
|
544
|
+
}
|
|
545
|
+
return "";
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* @type {ProtocolHandler}
|
|
549
|
+
*/
|
|
550
|
+
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
551
|
+
const value = extname$1(url);
|
|
552
|
+
if (value === ".js") {
|
|
553
|
+
const packageType = getPackageType(url);
|
|
554
|
+
if (packageType !== "none") return packageType;
|
|
555
|
+
return "commonjs";
|
|
556
|
+
}
|
|
557
|
+
if (value === "") {
|
|
558
|
+
const packageType = getPackageType(url);
|
|
559
|
+
if (packageType === "none" || packageType === "commonjs") return "commonjs";
|
|
560
|
+
return "module";
|
|
561
|
+
}
|
|
562
|
+
const format = extensionFormatMap[value];
|
|
563
|
+
if (format) return format;
|
|
564
|
+
if (ignoreErrors) return;
|
|
565
|
+
throw new ERR_UNKNOWN_FILE_EXTENSION(value, fileURLToPath(url));
|
|
566
|
+
}
|
|
567
|
+
function getHttpProtocolModuleFormat() {}
|
|
568
|
+
/**
|
|
569
|
+
* @param {URL} url
|
|
570
|
+
* @param {{parentURL: string}} context
|
|
571
|
+
* @returns {string | null}
|
|
572
|
+
*/
|
|
573
|
+
function defaultGetFormatWithoutErrors(url, context) {
|
|
574
|
+
const protocol = url.protocol;
|
|
575
|
+
if (!hasOwnProperty.call(protocolHandlers, protocol)) return null;
|
|
576
|
+
return protocolHandlers[protocol](url, context, true) || null;
|
|
577
|
+
}
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region ../node_modules/import-meta-resolve/lib/utils.js
|
|
580
|
+
var { ERR_INVALID_ARG_VALUE } = codes;
|
|
581
|
+
var DEFAULT_CONDITIONS = Object.freeze(["node", "import"]);
|
|
582
|
+
var DEFAULT_CONDITIONS_SET = new Set(DEFAULT_CONDITIONS);
|
|
583
|
+
/**
|
|
584
|
+
* Returns the default conditions for ES module loading.
|
|
585
|
+
*/
|
|
586
|
+
function getDefaultConditions() {
|
|
587
|
+
return DEFAULT_CONDITIONS;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Returns the default conditions for ES module loading, as a Set.
|
|
591
|
+
*/
|
|
592
|
+
function getDefaultConditionsSet() {
|
|
593
|
+
return DEFAULT_CONDITIONS_SET;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* @param {Array<string>} [conditions]
|
|
597
|
+
* @returns {Set<string>}
|
|
598
|
+
*/
|
|
599
|
+
function getConditionsSet(conditions) {
|
|
600
|
+
if (conditions !== void 0 && conditions !== getDefaultConditions()) {
|
|
601
|
+
if (!Array.isArray(conditions)) throw new ERR_INVALID_ARG_VALUE("conditions", conditions, "expected an array");
|
|
602
|
+
return new Set(conditions);
|
|
603
|
+
}
|
|
604
|
+
return getDefaultConditionsSet();
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region ../node_modules/import-meta-resolve/lib/resolve.js
|
|
608
|
+
/**
|
|
609
|
+
* @import {Stats} from 'node:fs'
|
|
610
|
+
* @import {ErrnoException} from './errors.js'
|
|
611
|
+
* @import {PackageConfig} from './package-json-reader.js'
|
|
612
|
+
*/
|
|
613
|
+
var RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
614
|
+
var { ERR_NETWORK_IMPORT_DISALLOWED, 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;
|
|
615
|
+
var own = {}.hasOwnProperty;
|
|
616
|
+
var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
617
|
+
var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
618
|
+
var invalidPackageNameRegEx = /^\.|%|\\/;
|
|
619
|
+
var patternRegEx = /\*/g;
|
|
620
|
+
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
621
|
+
/** @type {Set<string>} */
|
|
622
|
+
var emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
623
|
+
var doubleSlashRegEx = /[/\\]{2}/;
|
|
624
|
+
/**
|
|
625
|
+
*
|
|
626
|
+
* @param {string} target
|
|
627
|
+
* @param {string} request
|
|
628
|
+
* @param {string} match
|
|
629
|
+
* @param {URL} packageJsonUrl
|
|
630
|
+
* @param {boolean} internal
|
|
631
|
+
* @param {URL} base
|
|
632
|
+
* @param {boolean} isTarget
|
|
633
|
+
*/
|
|
634
|
+
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
635
|
+
if (process$1.noDeprecation) return;
|
|
636
|
+
const pjsonPath = fileURLToPath(packageJsonUrl);
|
|
637
|
+
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
638
|
+
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");
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* @param {URL} url
|
|
642
|
+
* @param {URL} packageJsonUrl
|
|
643
|
+
* @param {URL} base
|
|
644
|
+
* @param {string} [main]
|
|
645
|
+
* @returns {void}
|
|
646
|
+
*/
|
|
647
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
648
|
+
if (process$1.noDeprecation) return;
|
|
649
|
+
if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module") return;
|
|
650
|
+
const urlPath = fileURLToPath(url.href);
|
|
651
|
+
const packagePath = fileURLToPath(new URL(".", packageJsonUrl));
|
|
652
|
+
const basePath = fileURLToPath(base);
|
|
653
|
+
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");
|
|
654
|
+
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");
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* @param {string} path
|
|
658
|
+
* @returns {Stats | undefined}
|
|
659
|
+
*/
|
|
660
|
+
function tryStatSync(path) {
|
|
661
|
+
try {
|
|
662
|
+
return statSync(path);
|
|
663
|
+
} catch {}
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Legacy CommonJS main resolution:
|
|
667
|
+
* 1. let M = pkg_url + (json main field)
|
|
668
|
+
* 2. TRY(M, M.js, M.json, M.node)
|
|
669
|
+
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
670
|
+
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
671
|
+
* 5. NOT_FOUND
|
|
672
|
+
*
|
|
673
|
+
* @param {URL} url
|
|
674
|
+
* @returns {boolean}
|
|
675
|
+
*/
|
|
676
|
+
function fileExists(url) {
|
|
677
|
+
const stats = statSync(url, { throwIfNoEntry: false });
|
|
678
|
+
const isFile = stats ? stats.isFile() : void 0;
|
|
679
|
+
return isFile === null || isFile === void 0 ? false : isFile;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* @param {URL} packageJsonUrl
|
|
683
|
+
* @param {PackageConfig} packageConfig
|
|
684
|
+
* @param {URL} base
|
|
685
|
+
* @returns {URL}
|
|
686
|
+
*/
|
|
687
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
688
|
+
/** @type {URL | undefined} */
|
|
689
|
+
let guess;
|
|
690
|
+
if (packageConfig.main !== void 0) {
|
|
691
|
+
guess = new URL(packageConfig.main, packageJsonUrl);
|
|
692
|
+
if (fileExists(guess)) return guess;
|
|
693
|
+
const tries = [
|
|
694
|
+
`./${packageConfig.main}.js`,
|
|
695
|
+
`./${packageConfig.main}.json`,
|
|
696
|
+
`./${packageConfig.main}.node`,
|
|
697
|
+
`./${packageConfig.main}/index.js`,
|
|
698
|
+
`./${packageConfig.main}/index.json`,
|
|
699
|
+
`./${packageConfig.main}/index.node`
|
|
700
|
+
];
|
|
701
|
+
let i = -1;
|
|
702
|
+
while (++i < tries.length) {
|
|
703
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
704
|
+
if (fileExists(guess)) break;
|
|
705
|
+
guess = void 0;
|
|
706
|
+
}
|
|
707
|
+
if (guess) {
|
|
708
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
709
|
+
return guess;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
const tries = [
|
|
713
|
+
"./index.js",
|
|
714
|
+
"./index.json",
|
|
715
|
+
"./index.node"
|
|
716
|
+
];
|
|
717
|
+
let i = -1;
|
|
718
|
+
while (++i < tries.length) {
|
|
719
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
720
|
+
if (fileExists(guess)) break;
|
|
721
|
+
guess = void 0;
|
|
722
|
+
}
|
|
723
|
+
if (guess) {
|
|
724
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
725
|
+
return guess;
|
|
726
|
+
}
|
|
727
|
+
throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL(".", packageJsonUrl)), fileURLToPath(base));
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* @param {URL} resolved
|
|
731
|
+
* @param {URL} base
|
|
732
|
+
* @param {boolean} [preserveSymlinks]
|
|
733
|
+
* @returns {URL}
|
|
734
|
+
*/
|
|
735
|
+
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
736
|
+
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, "must not include encoded \"/\" or \"\\\" characters", fileURLToPath(base));
|
|
737
|
+
/** @type {string} */
|
|
738
|
+
let filePath;
|
|
739
|
+
try {
|
|
740
|
+
filePath = fileURLToPath(resolved);
|
|
741
|
+
} catch (error) {
|
|
742
|
+
const cause = error;
|
|
743
|
+
Object.defineProperty(cause, "input", { value: String(resolved) });
|
|
744
|
+
Object.defineProperty(cause, "module", { value: String(base) });
|
|
745
|
+
throw cause;
|
|
746
|
+
}
|
|
747
|
+
const stats = tryStatSync(filePath.endsWith("/") ? filePath.slice(-1) : filePath);
|
|
748
|
+
if (stats && stats.isDirectory()) {
|
|
749
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath(base));
|
|
750
|
+
error.url = String(resolved);
|
|
751
|
+
throw error;
|
|
752
|
+
}
|
|
753
|
+
if (!stats || !stats.isFile()) {
|
|
754
|
+
const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && fileURLToPath(base), true);
|
|
755
|
+
error.url = String(resolved);
|
|
756
|
+
throw error;
|
|
757
|
+
}
|
|
758
|
+
if (!preserveSymlinks) {
|
|
759
|
+
const real = realpathSync(filePath);
|
|
760
|
+
const { search, hash } = resolved;
|
|
761
|
+
resolved = pathToFileURL(real + (filePath.endsWith(path.sep) ? "/" : ""));
|
|
762
|
+
resolved.search = search;
|
|
763
|
+
resolved.hash = hash;
|
|
764
|
+
}
|
|
765
|
+
return resolved;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* @param {string} specifier
|
|
769
|
+
* @param {URL | undefined} packageJsonUrl
|
|
770
|
+
* @param {URL} base
|
|
771
|
+
* @returns {Error}
|
|
772
|
+
*/
|
|
773
|
+
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
774
|
+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && fileURLToPath(new URL(".", packageJsonUrl)), fileURLToPath(base));
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* @param {string} subpath
|
|
778
|
+
* @param {URL} packageJsonUrl
|
|
779
|
+
* @param {URL} base
|
|
780
|
+
* @returns {Error}
|
|
781
|
+
*/
|
|
782
|
+
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
783
|
+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL(".", packageJsonUrl)), subpath, base && fileURLToPath(base));
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* @param {string} request
|
|
787
|
+
* @param {string} match
|
|
788
|
+
* @param {URL} packageJsonUrl
|
|
789
|
+
* @param {boolean} internal
|
|
790
|
+
* @param {URL} [base]
|
|
791
|
+
* @returns {never}
|
|
792
|
+
*/
|
|
793
|
+
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
794
|
+
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));
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* @param {string} subpath
|
|
798
|
+
* @param {unknown} target
|
|
799
|
+
* @param {URL} packageJsonUrl
|
|
800
|
+
* @param {boolean} internal
|
|
801
|
+
* @param {URL} [base]
|
|
802
|
+
* @returns {Error}
|
|
803
|
+
*/
|
|
804
|
+
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
805
|
+
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
806
|
+
return new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL(".", packageJsonUrl)), subpath, target, internal, base && fileURLToPath(base));
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* @param {string} target
|
|
810
|
+
* @param {string} subpath
|
|
811
|
+
* @param {string} match
|
|
812
|
+
* @param {URL} packageJsonUrl
|
|
813
|
+
* @param {URL} base
|
|
814
|
+
* @param {boolean} pattern
|
|
815
|
+
* @param {boolean} internal
|
|
816
|
+
* @param {boolean} isPathMap
|
|
817
|
+
* @param {Set<string> | undefined} conditions
|
|
818
|
+
* @returns {URL}
|
|
819
|
+
*/
|
|
820
|
+
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
821
|
+
if (subpath !== "" && !pattern && target[target.length - 1] !== "/") throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
822
|
+
if (!target.startsWith("./")) {
|
|
823
|
+
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
824
|
+
let isURL = false;
|
|
825
|
+
try {
|
|
826
|
+
new URL(target);
|
|
827
|
+
isURL = true;
|
|
828
|
+
} catch {}
|
|
829
|
+
if (!isURL) return packageResolve(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath, packageJsonUrl, conditions);
|
|
830
|
+
}
|
|
831
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
832
|
+
}
|
|
833
|
+
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
834
|
+
if (!isPathMap) {
|
|
835
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
836
|
+
emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, true);
|
|
837
|
+
}
|
|
838
|
+
} else throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
839
|
+
const resolved = new URL(target, packageJsonUrl);
|
|
840
|
+
const resolvedPath = resolved.pathname;
|
|
841
|
+
const packagePath = new URL(".", packageJsonUrl).pathname;
|
|
842
|
+
if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
843
|
+
if (subpath === "") return resolved;
|
|
844
|
+
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
845
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
846
|
+
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
847
|
+
if (!isPathMap) emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, false);
|
|
848
|
+
} else throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
849
|
+
}
|
|
850
|
+
if (pattern) return new URL(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
|
|
851
|
+
return new URL(subpath, resolved);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* @param {string} key
|
|
855
|
+
* @returns {boolean}
|
|
856
|
+
*/
|
|
857
|
+
function isArrayIndex(key) {
|
|
858
|
+
const keyNumber = Number(key);
|
|
859
|
+
if (`${keyNumber}` !== key) return false;
|
|
860
|
+
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* @param {URL} packageJsonUrl
|
|
864
|
+
* @param {unknown} target
|
|
865
|
+
* @param {string} subpath
|
|
866
|
+
* @param {string} packageSubpath
|
|
867
|
+
* @param {URL} base
|
|
868
|
+
* @param {boolean} pattern
|
|
869
|
+
* @param {boolean} internal
|
|
870
|
+
* @param {boolean} isPathMap
|
|
871
|
+
* @param {Set<string> | undefined} conditions
|
|
872
|
+
* @returns {URL | null}
|
|
873
|
+
*/
|
|
874
|
+
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
875
|
+
if (typeof target === "string") return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
|
|
876
|
+
if (Array.isArray(target)) {
|
|
877
|
+
/** @type {Array<unknown>} */
|
|
878
|
+
const targetList = target;
|
|
879
|
+
if (targetList.length === 0) return null;
|
|
880
|
+
/** @type {ErrnoException | null | undefined} */
|
|
881
|
+
let lastException;
|
|
882
|
+
let i = -1;
|
|
883
|
+
while (++i < targetList.length) {
|
|
884
|
+
const targetItem = targetList[i];
|
|
885
|
+
/** @type {URL | null} */
|
|
886
|
+
let resolveResult;
|
|
887
|
+
try {
|
|
888
|
+
resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
889
|
+
} catch (error) {
|
|
890
|
+
const exception = error;
|
|
891
|
+
lastException = exception;
|
|
892
|
+
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
893
|
+
throw error;
|
|
894
|
+
}
|
|
895
|
+
if (resolveResult === void 0) continue;
|
|
896
|
+
if (resolveResult === null) {
|
|
897
|
+
lastException = null;
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
return resolveResult;
|
|
901
|
+
}
|
|
902
|
+
if (lastException === void 0 || lastException === null) return null;
|
|
903
|
+
throw lastException;
|
|
904
|
+
}
|
|
905
|
+
if (typeof target === "object" && target !== null) {
|
|
906
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
907
|
+
let i = -1;
|
|
908
|
+
while (++i < keys.length) {
|
|
909
|
+
const key = keys[i];
|
|
910
|
+
if (isArrayIndex(key)) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), base, "\"exports\" cannot contain numeric property keys.");
|
|
911
|
+
}
|
|
912
|
+
i = -1;
|
|
913
|
+
while (++i < keys.length) {
|
|
914
|
+
const key = keys[i];
|
|
915
|
+
if (key === "default" || conditions && conditions.has(key)) {
|
|
916
|
+
const conditionalTarget = target[key];
|
|
917
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
918
|
+
if (resolveResult === void 0) continue;
|
|
919
|
+
return resolveResult;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return null;
|
|
923
|
+
}
|
|
924
|
+
if (target === null) return null;
|
|
925
|
+
throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* @param {unknown} exports
|
|
929
|
+
* @param {URL} packageJsonUrl
|
|
930
|
+
* @param {URL} base
|
|
931
|
+
* @returns {boolean}
|
|
932
|
+
*/
|
|
933
|
+
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
934
|
+
if (typeof exports === "string" || Array.isArray(exports)) return true;
|
|
935
|
+
if (typeof exports !== "object" || exports === null) return false;
|
|
936
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
937
|
+
let isConditionalSugar = false;
|
|
938
|
+
let i = 0;
|
|
939
|
+
let keyIndex = -1;
|
|
940
|
+
while (++keyIndex < keys.length) {
|
|
941
|
+
const key = keys[keyIndex];
|
|
942
|
+
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
943
|
+
if (i++ === 0) isConditionalSugar = currentIsConditionalSugar;
|
|
944
|
+
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.");
|
|
945
|
+
}
|
|
946
|
+
return isConditionalSugar;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* @param {string} match
|
|
950
|
+
* @param {URL} pjsonUrl
|
|
951
|
+
* @param {URL} base
|
|
952
|
+
*/
|
|
953
|
+
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
954
|
+
if (process$1.noDeprecation) return;
|
|
955
|
+
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
956
|
+
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
957
|
+
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
958
|
+
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");
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* @param {URL} packageJsonUrl
|
|
962
|
+
* @param {string} packageSubpath
|
|
963
|
+
* @param {Record<string, unknown>} packageConfig
|
|
964
|
+
* @param {URL} base
|
|
965
|
+
* @param {Set<string> | undefined} conditions
|
|
966
|
+
* @returns {URL}
|
|
967
|
+
*/
|
|
968
|
+
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
969
|
+
let exports = packageConfig.exports;
|
|
970
|
+
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) exports = { ".": exports };
|
|
971
|
+
if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
972
|
+
const target = exports[packageSubpath];
|
|
973
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, target, "", packageSubpath, base, false, false, false, conditions);
|
|
974
|
+
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
975
|
+
return resolveResult;
|
|
976
|
+
}
|
|
977
|
+
let bestMatch = "";
|
|
978
|
+
let bestMatchSubpath = "";
|
|
979
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
980
|
+
let i = -1;
|
|
981
|
+
while (++i < keys.length) {
|
|
982
|
+
const key = keys[i];
|
|
983
|
+
const patternIndex = key.indexOf("*");
|
|
984
|
+
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
985
|
+
if (packageSubpath.endsWith("/")) emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
|
|
986
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
987
|
+
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
988
|
+
bestMatch = key;
|
|
989
|
+
bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
if (bestMatch) {
|
|
994
|
+
const target = exports[bestMatch];
|
|
995
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith("/"), conditions);
|
|
996
|
+
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
997
|
+
return resolveResult;
|
|
998
|
+
}
|
|
999
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* @param {string} a
|
|
1003
|
+
* @param {string} b
|
|
1004
|
+
*/
|
|
1005
|
+
function patternKeyCompare(a, b) {
|
|
1006
|
+
const aPatternIndex = a.indexOf("*");
|
|
1007
|
+
const bPatternIndex = b.indexOf("*");
|
|
1008
|
+
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
1009
|
+
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
1010
|
+
if (baseLengthA > baseLengthB) return -1;
|
|
1011
|
+
if (baseLengthB > baseLengthA) return 1;
|
|
1012
|
+
if (aPatternIndex === -1) return 1;
|
|
1013
|
+
if (bPatternIndex === -1) return -1;
|
|
1014
|
+
if (a.length > b.length) return -1;
|
|
1015
|
+
if (b.length > a.length) return 1;
|
|
1016
|
+
return 0;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* @param {string} name
|
|
1020
|
+
* @param {URL} base
|
|
1021
|
+
* @param {Set<string>} [conditions]
|
|
1022
|
+
* @returns {URL}
|
|
1023
|
+
*/
|
|
1024
|
+
function packageImportsResolve(name, base, conditions) {
|
|
1025
|
+
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) throw new ERR_INVALID_MODULE_SPECIFIER(name, "is not a valid internal imports specifier name", fileURLToPath(base));
|
|
1026
|
+
/** @type {URL | undefined} */
|
|
1027
|
+
let packageJsonUrl;
|
|
1028
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
1029
|
+
if (packageConfig.exists) {
|
|
1030
|
+
packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
1031
|
+
const imports = packageConfig.imports;
|
|
1032
|
+
if (imports) if (own.call(imports, name) && !name.includes("*")) {
|
|
1033
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], "", name, base, false, true, false, conditions);
|
|
1034
|
+
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
1035
|
+
} else {
|
|
1036
|
+
let bestMatch = "";
|
|
1037
|
+
let bestMatchSubpath = "";
|
|
1038
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
1039
|
+
let i = -1;
|
|
1040
|
+
while (++i < keys.length) {
|
|
1041
|
+
const key = keys[i];
|
|
1042
|
+
const patternIndex = key.indexOf("*");
|
|
1043
|
+
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
1044
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
1045
|
+
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
1046
|
+
bestMatch = key;
|
|
1047
|
+
bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
if (bestMatch) {
|
|
1052
|
+
const target = imports[bestMatch];
|
|
1053
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
|
|
1054
|
+
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
throw importNotDefined(name, packageJsonUrl, base);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* @param {string} specifier
|
|
1062
|
+
* @param {URL} base
|
|
1063
|
+
*/
|
|
1064
|
+
function parsePackageName(specifier, base) {
|
|
1065
|
+
let separatorIndex = specifier.indexOf("/");
|
|
1066
|
+
let validPackageName = true;
|
|
1067
|
+
let isScoped = false;
|
|
1068
|
+
if (specifier[0] === "@") {
|
|
1069
|
+
isScoped = true;
|
|
1070
|
+
if (separatorIndex === -1 || specifier.length === 0) validPackageName = false;
|
|
1071
|
+
else separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
1072
|
+
}
|
|
1073
|
+
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
1074
|
+
if (invalidPackageNameRegEx.exec(packageName) !== null) validPackageName = false;
|
|
1075
|
+
if (!validPackageName) throw new ERR_INVALID_MODULE_SPECIFIER(specifier, "is not a valid package name", fileURLToPath(base));
|
|
1076
|
+
return {
|
|
1077
|
+
packageName,
|
|
1078
|
+
packageSubpath: "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex)),
|
|
1079
|
+
isScoped
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* @param {string} specifier
|
|
1084
|
+
* @param {URL} base
|
|
1085
|
+
* @param {Set<string> | undefined} conditions
|
|
1086
|
+
* @returns {URL}
|
|
1087
|
+
*/
|
|
1088
|
+
function packageResolve(specifier, base, conditions) {
|
|
1089
|
+
if (builtinModules.includes(specifier)) return new URL("node:" + specifier);
|
|
1090
|
+
const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
|
|
1091
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
1092
|
+
/* c8 ignore next 16 */
|
|
1093
|
+
if (packageConfig.exists) {
|
|
1094
|
+
const packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
1095
|
+
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
|
|
1096
|
+
}
|
|
1097
|
+
let packageJsonUrl = new URL("./node_modules/" + packageName + "/package.json", base);
|
|
1098
|
+
let packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
1099
|
+
/** @type {string} */
|
|
1100
|
+
let lastPath;
|
|
1101
|
+
do {
|
|
1102
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
1103
|
+
if (!stat || !stat.isDirectory()) {
|
|
1104
|
+
lastPath = packageJsonPath;
|
|
1105
|
+
packageJsonUrl = new URL((isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json", packageJsonUrl);
|
|
1106
|
+
packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
const packageConfig = read(packageJsonPath, {
|
|
1110
|
+
base,
|
|
1111
|
+
specifier
|
|
1112
|
+
});
|
|
1113
|
+
if (packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
|
|
1114
|
+
if (packageSubpath === ".") return legacyMainResolve(packageJsonUrl, packageConfig, base);
|
|
1115
|
+
return new URL(packageSubpath, packageJsonUrl);
|
|
1116
|
+
} while (packageJsonPath.length !== lastPath.length);
|
|
1117
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), false);
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* @param {string} specifier
|
|
1121
|
+
* @returns {boolean}
|
|
1122
|
+
*/
|
|
1123
|
+
function isRelativeSpecifier(specifier) {
|
|
1124
|
+
if (specifier[0] === ".") {
|
|
1125
|
+
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
1126
|
+
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) return true;
|
|
1127
|
+
}
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* @param {string} specifier
|
|
1132
|
+
* @returns {boolean}
|
|
1133
|
+
*/
|
|
1134
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
1135
|
+
if (specifier === "") return false;
|
|
1136
|
+
if (specifier[0] === "/") return true;
|
|
1137
|
+
return isRelativeSpecifier(specifier);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
1141
|
+
* sync and slightly lower-level than `resolve`).
|
|
1142
|
+
*
|
|
1143
|
+
* @param {string} specifier
|
|
1144
|
+
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
|
|
1145
|
+
* @param {URL} base
|
|
1146
|
+
* Full URL (to a file) that `specifier` is resolved relative from.
|
|
1147
|
+
* @param {Set<string>} [conditions]
|
|
1148
|
+
* Conditions.
|
|
1149
|
+
* @param {boolean} [preserveSymlinks]
|
|
1150
|
+
* Keep symlinks instead of resolving them.
|
|
1151
|
+
* @returns {URL}
|
|
1152
|
+
* A URL object to the found thing.
|
|
1153
|
+
*/
|
|
1154
|
+
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
1155
|
+
if (conditions === void 0) conditions = getConditionsSet();
|
|
1156
|
+
const protocol = base.protocol;
|
|
1157
|
+
const isRemote = protocol === "data:" || protocol === "http:" || protocol === "https:";
|
|
1158
|
+
/** @type {URL | undefined} */
|
|
1159
|
+
let resolved;
|
|
1160
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) try {
|
|
1161
|
+
resolved = new URL(specifier, base);
|
|
1162
|
+
} catch (error_) {
|
|
1163
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1164
|
+
error.cause = error_;
|
|
1165
|
+
throw error;
|
|
1166
|
+
}
|
|
1167
|
+
else if (protocol === "file:" && specifier[0] === "#") resolved = packageImportsResolve(specifier, base, conditions);
|
|
1168
|
+
else try {
|
|
1169
|
+
resolved = new URL(specifier);
|
|
1170
|
+
} catch (error_) {
|
|
1171
|
+
if (isRemote && !builtinModules.includes(specifier)) {
|
|
1172
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1173
|
+
error.cause = error_;
|
|
1174
|
+
throw error;
|
|
1175
|
+
}
|
|
1176
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
1177
|
+
}
|
|
1178
|
+
assert.ok(resolved !== void 0, "expected to be defined");
|
|
1179
|
+
if (resolved.protocol !== "file:") return resolved;
|
|
1180
|
+
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* @param {string} specifier
|
|
1184
|
+
* @param {URL | undefined} parsed
|
|
1185
|
+
* @param {URL | undefined} parsedParentURL
|
|
1186
|
+
*/
|
|
1187
|
+
function checkIfDisallowedImport(specifier, parsed, parsedParentURL) {
|
|
1188
|
+
if (parsedParentURL) {
|
|
1189
|
+
const parentProtocol = parsedParentURL.protocol;
|
|
1190
|
+
if (parentProtocol === "http:" || parentProtocol === "https:") {
|
|
1191
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
1192
|
+
const parsedProtocol = parsed?.protocol;
|
|
1193
|
+
if (parsedProtocol && parsedProtocol !== "https:" && parsedProtocol !== "http:") throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, "remote imports cannot import from a local location.");
|
|
1194
|
+
return { url: parsed?.href || "" };
|
|
1195
|
+
}
|
|
1196
|
+
if (builtinModules.includes(specifier)) throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, "remote imports cannot import from a local location.");
|
|
1197
|
+
throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, "only relative and absolute specifiers are supported.");
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Checks if a value has the shape of a WHATWG URL object.
|
|
1203
|
+
*
|
|
1204
|
+
* Using a symbol or instanceof would not be able to recognize URL objects
|
|
1205
|
+
* coming from other implementations (e.g. in Electron), so instead we are
|
|
1206
|
+
* checking some well known properties for a lack of a better test.
|
|
1207
|
+
*
|
|
1208
|
+
* We use `href` and `protocol` as they are the only properties that are
|
|
1209
|
+
* easy to retrieve and calculate due to the lazy nature of the getters.
|
|
1210
|
+
*
|
|
1211
|
+
* @template {unknown} Value
|
|
1212
|
+
* @param {Value} self
|
|
1213
|
+
* @returns {Value is URL}
|
|
1214
|
+
*/
|
|
1215
|
+
function isURL(self) {
|
|
1216
|
+
return Boolean(self && typeof self === "object" && "href" in self && typeof self.href === "string" && "protocol" in self && typeof self.protocol === "string" && self.href && self.protocol);
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Validate user-input in `context` supplied by a custom loader.
|
|
1220
|
+
*
|
|
1221
|
+
* @param {unknown} parentURL
|
|
1222
|
+
* @returns {asserts parentURL is URL | string | undefined}
|
|
1223
|
+
*/
|
|
1224
|
+
function throwIfInvalidParentURL(parentURL) {
|
|
1225
|
+
if (parentURL === void 0) return;
|
|
1226
|
+
if (typeof parentURL !== "string" && !isURL(parentURL)) throw new codes.ERR_INVALID_ARG_TYPE("parentURL", ["string", "URL"], parentURL);
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* @param {string} specifier
|
|
1230
|
+
* @param {{parentURL?: string, conditions?: Array<string>}} context
|
|
1231
|
+
* @returns {{url: string, format?: string | null}}
|
|
1232
|
+
*/
|
|
1233
|
+
function defaultResolve(specifier, context = {}) {
|
|
1234
|
+
const { parentURL } = context;
|
|
1235
|
+
assert.ok(parentURL !== void 0, "expected `parentURL` to be defined");
|
|
1236
|
+
throwIfInvalidParentURL(parentURL);
|
|
1237
|
+
/** @type {URL | undefined} */
|
|
1238
|
+
let parsedParentURL;
|
|
1239
|
+
if (parentURL) try {
|
|
1240
|
+
parsedParentURL = new URL(parentURL);
|
|
1241
|
+
} catch {}
|
|
1242
|
+
/** @type {URL | undefined} */
|
|
1243
|
+
let parsed;
|
|
1244
|
+
/** @type {string | undefined} */
|
|
1245
|
+
let protocol;
|
|
1246
|
+
try {
|
|
1247
|
+
parsed = shouldBeTreatedAsRelativeOrAbsolutePath(specifier) ? new URL(specifier, parsedParentURL) : new URL(specifier);
|
|
1248
|
+
protocol = parsed.protocol;
|
|
1249
|
+
if (protocol === "data:") return {
|
|
1250
|
+
url: parsed.href,
|
|
1251
|
+
format: null
|
|
1252
|
+
};
|
|
1253
|
+
} catch {}
|
|
1254
|
+
const maybeReturn = checkIfDisallowedImport(specifier, parsed, parsedParentURL);
|
|
1255
|
+
if (maybeReturn) return maybeReturn;
|
|
1256
|
+
if (protocol === void 0 && parsed) protocol = parsed.protocol;
|
|
1257
|
+
if (protocol === "node:") return { url: specifier };
|
|
1258
|
+
if (parsed && parsed.protocol === "node:") return { url: specifier };
|
|
1259
|
+
const conditions = getConditionsSet(context.conditions);
|
|
1260
|
+
const url = moduleResolve(specifier, new URL(parentURL), conditions, false);
|
|
1261
|
+
return {
|
|
1262
|
+
url: url.href,
|
|
1263
|
+
format: defaultGetFormatWithoutErrors(url, { parentURL })
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
//#endregion
|
|
1267
|
+
//#region ../node_modules/import-meta-resolve/index.js
|
|
1268
|
+
/**
|
|
1269
|
+
* @typedef {import('./lib/errors.js').ErrnoException} ErrnoException
|
|
1270
|
+
*/
|
|
1271
|
+
/**
|
|
1272
|
+
* Match `import.meta.resolve` except that `parent` is required (you can pass
|
|
1273
|
+
* `import.meta.url`).
|
|
1274
|
+
*
|
|
1275
|
+
* @param {string} specifier
|
|
1276
|
+
* The module specifier to resolve relative to parent
|
|
1277
|
+
* (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`,
|
|
1278
|
+
* etc).
|
|
1279
|
+
* @param {string} parent
|
|
1280
|
+
* The absolute parent module URL to resolve from.
|
|
1281
|
+
* You must pass `import.meta.url` or something else.
|
|
1282
|
+
* @returns {string}
|
|
1283
|
+
* Returns a string to a full `file:`, `data:`, or `node:` URL
|
|
1284
|
+
* to the found thing.
|
|
1285
|
+
*/
|
|
1286
|
+
function resolve$1(specifier, parent) {
|
|
1287
|
+
if (!parent) throw new Error("Please pass `parent`: `import-meta-resolve` cannot ponyfill that");
|
|
1288
|
+
try {
|
|
1289
|
+
return defaultResolve(specifier, { parentURL: parent }).url;
|
|
1290
|
+
} catch (error) {
|
|
1291
|
+
const exception = error;
|
|
1292
|
+
if ((exception.code === "ERR_UNSUPPORTED_DIR_IMPORT" || exception.code === "ERR_MODULE_NOT_FOUND") && typeof exception.url === "string") return exception.url;
|
|
1293
|
+
throw error;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
//#endregion
|
|
1297
|
+
//#region ../node_modules/semver/internal/lrucache.js
|
|
1298
|
+
var require_lrucache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1299
|
+
var LRUCache = class {
|
|
1300
|
+
constructor() {
|
|
1301
|
+
this.max = 1e3;
|
|
1302
|
+
this.map = /* @__PURE__ */ new Map();
|
|
1303
|
+
}
|
|
1304
|
+
get(key) {
|
|
1305
|
+
const value = this.map.get(key);
|
|
1306
|
+
if (value === void 0) return;
|
|
1307
|
+
else {
|
|
1308
|
+
this.map.delete(key);
|
|
1309
|
+
this.map.set(key, value);
|
|
1310
|
+
return value;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
delete(key) {
|
|
1314
|
+
return this.map.delete(key);
|
|
1315
|
+
}
|
|
1316
|
+
set(key, value) {
|
|
1317
|
+
if (!this.delete(key) && value !== void 0) {
|
|
1318
|
+
if (this.map.size >= this.max) {
|
|
1319
|
+
const firstKey = this.map.keys().next().value;
|
|
1320
|
+
this.delete(firstKey);
|
|
1321
|
+
}
|
|
1322
|
+
this.map.set(key, value);
|
|
1323
|
+
}
|
|
1324
|
+
return this;
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
module.exports = LRUCache;
|
|
1328
|
+
}));
|
|
1329
|
+
//#endregion
|
|
1330
|
+
//#region ../node_modules/semver/internal/parse-options.js
|
|
1331
|
+
var require_parse_options = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1332
|
+
var looseOption = Object.freeze({ loose: true });
|
|
1333
|
+
var emptyOpts = Object.freeze({});
|
|
1334
|
+
var parseOptions = (options) => {
|
|
1335
|
+
if (!options) return emptyOpts;
|
|
1336
|
+
if (typeof options !== "object") return looseOption;
|
|
1337
|
+
return options;
|
|
1338
|
+
};
|
|
1339
|
+
module.exports = parseOptions;
|
|
1340
|
+
}));
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region ../node_modules/semver/internal/constants.js
|
|
1343
|
+
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1344
|
+
var SEMVER_SPEC_VERSION = "2.0.0";
|
|
1345
|
+
var MAX_LENGTH = 256;
|
|
1346
|
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
|
|
1347
|
+
module.exports = {
|
|
1348
|
+
MAX_LENGTH,
|
|
1349
|
+
MAX_SAFE_COMPONENT_LENGTH: 16,
|
|
1350
|
+
MAX_SAFE_BUILD_LENGTH: MAX_LENGTH - 6,
|
|
1351
|
+
MAX_SAFE_INTEGER,
|
|
1352
|
+
RELEASE_TYPES: [
|
|
1353
|
+
"major",
|
|
1354
|
+
"premajor",
|
|
1355
|
+
"minor",
|
|
1356
|
+
"preminor",
|
|
1357
|
+
"patch",
|
|
1358
|
+
"prepatch",
|
|
1359
|
+
"prerelease"
|
|
1360
|
+
],
|
|
1361
|
+
SEMVER_SPEC_VERSION,
|
|
1362
|
+
FLAG_INCLUDE_PRERELEASE: 1,
|
|
1363
|
+
FLAG_LOOSE: 2
|
|
1364
|
+
};
|
|
1365
|
+
}));
|
|
1366
|
+
//#endregion
|
|
1367
|
+
//#region ../node_modules/semver/internal/debug.js
|
|
1368
|
+
var require_debug = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1369
|
+
module.exports = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {};
|
|
1370
|
+
}));
|
|
1371
|
+
//#endregion
|
|
1372
|
+
//#region ../node_modules/semver/internal/re.js
|
|
1373
|
+
var require_re = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1374
|
+
var { MAX_SAFE_COMPONENT_LENGTH, MAX_SAFE_BUILD_LENGTH, MAX_LENGTH } = require_constants();
|
|
1375
|
+
var debug = require_debug();
|
|
1376
|
+
exports = module.exports = {};
|
|
1377
|
+
var re = exports.re = [];
|
|
1378
|
+
var safeRe = exports.safeRe = [];
|
|
1379
|
+
var src = exports.src = [];
|
|
1380
|
+
var safeSrc = exports.safeSrc = [];
|
|
1381
|
+
var t = exports.t = {};
|
|
1382
|
+
var R = 0;
|
|
1383
|
+
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
1384
|
+
var safeRegexReplacements = [
|
|
1385
|
+
["\\s", 1],
|
|
1386
|
+
["\\d", MAX_LENGTH],
|
|
1387
|
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
|
|
1388
|
+
];
|
|
1389
|
+
var makeSafeRegex = (value) => {
|
|
1390
|
+
for (const [token, max] of safeRegexReplacements) value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
|
|
1391
|
+
return value;
|
|
1392
|
+
};
|
|
1393
|
+
var createToken = (name, value, isGlobal) => {
|
|
1394
|
+
const safe = makeSafeRegex(value);
|
|
1395
|
+
const index = R++;
|
|
1396
|
+
debug(name, index, value);
|
|
1397
|
+
t[name] = index;
|
|
1398
|
+
src[index] = value;
|
|
1399
|
+
safeSrc[index] = safe;
|
|
1400
|
+
re[index] = new RegExp(value, isGlobal ? "g" : void 0);
|
|
1401
|
+
safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
|
|
1402
|
+
};
|
|
1403
|
+
createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
|
|
1404
|
+
createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
|
|
1405
|
+
createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
1406
|
+
createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
|
|
1407
|
+
createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
1408
|
+
createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
|
|
1409
|
+
createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
1410
|
+
createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
1411
|
+
createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
1412
|
+
createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
|
|
1413
|
+
createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
1414
|
+
createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
|
|
1415
|
+
createToken("FULL", `^${src[t.FULLPLAIN]}$`);
|
|
1416
|
+
createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
|
|
1417
|
+
createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
|
|
1418
|
+
createToken("GTLT", "((?:<|>)?=?)");
|
|
1419
|
+
createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
1420
|
+
createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
1421
|
+
createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
|
|
1422
|
+
createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
|
|
1423
|
+
createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
1424
|
+
createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
1425
|
+
createToken("COERCEPLAIN", `(^|[^\\d])(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
1426
|
+
createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
1427
|
+
createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
|
|
1428
|
+
createToken("COERCERTL", src[t.COERCE], true);
|
|
1429
|
+
createToken("COERCERTLFULL", src[t.COERCEFULL], true);
|
|
1430
|
+
createToken("LONETILDE", "(?:~>?)");
|
|
1431
|
+
createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
1432
|
+
exports.tildeTrimReplace = "$1~";
|
|
1433
|
+
createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
1434
|
+
createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
1435
|
+
createToken("LONECARET", "(?:\\^)");
|
|
1436
|
+
createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
1437
|
+
exports.caretTrimReplace = "$1^";
|
|
1438
|
+
createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
1439
|
+
createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
1440
|
+
createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
1441
|
+
createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
1442
|
+
createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
1443
|
+
exports.comparatorTrimReplace = "$1$2$3";
|
|
1444
|
+
createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
|
|
1445
|
+
createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
|
|
1446
|
+
createToken("STAR", "(<|>)?=?\\s*\\*");
|
|
1447
|
+
createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
|
|
1448
|
+
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
|
|
1449
|
+
}));
|
|
1450
|
+
//#endregion
|
|
1451
|
+
//#region ../node_modules/semver/internal/identifiers.js
|
|
1452
|
+
var require_identifiers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1453
|
+
var numeric = /^[0-9]+$/;
|
|
1454
|
+
var compareIdentifiers = (a, b) => {
|
|
1455
|
+
if (typeof a === "number" && typeof b === "number") return a === b ? 0 : a < b ? -1 : 1;
|
|
1456
|
+
const anum = numeric.test(a);
|
|
1457
|
+
const bnum = numeric.test(b);
|
|
1458
|
+
if (anum && bnum) {
|
|
1459
|
+
a = +a;
|
|
1460
|
+
b = +b;
|
|
1461
|
+
}
|
|
1462
|
+
return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
|
|
1463
|
+
};
|
|
1464
|
+
var rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
|
|
1465
|
+
module.exports = {
|
|
1466
|
+
compareIdentifiers,
|
|
1467
|
+
rcompareIdentifiers
|
|
1468
|
+
};
|
|
1469
|
+
}));
|
|
1470
|
+
//#endregion
|
|
1471
|
+
//#region ../node_modules/semver/classes/semver.js
|
|
1472
|
+
var require_semver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1473
|
+
var debug = require_debug();
|
|
1474
|
+
var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
|
|
1475
|
+
var { safeRe: re, t } = require_re();
|
|
1476
|
+
var parseOptions = require_parse_options();
|
|
1477
|
+
var { compareIdentifiers } = require_identifiers();
|
|
1478
|
+
var isPrereleaseIdentifier = (prerelease, identifier) => {
|
|
1479
|
+
const identifiers = identifier.split(".");
|
|
1480
|
+
if (identifiers.length > prerelease.length) return false;
|
|
1481
|
+
for (let i = 0; i < identifiers.length; i++) if (compareIdentifiers(prerelease[i], identifiers[i]) !== 0) return false;
|
|
1482
|
+
return true;
|
|
1483
|
+
};
|
|
1484
|
+
module.exports = class SemVer {
|
|
1485
|
+
constructor(version, options) {
|
|
1486
|
+
options = parseOptions(options);
|
|
1487
|
+
if (version instanceof SemVer) if (version.loose === !!options.loose && version.includePrerelease === !!options.includePrerelease) return version;
|
|
1488
|
+
else version = version.version;
|
|
1489
|
+
else if (typeof version !== "string") throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`);
|
|
1490
|
+
if (version.length > MAX_LENGTH) throw new TypeError(`version is longer than ${MAX_LENGTH} characters`);
|
|
1491
|
+
debug("SemVer", version, options);
|
|
1492
|
+
this.options = options;
|
|
1493
|
+
this.loose = !!options.loose;
|
|
1494
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
1495
|
+
const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
|
|
1496
|
+
if (!m) throw new TypeError(`Invalid Version: ${version}`);
|
|
1497
|
+
this.raw = version;
|
|
1498
|
+
this.major = +m[1];
|
|
1499
|
+
this.minor = +m[2];
|
|
1500
|
+
this.patch = +m[3];
|
|
1501
|
+
if (this.major > MAX_SAFE_INTEGER || this.major < 0) throw new TypeError("Invalid major version");
|
|
1502
|
+
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) throw new TypeError("Invalid minor version");
|
|
1503
|
+
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) throw new TypeError("Invalid patch version");
|
|
1504
|
+
if (!m[4]) this.prerelease = [];
|
|
1505
|
+
else this.prerelease = m[4].split(".").map((id) => {
|
|
1506
|
+
if (/^[0-9]+$/.test(id)) {
|
|
1507
|
+
const num = +id;
|
|
1508
|
+
if (num >= 0 && num < MAX_SAFE_INTEGER) return num;
|
|
1509
|
+
}
|
|
1510
|
+
return id;
|
|
1511
|
+
});
|
|
1512
|
+
this.build = m[5] ? m[5].split(".") : [];
|
|
1513
|
+
this.format();
|
|
1514
|
+
}
|
|
1515
|
+
format() {
|
|
1516
|
+
this.version = `${this.major}.${this.minor}.${this.patch}`;
|
|
1517
|
+
if (this.prerelease.length) this.version += `-${this.prerelease.join(".")}`;
|
|
1518
|
+
return this.version;
|
|
1519
|
+
}
|
|
1520
|
+
toString() {
|
|
1521
|
+
return this.version;
|
|
1522
|
+
}
|
|
1523
|
+
compare(other) {
|
|
1524
|
+
debug("SemVer.compare", this.version, this.options, other);
|
|
1525
|
+
if (!(other instanceof SemVer)) {
|
|
1526
|
+
if (typeof other === "string" && other === this.version) return 0;
|
|
1527
|
+
other = new SemVer(other, this.options);
|
|
1528
|
+
}
|
|
1529
|
+
if (other.version === this.version) return 0;
|
|
1530
|
+
return this.compareMain(other) || this.comparePre(other);
|
|
1531
|
+
}
|
|
1532
|
+
compareMain(other) {
|
|
1533
|
+
if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
|
|
1534
|
+
if (this.major < other.major) return -1;
|
|
1535
|
+
if (this.major > other.major) return 1;
|
|
1536
|
+
if (this.minor < other.minor) return -1;
|
|
1537
|
+
if (this.minor > other.minor) return 1;
|
|
1538
|
+
if (this.patch < other.patch) return -1;
|
|
1539
|
+
if (this.patch > other.patch) return 1;
|
|
1540
|
+
return 0;
|
|
1541
|
+
}
|
|
1542
|
+
comparePre(other) {
|
|
1543
|
+
if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
|
|
1544
|
+
if (this.prerelease.length && !other.prerelease.length) return -1;
|
|
1545
|
+
else if (!this.prerelease.length && other.prerelease.length) return 1;
|
|
1546
|
+
else if (!this.prerelease.length && !other.prerelease.length) return 0;
|
|
1547
|
+
let i = 0;
|
|
1548
|
+
do {
|
|
1549
|
+
const a = this.prerelease[i];
|
|
1550
|
+
const b = other.prerelease[i];
|
|
1551
|
+
debug("prerelease compare", i, a, b);
|
|
1552
|
+
if (a === void 0 && b === void 0) return 0;
|
|
1553
|
+
else if (b === void 0) return 1;
|
|
1554
|
+
else if (a === void 0) return -1;
|
|
1555
|
+
else if (a === b) continue;
|
|
1556
|
+
else return compareIdentifiers(a, b);
|
|
1557
|
+
} while (++i);
|
|
1558
|
+
}
|
|
1559
|
+
compareBuild(other) {
|
|
1560
|
+
if (!(other instanceof SemVer)) other = new SemVer(other, this.options);
|
|
1561
|
+
let i = 0;
|
|
1562
|
+
do {
|
|
1563
|
+
const a = this.build[i];
|
|
1564
|
+
const b = other.build[i];
|
|
1565
|
+
debug("build compare", i, a, b);
|
|
1566
|
+
if (a === void 0 && b === void 0) return 0;
|
|
1567
|
+
else if (b === void 0) return 1;
|
|
1568
|
+
else if (a === void 0) return -1;
|
|
1569
|
+
else if (a === b) continue;
|
|
1570
|
+
else return compareIdentifiers(a, b);
|
|
1571
|
+
} while (++i);
|
|
1572
|
+
}
|
|
1573
|
+
inc(release, identifier, identifierBase) {
|
|
1574
|
+
if (release.startsWith("pre")) {
|
|
1575
|
+
if (!identifier && identifierBase === false) throw new Error("invalid increment argument: identifier is empty");
|
|
1576
|
+
if (identifier) {
|
|
1577
|
+
const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
|
|
1578
|
+
if (!match || match[1] !== identifier) throw new Error(`invalid identifier: ${identifier}`);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
switch (release) {
|
|
1582
|
+
case "premajor":
|
|
1583
|
+
this.prerelease.length = 0;
|
|
1584
|
+
this.patch = 0;
|
|
1585
|
+
this.minor = 0;
|
|
1586
|
+
this.major++;
|
|
1587
|
+
this.inc("pre", identifier, identifierBase);
|
|
1588
|
+
break;
|
|
1589
|
+
case "preminor":
|
|
1590
|
+
this.prerelease.length = 0;
|
|
1591
|
+
this.patch = 0;
|
|
1592
|
+
this.minor++;
|
|
1593
|
+
this.inc("pre", identifier, identifierBase);
|
|
1594
|
+
break;
|
|
1595
|
+
case "prepatch":
|
|
1596
|
+
this.prerelease.length = 0;
|
|
1597
|
+
this.inc("patch", identifier, identifierBase);
|
|
1598
|
+
this.inc("pre", identifier, identifierBase);
|
|
1599
|
+
break;
|
|
1600
|
+
case "prerelease":
|
|
1601
|
+
if (this.prerelease.length === 0) this.inc("patch", identifier, identifierBase);
|
|
1602
|
+
this.inc("pre", identifier, identifierBase);
|
|
1603
|
+
break;
|
|
1604
|
+
case "release":
|
|
1605
|
+
if (this.prerelease.length === 0) throw new Error(`version ${this.raw} is not a prerelease`);
|
|
1606
|
+
this.prerelease.length = 0;
|
|
1607
|
+
break;
|
|
1608
|
+
case "major":
|
|
1609
|
+
if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) this.major++;
|
|
1610
|
+
this.minor = 0;
|
|
1611
|
+
this.patch = 0;
|
|
1612
|
+
this.prerelease = [];
|
|
1613
|
+
break;
|
|
1614
|
+
case "minor":
|
|
1615
|
+
if (this.patch !== 0 || this.prerelease.length === 0) this.minor++;
|
|
1616
|
+
this.patch = 0;
|
|
1617
|
+
this.prerelease = [];
|
|
1618
|
+
break;
|
|
1619
|
+
case "patch":
|
|
1620
|
+
if (this.prerelease.length === 0) this.patch++;
|
|
1621
|
+
this.prerelease = [];
|
|
1622
|
+
break;
|
|
1623
|
+
case "pre": {
|
|
1624
|
+
const base = Number(identifierBase) ? 1 : 0;
|
|
1625
|
+
if (this.prerelease.length === 0) this.prerelease = [base];
|
|
1626
|
+
else {
|
|
1627
|
+
let i = this.prerelease.length;
|
|
1628
|
+
while (--i >= 0) if (typeof this.prerelease[i] === "number") {
|
|
1629
|
+
this.prerelease[i]++;
|
|
1630
|
+
i = -2;
|
|
1631
|
+
}
|
|
1632
|
+
if (i === -1) {
|
|
1633
|
+
if (identifier === this.prerelease.join(".") && identifierBase === false) throw new Error("invalid increment argument: identifier already exists");
|
|
1634
|
+
this.prerelease.push(base);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
if (identifier) {
|
|
1638
|
+
let prerelease = [identifier, base];
|
|
1639
|
+
if (identifierBase === false) prerelease = [identifier];
|
|
1640
|
+
if (isPrereleaseIdentifier(this.prerelease, identifier)) {
|
|
1641
|
+
const prereleaseBase = this.prerelease[identifier.split(".").length];
|
|
1642
|
+
if (isNaN(prereleaseBase)) this.prerelease = prerelease;
|
|
1643
|
+
} else this.prerelease = prerelease;
|
|
1644
|
+
}
|
|
1645
|
+
break;
|
|
1646
|
+
}
|
|
1647
|
+
default: throw new Error(`invalid increment argument: ${release}`);
|
|
1648
|
+
}
|
|
1649
|
+
this.raw = this.format();
|
|
1650
|
+
if (this.build.length) this.raw += `+${this.build.join(".")}`;
|
|
1651
|
+
return this;
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
}));
|
|
1655
|
+
//#endregion
|
|
1656
|
+
//#region ../node_modules/semver/functions/compare.js
|
|
1657
|
+
var require_compare = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1658
|
+
var SemVer = require_semver();
|
|
1659
|
+
var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
1660
|
+
module.exports = compare;
|
|
1661
|
+
}));
|
|
1662
|
+
//#endregion
|
|
1663
|
+
//#region ../node_modules/semver/functions/eq.js
|
|
1664
|
+
var require_eq = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1665
|
+
var compare = require_compare();
|
|
1666
|
+
var eq = (a, b, loose) => compare(a, b, loose) === 0;
|
|
1667
|
+
module.exports = eq;
|
|
1668
|
+
}));
|
|
1669
|
+
//#endregion
|
|
1670
|
+
//#region ../node_modules/semver/functions/neq.js
|
|
1671
|
+
var require_neq = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1672
|
+
var compare = require_compare();
|
|
1673
|
+
var neq = (a, b, loose) => compare(a, b, loose) !== 0;
|
|
1674
|
+
module.exports = neq;
|
|
1675
|
+
}));
|
|
1676
|
+
//#endregion
|
|
1677
|
+
//#region ../node_modules/semver/functions/gt.js
|
|
1678
|
+
var require_gt = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1679
|
+
var compare = require_compare();
|
|
1680
|
+
var gt = (a, b, loose) => compare(a, b, loose) > 0;
|
|
1681
|
+
module.exports = gt;
|
|
1682
|
+
}));
|
|
1683
|
+
//#endregion
|
|
1684
|
+
//#region ../node_modules/semver/functions/gte.js
|
|
1685
|
+
var require_gte = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1686
|
+
var compare = require_compare();
|
|
1687
|
+
var gte = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
1688
|
+
module.exports = gte;
|
|
1689
|
+
}));
|
|
1690
|
+
//#endregion
|
|
1691
|
+
//#region ../node_modules/semver/functions/lt.js
|
|
1692
|
+
var require_lt = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1693
|
+
var compare = require_compare();
|
|
1694
|
+
var lt = (a, b, loose) => compare(a, b, loose) < 0;
|
|
1695
|
+
module.exports = lt;
|
|
1696
|
+
}));
|
|
1697
|
+
//#endregion
|
|
1698
|
+
//#region ../node_modules/semver/functions/lte.js
|
|
1699
|
+
var require_lte = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1700
|
+
var compare = require_compare();
|
|
1701
|
+
var lte = (a, b, loose) => compare(a, b, loose) <= 0;
|
|
1702
|
+
module.exports = lte;
|
|
1703
|
+
}));
|
|
1704
|
+
//#endregion
|
|
1705
|
+
//#region ../node_modules/semver/functions/cmp.js
|
|
1706
|
+
var require_cmp = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1707
|
+
var eq = require_eq();
|
|
1708
|
+
var neq = require_neq();
|
|
1709
|
+
var gt = require_gt();
|
|
1710
|
+
var gte = require_gte();
|
|
1711
|
+
var lt = require_lt();
|
|
1712
|
+
var lte = require_lte();
|
|
1713
|
+
var cmp = (a, op, b, loose) => {
|
|
1714
|
+
switch (op) {
|
|
1715
|
+
case "===":
|
|
1716
|
+
if (typeof a === "object") a = a.version;
|
|
1717
|
+
if (typeof b === "object") b = b.version;
|
|
1718
|
+
return a === b;
|
|
1719
|
+
case "!==":
|
|
1720
|
+
if (typeof a === "object") a = a.version;
|
|
1721
|
+
if (typeof b === "object") b = b.version;
|
|
1722
|
+
return a !== b;
|
|
1723
|
+
case "":
|
|
1724
|
+
case "=":
|
|
1725
|
+
case "==": return eq(a, b, loose);
|
|
1726
|
+
case "!=": return neq(a, b, loose);
|
|
1727
|
+
case ">": return gt(a, b, loose);
|
|
1728
|
+
case ">=": return gte(a, b, loose);
|
|
1729
|
+
case "<": return lt(a, b, loose);
|
|
1730
|
+
case "<=": return lte(a, b, loose);
|
|
1731
|
+
default: throw new TypeError(`Invalid operator: ${op}`);
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
module.exports = cmp;
|
|
1735
|
+
}));
|
|
1736
|
+
//#endregion
|
|
1737
|
+
//#region ../node_modules/semver/classes/comparator.js
|
|
1738
|
+
var require_comparator = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1739
|
+
var ANY = Symbol("SemVer ANY");
|
|
1740
|
+
module.exports = class Comparator {
|
|
1741
|
+
static get ANY() {
|
|
1742
|
+
return ANY;
|
|
1743
|
+
}
|
|
1744
|
+
constructor(comp, options) {
|
|
1745
|
+
options = parseOptions(options);
|
|
1746
|
+
if (comp instanceof Comparator) if (comp.loose === !!options.loose) return comp;
|
|
1747
|
+
else comp = comp.value;
|
|
1748
|
+
comp = comp.trim().split(/\s+/).join(" ");
|
|
1749
|
+
debug("comparator", comp, options);
|
|
1750
|
+
this.options = options;
|
|
1751
|
+
this.loose = !!options.loose;
|
|
1752
|
+
this.parse(comp);
|
|
1753
|
+
if (this.semver === ANY) this.value = "";
|
|
1754
|
+
else this.value = this.operator + this.semver.version;
|
|
1755
|
+
debug("comp", this);
|
|
1756
|
+
}
|
|
1757
|
+
parse(comp) {
|
|
1758
|
+
const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
|
|
1759
|
+
const m = comp.match(r);
|
|
1760
|
+
if (!m) throw new TypeError(`Invalid comparator: ${comp}`);
|
|
1761
|
+
this.operator = m[1] !== void 0 ? m[1] : "";
|
|
1762
|
+
if (this.operator === "=") this.operator = "";
|
|
1763
|
+
if (!m[2]) this.semver = ANY;
|
|
1764
|
+
else this.semver = new SemVer(m[2], this.options.loose);
|
|
1765
|
+
}
|
|
1766
|
+
toString() {
|
|
1767
|
+
return this.value;
|
|
1768
|
+
}
|
|
1769
|
+
test(version) {
|
|
1770
|
+
debug("Comparator.test", version, this.options.loose);
|
|
1771
|
+
if (this.semver === ANY || version === ANY) return true;
|
|
1772
|
+
if (typeof version === "string") try {
|
|
1773
|
+
version = new SemVer(version, this.options);
|
|
1774
|
+
} catch (er) {
|
|
1775
|
+
return false;
|
|
1776
|
+
}
|
|
1777
|
+
return cmp(version, this.operator, this.semver, this.options);
|
|
1778
|
+
}
|
|
1779
|
+
intersects(comp, options) {
|
|
1780
|
+
if (!(comp instanceof Comparator)) throw new TypeError("a Comparator is required");
|
|
1781
|
+
if (this.operator === "") {
|
|
1782
|
+
if (this.value === "") return true;
|
|
1783
|
+
return new Range(comp.value, options).test(this.value);
|
|
1784
|
+
} else if (comp.operator === "") {
|
|
1785
|
+
if (comp.value === "") return true;
|
|
1786
|
+
return new Range(this.value, options).test(comp.semver);
|
|
1787
|
+
}
|
|
1788
|
+
options = parseOptions(options);
|
|
1789
|
+
if (options.includePrerelease && (this.value === "<0.0.0-0" || comp.value === "<0.0.0-0")) return false;
|
|
1790
|
+
if (!options.includePrerelease && (this.value.startsWith("<0.0.0") || comp.value.startsWith("<0.0.0"))) return false;
|
|
1791
|
+
if (this.operator.startsWith(">") && comp.operator.startsWith(">")) return true;
|
|
1792
|
+
if (this.operator.startsWith("<") && comp.operator.startsWith("<")) return true;
|
|
1793
|
+
if (this.semver.version === comp.semver.version && this.operator.includes("=") && comp.operator.includes("=")) return true;
|
|
1794
|
+
if (cmp(this.semver, "<", comp.semver, options) && this.operator.startsWith(">") && comp.operator.startsWith("<")) return true;
|
|
1795
|
+
if (cmp(this.semver, ">", comp.semver, options) && this.operator.startsWith("<") && comp.operator.startsWith(">")) return true;
|
|
1796
|
+
return false;
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
var parseOptions = require_parse_options();
|
|
1800
|
+
var { safeRe: re, t } = require_re();
|
|
1801
|
+
var cmp = require_cmp();
|
|
1802
|
+
var debug = require_debug();
|
|
1803
|
+
var SemVer = require_semver();
|
|
1804
|
+
var Range = require_range();
|
|
1805
|
+
}));
|
|
1806
|
+
//#endregion
|
|
1807
|
+
//#region ../node_modules/semver/classes/range.js
|
|
1808
|
+
var require_range = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1809
|
+
var SPACE_CHARACTERS = /\s+/g;
|
|
1810
|
+
module.exports = class Range {
|
|
1811
|
+
constructor(range, options) {
|
|
1812
|
+
options = parseOptions(options);
|
|
1813
|
+
if (range instanceof Range) if (range.loose === !!options.loose && range.includePrerelease === !!options.includePrerelease) return range;
|
|
1814
|
+
else return new Range(range.raw, options);
|
|
1815
|
+
if (range instanceof Comparator) {
|
|
1816
|
+
this.raw = range.value;
|
|
1817
|
+
this.set = [[range]];
|
|
1818
|
+
this.formatted = void 0;
|
|
1819
|
+
return this;
|
|
1820
|
+
}
|
|
1821
|
+
this.options = options;
|
|
1822
|
+
this.loose = !!options.loose;
|
|
1823
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
1824
|
+
this.raw = range.trim().replace(SPACE_CHARACTERS, " ");
|
|
1825
|
+
this.set = this.raw.split("||").map((r) => this.parseRange(r.trim())).filter((c) => c.length);
|
|
1826
|
+
if (!this.set.length) throw new TypeError(`Invalid SemVer Range: ${this.raw}`);
|
|
1827
|
+
if (this.set.length > 1) {
|
|
1828
|
+
const first = this.set[0];
|
|
1829
|
+
this.set = this.set.filter((c) => !isNullSet(c[0]));
|
|
1830
|
+
if (this.set.length === 0) this.set = [first];
|
|
1831
|
+
else if (this.set.length > 1) {
|
|
1832
|
+
for (const c of this.set) if (c.length === 1 && isAny(c[0])) {
|
|
1833
|
+
this.set = [c];
|
|
1834
|
+
break;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
this.formatted = void 0;
|
|
1839
|
+
}
|
|
1840
|
+
get range() {
|
|
1841
|
+
if (this.formatted === void 0) {
|
|
1842
|
+
this.formatted = "";
|
|
1843
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1844
|
+
if (i > 0) this.formatted += "||";
|
|
1845
|
+
const comps = this.set[i];
|
|
1846
|
+
for (let k = 0; k < comps.length; k++) {
|
|
1847
|
+
if (k > 0) this.formatted += " ";
|
|
1848
|
+
this.formatted += comps[k].toString().trim();
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
return this.formatted;
|
|
1853
|
+
}
|
|
1854
|
+
format() {
|
|
1855
|
+
return this.range;
|
|
1856
|
+
}
|
|
1857
|
+
toString() {
|
|
1858
|
+
return this.range;
|
|
1859
|
+
}
|
|
1860
|
+
parseRange(range) {
|
|
1861
|
+
range = range.replace(BUILDSTRIPRE, "");
|
|
1862
|
+
const memoKey = ((this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) | (this.options.loose && FLAG_LOOSE)) + ":" + range;
|
|
1863
|
+
const cached = cache.get(memoKey);
|
|
1864
|
+
if (cached) return cached;
|
|
1865
|
+
const loose = this.options.loose;
|
|
1866
|
+
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
|
|
1867
|
+
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
1868
|
+
debug("hyphen replace", range);
|
|
1869
|
+
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
1870
|
+
debug("comparator trim", range);
|
|
1871
|
+
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
|
1872
|
+
debug("tilde trim", range);
|
|
1873
|
+
range = range.replace(re[t.CARETTRIM], caretTrimReplace);
|
|
1874
|
+
debug("caret trim", range);
|
|
1875
|
+
let rangeList = range.split(" ").map((comp) => parseComparator(comp, this.options)).join(" ").split(/\s+/).map((comp) => replaceGTE0(comp, this.options));
|
|
1876
|
+
if (loose) rangeList = rangeList.filter((comp) => {
|
|
1877
|
+
debug("loose invalid filter", comp, this.options);
|
|
1878
|
+
return !!comp.match(re[t.COMPARATORLOOSE]);
|
|
1879
|
+
});
|
|
1880
|
+
debug("range list", rangeList);
|
|
1881
|
+
const rangeMap = /* @__PURE__ */ new Map();
|
|
1882
|
+
const comparators = rangeList.map((comp) => new Comparator(comp, this.options));
|
|
1883
|
+
for (const comp of comparators) {
|
|
1884
|
+
if (isNullSet(comp)) return [comp];
|
|
1885
|
+
rangeMap.set(comp.value, comp);
|
|
1886
|
+
}
|
|
1887
|
+
if (rangeMap.size > 1 && rangeMap.has("")) rangeMap.delete("");
|
|
1888
|
+
const result = [...rangeMap.values()];
|
|
1889
|
+
cache.set(memoKey, result);
|
|
1890
|
+
return result;
|
|
1891
|
+
}
|
|
1892
|
+
intersects(range, options) {
|
|
1893
|
+
if (!(range instanceof Range)) throw new TypeError("a Range is required");
|
|
1894
|
+
return this.set.some((thisComparators) => {
|
|
1895
|
+
return isSatisfiable(thisComparators, options) && range.set.some((rangeComparators) => {
|
|
1896
|
+
return isSatisfiable(rangeComparators, options) && thisComparators.every((thisComparator) => {
|
|
1897
|
+
return rangeComparators.every((rangeComparator) => {
|
|
1898
|
+
return thisComparator.intersects(rangeComparator, options);
|
|
1899
|
+
});
|
|
1900
|
+
});
|
|
1901
|
+
});
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
test(version) {
|
|
1905
|
+
if (!version) return false;
|
|
1906
|
+
if (typeof version === "string") try {
|
|
1907
|
+
version = new SemVer(version, this.options);
|
|
1908
|
+
} catch (er) {
|
|
1909
|
+
return false;
|
|
1910
|
+
}
|
|
1911
|
+
for (let i = 0; i < this.set.length; i++) if (testSet(this.set[i], version, this.options)) return true;
|
|
1912
|
+
return false;
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
var cache = new (require_lrucache())();
|
|
1916
|
+
var parseOptions = require_parse_options();
|
|
1917
|
+
var Comparator = require_comparator();
|
|
1918
|
+
var debug = require_debug();
|
|
1919
|
+
var SemVer = require_semver();
|
|
1920
|
+
var { safeRe: re, src, t, comparatorTrimReplace, tildeTrimReplace, caretTrimReplace } = require_re();
|
|
1921
|
+
var { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require_constants();
|
|
1922
|
+
var BUILDSTRIPRE = new RegExp(src[t.BUILD], "g");
|
|
1923
|
+
var isNullSet = (c) => c.value === "<0.0.0-0";
|
|
1924
|
+
var isAny = (c) => c.value === "";
|
|
1925
|
+
var isSatisfiable = (comparators, options) => {
|
|
1926
|
+
let result = true;
|
|
1927
|
+
const remainingComparators = comparators.slice();
|
|
1928
|
+
let testComparator = remainingComparators.pop();
|
|
1929
|
+
while (result && remainingComparators.length) {
|
|
1930
|
+
result = remainingComparators.every((otherComparator) => {
|
|
1931
|
+
return testComparator.intersects(otherComparator, options);
|
|
1932
|
+
});
|
|
1933
|
+
testComparator = remainingComparators.pop();
|
|
1934
|
+
}
|
|
1935
|
+
return result;
|
|
1936
|
+
};
|
|
1937
|
+
var parseComparator = (comp, options) => {
|
|
1938
|
+
comp = comp.replace(re[t.BUILD], "");
|
|
1939
|
+
debug("comp", comp, options);
|
|
1940
|
+
comp = replaceCarets(comp, options);
|
|
1941
|
+
debug("caret", comp);
|
|
1942
|
+
comp = replaceTildes(comp, options);
|
|
1943
|
+
debug("tildes", comp);
|
|
1944
|
+
comp = replaceXRanges(comp, options);
|
|
1945
|
+
debug("xrange", comp);
|
|
1946
|
+
comp = replaceStars(comp, options);
|
|
1947
|
+
debug("stars", comp);
|
|
1948
|
+
return comp;
|
|
1949
|
+
};
|
|
1950
|
+
var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
|
|
1951
|
+
var invalidXRangeOrder = (M, m, p) => isX(M) && !isX(m) || isX(m) && p && !isX(p);
|
|
1952
|
+
var replaceTildes = (comp, options) => {
|
|
1953
|
+
return comp.trim().split(/\s+/).map((c) => replaceTilde(c, options)).join(" ");
|
|
1954
|
+
};
|
|
1955
|
+
var replaceTilde = (comp, options) => {
|
|
1956
|
+
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
1957
|
+
const z = options.includePrerelease ? "-0" : "";
|
|
1958
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1959
|
+
debug("tilde", comp, _, M, m, p, pr);
|
|
1960
|
+
let ret;
|
|
1961
|
+
if (isX(M)) ret = "";
|
|
1962
|
+
else if (isX(m)) ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
1963
|
+
else if (isX(p)) ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
1964
|
+
else if (pr) {
|
|
1965
|
+
debug("replaceTilde pr", pr);
|
|
1966
|
+
ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
1967
|
+
} else ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
|
1968
|
+
debug("tilde return", ret);
|
|
1969
|
+
return ret;
|
|
1970
|
+
});
|
|
1971
|
+
};
|
|
1972
|
+
var replaceCarets = (comp, options) => {
|
|
1973
|
+
return comp.trim().split(/\s+/).map((c) => replaceCaret(c, options)).join(" ");
|
|
1974
|
+
};
|
|
1975
|
+
var replaceCaret = (comp, options) => {
|
|
1976
|
+
debug("caret", comp, options);
|
|
1977
|
+
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
1978
|
+
const z = options.includePrerelease ? "-0" : "";
|
|
1979
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1980
|
+
debug("caret", comp, _, M, m, p, pr);
|
|
1981
|
+
let ret;
|
|
1982
|
+
if (isX(M)) ret = "";
|
|
1983
|
+
else if (isX(m)) ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
1984
|
+
else if (isX(p)) if (M === "0") ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
1985
|
+
else ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
1986
|
+
else if (pr) {
|
|
1987
|
+
debug("replaceCaret pr", pr);
|
|
1988
|
+
if (M === "0") if (m === "0") ret = `>=${M}.${m}.${p}-${pr} <${M}.${m}.${+p + 1}-0`;
|
|
1989
|
+
else ret = `>=${M}.${m}.${p}-${pr} <${M}.${+m + 1}.0-0`;
|
|
1990
|
+
else ret = `>=${M}.${m}.${p}-${pr} <${+M + 1}.0.0-0`;
|
|
1991
|
+
} else {
|
|
1992
|
+
debug("no pr");
|
|
1993
|
+
if (M === "0") if (m === "0") ret = `>=${M}.${m}.${p} <${M}.${m}.${+p + 1}-0`;
|
|
1994
|
+
else ret = `>=${M}.${m}.${p} <${M}.${+m + 1}.0-0`;
|
|
1995
|
+
else ret = `>=${M}.${m}.${p} <${+M + 1}.0.0-0`;
|
|
1996
|
+
}
|
|
1997
|
+
debug("caret return", ret);
|
|
1998
|
+
return ret;
|
|
1999
|
+
});
|
|
2000
|
+
};
|
|
2001
|
+
var replaceXRanges = (comp, options) => {
|
|
2002
|
+
debug("replaceXRanges", comp, options);
|
|
2003
|
+
return comp.split(/\s+/).map((c) => replaceXRange(c, options)).join(" ");
|
|
2004
|
+
};
|
|
2005
|
+
var replaceXRange = (comp, options) => {
|
|
2006
|
+
comp = comp.trim();
|
|
2007
|
+
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
2008
|
+
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
2009
|
+
debug("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
2010
|
+
if (invalidXRangeOrder(M, m, p)) return comp;
|
|
2011
|
+
const xM = isX(M);
|
|
2012
|
+
const xm = xM || isX(m);
|
|
2013
|
+
const xp = xm || isX(p);
|
|
2014
|
+
const anyX = xp;
|
|
2015
|
+
if (gtlt === "=" && anyX) gtlt = "";
|
|
2016
|
+
pr = options.includePrerelease ? "-0" : "";
|
|
2017
|
+
if (xM) if (gtlt === ">" || gtlt === "<") ret = "<0.0.0-0";
|
|
2018
|
+
else ret = "*";
|
|
2019
|
+
else if (gtlt && anyX) {
|
|
2020
|
+
if (xm) m = 0;
|
|
2021
|
+
p = 0;
|
|
2022
|
+
if (gtlt === ">") {
|
|
2023
|
+
gtlt = ">=";
|
|
2024
|
+
if (xm) {
|
|
2025
|
+
M = +M + 1;
|
|
2026
|
+
m = 0;
|
|
2027
|
+
p = 0;
|
|
2028
|
+
} else {
|
|
2029
|
+
m = +m + 1;
|
|
2030
|
+
p = 0;
|
|
2031
|
+
}
|
|
2032
|
+
} else if (gtlt === "<=") {
|
|
2033
|
+
gtlt = "<";
|
|
2034
|
+
if (xm) M = +M + 1;
|
|
2035
|
+
else m = +m + 1;
|
|
2036
|
+
}
|
|
2037
|
+
if (gtlt === "<") pr = "-0";
|
|
2038
|
+
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
|
2039
|
+
} else if (xm) ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
|
2040
|
+
else if (xp) ret = `>=${M}.${m}.0${pr} <${M}.${+m + 1}.0-0`;
|
|
2041
|
+
debug("xRange return", ret);
|
|
2042
|
+
return ret;
|
|
2043
|
+
});
|
|
2044
|
+
};
|
|
2045
|
+
var replaceStars = (comp, options) => {
|
|
2046
|
+
debug("replaceStars", comp, options);
|
|
2047
|
+
return comp.trim().replace(re[t.STAR], "");
|
|
2048
|
+
};
|
|
2049
|
+
var replaceGTE0 = (comp, options) => {
|
|
2050
|
+
debug("replaceGTE0", comp, options);
|
|
2051
|
+
return comp.trim().replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], "");
|
|
2052
|
+
};
|
|
2053
|
+
var hyphenReplace = (incPr) => ($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr) => {
|
|
2054
|
+
if (isX(fM)) from = "";
|
|
2055
|
+
else if (isX(fm)) from = `>=${fM}.0.0${incPr ? "-0" : ""}`;
|
|
2056
|
+
else if (isX(fp)) from = `>=${fM}.${fm}.0${incPr ? "-0" : ""}`;
|
|
2057
|
+
else if (fpr) from = `>=${from}`;
|
|
2058
|
+
else from = `>=${from}${incPr ? "-0" : ""}`;
|
|
2059
|
+
if (isX(tM)) to = "";
|
|
2060
|
+
else if (isX(tm)) to = `<${+tM + 1}.0.0-0`;
|
|
2061
|
+
else if (isX(tp)) to = `<${tM}.${+tm + 1}.0-0`;
|
|
2062
|
+
else if (tpr) to = `<=${tM}.${tm}.${tp}-${tpr}`;
|
|
2063
|
+
else if (incPr) to = `<${tM}.${tm}.${+tp + 1}-0`;
|
|
2064
|
+
else to = `<=${to}`;
|
|
2065
|
+
return `${from} ${to}`.trim();
|
|
2066
|
+
};
|
|
2067
|
+
var testSet = (set, version, options) => {
|
|
2068
|
+
for (let i = 0; i < set.length; i++) if (!set[i].test(version)) return false;
|
|
2069
|
+
if (version.prerelease.length && !options.includePrerelease) {
|
|
2070
|
+
for (let i = 0; i < set.length; i++) {
|
|
2071
|
+
debug(set[i].semver);
|
|
2072
|
+
if (set[i].semver === Comparator.ANY) continue;
|
|
2073
|
+
if (set[i].semver.prerelease.length > 0) {
|
|
2074
|
+
const allowed = set[i].semver;
|
|
2075
|
+
if (allowed.major === version.major && allowed.minor === version.minor && allowed.patch === version.patch) return true;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return false;
|
|
2079
|
+
}
|
|
2080
|
+
return true;
|
|
2081
|
+
};
|
|
2082
|
+
}));
|
|
2083
|
+
//#endregion
|
|
2084
|
+
//#region ../node_modules/semver/functions/satisfies.js
|
|
2085
|
+
var require_satisfies = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2086
|
+
var Range = require_range();
|
|
2087
|
+
var satisfies = (version, range, options) => {
|
|
2088
|
+
try {
|
|
2089
|
+
range = new Range(range, options);
|
|
2090
|
+
} catch (er) {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
2093
|
+
return range.test(version);
|
|
2094
|
+
};
|
|
2095
|
+
module.exports = satisfies;
|
|
2096
|
+
}));
|
|
2097
|
+
//#endregion
|
|
2098
|
+
//#region ../node_modules/semver/ranges/valid.js
|
|
2099
|
+
var require_valid = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2100
|
+
var Range = require_range();
|
|
2101
|
+
var validRange = (range, options) => {
|
|
2102
|
+
try {
|
|
2103
|
+
return new Range(range, options).range || "*";
|
|
2104
|
+
} catch (er) {
|
|
2105
|
+
return null;
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
2108
|
+
module.exports = validRange;
|
|
2109
|
+
}));
|
|
2110
|
+
//#endregion
|
|
2111
|
+
//#region src/index.ts
|
|
2112
|
+
var import_satisfies = /* @__PURE__ */ __toESM(require_satisfies(), 1);
|
|
2113
|
+
var import_valid = /* @__PURE__ */ __toESM(require_valid(), 1);
|
|
2114
|
+
var semverSatisfies = __resolveDefaultExport(import_satisfies.default, false);
|
|
2115
|
+
var semverValidRange = __resolveDefaultExport(import_valid.default, false);
|
|
2116
|
+
globalThis.__screwUpIsInCJS_2e87ba0361d8 = false;
|
|
2117
|
+
function __resolveDefaultExport(module, isESM) {
|
|
2118
|
+
const __isInCJS = typeof globalThis !== "undefined" && globalThis.__screwUpIsInCJS_2e87ba0361d8 === true;
|
|
2119
|
+
const maybe = module;
|
|
2120
|
+
const hasDefault = !!(maybe && typeof maybe === "object" && "default" in maybe);
|
|
2121
|
+
const unwrapNamespaceDefault = (value) => {
|
|
2122
|
+
if (!value || typeof value !== "object") return value;
|
|
2123
|
+
const inner = value;
|
|
2124
|
+
if ((inner.__esModule === true || typeof Symbol !== "undefined" && inner[Symbol.toStringTag] === "Module") && "default" in inner) return inner.default;
|
|
2125
|
+
return value;
|
|
2126
|
+
};
|
|
2127
|
+
const resolvedDefault = hasDefault ? unwrapNamespaceDefault(maybe.default) : void 0;
|
|
2128
|
+
if (__isInCJS) return hasDefault ? resolvedDefault ?? module : module;
|
|
2129
|
+
if (isESM) {
|
|
2130
|
+
if (hasDefault) return resolvedDefault;
|
|
2131
|
+
throw new Error("Default export not found.");
|
|
2132
|
+
}
|
|
2133
|
+
return hasDefault ? resolvedDefault ?? module : module;
|
|
2134
|
+
}
|
|
2135
|
+
var protocolName = "muon-node/1";
|
|
2136
|
+
var supportedNodeRange = "^20.19.0 || >=22.12.0";
|
|
2137
|
+
var maximumFramePayloadLength = 16 * 1024 * 1024;
|
|
2138
|
+
var signed64Minimum = -(2n ** 63n);
|
|
2139
|
+
var signed64Maximum = 2n ** 63n - 1n;
|
|
2140
|
+
var unsigned64Maximum = 2n ** 64n - 1n;
|
|
2141
|
+
var reservedModuleExportNames = new Set(["$release", "then"]);
|
|
2142
|
+
var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
|
|
2143
|
+
var createBridgeError = (code, message) => {
|
|
2144
|
+
const error = new Error(message);
|
|
2145
|
+
error.code = code;
|
|
2146
|
+
return error;
|
|
2147
|
+
};
|
|
2148
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2149
|
+
var isNodeError = (value) => value instanceof Error;
|
|
2150
|
+
var isProjectRelativeSpecifier = (specifier) => specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../");
|
|
2151
|
+
var getErrorCode = (error, fallbackCode) => {
|
|
2152
|
+
if (isNodeError(error) && typeof error.code === "string" && error.code.length !== 0) return error.code;
|
|
2153
|
+
return fallbackCode;
|
|
2154
|
+
};
|
|
2155
|
+
var getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
2156
|
+
var requireRecord = (value, code, description) => {
|
|
2157
|
+
if (!isRecord(value)) throw createBridgeError(code, `${description} must be an object.`);
|
|
2158
|
+
return value;
|
|
2159
|
+
};
|
|
2160
|
+
var requireString = (value, code, description) => {
|
|
2161
|
+
if (typeof value !== "string" || value.length === 0) throw createBridgeError(code, `${description} must be a non-empty string.`);
|
|
2162
|
+
return value;
|
|
2163
|
+
};
|
|
2164
|
+
var requireArray = (value, code, description) => {
|
|
2165
|
+
if (!Array.isArray(value)) throw createBridgeError(code, `${description} must be an array.`);
|
|
2166
|
+
return value;
|
|
2167
|
+
};
|
|
2168
|
+
var encodeFrame = (message) => {
|
|
2169
|
+
const payload = Buffer.from(JSON.stringify(message), "utf8");
|
|
2170
|
+
if (payload.length > maximumFramePayloadLength) throw createBridgeError("ERR_MUON_NODE_FRAME_TOO_LARGE", "The encoded protocol frame is too large.");
|
|
2171
|
+
const header = Buffer.allocUnsafe(4);
|
|
2172
|
+
header.writeUInt32BE(payload.length);
|
|
2173
|
+
return Buffer.concat([header, payload]);
|
|
2174
|
+
};
|
|
2175
|
+
var decodeIntegerTag = (value, kind) => {
|
|
2176
|
+
const decimal = value.value;
|
|
2177
|
+
if (typeof decimal !== "string" || !/^(?:0|-?[1-9][0-9]*)$/.test(decimal)) throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", `${kind} values must contain a canonical decimal string.`);
|
|
2178
|
+
let decoded;
|
|
2179
|
+
try {
|
|
2180
|
+
decoded = BigInt(decimal);
|
|
2181
|
+
} catch {
|
|
2182
|
+
throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", `${kind} contains an invalid integer.`);
|
|
2183
|
+
}
|
|
2184
|
+
if (!(kind === "i64" ? decoded >= signed64Minimum && decoded <= signed64Maximum : decoded >= 0n && decoded <= unsigned64Maximum)) throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", `${kind} is outside its supported range.`);
|
|
2185
|
+
return decoded;
|
|
2186
|
+
};
|
|
2187
|
+
var decodeBufferTag = (value) => {
|
|
2188
|
+
const data = value.data;
|
|
2189
|
+
if (typeof data !== "string") throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "buffer values must contain base64 data.");
|
|
2190
|
+
const decoded = Buffer.from(data, "base64");
|
|
2191
|
+
if (decoded.toString("base64") !== data) throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "buffer contains non-canonical base64 data.");
|
|
2192
|
+
return decoded;
|
|
2193
|
+
};
|
|
2194
|
+
var arrayBufferByteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength")?.get;
|
|
2195
|
+
var hasArrayBufferInternalSlot = (value) => {
|
|
2196
|
+
if (arrayBufferByteLengthGetter === void 0) return false;
|
|
2197
|
+
try {
|
|
2198
|
+
Reflect.apply(arrayBufferByteLengthGetter, value, []);
|
|
2199
|
+
return true;
|
|
2200
|
+
} catch {
|
|
2201
|
+
return false;
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
var getBinaryView = (value) => {
|
|
2205
|
+
if (Buffer.isBuffer(value)) return value;
|
|
2206
|
+
if (hasArrayBufferInternalSlot(value)) return Buffer.from(value);
|
|
2207
|
+
if (ArrayBuffer.isView(value)) return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
2208
|
+
};
|
|
2209
|
+
var getBinaryViewSafely = (value) => {
|
|
2210
|
+
try {
|
|
2211
|
+
return getBinaryView(value);
|
|
2212
|
+
} catch {
|
|
2213
|
+
throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "The bridge value could not be inspected safely.");
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
var unsupportedJsonErrors = /* @__PURE__ */ new WeakSet();
|
|
2217
|
+
var throwUnsupportedJsonValue = (message) => {
|
|
2218
|
+
const error = createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", message);
|
|
2219
|
+
unsupportedJsonErrors.add(error);
|
|
2220
|
+
throw error;
|
|
2221
|
+
};
|
|
2222
|
+
var requireJsonDataProperty = (descriptor, description) => {
|
|
2223
|
+
if (descriptor === void 0 || !descriptor.enumerable || !Object.prototype.hasOwnProperty.call(descriptor, "value")) return throwUnsupportedJsonValue(`${description} must be an enumerable data property.`);
|
|
2224
|
+
return descriptor.value;
|
|
2225
|
+
};
|
|
2226
|
+
var normalizeStrictJsonValue = (value, ancestors) => {
|
|
2227
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") return value;
|
|
2228
|
+
if (typeof value === "number") {
|
|
2229
|
+
if (!Number.isFinite(value) || Object.is(value, -0)) return throwUnsupportedJsonValue("JSON containers support only finite number values other than negative zero.");
|
|
2230
|
+
return value;
|
|
2231
|
+
}
|
|
2232
|
+
if (typeof value !== "object") return throwUnsupportedJsonValue("JSON containers can contain only JSON-compatible values.");
|
|
2233
|
+
if (ancestors.has(value)) return throwUnsupportedJsonValue("JSON containers cannot contain circular references.");
|
|
2234
|
+
ancestors.add(value);
|
|
2235
|
+
try {
|
|
2236
|
+
if (Array.isArray(value)) {
|
|
2237
|
+
if (Object.getPrototypeOf(value) !== Array.prototype) return throwUnsupportedJsonValue("JSON arrays must use Array.prototype.");
|
|
2238
|
+
const keys = Reflect.ownKeys(value);
|
|
2239
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(value, "length");
|
|
2240
|
+
if (lengthDescriptor === void 0 || lengthDescriptor.enumerable || !Object.prototype.hasOwnProperty.call(lengthDescriptor, "value") || typeof lengthDescriptor.value !== "number" || !Number.isInteger(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295) return throwUnsupportedJsonValue("JSON arrays must have a valid length data property.");
|
|
2241
|
+
const length = lengthDescriptor.value;
|
|
2242
|
+
if (keys.length !== length + 1) return throwUnsupportedJsonValue("JSON arrays must be dense and cannot contain additional properties.");
|
|
2243
|
+
const stringKeys = /* @__PURE__ */ new Set();
|
|
2244
|
+
for (const key of keys) {
|
|
2245
|
+
if (typeof key !== "string") return throwUnsupportedJsonValue("JSON arrays must be dense and cannot contain additional properties.");
|
|
2246
|
+
stringKeys.add(key);
|
|
2247
|
+
}
|
|
2248
|
+
if (!stringKeys.has("length")) return throwUnsupportedJsonValue("JSON arrays must have a length property.");
|
|
2249
|
+
const normalized = new Array(length);
|
|
2250
|
+
for (let index = 0; index < length; index += 1) {
|
|
2251
|
+
const key = String(index);
|
|
2252
|
+
if (!stringKeys.has(key)) return throwUnsupportedJsonValue("JSON arrays must be dense and cannot contain additional properties.");
|
|
2253
|
+
const element = requireJsonDataProperty(Object.getOwnPropertyDescriptor(value, key), `JSON array element ${key}`);
|
|
2254
|
+
Object.defineProperty(normalized, key, {
|
|
2255
|
+
value: normalizeStrictJsonValue(element, ancestors),
|
|
2256
|
+
enumerable: true,
|
|
2257
|
+
configurable: true,
|
|
2258
|
+
writable: true
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
return normalized;
|
|
2262
|
+
}
|
|
2263
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2264
|
+
if (prototype !== Object.prototype && prototype !== null) return throwUnsupportedJsonValue("JSON objects must use Object.prototype or a null prototype.");
|
|
2265
|
+
const normalized = {};
|
|
2266
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
2267
|
+
if (typeof key !== "string") return throwUnsupportedJsonValue("JSON objects cannot contain symbol properties.");
|
|
2268
|
+
const property = requireJsonDataProperty(Object.getOwnPropertyDescriptor(value, key), `JSON object property ${JSON.stringify(key)}`);
|
|
2269
|
+
Object.defineProperty(normalized, key, {
|
|
2270
|
+
value: normalizeStrictJsonValue(property, ancestors),
|
|
2271
|
+
enumerable: true,
|
|
2272
|
+
configurable: true,
|
|
2273
|
+
writable: true
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
return normalized;
|
|
2277
|
+
} finally {
|
|
2278
|
+
ancestors.delete(value);
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
var normalizeStrictJsonContainer = (value) => {
|
|
2282
|
+
try {
|
|
2283
|
+
if (typeof value !== "object" || value === null) return throwUnsupportedJsonValue("A JSON bridge value must be an object or array.");
|
|
2284
|
+
return normalizeStrictJsonValue(value, /* @__PURE__ */ new Set());
|
|
2285
|
+
} catch (error) {
|
|
2286
|
+
if (error !== null && (typeof error === "object" || typeof error === "function") && unsupportedJsonErrors.has(error)) throw error;
|
|
2287
|
+
throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "The JSON bridge value could not be inspected safely.");
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
var encodeScalarWireValue = (value) => {
|
|
2291
|
+
if (value === void 0) return { kind: "undefined" };
|
|
2292
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") return value;
|
|
2293
|
+
if (typeof value === "number") {
|
|
2294
|
+
if (!Number.isFinite(value) || Object.is(value, -0)) throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "Only finite number values other than negative zero are supported.");
|
|
2295
|
+
return value;
|
|
2296
|
+
}
|
|
2297
|
+
if (typeof value === "bigint") {
|
|
2298
|
+
if (value >= signed64Minimum && value <= signed64Maximum) return {
|
|
2299
|
+
kind: "i64",
|
|
2300
|
+
value: value.toString()
|
|
2301
|
+
};
|
|
2302
|
+
if (value >= 0n && value <= unsigned64Maximum) return {
|
|
2303
|
+
kind: "u64",
|
|
2304
|
+
value: value.toString()
|
|
2305
|
+
};
|
|
2306
|
+
throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "The bigint value is outside the i64/u64 range.");
|
|
2307
|
+
}
|
|
2308
|
+
const binary = getBinaryViewSafely(value);
|
|
2309
|
+
if (binary !== void 0) return {
|
|
2310
|
+
kind: "buffer",
|
|
2311
|
+
data: binary.toString("base64")
|
|
2312
|
+
};
|
|
2313
|
+
throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "Only primitive, i64, u64, and buffer values can cross the bridge.");
|
|
2314
|
+
};
|
|
2315
|
+
var encodeWireValue = (value) => {
|
|
2316
|
+
if (value !== null && typeof value === "object") {
|
|
2317
|
+
if (getBinaryViewSafely(value) === void 0) return {
|
|
2318
|
+
kind: "json",
|
|
2319
|
+
value: normalizeStrictJsonContainer(value)
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
return encodeScalarWireValue(value);
|
|
2323
|
+
};
|
|
2324
|
+
var tokensMatch = (actual, expected) => {
|
|
2325
|
+
const actualBytes = Buffer.from(actual, "utf8");
|
|
2326
|
+
const expectedBytes = Buffer.from(expected, "utf8");
|
|
2327
|
+
return actualBytes.length === expectedBytes.length && timingSafeEqual(actualBytes, expectedBytes);
|
|
2328
|
+
};
|
|
2329
|
+
var readPackageManifest = async (projectRoot) => {
|
|
2330
|
+
const packageFile = join(projectRoot, "package.json");
|
|
2331
|
+
let source;
|
|
2332
|
+
try {
|
|
2333
|
+
source = await readFile(packageFile, "utf8");
|
|
2334
|
+
} catch (error) {
|
|
2335
|
+
throw createBridgeError("ERR_MUON_NODE_PROJECT", `Unable to read the Node project package.json: ${getErrorMessage(error)}`);
|
|
2336
|
+
}
|
|
2337
|
+
let parsed;
|
|
2338
|
+
try {
|
|
2339
|
+
parsed = JSON.parse(source);
|
|
2340
|
+
} catch (error) {
|
|
2341
|
+
throw createBridgeError("ERR_MUON_NODE_PROJECT", `The Node project package.json is invalid: ${getErrorMessage(error)}`);
|
|
2342
|
+
}
|
|
2343
|
+
return requireRecord(parsed, "ERR_MUON_NODE_PROJECT", "The Node project package.json");
|
|
2344
|
+
};
|
|
2345
|
+
var validateNodeEngine = (manifest) => {
|
|
2346
|
+
const enginesValue = manifest.engines;
|
|
2347
|
+
if (enginesValue === void 0) return;
|
|
2348
|
+
const nodeRange = requireRecord(enginesValue, "ERR_MUON_NODE_ENGINE", "package.json engines").node;
|
|
2349
|
+
if (nodeRange === void 0) return;
|
|
2350
|
+
if (typeof nodeRange !== "string" || nodeRange.length === 0) throw createBridgeError("ERR_MUON_NODE_ENGINE", "package.json engines.node must be a non-empty string.");
|
|
2351
|
+
if (semverValidRange(nodeRange) === null) throw createBridgeError("ERR_MUON_NODE_ENGINE", `package.json engines.node is not a valid range: ${nodeRange}.`);
|
|
2352
|
+
if (!semverSatisfies(process.version, nodeRange)) throw createBridgeError("ERR_MUON_NODE_ENGINE", `Node ${process.version} does not satisfy engines.node ${nodeRange}.`);
|
|
2353
|
+
};
|
|
2354
|
+
var validateHostedNodeEngine = () => {
|
|
2355
|
+
if (!semverSatisfies(process.version, supportedNodeRange)) throw createBridgeError("ERR_MUON_NODE_ENGINE", `Node ${process.version} is not supported by the muon Node sidecar; expected ${supportedNodeRange}.`);
|
|
2356
|
+
};
|
|
2357
|
+
var initializeProject = async (params, expectedToken, changeWorkingDirectory) => {
|
|
2358
|
+
const requestedProtocol = requireString(params.protocol, "ERR_MUON_NODE_PROTOCOL", "initialize protocol");
|
|
2359
|
+
if (requestedProtocol !== protocolName) throw createBridgeError("ERR_MUON_NODE_PROTOCOL", `Unsupported muon Node protocol ${requestedProtocol}.`);
|
|
2360
|
+
if (expectedToken !== void 0) {
|
|
2361
|
+
if (!tokensMatch(requireString(params.token, "ERR_MUON_NODE_AUTH", "initialize token"), expectedToken)) throw createBridgeError("ERR_MUON_NODE_AUTH", "The initialize token is invalid.");
|
|
2362
|
+
}
|
|
2363
|
+
validateHostedNodeEngine();
|
|
2364
|
+
const requestedRoot = requireString(params.projectRoot, "ERR_MUON_NODE_PROJECT", "initialize projectRoot");
|
|
2365
|
+
let root;
|
|
2366
|
+
try {
|
|
2367
|
+
root = await realpath(resolve(requestedRoot));
|
|
2368
|
+
} catch (error) {
|
|
2369
|
+
throw createBridgeError("ERR_MUON_NODE_PROJECT", `Unable to resolve the Node project: ${getErrorMessage(error)}`);
|
|
2370
|
+
}
|
|
2371
|
+
validateNodeEngine(await readPackageManifest(root));
|
|
2372
|
+
if (changeWorkingDirectory) try {
|
|
2373
|
+
process.chdir(root);
|
|
2374
|
+
} catch (error) {
|
|
2375
|
+
throw createBridgeError("ERR_MUON_NODE_PROJECT", `Unable to use the Node project as the working directory: ${getErrorMessage(error)}`);
|
|
2376
|
+
}
|
|
2377
|
+
return {
|
|
2378
|
+
root,
|
|
2379
|
+
parentUrl: pathToFileURL(join(root, "package.json")).href
|
|
2380
|
+
};
|
|
2381
|
+
};
|
|
2382
|
+
var isCommonJsFile = async (filePath) => {
|
|
2383
|
+
const extension = extname(filePath);
|
|
2384
|
+
if (extension === ".cjs") return true;
|
|
2385
|
+
if (extension === ".mjs") return false;
|
|
2386
|
+
if (extension !== ".js") return false;
|
|
2387
|
+
let directory = dirname(filePath);
|
|
2388
|
+
const filesystemRoot = parse(directory).root;
|
|
2389
|
+
while (true) {
|
|
2390
|
+
try {
|
|
2391
|
+
const source = await readFile(join(directory, "package.json"), "utf8");
|
|
2392
|
+
const manifest = JSON.parse(source);
|
|
2393
|
+
return !isRecord(manifest) || manifest.type !== "module";
|
|
2394
|
+
} catch (error) {
|
|
2395
|
+
if (!isNodeError(error) || error.code !== "ENOENT") throw error;
|
|
2396
|
+
}
|
|
2397
|
+
if (directory === filesystemRoot) return true;
|
|
2398
|
+
directory = dirname(directory);
|
|
2399
|
+
}
|
|
2400
|
+
};
|
|
2401
|
+
var importNamespaceWithoutThenableAssimilation = async (specifier) => {
|
|
2402
|
+
const wrapperSource = [`import * as namespace from ${JSON.stringify(specifier)};`, "export default { namespace };"].join("\n");
|
|
2403
|
+
return { namespace: requireRecord(requireRecord((await import(
|
|
2404
|
+
/* @vite-ignore */
|
|
2405
|
+
`data:text/javascript;charset=utf-8,${encodeURIComponent(wrapperSource)}`
|
|
2406
|
+
)).default, "ERR_MUON_NODE_MODULE_SPECIFIER", "Internal module namespace holder").namespace, "ERR_MUON_NODE_MODULE_SPECIFIER", "Imported module namespace") };
|
|
2407
|
+
};
|
|
2408
|
+
var importProjectModule = async (project, specifier) => {
|
|
2409
|
+
if (specifier.startsWith("node:")) {
|
|
2410
|
+
if (!isBuiltin(specifier)) throw createBridgeError("ERR_MUON_NODE_BUILTIN_SPECIFIER", `${specifier} is not a Node built-in module.`);
|
|
2411
|
+
return {
|
|
2412
|
+
namespace: (await importNamespaceWithoutThenableAssimilation(specifier)).namespace,
|
|
2413
|
+
resolvedFile: void 0
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
if (isBuiltin(specifier)) throw createBridgeError("ERR_MUON_NODE_BUILTIN_SPECIFIER", `Node built-in modules must use the node: prefix: node:${specifier}.`);
|
|
2417
|
+
if (isAbsolute(specifier) || /^[A-Za-z][A-Za-z+.-]*:/.test(specifier)) throw createBridgeError("ERR_MUON_NODE_MODULE_OUTSIDE_PROJECT", "Absolute module specifiers are not supported.");
|
|
2418
|
+
let resolvedUrl;
|
|
2419
|
+
if (specifier === ".") try {
|
|
2420
|
+
resolvedUrl = pathToFileURL(createRequire(project.parentUrl).resolve(project.root));
|
|
2421
|
+
} catch (error) {
|
|
2422
|
+
throw createBridgeError(getErrorCode(error, "ERR_MUON_NODE_MODULE_NOT_FOUND"), getErrorMessage(error));
|
|
2423
|
+
}
|
|
2424
|
+
else try {
|
|
2425
|
+
resolvedUrl = new URL(resolve$1(specifier, project.parentUrl));
|
|
2426
|
+
} catch (error) {
|
|
2427
|
+
throw createBridgeError(getErrorCode(error, "ERR_MUON_NODE_MODULE_NOT_FOUND"), getErrorMessage(error));
|
|
2428
|
+
}
|
|
2429
|
+
if (resolvedUrl.protocol !== "file:") throw createBridgeError("ERR_MUON_NODE_MODULE_SPECIFIER", `Unsupported resolved module protocol ${resolvedUrl.protocol}.`);
|
|
2430
|
+
const resolvedFile = fileURLToPath(resolvedUrl);
|
|
2431
|
+
if (isProjectRelativeSpecifier(specifier)) {
|
|
2432
|
+
if (resolvedFile !== project.root && !resolvedFile.startsWith(`${project.root}${sep}`)) throw createBridgeError("ERR_MUON_NODE_MODULE_OUTSIDE_PROJECT", "Project-relative imports cannot leave the configured project root.");
|
|
2433
|
+
}
|
|
2434
|
+
return {
|
|
2435
|
+
namespace: (await importNamespaceWithoutThenableAssimilation(resolvedUrl.href)).namespace,
|
|
2436
|
+
resolvedFile
|
|
2437
|
+
};
|
|
2438
|
+
};
|
|
2439
|
+
var collectModuleExports = async (imported) => {
|
|
2440
|
+
const exports = /* @__PURE__ */ new Map();
|
|
2441
|
+
for (const name of Object.keys(imported.namespace)) exports.set(name, {
|
|
2442
|
+
value: imported.namespace[name],
|
|
2443
|
+
receiver: void 0
|
|
2444
|
+
});
|
|
2445
|
+
if (imported.resolvedFile !== void 0 && await isCommonJsFile(imported.resolvedFile)) {
|
|
2446
|
+
const commonJsExports = imported.namespace.default;
|
|
2447
|
+
if (commonJsExports !== null && (typeof commonJsExports === "object" || typeof commonJsExports === "function")) for (const name of Object.keys(commonJsExports)) {
|
|
2448
|
+
if (name === "default") continue;
|
|
2449
|
+
exports.set(name, {
|
|
2450
|
+
value: Reflect.get(commonJsExports, name),
|
|
2451
|
+
receiver: commonJsExports
|
|
2452
|
+
});
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
return { exports };
|
|
2456
|
+
};
|
|
2457
|
+
var describeModuleExports = (exports) => {
|
|
2458
|
+
const descriptor = [];
|
|
2459
|
+
const names = [...exports.keys()].sort();
|
|
2460
|
+
for (const name of names) {
|
|
2461
|
+
const value = exports.get(name)?.value;
|
|
2462
|
+
if (typeof value === "function") {
|
|
2463
|
+
descriptor.push({
|
|
2464
|
+
name,
|
|
2465
|
+
kind: "function",
|
|
2466
|
+
value: void 0
|
|
2467
|
+
});
|
|
2468
|
+
continue;
|
|
2469
|
+
}
|
|
2470
|
+
try {
|
|
2471
|
+
descriptor.push({
|
|
2472
|
+
name,
|
|
2473
|
+
kind: "primitive",
|
|
2474
|
+
value: encodeScalarWireValue(value)
|
|
2475
|
+
});
|
|
2476
|
+
} catch (error) {
|
|
2477
|
+
if (getErrorCode(error, "") !== "ERR_MUON_NODE_UNSUPPORTED_VALUE") throw error;
|
|
2478
|
+
}
|
|
2479
|
+
}
|
|
2480
|
+
return descriptor.map((entry) => entry.kind === "function" ? {
|
|
2481
|
+
name: entry.name,
|
|
2482
|
+
kind: entry.kind
|
|
2483
|
+
} : entry);
|
|
2484
|
+
};
|
|
2485
|
+
var parseRequest = (value) => {
|
|
2486
|
+
const message = requireRecord(value, "ERR_MUON_NODE_PROTOCOL", "Protocol message");
|
|
2487
|
+
if (message.kind !== "request") throw createBridgeError("ERR_MUON_NODE_PROTOCOL", "Expected a request or callbackResult message.");
|
|
2488
|
+
return {
|
|
2489
|
+
kind: "request",
|
|
2490
|
+
id: requireString(message.id, "ERR_MUON_NODE_PROTOCOL", "Request id"),
|
|
2491
|
+
command: requireString(message.command, "ERR_MUON_NODE_PROTOCOL", "Request command"),
|
|
2492
|
+
params: requireRecord(message.params, "ERR_MUON_NODE_PROTOCOL", "Request params")
|
|
2493
|
+
};
|
|
2494
|
+
};
|
|
2495
|
+
var parseCallbackResult = (value) => {
|
|
2496
|
+
const message = requireRecord(value, "ERR_MUON_NODE_PROTOCOL", "Callback result");
|
|
2497
|
+
const id = requireString(message.id, "ERR_MUON_NODE_PROTOCOL", "Callback result id");
|
|
2498
|
+
if (typeof message.ok !== "boolean") throw createBridgeError("ERR_MUON_NODE_PROTOCOL", "Callback result ok must be a boolean.");
|
|
2499
|
+
if (message.ok) return {
|
|
2500
|
+
kind: "callbackResult",
|
|
2501
|
+
id,
|
|
2502
|
+
ok: true,
|
|
2503
|
+
value: message.value,
|
|
2504
|
+
error: null
|
|
2505
|
+
};
|
|
2506
|
+
const error = requireRecord(message.error, "ERR_MUON_NODE_PROTOCOL", "Callback result error");
|
|
2507
|
+
return {
|
|
2508
|
+
kind: "callbackResult",
|
|
2509
|
+
id,
|
|
2510
|
+
ok: false,
|
|
2511
|
+
value: void 0,
|
|
2512
|
+
error: {
|
|
2513
|
+
code: requireString(error.code, "ERR_MUON_NODE_PROTOCOL", "Callback error code"),
|
|
2514
|
+
message: requireString(error.message, "ERR_MUON_NODE_PROTOCOL", "Callback error message")
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
};
|
|
2518
|
+
/**
|
|
2519
|
+
* Creates a host for framed muon Node requests.
|
|
2520
|
+
*
|
|
2521
|
+
* @param options - Streams and optional transport authentication token.
|
|
2522
|
+
* @returns A bridge whose lifecycle remains owned by the caller.
|
|
2523
|
+
*/
|
|
2524
|
+
var createMuonNodeBridge = (options) => {
|
|
2525
|
+
let pendingInput = Buffer.alloc(0);
|
|
2526
|
+
let project = void 0;
|
|
2527
|
+
let nextModuleId = 1;
|
|
2528
|
+
let nextCallbackId = 1;
|
|
2529
|
+
let initializationDrain = void 0;
|
|
2530
|
+
let closeOperation = void 0;
|
|
2531
|
+
let closing = false;
|
|
2532
|
+
let shutdownRequested = false;
|
|
2533
|
+
let shutdownSettled = false;
|
|
2534
|
+
const requests = [];
|
|
2535
|
+
const activeRequests = /* @__PURE__ */ new Set();
|
|
2536
|
+
const modules = /* @__PURE__ */ new Map();
|
|
2537
|
+
const releasedModules = /* @__PURE__ */ new Set();
|
|
2538
|
+
const pendingCallbacks = /* @__PURE__ */ new Map();
|
|
2539
|
+
let resolveShutdown = () => void 0;
|
|
2540
|
+
let rejectShutdown = () => void 0;
|
|
2541
|
+
const shutdown = new Promise((resolvePromise, rejectPromise) => {
|
|
2542
|
+
resolveShutdown = resolvePromise;
|
|
2543
|
+
rejectShutdown = rejectPromise;
|
|
2544
|
+
});
|
|
2545
|
+
const signalShutdown = (error) => {
|
|
2546
|
+
if (shutdownSettled) return;
|
|
2547
|
+
shutdownSettled = true;
|
|
2548
|
+
if (error === void 0) resolveShutdown();
|
|
2549
|
+
else rejectShutdown(error);
|
|
2550
|
+
};
|
|
2551
|
+
const writeMessage = async (message) => {
|
|
2552
|
+
const frame = encodeFrame(message);
|
|
2553
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
2554
|
+
options.output.write(frame, (error) => {
|
|
2555
|
+
if (error !== void 0 && error !== null) {
|
|
2556
|
+
rejectPromise(error);
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
resolvePromise();
|
|
2560
|
+
});
|
|
2561
|
+
});
|
|
2562
|
+
};
|
|
2563
|
+
const rejectPendingCallbacks = (error) => {
|
|
2564
|
+
for (const callback of pendingCallbacks.values()) callback.reject(error);
|
|
2565
|
+
pendingCallbacks.clear();
|
|
2566
|
+
};
|
|
2567
|
+
const invokeRemoteCallback = async (handle, argumentsValue) => {
|
|
2568
|
+
if (closing) throw createBridgeError("ERR_MUON_NODE_CLOSED", "The muon Node bridge is closing.");
|
|
2569
|
+
const id = `callback-${nextCallbackId}`;
|
|
2570
|
+
nextCallbackId += 1;
|
|
2571
|
+
const encodedArguments = argumentsValue.map((value) => encodeWireValue(value));
|
|
2572
|
+
const result = new Promise((resolvePromise, rejectPromise) => {
|
|
2573
|
+
pendingCallbacks.set(id, {
|
|
2574
|
+
resolve: resolvePromise,
|
|
2575
|
+
reject: rejectPromise
|
|
2576
|
+
});
|
|
2577
|
+
});
|
|
2578
|
+
try {
|
|
2579
|
+
const [, callbackResult] = await Promise.all([writeMessage({
|
|
2580
|
+
kind: "callback",
|
|
2581
|
+
id,
|
|
2582
|
+
handle,
|
|
2583
|
+
arguments: encodedArguments
|
|
2584
|
+
}), result]);
|
|
2585
|
+
return callbackResult;
|
|
2586
|
+
} finally {
|
|
2587
|
+
pendingCallbacks.delete(id);
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
const decodeWireValue = (value) => {
|
|
2591
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") return value;
|
|
2592
|
+
if (typeof value === "number") {
|
|
2593
|
+
if (!Number.isFinite(value) || Object.is(value, -0)) throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "Only finite number values other than negative zero are supported.");
|
|
2594
|
+
return value;
|
|
2595
|
+
}
|
|
2596
|
+
const tagged = requireRecord(value, "ERR_MUON_NODE_UNSUPPORTED_VALUE", "Wire value");
|
|
2597
|
+
if (tagged.kind === "undefined") return;
|
|
2598
|
+
if (tagged.kind === "i64" || tagged.kind === "u64") return decodeIntegerTag(tagged, tagged.kind);
|
|
2599
|
+
if (tagged.kind === "buffer") return decodeBufferTag(tagged);
|
|
2600
|
+
if (tagged.kind === "json") return normalizeStrictJsonContainer(tagged.value);
|
|
2601
|
+
if (tagged.kind === "function") {
|
|
2602
|
+
const handle = requireString(tagged.handle, "ERR_MUON_NODE_UNSUPPORTED_VALUE", "Function handle");
|
|
2603
|
+
return async (...argumentsValue) => await invokeRemoteCallback(handle, argumentsValue);
|
|
2604
|
+
}
|
|
2605
|
+
throw createBridgeError("ERR_MUON_NODE_UNSUPPORTED_VALUE", "Arbitrary object values cannot cross the muon Node bridge.");
|
|
2606
|
+
};
|
|
2607
|
+
const requireProject = () => {
|
|
2608
|
+
if (project === void 0) throw createBridgeError("ERR_MUON_NODE_NOT_INITIALIZED", "The muon Node bridge has not been initialized.");
|
|
2609
|
+
return project;
|
|
2610
|
+
};
|
|
2611
|
+
const importModule = async (params) => {
|
|
2612
|
+
const collected = await collectModuleExports(await importProjectModule(requireProject(), requireString(params.specifier, "ERR_MUON_NODE_MODULE_SPECIFIER", "Module specifier")));
|
|
2613
|
+
for (const reservedName of reservedModuleExportNames) if (collected.exports.has(reservedName)) throw createBridgeError("ERR_MUON_NODE_RESERVED_EXPORT", `Module export ${reservedName} is reserved by the muon Node facade.`);
|
|
2614
|
+
const descriptor = { exports: describeModuleExports(collected.exports) };
|
|
2615
|
+
const moduleId = `module-${nextModuleId}`;
|
|
2616
|
+
nextModuleId += 1;
|
|
2617
|
+
modules.set(moduleId, { exports: collected.exports });
|
|
2618
|
+
return {
|
|
2619
|
+
moduleId,
|
|
2620
|
+
descriptor
|
|
2621
|
+
};
|
|
2622
|
+
};
|
|
2623
|
+
const callModuleExport = async (params) => {
|
|
2624
|
+
requireProject();
|
|
2625
|
+
const moduleId = requireString(params.moduleId, "ERR_MUON_NODE_UNKNOWN_HANDLE", "Module id");
|
|
2626
|
+
if (releasedModules.has(moduleId)) throw createBridgeError("ERR_MUON_NODE_RELEASED_HANDLE", `Module handle ${moduleId} has been released.`);
|
|
2627
|
+
const module = modules.get(moduleId);
|
|
2628
|
+
if (module === void 0) throw createBridgeError("ERR_MUON_NODE_UNKNOWN_HANDLE", `Unknown module handle ${moduleId}.`);
|
|
2629
|
+
const exportName = requireString(params.exportName, "ERR_MUON_NODE_EXPORT", "Export name");
|
|
2630
|
+
const exported = module.exports.get(exportName);
|
|
2631
|
+
if (exported === void 0 || typeof exported.value !== "function") throw createBridgeError("ERR_MUON_NODE_NOT_CALLABLE", `Module export ${exportName} is not callable.`);
|
|
2632
|
+
const argumentsValue = requireArray(params.arguments, "ERR_MUON_NODE_UNSUPPORTED_VALUE", "Call arguments").map((value) => decodeWireValue(value));
|
|
2633
|
+
return encodeWireValue(await Reflect.apply(exported.value, exported.receiver, argumentsValue));
|
|
2634
|
+
};
|
|
2635
|
+
const releaseHandle = (params) => {
|
|
2636
|
+
requireProject();
|
|
2637
|
+
const kind = requireString(params.kind, "ERR_MUON_NODE_UNKNOWN_HANDLE", "Release kind");
|
|
2638
|
+
const handle = requireString(params.handle, "ERR_MUON_NODE_UNKNOWN_HANDLE", "Release handle");
|
|
2639
|
+
if (kind === "module") {
|
|
2640
|
+
const released = modules.delete(handle);
|
|
2641
|
+
releasedModules.add(handle);
|
|
2642
|
+
return { released };
|
|
2643
|
+
}
|
|
2644
|
+
throw createBridgeError("ERR_MUON_NODE_UNKNOWN_HANDLE", `Unsupported release kind ${kind}.`);
|
|
2645
|
+
};
|
|
2646
|
+
const executeCommand = async (request) => {
|
|
2647
|
+
if (shutdownRequested) throw createBridgeError("ERR_MUON_NODE_CLOSED", "The muon Node bridge is shutting down.");
|
|
2648
|
+
switch (request.command) {
|
|
2649
|
+
case "initialize":
|
|
2650
|
+
if (project !== void 0) throw createBridgeError("ERR_MUON_NODE_ALREADY_INITIALIZED", "The muon Node bridge is already initialized.");
|
|
2651
|
+
project = await initializeProject(request.params, options.expectedToken, options.changeWorkingDirectory);
|
|
2652
|
+
return {
|
|
2653
|
+
value: {
|
|
2654
|
+
protocol: protocolName,
|
|
2655
|
+
nodeVersion: process.version
|
|
2656
|
+
},
|
|
2657
|
+
shutdown: false,
|
|
2658
|
+
responseFailure: void 0
|
|
2659
|
+
};
|
|
2660
|
+
case "importModule": {
|
|
2661
|
+
const imported = await importModule(request.params);
|
|
2662
|
+
return {
|
|
2663
|
+
value: imported,
|
|
2664
|
+
shutdown: false,
|
|
2665
|
+
responseFailure: () => {
|
|
2666
|
+
modules.delete(imported.moduleId);
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
}
|
|
2670
|
+
case "call": return {
|
|
2671
|
+
value: await callModuleExport(request.params),
|
|
2672
|
+
shutdown: false,
|
|
2673
|
+
responseFailure: void 0
|
|
2674
|
+
};
|
|
2675
|
+
case "release": return {
|
|
2676
|
+
value: releaseHandle(request.params),
|
|
2677
|
+
shutdown: false,
|
|
2678
|
+
responseFailure: void 0
|
|
2679
|
+
};
|
|
2680
|
+
case "shutdown":
|
|
2681
|
+
requireProject();
|
|
2682
|
+
shutdownRequested = true;
|
|
2683
|
+
return {
|
|
2684
|
+
value: { shutdown: true },
|
|
2685
|
+
shutdown: true,
|
|
2686
|
+
responseFailure: void 0
|
|
2687
|
+
};
|
|
2688
|
+
default: throw createBridgeError("ERR_MUON_NODE_UNKNOWN_COMMAND", `Unknown muon Node command ${request.command}.`);
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2691
|
+
const processRequest = async (request) => {
|
|
2692
|
+
const writeFailure = async (error) => {
|
|
2693
|
+
if (closing) return;
|
|
2694
|
+
await writeMessage({
|
|
2695
|
+
kind: "response",
|
|
2696
|
+
id: request.id,
|
|
2697
|
+
ok: false,
|
|
2698
|
+
error: {
|
|
2699
|
+
code: getErrorCode(error, "ERR_MUON_NODE_REQUEST"),
|
|
2700
|
+
message: getErrorMessage(error)
|
|
2701
|
+
}
|
|
2702
|
+
});
|
|
2703
|
+
};
|
|
2704
|
+
let result;
|
|
2705
|
+
try {
|
|
2706
|
+
result = await executeCommand(request);
|
|
2707
|
+
} catch (error) {
|
|
2708
|
+
await writeFailure(error);
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2711
|
+
if (closing) {
|
|
2712
|
+
result.responseFailure?.();
|
|
2713
|
+
return;
|
|
2714
|
+
}
|
|
2715
|
+
try {
|
|
2716
|
+
await writeMessage({
|
|
2717
|
+
kind: "response",
|
|
2718
|
+
id: request.id,
|
|
2719
|
+
ok: true,
|
|
2720
|
+
value: result.value
|
|
2721
|
+
});
|
|
2722
|
+
} catch (error) {
|
|
2723
|
+
result.responseFailure?.();
|
|
2724
|
+
if (getErrorCode(error, "") !== "ERR_MUON_NODE_FRAME_TOO_LARGE") throw error;
|
|
2725
|
+
await writeFailure(error);
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
if (result.shutdown) signalShutdown(void 0);
|
|
2729
|
+
};
|
|
2730
|
+
const handleCallbackResult = (result) => {
|
|
2731
|
+
const callback = pendingCallbacks.get(result.id);
|
|
2732
|
+
if (callback === void 0) throw createBridgeError("ERR_MUON_NODE_UNKNOWN_CALLBACK", `Unknown callback result id ${result.id}.`);
|
|
2733
|
+
pendingCallbacks.delete(result.id);
|
|
2734
|
+
if (result.ok) {
|
|
2735
|
+
try {
|
|
2736
|
+
callback.resolve(decodeWireValue(result.value));
|
|
2737
|
+
} catch (error) {
|
|
2738
|
+
callback.reject(error instanceof Error ? error : new Error(String(error)));
|
|
2739
|
+
}
|
|
2740
|
+
return;
|
|
2741
|
+
}
|
|
2742
|
+
const callbackError = result.error;
|
|
2743
|
+
if (callbackError === null) {
|
|
2744
|
+
callback.reject(createBridgeError("ERR_MUON_NODE_PROTOCOL", "A failed callback result omitted its error."));
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
callback.reject(createBridgeError(callbackError.code, callbackError.message));
|
|
2748
|
+
};
|
|
2749
|
+
const parseInputFrames = () => {
|
|
2750
|
+
while (pendingInput.length >= 4) {
|
|
2751
|
+
const payloadLength = pendingInput.readUInt32BE(0);
|
|
2752
|
+
if (payloadLength > maximumFramePayloadLength) throw createBridgeError("ERR_MUON_NODE_FRAME_TOO_LARGE", "The incoming protocol frame is too large.");
|
|
2753
|
+
const frameLength = payloadLength + 4;
|
|
2754
|
+
if (pendingInput.length < frameLength) return;
|
|
2755
|
+
const payload = pendingInput.subarray(4, frameLength);
|
|
2756
|
+
pendingInput = pendingInput.subarray(frameLength);
|
|
2757
|
+
let source;
|
|
2758
|
+
try {
|
|
2759
|
+
source = utf8Decoder.decode(payload);
|
|
2760
|
+
} catch {
|
|
2761
|
+
throw createBridgeError("ERR_MUON_NODE_PROTOCOL", "The protocol frame payload is not valid UTF-8.");
|
|
2762
|
+
}
|
|
2763
|
+
let decoded;
|
|
2764
|
+
try {
|
|
2765
|
+
decoded = JSON.parse(source);
|
|
2766
|
+
} catch (error) {
|
|
2767
|
+
throw createBridgeError("ERR_MUON_NODE_PROTOCOL", `The protocol frame is not valid JSON: ${getErrorMessage(error)}`);
|
|
2768
|
+
}
|
|
2769
|
+
if (isRecord(decoded) && decoded.kind === "callbackResult") handleCallbackResult(parseCallbackResult(decoded));
|
|
2770
|
+
else requests.push(parseRequest(decoded));
|
|
2771
|
+
}
|
|
2772
|
+
};
|
|
2773
|
+
const handleFatalError = (error) => {
|
|
2774
|
+
if (closing) return;
|
|
2775
|
+
closing = true;
|
|
2776
|
+
options.input.pause();
|
|
2777
|
+
const fatalError = createBridgeError(getErrorCode(error, "ERR_MUON_NODE_PROTOCOL"), getErrorMessage(error));
|
|
2778
|
+
rejectPendingCallbacks(fatalError);
|
|
2779
|
+
signalShutdown(fatalError);
|
|
2780
|
+
};
|
|
2781
|
+
const runActiveRequest = async (activeRequest, request) => {
|
|
2782
|
+
try {
|
|
2783
|
+
await processRequest(request);
|
|
2784
|
+
} catch (error) {
|
|
2785
|
+
handleFatalError(error);
|
|
2786
|
+
} finally {
|
|
2787
|
+
activeRequests.delete(activeRequest);
|
|
2788
|
+
}
|
|
2789
|
+
};
|
|
2790
|
+
const startActiveRequest = (request) => {
|
|
2791
|
+
if (closing) return;
|
|
2792
|
+
const activeRequest = { operation: void 0 };
|
|
2793
|
+
activeRequests.add(activeRequest);
|
|
2794
|
+
activeRequest.operation = runActiveRequest(activeRequest, request);
|
|
2795
|
+
};
|
|
2796
|
+
const scheduleRequests = () => {
|
|
2797
|
+
if (closing || requests.length === 0 || initializationDrain !== void 0) return;
|
|
2798
|
+
if (project !== void 0) for (;;) {
|
|
2799
|
+
const request = requests.shift();
|
|
2800
|
+
if (request === void 0) return;
|
|
2801
|
+
startActiveRequest(request);
|
|
2802
|
+
}
|
|
2803
|
+
initializationDrain = drainInitializationRequests();
|
|
2804
|
+
};
|
|
2805
|
+
const drainInitializationRequests = async () => {
|
|
2806
|
+
try {
|
|
2807
|
+
while (!closing && project === void 0) {
|
|
2808
|
+
const request = requests.shift();
|
|
2809
|
+
if (request === void 0) return;
|
|
2810
|
+
await processRequest(request);
|
|
2811
|
+
}
|
|
2812
|
+
if (!closing) for (;;) {
|
|
2813
|
+
const request = requests.shift();
|
|
2814
|
+
if (request === void 0) return;
|
|
2815
|
+
startActiveRequest(request);
|
|
2816
|
+
}
|
|
2817
|
+
} catch (error) {
|
|
2818
|
+
handleFatalError(error);
|
|
2819
|
+
} finally {
|
|
2820
|
+
initializationDrain = void 0;
|
|
2821
|
+
scheduleRequests();
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
const consumeInput = (chunk) => {
|
|
2825
|
+
const bytes = typeof chunk === "string" ? Buffer.from(chunk) : Buffer.isBuffer(chunk) ? chunk : chunk instanceof Uint8Array ? Buffer.from(chunk) : void 0;
|
|
2826
|
+
if (bytes === void 0) throw createBridgeError("ERR_MUON_NODE_PROTOCOL", "The protocol input emitted a non-binary chunk.");
|
|
2827
|
+
pendingInput = Buffer.concat([pendingInput, bytes]);
|
|
2828
|
+
parseInputFrames();
|
|
2829
|
+
scheduleRequests();
|
|
2830
|
+
};
|
|
2831
|
+
const handleInputData = (chunk) => {
|
|
2832
|
+
try {
|
|
2833
|
+
consumeInput(chunk);
|
|
2834
|
+
} catch (error) {
|
|
2835
|
+
handleFatalError(error);
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
const handleInputEnd = () => {
|
|
2839
|
+
if (pendingInput.length !== 0) {
|
|
2840
|
+
handleFatalError(createBridgeError("ERR_MUON_NODE_PROTOCOL", "The protocol input ended with an incomplete frame."));
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
closing = true;
|
|
2844
|
+
rejectPendingCallbacks(createBridgeError("ERR_MUON_NODE_CLOSED", "The muon Node protocol input ended."));
|
|
2845
|
+
signalShutdown(void 0);
|
|
2846
|
+
};
|
|
2847
|
+
const handleStreamError = (error) => {
|
|
2848
|
+
handleFatalError(error);
|
|
2849
|
+
};
|
|
2850
|
+
options.input.on("data", handleInputData);
|
|
2851
|
+
options.input.on("end", handleInputEnd);
|
|
2852
|
+
options.input.on("error", handleStreamError);
|
|
2853
|
+
options.output.on("error", handleStreamError);
|
|
2854
|
+
const performClose = async () => {
|
|
2855
|
+
closing = true;
|
|
2856
|
+
options.input.removeListener("data", handleInputData);
|
|
2857
|
+
options.input.removeListener("end", handleInputEnd);
|
|
2858
|
+
options.input.removeListener("error", handleStreamError);
|
|
2859
|
+
rejectPendingCallbacks(createBridgeError("ERR_MUON_NODE_CLOSED", "The muon Node bridge was closed."));
|
|
2860
|
+
options.output.removeListener("error", handleStreamError);
|
|
2861
|
+
requests.splice(0);
|
|
2862
|
+
activeRequests.clear();
|
|
2863
|
+
modules.clear();
|
|
2864
|
+
signalShutdown(void 0);
|
|
2865
|
+
};
|
|
2866
|
+
return {
|
|
2867
|
+
waitForShutdown: async () => {
|
|
2868
|
+
await shutdown;
|
|
2869
|
+
},
|
|
2870
|
+
close: async () => {
|
|
2871
|
+
if (closeOperation === void 0) closeOperation = performClose();
|
|
2872
|
+
await closeOperation;
|
|
2873
|
+
}
|
|
2874
|
+
};
|
|
2875
|
+
};
|
|
2876
|
+
//#endregion
|
|
2877
|
+
//#region src/cli.ts
|
|
2878
|
+
var requireEnvironment = (name) => {
|
|
2879
|
+
const value = process.env[name];
|
|
2880
|
+
if (value === void 0 || value.length === 0) throw new Error(`${name} must contain a non-empty value.`);
|
|
2881
|
+
return value;
|
|
2882
|
+
};
|
|
2883
|
+
var finishWritable = async (output) => {
|
|
2884
|
+
if (output.destroyed || output.writableEnded) return;
|
|
2885
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
2886
|
+
const handleError = (error) => {
|
|
2887
|
+
output.removeListener("finish", handleFinish);
|
|
2888
|
+
rejectPromise(error);
|
|
2889
|
+
};
|
|
2890
|
+
const handleFinish = () => {
|
|
2891
|
+
output.removeListener("error", handleError);
|
|
2892
|
+
resolvePromise();
|
|
2893
|
+
};
|
|
2894
|
+
output.once("error", handleError);
|
|
2895
|
+
output.once("finish", handleFinish);
|
|
2896
|
+
output.end();
|
|
2897
|
+
});
|
|
2898
|
+
};
|
|
2899
|
+
var writeStandardError = async (message) => {
|
|
2900
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
2901
|
+
process.stderr.write(message, (error) => {
|
|
2902
|
+
if (error !== null && error !== void 0) {
|
|
2903
|
+
rejectPromise(error);
|
|
2904
|
+
return;
|
|
2905
|
+
}
|
|
2906
|
+
resolvePromise();
|
|
2907
|
+
});
|
|
2908
|
+
});
|
|
2909
|
+
};
|
|
2910
|
+
var parseInheritedFileDescriptor = (source) => {
|
|
2911
|
+
if (!/^[0-9]+$/.test(source)) throw new Error("MUON_NODE_FD must be a decimal file descriptor.");
|
|
2912
|
+
const fileDescriptor = Number(source);
|
|
2913
|
+
if (!Number.isSafeInteger(fileDescriptor) || fileDescriptor < 3) throw new Error("MUON_NODE_FD must identify an inherited descriptor.");
|
|
2914
|
+
return fileDescriptor;
|
|
2915
|
+
};
|
|
2916
|
+
var openInheritedFileDescriptor = (fileDescriptor) => {
|
|
2917
|
+
const socket = new Socket({
|
|
2918
|
+
fd: fileDescriptor,
|
|
2919
|
+
readable: true,
|
|
2920
|
+
writable: true,
|
|
2921
|
+
allowHalfOpen: true
|
|
2922
|
+
});
|
|
2923
|
+
let closed = false;
|
|
2924
|
+
return {
|
|
2925
|
+
input: socket,
|
|
2926
|
+
output: socket,
|
|
2927
|
+
close: async () => {
|
|
2928
|
+
if (closed) return;
|
|
2929
|
+
closed = true;
|
|
2930
|
+
try {
|
|
2931
|
+
await finishWritable(socket);
|
|
2932
|
+
} finally {
|
|
2933
|
+
socket.destroy();
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
};
|
|
2937
|
+
};
|
|
2938
|
+
var waitForSocketConnection = async (socket) => {
|
|
2939
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
2940
|
+
const handleConnect = () => {
|
|
2941
|
+
socket.removeListener("error", handleError);
|
|
2942
|
+
resolvePromise();
|
|
2943
|
+
};
|
|
2944
|
+
const handleError = (error) => {
|
|
2945
|
+
socket.removeListener("connect", handleConnect);
|
|
2946
|
+
rejectPromise(error);
|
|
2947
|
+
};
|
|
2948
|
+
socket.once("connect", handleConnect);
|
|
2949
|
+
socket.once("error", handleError);
|
|
2950
|
+
});
|
|
2951
|
+
};
|
|
2952
|
+
var openWindowsNamedPipe = async (pipeName) => {
|
|
2953
|
+
const socket = createConnection({
|
|
2954
|
+
path: pipeName,
|
|
2955
|
+
allowHalfOpen: true
|
|
2956
|
+
});
|
|
2957
|
+
try {
|
|
2958
|
+
await waitForSocketConnection(socket);
|
|
2959
|
+
} catch (error) {
|
|
2960
|
+
socket.destroy();
|
|
2961
|
+
throw error;
|
|
2962
|
+
}
|
|
2963
|
+
let closed = false;
|
|
2964
|
+
return {
|
|
2965
|
+
input: socket,
|
|
2966
|
+
output: socket,
|
|
2967
|
+
close: async () => {
|
|
2968
|
+
if (closed) return;
|
|
2969
|
+
closed = true;
|
|
2970
|
+
try {
|
|
2971
|
+
await finishWritable(socket);
|
|
2972
|
+
} finally {
|
|
2973
|
+
socket.destroy();
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
};
|
|
2977
|
+
};
|
|
2978
|
+
var openSidecarConnection = async () => {
|
|
2979
|
+
if (process.platform === "win32") return await openWindowsNamedPipe(requireEnvironment("MUON_NODE_PIPE"));
|
|
2980
|
+
return openInheritedFileDescriptor(parseInheritedFileDescriptor(requireEnvironment("MUON_NODE_FD")));
|
|
2981
|
+
};
|
|
2982
|
+
var runSidecar = async () => {
|
|
2983
|
+
const expectedToken = requireEnvironment("MUON_NODE_TOKEN");
|
|
2984
|
+
delete process.env.MUON_NODE_TOKEN;
|
|
2985
|
+
const connection = await openSidecarConnection();
|
|
2986
|
+
const bridge = createMuonNodeBridge({
|
|
2987
|
+
input: connection.input,
|
|
2988
|
+
output: connection.output,
|
|
2989
|
+
expectedToken,
|
|
2990
|
+
changeWorkingDirectory: true
|
|
2991
|
+
});
|
|
2992
|
+
try {
|
|
2993
|
+
await bridge.waitForShutdown();
|
|
2994
|
+
} finally {
|
|
2995
|
+
try {
|
|
2996
|
+
await bridge.close();
|
|
2997
|
+
} finally {
|
|
2998
|
+
await connection.close();
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
try {
|
|
3003
|
+
await runSidecar();
|
|
3004
|
+
process.exit(0);
|
|
3005
|
+
} catch (error) {
|
|
3006
|
+
const message = error instanceof Error ? error.stack ?? error.message : String(error);
|
|
3007
|
+
try {
|
|
3008
|
+
await writeStandardError(`muon Node sidecar failed: ${message}\n`);
|
|
3009
|
+
} finally {
|
|
3010
|
+
process.exit(1);
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
//#endregion
|