@nasti-toolchain/nasti 2.5.0 → 2.5.2

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