@nasti-toolchain/nasti 2.4.4 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -10,16 +10,25 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
10
10
  if (typeof require !== "undefined") return require.apply(this, arguments);
11
11
  throw Error('Dynamic require of "' + x + '" is not supported');
12
12
  });
13
- var __glob = (map) => (path19) => {
14
- var fn = map[path19];
13
+ var __glob = (map) => (path21) => {
14
+ var fn = map[path21];
15
15
  if (fn) return fn();
16
- throw new Error("Module not found in bundle: " + path19);
16
+ throw new Error("Module not found in bundle: " + path21);
17
17
  };
18
- var __esm = (fn, res) => function __init() {
19
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
18
+ var __esm = (fn, res, err) => function __init() {
19
+ if (err) throw err[0];
20
+ try {
21
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
22
+ } catch (e) {
23
+ throw err = [e], e;
24
+ }
20
25
  };
21
26
  var __commonJS = (cb, mod) => function __require3() {
22
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27
+ try {
28
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
29
+ } catch (e) {
30
+ throw mod = 0, e;
31
+ }
23
32
  };
24
33
  var __export = (target, all) => {
25
34
  for (var name in all)
@@ -69,7 +78,7 @@ function createLogger(level = "info", options = {}) {
69
78
  const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
70
79
  const clear = canClearScreen ? clearScreen : () => {
71
80
  };
72
- function format(type, msg, options2 = {}) {
81
+ function format2(type, msg, options2 = {}) {
73
82
  if (options2.timestamp) {
74
83
  const tag = type === "info" ? pc.cyan(pc.bold(prefix)) : type === "warn" ? pc.yellow(pc.bold(prefix)) : pc.red(pc.bold(prefix));
75
84
  return `${pc.dim(timeFormatter.format(/* @__PURE__ */ new Date()))} ${tag} ${msg}`;
@@ -86,16 +95,16 @@ function createLogger(level = "info", options = {}) {
86
95
  if (type === lastType && msg === lastMsg) {
87
96
  sameCount++;
88
97
  clear();
89
- console_[method](format(type, msg, options2), pc.yellow(`(x${sameCount + 1})`));
98
+ console_[method](format2(type, msg, options2), pc.yellow(`(x${sameCount + 1})`));
90
99
  } else {
91
100
  sameCount = 0;
92
101
  lastMsg = msg;
93
102
  lastType = type;
94
103
  if (options2.clear) clear();
95
- console_[method](format(type, msg, options2));
104
+ console_[method](format2(type, msg, options2));
96
105
  }
97
106
  } else {
98
- console_[method](format(type, msg, options2));
107
+ console_[method](format2(type, msg, options2));
99
108
  }
100
109
  }
101
110
  const warnedMessages = /* @__PURE__ */ new Set();
@@ -162,7 +171,7 @@ var init_logger = __esm({
162
171
  });
163
172
 
164
173
  // src/config/defaults.ts
165
- var defaultResolve, defaultServer, defaultBuild, defaultElectron, defaultExperimental, defaults;
174
+ var defaultResolve, defaultServer, defaultBuild, defaultElectron, defaultExperimental, defaultReact, defaults;
166
175
  var init_defaults = __esm({
167
176
  "src/config/defaults.ts"() {
168
177
  "use strict";
@@ -215,12 +224,20 @@ var init_defaults = __esm({
215
224
  defaultExperimental = {
216
225
  bundledDev: false
217
226
  };
227
+ defaultReact = {
228
+ include: /\.[tj]sx?$/,
229
+ exclude: /node_modules/,
230
+ jsxImportSource: "react",
231
+ jsxRuntime: "automatic",
232
+ compiler: false
233
+ };
218
234
  defaults = {
219
235
  root: ".",
220
236
  base: "/",
221
237
  mode: "development",
222
238
  target: "web",
223
239
  framework: "auto",
240
+ react: defaultReact,
224
241
  resolve: defaultResolve,
225
242
  server: defaultServer,
226
243
  build: defaultBuild,
@@ -445,6 +462,13 @@ async function resolveConfig(inlineConfig = {}, command) {
445
462
  mode,
446
463
  target: merged.target ?? defaults.target,
447
464
  framework: (merged.framework ?? defaults.framework) === "auto" ? detectFramework(root) : merged.framework,
465
+ react: {
466
+ include: merged.react?.include ?? defaultReact.include,
467
+ exclude: merged.react?.exclude ?? defaultReact.exclude,
468
+ jsxImportSource: merged.react?.jsxImportSource ?? defaultReact.jsxImportSource,
469
+ jsxRuntime: merged.react?.jsxRuntime ?? defaultReact.jsxRuntime,
470
+ compiler: merged.react?.compiler === true ? {} : merged.react?.compiler ?? defaultReact.compiler
471
+ },
448
472
  command,
449
473
  resolve: {
450
474
  // tsconfig paths 优先级最低:tsconfig < defaults < user config
@@ -1359,13 +1383,88 @@ ${msg}`);
1359
1383
  map: result.map ? JSON.stringify(result.map) : null
1360
1384
  };
1361
1385
  }
1362
- var JS_EXTENSIONS, TS_EXTENSIONS, JSX_EXTENSIONS;
1386
+ async function transformReactCode(filename, code, options) {
1387
+ if (!matchesReactFilter(filename, options.react.include, options.react.exclude)) {
1388
+ return null;
1389
+ }
1390
+ if (!options.react.compiler) {
1391
+ if (!shouldTransform(filename)) return null;
1392
+ return transformCode(filename, code, {
1393
+ sourcemap: options.sourcemap,
1394
+ jsxRuntime: options.react.jsxRuntime,
1395
+ jsxImportSource: options.react.jsxImportSource,
1396
+ reactRefresh: options.reactRefresh,
1397
+ target: options.target
1398
+ });
1399
+ }
1400
+ if (!shouldTransform(filename)) return null;
1401
+ const compiler2 = await loadReactCompiler();
1402
+ const compilerOptions = options.react.compiler;
1403
+ const shouldCompile = options.consumer === "client" && (compilerOptions.compilationMode === "annotation" ? /['"]use memo['"]/.test(code) : defaultReactCompilerCodeFilter.test(code));
1404
+ const result = await compiler2.transform(cleanTransformId(filename), code, {
1405
+ jsx: {
1406
+ runtime: options.react.jsxRuntime,
1407
+ development: options.development,
1408
+ importSource: options.react.jsxImportSource,
1409
+ refresh: options.consumer === "client" && !!options.reactRefresh
1410
+ },
1411
+ reactCompiler: shouldCompile ? compilerOptions : false,
1412
+ sourcemap: options.sourcemap ?? true
1413
+ });
1414
+ const diagnostics = result.errors.map(
1415
+ (error) => `${error.message}${error.codeframe ? `
1416
+ ${error.codeframe}` : ""}`
1417
+ );
1418
+ if (result.fatal) {
1419
+ throw new Error(
1420
+ diagnostics.join("\n\n") || `React Compiler transform failed for ${filename}`
1421
+ );
1422
+ }
1423
+ for (const diagnostic of diagnostics) options.onWarning?.(diagnostic);
1424
+ return {
1425
+ code: result.code,
1426
+ map: result.map ? JSON.stringify(result.map) : null
1427
+ };
1428
+ }
1429
+ function matchesReactFilter(id, include, exclude) {
1430
+ const cleanId = cleanTransformId(id);
1431
+ return matchesFilter(cleanId, include) && !matchesFilter(cleanId, exclude);
1432
+ }
1433
+ function matchesFilter(id, filter2) {
1434
+ const patterns = Array.isArray(filter2) ? filter2 : [filter2];
1435
+ return patterns.some((pattern) => {
1436
+ if (pattern instanceof RegExp) {
1437
+ pattern.lastIndex = 0;
1438
+ return pattern.test(id);
1439
+ }
1440
+ if (!pattern.includes("*")) return id.includes(pattern);
1441
+ const expression = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\0").replace(/\*/g, "[^/]*").replace(/\0/g, ".*");
1442
+ return new RegExp(`^${expression}$`).test(id);
1443
+ });
1444
+ }
1445
+ function cleanTransformId(id) {
1446
+ return id.split(/[?#]/, 1)[0];
1447
+ }
1448
+ async function loadReactCompiler() {
1449
+ if (reactCompilerImplementation) return reactCompilerImplementation;
1450
+ try {
1451
+ reactCompilerImplementation = await import("oxc-transform-react");
1452
+ return reactCompilerImplementation;
1453
+ } catch (error) {
1454
+ throw new Error(
1455
+ '[nasti] React Compiler requires the optional "oxc-transform-react" package. Install it before setting react.compiler.' + (error instanceof Error ? `
1456
+ ${error.message}` : "")
1457
+ );
1458
+ }
1459
+ }
1460
+ var JS_EXTENSIONS, TS_EXTENSIONS, JSX_EXTENSIONS, defaultReactCompilerCodeFilter, reactCompilerImplementation;
1363
1461
  var init_transformer = __esm({
1364
1462
  "src/core/transformer.ts"() {
1365
1463
  "use strict";
1366
1464
  JS_EXTENSIONS = /\.(js|mjs|cjs)$/;
1367
1465
  TS_EXTENSIONS = /\.(ts|mts|cts)$/;
1368
1466
  JSX_EXTENSIONS = /\.(jsx|tsx)$/;
1467
+ defaultReactCompilerCodeFilter = /forwardRef|memo|\b(?:[A-Z]|use[A-Z0-9])/;
1369
1468
  }
1370
1469
  });
1371
1470
 
@@ -2001,22 +2100,35 @@ async function transformRequest(url, ctx) {
2001
2100
  }
2002
2101
  const stableUrl = cleanReqUrl;
2003
2102
  let wrappedWithRefresh = false;
2004
- if (shouldTransform(filePath)) {
2005
- const isJsx = /\.[jt]sx$/.test(filePath);
2006
- const useRefresh = isJsx && config.framework !== "vue";
2103
+ if (config.framework === "react") {
2104
+ const refreshEnabled = (ctx.environment?.consumer ?? "client") === "client" && config.server.hmr !== false;
2105
+ const useRefresh = refreshEnabled && (!!config.react.compiler || /\.[jt]sx$/.test(filePath));
2106
+ const result = await transformReactCode(filePath, code, {
2107
+ react: config.react,
2108
+ consumer: ctx.environment?.consumer ?? "client",
2109
+ development: true,
2110
+ reactRefresh: useRefresh,
2111
+ sourcemap: true,
2112
+ target: ctx.environment?.options.build.target ?? config.build.target,
2113
+ onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
2114
+ });
2115
+ if (result) {
2116
+ code = result.code;
2117
+ if (result.map) map = JSON.parse(result.map);
2118
+ if (useRefresh) {
2119
+ code = buildReactRefreshWrapper(stableUrl, code);
2120
+ wrappedWithRefresh = true;
2121
+ }
2122
+ }
2123
+ } else if (shouldTransform(filePath)) {
2007
2124
  const result = transformCode(filePath, code, {
2008
2125
  sourcemap: true,
2009
2126
  jsxRuntime: "automatic",
2010
- jsxImportSource: config.framework === "vue" ? "vue" : "react",
2011
- reactRefresh: useRefresh,
2127
+ jsxImportSource: "vue",
2012
2128
  target: ctx.environment?.options.build.target ?? config.build.target
2013
2129
  });
2014
2130
  code = result.code;
2015
2131
  if (result.map) map = JSON.parse(result.map);
2016
- if (useRefresh) {
2017
- code = buildReactRefreshWrapper(stableUrl, code);
2018
- wrappedWithRefresh = true;
2019
- }
2020
2132
  }
2021
2133
  const hotInfo = rewriteHotAcceptDeps(code, config, filePath);
2022
2134
  code = hotInfo.code;
@@ -2227,8 +2339,8 @@ function rewriteExternalRequires(code, baseDir, root) {
2227
2339
  }
2228
2340
  async function injectCjsNamedExports(code, entryFile) {
2229
2341
  try {
2230
- const { createRequire: createRequire7 } = await import("module");
2231
- const req = createRequire7(entryFile);
2342
+ const { createRequire: createRequire6 } = await import("module");
2343
+ const req = createRequire6(entryFile);
2232
2344
  const cjsExports = req(entryFile);
2233
2345
  if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
2234
2346
  const namedKeys = Object.keys(cjsExports).filter(
@@ -3220,27 +3332,27 @@ var require_process = __commonJS({
3220
3332
  var require_filesystem = __commonJS({
3221
3333
  "node_modules/detect-libc/lib/filesystem.js"(exports, module) {
3222
3334
  "use strict";
3223
- var fs14 = __require("fs");
3335
+ var fs15 = __require("fs");
3224
3336
  var LDD_PATH = "/usr/bin/ldd";
3225
3337
  var SELF_PATH = "/proc/self/exe";
3226
3338
  var MAX_LENGTH = 2048;
3227
- var readFileSync = (path19) => {
3228
- const fd = fs14.openSync(path19, "r");
3339
+ var readFileSync = (path21) => {
3340
+ const fd = fs15.openSync(path21, "r");
3229
3341
  const buffer = Buffer.alloc(MAX_LENGTH);
3230
- const bytesRead = fs14.readSync(fd, buffer, 0, MAX_LENGTH, 0);
3231
- fs14.close(fd, () => {
3342
+ const bytesRead = fs15.readSync(fd, buffer, 0, MAX_LENGTH, 0);
3343
+ fs15.close(fd, () => {
3232
3344
  });
3233
3345
  return buffer.subarray(0, bytesRead);
3234
3346
  };
3235
- var readFile = (path19) => new Promise((resolve, reject) => {
3236
- fs14.open(path19, "r", (err, fd) => {
3347
+ var readFile = (path21) => new Promise((resolve, reject) => {
3348
+ fs15.open(path21, "r", (err, fd) => {
3237
3349
  if (err) {
3238
3350
  reject(err);
3239
3351
  } else {
3240
3352
  const buffer = Buffer.alloc(MAX_LENGTH);
3241
- fs14.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
3353
+ fs15.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
3242
3354
  resolve(buffer.subarray(0, bytesRead));
3243
- fs14.close(fd, () => {
3355
+ fs15.close(fd, () => {
3244
3356
  });
3245
3357
  });
3246
3358
  }
@@ -3352,11 +3464,11 @@ var require_detect_libc = __commonJS({
3352
3464
  }
3353
3465
  return null;
3354
3466
  };
3355
- var familyFromInterpreterPath = (path19) => {
3356
- if (path19) {
3357
- if (path19.includes("/ld-musl-")) {
3467
+ var familyFromInterpreterPath = (path21) => {
3468
+ if (path21) {
3469
+ if (path21.includes("/ld-musl-")) {
3358
3470
  return MUSL;
3359
- } else if (path19.includes("/ld-linux-")) {
3471
+ } else if (path21.includes("/ld-linux-")) {
3360
3472
  return GLIBC;
3361
3473
  }
3362
3474
  }
@@ -3403,8 +3515,8 @@ var require_detect_libc = __commonJS({
3403
3515
  cachedFamilyInterpreter = null;
3404
3516
  try {
3405
3517
  const selfContent = await readFile(SELF_PATH);
3406
- const path19 = interpreterPath(selfContent);
3407
- cachedFamilyInterpreter = familyFromInterpreterPath(path19);
3518
+ const path21 = interpreterPath(selfContent);
3519
+ cachedFamilyInterpreter = familyFromInterpreterPath(path21);
3408
3520
  } catch (e) {
3409
3521
  }
3410
3522
  return cachedFamilyInterpreter;
@@ -3416,8 +3528,8 @@ var require_detect_libc = __commonJS({
3416
3528
  cachedFamilyInterpreter = null;
3417
3529
  try {
3418
3530
  const selfContent = readFileSync(SELF_PATH);
3419
- const path19 = interpreterPath(selfContent);
3420
- cachedFamilyInterpreter = familyFromInterpreterPath(path19);
3531
+ const path21 = interpreterPath(selfContent);
3532
+ cachedFamilyInterpreter = familyFromInterpreterPath(path21);
3421
3533
  } catch (e) {
3422
3534
  }
3423
3535
  return cachedFamilyInterpreter;
@@ -4444,8 +4556,8 @@ function vuePlugin(config, environmentName = "client") {
4444
4556
  let cached2 = descriptorCache.get(filePath);
4445
4557
  if (!cached2) {
4446
4558
  try {
4447
- const fs14 = await import("fs");
4448
- const rawSource = fs14.readFileSync(filePath, "utf-8");
4559
+ const fs15 = await import("fs");
4560
+ const rawSource = fs15.readFileSync(filePath, "utf-8");
4449
4561
  const transformedSfc = await applySourceTransform(
4450
4562
  vueOptions.transformSfc,
4451
4563
  rawSource,
@@ -4867,16 +4979,1320 @@ var init_builtins = __esm({
4867
4979
  }
4868
4980
  });
4869
4981
 
4982
+ // node_modules/import-meta-resolve/lib/errors.js
4983
+ import v8 from "v8";
4984
+ import assert from "assert";
4985
+ import { format, inspect } from "util";
4986
+ function formatList(array, type = "and") {
4987
+ return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array[array.length - 1]}`;
4988
+ }
4989
+ function createError(sym, value, constructor) {
4990
+ messages.set(sym, value);
4991
+ return makeNodeErrorWithCode(constructor, sym);
4992
+ }
4993
+ function makeNodeErrorWithCode(Base, key) {
4994
+ return NodeError;
4995
+ function NodeError(...parameters) {
4996
+ const limit = Error.stackTraceLimit;
4997
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
4998
+ const error = new Base();
4999
+ if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
5000
+ const message = getMessage(key, parameters, error);
5001
+ Object.defineProperties(error, {
5002
+ // Note: no need to implement `kIsNodeError` symbol, would be hard,
5003
+ // probably.
5004
+ message: {
5005
+ value: message,
5006
+ enumerable: false,
5007
+ writable: true,
5008
+ configurable: true
5009
+ },
5010
+ toString: {
5011
+ /** @this {Error} */
5012
+ value() {
5013
+ return `${this.name} [${key}]: ${this.message}`;
5014
+ },
5015
+ enumerable: false,
5016
+ writable: true,
5017
+ configurable: true
5018
+ }
5019
+ });
5020
+ captureLargerStackTrace(error);
5021
+ error.code = key;
5022
+ return error;
5023
+ }
5024
+ }
5025
+ function isErrorStackTraceLimitWritable() {
5026
+ try {
5027
+ if (v8.startupSnapshot.isBuildingSnapshot()) {
5028
+ return false;
5029
+ }
5030
+ } catch {
5031
+ }
5032
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
5033
+ if (desc === void 0) {
5034
+ return Object.isExtensible(Error);
5035
+ }
5036
+ return own.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
5037
+ }
5038
+ function hideStackFrames(wrappedFunction) {
5039
+ const hidden = nodeInternalPrefix + wrappedFunction.name;
5040
+ Object.defineProperty(wrappedFunction, "name", { value: hidden });
5041
+ return wrappedFunction;
5042
+ }
5043
+ function getMessage(key, parameters, self) {
5044
+ const message = messages.get(key);
5045
+ assert.ok(message !== void 0, "expected `message` to be found");
5046
+ if (typeof message === "function") {
5047
+ assert.ok(
5048
+ message.length <= parameters.length,
5049
+ // Default options do not count.
5050
+ `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`
5051
+ );
5052
+ return Reflect.apply(message, self, parameters);
5053
+ }
5054
+ const regex = /%[dfijoOs]/g;
5055
+ let expectedLength = 0;
5056
+ while (regex.exec(message) !== null) expectedLength++;
5057
+ assert.ok(
5058
+ expectedLength === parameters.length,
5059
+ `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`
5060
+ );
5061
+ if (parameters.length === 0) return message;
5062
+ parameters.unshift(message);
5063
+ return Reflect.apply(format, null, parameters);
5064
+ }
5065
+ function determineSpecificType(value) {
5066
+ if (value === null || value === void 0) {
5067
+ return String(value);
5068
+ }
5069
+ if (typeof value === "function" && value.name) {
5070
+ return `function ${value.name}`;
5071
+ }
5072
+ if (typeof value === "object") {
5073
+ if (value.constructor && value.constructor.name) {
5074
+ return `an instance of ${value.constructor.name}`;
5075
+ }
5076
+ return `${inspect(value, { depth: -1 })}`;
5077
+ }
5078
+ let inspected = inspect(value, { colors: false });
5079
+ if (inspected.length > 28) {
5080
+ inspected = `${inspected.slice(0, 25)}...`;
5081
+ }
5082
+ return `type ${typeof value} (${inspected})`;
5083
+ }
5084
+ var own, classRegExp, kTypes, codes, messages, nodeInternalPrefix, userStackTraceLimit, captureLargerStackTrace;
5085
+ var init_errors = __esm({
5086
+ "node_modules/import-meta-resolve/lib/errors.js"() {
5087
+ "use strict";
5088
+ own = {}.hasOwnProperty;
5089
+ classRegExp = /^([A-Z][a-z\d]*)+$/;
5090
+ kTypes = /* @__PURE__ */ new Set([
5091
+ "string",
5092
+ "function",
5093
+ "number",
5094
+ "object",
5095
+ // Accept 'Function' and 'Object' as alternative to the lower cased version.
5096
+ "Function",
5097
+ "Object",
5098
+ "boolean",
5099
+ "bigint",
5100
+ "symbol"
5101
+ ]);
5102
+ codes = {};
5103
+ messages = /* @__PURE__ */ new Map();
5104
+ nodeInternalPrefix = "__node_internal_";
5105
+ codes.ERR_INVALID_ARG_TYPE = createError(
5106
+ "ERR_INVALID_ARG_TYPE",
5107
+ /**
5108
+ * @param {string} name
5109
+ * @param {Array<string> | string} expected
5110
+ * @param {unknown} actual
5111
+ */
5112
+ (name, expected, actual) => {
5113
+ assert.ok(typeof name === "string", "'name' must be a string");
5114
+ if (!Array.isArray(expected)) {
5115
+ expected = [expected];
5116
+ }
5117
+ let message = "The ";
5118
+ if (name.endsWith(" argument")) {
5119
+ message += `${name} `;
5120
+ } else {
5121
+ const type = name.includes(".") ? "property" : "argument";
5122
+ message += `"${name}" ${type} `;
5123
+ }
5124
+ message += "must be ";
5125
+ const types = [];
5126
+ const instances = [];
5127
+ const other = [];
5128
+ for (const value of expected) {
5129
+ assert.ok(
5130
+ typeof value === "string",
5131
+ "All expected entries have to be of type string"
5132
+ );
5133
+ if (kTypes.has(value)) {
5134
+ types.push(value.toLowerCase());
5135
+ } else if (classRegExp.exec(value) === null) {
5136
+ assert.ok(
5137
+ value !== "object",
5138
+ 'The value "object" should be written as "Object"'
5139
+ );
5140
+ other.push(value);
5141
+ } else {
5142
+ instances.push(value);
5143
+ }
5144
+ }
5145
+ if (instances.length > 0) {
5146
+ const pos = types.indexOf("object");
5147
+ if (pos !== -1) {
5148
+ types.slice(pos, 1);
5149
+ instances.push("Object");
5150
+ }
5151
+ }
5152
+ if (types.length > 0) {
5153
+ message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(
5154
+ types,
5155
+ "or"
5156
+ )}`;
5157
+ if (instances.length > 0 || other.length > 0) message += " or ";
5158
+ }
5159
+ if (instances.length > 0) {
5160
+ message += `an instance of ${formatList(instances, "or")}`;
5161
+ if (other.length > 0) message += " or ";
5162
+ }
5163
+ if (other.length > 0) {
5164
+ if (other.length > 1) {
5165
+ message += `one of ${formatList(other, "or")}`;
5166
+ } else {
5167
+ if (other[0].toLowerCase() !== other[0]) message += "an ";
5168
+ message += `${other[0]}`;
5169
+ }
5170
+ }
5171
+ message += `. Received ${determineSpecificType(actual)}`;
5172
+ return message;
5173
+ },
5174
+ TypeError
5175
+ );
5176
+ codes.ERR_INVALID_MODULE_SPECIFIER = createError(
5177
+ "ERR_INVALID_MODULE_SPECIFIER",
5178
+ /**
5179
+ * @param {string} request
5180
+ * @param {string} reason
5181
+ * @param {string} [base]
5182
+ */
5183
+ (request, reason, base = void 0) => {
5184
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
5185
+ },
5186
+ TypeError
5187
+ );
5188
+ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
5189
+ "ERR_INVALID_PACKAGE_CONFIG",
5190
+ /**
5191
+ * @param {string} path
5192
+ * @param {string} [base]
5193
+ * @param {string} [message]
5194
+ */
5195
+ (path21, base, message) => {
5196
+ return `Invalid package config ${path21}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
5197
+ },
5198
+ Error
5199
+ );
5200
+ codes.ERR_INVALID_PACKAGE_TARGET = createError(
5201
+ "ERR_INVALID_PACKAGE_TARGET",
5202
+ /**
5203
+ * @param {string} packagePath
5204
+ * @param {string} key
5205
+ * @param {unknown} target
5206
+ * @param {boolean} [isImport=false]
5207
+ * @param {string} [base]
5208
+ */
5209
+ (packagePath, key, target, isImport = false, base = void 0) => {
5210
+ const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
5211
+ if (key === ".") {
5212
+ assert.ok(isImport === false);
5213
+ 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 "./"' : ""}`;
5214
+ }
5215
+ return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
5216
+ target
5217
+ )} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
5218
+ },
5219
+ Error
5220
+ );
5221
+ codes.ERR_MODULE_NOT_FOUND = createError(
5222
+ "ERR_MODULE_NOT_FOUND",
5223
+ /**
5224
+ * @param {string} path
5225
+ * @param {string} base
5226
+ * @param {boolean} [exactUrl]
5227
+ */
5228
+ (path21, base, exactUrl = false) => {
5229
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path21}' imported from ${base}`;
5230
+ },
5231
+ Error
5232
+ );
5233
+ codes.ERR_NETWORK_IMPORT_DISALLOWED = createError(
5234
+ "ERR_NETWORK_IMPORT_DISALLOWED",
5235
+ "import of '%s' by %s is not supported: %s",
5236
+ Error
5237
+ );
5238
+ codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
5239
+ "ERR_PACKAGE_IMPORT_NOT_DEFINED",
5240
+ /**
5241
+ * @param {string} specifier
5242
+ * @param {string} packagePath
5243
+ * @param {string} base
5244
+ */
5245
+ (specifier, packagePath, base) => {
5246
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
5247
+ },
5248
+ TypeError
5249
+ );
5250
+ codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
5251
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
5252
+ /**
5253
+ * @param {string} packagePath
5254
+ * @param {string} subpath
5255
+ * @param {string} [base]
5256
+ */
5257
+ (packagePath, subpath, base = void 0) => {
5258
+ if (subpath === ".")
5259
+ return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
5260
+ return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
5261
+ },
5262
+ Error
5263
+ );
5264
+ codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
5265
+ "ERR_UNSUPPORTED_DIR_IMPORT",
5266
+ "Directory import '%s' is not supported resolving ES modules imported from %s",
5267
+ Error
5268
+ );
5269
+ codes.ERR_UNSUPPORTED_RESOLVE_REQUEST = createError(
5270
+ "ERR_UNSUPPORTED_RESOLVE_REQUEST",
5271
+ 'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.',
5272
+ TypeError
5273
+ );
5274
+ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
5275
+ "ERR_UNKNOWN_FILE_EXTENSION",
5276
+ /**
5277
+ * @param {string} extension
5278
+ * @param {string} path
5279
+ */
5280
+ (extension, path21) => {
5281
+ return `Unknown file extension "${extension}" for ${path21}`;
5282
+ },
5283
+ TypeError
5284
+ );
5285
+ codes.ERR_INVALID_ARG_VALUE = createError(
5286
+ "ERR_INVALID_ARG_VALUE",
5287
+ /**
5288
+ * @param {string} name
5289
+ * @param {unknown} value
5290
+ * @param {string} [reason='is invalid']
5291
+ */
5292
+ (name, value, reason = "is invalid") => {
5293
+ let inspected = inspect(value);
5294
+ if (inspected.length > 128) {
5295
+ inspected = `${inspected.slice(0, 128)}...`;
5296
+ }
5297
+ const type = name.includes(".") ? "property" : "argument";
5298
+ return `The ${type} '${name}' ${reason}. Received ${inspected}`;
5299
+ },
5300
+ TypeError
5301
+ // Note: extra classes have been shaken out.
5302
+ // , RangeError
5303
+ );
5304
+ captureLargerStackTrace = hideStackFrames(
5305
+ /**
5306
+ * @param {Error} error
5307
+ * @returns {Error}
5308
+ */
5309
+ // @ts-expect-error: fine
5310
+ function(error) {
5311
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
5312
+ if (stackTraceLimitIsWritable) {
5313
+ userStackTraceLimit = Error.stackTraceLimit;
5314
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
5315
+ }
5316
+ Error.captureStackTrace(error);
5317
+ if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
5318
+ return error;
5319
+ }
5320
+ );
5321
+ }
5322
+ });
5323
+
5324
+ // node_modules/import-meta-resolve/lib/package-json-reader.js
5325
+ import fs9 from "fs";
5326
+ import path11 from "path";
5327
+ import { fileURLToPath as fileURLToPath2 } from "url";
5328
+ function read(jsonPath, { base, specifier }) {
5329
+ const existing = cache.get(jsonPath);
5330
+ if (existing) {
5331
+ return existing;
5332
+ }
5333
+ let string;
5334
+ try {
5335
+ string = fs9.readFileSync(path11.toNamespacedPath(jsonPath), "utf8");
5336
+ } catch (error) {
5337
+ const exception = (
5338
+ /** @type {ErrnoException} */
5339
+ error
5340
+ );
5341
+ if (exception.code !== "ENOENT") {
5342
+ throw exception;
5343
+ }
5344
+ }
5345
+ const result = {
5346
+ exists: false,
5347
+ pjsonPath: jsonPath,
5348
+ main: void 0,
5349
+ name: void 0,
5350
+ type: "none",
5351
+ // Ignore unknown types for forwards compatibility
5352
+ exports: void 0,
5353
+ imports: void 0
5354
+ };
5355
+ if (string !== void 0) {
5356
+ let parsed;
5357
+ try {
5358
+ parsed = JSON.parse(string);
5359
+ } catch (error_) {
5360
+ const cause = (
5361
+ /** @type {ErrnoException} */
5362
+ error_
5363
+ );
5364
+ const error = new ERR_INVALID_PACKAGE_CONFIG(
5365
+ jsonPath,
5366
+ (base ? `"${specifier}" from ` : "") + fileURLToPath2(base || specifier),
5367
+ cause.message
5368
+ );
5369
+ error.cause = cause;
5370
+ throw error;
5371
+ }
5372
+ result.exists = true;
5373
+ if (hasOwnProperty.call(parsed, "name") && typeof parsed.name === "string") {
5374
+ result.name = parsed.name;
5375
+ }
5376
+ if (hasOwnProperty.call(parsed, "main") && typeof parsed.main === "string") {
5377
+ result.main = parsed.main;
5378
+ }
5379
+ if (hasOwnProperty.call(parsed, "exports")) {
5380
+ result.exports = parsed.exports;
5381
+ }
5382
+ if (hasOwnProperty.call(parsed, "imports")) {
5383
+ result.imports = parsed.imports;
5384
+ }
5385
+ if (hasOwnProperty.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) {
5386
+ result.type = parsed.type;
5387
+ }
5388
+ }
5389
+ cache.set(jsonPath, result);
5390
+ return result;
5391
+ }
5392
+ function getPackageScopeConfig(resolved) {
5393
+ let packageJSONUrl = new URL("package.json", resolved);
5394
+ while (true) {
5395
+ const packageJSONPath2 = packageJSONUrl.pathname;
5396
+ if (packageJSONPath2.endsWith("node_modules/package.json")) {
5397
+ break;
5398
+ }
5399
+ const packageConfig = read(fileURLToPath2(packageJSONUrl), {
5400
+ specifier: resolved
5401
+ });
5402
+ if (packageConfig.exists) {
5403
+ return packageConfig;
5404
+ }
5405
+ const lastPackageJSONUrl = packageJSONUrl;
5406
+ packageJSONUrl = new URL("../package.json", packageJSONUrl);
5407
+ if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
5408
+ break;
5409
+ }
5410
+ }
5411
+ const packageJSONPath = fileURLToPath2(packageJSONUrl);
5412
+ return {
5413
+ pjsonPath: packageJSONPath,
5414
+ exists: false,
5415
+ type: "none"
5416
+ };
5417
+ }
5418
+ function getPackageType(url) {
5419
+ return getPackageScopeConfig(url).type;
5420
+ }
5421
+ var hasOwnProperty, ERR_INVALID_PACKAGE_CONFIG, cache;
5422
+ var init_package_json_reader = __esm({
5423
+ "node_modules/import-meta-resolve/lib/package-json-reader.js"() {
5424
+ "use strict";
5425
+ init_errors();
5426
+ hasOwnProperty = {}.hasOwnProperty;
5427
+ ({ ERR_INVALID_PACKAGE_CONFIG } = codes);
5428
+ cache = /* @__PURE__ */ new Map();
5429
+ }
5430
+ });
5431
+
5432
+ // node_modules/import-meta-resolve/lib/get-format.js
5433
+ import { fileURLToPath as fileURLToPath3 } from "url";
5434
+ function mimeToFormat(mime) {
5435
+ if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime))
5436
+ return "module";
5437
+ if (mime === "application/json") return "json";
5438
+ return null;
5439
+ }
5440
+ function getDataProtocolModuleFormat(parsed) {
5441
+ const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
5442
+ parsed.pathname
5443
+ ) || [null, null, null];
5444
+ return mimeToFormat(mime);
5445
+ }
5446
+ function extname(url) {
5447
+ const pathname = url.pathname;
5448
+ let index2 = pathname.length;
5449
+ while (index2--) {
5450
+ const code = pathname.codePointAt(index2);
5451
+ if (code === 47) {
5452
+ return "";
5453
+ }
5454
+ if (code === 46) {
5455
+ return pathname.codePointAt(index2 - 1) === 47 ? "" : pathname.slice(index2);
5456
+ }
5457
+ }
5458
+ return "";
5459
+ }
5460
+ function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
5461
+ const value = extname(url);
5462
+ if (value === ".js") {
5463
+ const packageType = getPackageType(url);
5464
+ if (packageType !== "none") {
5465
+ return packageType;
5466
+ }
5467
+ return "commonjs";
5468
+ }
5469
+ if (value === "") {
5470
+ const packageType = getPackageType(url);
5471
+ if (packageType === "none" || packageType === "commonjs") {
5472
+ return "commonjs";
5473
+ }
5474
+ return "module";
5475
+ }
5476
+ const format2 = extensionFormatMap[value];
5477
+ if (format2) return format2;
5478
+ if (ignoreErrors) {
5479
+ return void 0;
5480
+ }
5481
+ const filepath = fileURLToPath3(url);
5482
+ throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath);
5483
+ }
5484
+ function getHttpProtocolModuleFormat() {
5485
+ }
5486
+ function defaultGetFormatWithoutErrors(url, context) {
5487
+ const protocol = url.protocol;
5488
+ if (!hasOwnProperty2.call(protocolHandlers, protocol)) {
5489
+ return null;
5490
+ }
5491
+ return protocolHandlers[protocol](url, context, true) || null;
5492
+ }
5493
+ var ERR_UNKNOWN_FILE_EXTENSION, hasOwnProperty2, extensionFormatMap, protocolHandlers;
5494
+ var init_get_format = __esm({
5495
+ "node_modules/import-meta-resolve/lib/get-format.js"() {
5496
+ "use strict";
5497
+ init_package_json_reader();
5498
+ init_errors();
5499
+ ({ ERR_UNKNOWN_FILE_EXTENSION } = codes);
5500
+ hasOwnProperty2 = {}.hasOwnProperty;
5501
+ extensionFormatMap = {
5502
+ // @ts-expect-error: hush.
5503
+ __proto__: null,
5504
+ ".cjs": "commonjs",
5505
+ ".js": "module",
5506
+ ".json": "json",
5507
+ ".mjs": "module"
5508
+ };
5509
+ protocolHandlers = {
5510
+ // @ts-expect-error: hush.
5511
+ __proto__: null,
5512
+ "data:": getDataProtocolModuleFormat,
5513
+ "file:": getFileProtocolModuleFormat,
5514
+ "http:": getHttpProtocolModuleFormat,
5515
+ "https:": getHttpProtocolModuleFormat,
5516
+ "node:"() {
5517
+ return "builtin";
5518
+ }
5519
+ };
5520
+ }
5521
+ });
5522
+
5523
+ // node_modules/import-meta-resolve/lib/utils.js
5524
+ function getDefaultConditions() {
5525
+ return DEFAULT_CONDITIONS;
5526
+ }
5527
+ function getDefaultConditionsSet() {
5528
+ return DEFAULT_CONDITIONS_SET;
5529
+ }
5530
+ function getConditionsSet(conditions) {
5531
+ if (conditions !== void 0 && conditions !== getDefaultConditions()) {
5532
+ if (!Array.isArray(conditions)) {
5533
+ throw new ERR_INVALID_ARG_VALUE(
5534
+ "conditions",
5535
+ conditions,
5536
+ "expected an array"
5537
+ );
5538
+ }
5539
+ return new Set(conditions);
5540
+ }
5541
+ return getDefaultConditionsSet();
5542
+ }
5543
+ var ERR_INVALID_ARG_VALUE, DEFAULT_CONDITIONS, DEFAULT_CONDITIONS_SET;
5544
+ var init_utils = __esm({
5545
+ "node_modules/import-meta-resolve/lib/utils.js"() {
5546
+ "use strict";
5547
+ init_errors();
5548
+ ({ ERR_INVALID_ARG_VALUE } = codes);
5549
+ DEFAULT_CONDITIONS = Object.freeze(["node", "import"]);
5550
+ DEFAULT_CONDITIONS_SET = new Set(DEFAULT_CONDITIONS);
5551
+ }
5552
+ });
5553
+
5554
+ // node_modules/import-meta-resolve/lib/resolve.js
5555
+ import assert2 from "assert";
5556
+ import { statSync, realpathSync } from "fs";
5557
+ import process2 from "process";
5558
+ import { fileURLToPath as fileURLToPath4, pathToFileURL as pathToFileURL4 } from "url";
5559
+ import path12 from "path";
5560
+ import { builtinModules } from "module";
5561
+ function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
5562
+ if (process2.noDeprecation) {
5563
+ return;
5564
+ }
5565
+ const pjsonPath = fileURLToPath4(packageJsonUrl);
5566
+ const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
5567
+ process2.emitWarning(
5568
+ `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 ${fileURLToPath4(base)}` : ""}.`,
5569
+ "DeprecationWarning",
5570
+ "DEP0166"
5571
+ );
5572
+ }
5573
+ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
5574
+ if (process2.noDeprecation) {
5575
+ return;
5576
+ }
5577
+ const format2 = defaultGetFormatWithoutErrors(url, { parentURL: base.href });
5578
+ if (format2 !== "module") return;
5579
+ const urlPath = fileURLToPath4(url.href);
5580
+ const packagePath = fileURLToPath4(new URL(".", packageJsonUrl));
5581
+ const basePath = fileURLToPath4(base);
5582
+ if (!main) {
5583
+ process2.emitWarning(
5584
+ `No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(
5585
+ packagePath.length
5586
+ )}", imported from ${basePath}.
5587
+ Default "index" lookups for the main are deprecated for ES modules.`,
5588
+ "DeprecationWarning",
5589
+ "DEP0151"
5590
+ );
5591
+ } else if (path12.resolve(packagePath, main) !== urlPath) {
5592
+ process2.emitWarning(
5593
+ `Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(
5594
+ packagePath.length
5595
+ )}", imported from ${basePath}.
5596
+ Automatic extension resolution of the "main" field is deprecated for ES modules.`,
5597
+ "DeprecationWarning",
5598
+ "DEP0151"
5599
+ );
5600
+ }
5601
+ }
5602
+ function tryStatSync(path21) {
5603
+ try {
5604
+ return statSync(path21);
5605
+ } catch {
5606
+ }
5607
+ }
5608
+ function fileExists(url) {
5609
+ const stats = statSync(url, { throwIfNoEntry: false });
5610
+ const isFile = stats ? stats.isFile() : void 0;
5611
+ return isFile === null || isFile === void 0 ? false : isFile;
5612
+ }
5613
+ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
5614
+ let guess;
5615
+ if (packageConfig.main !== void 0) {
5616
+ guess = new URL(packageConfig.main, packageJsonUrl);
5617
+ if (fileExists(guess)) return guess;
5618
+ const tries2 = [
5619
+ `./${packageConfig.main}.js`,
5620
+ `./${packageConfig.main}.json`,
5621
+ `./${packageConfig.main}.node`,
5622
+ `./${packageConfig.main}/index.js`,
5623
+ `./${packageConfig.main}/index.json`,
5624
+ `./${packageConfig.main}/index.node`
5625
+ ];
5626
+ let i2 = -1;
5627
+ while (++i2 < tries2.length) {
5628
+ guess = new URL(tries2[i2], packageJsonUrl);
5629
+ if (fileExists(guess)) break;
5630
+ guess = void 0;
5631
+ }
5632
+ if (guess) {
5633
+ emitLegacyIndexDeprecation(
5634
+ guess,
5635
+ packageJsonUrl,
5636
+ base,
5637
+ packageConfig.main
5638
+ );
5639
+ return guess;
5640
+ }
5641
+ }
5642
+ const tries = ["./index.js", "./index.json", "./index.node"];
5643
+ let i = -1;
5644
+ while (++i < tries.length) {
5645
+ guess = new URL(tries[i], packageJsonUrl);
5646
+ if (fileExists(guess)) break;
5647
+ guess = void 0;
5648
+ }
5649
+ if (guess) {
5650
+ emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
5651
+ return guess;
5652
+ }
5653
+ throw new ERR_MODULE_NOT_FOUND(
5654
+ fileURLToPath4(new URL(".", packageJsonUrl)),
5655
+ fileURLToPath4(base)
5656
+ );
5657
+ }
5658
+ function finalizeResolution(resolved, base, preserveSymlinks) {
5659
+ if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
5660
+ throw new ERR_INVALID_MODULE_SPECIFIER(
5661
+ resolved.pathname,
5662
+ 'must not include encoded "/" or "\\" characters',
5663
+ fileURLToPath4(base)
5664
+ );
5665
+ }
5666
+ let filePath;
5667
+ try {
5668
+ filePath = fileURLToPath4(resolved);
5669
+ } catch (error) {
5670
+ const cause = (
5671
+ /** @type {ErrnoException} */
5672
+ error
5673
+ );
5674
+ Object.defineProperty(cause, "input", { value: String(resolved) });
5675
+ Object.defineProperty(cause, "module", { value: String(base) });
5676
+ throw cause;
5677
+ }
5678
+ const stats = tryStatSync(
5679
+ filePath.endsWith("/") ? filePath.slice(-1) : filePath
5680
+ );
5681
+ if (stats && stats.isDirectory()) {
5682
+ const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath4(base));
5683
+ error.url = String(resolved);
5684
+ throw error;
5685
+ }
5686
+ if (!stats || !stats.isFile()) {
5687
+ const error = new ERR_MODULE_NOT_FOUND(
5688
+ filePath || resolved.pathname,
5689
+ base && fileURLToPath4(base),
5690
+ true
5691
+ );
5692
+ error.url = String(resolved);
5693
+ throw error;
5694
+ }
5695
+ if (!preserveSymlinks) {
5696
+ const real = realpathSync(filePath);
5697
+ const { search, hash } = resolved;
5698
+ resolved = pathToFileURL4(real + (filePath.endsWith(path12.sep) ? "/" : ""));
5699
+ resolved.search = search;
5700
+ resolved.hash = hash;
5701
+ }
5702
+ return resolved;
5703
+ }
5704
+ function importNotDefined(specifier, packageJsonUrl, base) {
5705
+ return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
5706
+ specifier,
5707
+ packageJsonUrl && fileURLToPath4(new URL(".", packageJsonUrl)),
5708
+ fileURLToPath4(base)
5709
+ );
5710
+ }
5711
+ function exportsNotFound(subpath, packageJsonUrl, base) {
5712
+ return new ERR_PACKAGE_PATH_NOT_EXPORTED(
5713
+ fileURLToPath4(new URL(".", packageJsonUrl)),
5714
+ subpath,
5715
+ base && fileURLToPath4(base)
5716
+ );
5717
+ }
5718
+ function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
5719
+ const reason = `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath4(packageJsonUrl)}`;
5720
+ throw new ERR_INVALID_MODULE_SPECIFIER(
5721
+ request,
5722
+ reason,
5723
+ base && fileURLToPath4(base)
5724
+ );
5725
+ }
5726
+ function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
5727
+ target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
5728
+ return new ERR_INVALID_PACKAGE_TARGET(
5729
+ fileURLToPath4(new URL(".", packageJsonUrl)),
5730
+ subpath,
5731
+ target,
5732
+ internal,
5733
+ base && fileURLToPath4(base)
5734
+ );
5735
+ }
5736
+ function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
5737
+ if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
5738
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
5739
+ if (!target.startsWith("./")) {
5740
+ if (internal && !target.startsWith("../") && !target.startsWith("/")) {
5741
+ let isURL = false;
5742
+ try {
5743
+ new URL(target);
5744
+ isURL = true;
5745
+ } catch {
5746
+ }
5747
+ if (!isURL) {
5748
+ const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(
5749
+ patternRegEx,
5750
+ target,
5751
+ () => subpath
5752
+ ) : target + subpath;
5753
+ return packageResolve(exportTarget, packageJsonUrl, conditions);
5754
+ }
5755
+ }
5756
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
5757
+ }
5758
+ if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
5759
+ if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
5760
+ if (!isPathMap) {
5761
+ const request = pattern ? match.replace("*", () => subpath) : match + subpath;
5762
+ const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
5763
+ patternRegEx,
5764
+ target,
5765
+ () => subpath
5766
+ ) : target;
5767
+ emitInvalidSegmentDeprecation(
5768
+ resolvedTarget,
5769
+ request,
5770
+ match,
5771
+ packageJsonUrl,
5772
+ internal,
5773
+ base,
5774
+ true
5775
+ );
5776
+ }
5777
+ } else {
5778
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
5779
+ }
5780
+ }
5781
+ const resolved = new URL(target, packageJsonUrl);
5782
+ const resolvedPath = resolved.pathname;
5783
+ const packagePath = new URL(".", packageJsonUrl).pathname;
5784
+ if (!resolvedPath.startsWith(packagePath))
5785
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
5786
+ if (subpath === "") return resolved;
5787
+ if (invalidSegmentRegEx.exec(subpath) !== null) {
5788
+ const request = pattern ? match.replace("*", () => subpath) : match + subpath;
5789
+ if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
5790
+ if (!isPathMap) {
5791
+ const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(
5792
+ patternRegEx,
5793
+ target,
5794
+ () => subpath
5795
+ ) : target;
5796
+ emitInvalidSegmentDeprecation(
5797
+ resolvedTarget,
5798
+ request,
5799
+ match,
5800
+ packageJsonUrl,
5801
+ internal,
5802
+ base,
5803
+ false
5804
+ );
5805
+ }
5806
+ } else {
5807
+ throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
5808
+ }
5809
+ }
5810
+ if (pattern) {
5811
+ return new URL(
5812
+ RegExpPrototypeSymbolReplace.call(
5813
+ patternRegEx,
5814
+ resolved.href,
5815
+ () => subpath
5816
+ )
5817
+ );
5818
+ }
5819
+ return new URL(subpath, resolved);
5820
+ }
5821
+ function isArrayIndex(key) {
5822
+ const keyNumber = Number(key);
5823
+ if (`${keyNumber}` !== key) return false;
5824
+ return keyNumber >= 0 && keyNumber < 4294967295;
5825
+ }
5826
+ function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
5827
+ if (typeof target === "string") {
5828
+ return resolvePackageTargetString(
5829
+ target,
5830
+ subpath,
5831
+ packageSubpath,
5832
+ packageJsonUrl,
5833
+ base,
5834
+ pattern,
5835
+ internal,
5836
+ isPathMap,
5837
+ conditions
5838
+ );
5839
+ }
5840
+ if (Array.isArray(target)) {
5841
+ const targetList = target;
5842
+ if (targetList.length === 0) return null;
5843
+ let lastException;
5844
+ let i = -1;
5845
+ while (++i < targetList.length) {
5846
+ const targetItem = targetList[i];
5847
+ let resolveResult;
5848
+ try {
5849
+ resolveResult = resolvePackageTarget(
5850
+ packageJsonUrl,
5851
+ targetItem,
5852
+ subpath,
5853
+ packageSubpath,
5854
+ base,
5855
+ pattern,
5856
+ internal,
5857
+ isPathMap,
5858
+ conditions
5859
+ );
5860
+ } catch (error) {
5861
+ const exception = (
5862
+ /** @type {ErrnoException} */
5863
+ error
5864
+ );
5865
+ lastException = exception;
5866
+ if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
5867
+ throw error;
5868
+ }
5869
+ if (resolveResult === void 0) continue;
5870
+ if (resolveResult === null) {
5871
+ lastException = null;
5872
+ continue;
5873
+ }
5874
+ return resolveResult;
5875
+ }
5876
+ if (lastException === void 0 || lastException === null) {
5877
+ return null;
5878
+ }
5879
+ throw lastException;
5880
+ }
5881
+ if (typeof target === "object" && target !== null) {
5882
+ const keys = Object.getOwnPropertyNames(target);
5883
+ let i = -1;
5884
+ while (++i < keys.length) {
5885
+ const key = keys[i];
5886
+ if (isArrayIndex(key)) {
5887
+ throw new ERR_INVALID_PACKAGE_CONFIG2(
5888
+ fileURLToPath4(packageJsonUrl),
5889
+ base,
5890
+ '"exports" cannot contain numeric property keys.'
5891
+ );
5892
+ }
5893
+ }
5894
+ i = -1;
5895
+ while (++i < keys.length) {
5896
+ const key = keys[i];
5897
+ if (key === "default" || conditions && conditions.has(key)) {
5898
+ const conditionalTarget = (
5899
+ /** @type {unknown} */
5900
+ target[key]
5901
+ );
5902
+ const resolveResult = resolvePackageTarget(
5903
+ packageJsonUrl,
5904
+ conditionalTarget,
5905
+ subpath,
5906
+ packageSubpath,
5907
+ base,
5908
+ pattern,
5909
+ internal,
5910
+ isPathMap,
5911
+ conditions
5912
+ );
5913
+ if (resolveResult === void 0) continue;
5914
+ return resolveResult;
5915
+ }
5916
+ }
5917
+ return null;
5918
+ }
5919
+ if (target === null) {
5920
+ return null;
5921
+ }
5922
+ throw invalidPackageTarget(
5923
+ packageSubpath,
5924
+ target,
5925
+ packageJsonUrl,
5926
+ internal,
5927
+ base
5928
+ );
5929
+ }
5930
+ function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
5931
+ if (typeof exports === "string" || Array.isArray(exports)) return true;
5932
+ if (typeof exports !== "object" || exports === null) return false;
5933
+ const keys = Object.getOwnPropertyNames(exports);
5934
+ let isConditionalSugar = false;
5935
+ let i = 0;
5936
+ let keyIndex = -1;
5937
+ while (++keyIndex < keys.length) {
5938
+ const key = keys[keyIndex];
5939
+ const currentIsConditionalSugar = key === "" || key[0] !== ".";
5940
+ if (i++ === 0) {
5941
+ isConditionalSugar = currentIsConditionalSugar;
5942
+ } else if (isConditionalSugar !== currentIsConditionalSugar) {
5943
+ throw new ERR_INVALID_PACKAGE_CONFIG2(
5944
+ fileURLToPath4(packageJsonUrl),
5945
+ base,
5946
+ `"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.`
5947
+ );
5948
+ }
5949
+ }
5950
+ return isConditionalSugar;
5951
+ }
5952
+ function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
5953
+ if (process2.noDeprecation) {
5954
+ return;
5955
+ }
5956
+ const pjsonPath = fileURLToPath4(pjsonUrl);
5957
+ if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
5958
+ emittedPackageWarnings.add(pjsonPath + "|" + match);
5959
+ process2.emitWarning(
5960
+ `Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath4(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`,
5961
+ "DeprecationWarning",
5962
+ "DEP0155"
5963
+ );
5964
+ }
5965
+ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
5966
+ let exports = packageConfig.exports;
5967
+ if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
5968
+ exports = { ".": exports };
5969
+ }
5970
+ if (own2.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
5971
+ const target = exports[packageSubpath];
5972
+ const resolveResult = resolvePackageTarget(
5973
+ packageJsonUrl,
5974
+ target,
5975
+ "",
5976
+ packageSubpath,
5977
+ base,
5978
+ false,
5979
+ false,
5980
+ false,
5981
+ conditions
5982
+ );
5983
+ if (resolveResult === null || resolveResult === void 0) {
5984
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
5985
+ }
5986
+ return resolveResult;
5987
+ }
5988
+ let bestMatch = "";
5989
+ let bestMatchSubpath = "";
5990
+ const keys = Object.getOwnPropertyNames(exports);
5991
+ let i = -1;
5992
+ while (++i < keys.length) {
5993
+ const key = keys[i];
5994
+ const patternIndex = key.indexOf("*");
5995
+ if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
5996
+ if (packageSubpath.endsWith("/")) {
5997
+ emitTrailingSlashPatternDeprecation(
5998
+ packageSubpath,
5999
+ packageJsonUrl,
6000
+ base
6001
+ );
6002
+ }
6003
+ const patternTrailer = key.slice(patternIndex + 1);
6004
+ if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
6005
+ bestMatch = key;
6006
+ bestMatchSubpath = packageSubpath.slice(
6007
+ patternIndex,
6008
+ packageSubpath.length - patternTrailer.length
6009
+ );
6010
+ }
6011
+ }
6012
+ }
6013
+ if (bestMatch) {
6014
+ const target = (
6015
+ /** @type {unknown} */
6016
+ exports[bestMatch]
6017
+ );
6018
+ const resolveResult = resolvePackageTarget(
6019
+ packageJsonUrl,
6020
+ target,
6021
+ bestMatchSubpath,
6022
+ bestMatch,
6023
+ base,
6024
+ true,
6025
+ false,
6026
+ packageSubpath.endsWith("/"),
6027
+ conditions
6028
+ );
6029
+ if (resolveResult === null || resolveResult === void 0) {
6030
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
6031
+ }
6032
+ return resolveResult;
6033
+ }
6034
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
6035
+ }
6036
+ function patternKeyCompare(a, b) {
6037
+ const aPatternIndex = a.indexOf("*");
6038
+ const bPatternIndex = b.indexOf("*");
6039
+ const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
6040
+ const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
6041
+ if (baseLengthA > baseLengthB) return -1;
6042
+ if (baseLengthB > baseLengthA) return 1;
6043
+ if (aPatternIndex === -1) return 1;
6044
+ if (bPatternIndex === -1) return -1;
6045
+ if (a.length > b.length) return -1;
6046
+ if (b.length > a.length) return 1;
6047
+ return 0;
6048
+ }
6049
+ function packageImportsResolve(name, base, conditions) {
6050
+ if (name === "#" || name.startsWith("#/") || name.endsWith("/")) {
6051
+ const reason = "is not a valid internal imports specifier name";
6052
+ throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath4(base));
6053
+ }
6054
+ let packageJsonUrl;
6055
+ const packageConfig = getPackageScopeConfig(base);
6056
+ if (packageConfig.exists) {
6057
+ packageJsonUrl = pathToFileURL4(packageConfig.pjsonPath);
6058
+ const imports = packageConfig.imports;
6059
+ if (imports) {
6060
+ if (own2.call(imports, name) && !name.includes("*")) {
6061
+ const resolveResult = resolvePackageTarget(
6062
+ packageJsonUrl,
6063
+ imports[name],
6064
+ "",
6065
+ name,
6066
+ base,
6067
+ false,
6068
+ true,
6069
+ false,
6070
+ conditions
6071
+ );
6072
+ if (resolveResult !== null && resolveResult !== void 0) {
6073
+ return resolveResult;
6074
+ }
6075
+ } else {
6076
+ let bestMatch = "";
6077
+ let bestMatchSubpath = "";
6078
+ const keys = Object.getOwnPropertyNames(imports);
6079
+ let i = -1;
6080
+ while (++i < keys.length) {
6081
+ const key = keys[i];
6082
+ const patternIndex = key.indexOf("*");
6083
+ if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
6084
+ const patternTrailer = key.slice(patternIndex + 1);
6085
+ if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
6086
+ bestMatch = key;
6087
+ bestMatchSubpath = name.slice(
6088
+ patternIndex,
6089
+ name.length - patternTrailer.length
6090
+ );
6091
+ }
6092
+ }
6093
+ }
6094
+ if (bestMatch) {
6095
+ const target = imports[bestMatch];
6096
+ const resolveResult = resolvePackageTarget(
6097
+ packageJsonUrl,
6098
+ target,
6099
+ bestMatchSubpath,
6100
+ bestMatch,
6101
+ base,
6102
+ true,
6103
+ true,
6104
+ false,
6105
+ conditions
6106
+ );
6107
+ if (resolveResult !== null && resolveResult !== void 0) {
6108
+ return resolveResult;
6109
+ }
6110
+ }
6111
+ }
6112
+ }
6113
+ }
6114
+ throw importNotDefined(name, packageJsonUrl, base);
6115
+ }
6116
+ function parsePackageName(specifier, base) {
6117
+ let separatorIndex = specifier.indexOf("/");
6118
+ let validPackageName = true;
6119
+ let isScoped = false;
6120
+ if (specifier[0] === "@") {
6121
+ isScoped = true;
6122
+ if (separatorIndex === -1 || specifier.length === 0) {
6123
+ validPackageName = false;
6124
+ } else {
6125
+ separatorIndex = specifier.indexOf("/", separatorIndex + 1);
6126
+ }
6127
+ }
6128
+ const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
6129
+ if (invalidPackageNameRegEx.exec(packageName) !== null) {
6130
+ validPackageName = false;
6131
+ }
6132
+ if (!validPackageName) {
6133
+ throw new ERR_INVALID_MODULE_SPECIFIER(
6134
+ specifier,
6135
+ "is not a valid package name",
6136
+ fileURLToPath4(base)
6137
+ );
6138
+ }
6139
+ const packageSubpath = "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex));
6140
+ return { packageName, packageSubpath, isScoped };
6141
+ }
6142
+ function packageResolve(specifier, base, conditions) {
6143
+ if (builtinModules.includes(specifier)) {
6144
+ return new URL("node:" + specifier);
6145
+ }
6146
+ const { packageName, packageSubpath, isScoped } = parsePackageName(
6147
+ specifier,
6148
+ base
6149
+ );
6150
+ const packageConfig = getPackageScopeConfig(base);
6151
+ if (packageConfig.exists) {
6152
+ const packageJsonUrl2 = pathToFileURL4(packageConfig.pjsonPath);
6153
+ if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) {
6154
+ return packageExportsResolve(
6155
+ packageJsonUrl2,
6156
+ packageSubpath,
6157
+ packageConfig,
6158
+ base,
6159
+ conditions
6160
+ );
6161
+ }
6162
+ }
6163
+ let packageJsonUrl = new URL(
6164
+ "./node_modules/" + packageName + "/package.json",
6165
+ base
6166
+ );
6167
+ let packageJsonPath = fileURLToPath4(packageJsonUrl);
6168
+ let lastPath;
6169
+ do {
6170
+ const stat = tryStatSync(packageJsonPath.slice(0, -13));
6171
+ if (!stat || !stat.isDirectory()) {
6172
+ lastPath = packageJsonPath;
6173
+ packageJsonUrl = new URL(
6174
+ (isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
6175
+ packageJsonUrl
6176
+ );
6177
+ packageJsonPath = fileURLToPath4(packageJsonUrl);
6178
+ continue;
6179
+ }
6180
+ const packageConfig2 = read(packageJsonPath, { base, specifier });
6181
+ if (packageConfig2.exports !== void 0 && packageConfig2.exports !== null) {
6182
+ return packageExportsResolve(
6183
+ packageJsonUrl,
6184
+ packageSubpath,
6185
+ packageConfig2,
6186
+ base,
6187
+ conditions
6188
+ );
6189
+ }
6190
+ if (packageSubpath === ".") {
6191
+ return legacyMainResolve(packageJsonUrl, packageConfig2, base);
6192
+ }
6193
+ return new URL(packageSubpath, packageJsonUrl);
6194
+ } while (packageJsonPath.length !== lastPath.length);
6195
+ throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath4(base), false);
6196
+ }
6197
+ function isRelativeSpecifier(specifier) {
6198
+ if (specifier[0] === ".") {
6199
+ if (specifier.length === 1 || specifier[1] === "/") return true;
6200
+ if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) {
6201
+ return true;
6202
+ }
6203
+ }
6204
+ return false;
6205
+ }
6206
+ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
6207
+ if (specifier === "") return false;
6208
+ if (specifier[0] === "/") return true;
6209
+ return isRelativeSpecifier(specifier);
6210
+ }
6211
+ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
6212
+ if (conditions === void 0) {
6213
+ conditions = getConditionsSet();
6214
+ }
6215
+ const protocol = base.protocol;
6216
+ const isData = protocol === "data:";
6217
+ const isRemote = isData || protocol === "http:" || protocol === "https:";
6218
+ let resolved;
6219
+ if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
6220
+ try {
6221
+ resolved = new URL(specifier, base);
6222
+ } catch (error_) {
6223
+ const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
6224
+ error.cause = error_;
6225
+ throw error;
6226
+ }
6227
+ } else if (protocol === "file:" && specifier[0] === "#") {
6228
+ resolved = packageImportsResolve(specifier, base, conditions);
6229
+ } else {
6230
+ try {
6231
+ resolved = new URL(specifier);
6232
+ } catch (error_) {
6233
+ if (isRemote && !builtinModules.includes(specifier)) {
6234
+ const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
6235
+ error.cause = error_;
6236
+ throw error;
6237
+ }
6238
+ resolved = packageResolve(specifier, base, conditions);
6239
+ }
6240
+ }
6241
+ assert2.ok(resolved !== void 0, "expected to be defined");
6242
+ if (resolved.protocol !== "file:") {
6243
+ return resolved;
6244
+ }
6245
+ return finalizeResolution(resolved, base, preserveSymlinks);
6246
+ }
6247
+ var RegExpPrototypeSymbolReplace, ERR_NETWORK_IMPORT_DISALLOWED, ERR_INVALID_MODULE_SPECIFIER, ERR_INVALID_PACKAGE_CONFIG2, 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, own2, invalidSegmentRegEx, deprecatedInvalidSegmentRegEx, invalidPackageNameRegEx, patternRegEx, encodedSeparatorRegEx, emittedPackageWarnings, doubleSlashRegEx;
6248
+ var init_resolve2 = __esm({
6249
+ "node_modules/import-meta-resolve/lib/resolve.js"() {
6250
+ "use strict";
6251
+ init_get_format();
6252
+ init_errors();
6253
+ init_package_json_reader();
6254
+ init_utils();
6255
+ RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
6256
+ ({
6257
+ ERR_NETWORK_IMPORT_DISALLOWED,
6258
+ ERR_INVALID_MODULE_SPECIFIER,
6259
+ ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG2,
6260
+ ERR_INVALID_PACKAGE_TARGET,
6261
+ ERR_MODULE_NOT_FOUND,
6262
+ ERR_PACKAGE_IMPORT_NOT_DEFINED,
6263
+ ERR_PACKAGE_PATH_NOT_EXPORTED,
6264
+ ERR_UNSUPPORTED_DIR_IMPORT,
6265
+ ERR_UNSUPPORTED_RESOLVE_REQUEST
6266
+ } = codes);
6267
+ own2 = {}.hasOwnProperty;
6268
+ 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;
6269
+ 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;
6270
+ invalidPackageNameRegEx = /^\.|%|\\/;
6271
+ patternRegEx = /\*/g;
6272
+ encodedSeparatorRegEx = /%2f|%5c/i;
6273
+ emittedPackageWarnings = /* @__PURE__ */ new Set();
6274
+ doubleSlashRegEx = /[/\\]{2}/;
6275
+ }
6276
+ });
6277
+
6278
+ // node_modules/import-meta-resolve/index.js
6279
+ var init_import_meta_resolve = __esm({
6280
+ "node_modules/import-meta-resolve/index.js"() {
6281
+ "use strict";
6282
+ init_resolve2();
6283
+ }
6284
+ });
6285
+
4870
6286
  // src/server/runnable-environment.ts
4871
6287
  var runnable_environment_exports = {};
4872
6288
  __export(runnable_environment_exports, {
4873
6289
  NastiModuleRunner: () => NastiModuleRunner,
4874
6290
  createModuleRunner: () => createModuleRunner
4875
6291
  });
4876
- import path11 from "path";
4877
- import fs9 from "fs";
4878
- import { builtinModules, createRequire as createRequire4 } from "module";
4879
- import { pathToFileURL as pathToFileURL4 } from "url";
6292
+ import path13 from "path";
6293
+ import fs10 from "fs";
6294
+ import { builtinModules as builtinModules2 } from "module";
6295
+ import { pathToFileURL as pathToFileURL5 } from "url";
4880
6296
  function createModuleRunner(environment) {
4881
6297
  if (environment.consumer !== "server") {
4882
6298
  throw new Error(
@@ -4889,17 +6305,19 @@ var debug4, NODE_BUILTINS, NastiModuleRunner, AsyncFunction;
4889
6305
  var init_runnable_environment = __esm({
4890
6306
  "src/server/runnable-environment.ts"() {
4891
6307
  "use strict";
6308
+ init_import_meta_resolve();
4892
6309
  init_transformer();
4893
6310
  init_env();
4894
6311
  init_debug();
4895
6312
  debug4 = createDebugger("nasti:ssr");
4896
- NODE_BUILTINS = /* @__PURE__ */ new Set([...builtinModules, ...builtinModules.map((m) => `node:${m}`)]);
6313
+ NODE_BUILTINS = /* @__PURE__ */ new Set([...builtinModules2, ...builtinModules2.map((m) => `node:${m}`)]);
4897
6314
  NastiModuleRunner = class {
4898
6315
  environment;
4899
6316
  config;
4900
6317
  cache = /* @__PURE__ */ new Map();
4901
6318
  envDefine;
4902
- require;
6319
+ externalImportParent;
6320
+ externalImportConditions;
4903
6321
  constructor(environment) {
4904
6322
  this.environment = environment;
4905
6323
  this.config = environment.config;
@@ -4908,10 +6326,15 @@ var init_runnable_environment = __esm({
4908
6326
  this.config.mode,
4909
6327
  ssrDefineOverrides(environment.consumer)
4910
6328
  );
4911
- this.require = createRequire4(path11.join(this.config.root, "package.json"));
6329
+ this.externalImportParent = pathToFileURL5(path13.join(this.config.root, "package.json"));
6330
+ this.externalImportConditions = /* @__PURE__ */ new Set([
6331
+ ...environment.options.resolve.conditions.filter((condition) => condition !== "require"),
6332
+ "node",
6333
+ "import"
6334
+ ]);
4912
6335
  const handlers = {
4913
6336
  fetchModule: async (id, importer) => this.fetchModule(id, importer),
4914
- getBuiltins: () => [/^node:/, ...builtinModules]
6337
+ getBuiltins: () => [/^node:/, ...builtinModules2]
4915
6338
  };
4916
6339
  environment.hot.setInvokeHandler?.(handlers);
4917
6340
  }
@@ -4932,9 +6355,9 @@ var init_runnable_environment = __esm({
4932
6355
  this.cache.clear();
4933
6356
  }
4934
6357
  resolveToId(rawUrl) {
4935
- if (path11.isAbsolute(rawUrl) && fs9.existsSync(rawUrl.split("?")[0])) return rawUrl;
6358
+ if (path13.isAbsolute(rawUrl) && fs10.existsSync(rawUrl.split("?")[0])) return rawUrl;
4936
6359
  const clean = rawUrl.replace(/^\//, "");
4937
- return path11.resolve(this.config.root, clean);
6360
+ return path13.resolve(this.config.root, clean);
4938
6361
  }
4939
6362
  /**
4940
6363
  * fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
@@ -4943,14 +6366,14 @@ var init_runnable_environment = __esm({
4943
6366
  */
4944
6367
  async fetchModule(id, importer) {
4945
6368
  if (NODE_BUILTINS.has(id)) return { externalize: id };
4946
- if (!id.startsWith(".") && !path11.isAbsolute(id) && !id.startsWith("\0")) {
6369
+ if (!id.startsWith(".") && !path13.isAbsolute(id) && !id.startsWith("\0")) {
4947
6370
  return { externalize: id };
4948
6371
  }
4949
6372
  const container = this.environment.pluginContainer;
4950
6373
  let resolvedId = id;
4951
6374
  if (id.startsWith(".") && importer) {
4952
6375
  const resolved = await container.resolveId(id, importer);
4953
- resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : path11.resolve(path11.dirname(importer.split("?")[0]), id);
6376
+ resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : path13.resolve(path13.dirname(importer.split("?")[0]), id);
4954
6377
  }
4955
6378
  resolvedId = this.completeExtension(resolvedId);
4956
6379
  const cleanId = resolvedId.split("?")[0];
@@ -4958,8 +6381,8 @@ var init_runnable_environment = __esm({
4958
6381
  const loaded = await container.load(resolvedId);
4959
6382
  if (loaded != null) {
4960
6383
  code = typeof loaded === "string" ? loaded : loaded.code;
4961
- } else if (fs9.existsSync(cleanId)) {
4962
- code = fs9.readFileSync(cleanId, "utf-8");
6384
+ } else if (fs10.existsSync(cleanId)) {
6385
+ code = fs10.readFileSync(cleanId, "utf-8");
4963
6386
  } else {
4964
6387
  throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
4965
6388
  }
@@ -4967,12 +6390,32 @@ var init_runnable_environment = __esm({
4967
6390
  if (transformed != null) {
4968
6391
  code = typeof transformed === "string" ? transformed : transformed.code;
4969
6392
  }
4970
- if (shouldTransform(cleanId)) {
6393
+ if (this.config.framework === "react") {
6394
+ const result = await transformReactCode(cleanId, code, {
6395
+ react: this.config.react,
6396
+ consumer: this.environment.consumer,
6397
+ development: true,
6398
+ sourcemap: false,
6399
+ target: this.environment.options.build.target,
6400
+ onWarning: (message) => this.config.logger.warn(`[nasti:react] ${message}`)
6401
+ });
6402
+ if (result) {
6403
+ code = result.code;
6404
+ } else if (shouldTransform(cleanId)) {
6405
+ const fallback = transformCode(cleanId, code, {
6406
+ sourcemap: false,
6407
+ jsxRuntime: this.config.react.jsxRuntime,
6408
+ jsxImportSource: this.config.react.jsxImportSource,
6409
+ target: this.environment.options.build.target
6410
+ });
6411
+ code = fallback.code;
6412
+ }
6413
+ } else if (shouldTransform(cleanId)) {
4971
6414
  const result = transformCode(cleanId, code, {
4972
6415
  sourcemap: false,
4973
6416
  target: this.environment.options.build.target,
4974
6417
  jsxRuntime: "automatic",
4975
- jsxImportSource: this.config.framework === "vue" ? "vue" : "react"
6418
+ jsxImportSource: "vue"
4976
6419
  });
4977
6420
  code = result.code;
4978
6421
  }
@@ -4993,19 +6436,19 @@ var init_runnable_environment = __esm({
4993
6436
  completeExtension(id) {
4994
6437
  const clean = id.split("?")[0];
4995
6438
  const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
4996
- if (fs9.existsSync(clean) && fs9.statSync(clean).isFile()) return id;
6439
+ if (fs10.existsSync(clean) && fs10.statSync(clean).isFile()) return id;
4997
6440
  const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
4998
6441
  if (jsMatch) {
4999
6442
  for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
5000
- if (fs9.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
6443
+ if (fs10.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
5001
6444
  }
5002
6445
  }
5003
6446
  for (const ext of this.config.resolve.extensions) {
5004
- if (fs9.existsSync(clean + ext)) return clean + ext + query;
6447
+ if (fs10.existsSync(clean + ext)) return clean + ext + query;
5005
6448
  }
5006
6449
  for (const ext of this.config.resolve.extensions) {
5007
- const indexPath = path11.join(clean, `index${ext}`);
5008
- if (fs9.existsSync(indexPath)) return indexPath;
6450
+ const indexPath = path13.join(clean, `index${ext}`);
6451
+ if (fs10.existsSync(indexPath)) return indexPath;
5009
6452
  }
5010
6453
  return id;
5011
6454
  }
@@ -5032,10 +6475,10 @@ var init_runnable_environment = __esm({
5032
6475
  return;
5033
6476
  }
5034
6477
  const ssrImport = async (dep) => {
5035
- if (NODE_BUILTINS.has(dep) || !dep.startsWith(".") && !path11.isAbsolute(dep) && !dep.startsWith("\0")) {
6478
+ if (NODE_BUILTINS.has(dep) || !dep.startsWith(".") && !path13.isAbsolute(dep) && !dep.startsWith("\0")) {
5036
6479
  return this.importExternal(dep);
5037
6480
  }
5038
- const depId = dep.startsWith(".") ? this.completeExtension(path11.resolve(path11.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
6481
+ const depId = dep.startsWith(".") ? this.completeExtension(path13.resolve(path13.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
5039
6482
  return this.instantiate(depId);
5040
6483
  };
5041
6484
  const ssrExportAll = (sourceModule) => {
@@ -5050,7 +6493,7 @@ var init_runnable_environment = __esm({
5050
6493
  }
5051
6494
  };
5052
6495
  const importMeta = {
5053
- url: pathToFileURL4(fetched.id.split("?")[0]).href,
6496
+ url: pathToFileURL5(fetched.id.split("?")[0]).href,
5054
6497
  env: { SSR: true, MODE: this.config.mode, DEV: this.config.mode !== "production", PROD: this.config.mode === "production" },
5055
6498
  hot: void 0
5056
6499
  };
@@ -5067,20 +6510,21 @@ var init_runnable_environment = __esm({
5067
6510
  }
5068
6511
  async importExternal(spec) {
5069
6512
  try {
5070
- return await (spec.startsWith("node:") || !path11.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import(pathToFileURL4(spec).href));
6513
+ return await (spec.startsWith("node:") || !path13.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import(pathToFileURL5(spec).href));
5071
6514
  } catch (err) {
5072
6515
  throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
5073
6516
  }
5074
6517
  }
5075
- /** bare specifier → 项目 node_modules 的绝对 URL(避免相对 Nasti 自身解析) */
6518
+ /** bare specifier → 项目 node_modules ESM URL(避免相对 Nasti 自身解析) */
5076
6519
  resolveExternalSpecifier(spec) {
5077
6520
  if (spec.startsWith("node:")) return spec;
5078
6521
  if (NODE_BUILTINS.has(spec)) return `node:${spec}`;
5079
- try {
5080
- return pathToFileURL4(this.require.resolve(spec)).href;
5081
- } catch {
5082
- return spec;
5083
- }
6522
+ return moduleResolve(
6523
+ spec,
6524
+ this.externalImportParent,
6525
+ this.externalImportConditions,
6526
+ false
6527
+ ).href;
5084
6528
  }
5085
6529
  };
5086
6530
  AsyncFunction = Object.getPrototypeOf(async function() {
@@ -5088,8 +6532,46 @@ var init_runnable_environment = __esm({
5088
6532
  }
5089
6533
  });
5090
6534
 
6535
+ // src/plugins/react.ts
6536
+ function reactPlugin(config, environment) {
6537
+ return {
6538
+ name: "nasti:oxc-transform",
6539
+ async transform(code, id) {
6540
+ const result = await transformReactCode(id, code, {
6541
+ react: config.react,
6542
+ consumer: environment.consumer,
6543
+ development: config.mode === "development",
6544
+ sourcemap: !!environment.options.build.sourcemap,
6545
+ target: environment.options.build.target,
6546
+ onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
6547
+ });
6548
+ if (!result) return null;
6549
+ return {
6550
+ code: result.code,
6551
+ map: result.map ? JSON.parse(result.map) : void 0
6552
+ };
6553
+ },
6554
+ handleHotUpdate(ctx) {
6555
+ for (const mod of ctx.modules) {
6556
+ if (REACT_FILE_RE.test(mod.url) && matchesReactFilter(mod.url, config.react.include, config.react.exclude)) {
6557
+ mod.isSelfAccepting = true;
6558
+ }
6559
+ }
6560
+ return ctx.modules;
6561
+ }
6562
+ };
6563
+ }
6564
+ var REACT_FILE_RE;
6565
+ var init_react = __esm({
6566
+ "src/plugins/react.ts"() {
6567
+ "use strict";
6568
+ init_transformer();
6569
+ REACT_FILE_RE = /\.[jt]sx(?:[?#].*)?$/;
6570
+ }
6571
+ });
6572
+
5091
6573
  // src/build/reporter.ts
5092
- import path12 from "path";
6574
+ import path14 from "path";
5093
6575
  import { gzipSync } from "zlib";
5094
6576
  import pc5 from "picocolors";
5095
6577
  async function tryNativeReporterPlugin(config, logger) {
@@ -5130,7 +6612,7 @@ function reportBuildOutput(output, config, logger) {
5130
6612
  if (compressed && content != null) {
5131
6613
  gzip = gzipSync(typeof content === "string" ? Buffer.from(content) : content).byteLength;
5132
6614
  }
5133
- const ext = path12.extname(file.fileName);
6615
+ const ext = path14.extname(file.fileName);
5134
6616
  const group = file.type === "chunk" ? "js" : ext === ".css" ? "css" : "assets";
5135
6617
  entries.push({ name: file.fileName, size, gzip, group });
5136
6618
  }
@@ -5178,12 +6660,12 @@ var init_reporter = __esm({
5178
6660
  });
5179
6661
 
5180
6662
  // src/core/build-app-context.ts
5181
- import fs10 from "fs";
5182
- import path13 from "path";
6663
+ import fs11 from "fs";
6664
+ import path15 from "path";
5183
6665
  function createBuildAppContext(config, results) {
5184
6666
  const output = [];
5185
6667
  const emitted = /* @__PURE__ */ new Set();
5186
- const outDir = path13.resolve(config.root, config.build.outDir);
6668
+ const outDir = path15.resolve(config.root, config.build.outDir);
5187
6669
  let environmentArtifacts;
5188
6670
  return {
5189
6671
  config,
@@ -5239,14 +6721,14 @@ function createBuildAppContext(config, results) {
5239
6721
  if (environmentArtifacts.has(collisionKey)) {
5240
6722
  throw new Error(`[nasti] app artifact conflicts with environment output: ${fileName}`);
5241
6723
  }
5242
- const target = path13.resolve(outDir, ...fileName.split("/"));
5243
- const relative = path13.relative(outDir, target);
5244
- if (relative.startsWith("..") || path13.isAbsolute(relative)) {
6724
+ const target = path15.resolve(outDir, ...fileName.split("/"));
6725
+ const relative = path15.relative(outDir, target);
6726
+ if (relative.startsWith("..") || path15.isAbsolute(relative)) {
5245
6727
  throw new Error(`[nasti] app artifact must stay inside build.outDir: ${file.fileName}`);
5246
6728
  }
5247
6729
  assertNoSymlinkComponents(outDir, fileName);
5248
- fs10.mkdirSync(path13.dirname(target), { recursive: true });
5249
- fs10.writeFileSync(target, file.source);
6730
+ fs11.mkdirSync(path15.dirname(target), { recursive: true });
6731
+ fs11.writeFileSync(target, file.source);
5250
6732
  const artifact = {
5251
6733
  ...file,
5252
6734
  fileName,
@@ -5262,10 +6744,10 @@ function joinPublicPath(base, fileName) {
5262
6744
  return `${base.endsWith("/") ? base : `${base}/`}${fileName.replace(/^\//, "")}`;
5263
6745
  }
5264
6746
  function normalizeEnvironmentFileName(fileName) {
5265
- return path13.posix.normalize(fileName.replace(/\\/g, "/").replace(/^\.\//, ""));
6747
+ return path15.posix.normalize(fileName.replace(/\\/g, "/").replace(/^\.\//, ""));
5266
6748
  }
5267
6749
  function isInvalidEnvironmentFileName(fileName) {
5268
- return !fileName || fileName === "." || fileName === ".." || fileName.startsWith("../") || path13.posix.isAbsolute(fileName) || /^[A-Za-z]:\//.test(fileName);
6750
+ return !fileName || fileName === "." || fileName === ".." || fileName.startsWith("../") || path15.posix.isAbsolute(fileName) || /^[A-Za-z]:\//.test(fileName);
5269
6751
  }
5270
6752
  function normalizeAppFileName(fileName) {
5271
6753
  const normalized = normalizeEnvironmentFileName(fileName);
@@ -5282,14 +6764,14 @@ function collectEnvironmentArtifacts(config, results, appOutDir) {
5282
6764
  for (const [environmentName, result] of Object.entries(results)) {
5283
6765
  const environment = config.environments[environmentName];
5284
6766
  if (!environment) continue;
5285
- const environmentOutDir = path13.resolve(config.root, environment.build.outDir);
6767
+ const environmentOutDir = path15.resolve(config.root, environment.build.outDir);
5286
6768
  for (const artifact of result.output) {
5287
- const artifactPath = path13.resolve(
6769
+ const artifactPath = path15.resolve(
5288
6770
  environmentOutDir,
5289
6771
  ...normalizeEnvironmentFileName(artifact.fileName).split("/")
5290
6772
  );
5291
- const relative = path13.relative(appOutDir, artifactPath);
5292
- if (!relative.startsWith("..") && !path13.isAbsolute(relative)) {
6773
+ const relative = path15.relative(appOutDir, artifactPath);
6774
+ if (!relative.startsWith("..") && !path15.isAbsolute(relative)) {
5293
6775
  occupied.add(artifactCollisionKey(relative));
5294
6776
  }
5295
6777
  }
@@ -5299,10 +6781,10 @@ function collectEnvironmentArtifacts(config, results, appOutDir) {
5299
6781
  function assertNoSymlinkComponents(outDir, fileName) {
5300
6782
  let current = outDir;
5301
6783
  for (const segment of fileName.split("/")) {
5302
- current = path13.join(current, segment);
6784
+ current = path15.join(current, segment);
5303
6785
  let stats;
5304
6786
  try {
5305
- stats = fs10.lstatSync(current);
6787
+ stats = fs11.lstatSync(current);
5306
6788
  } catch (error) {
5307
6789
  if (error.code === "ENOENT") continue;
5308
6790
  throw error;
@@ -5335,16 +6817,16 @@ __export(build_exports, {
5335
6817
  resolveClientEntries: () => resolveClientEntries,
5336
6818
  toRolldownPlugins: () => toRolldownPlugins
5337
6819
  });
5338
- import path14 from "path";
5339
- import fs11 from "fs";
5340
- import { builtinModules as builtinModules2 } from "module";
6820
+ import path16 from "path";
6821
+ import fs12 from "fs";
6822
+ import { builtinModules as builtinModules3 } from "module";
5341
6823
  import { rolldown } from "rolldown";
5342
6824
  import pc6 from "picocolors";
5343
6825
  function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
5344
6826
  const config = environment.config;
5345
6827
  const envOptions = environment.options;
5346
6828
  const isServer = environment.consumer === "server";
5347
- const outDir = path14.resolve(config.root, envOptions.build.outDir);
6829
+ const outDir = path16.resolve(config.root, envOptions.build.outDir);
5348
6830
  const assetsDir = envOptions.build.assetsDir;
5349
6831
  const {
5350
6832
  output: userOutput,
@@ -5384,7 +6866,7 @@ function getRolldownOptions(environment, entryPoints, rolldownPlugins) {
5384
6866
  // 相对/绝对/虚拟模块照常打包。需要内联依赖时经 rolldownOptions.external 覆盖。
5385
6867
  external: restInputOptions.external ?? ((id) => {
5386
6868
  if (NODE_BUILTINS2.has(id)) return true;
5387
- return !id.startsWith(".") && !path14.isAbsolute(id) && !id.startsWith("\0");
6869
+ return !id.startsWith(".") && !path16.isAbsolute(id) && !id.startsWith("\0") && !id.startsWith("virtual:");
5388
6870
  })
5389
6871
  } : {}
5390
6872
  };
@@ -5541,11 +7023,11 @@ function prepareBuildOutputDirectories(config, buildableNames) {
5541
7023
  const protectedPaths = /* @__PURE__ */ new Set();
5542
7024
  const clientIsBuilt = buildableNames.includes("client");
5543
7025
  if (!clientIsBuilt && config.build.emptyOutDir) {
5544
- directories.add(path14.resolve(config.root, config.build.outDir));
7026
+ directories.add(path16.resolve(config.root, config.build.outDir));
5545
7027
  }
5546
7028
  for (const name of buildableNames) {
5547
7029
  const environment = config.environments[name];
5548
- const outDir = path14.resolve(config.root, environment.build.outDir);
7030
+ const outDir = path16.resolve(config.root, environment.build.outDir);
5549
7031
  if (!environment.build.emptyOutDir) {
5550
7032
  protectedPaths.add(outDir);
5551
7033
  continue;
@@ -5553,8 +7035,8 @@ function prepareBuildOutputDirectories(config, buildableNames) {
5553
7035
  if (!environment.driver) directories.add(outDir);
5554
7036
  }
5555
7037
  const containsPath = (parent, child) => {
5556
- const relative = path14.relative(parent, child);
5557
- return relative === "" || !relative.startsWith("..") && !path14.isAbsolute(relative);
7038
+ const relative = path16.relative(parent, child);
7039
+ return relative === "" || !relative.startsWith("..") && !path16.isAbsolute(relative);
5558
7040
  };
5559
7041
  const roots = [...directories].filter(
5560
7042
  (directory) => ![...protectedPaths].some((protectedPath) => containsPath(directory, protectedPath))
@@ -5562,7 +7044,7 @@ function prepareBuildOutputDirectories(config, buildableNames) {
5562
7044
  (directory, index2, all) => !all.slice(0, index2).some((parent) => containsPath(parent, directory))
5563
7045
  );
5564
7046
  for (const directory of roots) {
5565
- if (fs11.existsSync(directory)) fs11.rmSync(directory, { recursive: true, force: true });
7047
+ if (fs12.existsSync(directory)) fs12.rmSync(directory, { recursive: true, force: true });
5566
7048
  }
5567
7049
  }
5568
7050
  function assertDriverBuildResult(environment, result) {
@@ -5581,7 +7063,7 @@ function resolveClientEntries(config, html) {
5581
7063
  if (configuredEntries.length > 0) return configuredEntries;
5582
7064
  const entryPoints = [];
5583
7065
  const htmlFile = config.environments.client?.html;
5584
- const htmlDir = htmlFile ? path14.dirname(htmlFile) : config.root;
7066
+ const htmlDir = htmlFile ? path16.dirname(htmlFile) : config.root;
5585
7067
  if (html) {
5586
7068
  const scriptMatches = html.matchAll(/<script[^>]+src=["']([^"']+)["'][^>]*>/gi);
5587
7069
  for (const match of scriptMatches) {
@@ -5589,7 +7071,7 @@ function resolveClientEntries(config, html) {
5589
7071
  if (src && !src.startsWith("http")) {
5590
7072
  const cleanSrc = src.split(/[?#]/, 1)[0];
5591
7073
  entryPoints.push(
5592
- cleanSrc.startsWith("/") ? path14.resolve(config.root, cleanSrc.replace(/^\//, "")) : path14.resolve(htmlDir, cleanSrc)
7074
+ cleanSrc.startsWith("/") ? path16.resolve(config.root, cleanSrc.replace(/^\//, "")) : path16.resolve(htmlDir, cleanSrc)
5593
7075
  );
5594
7076
  }
5595
7077
  }
@@ -5597,8 +7079,8 @@ function resolveClientEntries(config, html) {
5597
7079
  if (entryPoints.length === 0) {
5598
7080
  const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
5599
7081
  for (const entry of fallbackEntries) {
5600
- const fullPath = path14.resolve(config.root, entry);
5601
- if (fs11.existsSync(fullPath)) {
7082
+ const fullPath = path16.resolve(config.root, entry);
7083
+ if (fs12.existsSync(fullPath)) {
5602
7084
  entryPoints.push(fullPath);
5603
7085
  break;
5604
7086
  }
@@ -5607,6 +7089,7 @@ function resolveClientEntries(config, html) {
5607
7089
  return entryPoints;
5608
7090
  }
5609
7091
  function createOxcTransformPlugin(config, environment) {
7092
+ if (config.framework === "react") return reactPlugin(config, environment);
5610
7093
  return {
5611
7094
  name: "nasti:oxc-transform",
5612
7095
  transform(code, id) {
@@ -5627,7 +7110,7 @@ async function build(inlineConfig = {}) {
5627
7110
  const startTime = performance.now();
5628
7111
  logger.info(
5629
7112
  pc6.cyan(`
5630
- nasti v${"2.4.4"} `) + pc6.green(`building for ${config.mode}...`)
7113
+ nasti v${"2.5.1"} `) + pc6.green(`building for ${config.mode}...`)
5631
7114
  );
5632
7115
  debug6?.(`root: ${config.root}`);
5633
7116
  const buildableNames = Object.keys(config.environments).filter((name) => {
@@ -5702,7 +7185,7 @@ nasti v${"2.4.4"} `) + pc6.green(`building for ${config.mode}...`)
5702
7185
  }
5703
7186
  async function buildClientEnvironment(config) {
5704
7187
  const logger = config.logger;
5705
- const outDir = path14.resolve(config.root, config.build.outDir);
7188
+ const outDir = path16.resolve(config.root, config.build.outDir);
5706
7189
  const cssEngine = createCssEngine();
5707
7190
  const pluginList = resolvePluginList(config, config.plugins, {
5708
7191
  cssEngine,
@@ -5725,8 +7208,8 @@ async function buildClientEnvironment(config) {
5725
7208
  assertDriverBuildResult(clientEnv, result);
5726
7209
  return { environment: clientEnv, result: finalizeEnvironmentResult(clientEnv, result) };
5727
7210
  }
5728
- fs11.mkdirSync(outDir, { recursive: true });
5729
- const htmlFile = config.environments.client.html ?? path14.resolve(config.root, "index.html");
7211
+ fs12.mkdirSync(outDir, { recursive: true });
7212
+ const htmlFile = config.environments.client.html ?? path16.resolve(config.root, "index.html");
5730
7213
  const html = await readHtmlFile(config.root, htmlFile);
5731
7214
  const entryPoints = resolveClientEntries(config, html);
5732
7215
  if (entryPoints.length === 0) {
@@ -5776,7 +7259,7 @@ async function buildClientEnvironment(config) {
5776
7259
  );
5777
7260
  }
5778
7261
  }
5779
- fs11.writeFileSync(path14.resolve(outDir, "index.html"), processedHtml);
7262
+ fs12.writeFileSync(path16.resolve(outDir, "index.html"), processedHtml);
5780
7263
  }
5781
7264
  if (!nativeReporter && config.logLevel !== "silent") {
5782
7265
  reportBuildOutput(output, config, logger);
@@ -5830,7 +7313,7 @@ async function buildServerEnvironment(config, name) {
5830
7313
  }
5831
7314
  }
5832
7315
  for (const entry of envOptions.entry) {
5833
- if (!fs11.existsSync(entry)) {
7316
+ if (!fs12.existsSync(entry)) {
5834
7317
  await environment.close();
5835
7318
  throw new Error(`[nasti] environment "${name}" entry not found: ${entry}`);
5836
7319
  }
@@ -5844,13 +7327,13 @@ async function buildServerEnvironment(config, name) {
5844
7327
  envOptions.entry,
5845
7328
  rolldownPlugins
5846
7329
  );
5847
- fs11.mkdirSync(outDir, { recursive: true });
7330
+ fs12.mkdirSync(outDir, { recursive: true });
5848
7331
  const bundle2 = await rolldown(inputOptions);
5849
7332
  const { output } = await bundle2.write(outputOptions);
5850
7333
  await bundle2.close();
5851
7334
  if (cssEngine) environment.setBuildMetadata({ css: getCssMetadata(cssEngine) });
5852
7335
  logger.info(
5853
- pc6.dim(` [${name}] `) + output.map((o) => path14.join(envOptions.build.outDir, o.fileName)).join(pc6.dim(", "))
7336
+ pc6.dim(` [${name}] `) + output.map((o) => path16.join(envOptions.build.outDir, o.fileName)).join(pc6.dim(", "))
5854
7337
  );
5855
7338
  return {
5856
7339
  environment,
@@ -5882,9 +7365,9 @@ function escapeRegExp(string) {
5882
7365
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5883
7366
  }
5884
7367
  function replaceEntryScript(html, facadeModuleId, fileName, config, htmlFile, urlPrefix) {
5885
- const rootRelative = path14.relative(config.root, facadeModuleId).split(path14.sep).join("/");
5886
- const resolvedHtmlFile = path14.resolve(config.root, htmlFile);
5887
- const htmlRelative = path14.relative(path14.dirname(resolvedHtmlFile), facadeModuleId).split(path14.sep).join("/");
7368
+ const rootRelative = path16.relative(config.root, facadeModuleId).split(path16.sep).join("/");
7369
+ const resolvedHtmlFile = path16.resolve(config.root, htmlFile);
7370
+ const htmlRelative = path16.relative(path16.dirname(resolvedHtmlFile), facadeModuleId).split(path16.sep).join("/");
5888
7371
  const candidates = /* @__PURE__ */ new Set([
5889
7372
  rootRelative,
5890
7373
  `/${rootRelative}`,
@@ -5909,6 +7392,7 @@ var init_build = __esm({
5909
7392
  init_environment();
5910
7393
  init_css_engine();
5911
7394
  init_html();
7395
+ init_react();
5912
7396
  init_transformer();
5913
7397
  init_env();
5914
7398
  init_reporter();
@@ -5916,7 +7400,7 @@ var init_build = __esm({
5916
7400
  init_plugin_api();
5917
7401
  init_build_app_context();
5918
7402
  debug6 = createDebugger("nasti:build");
5919
- NODE_BUILTINS2 = /* @__PURE__ */ new Set([...builtinModules2, ...builtinModules2.map((m) => `node:${m}`)]);
7403
+ NODE_BUILTINS2 = /* @__PURE__ */ new Set([...builtinModules3, ...builtinModules3.map((m) => `node:${m}`)]);
5920
7404
  }
5921
7405
  });
5922
7406
 
@@ -5925,7 +7409,7 @@ var dev_engine_exports = {};
5925
7409
  __export(dev_engine_exports, {
5926
7410
  createBundledDevServer: () => createBundledDevServer
5927
7411
  });
5928
- import path15 from "path";
7412
+ import path17 from "path";
5929
7413
  import crypto3 from "crypto";
5930
7414
  import { WebSocketServer as WsServer2 } from "ws";
5931
7415
  import pc7 from "picocolors";
@@ -5955,11 +7439,11 @@ async function createBundledDevServer(opts) {
5955
7439
  const patches = new MemoryFiles();
5956
7440
  const entryFileNames = /* @__PURE__ */ new Map();
5957
7441
  const bundledClients = /* @__PURE__ */ new Map();
5958
- const useReactRefresh = config.framework !== "vue" && refreshWrapperFn != null;
7442
+ const useReactRefresh = config.framework === "react" && config.server.hmr !== false && refreshWrapperFn != null;
5959
7443
  const rolldownPlugins = [
5960
7444
  ...useReactRefresh ? [
5961
7445
  createReactRefreshRuntimePlugin(entryPoints),
5962
- createBundledOxcRefreshPlugin()
7446
+ createBundledOxcRefreshPlugin(config)
5963
7447
  ] : [],
5964
7448
  ...stripCatchAllLoad(toRolldownPlugins(clientEnv.plugins, clientEnv)),
5965
7449
  ...useReactRefresh ? [
@@ -6010,7 +7494,7 @@ async function createBundledDevServer(opts) {
6010
7494
  }
6011
7495
  const url = `/${patchPath}`;
6012
7496
  logger.info(
6013
- pc7.green("hmr update ") + pc7.dim(changedFiles.map((f) => path15.relative(config.root, f)).join(", ")),
7497
+ pc7.green("hmr update ") + pc7.dim(changedFiles.map((f) => path17.relative(config.root, f)).join(", ")),
6014
7498
  { timestamp: true }
6015
7499
  );
6016
7500
  sendTo(clientId, { type: "hmr:update", path: url, url });
@@ -6165,7 +7649,7 @@ async function createBundledDevServer(opts) {
6165
7649
  return;
6166
7650
  }
6167
7651
  res.setHeader("ETag", hit.etag);
6168
- res.setHeader("Content-Type", MIME_TYPES[path15.extname(fileName)] ?? "application/octet-stream");
7652
+ res.setHeader("Content-Type", MIME_TYPES[path17.extname(fileName)] ?? "application/octet-stream");
6169
7653
  res.setHeader("Cache-Control", "no-cache");
6170
7654
  res.once("finish", () => {
6171
7655
  void engine.notifyPayloadDelivered(fileName).catch(
@@ -6206,7 +7690,7 @@ function stripCatchAllLoad(plugins) {
6206
7690
  );
6207
7691
  }
6208
7692
  function createReactRefreshRuntimePlugin(entryPoints) {
6209
- const entryIds = new Set(entryPoints.map((p) => path15.resolve(p)));
7693
+ const entryIds = new Set(entryPoints.map((p) => path17.resolve(p)));
6210
7694
  return {
6211
7695
  name: "nasti:bundled-react-refresh",
6212
7696
  resolveId(source) {
@@ -6224,24 +7708,27 @@ function createReactRefreshRuntimePlugin(entryPoints) {
6224
7708
  return null;
6225
7709
  },
6226
7710
  transform(code, id) {
6227
- if (!entryIds.has(path15.resolve(id.split("?")[0]))) return null;
7711
+ if (!entryIds.has(path17.resolve(id.split("?")[0]))) return null;
6228
7712
  return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
6229
7713
  ${code}`, map: null };
6230
7714
  }
6231
7715
  };
6232
7716
  }
6233
- function createBundledOxcRefreshPlugin() {
7717
+ function createBundledOxcRefreshPlugin(config) {
6234
7718
  return {
6235
7719
  name: "nasti:bundled-oxc-refresh",
6236
- transform(code, id) {
7720
+ async transform(code, id) {
6237
7721
  const clean = id.split("?")[0];
6238
- if (!/\.[jt]sx$/.test(clean) || clean.includes("/node_modules/")) return null;
6239
- const result = transformCode(clean, code, {
7722
+ const result = await transformReactCode(clean, code, {
7723
+ react: config.react,
7724
+ consumer: "client",
7725
+ development: true,
7726
+ reactRefresh: true,
6240
7727
  sourcemap: true,
6241
- jsxRuntime: "automatic",
6242
- jsxImportSource: "react",
6243
- reactRefresh: true
7728
+ target: config.build.target,
7729
+ onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
6244
7730
  });
7731
+ if (!result) return null;
6245
7732
  return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
6246
7733
  }
6247
7734
  };
@@ -6395,7 +7882,7 @@ __export(server_exports, {
6395
7882
  createServer: () => createServer
6396
7883
  });
6397
7884
  import http from "http";
6398
- import path16 from "path";
7885
+ import path18 from "path";
6399
7886
  import os from "os";
6400
7887
  import connect from "connect";
6401
7888
  import sirv from "sirv";
@@ -6488,19 +7975,19 @@ async function createServer(inlineConfig = {}) {
6488
7975
  app.use(bundledServer.middleware);
6489
7976
  }
6490
7977
  const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
6491
- const outDirAbs = path16.resolve(config.root, config.build.outDir);
7978
+ const outDirAbs = path18.resolve(config.root, config.build.outDir);
6492
7979
  const linkedPackageRoots = getLinkedPackageRoots(config.root).filter(
6493
7980
  (r) => r !== config.root && !isUnderRoot(config.root, r)
6494
7981
  );
6495
7982
  const watchTargets = [config.root, ...linkedPackageRoots];
6496
7983
  const watcher = watch(watchTargets, {
6497
7984
  ignored: (filePath) => {
6498
- if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path16.sep)) return true;
7985
+ if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path18.sep)) return true;
6499
7986
  for (const watchRoot of watchTargets) {
6500
7987
  if (filePath === watchRoot) return false;
6501
- const rel = path16.relative(watchRoot, filePath);
6502
- if (!rel || rel.startsWith("..") || path16.isAbsolute(rel)) continue;
6503
- for (const seg of rel.split(path16.sep)) {
7988
+ const rel = path18.relative(watchRoot, filePath);
7989
+ if (!rel || rel.startsWith("..") || path18.isAbsolute(rel)) continue;
7990
+ for (const seg of rel.split(path18.sep)) {
6504
7991
  if (ignoredSegments.has(seg)) return true;
6505
7992
  }
6506
7993
  return false;
@@ -6632,7 +8119,7 @@ async function createServer(inlineConfig = {}) {
6632
8119
  });
6633
8120
  };
6634
8121
  watcher.on("change", (file) => {
6635
- if (file.includes(`${path16.sep}node_modules${path16.sep}`) || file.endsWith(`${path16.sep}node_modules`)) {
8122
+ if (file.includes(`${path18.sep}node_modules${path18.sep}`) || file.endsWith(`${path18.sep}node_modules`)) {
6636
8123
  clearLinkedPackageRootsCache();
6637
8124
  }
6638
8125
  ssrRunner?.invalidateFile(file);
@@ -6640,7 +8127,7 @@ async function createServer(inlineConfig = {}) {
6640
8127
  notifyEnvironmentDrivers(file, "change");
6641
8128
  });
6642
8129
  watcher.on("add", (file) => {
6643
- if (file.includes(`${path16.sep}node_modules${path16.sep}`) || file.endsWith(`${path16.sep}node_modules`)) {
8130
+ if (file.includes(`${path18.sep}node_modules${path18.sep}`) || file.endsWith(`${path18.sep}node_modules`)) {
6644
8131
  clearLinkedPackageRootsCache();
6645
8132
  }
6646
8133
  ssrRunner?.invalidateFile(file);
@@ -6648,7 +8135,7 @@ async function createServer(inlineConfig = {}) {
6648
8135
  notifyEnvironmentDrivers(file, "add");
6649
8136
  });
6650
8137
  watcher.on("unlink", (file) => {
6651
- if (file.includes(`${path16.sep}node_modules${path16.sep}`) || file.endsWith(`${path16.sep}node_modules`)) {
8138
+ if (file.includes(`${path18.sep}node_modules${path18.sep}`) || file.endsWith(`${path18.sep}node_modules`)) {
6652
8139
  clearLinkedPackageRootsCache();
6653
8140
  }
6654
8141
  ssrRunner?.invalidateFile(file);
@@ -6680,7 +8167,7 @@ async function createServer(inlineConfig = {}) {
6680
8167
  const readyIn = Math.ceil(performance.now() - startTime);
6681
8168
  logger.info(
6682
8169
  `
6683
- ${pc8.cyan(pc8.bold("NASTI"))} ${pc8.cyan(`v${"2.4.4"}`)} ${pc8.dim("ready in")} ${pc8.bold(readyIn)} ${pc8.dim("ms")}
8170
+ ${pc8.cyan(pc8.bold("NASTI"))} ${pc8.cyan(`v${"2.5.1"}`)} ${pc8.dim("ready in")} ${pc8.bold(readyIn)} ${pc8.dim("ms")}
6684
8171
  `
6685
8172
  );
6686
8173
  printServerUrls(
@@ -6777,7 +8264,7 @@ async function createServer(inlineConfig = {}) {
6777
8264
  throw error;
6778
8265
  }
6779
8266
  app.use(transformMiddleware(transformContexts.get("client")));
6780
- const publicDir = path16.resolve(config.root, "public");
8267
+ const publicDir = path18.resolve(config.root, "public");
6781
8268
  app.use(sirv(publicDir, { dev: true, etag: true }));
6782
8269
  app.use(sirv(config.root, { dev: true, etag: true }));
6783
8270
  const postMiddlewares = [];
@@ -6821,7 +8308,7 @@ var init_server = __esm({
6821
8308
  });
6822
8309
 
6823
8310
  // src/plugins/electron.ts
6824
- import { builtinModules as builtinModules3 } from "module";
8311
+ import { builtinModules as builtinModules4 } from "module";
6825
8312
  function electronPlugin(config) {
6826
8313
  const external = /* @__PURE__ */ new Set([
6827
8314
  ...ELECTRON_MODULES,
@@ -6847,8 +8334,8 @@ var init_electron = __esm({
6847
8334
  "src/plugins/electron.ts"() {
6848
8335
  "use strict";
6849
8336
  NODE_BUILTINS3 = /* @__PURE__ */ new Set([
6850
- ...builtinModules3,
6851
- ...builtinModules3.map((m) => `node:${m}`)
8337
+ ...builtinModules4,
8338
+ ...builtinModules4.map((m) => `node:${m}`)
6852
8339
  ]);
6853
8340
  ELECTRON_MODULES = /* @__PURE__ */ new Set([
6854
8341
  "electron",
@@ -6867,25 +8354,25 @@ __export(electron_exports, {
6867
8354
  detectInstalledElectron: () => detectInstalledElectron,
6868
8355
  normalizePreload: () => normalizePreload
6869
8356
  });
6870
- import path17 from "path";
6871
- import fs12 from "fs";
6872
- import { createRequire as createRequire5 } from "module";
8357
+ import path19 from "path";
8358
+ import fs13 from "fs";
8359
+ import { createRequire as createRequire4 } from "module";
6873
8360
  import { rolldown as rolldown2 } from "rolldown";
6874
8361
  import pc9 from "picocolors";
6875
8362
  async function buildElectron(inlineConfig = {}) {
6876
8363
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
6877
8364
  const startTime = performance.now();
6878
8365
  assertElectronVersion(config);
6879
- console.log(pc9.cyan("\n\u26A1 nasti build (electron)") + pc9.dim(` v${"2.4.4"}`));
8366
+ console.log(pc9.cyan("\n\u26A1 nasti build (electron)") + pc9.dim(` v${"2.5.1"}`));
6880
8367
  console.log(pc9.dim(` root: ${config.root}`));
6881
8368
  console.log(pc9.dim(` mode: ${config.mode}`));
6882
8369
  console.log(pc9.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
6883
- const outDir = path17.resolve(config.root, config.build.outDir);
6884
- if (config.build.emptyOutDir && fs12.existsSync(outDir)) {
6885
- fs12.rmSync(outDir, { recursive: true, force: true });
8370
+ const outDir = path19.resolve(config.root, config.build.outDir);
8371
+ if (config.build.emptyOutDir && fs13.existsSync(outDir)) {
8372
+ fs13.rmSync(outDir, { recursive: true, force: true });
6886
8373
  }
6887
- fs12.mkdirSync(outDir, { recursive: true });
6888
- const rendererOutDir = path17.join(outDir, "renderer");
8374
+ fs13.mkdirSync(outDir, { recursive: true });
8375
+ const rendererOutDir = path19.join(outDir, "renderer");
6889
8376
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
6890
8377
  await build2(createElectronRendererConfig(config, inlineConfig, {
6891
8378
  build: {
@@ -6894,8 +8381,8 @@ async function buildElectron(inlineConfig = {}) {
6894
8381
  emptyOutDir: false
6895
8382
  }
6896
8383
  }));
6897
- const mainEntry = path17.resolve(config.root, config.electron.main);
6898
- if (!fs12.existsSync(mainEntry)) {
8384
+ const mainEntry = path19.resolve(config.root, config.electron.main);
8385
+ if (!fs13.existsSync(mainEntry)) {
6899
8386
  throw new Error(
6900
8387
  `Electron main entry not found: ${config.electron.main}
6901
8388
  \u5728 nasti.config.ts \u7684 electron.main \u6307\u5B9A\u4E3B\u8FDB\u7A0B\u5165\u53E3\u6587\u4EF6\u3002`
@@ -6909,11 +8396,11 @@ async function buildElectron(inlineConfig = {}) {
6909
8396
  const preloadEntries = normalizePreload(config.electron.preload, config.root);
6910
8397
  const preloadFiles = [];
6911
8398
  for (const entry of preloadEntries) {
6912
- if (!fs12.existsSync(entry)) {
8399
+ if (!fs13.existsSync(entry)) {
6913
8400
  console.warn(pc9.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
6914
8401
  continue;
6915
8402
  }
6916
- const base = path17.basename(entry).replace(/\.[^.]+$/, "");
8403
+ const base = path19.basename(entry).replace(/\.[^.]+$/, "");
6917
8404
  const out = outFileName(outDir, base, config.electron.preloadFormat);
6918
8405
  await bundleNode(config, entry, {
6919
8406
  outFile: out,
@@ -6925,10 +8412,10 @@ async function buildElectron(inlineConfig = {}) {
6925
8412
  const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
6926
8413
  console.log(pc9.green(`
6927
8414
  \u2713 Electron build complete in ${elapsed}s`));
6928
- console.log(pc9.dim(` renderer: ${path17.relative(config.root, rendererOutDir)}/`));
6929
- console.log(pc9.dim(` main: ${path17.relative(config.root, mainFile)}`));
8415
+ console.log(pc9.dim(` renderer: ${path19.relative(config.root, rendererOutDir)}/`));
8416
+ console.log(pc9.dim(` main: ${path19.relative(config.root, mainFile)}`));
6930
8417
  for (const pf of preloadFiles) {
6931
- console.log(pc9.dim(` preload: ${path17.relative(config.root, pf)}`));
8418
+ console.log(pc9.dim(` preload: ${path19.relative(config.root, pf)}`));
6932
8419
  }
6933
8420
  console.log();
6934
8421
  return { rendererOutDir, mainFile, preloadFiles };
@@ -6942,14 +8429,21 @@ async function bundleNode(config, entry, opts) {
6942
8429
  };
6943
8430
  const oxcTransformPlugin = {
6944
8431
  name: "nasti:oxc-transform",
6945
- transform(code, id) {
6946
- if (!shouldTransform(id)) return null;
6947
- const result = transformCode(id, code, {
8432
+ async transform(code, id) {
8433
+ const result = config.framework === "react" ? await transformReactCode(id, code, {
8434
+ react: config.react,
8435
+ consumer: "server",
8436
+ development: config.mode === "development",
8437
+ sourcemap: !!config.build.sourcemap,
8438
+ target: config.electron.nodeTarget,
8439
+ onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
8440
+ }) : shouldTransform(id) ? transformCode(id, code, {
6948
8441
  sourcemap: !!config.build.sourcemap,
6949
8442
  jsxRuntime: "automatic",
6950
- jsxImportSource: config.framework === "vue" ? "vue" : "react",
8443
+ jsxImportSource: "vue",
6951
8444
  target: config.electron.nodeTarget
6952
- });
8445
+ }) : null;
8446
+ if (!result) return null;
6953
8447
  return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
6954
8448
  }
6955
8449
  };
@@ -6966,7 +8460,7 @@ async function bundleNode(config, entry, opts) {
6966
8460
  },
6967
8461
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
6968
8462
  });
6969
- fs12.mkdirSync(path17.dirname(opts.outFile), { recursive: true });
8463
+ fs13.mkdirSync(path19.dirname(opts.outFile), { recursive: true });
6970
8464
  await bundle2.write({
6971
8465
  sourcemap: !!config.build.sourcemap,
6972
8466
  minify: !!config.build.minify,
@@ -6977,7 +8471,7 @@ async function bundleNode(config, entry, opts) {
6977
8471
  codeSplitting: false
6978
8472
  });
6979
8473
  await bundle2.close();
6980
- console.log(pc9.dim(` \u2713 ${opts.label} \u2192 ${path17.relative(config.root, opts.outFile)}`));
8474
+ console.log(pc9.dim(` \u2713 ${opts.label} \u2192 ${path19.relative(config.root, opts.outFile)}`));
6981
8475
  return opts.outFile;
6982
8476
  }
6983
8477
  function createElectronRendererConfig(config, inlineConfig = {}, overrides = {}) {
@@ -6999,13 +8493,13 @@ function createElectronRendererConfig(config, inlineConfig = {}, overrides = {})
6999
8493
  }
7000
8494
  };
7001
8495
  }
7002
- function outFileName(outDir, base, format) {
7003
- const ext = format === "cjs" ? ".cjs" : ".mjs";
7004
- return path17.join(outDir, base + ext);
8496
+ function outFileName(outDir, base, format2) {
8497
+ const ext = format2 === "cjs" ? ".cjs" : ".mjs";
8498
+ return path19.join(outDir, base + ext);
7005
8499
  }
7006
8500
  function normalizePreload(preload, root) {
7007
8501
  const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
7008
- return list.map((p) => path17.resolve(root, p));
8502
+ return list.map((p) => path19.resolve(root, p));
7009
8503
  }
7010
8504
  function assertElectronVersion(config) {
7011
8505
  const min = config.electron.minVersion;
@@ -7020,16 +8514,16 @@ function assertElectronVersion(config) {
7020
8514
  }
7021
8515
  function detectInstalledElectron(root) {
7022
8516
  try {
7023
- const require2 = createRequire5(path17.resolve(root, "package.json"));
8517
+ const require2 = createRequire4(path19.resolve(root, "package.json"));
7024
8518
  const pkgPath = require2.resolve("electron/package.json");
7025
- const pkg = JSON.parse(fs12.readFileSync(pkgPath, "utf-8"));
8519
+ const pkg = JSON.parse(fs13.readFileSync(pkgPath, "utf-8"));
7026
8520
  const major = parseInt(String(pkg.version).split(".")[0], 10);
7027
8521
  return Number.isFinite(major) ? major : null;
7028
8522
  } catch {
7029
8523
  try {
7030
- const pkgPath = path17.resolve(root, "node_modules/electron/package.json");
7031
- if (!fs12.existsSync(pkgPath)) return null;
7032
- const pkg = JSON.parse(fs12.readFileSync(pkgPath, "utf-8"));
8524
+ const pkgPath = path19.resolve(root, "node_modules/electron/package.json");
8525
+ if (!fs13.existsSync(pkgPath)) return null;
8526
+ const pkg = JSON.parse(fs13.readFileSync(pkgPath, "utf-8"));
7033
8527
  const major = parseInt(String(pkg.version).split(".")[0], 10);
7034
8528
  return Number.isFinite(major) ? major : null;
7035
8529
  } catch {
@@ -7054,9 +8548,9 @@ __export(electron_dev_exports, {
7054
8548
  electronRendererDevPath: () => electronRendererDevPath,
7055
8549
  startElectronDev: () => startElectronDev
7056
8550
  });
7057
- import path18 from "path";
7058
- import fs13 from "fs";
7059
- import { createRequire as createRequire6 } from "module";
8551
+ import path20 from "path";
8552
+ import fs14 from "fs";
8553
+ import { createRequire as createRequire5 } from "module";
7060
8554
  import { spawn } from "child_process";
7061
8555
  import chokidar from "chokidar";
7062
8556
  import pc10 from "picocolors";
@@ -7065,7 +8559,7 @@ async function startElectronDev(inlineConfig = {}) {
7065
8559
  const { noSpawn, ...rest } = inlineConfig;
7066
8560
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
7067
8561
  warnElectronVersion(config);
7068
- console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.4.4"}`));
8562
+ console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.5.1"}`));
7069
8563
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
7070
8564
  const server = await createServer2({
7071
8565
  ...rest,
@@ -7075,11 +8569,11 @@ async function startElectronDev(inlineConfig = {}) {
7075
8569
  await server.listen();
7076
8570
  const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
7077
8571
  console.log(pc10.dim(` renderer: ${devUrl}`));
7078
- const stageDir = path18.resolve(config.root, ".nasti");
7079
- fs13.mkdirSync(stageDir, { recursive: true });
7080
- const mainEntry = path18.resolve(config.root, config.electron.main);
8572
+ const stageDir = path20.resolve(config.root, ".nasti");
8573
+ fs14.mkdirSync(stageDir, { recursive: true });
8574
+ const mainEntry = path20.resolve(config.root, config.electron.main);
7081
8575
  const preloadEntries = normalizePreload(config.electron.preload, config.root);
7082
- const builtMainFile = path18.join(stageDir, "main" + extFor(config.electron.mainFormat));
8576
+ const builtMainFile = path20.join(stageDir, "main" + extFor(config.electron.mainFormat));
7083
8577
  const builtPreloadFiles = [];
7084
8578
  const compileAll = async () => {
7085
8579
  await compileNode(config, mainEntry, {
@@ -7089,9 +8583,9 @@ async function startElectronDev(inlineConfig = {}) {
7089
8583
  });
7090
8584
  builtPreloadFiles.length = 0;
7091
8585
  for (const entry of preloadEntries) {
7092
- if (!fs13.existsSync(entry)) continue;
7093
- const base = path18.basename(entry).replace(/\.[^.]+$/, "");
7094
- const out = path18.join(stageDir, base + extFor(config.electron.preloadFormat));
8586
+ if (!fs14.existsSync(entry)) continue;
8587
+ const base = path20.basename(entry).replace(/\.[^.]+$/, "");
8588
+ const out = path20.join(stageDir, base + extFor(config.electron.preloadFormat));
7095
8589
  await compileNode(config, entry, {
7096
8590
  outFile: out,
7097
8591
  format: config.electron.preloadFormat,
@@ -7130,7 +8624,7 @@ async function startElectronDev(inlineConfig = {}) {
7130
8624
  };
7131
8625
  spawnElectron();
7132
8626
  if (config.electron.autoRestart) {
7133
- const watchTargets = [mainEntry, ...preloadEntries].filter(fs13.existsSync);
8627
+ const watchTargets = [mainEntry, ...preloadEntries].filter(fs14.existsSync);
7134
8628
  const watcher = chokidar.watch(watchTargets, { ignoreInitial: true });
7135
8629
  let restarting = null;
7136
8630
  let pending = false;
@@ -7177,8 +8671,8 @@ async function startElectronDev(inlineConfig = {}) {
7177
8671
  });
7178
8672
  }
7179
8673
  }
7180
- function extFor(format) {
7181
- return format === "cjs" ? ".cjs" : ".mjs";
8674
+ function extFor(format2) {
8675
+ return format2 === "cjs" ? ".cjs" : ".mjs";
7182
8676
  }
7183
8677
  async function compileNode(config, entry, opts) {
7184
8678
  const env = loadEnv(config.mode, config.root, config.envPrefix);
@@ -7190,14 +8684,21 @@ async function compileNode(config, entry, opts) {
7190
8684
  };
7191
8685
  const oxcTransformPlugin = {
7192
8686
  name: "nasti:oxc-transform",
7193
- transform(code, id) {
7194
- if (!shouldTransform(id)) return null;
7195
- const result = transformCode(id, code, {
8687
+ async transform(code, id) {
8688
+ const result = config.framework === "react" ? await transformReactCode(id, code, {
8689
+ react: config.react,
8690
+ consumer: "server",
8691
+ development: true,
8692
+ sourcemap: true,
8693
+ target: config.electron.nodeTarget,
8694
+ onWarning: (message) => config.logger.warn(`[nasti:react] ${message}`)
8695
+ }) : shouldTransform(id) ? transformCode(id, code, {
7196
8696
  sourcemap: true,
7197
8697
  jsxRuntime: "automatic",
7198
- jsxImportSource: config.framework === "vue" ? "vue" : "react",
8698
+ jsxImportSource: "vue",
7199
8699
  target: config.electron.nodeTarget
7200
- });
8700
+ }) : null;
8701
+ if (!result) return null;
7201
8702
  return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
7202
8703
  }
7203
8704
  };
@@ -7210,7 +8711,7 @@ async function compileNode(config, entry, opts) {
7210
8711
  platform: "node",
7211
8712
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
7212
8713
  });
7213
- fs13.mkdirSync(path18.dirname(opts.outFile), { recursive: true });
8714
+ fs14.mkdirSync(path20.dirname(opts.outFile), { recursive: true });
7214
8715
  await bundle2.write({
7215
8716
  file: opts.outFile,
7216
8717
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -7223,18 +8724,18 @@ async function compileNode(config, entry, opts) {
7223
8724
  await bundle2.close();
7224
8725
  }
7225
8726
  function electronRendererDevPath(renderer) {
7226
- const normalized = renderer.split(path18.sep).join("/").replace(/^\.?\//, "");
8727
+ const normalized = renderer.split(path20.sep).join("/").replace(/^\.?\//, "");
7227
8728
  return normalized === "index.html" ? "/" : `/${normalized}`;
7228
8729
  }
7229
8730
  function resolveElectronBinary(config) {
7230
- if (config.electron.electronPath && fs13.existsSync(config.electron.electronPath)) {
8731
+ if (config.electron.electronPath && fs14.existsSync(config.electron.electronPath)) {
7231
8732
  return config.electron.electronPath;
7232
8733
  }
7233
8734
  try {
7234
- const require2 = createRequire6(path18.resolve(config.root, "package.json"));
8735
+ const require2 = createRequire5(path20.resolve(config.root, "package.json"));
7235
8736
  const pathFile = require2.resolve("electron");
7236
8737
  const electronModule = require2(pathFile);
7237
- if (typeof electronModule === "string" && fs13.existsSync(electronModule)) {
8738
+ if (typeof electronModule === "string" && fs14.existsSync(electronModule)) {
7238
8739
  return electronModule;
7239
8740
  }
7240
8741
  } catch {
@@ -7409,20 +8910,20 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
7409
8910
  const logger = createCliLogger(options);
7410
8911
  try {
7411
8912
  const http2 = await import("http");
7412
- const path19 = await import("path");
8913
+ const path21 = await import("path");
7413
8914
  const os2 = await import("os");
7414
8915
  const sirv2 = (await import("sirv")).default;
7415
8916
  const connect2 = (await import("connect")).default;
7416
8917
  const { printServerUrls: printServerUrls2 } = await Promise.resolve().then(() => (init_logger(), logger_exports));
7417
- const resolvedRoot = path19.resolve(root ?? ".");
7418
- const outDir = path19.resolve(resolvedRoot, options.outDir);
8918
+ const resolvedRoot = path21.resolve(root ?? ".");
8919
+ const outDir = path21.resolve(resolvedRoot, options.outDir);
7419
8920
  const app = connect2();
7420
8921
  app.use(sirv2(outDir, { single: true, etag: true, gzip: true, brotli: true }));
7421
8922
  const port = options.port;
7422
8923
  const host = options.host === true ? "0.0.0.0" : options.host ?? "localhost";
7423
8924
  http2.createServer(app).listen(port, host, () => {
7424
8925
  logger.info(`
7425
- ${pc11.cyan(pc11.bold("NASTI"))} ${pc11.cyan(`v${"2.4.4"}`)} ${pc11.dim("preview")}
8926
+ ${pc11.cyan(pc11.bold("NASTI"))} ${pc11.cyan(`v${"2.5.1"}`)} ${pc11.dim("preview")}
7426
8927
  `);
7427
8928
  printServerUrls2(
7428
8929
  {
@@ -7439,6 +8940,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
7439
8940
  }
7440
8941
  });
7441
8942
  cli.help();
7442
- cli.version("2.4.4");
8943
+ cli.version("2.5.1");
7443
8944
  cli.parse();
7444
8945
  //# sourceMappingURL=cli.js.map