@nasti-toolchain/nasti 2.4.2 → 2.4.4

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/index.cjs CHANGED
@@ -5,10 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __glob = (map) => (path19) => {
9
- var fn = map[path19];
8
+ var __glob = (map) => (path20) => {
9
+ var fn = map[path20];
10
10
  if (fn) return fn();
11
- throw new Error("Module not found in bundle: " + path19);
11
+ throw new Error("Module not found in bundle: " + path20);
12
12
  };
13
13
  var __esm = (fn, res) => function __init() {
14
14
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -873,27 +873,27 @@ var require_process = __commonJS({
873
873
  var require_filesystem = __commonJS({
874
874
  "node_modules/detect-libc/lib/filesystem.js"(exports2, module2) {
875
875
  "use strict";
876
- var fs14 = require("fs");
876
+ var fs15 = require("fs");
877
877
  var LDD_PATH = "/usr/bin/ldd";
878
878
  var SELF_PATH = "/proc/self/exe";
879
879
  var MAX_LENGTH = 2048;
880
- var readFileSync = (path19) => {
881
- const fd = fs14.openSync(path19, "r");
880
+ var readFileSync = (path20) => {
881
+ const fd = fs15.openSync(path20, "r");
882
882
  const buffer = Buffer.alloc(MAX_LENGTH);
883
- const bytesRead = fs14.readSync(fd, buffer, 0, MAX_LENGTH, 0);
884
- fs14.close(fd, () => {
883
+ const bytesRead = fs15.readSync(fd, buffer, 0, MAX_LENGTH, 0);
884
+ fs15.close(fd, () => {
885
885
  });
886
886
  return buffer.subarray(0, bytesRead);
887
887
  };
888
- var readFile = (path19) => new Promise((resolve, reject) => {
889
- fs14.open(path19, "r", (err, fd) => {
888
+ var readFile = (path20) => new Promise((resolve, reject) => {
889
+ fs15.open(path20, "r", (err, fd) => {
890
890
  if (err) {
891
891
  reject(err);
892
892
  } else {
893
893
  const buffer = Buffer.alloc(MAX_LENGTH);
894
- fs14.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
894
+ fs15.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
895
895
  resolve(buffer.subarray(0, bytesRead));
896
- fs14.close(fd, () => {
896
+ fs15.close(fd, () => {
897
897
  });
898
898
  });
899
899
  }
@@ -1005,11 +1005,11 @@ var require_detect_libc = __commonJS({
1005
1005
  }
1006
1006
  return null;
1007
1007
  };
1008
- var familyFromInterpreterPath = (path19) => {
1009
- if (path19) {
1010
- if (path19.includes("/ld-musl-")) {
1008
+ var familyFromInterpreterPath = (path20) => {
1009
+ if (path20) {
1010
+ if (path20.includes("/ld-musl-")) {
1011
1011
  return MUSL;
1012
- } else if (path19.includes("/ld-linux-")) {
1012
+ } else if (path20.includes("/ld-linux-")) {
1013
1013
  return GLIBC;
1014
1014
  }
1015
1015
  }
@@ -1056,8 +1056,8 @@ var require_detect_libc = __commonJS({
1056
1056
  cachedFamilyInterpreter = null;
1057
1057
  try {
1058
1058
  const selfContent = await readFile(SELF_PATH);
1059
- const path19 = interpreterPath(selfContent);
1060
- cachedFamilyInterpreter = familyFromInterpreterPath(path19);
1059
+ const path20 = interpreterPath(selfContent);
1060
+ cachedFamilyInterpreter = familyFromInterpreterPath(path20);
1061
1061
  } catch (e) {
1062
1062
  }
1063
1063
  return cachedFamilyInterpreter;
@@ -1069,8 +1069,8 @@ var require_detect_libc = __commonJS({
1069
1069
  cachedFamilyInterpreter = null;
1070
1070
  try {
1071
1071
  const selfContent = readFileSync(SELF_PATH);
1072
- const path19 = interpreterPath(selfContent);
1073
- cachedFamilyInterpreter = familyFromInterpreterPath(path19);
1072
+ const path20 = interpreterPath(selfContent);
1073
+ cachedFamilyInterpreter = familyFromInterpreterPath(path20);
1074
1074
  } catch (e) {
1075
1075
  }
1076
1076
  return cachedFamilyInterpreter;
@@ -2218,8 +2218,8 @@ function vuePlugin(config, environmentName = "client") {
2218
2218
  let cached2 = descriptorCache.get(filePath);
2219
2219
  if (!cached2) {
2220
2220
  try {
2221
- const fs14 = await import("fs");
2222
- const rawSource = fs14.readFileSync(filePath, "utf-8");
2221
+ const fs15 = await import("fs");
2222
+ const rawSource = fs15.readFileSync(filePath, "utf-8");
2223
2223
  const transformedSfc = await applySourceTransform(
2224
2224
  vueOptions.transformSfc,
2225
2225
  rawSource,
@@ -2308,8 +2308,10 @@ function vuePlugin(config, environmentName = "client") {
2308
2308
  });
2309
2309
  const scopeId = hashId(id);
2310
2310
  const wantsSourceMap = !!config.build.sourcemap || transformedSfc.map != null;
2311
+ const vapor = resolveVaporMode(descriptor, vueOptions, sfc, config);
2311
2312
  let scriptCode = "";
2312
2313
  let scriptMap;
2314
+ let scriptBindings;
2313
2315
  if (descriptor.script || descriptor.scriptSetup) {
2314
2316
  const inlineTemplate = vueOptions.script?.inlineTemplate !== false;
2315
2317
  const compiled = sfc.compileScript(descriptor, {
@@ -2321,9 +2323,11 @@ function vuePlugin(config, environmentName = "client") {
2321
2323
  // 让 compileScript 产出 `const __sfc__ = ...`(而非默认的 `export default {...}`)。
2322
2324
  // 否则下方追加的 `__sfc__.render` / `__sfc__.__scopeId` / HMR 记录会引用一个
2323
2325
  // 不存在的 `__sfc__`,并与 compileScript 自带的 `export default` 形成双重默认导出。
2324
- genDefaultAs: "__sfc__"
2326
+ genDefaultAs: "__sfc__",
2327
+ vapor
2325
2328
  });
2326
2329
  scriptCode = compiled.content;
2330
+ scriptBindings = compiled.bindings;
2327
2331
  scriptMap = composeSourceMapChain(
2328
2332
  [compiled.map, transformedSfc.map],
2329
2333
  { filename: id, environmentName, type: "sfc" }
@@ -2337,7 +2341,9 @@ function vuePlugin(config, environmentName = "client") {
2337
2341
  }
2338
2342
  let templateCode = "";
2339
2343
  let templateMap;
2344
+ let templateMultiRoot;
2340
2345
  const scriptSetupIsInline = !!descriptor.scriptSetup && vueOptions.script?.inlineTemplate !== false;
2346
+ const isTemplateOnlyVapor = vapor && !descriptor.script && !descriptor.scriptSetup;
2341
2347
  if (descriptor.template && !scriptSetupIsInline) {
2342
2348
  const transformedTemplate = await applySourceTransform(
2343
2349
  vueOptions.transformTemplate,
@@ -2359,12 +2365,16 @@ function vuePlugin(config, environmentName = "client") {
2359
2365
  filename: id,
2360
2366
  id: scopeId,
2361
2367
  inMap: templateInputMap,
2368
+ vapor,
2362
2369
  compilerOptions: {
2363
2370
  ...customCompilerOptions,
2371
+ // Vapor 在 bindingMetadata 缺失时需要空对象(与 Vite / compiler-sfc 一致)
2372
+ bindingMetadata: customCompilerOptions.bindingMetadata ?? scriptBindings ?? (vapor ? {} : void 0),
2364
2373
  scopeId: `data-v-${scopeId}`
2365
2374
  }
2366
2375
  });
2367
2376
  templateCode = compiled.code;
2377
+ templateMultiRoot = compiled.multiRoot;
2368
2378
  if (wantsSourceMap || transformedTemplate.map != null) {
2369
2379
  templateMap = compiled.map;
2370
2380
  }
@@ -2402,12 +2412,20 @@ function vuePlugin(config, environmentName = "client") {
2402
2412
  outputNode.add(fragment);
2403
2413
  }
2404
2414
  };
2405
- append(scriptCode || "const __sfc__ = {}", scriptMap);
2415
+ append(
2416
+ scriptCode || (vapor ? "const __sfc__ = { __vapor: true }" : "const __sfc__ = {}"),
2417
+ scriptMap
2418
+ );
2406
2419
  if (templateCode) {
2407
2420
  append("\n");
2408
2421
  append(templateCode, templateMap);
2409
2422
  append("\n");
2410
2423
  append("\n__sfc__.render = render\n");
2424
+ if (isTemplateOnlyVapor && templateMultiRoot !== void 0) {
2425
+ append(`
2426
+ __sfc__.__multiRoot = ${JSON.stringify(templateMultiRoot)}
2427
+ `);
2428
+ }
2411
2429
  }
2412
2430
  if (descriptor.styles.length > 0) {
2413
2431
  for (let i = 0; i < descriptor.styles.length; i++) {
@@ -2416,6 +2434,16 @@ import "${id}?vue&type=style&index=${i}&lang.css"
2416
2434
  `);
2417
2435
  }
2418
2436
  }
2437
+ if (vapor) {
2438
+ append(
2439
+ `
2440
+ if (!globalThis.__NASTI_VAPOR_BETA_WARNED__) {
2441
+ globalThis.__NASTI_VAPOR_BETA_WARNED__ = true
2442
+ console.warn(${JSON.stringify(VAPOR_BETA_WARNING)})
2443
+ }
2444
+ `
2445
+ );
2446
+ }
2419
2447
  append(`
2420
2448
  __sfc__.__scopeId = "data-v-${scopeId}"
2421
2449
  `);
@@ -2475,6 +2503,32 @@ if (import.meta.hot) {
2475
2503
  }
2476
2504
  };
2477
2505
  }
2506
+ function resolveVaporMode(descriptor, vueOptions, sfc, config) {
2507
+ const requested = !!descriptor.vapor || !!vueOptions.features?.vapor && canForceVaporMode(descriptor);
2508
+ if (!requested) return false;
2509
+ if (!supportsVaporCompiler(sfc)) {
2510
+ config.logger.warnOnce(
2511
+ "[nasti:vue] Vapor Mode requires @vue/compiler-sfc >= 3.6. Install it: npm install @vue/compiler-sfc@^3.6.0-0"
2512
+ );
2513
+ return false;
2514
+ }
2515
+ config.logger.warnOnce(VAPOR_BETA_WARNING);
2516
+ return true;
2517
+ }
2518
+ function canForceVaporMode(descriptor) {
2519
+ if (typeof descriptor.filename === "string" && descriptor.filename.endsWith(".vue")) {
2520
+ if (descriptor.script && !descriptor.scriptSetup) return false;
2521
+ return !!(descriptor.scriptSetup || descriptor.template);
2522
+ }
2523
+ return true;
2524
+ }
2525
+ function supportsVaporCompiler(sfc) {
2526
+ const version = sfc.version;
2527
+ if (!version) return false;
2528
+ const [major, minor] = version.split(".").map((part) => Number.parseInt(part, 10));
2529
+ if (!Number.isFinite(major) || !Number.isFinite(minor)) return false;
2530
+ return major > 3 || major === 3 && minor >= 6;
2531
+ }
2478
2532
  async function applySourceTransform(transform2, source, context) {
2479
2533
  if (!transform2) return { code: source };
2480
2534
  const result = await transform2(source, context);
@@ -2535,7 +2589,7 @@ function warnUnchainableMap(context, reason) {
2535
2589
  function hashId(filename) {
2536
2590
  return import_node_crypto2.default.createHash("sha256").update(filename).digest("hex").slice(0, 8);
2537
2591
  }
2538
- var import_node_crypto2, import_source_map_js2, VUE_FILE_RE, VUE_QUERY_RE, debug2, compiler;
2592
+ var import_node_crypto2, import_source_map_js2, VUE_FILE_RE, VUE_QUERY_RE, debug2, VAPOR_BETA_WARNING, compiler;
2539
2593
  var init_vue = __esm({
2540
2594
  "src/plugins/vue.ts"() {
2541
2595
  "use strict";
@@ -2546,6 +2600,7 @@ var init_vue = __esm({
2546
2600
  VUE_FILE_RE = /\.vue$/;
2547
2601
  VUE_QUERY_RE = /\.vue\?vue&type=(script|template|style)(&index=\d+)?(&lang[.=]\w+)?/;
2548
2602
  debug2 = createDebugger("nasti:vue");
2603
+ VAPOR_BETA_WARNING = "Vapor Mode is a beta feature; Zixiao Labs and the Vue team do not provide guarantees against crashes in production environments, and it is not suitable for server-side rendering environments.";
2549
2604
  compiler = null;
2550
2605
  }
2551
2606
  });
@@ -2832,6 +2887,24 @@ var init_module_graph = __esm({
2832
2887
  getModulesByFile(file) {
2833
2888
  return this.fileToModulesMap.get(file);
2834
2889
  }
2890
+ /**
2891
+ * Modules whose registered entry file lives under `dir` (inclusive).
2892
+ * Used when a non-entry source inside a prebundled workspace package changes:
2893
+ * only the package entry was registered, so getModulesByFile(changedFile)
2894
+ * misses — we invalidate every /@modules entry rooted in that package.
2895
+ */
2896
+ getModulesWithFileUnder(dir) {
2897
+ const result = /* @__PURE__ */ new Set();
2898
+ const normDir = dir.replace(/\\/g, "/");
2899
+ const normPrefix = normDir.endsWith("/") ? normDir : normDir + "/";
2900
+ for (const [file, mods] of this.fileToModulesMap) {
2901
+ const normFile = file.replace(/\\/g, "/");
2902
+ if (normFile === normDir || normFile.startsWith(normPrefix)) {
2903
+ for (const m of mods) result.add(m);
2904
+ }
2905
+ }
2906
+ return result;
2907
+ }
2835
2908
  async ensureEntryFromUrl(url) {
2836
2909
  const normalizedUrl = removeTimestampQuery(url);
2837
2910
  let mod = this.urlToModuleMap.get(normalizedUrl);
@@ -3802,7 +3875,7 @@ async function build(inlineConfig = {}) {
3802
3875
  const startTime = performance.now();
3803
3876
  logger.info(
3804
3877
  import_picocolors4.default.cyan(`
3805
- nasti v${"2.4.2"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
3878
+ nasti v${"2.4.4"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
3806
3879
  );
3807
3880
  debug5?.(`root: ${config.root}`);
3808
3881
  const buildableNames = Object.keys(config.environments).filter((name) => {
@@ -4145,6 +4218,120 @@ var init_ws = __esm({
4145
4218
  }
4146
4219
  });
4147
4220
 
4221
+ // src/server/fs-allow.ts
4222
+ function isUnderRoot(abs, root) {
4223
+ const rel = import_node_path12.default.relative(root, abs);
4224
+ return !!rel && !rel.startsWith("..") && !import_node_path12.default.isAbsolute(rel);
4225
+ }
4226
+ function discoverLinkedPackageRoots(projectRoot, maxDepth = 4) {
4227
+ const results = [];
4228
+ const seenReal = /* @__PURE__ */ new Set();
4229
+ const queued = /* @__PURE__ */ new Set([projectRoot]);
4230
+ const queue = [projectRoot];
4231
+ for (let depth = 0; depth < maxDepth && queue.length > 0; depth++) {
4232
+ const levelCount = queue.length;
4233
+ for (let i = 0; i < levelCount; i++) {
4234
+ const dir = queue.shift();
4235
+ const nm = import_node_path12.default.join(dir, "node_modules");
4236
+ let entries;
4237
+ try {
4238
+ entries = import_node_fs9.default.readdirSync(nm, { withFileTypes: true });
4239
+ } catch {
4240
+ continue;
4241
+ }
4242
+ for (const ent of entries) {
4243
+ if (ent.name.startsWith(".") || ent.name === "node_modules") continue;
4244
+ const pkgNames = ent.name.startsWith("@") ? listScopedPackages(nm, ent.name) : [ent.name];
4245
+ for (const pkgName of pkgNames) {
4246
+ const pkgPath = import_node_path12.default.join(nm, pkgName);
4247
+ let real;
4248
+ try {
4249
+ real = import_node_fs9.default.realpathSync(pkgPath);
4250
+ } catch {
4251
+ continue;
4252
+ }
4253
+ if (seenReal.has(real)) continue;
4254
+ seenReal.add(real);
4255
+ if (!queued.has(real)) {
4256
+ queued.add(real);
4257
+ queue.push(real);
4258
+ }
4259
+ if (real !== projectRoot && !isUnderRoot(real, projectRoot) && !real.includes(NM)) {
4260
+ results.push(real);
4261
+ }
4262
+ }
4263
+ }
4264
+ }
4265
+ }
4266
+ return results;
4267
+ }
4268
+ function listScopedPackages(nm, scope) {
4269
+ try {
4270
+ return import_node_fs9.default.readdirSync(import_node_path12.default.join(nm, scope)).filter((name) => !name.startsWith(".")).map((name) => import_node_path12.default.join(scope, name));
4271
+ } catch {
4272
+ return [];
4273
+ }
4274
+ }
4275
+ function getLinkedPackageRoots(projectRoot) {
4276
+ let mtimeMs = 0;
4277
+ try {
4278
+ mtimeMs = import_node_fs9.default.statSync(import_node_path12.default.join(projectRoot, "node_modules")).mtimeMs;
4279
+ } catch {
4280
+ mtimeMs = 0;
4281
+ }
4282
+ const cached2 = linkedRootsCache.get(projectRoot);
4283
+ if (cached2 && cached2.mtimeMs === mtimeMs) {
4284
+ return cached2.roots;
4285
+ }
4286
+ const roots = discoverLinkedPackageRoots(projectRoot);
4287
+ linkedRootsCache.set(projectRoot, { roots, mtimeMs });
4288
+ return roots;
4289
+ }
4290
+ function clearLinkedPackageRootsCache() {
4291
+ linkedRootsCache.clear();
4292
+ }
4293
+ function isAllowedDevModulePath(realId, projectRoot) {
4294
+ if (realId === projectRoot || isUnderRoot(realId, projectRoot)) return true;
4295
+ for (const pkgRoot of getLinkedPackageRoots(projectRoot)) {
4296
+ if (realId === pkgRoot || realId.startsWith(pkgRoot + import_node_path12.default.sep)) return true;
4297
+ }
4298
+ let dir = projectRoot;
4299
+ for (; ; ) {
4300
+ const nm = import_node_path12.default.join(dir, "node_modules");
4301
+ if (realId === nm || realId.startsWith(nm + import_node_path12.default.sep)) return true;
4302
+ const parent = import_node_path12.default.dirname(dir);
4303
+ if (parent === dir) break;
4304
+ dir = parent;
4305
+ }
4306
+ return false;
4307
+ }
4308
+ function findNearestPackageRoot(file) {
4309
+ let dir = import_node_path12.default.dirname(file);
4310
+ for (; ; ) {
4311
+ const pkgJson = import_node_path12.default.join(dir, "package.json");
4312
+ if (import_node_fs9.default.existsSync(pkgJson)) {
4313
+ try {
4314
+ const pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJson, "utf-8"));
4315
+ if (typeof pkg?.name === "string" && pkg.name) return dir;
4316
+ } catch {
4317
+ }
4318
+ }
4319
+ const parent = import_node_path12.default.dirname(dir);
4320
+ if (parent === dir) return null;
4321
+ dir = parent;
4322
+ }
4323
+ }
4324
+ var import_node_fs9, import_node_path12, NM, linkedRootsCache;
4325
+ var init_fs_allow = __esm({
4326
+ "src/server/fs-allow.ts"() {
4327
+ "use strict";
4328
+ import_node_fs9 = __toESM(require("fs"), 1);
4329
+ import_node_path12 = __toESM(require("path"), 1);
4330
+ NM = `${import_node_path12.default.sep}node_modules${import_node_path12.default.sep}`;
4331
+ linkedRootsCache = /* @__PURE__ */ new Map();
4332
+ }
4333
+ });
4334
+
4148
4335
  // src/server/middleware.ts
4149
4336
  function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
4150
4337
  if (__refreshRuntimeCache) {
@@ -4153,10 +4340,10 @@ function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
4153
4340
  let cjsPath;
4154
4341
  try {
4155
4342
  const pkgPath = __require.resolve("react-refresh/package.json");
4156
- cjsPath = import_node_path12.default.join(import_node_path12.default.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
4343
+ cjsPath = import_node_path13.default.join(import_node_path13.default.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
4157
4344
  } catch (err) {
4158
- cjsPath = import_node_path12.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
4159
- if (!import_node_fs9.default.existsSync(cjsPath)) {
4345
+ cjsPath = import_node_path13.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
4346
+ if (!import_node_fs10.default.existsSync(cjsPath)) {
4160
4347
  const origMsg = err instanceof Error ? err.message : String(err);
4161
4348
  throw new Error(
4162
4349
  `[nasti] Missing dependency "react-refresh". Install it with: npm install react-refresh
@@ -4164,7 +4351,7 @@ Original resolve error: ${origMsg}`
4164
4351
  );
4165
4352
  }
4166
4353
  }
4167
- const cjsSource = import_node_fs9.default.readFileSync(cjsPath, "utf-8");
4354
+ const cjsSource = import_node_fs10.default.readFileSync(cjsPath, "utf-8");
4168
4355
  __refreshRuntimeCache = `// Wrapped react-refresh runtime -> ESM
4169
4356
  const exports = {};
4170
4357
  const module = { exports };
@@ -4335,8 +4522,8 @@ async function transformRequest(url, ctx) {
4335
4522
  let realIdValid = false;
4336
4523
  try {
4337
4524
  if (idParam) {
4338
- realId = import_node_fs9.default.realpathSync(idParam);
4339
- realIdValid = import_node_fs9.default.statSync(realId).isFile() && (realId.includes(`${import_node_path12.default.sep}node_modules${import_node_path12.default.sep}`) || isUnderRoot(realId, config.root));
4525
+ realId = import_node_fs10.default.realpathSync(idParam);
4526
+ realIdValid = import_node_fs10.default.statSync(realId).isFile() && isAllowedDevModulePath(realId, config.root);
4340
4527
  }
4341
4528
  } catch {
4342
4529
  realId = null;
@@ -4403,7 +4590,7 @@ async function transformRequest(url, ctx) {
4403
4590
  }
4404
4591
  }
4405
4592
  const filePath = resolveUrlToFile(url, config.root);
4406
- if (!filePath || !import_node_fs9.default.existsSync(filePath)) return null;
4593
+ if (!filePath || !import_node_fs10.default.existsSync(filePath)) return null;
4407
4594
  const mod = await moduleGraph.ensureEntryFromUrl(url);
4408
4595
  moduleGraph.registerModule(mod, filePath);
4409
4596
  const transformVersion = mod.invalidationVersion;
@@ -4414,7 +4601,7 @@ async function transformRequest(url, ctx) {
4414
4601
  return transformResult2;
4415
4602
  }
4416
4603
  const loaded = await pluginContainer.load(filePath);
4417
- let code = loaded == null ? import_node_fs9.default.readFileSync(filePath, "utf-8") : typeof loaded === "string" ? loaded : loaded.code;
4604
+ let code = loaded == null ? import_node_fs10.default.readFileSync(filePath, "utf-8") : typeof loaded === "string" ? loaded : loaded.code;
4418
4605
  let map = loaded && typeof loaded !== "string" ? loaded.map : void 0;
4419
4606
  const pluginResult = await pluginContainer.transform(code, filePath);
4420
4607
  if (pluginResult) {
@@ -4472,7 +4659,7 @@ async function loadVirtualModule(spec, ctx) {
4472
4659
  const resolved = await pluginContainer.resolveId(spec);
4473
4660
  if (resolved == null) return null;
4474
4661
  const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
4475
- const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs9.default.existsSync(resolvedId);
4662
+ const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs10.default.existsSync(resolvedId);
4476
4663
  if (!looksVirtual) return null;
4477
4664
  const loadResult = await pluginContainer.load(resolvedId);
4478
4665
  if (loadResult == null) return null;
@@ -4486,7 +4673,7 @@ async function loadVirtualModule(spec, ctx) {
4486
4673
  config.mode,
4487
4674
  ssrDefineOverrides(ctx.environment?.consumer ?? "client")
4488
4675
  ));
4489
- const anchor = import_node_path12.default.join(config.root, "__nasti_virtual__.ts");
4676
+ const anchor = import_node_path13.default.join(config.root, "__nasti_virtual__.ts");
4490
4677
  code = rewriteImports(code, config, anchor);
4491
4678
  return { id: resolvedId, result: { code } };
4492
4679
  }
@@ -4512,7 +4699,7 @@ async function doBundlePackage(entryFile, root) {
4512
4699
  await bundle2.close();
4513
4700
  let code = result.output[0].code;
4514
4701
  code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
4515
- const externalBaseDir = import_node_path12.default.dirname(entryFile);
4702
+ const externalBaseDir = import_node_path13.default.dirname(entryFile);
4516
4703
  code = code.replace(
4517
4704
  /^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
4518
4705
  (_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
@@ -4530,16 +4717,16 @@ async function doBundlePackage(entryFile, root) {
4530
4717
  return code;
4531
4718
  }
4532
4719
  async function tryGenerateSubpathShim(entryFile, root) {
4533
- const NM = `${import_node_path12.default.sep}node_modules${import_node_path12.default.sep}`;
4534
- if (!entryFile.includes(NM)) return null;
4720
+ const NM2 = `${import_node_path13.default.sep}node_modules${import_node_path13.default.sep}`;
4721
+ if (!entryFile.includes(NM2)) return null;
4535
4722
  let pkgDir = null;
4536
4723
  let pkgName = null;
4537
- let dir = import_node_path12.default.dirname(entryFile);
4724
+ let dir = import_node_path13.default.dirname(entryFile);
4538
4725
  while (true) {
4539
- const pkgJsonPath = import_node_path12.default.join(dir, "package.json");
4540
- if (import_node_fs9.default.existsSync(pkgJsonPath)) {
4726
+ const pkgJsonPath = import_node_path13.default.join(dir, "package.json");
4727
+ if (import_node_fs10.default.existsSync(pkgJsonPath)) {
4541
4728
  try {
4542
- const pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
4729
+ const pkg = JSON.parse(import_node_fs10.default.readFileSync(pkgJsonPath, "utf-8"));
4543
4730
  if (typeof pkg?.name === "string" && pkg.name) {
4544
4731
  pkgDir = dir;
4545
4732
  pkgName = pkg.name;
@@ -4548,16 +4735,16 @@ async function tryGenerateSubpathShim(entryFile, root) {
4548
4735
  } catch {
4549
4736
  }
4550
4737
  }
4551
- const parent = import_node_path12.default.dirname(dir);
4738
+ const parent = import_node_path13.default.dirname(dir);
4552
4739
  if (parent === dir) return null;
4553
4740
  dir = parent;
4554
- if (!dir.includes(NM)) return null;
4741
+ if (!dir.includes(NM2)) return null;
4555
4742
  }
4556
4743
  if (!pkgDir || !pkgName) return null;
4557
- const entryExt = import_node_path12.default.extname(entryFile);
4744
+ const entryExt = import_node_path13.default.extname(entryFile);
4558
4745
  const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
4559
4746
  if (!mainEntry) return null;
4560
- if (import_node_path12.default.resolve(mainEntry) === import_node_path12.default.resolve(entryFile)) return null;
4747
+ if (import_node_path13.default.resolve(mainEntry) === import_node_path13.default.resolve(entryFile)) return null;
4561
4748
  let mainNs;
4562
4749
  let subNs;
4563
4750
  try {
@@ -4581,7 +4768,7 @@ async function tryGenerateSubpathShim(entryFile, root) {
4581
4768
  if (mainNs["default"] !== subNs["default"]) return null;
4582
4769
  }
4583
4770
  const rootMain = resolveNodeModule(root, pkgName);
4584
- const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + import_node_path12.default.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
4771
+ const mainEntryUrl = rootMain && rootMain.startsWith(pkgDir + import_node_path13.default.sep) ? `/@modules/${pkgName}` : `/@modules/${pkgName}?id=${encodeURIComponent(mainEntry)}`;
4585
4772
  const lines = [
4586
4773
  `// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
4587
4774
  `import * as __pkg from "${mainEntryUrl}";`
@@ -4595,10 +4782,10 @@ async function tryGenerateSubpathShim(entryFile, root) {
4595
4782
  return lines.join("\n") + "\n";
4596
4783
  }
4597
4784
  function pickMainEntryByExtension(pkgDir, preferredExt) {
4598
- const pkgJsonPath = import_node_path12.default.join(pkgDir, "package.json");
4785
+ const pkgJsonPath = import_node_path13.default.join(pkgDir, "package.json");
4599
4786
  let pkg;
4600
4787
  try {
4601
- pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
4788
+ pkg = JSON.parse(import_node_fs10.default.readFileSync(pkgJsonPath, "utf-8"));
4602
4789
  } catch {
4603
4790
  return null;
4604
4791
  }
@@ -4617,14 +4804,14 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
4617
4804
  if (typeof pkg.module === "string") candidates.push(pkg.module);
4618
4805
  if (typeof pkg.main === "string") candidates.push(pkg.main);
4619
4806
  for (const cand of candidates) {
4620
- if (import_node_path12.default.extname(cand) === preferredExt) {
4621
- const full = import_node_path12.default.resolve(pkgDir, cand);
4622
- if (import_node_fs9.default.existsSync(full)) return full;
4807
+ if (import_node_path13.default.extname(cand) === preferredExt) {
4808
+ const full = import_node_path13.default.resolve(pkgDir, cand);
4809
+ if (import_node_fs10.default.existsSync(full)) return full;
4623
4810
  }
4624
4811
  }
4625
4812
  for (const cand of candidates) {
4626
- const full = import_node_path12.default.resolve(pkgDir, cand);
4627
- if (import_node_fs9.default.existsSync(full)) return full;
4813
+ const full = import_node_path13.default.resolve(pkgDir, cand);
4814
+ if (import_node_fs10.default.existsSync(full)) return full;
4628
4815
  }
4629
4816
  return null;
4630
4817
  }
@@ -4649,8 +4836,8 @@ function rewriteExternalRequires(code, baseDir, root) {
4649
4836
  }
4650
4837
  async function injectCjsNamedExports(code, entryFile) {
4651
4838
  try {
4652
- const { createRequire: createRequire7 } = await import("module");
4653
- const req = createRequire7(entryFile);
4839
+ const { createRequire: createRequire8 } = await import("module");
4840
+ const req = createRequire8(entryFile);
4654
4841
  const cjsExports = req(entryFile);
4655
4842
  if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
4656
4843
  const namedKeys = Object.keys(cjsExports).filter(
@@ -4691,11 +4878,22 @@ function rewriteImports(code, config, filePath, importedUrls, moduleGraph) {
4691
4878
  }
4692
4879
  function createModuleSpecifierResolver(config, filePath) {
4693
4880
  const root = config.root;
4694
- const fileDir = import_node_path12.default.dirname(filePath);
4881
+ const fileDir = import_node_path13.default.dirname(filePath);
4695
4882
  const aliasEntries = Object.entries(config.resolve.alias).sort(
4696
4883
  ([a], [b]) => b.length - a.length
4697
4884
  );
4698
- const toRootUrl = (abs) => "/" + import_node_path12.default.relative(root, abs).replace(/\\/g, "/");
4885
+ const toServableUrl = (abs) => {
4886
+ if (isUnderRoot(abs, root)) {
4887
+ return "/" + import_node_path13.default.relative(root, abs).replace(/\\/g, "/");
4888
+ }
4889
+ for (const pkgRoot of getLinkedPackageRoots(root)) {
4890
+ if (abs === pkgRoot || abs.startsWith(pkgRoot + import_node_path13.default.sep)) {
4891
+ const normalized = abs.replace(/\\/g, "/");
4892
+ return "/@fs/" + (normalized.startsWith("/") ? normalized.slice(1) : normalized);
4893
+ }
4894
+ }
4895
+ return null;
4896
+ };
4699
4897
  return (specifier) => {
4700
4898
  const suffixMatch = specifier.match(/[?#].*$/);
4701
4899
  const suffix = suffixMatch ? suffixMatch[0] : "";
@@ -4704,18 +4902,21 @@ function createModuleSpecifierResolver(config, filePath) {
4704
4902
  if (baseSpec === key || baseSpec.startsWith(key + "/")) {
4705
4903
  const aliasBase = resolveAliasTarget2(value, root);
4706
4904
  const sub = baseSpec.slice(key.length).replace(/^\//, "");
4707
- const target = sub ? import_node_path12.default.join(aliasBase, sub) : aliasBase;
4905
+ const target = sub ? import_node_path13.default.join(aliasBase, sub) : aliasBase;
4708
4906
  const resolved = tryResolveDiskPath(target);
4709
- return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
4907
+ const url = resolved ? toServableUrl(resolved) : null;
4908
+ return url ? url + suffix : specifier;
4710
4909
  }
4711
4910
  }
4712
4911
  if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
4713
- const resolved = tryResolveDiskPath(import_node_path12.default.resolve(fileDir, baseSpec));
4714
- return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
4912
+ const resolved = tryResolveDiskPath(import_node_path13.default.resolve(fileDir, baseSpec));
4913
+ const url = resolved ? toServableUrl(resolved) : null;
4914
+ return url ? url + suffix : specifier;
4715
4915
  }
4716
4916
  if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
4717
- const resolved = tryResolveDiskPath(import_node_path12.default.join(root, baseSpec.replace(/^\//, "")));
4718
- return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
4917
+ const resolved = tryResolveDiskPath(import_node_path13.default.join(root, baseSpec.replace(/^\//, "")));
4918
+ const url = resolved ? toServableUrl(resolved) : null;
4919
+ return url ? url + suffix : specifier;
4719
4920
  }
4720
4921
  if (baseSpec.startsWith("/")) return specifier;
4721
4922
  return `/@modules/${specifier}`;
@@ -4868,28 +5069,24 @@ function maskStringsAndComments(code) {
4868
5069
  return masked.join("");
4869
5070
  }
4870
5071
  function resolveAliasTarget2(value, root) {
4871
- if (import_node_path12.default.isAbsolute(value) && import_node_fs9.default.existsSync(value)) return value;
4872
- if (value.startsWith("/")) return import_node_path12.default.join(root, value.slice(1));
4873
- return import_node_path12.default.resolve(root, value);
5072
+ if (import_node_path13.default.isAbsolute(value) && import_node_fs10.default.existsSync(value)) return value;
5073
+ if (value.startsWith("/")) return import_node_path13.default.join(root, value.slice(1));
5074
+ return import_node_path13.default.resolve(root, value);
4874
5075
  }
4875
5076
  function tryResolveDiskPath(target) {
4876
- if (import_node_fs9.default.existsSync(target) && import_node_fs9.default.statSync(target).isFile()) return target;
5077
+ if (import_node_fs10.default.existsSync(target) && import_node_fs10.default.statSync(target).isFile()) return target;
4877
5078
  for (const ext of RESOLVE_EXTENSIONS) {
4878
5079
  const withExt = target + ext;
4879
- if (import_node_fs9.default.existsSync(withExt) && import_node_fs9.default.statSync(withExt).isFile()) return withExt;
5080
+ if (import_node_fs10.default.existsSync(withExt) && import_node_fs10.default.statSync(withExt).isFile()) return withExt;
4880
5081
  }
4881
- if (import_node_fs9.default.existsSync(target) && import_node_fs9.default.statSync(target).isDirectory()) {
5082
+ if (import_node_fs10.default.existsSync(target) && import_node_fs10.default.statSync(target).isDirectory()) {
4882
5083
  for (const ext of RESOLVE_EXTENSIONS) {
4883
- const idx = import_node_path12.default.join(target, "index" + ext);
4884
- if (import_node_fs9.default.existsSync(idx) && import_node_fs9.default.statSync(idx).isFile()) return idx;
5084
+ const idx = import_node_path13.default.join(target, "index" + ext);
5085
+ if (import_node_fs10.default.existsSync(idx) && import_node_fs10.default.statSync(idx).isFile()) return idx;
4885
5086
  }
4886
5087
  }
4887
5088
  return null;
4888
5089
  }
4889
- function isUnderRoot(abs, root) {
4890
- const rel = import_node_path12.default.relative(root, abs);
4891
- return !!rel && !rel.startsWith("..") && !import_node_path12.default.isAbsolute(rel);
4892
- }
4893
5090
  function appendTimestampQuery(url, timestamp) {
4894
5091
  const hashIndex = url.indexOf("#");
4895
5092
  const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
@@ -4907,7 +5104,7 @@ function resolveNodeModule(baseDir, moduleName) {
4907
5104
  const resolved = resolveNodeModuleEntry(baseDir, moduleName);
4908
5105
  if (!resolved) return null;
4909
5106
  try {
4910
- return import_node_fs9.default.realpathSync(resolved);
5107
+ return import_node_fs10.default.realpathSync(resolved);
4911
5108
  } catch {
4912
5109
  return resolved;
4913
5110
  }
@@ -4927,21 +5124,21 @@ function resolveNodeModuleEntry(root, moduleName) {
4927
5124
  let pkgDir = null;
4928
5125
  let dir = root;
4929
5126
  for (; ; ) {
4930
- const candidate = import_node_path12.default.join(dir, "node_modules", pkgName);
4931
- if (import_node_fs9.default.existsSync(candidate)) {
5127
+ const candidate = import_node_path13.default.join(dir, "node_modules", pkgName);
5128
+ if (import_node_fs10.default.existsSync(candidate)) {
4932
5129
  pkgDir = candidate;
4933
5130
  break;
4934
5131
  }
4935
- const parent = import_node_path12.default.dirname(dir);
5132
+ const parent = import_node_path13.default.dirname(dir);
4936
5133
  if (parent === dir) break;
4937
5134
  dir = parent;
4938
5135
  }
4939
5136
  if (!pkgDir) return null;
4940
- const pkgJsonPath = import_node_path12.default.join(pkgDir, "package.json");
4941
- if (!import_node_fs9.default.existsSync(pkgJsonPath)) return null;
5137
+ const pkgJsonPath = import_node_path13.default.join(pkgDir, "package.json");
5138
+ if (!import_node_fs10.default.existsSync(pkgJsonPath)) return null;
4942
5139
  let pkg;
4943
5140
  try {
4944
- pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
5141
+ pkg = JSON.parse(import_node_fs10.default.readFileSync(pkgJsonPath, "utf-8"));
4945
5142
  } catch {
4946
5143
  return null;
4947
5144
  }
@@ -4954,32 +5151,32 @@ function resolveNodeModuleEntry(root, moduleName) {
4954
5151
  const subDirs = [""];
4955
5152
  for (const field of ["module", "main"]) {
4956
5153
  if (typeof pkg[field] === "string") {
4957
- const dir2 = import_node_path12.default.dirname(pkg[field]);
5154
+ const dir2 = import_node_path13.default.dirname(pkg[field]);
4958
5155
  if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
4959
5156
  }
4960
5157
  }
4961
5158
  for (const dir2 of subDirs) {
4962
- const direct = import_node_path12.default.join(pkgDir, dir2, subpath);
4963
- if (import_node_fs9.default.existsSync(direct) && import_node_fs9.default.statSync(direct).isFile()) return direct;
5159
+ const direct = import_node_path13.default.join(pkgDir, dir2, subpath);
5160
+ if (import_node_fs10.default.existsSync(direct) && import_node_fs10.default.statSync(direct).isFile()) return direct;
4964
5161
  for (const ext of RESOLVE_EXTENSIONS) {
4965
- if (import_node_fs9.default.existsSync(direct + ext)) return direct + ext;
5162
+ if (import_node_fs10.default.existsSync(direct + ext)) return direct + ext;
4966
5163
  }
4967
5164
  }
4968
5165
  return null;
4969
5166
  }
4970
5167
  for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
4971
5168
  if (typeof pkg[field] === "string") {
4972
- const entry = import_node_path12.default.join(pkgDir, pkg[field]);
4973
- if (import_node_fs9.default.existsSync(entry)) return entry;
5169
+ const entry = import_node_path13.default.join(pkgDir, pkg[field]);
5170
+ if (import_node_fs10.default.existsSync(entry)) return entry;
4974
5171
  }
4975
5172
  }
4976
- const indexFallback = import_node_path12.default.join(pkgDir, "index.js");
4977
- if (import_node_fs9.default.existsSync(indexFallback)) return indexFallback;
5173
+ const indexFallback = import_node_path13.default.join(pkgDir, "index.js");
5174
+ if (import_node_fs10.default.existsSync(indexFallback)) return indexFallback;
4978
5175
  return null;
4979
5176
  }
4980
5177
  function resolvePackageExports(exports2, key, pkgDir) {
4981
5178
  if (typeof exports2 === "string") {
4982
- return key === "." ? import_node_path12.default.join(pkgDir, exports2) : null;
5179
+ return key === "." ? import_node_path13.default.join(pkgDir, exports2) : null;
4983
5180
  }
4984
5181
  const entry = exports2[key];
4985
5182
  if (entry === void 0) {
@@ -4991,7 +5188,7 @@ function resolvePackageExports(exports2, key, pkgDir) {
4991
5188
  return resolveExportValue(entry, pkgDir);
4992
5189
  }
4993
5190
  function resolveExportValue(value, pkgDir) {
4994
- if (typeof value === "string") return import_node_path12.default.join(pkgDir, value);
5191
+ if (typeof value === "string") return import_node_path13.default.join(pkgDir, value);
4995
5192
  if (Array.isArray(value)) {
4996
5193
  for (const item of value) {
4997
5194
  const r = resolveExportValue(item, pkgDir);
@@ -5010,35 +5207,54 @@ function resolveExportValue(value, pkgDir) {
5010
5207
  return null;
5011
5208
  }
5012
5209
  function resolveUrlToFile(url, root) {
5013
- const cleanUrl = url.split("?")[0];
5210
+ const cleanUrl = url.split(/[?#]/)[0];
5014
5211
  if (cleanUrl.startsWith("/@modules/")) {
5015
5212
  const moduleName = cleanUrl.slice("/@modules/".length);
5016
5213
  return resolveNodeModule(root, moduleName);
5017
5214
  }
5018
- const filePath = import_node_path12.default.resolve(root, cleanUrl.replace(/^\//, ""));
5019
- if (import_node_fs9.default.existsSync(filePath) && import_node_fs9.default.statSync(filePath).isFile()) {
5215
+ if (cleanUrl.startsWith("/@fs/")) {
5216
+ let abs = cleanUrl.slice("/@fs/".length);
5217
+ if (process.platform === "win32") {
5218
+ abs = abs.replace(/\//g, import_node_path13.default.sep);
5219
+ } else if (!abs.startsWith("/")) {
5220
+ abs = "/" + abs;
5221
+ }
5222
+ try {
5223
+ const real = import_node_fs10.default.realpathSync(abs);
5224
+ if (import_node_fs10.default.statSync(real).isFile() && isAllowedDevModulePath(real, root)) return real;
5225
+ } catch {
5226
+ return null;
5227
+ }
5228
+ return null;
5229
+ }
5230
+ const filePath = import_node_path13.default.resolve(root, cleanUrl.replace(/^\//, ""));
5231
+ if (import_node_fs10.default.existsSync(filePath) && import_node_fs10.default.statSync(filePath).isFile()) {
5020
5232
  return filePath;
5021
5233
  }
5022
5234
  for (const ext of RESOLVE_EXTENSIONS) {
5023
5235
  const withExt = filePath + ext;
5024
- if (import_node_fs9.default.existsSync(withExt)) return withExt;
5236
+ if (import_node_fs10.default.existsSync(withExt)) return withExt;
5025
5237
  }
5026
5238
  for (const ext of RESOLVE_EXTENSIONS) {
5027
- const indexFile = import_node_path12.default.join(filePath, "index" + ext);
5028
- if (import_node_fs9.default.existsSync(indexFile)) return indexFile;
5239
+ const indexFile = import_node_path13.default.join(filePath, "index" + ext);
5240
+ if (import_node_fs10.default.existsSync(indexFile)) return indexFile;
5029
5241
  }
5030
5242
  return null;
5031
5243
  }
5032
5244
  function isModuleRequest(url, destination) {
5033
- const cleanUrl = url.split("?")[0];
5245
+ const cleanUrl = url.split(/[?#]/)[0];
5034
5246
  if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
5035
5247
  if (cleanUrl.startsWith("/@modules/")) return true;
5248
+ if (cleanUrl.startsWith("/@fs/")) return true;
5036
5249
  if (isAssetFile(cleanUrl)) {
5037
- const query = url.includes("?") ? url.slice(url.indexOf("?") + 1) : "";
5250
+ const qIdx = url.indexOf("?");
5251
+ const hIdx = url.indexOf("#");
5252
+ const queryEnd = hIdx === -1 ? url.length : hIdx;
5253
+ const query = qIdx === -1 || qIdx > queryEnd ? "" : url.slice(qIdx + 1, queryEnd);
5038
5254
  const isExplicitAssetModule = /(?:^|&)(?:url|raw)(?:&|$)/.test(query);
5039
5255
  return isExplicitAssetModule || destination === "script";
5040
5256
  }
5041
- if (!import_node_path12.default.extname(cleanUrl)) return true;
5257
+ if (!import_node_path13.default.extname(cleanUrl)) return true;
5042
5258
  return false;
5043
5259
  }
5044
5260
  function getHmrClientCode() {
@@ -5268,13 +5484,13 @@ function clearCustomListeners(ownerPath) {
5268
5484
  }
5269
5485
  `;
5270
5486
  }
5271
- var import_node_path12, import_node_fs9, import_node_module5, import_node_url3, import_picocolors6, import_meta, __dirname_esm, __require, __refreshRuntimeCache, REACT_REFRESH_BOUNDARY_HELPERS, REACT_REFRESH_GLOBAL_PREAMBLE, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
5487
+ var import_node_path13, import_node_fs10, import_node_module6, import_node_url3, import_picocolors6, import_meta, __dirname_esm, __require, __refreshRuntimeCache, REACT_REFRESH_BOUNDARY_HELPERS, REACT_REFRESH_GLOBAL_PREAMBLE, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
5272
5488
  var init_middleware = __esm({
5273
5489
  "src/server/middleware.ts"() {
5274
5490
  "use strict";
5275
- import_node_path12 = __toESM(require("path"), 1);
5276
- import_node_fs9 = __toESM(require("fs"), 1);
5277
- import_node_module5 = require("module");
5491
+ import_node_path13 = __toESM(require("path"), 1);
5492
+ import_node_fs10 = __toESM(require("fs"), 1);
5493
+ import_node_module6 = require("module");
5278
5494
  import_node_url3 = require("url");
5279
5495
  import_picocolors6 = __toESM(require("picocolors"), 1);
5280
5496
  init_transformer();
@@ -5282,9 +5498,10 @@ var init_middleware = __esm({
5282
5498
  init_env();
5283
5499
  init_url();
5284
5500
  init_assets();
5501
+ init_fs_allow();
5285
5502
  import_meta = {};
5286
- __dirname_esm = import_node_path12.default.dirname((0, import_node_url3.fileURLToPath)(import_meta.url));
5287
- __require = (0, import_node_module5.createRequire)(import_meta.url);
5503
+ __dirname_esm = import_node_path13.default.dirname((0, import_node_url3.fileURLToPath)(import_meta.url));
5504
+ __require = (0, import_node_module6.createRequire)(import_meta.url);
5288
5505
  __refreshRuntimeCache = null;
5289
5506
  REACT_REFRESH_BOUNDARY_HELPERS = `
5290
5507
  function __nastiIsPlainObject(obj) {
@@ -5372,9 +5589,26 @@ async function handleFileChange(file, server, environmentName = "client", timest
5372
5589
  }
5373
5590
  const moduleGraph = environment.moduleGraph;
5374
5591
  const logger = config.logger;
5375
- const relativePath = "/" + import_node_path13.default.relative(config.root, file);
5376
- const shortFile = import_node_path13.default.relative(config.root, file);
5377
- const mods = moduleGraph.getModulesByFile(file);
5592
+ const relativePath = "/" + import_node_path14.default.relative(config.root, file);
5593
+ const shortFile = import_node_path14.default.relative(config.root, file);
5594
+ let mods = moduleGraph.getModulesByFile(file);
5595
+ if (!mods || mods.size === 0) {
5596
+ try {
5597
+ const real = import_node_fs11.default.realpathSync(file);
5598
+ if (real !== file) mods = moduleGraph.getModulesByFile(real);
5599
+ if (mods && mods.size > 0) file = real;
5600
+ } catch {
5601
+ }
5602
+ }
5603
+ if (!mods || mods.size === 0) {
5604
+ const packageRoot = findNearestPackageRoot(file);
5605
+ if (packageRoot && getLinkedPackageRoots(config.root).some(
5606
+ (r) => packageRoot === r || packageRoot.startsWith(r + import_node_path14.default.sep)
5607
+ )) {
5608
+ const under = moduleGraph.getModulesWithFileUnder(packageRoot);
5609
+ if (under.size > 0) mods = under;
5610
+ }
5611
+ }
5378
5612
  if (!mods || mods.size === 0) {
5379
5613
  return null;
5380
5614
  }
@@ -5389,7 +5623,7 @@ async function handleFileChange(file, server, environmentName = "client", timest
5389
5623
  file,
5390
5624
  timestamp,
5391
5625
  modules: [mod],
5392
- read: () => import_node_fs10.default.readFileSync(file, "utf-8"),
5626
+ read: () => import_node_fs11.default.readFileSync(file, "utf-8"),
5393
5627
  server,
5394
5628
  environment
5395
5629
  };
@@ -5450,13 +5684,14 @@ async function handleFileChange(file, server, environmentName = "client", timest
5450
5684
  fullReload
5451
5685
  };
5452
5686
  }
5453
- var import_node_path13, import_node_fs10, import_picocolors7;
5687
+ var import_node_path14, import_node_fs11, import_picocolors7;
5454
5688
  var init_hmr = __esm({
5455
5689
  "src/server/hmr.ts"() {
5456
5690
  "use strict";
5457
- import_node_path13 = __toESM(require("path"), 1);
5458
- import_node_fs10 = __toESM(require("fs"), 1);
5691
+ import_node_path14 = __toESM(require("path"), 1);
5692
+ import_node_fs11 = __toESM(require("fs"), 1);
5459
5693
  import_picocolors7 = __toESM(require("picocolors"), 1);
5694
+ init_fs_allow();
5460
5695
  }
5461
5696
  });
5462
5697
 
@@ -5474,19 +5709,19 @@ function createModuleRunner(environment) {
5474
5709
  }
5475
5710
  return new NastiModuleRunner(environment);
5476
5711
  }
5477
- var import_node_path14, import_node_fs11, import_node_module6, import_node_url4, debug6, NODE_BUILTINS3, NastiModuleRunner, AsyncFunction;
5712
+ var import_node_path15, import_node_fs12, import_node_module7, import_node_url4, debug6, NODE_BUILTINS3, NastiModuleRunner, AsyncFunction;
5478
5713
  var init_runnable_environment = __esm({
5479
5714
  "src/server/runnable-environment.ts"() {
5480
5715
  "use strict";
5481
- import_node_path14 = __toESM(require("path"), 1);
5482
- import_node_fs11 = __toESM(require("fs"), 1);
5483
- import_node_module6 = require("module");
5716
+ import_node_path15 = __toESM(require("path"), 1);
5717
+ import_node_fs12 = __toESM(require("fs"), 1);
5718
+ import_node_module7 = require("module");
5484
5719
  import_node_url4 = require("url");
5485
5720
  init_transformer();
5486
5721
  init_env();
5487
5722
  init_debug();
5488
5723
  debug6 = createDebugger("nasti:ssr");
5489
- NODE_BUILTINS3 = /* @__PURE__ */ new Set([...import_node_module6.builtinModules, ...import_node_module6.builtinModules.map((m) => `node:${m}`)]);
5724
+ NODE_BUILTINS3 = /* @__PURE__ */ new Set([...import_node_module7.builtinModules, ...import_node_module7.builtinModules.map((m) => `node:${m}`)]);
5490
5725
  NastiModuleRunner = class {
5491
5726
  environment;
5492
5727
  config;
@@ -5501,10 +5736,10 @@ var init_runnable_environment = __esm({
5501
5736
  this.config.mode,
5502
5737
  ssrDefineOverrides(environment.consumer)
5503
5738
  );
5504
- this.require = (0, import_node_module6.createRequire)(import_node_path14.default.join(this.config.root, "package.json"));
5739
+ this.require = (0, import_node_module7.createRequire)(import_node_path15.default.join(this.config.root, "package.json"));
5505
5740
  const handlers = {
5506
5741
  fetchModule: async (id, importer) => this.fetchModule(id, importer),
5507
- getBuiltins: () => [/^node:/, ...import_node_module6.builtinModules]
5742
+ getBuiltins: () => [/^node:/, ...import_node_module7.builtinModules]
5508
5743
  };
5509
5744
  environment.hot.setInvokeHandler?.(handlers);
5510
5745
  }
@@ -5525,9 +5760,9 @@ var init_runnable_environment = __esm({
5525
5760
  this.cache.clear();
5526
5761
  }
5527
5762
  resolveToId(rawUrl) {
5528
- if (import_node_path14.default.isAbsolute(rawUrl) && import_node_fs11.default.existsSync(rawUrl.split("?")[0])) return rawUrl;
5763
+ if (import_node_path15.default.isAbsolute(rawUrl) && import_node_fs12.default.existsSync(rawUrl.split("?")[0])) return rawUrl;
5529
5764
  const clean = rawUrl.replace(/^\//, "");
5530
- return import_node_path14.default.resolve(this.config.root, clean);
5765
+ return import_node_path15.default.resolve(this.config.root, clean);
5531
5766
  }
5532
5767
  /**
5533
5768
  * fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
@@ -5536,14 +5771,14 @@ var init_runnable_environment = __esm({
5536
5771
  */
5537
5772
  async fetchModule(id, importer) {
5538
5773
  if (NODE_BUILTINS3.has(id)) return { externalize: id };
5539
- if (!id.startsWith(".") && !import_node_path14.default.isAbsolute(id) && !id.startsWith("\0")) {
5774
+ if (!id.startsWith(".") && !import_node_path15.default.isAbsolute(id) && !id.startsWith("\0")) {
5540
5775
  return { externalize: id };
5541
5776
  }
5542
5777
  const container = this.environment.pluginContainer;
5543
5778
  let resolvedId = id;
5544
5779
  if (id.startsWith(".") && importer) {
5545
5780
  const resolved = await container.resolveId(id, importer);
5546
- resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : import_node_path14.default.resolve(import_node_path14.default.dirname(importer.split("?")[0]), id);
5781
+ resolvedId = resolved ? typeof resolved === "string" ? resolved : resolved.id : import_node_path15.default.resolve(import_node_path15.default.dirname(importer.split("?")[0]), id);
5547
5782
  }
5548
5783
  resolvedId = this.completeExtension(resolvedId);
5549
5784
  const cleanId = resolvedId.split("?")[0];
@@ -5551,8 +5786,8 @@ var init_runnable_environment = __esm({
5551
5786
  const loaded = await container.load(resolvedId);
5552
5787
  if (loaded != null) {
5553
5788
  code = typeof loaded === "string" ? loaded : loaded.code;
5554
- } else if (import_node_fs11.default.existsSync(cleanId)) {
5555
- code = import_node_fs11.default.readFileSync(cleanId, "utf-8");
5789
+ } else if (import_node_fs12.default.existsSync(cleanId)) {
5790
+ code = import_node_fs12.default.readFileSync(cleanId, "utf-8");
5556
5791
  } else {
5557
5792
  throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
5558
5793
  }
@@ -5586,19 +5821,19 @@ var init_runnable_environment = __esm({
5586
5821
  completeExtension(id) {
5587
5822
  const clean = id.split("?")[0];
5588
5823
  const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
5589
- if (import_node_fs11.default.existsSync(clean) && import_node_fs11.default.statSync(clean).isFile()) return id;
5824
+ if (import_node_fs12.default.existsSync(clean) && import_node_fs12.default.statSync(clean).isFile()) return id;
5590
5825
  const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
5591
5826
  if (jsMatch) {
5592
5827
  for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
5593
- if (import_node_fs11.default.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
5828
+ if (import_node_fs12.default.existsSync(jsMatch[1] + tsExt)) return jsMatch[1] + tsExt + query;
5594
5829
  }
5595
5830
  }
5596
5831
  for (const ext of this.config.resolve.extensions) {
5597
- if (import_node_fs11.default.existsSync(clean + ext)) return clean + ext + query;
5832
+ if (import_node_fs12.default.existsSync(clean + ext)) return clean + ext + query;
5598
5833
  }
5599
5834
  for (const ext of this.config.resolve.extensions) {
5600
- const indexPath = import_node_path14.default.join(clean, `index${ext}`);
5601
- if (import_node_fs11.default.existsSync(indexPath)) return indexPath;
5835
+ const indexPath = import_node_path15.default.join(clean, `index${ext}`);
5836
+ if (import_node_fs12.default.existsSync(indexPath)) return indexPath;
5602
5837
  }
5603
5838
  return id;
5604
5839
  }
@@ -5625,10 +5860,10 @@ var init_runnable_environment = __esm({
5625
5860
  return;
5626
5861
  }
5627
5862
  const ssrImport = async (dep) => {
5628
- if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !import_node_path14.default.isAbsolute(dep) && !dep.startsWith("\0")) {
5863
+ if (NODE_BUILTINS3.has(dep) || !dep.startsWith(".") && !import_node_path15.default.isAbsolute(dep) && !dep.startsWith("\0")) {
5629
5864
  return this.importExternal(dep);
5630
5865
  }
5631
- const depId = dep.startsWith(".") ? this.completeExtension(import_node_path14.default.resolve(import_node_path14.default.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
5866
+ const depId = dep.startsWith(".") ? this.completeExtension(import_node_path15.default.resolve(import_node_path15.default.dirname(fetched.id.split("?")[0]), dep)) : this.completeExtension(dep);
5632
5867
  return this.instantiate(depId);
5633
5868
  };
5634
5869
  const ssrExportAll = (sourceModule) => {
@@ -5660,7 +5895,7 @@ var init_runnable_environment = __esm({
5660
5895
  }
5661
5896
  async importExternal(spec) {
5662
5897
  try {
5663
- return await (spec.startsWith("node:") || !import_node_path14.default.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import((0, import_node_url4.pathToFileURL)(spec).href));
5898
+ return await (spec.startsWith("node:") || !import_node_path15.default.isAbsolute(spec) ? import(this.resolveExternalSpecifier(spec)) : import((0, import_node_url4.pathToFileURL)(spec).href));
5664
5899
  } catch (err) {
5665
5900
  throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
5666
5901
  }
@@ -5767,7 +6002,7 @@ async function createBundledDevServer(opts) {
5767
6002
  }
5768
6003
  const url = `/${patchPath}`;
5769
6004
  logger.info(
5770
- import_picocolors8.default.green("hmr update ") + import_picocolors8.default.dim(changedFiles.map((f) => import_node_path15.default.relative(config.root, f)).join(", ")),
6005
+ import_picocolors8.default.green("hmr update ") + import_picocolors8.default.dim(changedFiles.map((f) => import_node_path16.default.relative(config.root, f)).join(", ")),
5771
6006
  { timestamp: true }
5772
6007
  );
5773
6008
  sendTo(clientId, { type: "hmr:update", path: url, url });
@@ -5922,7 +6157,7 @@ async function createBundledDevServer(opts) {
5922
6157
  return;
5923
6158
  }
5924
6159
  res.setHeader("ETag", hit.etag);
5925
- res.setHeader("Content-Type", MIME_TYPES[import_node_path15.default.extname(fileName)] ?? "application/octet-stream");
6160
+ res.setHeader("Content-Type", MIME_TYPES[import_node_path16.default.extname(fileName)] ?? "application/octet-stream");
5926
6161
  res.setHeader("Cache-Control", "no-cache");
5927
6162
  res.once("finish", () => {
5928
6163
  void engine.notifyPayloadDelivered(fileName).catch(
@@ -5963,7 +6198,7 @@ function stripCatchAllLoad(plugins) {
5963
6198
  );
5964
6199
  }
5965
6200
  function createReactRefreshRuntimePlugin(entryPoints) {
5966
- const entryIds = new Set(entryPoints.map((p) => import_node_path15.default.resolve(p)));
6201
+ const entryIds = new Set(entryPoints.map((p) => import_node_path16.default.resolve(p)));
5967
6202
  return {
5968
6203
  name: "nasti:bundled-react-refresh",
5969
6204
  resolveId(source) {
@@ -5981,7 +6216,7 @@ function createReactRefreshRuntimePlugin(entryPoints) {
5981
6216
  return null;
5982
6217
  },
5983
6218
  transform(code, id) {
5984
- if (!entryIds.has(import_node_path15.default.resolve(id.split("?")[0]))) return null;
6219
+ if (!entryIds.has(import_node_path16.default.resolve(id.split("?")[0]))) return null;
5985
6220
  return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
5986
6221
  ${code}`, map: null };
5987
6222
  }
@@ -6028,11 +6263,11 @@ async function renderBundledIndexHtml(html, config, entryFileNames) {
6028
6263
  }
6029
6264
  return processed;
6030
6265
  }
6031
- var import_node_path15, import_node_crypto3, import_ws2, import_picocolors8, debug7, MIME_TYPES, MemoryFiles, PREAMBLE_SPEC, RESOLVED_PREAMBLE_ID, REFRESH_RUNTIME_URL, BUNDLED_PREAMBLE_CODE, WRAPPER_RUNTIME_HELPERS;
6266
+ var import_node_path16, import_node_crypto3, import_ws2, import_picocolors8, debug7, MIME_TYPES, MemoryFiles, PREAMBLE_SPEC, RESOLVED_PREAMBLE_ID, REFRESH_RUNTIME_URL, BUNDLED_PREAMBLE_CODE, WRAPPER_RUNTIME_HELPERS;
6032
6267
  var init_dev_engine = __esm({
6033
6268
  "src/server/bundled/dev-engine.ts"() {
6034
6269
  "use strict";
6035
- import_node_path15 = __toESM(require("path"), 1);
6270
+ import_node_path16 = __toESM(require("path"), 1);
6036
6271
  import_node_crypto3 = __toESM(require("crypto"), 1);
6037
6272
  import_ws2 = require("ws");
6038
6273
  import_picocolors8 = __toESM(require("picocolors"), 1);
@@ -6242,20 +6477,39 @@ async function createServer(inlineConfig = {}) {
6242
6477
  app.use(bundledServer.middleware);
6243
6478
  }
6244
6479
  const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
6245
- const outDirAbs = import_node_path16.default.resolve(config.root, config.build.outDir);
6246
- const watcher = (0, import_chokidar.watch)(config.root, {
6480
+ const outDirAbs = import_node_path17.default.resolve(config.root, config.build.outDir);
6481
+ const linkedPackageRoots = getLinkedPackageRoots(config.root).filter(
6482
+ (r) => r !== config.root && !isUnderRoot(config.root, r)
6483
+ );
6484
+ const watchTargets = [config.root, ...linkedPackageRoots];
6485
+ const watcher = (0, import_chokidar.watch)(watchTargets, {
6247
6486
  ignored: (filePath) => {
6248
- if (filePath === config.root) return false;
6249
- if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path16.default.sep)) return true;
6250
- const rel = import_node_path16.default.relative(config.root, filePath);
6251
- if (!rel || rel.startsWith("..") || import_node_path16.default.isAbsolute(rel)) return false;
6252
- for (const seg of rel.split(import_node_path16.default.sep)) {
6253
- if (ignoredSegments.has(seg)) return true;
6487
+ if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path17.default.sep)) return true;
6488
+ for (const watchRoot of watchTargets) {
6489
+ if (filePath === watchRoot) return false;
6490
+ const rel = import_node_path17.default.relative(watchRoot, filePath);
6491
+ if (!rel || rel.startsWith("..") || import_node_path17.default.isAbsolute(rel)) continue;
6492
+ for (const seg of rel.split(import_node_path17.default.sep)) {
6493
+ if (ignoredSegments.has(seg)) return true;
6494
+ }
6495
+ return false;
6254
6496
  }
6255
6497
  return false;
6256
6498
  },
6257
6499
  ignoreInitial: true
6258
6500
  });
6501
+ await new Promise((resolve, reject) => {
6502
+ const onReady = () => {
6503
+ watcher.off("error", onError);
6504
+ resolve();
6505
+ };
6506
+ const onError = (err) => {
6507
+ watcher.off("ready", onReady);
6508
+ reject(err);
6509
+ };
6510
+ watcher.once("ready", onReady);
6511
+ watcher.once("error", onError);
6512
+ });
6259
6513
  let server;
6260
6514
  const environmentServices = {};
6261
6515
  let environmentDriversStarted = false;
@@ -6367,16 +6621,25 @@ async function createServer(inlineConfig = {}) {
6367
6621
  });
6368
6622
  };
6369
6623
  watcher.on("change", (file) => {
6624
+ if (file.includes(`${import_node_path17.default.sep}node_modules${import_node_path17.default.sep}`) || file.endsWith(`${import_node_path17.default.sep}node_modules`)) {
6625
+ clearLinkedPackageRootsCache();
6626
+ }
6370
6627
  ssrRunner?.invalidateFile(file);
6371
6628
  queueClientEnvironmentUpdate(file);
6372
6629
  notifyEnvironmentDrivers(file, "change");
6373
6630
  });
6374
6631
  watcher.on("add", (file) => {
6632
+ if (file.includes(`${import_node_path17.default.sep}node_modules${import_node_path17.default.sep}`) || file.endsWith(`${import_node_path17.default.sep}node_modules`)) {
6633
+ clearLinkedPackageRootsCache();
6634
+ }
6375
6635
  ssrRunner?.invalidateFile(file);
6376
6636
  queueClientEnvironmentUpdate(file);
6377
6637
  notifyEnvironmentDrivers(file, "add");
6378
6638
  });
6379
6639
  watcher.on("unlink", (file) => {
6640
+ if (file.includes(`${import_node_path17.default.sep}node_modules${import_node_path17.default.sep}`) || file.endsWith(`${import_node_path17.default.sep}node_modules`)) {
6641
+ clearLinkedPackageRootsCache();
6642
+ }
6380
6643
  ssrRunner?.invalidateFile(file);
6381
6644
  notifyEnvironmentDrivers(file, "unlink");
6382
6645
  });
@@ -6406,7 +6669,7 @@ async function createServer(inlineConfig = {}) {
6406
6669
  const readyIn = Math.ceil(performance.now() - startTime);
6407
6670
  logger.info(
6408
6671
  `
6409
- ${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.4.2"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
6672
+ ${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.4.4"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
6410
6673
  `
6411
6674
  );
6412
6675
  printServerUrls(
@@ -6503,7 +6766,7 @@ async function createServer(inlineConfig = {}) {
6503
6766
  throw error;
6504
6767
  }
6505
6768
  app.use(transformMiddleware(transformContexts.get("client")));
6506
- const publicDir = import_node_path16.default.resolve(config.root, "public");
6769
+ const publicDir = import_node_path17.default.resolve(config.root, "public");
6507
6770
  app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
6508
6771
  app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
6509
6772
  const postMiddlewares = [];
@@ -6529,12 +6792,12 @@ function getNetworkAddress() {
6529
6792
  }
6530
6793
  return "localhost";
6531
6794
  }
6532
- var import_node_http, import_node_path16, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors9;
6795
+ var import_node_http, import_node_path17, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors9;
6533
6796
  var init_server = __esm({
6534
6797
  "src/server/index.ts"() {
6535
6798
  "use strict";
6536
6799
  import_node_http = __toESM(require("http"), 1);
6537
- import_node_path16 = __toESM(require("path"), 1);
6800
+ import_node_path17 = __toESM(require("path"), 1);
6538
6801
  import_node_os = __toESM(require("os"), 1);
6539
6802
  import_connect = __toESM(require("connect"), 1);
6540
6803
  import_sirv = __toESM(require("sirv"), 1);
@@ -6550,6 +6813,7 @@ var init_server = __esm({
6550
6813
  init_builtins();
6551
6814
  init_plugin_api();
6552
6815
  init_env();
6816
+ init_fs_allow();
6553
6817
  }
6554
6818
  });
6555
6819
 
@@ -6586,6 +6850,7 @@ init_build();
6586
6850
  // src/build/electron.ts
6587
6851
  var import_node_path11 = __toESM(require("path"), 1);
6588
6852
  var import_node_fs8 = __toESM(require("fs"), 1);
6853
+ var import_node_module5 = require("module");
6589
6854
  var import_rolldown2 = require("rolldown");
6590
6855
  var import_picocolors5 = __toESM(require("picocolors"), 1);
6591
6856
  init_config();
@@ -6631,7 +6896,7 @@ async function buildElectron(inlineConfig = {}) {
6631
6896
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
6632
6897
  const startTime = performance.now();
6633
6898
  assertElectronVersion(config);
6634
- console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.4.2"}`));
6899
+ console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.4.4"}`));
6635
6900
  console.log(import_picocolors5.default.dim(` root: ${config.root}`));
6636
6901
  console.log(import_picocolors5.default.dim(` mode: ${config.mode}`));
6637
6902
  console.log(import_picocolors5.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -6775,13 +7040,21 @@ function assertElectronVersion(config) {
6775
7040
  }
6776
7041
  function detectInstalledElectron(root) {
6777
7042
  try {
6778
- const pkgPath = import_node_path11.default.resolve(root, "node_modules/electron/package.json");
6779
- if (!import_node_fs8.default.existsSync(pkgPath)) return null;
7043
+ const require2 = (0, import_node_module5.createRequire)(import_node_path11.default.resolve(root, "package.json"));
7044
+ const pkgPath = require2.resolve("electron/package.json");
6780
7045
  const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgPath, "utf-8"));
6781
7046
  const major = parseInt(String(pkg.version).split(".")[0], 10);
6782
7047
  return Number.isFinite(major) ? major : null;
6783
7048
  } catch {
6784
- return null;
7049
+ try {
7050
+ const pkgPath = import_node_path11.default.resolve(root, "node_modules/electron/package.json");
7051
+ if (!import_node_fs8.default.existsSync(pkgPath)) return null;
7052
+ const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgPath, "utf-8"));
7053
+ const major = parseInt(String(pkg.version).split(".")[0], 10);
7054
+ return Number.isFinite(major) ? major : null;
7055
+ } catch {
7056
+ return null;
7057
+ }
6785
7058
  }
6786
7059
  }
6787
7060
 
@@ -6789,9 +7062,9 @@ function detectInstalledElectron(root) {
6789
7062
  init_server();
6790
7063
 
6791
7064
  // src/server/electron-dev.ts
6792
- var import_node_path17 = __toESM(require("path"), 1);
6793
- var import_node_fs12 = __toESM(require("fs"), 1);
6794
- var import_node_module7 = require("module");
7065
+ var import_node_path18 = __toESM(require("path"), 1);
7066
+ var import_node_fs13 = __toESM(require("fs"), 1);
7067
+ var import_node_module8 = require("module");
6795
7068
  var import_node_child_process = require("child_process");
6796
7069
  var import_chokidar2 = __toESM(require("chokidar"), 1);
6797
7070
  var import_picocolors10 = __toESM(require("picocolors"), 1);
@@ -6804,7 +7077,7 @@ async function startElectronDev(inlineConfig = {}) {
6804
7077
  const { noSpawn, ...rest } = inlineConfig;
6805
7078
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
6806
7079
  warnElectronVersion(config);
6807
- console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.4.2"}`));
7080
+ console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.4.4"}`));
6808
7081
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
6809
7082
  const server = await createServer2({
6810
7083
  ...rest,
@@ -6814,11 +7087,11 @@ async function startElectronDev(inlineConfig = {}) {
6814
7087
  await server.listen();
6815
7088
  const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
6816
7089
  console.log(import_picocolors10.default.dim(` renderer: ${devUrl}`));
6817
- const stageDir = import_node_path17.default.resolve(config.root, ".nasti");
6818
- import_node_fs12.default.mkdirSync(stageDir, { recursive: true });
6819
- const mainEntry = import_node_path17.default.resolve(config.root, config.electron.main);
7090
+ const stageDir = import_node_path18.default.resolve(config.root, ".nasti");
7091
+ import_node_fs13.default.mkdirSync(stageDir, { recursive: true });
7092
+ const mainEntry = import_node_path18.default.resolve(config.root, config.electron.main);
6820
7093
  const preloadEntries = normalizePreload(config.electron.preload, config.root);
6821
- const builtMainFile = import_node_path17.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
7094
+ const builtMainFile = import_node_path18.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
6822
7095
  const builtPreloadFiles = [];
6823
7096
  const compileAll = async () => {
6824
7097
  await compileNode(config, mainEntry, {
@@ -6828,9 +7101,9 @@ async function startElectronDev(inlineConfig = {}) {
6828
7101
  });
6829
7102
  builtPreloadFiles.length = 0;
6830
7103
  for (const entry of preloadEntries) {
6831
- if (!import_node_fs12.default.existsSync(entry)) continue;
6832
- const base = import_node_path17.default.basename(entry).replace(/\.[^.]+$/, "");
6833
- const out = import_node_path17.default.join(stageDir, base + extFor(config.electron.preloadFormat));
7104
+ if (!import_node_fs13.default.existsSync(entry)) continue;
7105
+ const base = import_node_path18.default.basename(entry).replace(/\.[^.]+$/, "");
7106
+ const out = import_node_path18.default.join(stageDir, base + extFor(config.electron.preloadFormat));
6834
7107
  await compileNode(config, entry, {
6835
7108
  outFile: out,
6836
7109
  format: config.electron.preloadFormat,
@@ -6869,7 +7142,7 @@ async function startElectronDev(inlineConfig = {}) {
6869
7142
  };
6870
7143
  spawnElectron();
6871
7144
  if (config.electron.autoRestart) {
6872
- const watchTargets = [mainEntry, ...preloadEntries].filter(import_node_fs12.default.existsSync);
7145
+ const watchTargets = [mainEntry, ...preloadEntries].filter(import_node_fs13.default.existsSync);
6873
7146
  const watcher = import_chokidar2.default.watch(watchTargets, { ignoreInitial: true });
6874
7147
  let restarting = null;
6875
7148
  let pending = false;
@@ -6949,7 +7222,7 @@ async function compileNode(config, entry, opts) {
6949
7222
  platform: "node",
6950
7223
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
6951
7224
  });
6952
- import_node_fs12.default.mkdirSync(import_node_path17.default.dirname(opts.outFile), { recursive: true });
7225
+ import_node_fs13.default.mkdirSync(import_node_path18.default.dirname(opts.outFile), { recursive: true });
6953
7226
  await bundle2.write({
6954
7227
  file: opts.outFile,
6955
7228
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -6962,18 +7235,18 @@ async function compileNode(config, entry, opts) {
6962
7235
  await bundle2.close();
6963
7236
  }
6964
7237
  function electronRendererDevPath(renderer) {
6965
- const normalized = renderer.split(import_node_path17.default.sep).join("/").replace(/^\.?\//, "");
7238
+ const normalized = renderer.split(import_node_path18.default.sep).join("/").replace(/^\.?\//, "");
6966
7239
  return normalized === "index.html" ? "/" : `/${normalized}`;
6967
7240
  }
6968
7241
  function resolveElectronBinary(config) {
6969
- if (config.electron.electronPath && import_node_fs12.default.existsSync(config.electron.electronPath)) {
7242
+ if (config.electron.electronPath && import_node_fs13.default.existsSync(config.electron.electronPath)) {
6970
7243
  return config.electron.electronPath;
6971
7244
  }
6972
7245
  try {
6973
- const require2 = (0, import_node_module7.createRequire)(import_node_path17.default.resolve(config.root, "package.json"));
7246
+ const require2 = (0, import_node_module8.createRequire)(import_node_path18.default.resolve(config.root, "package.json"));
6974
7247
  const pathFile = require2.resolve("electron");
6975
7248
  const electronModule = require2(pathFile);
6976
- if (typeof electronModule === "string" && import_node_fs12.default.existsSync(electronModule)) {
7249
+ if (typeof electronModule === "string" && import_node_fs13.default.existsSync(electronModule)) {
6977
7250
  return electronModule;
6978
7251
  }
6979
7252
  } catch {
@@ -7000,10 +7273,10 @@ function warnElectronVersion(config) {
7000
7273
  }
7001
7274
 
7002
7275
  // src/plugins/monaco-editor.ts
7003
- var import_node_path18 = __toESM(require("path"), 1);
7004
- var import_node_fs13 = __toESM(require("fs"), 1);
7276
+ var import_node_path19 = __toESM(require("path"), 1);
7277
+ var import_node_fs14 = __toESM(require("fs"), 1);
7005
7278
  var import_node_crypto4 = __toESM(require("crypto"), 1);
7006
- var import_node_module8 = require("module");
7279
+ var import_node_module9 = require("module");
7007
7280
  var DEFAULT_WORKERS = {
7008
7281
  editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
7009
7282
  css: "monaco-editor/esm/vs/language/css/css.worker",
@@ -7022,9 +7295,9 @@ function normalizePublicPath(p) {
7022
7295
  }
7023
7296
  function readMonacoVersion(root) {
7024
7297
  try {
7025
- const require2 = (0, import_node_module8.createRequire)(import_node_path18.default.resolve(root, "package.json"));
7298
+ const require2 = (0, import_node_module9.createRequire)(import_node_path19.default.resolve(root, "package.json"));
7026
7299
  const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
7027
- const pkg = JSON.parse(import_node_fs13.default.readFileSync(pkgJsonPath, "utf-8"));
7300
+ const pkg = JSON.parse(import_node_fs14.default.readFileSync(pkgJsonPath, "utf-8"));
7028
7301
  return typeof pkg.version === "string" ? pkg.version : "unknown";
7029
7302
  } catch {
7030
7303
  return "unknown";
@@ -7044,20 +7317,20 @@ function monacoEditorPlugin(options = {}) {
7044
7317
  let cacheDir = "";
7045
7318
  const building = /* @__PURE__ */ new Map();
7046
7319
  async function buildWorker(worker) {
7047
- const cacheFile = import_node_path18.default.join(cacheDir, `${worker.label}.worker.js`);
7048
- if (import_node_fs13.default.existsSync(cacheFile)) return cacheFile;
7320
+ const cacheFile = import_node_path19.default.join(cacheDir, `${worker.label}.worker.js`);
7321
+ if (import_node_fs14.default.existsSync(cacheFile)) return cacheFile;
7049
7322
  const existing = building.get(worker.label);
7050
7323
  if (existing) return existing;
7051
7324
  const task = (async () => {
7052
7325
  const { rolldown: rolldown4 } = await import("rolldown");
7053
- const require2 = (0, import_node_module8.createRequire)(import_node_path18.default.resolve(resolvedConfig.root, "package.json"));
7326
+ const require2 = (0, import_node_module9.createRequire)(import_node_path19.default.resolve(resolvedConfig.root, "package.json"));
7054
7327
  let entry;
7055
7328
  try {
7056
7329
  entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
7057
7330
  } catch {
7058
7331
  entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
7059
7332
  }
7060
- import_node_fs13.default.mkdirSync(cacheDir, { recursive: true });
7333
+ import_node_fs14.default.mkdirSync(cacheDir, { recursive: true });
7061
7334
  const bundle2 = await rolldown4({
7062
7335
  input: entry,
7063
7336
  platform: "browser"
@@ -7117,16 +7390,23 @@ function monacoEditorPlugin(options = {}) {
7117
7390
  resolvedConfig = config;
7118
7391
  const version = readMonacoVersion(config.root);
7119
7392
  const key = import_node_crypto4.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
7120
- cacheDir = import_node_path18.default.resolve(config.root, "node_modules/.nasti/monaco", key);
7393
+ cacheDir = import_node_path19.default.resolve(config.root, "node_modules/.nasti/monaco", key);
7121
7394
  },
7122
7395
  async configureServer(server) {
7123
7396
  const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
7124
7397
  const watcher = server.watcher;
7125
- const monacoDir = import_node_path18.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
7398
+ const monacoLogical = import_node_path19.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
7399
+ const monacoPaths = /* @__PURE__ */ new Set([monacoLogical]);
7126
7400
  try {
7127
- watcher?.unwatch?.(monacoDir);
7401
+ monacoPaths.add(import_node_fs14.default.realpathSync(monacoLogical));
7128
7402
  } catch {
7129
7403
  }
7404
+ for (const monacoDir of monacoPaths) {
7405
+ try {
7406
+ watcher?.unwatch?.(monacoDir);
7407
+ } catch {
7408
+ }
7409
+ }
7130
7410
  if (!shouldBuild) return;
7131
7411
  void Promise.all(
7132
7412
  workers.map(
@@ -7152,7 +7432,7 @@ function monacoEditorPlugin(options = {}) {
7152
7432
  const file = await buildWorker(worker);
7153
7433
  res.setHeader("Content-Type", "application/javascript; charset=utf-8");
7154
7434
  res.setHeader("Cache-Control", "public, max-age=604800, immutable");
7155
- import_node_fs13.default.createReadStream(file).pipe(res);
7435
+ import_node_fs14.default.createReadStream(file).pipe(res);
7156
7436
  } catch (e) {
7157
7437
  res.statusCode = 500;
7158
7438
  res.end(`Monaco worker build failed: ${e.message}`);
@@ -7187,16 +7467,16 @@ self.monaco = monaco;`,
7187
7467
  resolvedConfig.root,
7188
7468
  resolvedConfig.build.outDir,
7189
7469
  resolvedConfig.base
7190
- ) : isCDN(publicPath) ? import_node_path18.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path18.default.resolve(
7470
+ ) : isCDN(publicPath) ? import_node_path19.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path19.default.resolve(
7191
7471
  resolvedConfig.root,
7192
7472
  resolvedConfig.build.outDir,
7193
7473
  publicPath.replace(/^\//, "")
7194
7474
  );
7195
- import_node_fs13.default.mkdirSync(outDir, { recursive: true });
7475
+ import_node_fs14.default.mkdirSync(outDir, { recursive: true });
7196
7476
  for (const worker of workers) {
7197
7477
  try {
7198
7478
  const cacheFile = await buildWorker(worker);
7199
- import_node_fs13.default.copyFileSync(cacheFile, import_node_path18.default.join(outDir, `${worker.label}.worker.js`));
7479
+ import_node_fs14.default.copyFileSync(cacheFile, import_node_path19.default.join(outDir, `${worker.label}.worker.js`));
7200
7480
  } catch (e) {
7201
7481
  throw new Error(
7202
7482
  `[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}