@nasti-toolchain/nasti 2.4.3 → 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,
@@ -2887,6 +2887,24 @@ var init_module_graph = __esm({
2887
2887
  getModulesByFile(file) {
2888
2888
  return this.fileToModulesMap.get(file);
2889
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
+ }
2890
2908
  async ensureEntryFromUrl(url) {
2891
2909
  const normalizedUrl = removeTimestampQuery(url);
2892
2910
  let mod = this.urlToModuleMap.get(normalizedUrl);
@@ -3857,7 +3875,7 @@ async function build(inlineConfig = {}) {
3857
3875
  const startTime = performance.now();
3858
3876
  logger.info(
3859
3877
  import_picocolors4.default.cyan(`
3860
- nasti v${"2.4.3"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
3878
+ nasti v${"2.4.4"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
3861
3879
  );
3862
3880
  debug5?.(`root: ${config.root}`);
3863
3881
  const buildableNames = Object.keys(config.environments).filter((name) => {
@@ -4200,6 +4218,120 @@ var init_ws = __esm({
4200
4218
  }
4201
4219
  });
4202
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
+
4203
4335
  // src/server/middleware.ts
4204
4336
  function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
4205
4337
  if (__refreshRuntimeCache) {
@@ -4208,10 +4340,10 @@ function getReactRefreshRuntimeEsm(includeBoundaryHelpers = false) {
4208
4340
  let cjsPath;
4209
4341
  try {
4210
4342
  const pkgPath = __require.resolve("react-refresh/package.json");
4211
- 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");
4212
4344
  } catch (err) {
4213
- cjsPath = import_node_path12.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
4214
- 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)) {
4215
4347
  const origMsg = err instanceof Error ? err.message : String(err);
4216
4348
  throw new Error(
4217
4349
  `[nasti] Missing dependency "react-refresh". Install it with: npm install react-refresh
@@ -4219,7 +4351,7 @@ Original resolve error: ${origMsg}`
4219
4351
  );
4220
4352
  }
4221
4353
  }
4222
- const cjsSource = import_node_fs9.default.readFileSync(cjsPath, "utf-8");
4354
+ const cjsSource = import_node_fs10.default.readFileSync(cjsPath, "utf-8");
4223
4355
  __refreshRuntimeCache = `// Wrapped react-refresh runtime -> ESM
4224
4356
  const exports = {};
4225
4357
  const module = { exports };
@@ -4390,8 +4522,8 @@ async function transformRequest(url, ctx) {
4390
4522
  let realIdValid = false;
4391
4523
  try {
4392
4524
  if (idParam) {
4393
- realId = import_node_fs9.default.realpathSync(idParam);
4394
- 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);
4395
4527
  }
4396
4528
  } catch {
4397
4529
  realId = null;
@@ -4458,7 +4590,7 @@ async function transformRequest(url, ctx) {
4458
4590
  }
4459
4591
  }
4460
4592
  const filePath = resolveUrlToFile(url, config.root);
4461
- if (!filePath || !import_node_fs9.default.existsSync(filePath)) return null;
4593
+ if (!filePath || !import_node_fs10.default.existsSync(filePath)) return null;
4462
4594
  const mod = await moduleGraph.ensureEntryFromUrl(url);
4463
4595
  moduleGraph.registerModule(mod, filePath);
4464
4596
  const transformVersion = mod.invalidationVersion;
@@ -4469,7 +4601,7 @@ async function transformRequest(url, ctx) {
4469
4601
  return transformResult2;
4470
4602
  }
4471
4603
  const loaded = await pluginContainer.load(filePath);
4472
- 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;
4473
4605
  let map = loaded && typeof loaded !== "string" ? loaded.map : void 0;
4474
4606
  const pluginResult = await pluginContainer.transform(code, filePath);
4475
4607
  if (pluginResult) {
@@ -4527,7 +4659,7 @@ async function loadVirtualModule(spec, ctx) {
4527
4659
  const resolved = await pluginContainer.resolveId(spec);
4528
4660
  if (resolved == null) return null;
4529
4661
  const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
4530
- const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs9.default.existsSync(resolvedId);
4662
+ const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs10.default.existsSync(resolvedId);
4531
4663
  if (!looksVirtual) return null;
4532
4664
  const loadResult = await pluginContainer.load(resolvedId);
4533
4665
  if (loadResult == null) return null;
@@ -4541,7 +4673,7 @@ async function loadVirtualModule(spec, ctx) {
4541
4673
  config.mode,
4542
4674
  ssrDefineOverrides(ctx.environment?.consumer ?? "client")
4543
4675
  ));
4544
- 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");
4545
4677
  code = rewriteImports(code, config, anchor);
4546
4678
  return { id: resolvedId, result: { code } };
4547
4679
  }
@@ -4567,7 +4699,7 @@ async function doBundlePackage(entryFile, root) {
4567
4699
  await bundle2.close();
4568
4700
  let code = result.output[0].code;
4569
4701
  code = code.replace(/process\.env\.NODE_ENV/g, '"development"');
4570
- const externalBaseDir = import_node_path12.default.dirname(entryFile);
4702
+ const externalBaseDir = import_node_path13.default.dirname(entryFile);
4571
4703
  code = code.replace(
4572
4704
  /^(import\b[^;'"]*?\bfrom\s+)(['"])([^'"./][^'"]*)(\2)/gm,
4573
4705
  (_, prefix, q, spec) => `${prefix}${q}${externalSpecToModuleUrl(spec, externalBaseDir, root)}${q}`
@@ -4585,16 +4717,16 @@ async function doBundlePackage(entryFile, root) {
4585
4717
  return code;
4586
4718
  }
4587
4719
  async function tryGenerateSubpathShim(entryFile, root) {
4588
- const NM = `${import_node_path12.default.sep}node_modules${import_node_path12.default.sep}`;
4589
- 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;
4590
4722
  let pkgDir = null;
4591
4723
  let pkgName = null;
4592
- let dir = import_node_path12.default.dirname(entryFile);
4724
+ let dir = import_node_path13.default.dirname(entryFile);
4593
4725
  while (true) {
4594
- const pkgJsonPath = import_node_path12.default.join(dir, "package.json");
4595
- 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)) {
4596
4728
  try {
4597
- 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"));
4598
4730
  if (typeof pkg?.name === "string" && pkg.name) {
4599
4731
  pkgDir = dir;
4600
4732
  pkgName = pkg.name;
@@ -4603,16 +4735,16 @@ async function tryGenerateSubpathShim(entryFile, root) {
4603
4735
  } catch {
4604
4736
  }
4605
4737
  }
4606
- const parent = import_node_path12.default.dirname(dir);
4738
+ const parent = import_node_path13.default.dirname(dir);
4607
4739
  if (parent === dir) return null;
4608
4740
  dir = parent;
4609
- if (!dir.includes(NM)) return null;
4741
+ if (!dir.includes(NM2)) return null;
4610
4742
  }
4611
4743
  if (!pkgDir || !pkgName) return null;
4612
- const entryExt = import_node_path12.default.extname(entryFile);
4744
+ const entryExt = import_node_path13.default.extname(entryFile);
4613
4745
  const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
4614
4746
  if (!mainEntry) return null;
4615
- 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;
4616
4748
  let mainNs;
4617
4749
  let subNs;
4618
4750
  try {
@@ -4636,7 +4768,7 @@ async function tryGenerateSubpathShim(entryFile, root) {
4636
4768
  if (mainNs["default"] !== subNs["default"]) return null;
4637
4769
  }
4638
4770
  const rootMain = resolveNodeModule(root, pkgName);
4639
- 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)}`;
4640
4772
  const lines = [
4641
4773
  `// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
4642
4774
  `import * as __pkg from "${mainEntryUrl}";`
@@ -4650,10 +4782,10 @@ async function tryGenerateSubpathShim(entryFile, root) {
4650
4782
  return lines.join("\n") + "\n";
4651
4783
  }
4652
4784
  function pickMainEntryByExtension(pkgDir, preferredExt) {
4653
- const pkgJsonPath = import_node_path12.default.join(pkgDir, "package.json");
4785
+ const pkgJsonPath = import_node_path13.default.join(pkgDir, "package.json");
4654
4786
  let pkg;
4655
4787
  try {
4656
- pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
4788
+ pkg = JSON.parse(import_node_fs10.default.readFileSync(pkgJsonPath, "utf-8"));
4657
4789
  } catch {
4658
4790
  return null;
4659
4791
  }
@@ -4672,14 +4804,14 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
4672
4804
  if (typeof pkg.module === "string") candidates.push(pkg.module);
4673
4805
  if (typeof pkg.main === "string") candidates.push(pkg.main);
4674
4806
  for (const cand of candidates) {
4675
- if (import_node_path12.default.extname(cand) === preferredExt) {
4676
- const full = import_node_path12.default.resolve(pkgDir, cand);
4677
- 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;
4678
4810
  }
4679
4811
  }
4680
4812
  for (const cand of candidates) {
4681
- const full = import_node_path12.default.resolve(pkgDir, cand);
4682
- 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;
4683
4815
  }
4684
4816
  return null;
4685
4817
  }
@@ -4704,8 +4836,8 @@ function rewriteExternalRequires(code, baseDir, root) {
4704
4836
  }
4705
4837
  async function injectCjsNamedExports(code, entryFile) {
4706
4838
  try {
4707
- const { createRequire: createRequire7 } = await import("module");
4708
- const req = createRequire7(entryFile);
4839
+ const { createRequire: createRequire8 } = await import("module");
4840
+ const req = createRequire8(entryFile);
4709
4841
  const cjsExports = req(entryFile);
4710
4842
  if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
4711
4843
  const namedKeys = Object.keys(cjsExports).filter(
@@ -4746,11 +4878,22 @@ function rewriteImports(code, config, filePath, importedUrls, moduleGraph) {
4746
4878
  }
4747
4879
  function createModuleSpecifierResolver(config, filePath) {
4748
4880
  const root = config.root;
4749
- const fileDir = import_node_path12.default.dirname(filePath);
4881
+ const fileDir = import_node_path13.default.dirname(filePath);
4750
4882
  const aliasEntries = Object.entries(config.resolve.alias).sort(
4751
4883
  ([a], [b]) => b.length - a.length
4752
4884
  );
4753
- 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
+ };
4754
4897
  return (specifier) => {
4755
4898
  const suffixMatch = specifier.match(/[?#].*$/);
4756
4899
  const suffix = suffixMatch ? suffixMatch[0] : "";
@@ -4759,18 +4902,21 @@ function createModuleSpecifierResolver(config, filePath) {
4759
4902
  if (baseSpec === key || baseSpec.startsWith(key + "/")) {
4760
4903
  const aliasBase = resolveAliasTarget2(value, root);
4761
4904
  const sub = baseSpec.slice(key.length).replace(/^\//, "");
4762
- const target = sub ? import_node_path12.default.join(aliasBase, sub) : aliasBase;
4905
+ const target = sub ? import_node_path13.default.join(aliasBase, sub) : aliasBase;
4763
4906
  const resolved = tryResolveDiskPath(target);
4764
- return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : specifier;
4907
+ const url = resolved ? toServableUrl(resolved) : null;
4908
+ return url ? url + suffix : specifier;
4765
4909
  }
4766
4910
  }
4767
4911
  if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
4768
- const resolved = tryResolveDiskPath(import_node_path12.default.resolve(fileDir, baseSpec));
4769
- 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;
4770
4915
  }
4771
4916
  if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
4772
- const resolved = tryResolveDiskPath(import_node_path12.default.join(root, baseSpec.replace(/^\//, "")));
4773
- 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;
4774
4920
  }
4775
4921
  if (baseSpec.startsWith("/")) return specifier;
4776
4922
  return `/@modules/${specifier}`;
@@ -4923,28 +5069,24 @@ function maskStringsAndComments(code) {
4923
5069
  return masked.join("");
4924
5070
  }
4925
5071
  function resolveAliasTarget2(value, root) {
4926
- if (import_node_path12.default.isAbsolute(value) && import_node_fs9.default.existsSync(value)) return value;
4927
- if (value.startsWith("/")) return import_node_path12.default.join(root, value.slice(1));
4928
- 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);
4929
5075
  }
4930
5076
  function tryResolveDiskPath(target) {
4931
- 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;
4932
5078
  for (const ext of RESOLVE_EXTENSIONS) {
4933
5079
  const withExt = target + ext;
4934
- 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;
4935
5081
  }
4936
- 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()) {
4937
5083
  for (const ext of RESOLVE_EXTENSIONS) {
4938
- const idx = import_node_path12.default.join(target, "index" + ext);
4939
- 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;
4940
5086
  }
4941
5087
  }
4942
5088
  return null;
4943
5089
  }
4944
- function isUnderRoot(abs, root) {
4945
- const rel = import_node_path12.default.relative(root, abs);
4946
- return !!rel && !rel.startsWith("..") && !import_node_path12.default.isAbsolute(rel);
4947
- }
4948
5090
  function appendTimestampQuery(url, timestamp) {
4949
5091
  const hashIndex = url.indexOf("#");
4950
5092
  const hash = hashIndex >= 0 ? url.slice(hashIndex) : "";
@@ -4962,7 +5104,7 @@ function resolveNodeModule(baseDir, moduleName) {
4962
5104
  const resolved = resolveNodeModuleEntry(baseDir, moduleName);
4963
5105
  if (!resolved) return null;
4964
5106
  try {
4965
- return import_node_fs9.default.realpathSync(resolved);
5107
+ return import_node_fs10.default.realpathSync(resolved);
4966
5108
  } catch {
4967
5109
  return resolved;
4968
5110
  }
@@ -4982,21 +5124,21 @@ function resolveNodeModuleEntry(root, moduleName) {
4982
5124
  let pkgDir = null;
4983
5125
  let dir = root;
4984
5126
  for (; ; ) {
4985
- const candidate = import_node_path12.default.join(dir, "node_modules", pkgName);
4986
- 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)) {
4987
5129
  pkgDir = candidate;
4988
5130
  break;
4989
5131
  }
4990
- const parent = import_node_path12.default.dirname(dir);
5132
+ const parent = import_node_path13.default.dirname(dir);
4991
5133
  if (parent === dir) break;
4992
5134
  dir = parent;
4993
5135
  }
4994
5136
  if (!pkgDir) return null;
4995
- const pkgJsonPath = import_node_path12.default.join(pkgDir, "package.json");
4996
- 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;
4997
5139
  let pkg;
4998
5140
  try {
4999
- pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgJsonPath, "utf-8"));
5141
+ pkg = JSON.parse(import_node_fs10.default.readFileSync(pkgJsonPath, "utf-8"));
5000
5142
  } catch {
5001
5143
  return null;
5002
5144
  }
@@ -5009,32 +5151,32 @@ function resolveNodeModuleEntry(root, moduleName) {
5009
5151
  const subDirs = [""];
5010
5152
  for (const field of ["module", "main"]) {
5011
5153
  if (typeof pkg[field] === "string") {
5012
- const dir2 = import_node_path12.default.dirname(pkg[field]);
5154
+ const dir2 = import_node_path13.default.dirname(pkg[field]);
5013
5155
  if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
5014
5156
  }
5015
5157
  }
5016
5158
  for (const dir2 of subDirs) {
5017
- const direct = import_node_path12.default.join(pkgDir, dir2, subpath);
5018
- 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;
5019
5161
  for (const ext of RESOLVE_EXTENSIONS) {
5020
- if (import_node_fs9.default.existsSync(direct + ext)) return direct + ext;
5162
+ if (import_node_fs10.default.existsSync(direct + ext)) return direct + ext;
5021
5163
  }
5022
5164
  }
5023
5165
  return null;
5024
5166
  }
5025
5167
  for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
5026
5168
  if (typeof pkg[field] === "string") {
5027
- const entry = import_node_path12.default.join(pkgDir, pkg[field]);
5028
- 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;
5029
5171
  }
5030
5172
  }
5031
- const indexFallback = import_node_path12.default.join(pkgDir, "index.js");
5032
- 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;
5033
5175
  return null;
5034
5176
  }
5035
5177
  function resolvePackageExports(exports2, key, pkgDir) {
5036
5178
  if (typeof exports2 === "string") {
5037
- return key === "." ? import_node_path12.default.join(pkgDir, exports2) : null;
5179
+ return key === "." ? import_node_path13.default.join(pkgDir, exports2) : null;
5038
5180
  }
5039
5181
  const entry = exports2[key];
5040
5182
  if (entry === void 0) {
@@ -5046,7 +5188,7 @@ function resolvePackageExports(exports2, key, pkgDir) {
5046
5188
  return resolveExportValue(entry, pkgDir);
5047
5189
  }
5048
5190
  function resolveExportValue(value, pkgDir) {
5049
- 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);
5050
5192
  if (Array.isArray(value)) {
5051
5193
  for (const item of value) {
5052
5194
  const r = resolveExportValue(item, pkgDir);
@@ -5065,35 +5207,54 @@ function resolveExportValue(value, pkgDir) {
5065
5207
  return null;
5066
5208
  }
5067
5209
  function resolveUrlToFile(url, root) {
5068
- const cleanUrl = url.split("?")[0];
5210
+ const cleanUrl = url.split(/[?#]/)[0];
5069
5211
  if (cleanUrl.startsWith("/@modules/")) {
5070
5212
  const moduleName = cleanUrl.slice("/@modules/".length);
5071
5213
  return resolveNodeModule(root, moduleName);
5072
5214
  }
5073
- const filePath = import_node_path12.default.resolve(root, cleanUrl.replace(/^\//, ""));
5074
- 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()) {
5075
5232
  return filePath;
5076
5233
  }
5077
5234
  for (const ext of RESOLVE_EXTENSIONS) {
5078
5235
  const withExt = filePath + ext;
5079
- if (import_node_fs9.default.existsSync(withExt)) return withExt;
5236
+ if (import_node_fs10.default.existsSync(withExt)) return withExt;
5080
5237
  }
5081
5238
  for (const ext of RESOLVE_EXTENSIONS) {
5082
- const indexFile = import_node_path12.default.join(filePath, "index" + ext);
5083
- 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;
5084
5241
  }
5085
5242
  return null;
5086
5243
  }
5087
5244
  function isModuleRequest(url, destination) {
5088
- const cleanUrl = url.split("?")[0];
5245
+ const cleanUrl = url.split(/[?#]/)[0];
5089
5246
  if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
5090
5247
  if (cleanUrl.startsWith("/@modules/")) return true;
5248
+ if (cleanUrl.startsWith("/@fs/")) return true;
5091
5249
  if (isAssetFile(cleanUrl)) {
5092
- 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);
5093
5254
  const isExplicitAssetModule = /(?:^|&)(?:url|raw)(?:&|$)/.test(query);
5094
5255
  return isExplicitAssetModule || destination === "script";
5095
5256
  }
5096
- if (!import_node_path12.default.extname(cleanUrl)) return true;
5257
+ if (!import_node_path13.default.extname(cleanUrl)) return true;
5097
5258
  return false;
5098
5259
  }
5099
5260
  function getHmrClientCode() {
@@ -5323,13 +5484,13 @@ function clearCustomListeners(ownerPath) {
5323
5484
  }
5324
5485
  `;
5325
5486
  }
5326
- 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;
5327
5488
  var init_middleware = __esm({
5328
5489
  "src/server/middleware.ts"() {
5329
5490
  "use strict";
5330
- import_node_path12 = __toESM(require("path"), 1);
5331
- import_node_fs9 = __toESM(require("fs"), 1);
5332
- 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");
5333
5494
  import_node_url3 = require("url");
5334
5495
  import_picocolors6 = __toESM(require("picocolors"), 1);
5335
5496
  init_transformer();
@@ -5337,9 +5498,10 @@ var init_middleware = __esm({
5337
5498
  init_env();
5338
5499
  init_url();
5339
5500
  init_assets();
5501
+ init_fs_allow();
5340
5502
  import_meta = {};
5341
- __dirname_esm = import_node_path12.default.dirname((0, import_node_url3.fileURLToPath)(import_meta.url));
5342
- __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);
5343
5505
  __refreshRuntimeCache = null;
5344
5506
  REACT_REFRESH_BOUNDARY_HELPERS = `
5345
5507
  function __nastiIsPlainObject(obj) {
@@ -5427,9 +5589,26 @@ async function handleFileChange(file, server, environmentName = "client", timest
5427
5589
  }
5428
5590
  const moduleGraph = environment.moduleGraph;
5429
5591
  const logger = config.logger;
5430
- const relativePath = "/" + import_node_path13.default.relative(config.root, file);
5431
- const shortFile = import_node_path13.default.relative(config.root, file);
5432
- 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
+ }
5433
5612
  if (!mods || mods.size === 0) {
5434
5613
  return null;
5435
5614
  }
@@ -5444,7 +5623,7 @@ async function handleFileChange(file, server, environmentName = "client", timest
5444
5623
  file,
5445
5624
  timestamp,
5446
5625
  modules: [mod],
5447
- read: () => import_node_fs10.default.readFileSync(file, "utf-8"),
5626
+ read: () => import_node_fs11.default.readFileSync(file, "utf-8"),
5448
5627
  server,
5449
5628
  environment
5450
5629
  };
@@ -5505,13 +5684,14 @@ async function handleFileChange(file, server, environmentName = "client", timest
5505
5684
  fullReload
5506
5685
  };
5507
5686
  }
5508
- var import_node_path13, import_node_fs10, import_picocolors7;
5687
+ var import_node_path14, import_node_fs11, import_picocolors7;
5509
5688
  var init_hmr = __esm({
5510
5689
  "src/server/hmr.ts"() {
5511
5690
  "use strict";
5512
- import_node_path13 = __toESM(require("path"), 1);
5513
- import_node_fs10 = __toESM(require("fs"), 1);
5691
+ import_node_path14 = __toESM(require("path"), 1);
5692
+ import_node_fs11 = __toESM(require("fs"), 1);
5514
5693
  import_picocolors7 = __toESM(require("picocolors"), 1);
5694
+ init_fs_allow();
5515
5695
  }
5516
5696
  });
5517
5697
 
@@ -5529,19 +5709,19 @@ function createModuleRunner(environment) {
5529
5709
  }
5530
5710
  return new NastiModuleRunner(environment);
5531
5711
  }
5532
- 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;
5533
5713
  var init_runnable_environment = __esm({
5534
5714
  "src/server/runnable-environment.ts"() {
5535
5715
  "use strict";
5536
- import_node_path14 = __toESM(require("path"), 1);
5537
- import_node_fs11 = __toESM(require("fs"), 1);
5538
- 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");
5539
5719
  import_node_url4 = require("url");
5540
5720
  init_transformer();
5541
5721
  init_env();
5542
5722
  init_debug();
5543
5723
  debug6 = createDebugger("nasti:ssr");
5544
- 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}`)]);
5545
5725
  NastiModuleRunner = class {
5546
5726
  environment;
5547
5727
  config;
@@ -5556,10 +5736,10 @@ var init_runnable_environment = __esm({
5556
5736
  this.config.mode,
5557
5737
  ssrDefineOverrides(environment.consumer)
5558
5738
  );
5559
- 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"));
5560
5740
  const handlers = {
5561
5741
  fetchModule: async (id, importer) => this.fetchModule(id, importer),
5562
- getBuiltins: () => [/^node:/, ...import_node_module6.builtinModules]
5742
+ getBuiltins: () => [/^node:/, ...import_node_module7.builtinModules]
5563
5743
  };
5564
5744
  environment.hot.setInvokeHandler?.(handlers);
5565
5745
  }
@@ -5580,9 +5760,9 @@ var init_runnable_environment = __esm({
5580
5760
  this.cache.clear();
5581
5761
  }
5582
5762
  resolveToId(rawUrl) {
5583
- 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;
5584
5764
  const clean = rawUrl.replace(/^\//, "");
5585
- return import_node_path14.default.resolve(this.config.root, clean);
5765
+ return import_node_path15.default.resolve(this.config.root, clean);
5586
5766
  }
5587
5767
  /**
5588
5768
  * fetchModule(invoke 契约方法):环境管线产出 runner 可执行代码。
@@ -5591,14 +5771,14 @@ var init_runnable_environment = __esm({
5591
5771
  */
5592
5772
  async fetchModule(id, importer) {
5593
5773
  if (NODE_BUILTINS3.has(id)) return { externalize: id };
5594
- 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")) {
5595
5775
  return { externalize: id };
5596
5776
  }
5597
5777
  const container = this.environment.pluginContainer;
5598
5778
  let resolvedId = id;
5599
5779
  if (id.startsWith(".") && importer) {
5600
5780
  const resolved = await container.resolveId(id, importer);
5601
- 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);
5602
5782
  }
5603
5783
  resolvedId = this.completeExtension(resolvedId);
5604
5784
  const cleanId = resolvedId.split("?")[0];
@@ -5606,8 +5786,8 @@ var init_runnable_environment = __esm({
5606
5786
  const loaded = await container.load(resolvedId);
5607
5787
  if (loaded != null) {
5608
5788
  code = typeof loaded === "string" ? loaded : loaded.code;
5609
- } else if (import_node_fs11.default.existsSync(cleanId)) {
5610
- 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");
5611
5791
  } else {
5612
5792
  throw new Error(`[nasti:ssr] cannot load module: ${resolvedId}`);
5613
5793
  }
@@ -5641,19 +5821,19 @@ var init_runnable_environment = __esm({
5641
5821
  completeExtension(id) {
5642
5822
  const clean = id.split("?")[0];
5643
5823
  const query = id.includes("?") ? id.slice(id.indexOf("?")) : "";
5644
- 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;
5645
5825
  const jsMatch = clean.match(/^(.*)\.([mc]?)jsx?$/);
5646
5826
  if (jsMatch) {
5647
5827
  for (const tsExt of [`.${jsMatch[2]}ts`, `.${jsMatch[2]}tsx`]) {
5648
- 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;
5649
5829
  }
5650
5830
  }
5651
5831
  for (const ext of this.config.resolve.extensions) {
5652
- 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;
5653
5833
  }
5654
5834
  for (const ext of this.config.resolve.extensions) {
5655
- const indexPath = import_node_path14.default.join(clean, `index${ext}`);
5656
- 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;
5657
5837
  }
5658
5838
  return id;
5659
5839
  }
@@ -5680,10 +5860,10 @@ var init_runnable_environment = __esm({
5680
5860
  return;
5681
5861
  }
5682
5862
  const ssrImport = async (dep) => {
5683
- 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")) {
5684
5864
  return this.importExternal(dep);
5685
5865
  }
5686
- 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);
5687
5867
  return this.instantiate(depId);
5688
5868
  };
5689
5869
  const ssrExportAll = (sourceModule) => {
@@ -5715,7 +5895,7 @@ var init_runnable_environment = __esm({
5715
5895
  }
5716
5896
  async importExternal(spec) {
5717
5897
  try {
5718
- 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));
5719
5899
  } catch (err) {
5720
5900
  throw new Error(`[nasti:ssr] failed to import external "${spec}": ${err.message}`);
5721
5901
  }
@@ -5822,7 +6002,7 @@ async function createBundledDevServer(opts) {
5822
6002
  }
5823
6003
  const url = `/${patchPath}`;
5824
6004
  logger.info(
5825
- 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(", ")),
5826
6006
  { timestamp: true }
5827
6007
  );
5828
6008
  sendTo(clientId, { type: "hmr:update", path: url, url });
@@ -5977,7 +6157,7 @@ async function createBundledDevServer(opts) {
5977
6157
  return;
5978
6158
  }
5979
6159
  res.setHeader("ETag", hit.etag);
5980
- 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");
5981
6161
  res.setHeader("Cache-Control", "no-cache");
5982
6162
  res.once("finish", () => {
5983
6163
  void engine.notifyPayloadDelivered(fileName).catch(
@@ -6018,7 +6198,7 @@ function stripCatchAllLoad(plugins) {
6018
6198
  );
6019
6199
  }
6020
6200
  function createReactRefreshRuntimePlugin(entryPoints) {
6021
- 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)));
6022
6202
  return {
6023
6203
  name: "nasti:bundled-react-refresh",
6024
6204
  resolveId(source) {
@@ -6036,7 +6216,7 @@ function createReactRefreshRuntimePlugin(entryPoints) {
6036
6216
  return null;
6037
6217
  },
6038
6218
  transform(code, id) {
6039
- 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;
6040
6220
  return { code: `import ${JSON.stringify(PREAMBLE_SPEC)};
6041
6221
  ${code}`, map: null };
6042
6222
  }
@@ -6083,11 +6263,11 @@ async function renderBundledIndexHtml(html, config, entryFileNames) {
6083
6263
  }
6084
6264
  return processed;
6085
6265
  }
6086
- 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;
6087
6267
  var init_dev_engine = __esm({
6088
6268
  "src/server/bundled/dev-engine.ts"() {
6089
6269
  "use strict";
6090
- import_node_path15 = __toESM(require("path"), 1);
6270
+ import_node_path16 = __toESM(require("path"), 1);
6091
6271
  import_node_crypto3 = __toESM(require("crypto"), 1);
6092
6272
  import_ws2 = require("ws");
6093
6273
  import_picocolors8 = __toESM(require("picocolors"), 1);
@@ -6297,20 +6477,39 @@ async function createServer(inlineConfig = {}) {
6297
6477
  app.use(bundledServer.middleware);
6298
6478
  }
6299
6479
  const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
6300
- const outDirAbs = import_node_path16.default.resolve(config.root, config.build.outDir);
6301
- 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, {
6302
6486
  ignored: (filePath) => {
6303
- if (filePath === config.root) return false;
6304
- if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path16.default.sep)) return true;
6305
- const rel = import_node_path16.default.relative(config.root, filePath);
6306
- if (!rel || rel.startsWith("..") || import_node_path16.default.isAbsolute(rel)) return false;
6307
- for (const seg of rel.split(import_node_path16.default.sep)) {
6308
- 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;
6309
6496
  }
6310
6497
  return false;
6311
6498
  },
6312
6499
  ignoreInitial: true
6313
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
+ });
6314
6513
  let server;
6315
6514
  const environmentServices = {};
6316
6515
  let environmentDriversStarted = false;
@@ -6422,16 +6621,25 @@ async function createServer(inlineConfig = {}) {
6422
6621
  });
6423
6622
  };
6424
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
+ }
6425
6627
  ssrRunner?.invalidateFile(file);
6426
6628
  queueClientEnvironmentUpdate(file);
6427
6629
  notifyEnvironmentDrivers(file, "change");
6428
6630
  });
6429
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
+ }
6430
6635
  ssrRunner?.invalidateFile(file);
6431
6636
  queueClientEnvironmentUpdate(file);
6432
6637
  notifyEnvironmentDrivers(file, "add");
6433
6638
  });
6434
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
+ }
6435
6643
  ssrRunner?.invalidateFile(file);
6436
6644
  notifyEnvironmentDrivers(file, "unlink");
6437
6645
  });
@@ -6461,7 +6669,7 @@ async function createServer(inlineConfig = {}) {
6461
6669
  const readyIn = Math.ceil(performance.now() - startTime);
6462
6670
  logger.info(
6463
6671
  `
6464
- ${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.4.3"}`)} ${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")}
6465
6673
  `
6466
6674
  );
6467
6675
  printServerUrls(
@@ -6558,7 +6766,7 @@ async function createServer(inlineConfig = {}) {
6558
6766
  throw error;
6559
6767
  }
6560
6768
  app.use(transformMiddleware(transformContexts.get("client")));
6561
- const publicDir = import_node_path16.default.resolve(config.root, "public");
6769
+ const publicDir = import_node_path17.default.resolve(config.root, "public");
6562
6770
  app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
6563
6771
  app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
6564
6772
  const postMiddlewares = [];
@@ -6584,12 +6792,12 @@ function getNetworkAddress() {
6584
6792
  }
6585
6793
  return "localhost";
6586
6794
  }
6587
- 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;
6588
6796
  var init_server = __esm({
6589
6797
  "src/server/index.ts"() {
6590
6798
  "use strict";
6591
6799
  import_node_http = __toESM(require("http"), 1);
6592
- import_node_path16 = __toESM(require("path"), 1);
6800
+ import_node_path17 = __toESM(require("path"), 1);
6593
6801
  import_node_os = __toESM(require("os"), 1);
6594
6802
  import_connect = __toESM(require("connect"), 1);
6595
6803
  import_sirv = __toESM(require("sirv"), 1);
@@ -6605,6 +6813,7 @@ var init_server = __esm({
6605
6813
  init_builtins();
6606
6814
  init_plugin_api();
6607
6815
  init_env();
6816
+ init_fs_allow();
6608
6817
  }
6609
6818
  });
6610
6819
 
@@ -6641,6 +6850,7 @@ init_build();
6641
6850
  // src/build/electron.ts
6642
6851
  var import_node_path11 = __toESM(require("path"), 1);
6643
6852
  var import_node_fs8 = __toESM(require("fs"), 1);
6853
+ var import_node_module5 = require("module");
6644
6854
  var import_rolldown2 = require("rolldown");
6645
6855
  var import_picocolors5 = __toESM(require("picocolors"), 1);
6646
6856
  init_config();
@@ -6686,7 +6896,7 @@ async function buildElectron(inlineConfig = {}) {
6686
6896
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
6687
6897
  const startTime = performance.now();
6688
6898
  assertElectronVersion(config);
6689
- console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.4.3"}`));
6899
+ console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.4.4"}`));
6690
6900
  console.log(import_picocolors5.default.dim(` root: ${config.root}`));
6691
6901
  console.log(import_picocolors5.default.dim(` mode: ${config.mode}`));
6692
6902
  console.log(import_picocolors5.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -6830,13 +7040,21 @@ function assertElectronVersion(config) {
6830
7040
  }
6831
7041
  function detectInstalledElectron(root) {
6832
7042
  try {
6833
- const pkgPath = import_node_path11.default.resolve(root, "node_modules/electron/package.json");
6834
- 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");
6835
7045
  const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgPath, "utf-8"));
6836
7046
  const major = parseInt(String(pkg.version).split(".")[0], 10);
6837
7047
  return Number.isFinite(major) ? major : null;
6838
7048
  } catch {
6839
- 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
+ }
6840
7058
  }
6841
7059
  }
6842
7060
 
@@ -6844,9 +7062,9 @@ function detectInstalledElectron(root) {
6844
7062
  init_server();
6845
7063
 
6846
7064
  // src/server/electron-dev.ts
6847
- var import_node_path17 = __toESM(require("path"), 1);
6848
- var import_node_fs12 = __toESM(require("fs"), 1);
6849
- 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");
6850
7068
  var import_node_child_process = require("child_process");
6851
7069
  var import_chokidar2 = __toESM(require("chokidar"), 1);
6852
7070
  var import_picocolors10 = __toESM(require("picocolors"), 1);
@@ -6859,7 +7077,7 @@ async function startElectronDev(inlineConfig = {}) {
6859
7077
  const { noSpawn, ...rest } = inlineConfig;
6860
7078
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
6861
7079
  warnElectronVersion(config);
6862
- console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.4.3"}`));
7080
+ console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.4.4"}`));
6863
7081
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
6864
7082
  const server = await createServer2({
6865
7083
  ...rest,
@@ -6869,11 +7087,11 @@ async function startElectronDev(inlineConfig = {}) {
6869
7087
  await server.listen();
6870
7088
  const devUrl = `http://localhost:${server.config.server.port}` + electronRendererDevPath(config.electron.renderer);
6871
7089
  console.log(import_picocolors10.default.dim(` renderer: ${devUrl}`));
6872
- const stageDir = import_node_path17.default.resolve(config.root, ".nasti");
6873
- import_node_fs12.default.mkdirSync(stageDir, { recursive: true });
6874
- 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);
6875
7093
  const preloadEntries = normalizePreload(config.electron.preload, config.root);
6876
- 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));
6877
7095
  const builtPreloadFiles = [];
6878
7096
  const compileAll = async () => {
6879
7097
  await compileNode(config, mainEntry, {
@@ -6883,9 +7101,9 @@ async function startElectronDev(inlineConfig = {}) {
6883
7101
  });
6884
7102
  builtPreloadFiles.length = 0;
6885
7103
  for (const entry of preloadEntries) {
6886
- if (!import_node_fs12.default.existsSync(entry)) continue;
6887
- const base = import_node_path17.default.basename(entry).replace(/\.[^.]+$/, "");
6888
- 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));
6889
7107
  await compileNode(config, entry, {
6890
7108
  outFile: out,
6891
7109
  format: config.electron.preloadFormat,
@@ -6924,7 +7142,7 @@ async function startElectronDev(inlineConfig = {}) {
6924
7142
  };
6925
7143
  spawnElectron();
6926
7144
  if (config.electron.autoRestart) {
6927
- const watchTargets = [mainEntry, ...preloadEntries].filter(import_node_fs12.default.existsSync);
7145
+ const watchTargets = [mainEntry, ...preloadEntries].filter(import_node_fs13.default.existsSync);
6928
7146
  const watcher = import_chokidar2.default.watch(watchTargets, { ignoreInitial: true });
6929
7147
  let restarting = null;
6930
7148
  let pending = false;
@@ -7004,7 +7222,7 @@ async function compileNode(config, entry, opts) {
7004
7222
  platform: "node",
7005
7223
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
7006
7224
  });
7007
- 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 });
7008
7226
  await bundle2.write({
7009
7227
  file: opts.outFile,
7010
7228
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -7017,18 +7235,18 @@ async function compileNode(config, entry, opts) {
7017
7235
  await bundle2.close();
7018
7236
  }
7019
7237
  function electronRendererDevPath(renderer) {
7020
- const normalized = renderer.split(import_node_path17.default.sep).join("/").replace(/^\.?\//, "");
7238
+ const normalized = renderer.split(import_node_path18.default.sep).join("/").replace(/^\.?\//, "");
7021
7239
  return normalized === "index.html" ? "/" : `/${normalized}`;
7022
7240
  }
7023
7241
  function resolveElectronBinary(config) {
7024
- 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)) {
7025
7243
  return config.electron.electronPath;
7026
7244
  }
7027
7245
  try {
7028
- 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"));
7029
7247
  const pathFile = require2.resolve("electron");
7030
7248
  const electronModule = require2(pathFile);
7031
- if (typeof electronModule === "string" && import_node_fs12.default.existsSync(electronModule)) {
7249
+ if (typeof electronModule === "string" && import_node_fs13.default.existsSync(electronModule)) {
7032
7250
  return electronModule;
7033
7251
  }
7034
7252
  } catch {
@@ -7055,10 +7273,10 @@ function warnElectronVersion(config) {
7055
7273
  }
7056
7274
 
7057
7275
  // src/plugins/monaco-editor.ts
7058
- var import_node_path18 = __toESM(require("path"), 1);
7059
- 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);
7060
7278
  var import_node_crypto4 = __toESM(require("crypto"), 1);
7061
- var import_node_module8 = require("module");
7279
+ var import_node_module9 = require("module");
7062
7280
  var DEFAULT_WORKERS = {
7063
7281
  editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
7064
7282
  css: "monaco-editor/esm/vs/language/css/css.worker",
@@ -7077,9 +7295,9 @@ function normalizePublicPath(p) {
7077
7295
  }
7078
7296
  function readMonacoVersion(root) {
7079
7297
  try {
7080
- 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"));
7081
7299
  const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
7082
- 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"));
7083
7301
  return typeof pkg.version === "string" ? pkg.version : "unknown";
7084
7302
  } catch {
7085
7303
  return "unknown";
@@ -7099,20 +7317,20 @@ function monacoEditorPlugin(options = {}) {
7099
7317
  let cacheDir = "";
7100
7318
  const building = /* @__PURE__ */ new Map();
7101
7319
  async function buildWorker(worker) {
7102
- const cacheFile = import_node_path18.default.join(cacheDir, `${worker.label}.worker.js`);
7103
- 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;
7104
7322
  const existing = building.get(worker.label);
7105
7323
  if (existing) return existing;
7106
7324
  const task = (async () => {
7107
7325
  const { rolldown: rolldown4 } = await import("rolldown");
7108
- 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"));
7109
7327
  let entry;
7110
7328
  try {
7111
7329
  entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
7112
7330
  } catch {
7113
7331
  entry = require2.resolve(worker.entry + ".js", { paths: [resolvedConfig.root] });
7114
7332
  }
7115
- import_node_fs13.default.mkdirSync(cacheDir, { recursive: true });
7333
+ import_node_fs14.default.mkdirSync(cacheDir, { recursive: true });
7116
7334
  const bundle2 = await rolldown4({
7117
7335
  input: entry,
7118
7336
  platform: "browser"
@@ -7172,16 +7390,23 @@ function monacoEditorPlugin(options = {}) {
7172
7390
  resolvedConfig = config;
7173
7391
  const version = readMonacoVersion(config.root);
7174
7392
  const key = import_node_crypto4.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
7175
- 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);
7176
7394
  },
7177
7395
  async configureServer(server) {
7178
7396
  const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
7179
7397
  const watcher = server.watcher;
7180
- 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]);
7181
7400
  try {
7182
- watcher?.unwatch?.(monacoDir);
7401
+ monacoPaths.add(import_node_fs14.default.realpathSync(monacoLogical));
7183
7402
  } catch {
7184
7403
  }
7404
+ for (const monacoDir of monacoPaths) {
7405
+ try {
7406
+ watcher?.unwatch?.(monacoDir);
7407
+ } catch {
7408
+ }
7409
+ }
7185
7410
  if (!shouldBuild) return;
7186
7411
  void Promise.all(
7187
7412
  workers.map(
@@ -7207,7 +7432,7 @@ function monacoEditorPlugin(options = {}) {
7207
7432
  const file = await buildWorker(worker);
7208
7433
  res.setHeader("Content-Type", "application/javascript; charset=utf-8");
7209
7434
  res.setHeader("Cache-Control", "public, max-age=604800, immutable");
7210
- import_node_fs13.default.createReadStream(file).pipe(res);
7435
+ import_node_fs14.default.createReadStream(file).pipe(res);
7211
7436
  } catch (e) {
7212
7437
  res.statusCode = 500;
7213
7438
  res.end(`Monaco worker build failed: ${e.message}`);
@@ -7242,16 +7467,16 @@ self.monaco = monaco;`,
7242
7467
  resolvedConfig.root,
7243
7468
  resolvedConfig.build.outDir,
7244
7469
  resolvedConfig.base
7245
- ) : 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(
7246
7471
  resolvedConfig.root,
7247
7472
  resolvedConfig.build.outDir,
7248
7473
  publicPath.replace(/^\//, "")
7249
7474
  );
7250
- import_node_fs13.default.mkdirSync(outDir, { recursive: true });
7475
+ import_node_fs14.default.mkdirSync(outDir, { recursive: true });
7251
7476
  for (const worker of workers) {
7252
7477
  try {
7253
7478
  const cacheFile = await buildWorker(worker);
7254
- 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`));
7255
7480
  } catch (e) {
7256
7481
  throw new Error(
7257
7482
  `[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}