@nasti-toolchain/nasti 1.6.3 → 1.6.5

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
@@ -57,7 +57,8 @@ var init_defaults = __esm({
57
57
  sourcemap: false,
58
58
  target: "es2022",
59
59
  rolldownOptions: {},
60
- emptyOutDir: true
60
+ emptyOutDir: true,
61
+ css: {}
61
62
  };
62
63
  defaultElectron = {
63
64
  main: "src/electron/main.ts",
@@ -301,20 +302,29 @@ var init_config = __esm({
301
302
  function resolvePlugin(config) {
302
303
  const { alias, extensions } = config.resolve;
303
304
  const require2 = (0, import_node_module.createRequire)(import_node_path2.default.resolve(config.root, "package.json"));
305
+ const aliasEntries = Object.entries(alias).sort(
306
+ ([a], [b]) => b.length - a.length
307
+ );
304
308
  return {
305
309
  name: "nasti:resolve",
306
310
  enforce: "pre",
307
311
  resolveId(source, importer) {
308
- for (const [key, value] of Object.entries(alias)) {
312
+ for (const [key, value] of aliasEntries) {
309
313
  if (source === key || source.startsWith(key + "/")) {
310
- source = source.replace(key, value);
311
- if (!import_node_path2.default.isAbsolute(source)) {
312
- source = import_node_path2.default.resolve(config.root, source);
313
- }
314
+ const aliasBase = resolveAliasTarget(value, config.root);
315
+ const sub = source.slice(key.length).replace(/^\//, "");
316
+ const target = sub ? import_node_path2.default.join(aliasBase, sub) : aliasBase;
317
+ const resolved = tryResolveFile(target, extensions);
318
+ if (resolved) return resolved;
314
319
  break;
315
320
  }
316
321
  }
317
- if (import_node_path2.default.isAbsolute(source)) {
322
+ if (source.startsWith("/") && !source.startsWith("//")) {
323
+ const rootRelative = import_node_path2.default.join(config.root, source.slice(1));
324
+ const resolved = tryResolveFile(rootRelative, extensions);
325
+ if (resolved) return resolved;
326
+ }
327
+ if (import_node_path2.default.isAbsolute(source) && import_node_fs2.default.existsSync(source)) {
318
328
  const resolved = tryResolveFile(source, extensions);
319
329
  if (resolved) return resolved;
320
330
  }
@@ -337,6 +347,7 @@ function resolvePlugin(config) {
337
347
  return null;
338
348
  },
339
349
  load(id) {
350
+ if (id.startsWith("\0")) return null;
340
351
  if (!import_node_fs2.default.existsSync(id)) return null;
341
352
  if (id.endsWith(".json")) {
342
353
  const content = import_node_fs2.default.readFileSync(id, "utf-8");
@@ -346,6 +357,11 @@ function resolvePlugin(config) {
346
357
  }
347
358
  };
348
359
  }
360
+ function resolveAliasTarget(value, root) {
361
+ if (import_node_path2.default.isAbsolute(value) && import_node_fs2.default.existsSync(value)) return value;
362
+ if (value.startsWith("/")) return import_node_path2.default.join(root, value.slice(1));
363
+ return import_node_path2.default.resolve(root, value);
364
+ }
349
365
  function tryResolveFile(file, extensions) {
350
366
  if (import_node_fs2.default.existsSync(file) && import_node_fs2.default.statSync(file).isFile()) {
351
367
  return file;
@@ -376,6 +392,59 @@ var init_resolve = __esm({
376
392
  }
377
393
  });
378
394
 
395
+ // src/plugins/tailwind.ts
396
+ function hasTailwindDirectives(css) {
397
+ const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
398
+ const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
399
+ return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
400
+ }
401
+ async function loadTailwind(projectRoot) {
402
+ if (cached && cachedRoot === projectRoot) return cached;
403
+ const req = (0, import_node_module2.createRequire)(import_node_path3.default.join(projectRoot, "package.json"));
404
+ let nodePath;
405
+ let oxidePath;
406
+ try {
407
+ nodePath = req.resolve("@tailwindcss/node");
408
+ oxidePath = req.resolve("@tailwindcss/oxide");
409
+ } catch {
410
+ throw new Error(
411
+ "[nasti] CSS contains Tailwind v4 directives but `@tailwindcss/node` and/or `@tailwindcss/oxide` are not installed in this project. Install them with: npm i -D tailwindcss @tailwindcss/node @tailwindcss/oxide"
412
+ );
413
+ }
414
+ const node = await import((0, import_node_url2.pathToFileURL)(nodePath).href);
415
+ const oxide = await import((0, import_node_url2.pathToFileURL)(oxidePath).href);
416
+ cached = { node, oxide };
417
+ cachedRoot = projectRoot;
418
+ return cached;
419
+ }
420
+ async function compileTailwind(css, fromFile, projectRoot) {
421
+ const { node, oxide } = await loadTailwind(projectRoot);
422
+ const dependencies = [];
423
+ const compiler = await node.compile(css, {
424
+ base: import_node_path3.default.dirname(fromFile),
425
+ from: fromFile,
426
+ onDependency: (p) => dependencies.push(p)
427
+ });
428
+ const scanner = new oxide.Scanner({ sources: compiler.sources });
429
+ const candidates = scanner.scan();
430
+ return {
431
+ css: compiler.build(candidates),
432
+ dependencies: [...dependencies, ...scanner.files]
433
+ };
434
+ }
435
+ var import_node_path3, import_node_module2, import_node_url2, TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
436
+ var init_tailwind = __esm({
437
+ "src/plugins/tailwind.ts"() {
438
+ "use strict";
439
+ import_node_path3 = __toESM(require("path"), 1);
440
+ import_node_module2 = require("module");
441
+ import_node_url2 = require("url");
442
+ TAILWIND_DIRECTIVE_RE = /@(?:import\s+["']tailwindcss(?:\b|\/)|tailwind\b|theme\b|apply\b|plugin\b|source\b|utility\b|variant\b|custom-variant\b|reference\b)/;
443
+ cached = null;
444
+ cachedRoot = null;
445
+ }
446
+ });
447
+
379
448
  // src/plugins/css.ts
380
449
  function cssPlugin(config) {
381
450
  return {
@@ -384,11 +453,16 @@ function cssPlugin(config) {
384
453
  if (source.endsWith(".css")) return null;
385
454
  return null;
386
455
  },
387
- transform(code, id) {
456
+ async transform(code, id) {
388
457
  if (!id.endsWith(".css")) return null;
389
- const rewritten = rewriteCssUrls(code, id, config.root);
458
+ let cssSource = code;
459
+ if (hasTailwindDirectives(code)) {
460
+ const compiled = await compileTailwind(code, id, config.root);
461
+ cssSource = compiled.css;
462
+ }
463
+ const rewritten = rewriteCssUrls(cssSource, id, config.root);
464
+ const escaped = JSON.stringify(rewritten);
390
465
  if (config.command === "serve") {
391
- const escaped = JSON.stringify(rewritten);
392
466
  return {
393
467
  code: `
394
468
  const css = ${escaped};
@@ -412,7 +486,42 @@ export default css;
412
486
  `
413
487
  };
414
488
  }
415
- return rewritten !== code ? { code: rewritten } : null;
489
+ const cssConfig = config.build.css || {};
490
+ const nonce = cssConfig.nonce;
491
+ const emitCssFile = cssConfig.emitCssFile;
492
+ if (emitCssFile) {
493
+ const fileName = `assets/${import_node_path4.default.basename(id, ".css")}.css`;
494
+ this.emitFile({
495
+ type: "asset",
496
+ fileName,
497
+ source: rewritten
498
+ });
499
+ return {
500
+ code: `
501
+ const link = document.createElement('link');
502
+ link.rel = 'stylesheet';
503
+ link.href = ${JSON.stringify("/" + fileName)};
504
+ document.head.appendChild(link);
505
+
506
+ export default ${escaped};
507
+ `,
508
+ moduleType: "js"
509
+ };
510
+ }
511
+ const nonceAttr = nonce ? `style.setAttribute('nonce', ${JSON.stringify(nonce)});` : "";
512
+ return {
513
+ code: `
514
+ const css = ${escaped};
515
+ const style = document.createElement('style');
516
+ style.setAttribute('data-nasti-css', ${JSON.stringify(id)});
517
+ ${nonceAttr}
518
+ style.textContent = css;
519
+ document.head.appendChild(style);
520
+
521
+ export default css;
522
+ `,
523
+ moduleType: "js"
524
+ };
416
525
  }
417
526
  };
418
527
  }
@@ -421,16 +530,17 @@ function rewriteCssUrls(css, from, root) {
421
530
  if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
422
531
  return match;
423
532
  }
424
- const resolved = import_node_path3.default.resolve(import_node_path3.default.dirname(from), url);
425
- const relative = "/" + import_node_path3.default.relative(root, resolved);
533
+ const resolved = import_node_path4.default.resolve(import_node_path4.default.dirname(from), url);
534
+ const relative = "/" + import_node_path4.default.relative(root, resolved);
426
535
  return `url(${relative})`;
427
536
  });
428
537
  }
429
- var import_node_path3;
538
+ var import_node_path4;
430
539
  var init_css = __esm({
431
540
  "src/plugins/css.ts"() {
432
541
  "use strict";
433
- import_node_path3 = __toESM(require("path"), 1);
542
+ import_node_path4 = __toESM(require("path"), 1);
543
+ init_tailwind();
434
544
  }
435
545
  });
436
546
 
@@ -445,7 +555,7 @@ function assetsPlugin(config) {
445
555
  return null;
446
556
  },
447
557
  load(id) {
448
- const ext = import_node_path4.default.extname(id.replace(/\?.*$/, ""));
558
+ const ext = import_node_path5.default.extname(id.replace(/\?.*$/, ""));
449
559
  if (id.endsWith("?raw")) {
450
560
  const file = id.slice(0, -4);
451
561
  if (import_node_fs3.default.existsSync(file)) {
@@ -457,12 +567,12 @@ function assetsPlugin(config) {
457
567
  const file = id.replace(/\?.*$/, "");
458
568
  if (!import_node_fs3.default.existsSync(file)) return null;
459
569
  if (config.command === "serve") {
460
- const url = "/" + import_node_path4.default.relative(config.root, file);
570
+ const url = "/" + import_node_path5.default.relative(config.root, file);
461
571
  return `export default ${JSON.stringify(url)}`;
462
572
  }
463
573
  const content = import_node_fs3.default.readFileSync(file);
464
574
  const hash = import_node_crypto.default.createHash("sha256").update(content).digest("hex").slice(0, 8);
465
- const basename = import_node_path4.default.basename(file, ext);
575
+ const basename = import_node_path5.default.basename(file, ext);
466
576
  const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
467
577
  return `export default ${JSON.stringify(config.base + hashedName)}`;
468
578
  }
@@ -470,11 +580,11 @@ function assetsPlugin(config) {
470
580
  }
471
581
  };
472
582
  }
473
- var import_node_path4, import_node_fs3, import_node_crypto, ASSET_EXTENSIONS;
583
+ var import_node_path5, import_node_fs3, import_node_crypto, ASSET_EXTENSIONS;
474
584
  var init_assets = __esm({
475
585
  "src/plugins/assets.ts"() {
476
586
  "use strict";
477
- import_node_path4 = __toESM(require("path"), 1);
587
+ import_node_path5 = __toESM(require("path"), 1);
478
588
  import_node_fs3 = __toESM(require("fs"), 1);
479
589
  import_node_crypto = __toESM(require("crypto"), 1);
480
590
  ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
@@ -567,15 +677,15 @@ function serializeTag(tag) {
567
677
  return ` <${tag.tag}${attrs}>${children}</${tag.tag}>`;
568
678
  }
569
679
  async function readHtmlFile(root) {
570
- const htmlPath = import_node_path5.default.resolve(root, "index.html");
680
+ const htmlPath = import_node_path6.default.resolve(root, "index.html");
571
681
  if (!import_node_fs4.default.existsSync(htmlPath)) return null;
572
682
  return import_node_fs4.default.readFileSync(htmlPath, "utf-8");
573
683
  }
574
- var import_node_path5, import_node_fs4, REACT_REFRESH_HTML_PREAMBLE;
684
+ var import_node_path6, import_node_fs4, REACT_REFRESH_HTML_PREAMBLE;
575
685
  var init_html = __esm({
576
686
  "src/plugins/html.ts"() {
577
687
  "use strict";
578
- import_node_path5 = __toESM(require("path"), 1);
688
+ import_node_path6 = __toESM(require("path"), 1);
579
689
  import_node_fs4 = __toESM(require("fs"), 1);
580
690
  REACT_REFRESH_HTML_PREAMBLE = `
581
691
  import RefreshRuntime from "/@react-refresh";
@@ -634,7 +744,7 @@ function loadEnv(mode, root, prefixes) {
634
744
  ];
635
745
  const raw = {};
636
746
  for (const file of envFiles) {
637
- const filePath = import_node_path6.default.resolve(root, file);
747
+ const filePath = import_node_path7.default.resolve(root, file);
638
748
  if (!import_node_fs5.default.existsSync(filePath)) continue;
639
749
  const content = import_node_fs5.default.readFileSync(filePath, "utf-8");
640
750
  for (const line of content.split("\n")) {
@@ -677,11 +787,11 @@ function replaceEnvInCode(code, define) {
677
787
  }
678
788
  return result;
679
789
  }
680
- var import_node_path6, import_node_fs5;
790
+ var import_node_path7, import_node_fs5;
681
791
  var init_env = __esm({
682
792
  "src/core/env.ts"() {
683
793
  "use strict";
684
- import_node_path6 = __toESM(require("path"), 1);
794
+ import_node_path7 = __toESM(require("path"), 1);
685
795
  import_node_fs5 = __toESM(require("fs"), 1);
686
796
  }
687
797
  });
@@ -814,10 +924,10 @@ __export(build_exports, {
814
924
  async function build(inlineConfig = {}) {
815
925
  const config = await resolveConfig(inlineConfig, "build");
816
926
  const startTime = performance.now();
817
- console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.3"}`));
927
+ console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.5"}`));
818
928
  console.log(import_picocolors.default.dim(` root: ${config.root}`));
819
929
  console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
820
- const outDir = import_node_path7.default.resolve(config.root, config.build.outDir);
930
+ const outDir = import_node_path8.default.resolve(config.root, config.build.outDir);
821
931
  if (config.build.emptyOutDir && import_node_fs6.default.existsSync(outDir)) {
822
932
  import_node_fs6.default.rmSync(outDir, { recursive: true, force: true });
823
933
  }
@@ -829,14 +939,14 @@ async function build(inlineConfig = {}) {
829
939
  for (const match of scriptMatches) {
830
940
  const src = match[1];
831
941
  if (src && !src.startsWith("http")) {
832
- entryPoints.push(import_node_path7.default.resolve(config.root, src.replace(/^\//, "")));
942
+ entryPoints.push(import_node_path8.default.resolve(config.root, src.replace(/^\//, "")));
833
943
  }
834
944
  }
835
945
  }
836
946
  if (entryPoints.length === 0) {
837
947
  const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
838
948
  for (const entry of fallbackEntries) {
839
- const fullPath = import_node_path7.default.resolve(config.root, entry);
949
+ const fullPath = import_node_path8.default.resolve(config.root, entry);
840
950
  if (import_node_fs6.default.existsSync(fullPath)) {
841
951
  entryPoints.push(fullPath);
842
952
  break;
@@ -868,9 +978,11 @@ async function build(inlineConfig = {}) {
868
978
  };
869
979
  const env = loadEnv(config.mode, config.root, config.envPrefix);
870
980
  const envDefine = buildEnvDefine(env, config.mode);
981
+ const existingTransform = config.build.rolldownOptions?.transform;
982
+ const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
871
983
  const bundle = await (0, import_rolldown.rolldown)({
872
984
  input: entryPoints,
873
- define: envDefine,
985
+ transform: { ...existingTransform, define: mergedDefine },
874
986
  plugins: [
875
987
  oxcTransformPlugin,
876
988
  // 转换 Nasti 插件为 Rolldown 插件格式
@@ -901,8 +1013,8 @@ async function build(inlineConfig = {}) {
901
1013
  await bundle.close();
902
1014
  await pluginContainer.buildEnd();
903
1015
  for (const ef of pluginContainer.getEmittedFiles()) {
904
- const dest = import_node_path7.default.resolve(outDir, ef.fileName);
905
- import_node_fs6.default.mkdirSync(import_node_path7.default.dirname(dest), { recursive: true });
1016
+ const dest = import_node_path8.default.resolve(outDir, ef.fileName);
1017
+ import_node_fs6.default.mkdirSync(import_node_path8.default.dirname(dest), { recursive: true });
906
1018
  import_node_fs6.default.writeFileSync(dest, ef.source);
907
1019
  }
908
1020
  if (html) {
@@ -920,14 +1032,14 @@ async function build(inlineConfig = {}) {
920
1032
  }
921
1033
  for (const chunk of output) {
922
1034
  if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
923
- const originalEntry = import_node_path7.default.relative(config.root, chunk.facadeModuleId);
1035
+ const originalEntry = import_node_path8.default.relative(config.root, chunk.facadeModuleId);
924
1036
  processedHtml = processedHtml.replace(
925
1037
  new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
926
1038
  `$1${config.base}${chunk.fileName}$3`
927
1039
  );
928
1040
  }
929
1041
  }
930
- import_node_fs6.default.writeFileSync(import_node_path7.default.resolve(outDir, "index.html"), processedHtml);
1042
+ import_node_fs6.default.writeFileSync(import_node_path8.default.resolve(outDir, "index.html"), processedHtml);
931
1043
  }
932
1044
  const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
933
1045
  const totalSize = output.reduce((sum, chunk) => {
@@ -949,11 +1061,11 @@ function formatSize(bytes) {
949
1061
  function escapeRegExp(string) {
950
1062
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
951
1063
  }
952
- var import_node_path7, import_node_fs6, import_rolldown, import_picocolors;
1064
+ var import_node_path8, import_node_fs6, import_rolldown, import_picocolors;
953
1065
  var init_build = __esm({
954
1066
  "src/build/index.ts"() {
955
1067
  "use strict";
956
- import_node_path7 = __toESM(require("path"), 1);
1068
+ import_node_path8 = __toESM(require("path"), 1);
957
1069
  import_node_fs6 = __toESM(require("fs"), 1);
958
1070
  import_rolldown = require("rolldown");
959
1071
  init_config();
@@ -1150,9 +1262,9 @@ function getReactRefreshRuntimeEsm() {
1150
1262
  let cjsPath;
1151
1263
  try {
1152
1264
  const pkgPath = __require.resolve("react-refresh/package.json");
1153
- cjsPath = import_node_path9.default.join(import_node_path9.default.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
1265
+ cjsPath = import_node_path10.default.join(import_node_path10.default.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
1154
1266
  } catch (err) {
1155
- cjsPath = import_node_path9.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
1267
+ cjsPath = import_node_path10.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
1156
1268
  if (!import_node_fs8.default.existsSync(cjsPath)) {
1157
1269
  const origMsg = err instanceof Error ? err.message : String(err);
1158
1270
  throw new Error(
@@ -1292,9 +1404,9 @@ function transformMiddleware(ctx) {
1292
1404
  async function transformRequest(url, ctx) {
1293
1405
  const { config, pluginContainer, moduleGraph } = ctx;
1294
1406
  const cleanReqUrl = url.split("?")[0];
1295
- const cached = moduleGraph.getModuleByUrl(url);
1296
- if (cached?.transformResult) {
1297
- return cached.transformResult;
1407
+ const cached2 = moduleGraph.getModuleByUrl(url);
1408
+ if (cached2?.transformResult) {
1409
+ return cached2.transformResult;
1298
1410
  }
1299
1411
  if (cleanReqUrl === "/@react-refresh") {
1300
1412
  return { code: getReactRefreshRuntimeEsm() };
@@ -1373,7 +1485,7 @@ async function loadVirtualModule(spec, ctx) {
1373
1485
  loadEnv(config.mode, config.root, config.envPrefix),
1374
1486
  config.mode
1375
1487
  ));
1376
- const anchor = import_node_path9.default.join(config.root, "__nasti_virtual__.ts");
1488
+ const anchor = import_node_path10.default.join(config.root, "__nasti_virtual__.ts");
1377
1489
  code = rewriteImports(code, config, anchor);
1378
1490
  return { id: resolvedId, result: { code } };
1379
1491
  }
@@ -1416,13 +1528,13 @@ async function doBundlePackage(entryFile) {
1416
1528
  return code;
1417
1529
  }
1418
1530
  async function tryGenerateSubpathShim(entryFile) {
1419
- const NM = `${import_node_path9.default.sep}node_modules${import_node_path9.default.sep}`;
1531
+ const NM = `${import_node_path10.default.sep}node_modules${import_node_path10.default.sep}`;
1420
1532
  if (!entryFile.includes(NM)) return null;
1421
1533
  let pkgDir = null;
1422
1534
  let pkgName = null;
1423
- let dir = import_node_path9.default.dirname(entryFile);
1535
+ let dir = import_node_path10.default.dirname(entryFile);
1424
1536
  while (true) {
1425
- const pkgJsonPath = import_node_path9.default.join(dir, "package.json");
1537
+ const pkgJsonPath = import_node_path10.default.join(dir, "package.json");
1426
1538
  if (import_node_fs8.default.existsSync(pkgJsonPath)) {
1427
1539
  try {
1428
1540
  const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgJsonPath, "utf-8"));
@@ -1434,21 +1546,21 @@ async function tryGenerateSubpathShim(entryFile) {
1434
1546
  } catch {
1435
1547
  }
1436
1548
  }
1437
- const parent = import_node_path9.default.dirname(dir);
1549
+ const parent = import_node_path10.default.dirname(dir);
1438
1550
  if (parent === dir) return null;
1439
1551
  dir = parent;
1440
1552
  if (!dir.includes(NM)) return null;
1441
1553
  }
1442
1554
  if (!pkgDir || !pkgName) return null;
1443
- const entryExt = import_node_path9.default.extname(entryFile);
1555
+ const entryExt = import_node_path10.default.extname(entryFile);
1444
1556
  const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
1445
1557
  if (!mainEntry) return null;
1446
- if (import_node_path9.default.resolve(mainEntry) === import_node_path9.default.resolve(entryFile)) return null;
1558
+ if (import_node_path10.default.resolve(mainEntry) === import_node_path10.default.resolve(entryFile)) return null;
1447
1559
  let mainNs;
1448
1560
  let subNs;
1449
1561
  try {
1450
- mainNs = await import((0, import_node_url2.pathToFileURL)(mainEntry).href);
1451
- subNs = await import((0, import_node_url2.pathToFileURL)(entryFile).href);
1562
+ mainNs = await import((0, import_node_url3.pathToFileURL)(mainEntry).href);
1563
+ subNs = await import((0, import_node_url3.pathToFileURL)(entryFile).href);
1452
1564
  } catch {
1453
1565
  return null;
1454
1566
  }
@@ -1479,7 +1591,7 @@ async function tryGenerateSubpathShim(entryFile) {
1479
1591
  return lines.join("\n") + "\n";
1480
1592
  }
1481
1593
  function pickMainEntryByExtension(pkgDir, preferredExt) {
1482
- const pkgJsonPath = import_node_path9.default.join(pkgDir, "package.json");
1594
+ const pkgJsonPath = import_node_path10.default.join(pkgDir, "package.json");
1483
1595
  let pkg;
1484
1596
  try {
1485
1597
  pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgJsonPath, "utf-8"));
@@ -1501,13 +1613,13 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
1501
1613
  if (typeof pkg.module === "string") candidates.push(pkg.module);
1502
1614
  if (typeof pkg.main === "string") candidates.push(pkg.main);
1503
1615
  for (const cand of candidates) {
1504
- if (import_node_path9.default.extname(cand) === preferredExt) {
1505
- const full = import_node_path9.default.resolve(pkgDir, cand);
1616
+ if (import_node_path10.default.extname(cand) === preferredExt) {
1617
+ const full = import_node_path10.default.resolve(pkgDir, cand);
1506
1618
  if (import_node_fs8.default.existsSync(full)) return full;
1507
1619
  }
1508
1620
  }
1509
1621
  for (const cand of candidates) {
1510
- const full = import_node_path9.default.resolve(pkgDir, cand);
1622
+ const full = import_node_path10.default.resolve(pkgDir, cand);
1511
1623
  if (import_node_fs8.default.existsSync(full)) return full;
1512
1624
  }
1513
1625
  return null;
@@ -1533,19 +1645,20 @@ function rewriteExternalRequires(code) {
1533
1645
  }
1534
1646
  async function injectCjsNamedExports(code, entryFile) {
1535
1647
  try {
1536
- const { createRequire: createRequire5 } = await import("module");
1537
- const req = createRequire5(entryFile);
1648
+ const { createRequire: createRequire6 } = await import("module");
1649
+ const req = createRequire6(entryFile);
1538
1650
  const cjsExports = req(entryFile);
1539
1651
  if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
1540
1652
  const namedKeys = Object.keys(cjsExports).filter(
1541
1653
  (k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
1542
1654
  );
1543
- if (namedKeys.length === 0) return code;
1655
+ const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
1656
+ if (!hasEsmInterop && namedKeys.length === 0) return code;
1544
1657
  return code.replace(
1545
1658
  /^export default (\w+\(\));?\s*$/m,
1546
1659
  (_, call) => [
1547
1660
  `const __cjsMod = ${call};`,
1548
- `export default __cjsMod;`,
1661
+ hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
1549
1662
  ...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
1550
1663
  ].join("\n")
1551
1664
  );
@@ -1555,31 +1668,31 @@ async function injectCjsNamedExports(code, entryFile) {
1555
1668
  }
1556
1669
  function rewriteImports(code, config, filePath) {
1557
1670
  const root = config.root;
1558
- const fileDir = import_node_path9.default.dirname(filePath);
1671
+ const fileDir = import_node_path10.default.dirname(filePath);
1559
1672
  const aliasEntries = Object.entries(config.resolve.alias).sort(
1560
1673
  ([a], [b]) => b.length - a.length
1561
1674
  );
1562
- const toRootUrl = (abs) => "/" + import_node_path9.default.relative(root, abs).replace(/\\/g, "/");
1675
+ const toRootUrl = (abs) => "/" + import_node_path10.default.relative(root, abs).replace(/\\/g, "/");
1563
1676
  const transformSpec = (spec) => {
1564
1677
  const suffixMatch = spec.match(/[?#].*$/);
1565
1678
  const suffix = suffixMatch ? suffixMatch[0] : "";
1566
1679
  const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
1567
1680
  for (const [key, value] of aliasEntries) {
1568
1681
  if (baseSpec === key || baseSpec.startsWith(key + "/")) {
1569
- const aliasBase = resolveAliasTarget(value, root);
1682
+ const aliasBase = resolveAliasTarget2(value, root);
1570
1683
  const sub = baseSpec.slice(key.length).replace(/^\//, "");
1571
- const target = sub ? import_node_path9.default.join(aliasBase, sub) : aliasBase;
1684
+ const target = sub ? import_node_path10.default.join(aliasBase, sub) : aliasBase;
1572
1685
  const resolved = tryResolveDiskPath(target);
1573
1686
  return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1574
1687
  }
1575
1688
  }
1576
1689
  if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
1577
- const target = import_node_path9.default.resolve(fileDir, baseSpec);
1690
+ const target = import_node_path10.default.resolve(fileDir, baseSpec);
1578
1691
  const resolved = tryResolveDiskPath(target);
1579
1692
  return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1580
1693
  }
1581
1694
  if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
1582
- const target = import_node_path9.default.join(root, baseSpec.replace(/^\//, ""));
1695
+ const target = import_node_path10.default.join(root, baseSpec.replace(/^\//, ""));
1583
1696
  const resolved = tryResolveDiskPath(target);
1584
1697
  return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1585
1698
  }
@@ -1597,10 +1710,10 @@ function rewriteImports(code, config, filePath) {
1597
1710
  (_m, q, s) => `import(${q}${transformSpec(s)}${q})`
1598
1711
  );
1599
1712
  }
1600
- function resolveAliasTarget(value, root) {
1601
- if (import_node_path9.default.isAbsolute(value) && import_node_fs8.default.existsSync(value)) return value;
1602
- if (value.startsWith("/")) return import_node_path9.default.join(root, value.slice(1));
1603
- return import_node_path9.default.resolve(root, value);
1713
+ function resolveAliasTarget2(value, root) {
1714
+ if (import_node_path10.default.isAbsolute(value) && import_node_fs8.default.existsSync(value)) return value;
1715
+ if (value.startsWith("/")) return import_node_path10.default.join(root, value.slice(1));
1716
+ return import_node_path10.default.resolve(root, value);
1604
1717
  }
1605
1718
  function tryResolveDiskPath(target) {
1606
1719
  if (import_node_fs8.default.existsSync(target) && import_node_fs8.default.statSync(target).isFile()) return target;
@@ -1610,15 +1723,15 @@ function tryResolveDiskPath(target) {
1610
1723
  }
1611
1724
  if (import_node_fs8.default.existsSync(target) && import_node_fs8.default.statSync(target).isDirectory()) {
1612
1725
  for (const ext of RESOLVE_EXTENSIONS) {
1613
- const idx = import_node_path9.default.join(target, "index" + ext);
1726
+ const idx = import_node_path10.default.join(target, "index" + ext);
1614
1727
  if (import_node_fs8.default.existsSync(idx) && import_node_fs8.default.statSync(idx).isFile()) return idx;
1615
1728
  }
1616
1729
  }
1617
1730
  return null;
1618
1731
  }
1619
1732
  function isUnderRoot(abs, root) {
1620
- const rel = import_node_path9.default.relative(root, abs);
1621
- return !!rel && !rel.startsWith("..") && !import_node_path9.default.isAbsolute(rel);
1733
+ const rel = import_node_path10.default.relative(root, abs);
1734
+ return !!rel && !rel.startsWith("..") && !import_node_path10.default.isAbsolute(rel);
1622
1735
  }
1623
1736
  function resolveNodeModule(root, moduleName) {
1624
1737
  let pkgName;
@@ -1635,17 +1748,17 @@ function resolveNodeModule(root, moduleName) {
1635
1748
  let pkgDir = null;
1636
1749
  let dir = root;
1637
1750
  for (; ; ) {
1638
- const candidate = import_node_path9.default.join(dir, "node_modules", pkgName);
1751
+ const candidate = import_node_path10.default.join(dir, "node_modules", pkgName);
1639
1752
  if (import_node_fs8.default.existsSync(candidate)) {
1640
1753
  pkgDir = candidate;
1641
1754
  break;
1642
1755
  }
1643
- const parent = import_node_path9.default.dirname(dir);
1756
+ const parent = import_node_path10.default.dirname(dir);
1644
1757
  if (parent === dir) break;
1645
1758
  dir = parent;
1646
1759
  }
1647
1760
  if (!pkgDir) return null;
1648
- const pkgJsonPath = import_node_path9.default.join(pkgDir, "package.json");
1761
+ const pkgJsonPath = import_node_path10.default.join(pkgDir, "package.json");
1649
1762
  if (!import_node_fs8.default.existsSync(pkgJsonPath)) return null;
1650
1763
  let pkg;
1651
1764
  try {
@@ -1662,12 +1775,12 @@ function resolveNodeModule(root, moduleName) {
1662
1775
  const subDirs = [""];
1663
1776
  for (const field of ["module", "main"]) {
1664
1777
  if (typeof pkg[field] === "string") {
1665
- const dir2 = import_node_path9.default.dirname(pkg[field]);
1778
+ const dir2 = import_node_path10.default.dirname(pkg[field]);
1666
1779
  if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
1667
1780
  }
1668
1781
  }
1669
1782
  for (const dir2 of subDirs) {
1670
- const direct = import_node_path9.default.join(pkgDir, dir2, subpath);
1783
+ const direct = import_node_path10.default.join(pkgDir, dir2, subpath);
1671
1784
  if (import_node_fs8.default.existsSync(direct) && import_node_fs8.default.statSync(direct).isFile()) return direct;
1672
1785
  for (const ext of RESOLVE_EXTENSIONS) {
1673
1786
  if (import_node_fs8.default.existsSync(direct + ext)) return direct + ext;
@@ -1677,24 +1790,24 @@ function resolveNodeModule(root, moduleName) {
1677
1790
  }
1678
1791
  for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
1679
1792
  if (typeof pkg[field] === "string") {
1680
- const entry = import_node_path9.default.join(pkgDir, pkg[field]);
1793
+ const entry = import_node_path10.default.join(pkgDir, pkg[field]);
1681
1794
  if (import_node_fs8.default.existsSync(entry)) return entry;
1682
1795
  }
1683
1796
  }
1684
- const indexFallback = import_node_path9.default.join(pkgDir, "index.js");
1797
+ const indexFallback = import_node_path10.default.join(pkgDir, "index.js");
1685
1798
  if (import_node_fs8.default.existsSync(indexFallback)) return indexFallback;
1686
1799
  return null;
1687
1800
  }
1688
1801
  function resolvePackageExports(exports2, key, pkgDir) {
1689
1802
  if (typeof exports2 === "string") {
1690
- return key === "." ? import_node_path9.default.join(pkgDir, exports2) : null;
1803
+ return key === "." ? import_node_path10.default.join(pkgDir, exports2) : null;
1691
1804
  }
1692
1805
  const entry = exports2[key];
1693
1806
  if (entry === void 0) return null;
1694
1807
  return resolveExportValue(entry, pkgDir);
1695
1808
  }
1696
1809
  function resolveExportValue(value, pkgDir) {
1697
- if (typeof value === "string") return import_node_path9.default.join(pkgDir, value);
1810
+ if (typeof value === "string") return import_node_path10.default.join(pkgDir, value);
1698
1811
  if (Array.isArray(value)) {
1699
1812
  for (const item of value) {
1700
1813
  const r = resolveExportValue(item, pkgDir);
@@ -1718,7 +1831,7 @@ function resolveUrlToFile(url, root) {
1718
1831
  const moduleName = cleanUrl.slice("/@modules/".length);
1719
1832
  return resolveNodeModule(root, moduleName);
1720
1833
  }
1721
- const filePath = import_node_path9.default.resolve(root, cleanUrl.replace(/^\//, ""));
1834
+ const filePath = import_node_path10.default.resolve(root, cleanUrl.replace(/^\//, ""));
1722
1835
  if (import_node_fs8.default.existsSync(filePath) && import_node_fs8.default.statSync(filePath).isFile()) {
1723
1836
  return filePath;
1724
1837
  }
@@ -1727,7 +1840,7 @@ function resolveUrlToFile(url, root) {
1727
1840
  if (import_node_fs8.default.existsSync(withExt)) return withExt;
1728
1841
  }
1729
1842
  for (const ext of RESOLVE_EXTENSIONS) {
1730
- const indexFile = import_node_path9.default.join(filePath, "index" + ext);
1843
+ const indexFile = import_node_path10.default.join(filePath, "index" + ext);
1731
1844
  if (import_node_fs8.default.existsSync(indexFile)) return indexFile;
1732
1845
  }
1733
1846
  return null;
@@ -1736,7 +1849,7 @@ function isModuleRequest(url) {
1736
1849
  const cleanUrl = url.split("?")[0];
1737
1850
  if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
1738
1851
  if (cleanUrl.startsWith("/@modules/")) return true;
1739
- if (!import_node_path9.default.extname(cleanUrl)) return true;
1852
+ if (!import_node_path10.default.extname(cleanUrl)) return true;
1740
1853
  return false;
1741
1854
  }
1742
1855
  function getHmrClientCode() {
@@ -1867,20 +1980,20 @@ export function createHotContext(ownerPath) {
1867
1980
  }
1868
1981
  `;
1869
1982
  }
1870
- var import_node_path9, import_node_fs8, import_node_module3, import_node_url2, import_meta, __dirname_esm, __require, __refreshRuntimeCache, REACT_REFRESH_GLOBAL_PREAMBLE, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
1983
+ var import_node_path10, import_node_fs8, import_node_module4, import_node_url3, import_meta, __dirname_esm, __require, __refreshRuntimeCache, REACT_REFRESH_GLOBAL_PREAMBLE, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
1871
1984
  var init_middleware = __esm({
1872
1985
  "src/server/middleware.ts"() {
1873
1986
  "use strict";
1874
- import_node_path9 = __toESM(require("path"), 1);
1987
+ import_node_path10 = __toESM(require("path"), 1);
1875
1988
  import_node_fs8 = __toESM(require("fs"), 1);
1876
- import_node_module3 = require("module");
1877
- import_node_url2 = require("url");
1989
+ import_node_module4 = require("module");
1990
+ import_node_url3 = require("url");
1878
1991
  init_transformer();
1879
1992
  init_html();
1880
1993
  init_env();
1881
1994
  import_meta = {};
1882
- __dirname_esm = import_node_path9.default.dirname((0, import_node_url2.fileURLToPath)(import_meta.url));
1883
- __require = (0, import_node_module3.createRequire)(import_meta.url);
1995
+ __dirname_esm = import_node_path10.default.dirname((0, import_node_url3.fileURLToPath)(import_meta.url));
1996
+ __require = (0, import_node_module4.createRequire)(import_meta.url);
1884
1997
  __refreshRuntimeCache = null;
1885
1998
  REACT_REFRESH_GLOBAL_PREAMBLE = `
1886
1999
  import RefreshRuntime from "/@react-refresh";
@@ -1899,7 +2012,7 @@ window.__vite_plugin_react_preamble_installed__ = true;
1899
2012
  // src/server/hmr.ts
1900
2013
  async function handleFileChange(file, server) {
1901
2014
  const { moduleGraph, ws, config } = server;
1902
- const relativePath = "/" + import_node_path10.default.relative(config.root, file);
2015
+ const relativePath = "/" + import_node_path11.default.relative(config.root, file);
1903
2016
  const mods = moduleGraph.getModulesByFile(file);
1904
2017
  if (!mods || mods.size === 0) {
1905
2018
  return;
@@ -1944,11 +2057,11 @@ async function handleFileChange(file, server) {
1944
2057
  ws.send({ type: "update", updates });
1945
2058
  }
1946
2059
  }
1947
- var import_node_path10, import_node_fs9;
2060
+ var import_node_path11, import_node_fs9;
1948
2061
  var init_hmr = __esm({
1949
2062
  "src/server/hmr.ts"() {
1950
2063
  "use strict";
1951
- import_node_path10 = __toESM(require("path"), 1);
2064
+ import_node_path11 = __toESM(require("path"), 1);
1952
2065
  import_node_fs9 = __toESM(require("fs"), 1);
1953
2066
  }
1954
2067
  });
@@ -1976,20 +2089,20 @@ async function createServer(inlineConfig = {}) {
1976
2089
  pluginContainer,
1977
2090
  moduleGraph
1978
2091
  }));
1979
- const publicDir = import_node_path11.default.resolve(config.root, "public");
2092
+ const publicDir = import_node_path12.default.resolve(config.root, "public");
1980
2093
  app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
1981
2094
  app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
1982
2095
  const httpServer = import_node_http.default.createServer(app);
1983
2096
  const ws = createWebSocketServer(httpServer);
1984
2097
  const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
1985
- const outDirAbs = import_node_path11.default.resolve(config.root, config.build.outDir);
2098
+ const outDirAbs = import_node_path12.default.resolve(config.root, config.build.outDir);
1986
2099
  const watcher = (0, import_chokidar.watch)(config.root, {
1987
2100
  ignored: (filePath) => {
1988
2101
  if (filePath === config.root) return false;
1989
- if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path11.default.sep)) return true;
1990
- const rel = import_node_path11.default.relative(config.root, filePath);
1991
- if (!rel || rel.startsWith("..") || import_node_path11.default.isAbsolute(rel)) return false;
1992
- for (const seg of rel.split(import_node_path11.default.sep)) {
2102
+ if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path12.default.sep)) return true;
2103
+ const rel = import_node_path12.default.relative(config.root, filePath);
2104
+ if (!rel || rel.startsWith("..") || import_node_path12.default.isAbsolute(rel)) return false;
2105
+ for (const seg of rel.split(import_node_path12.default.sep)) {
1993
2106
  if (ignoredSegments.has(seg)) return true;
1994
2107
  }
1995
2108
  return false;
@@ -2021,7 +2134,7 @@ async function createServer(inlineConfig = {}) {
2021
2134
  const localUrl = `http://localhost:${actualPort}`;
2022
2135
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
2023
2136
  console.log();
2024
- console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.3"}`));
2137
+ console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.5"}`));
2025
2138
  console.log();
2026
2139
  console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
2027
2140
  if (networkUrl) {
@@ -2077,12 +2190,12 @@ function getNetworkAddress() {
2077
2190
  }
2078
2191
  return "localhost";
2079
2192
  }
2080
- var import_node_http, import_node_path11, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors3;
2193
+ var import_node_http, import_node_path12, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors3;
2081
2194
  var init_server = __esm({
2082
2195
  "src/server/index.ts"() {
2083
2196
  "use strict";
2084
2197
  import_node_http = __toESM(require("http"), 1);
2085
- import_node_path11 = __toESM(require("path"), 1);
2198
+ import_node_path12 = __toESM(require("path"), 1);
2086
2199
  import_node_os = __toESM(require("os"), 1);
2087
2200
  import_connect = __toESM(require("connect"), 1);
2088
2201
  import_sirv = __toESM(require("sirv"), 1);
@@ -2118,7 +2231,7 @@ init_config();
2118
2231
  init_build();
2119
2232
 
2120
2233
  // src/build/electron.ts
2121
- var import_node_path8 = __toESM(require("path"), 1);
2234
+ var import_node_path9 = __toESM(require("path"), 1);
2122
2235
  var import_node_fs7 = __toESM(require("fs"), 1);
2123
2236
  var import_rolldown2 = require("rolldown");
2124
2237
  var import_picocolors2 = __toESM(require("picocolors"), 1);
@@ -2126,10 +2239,10 @@ init_config();
2126
2239
  init_resolve();
2127
2240
 
2128
2241
  // src/plugins/electron.ts
2129
- var import_node_module2 = require("module");
2242
+ var import_node_module3 = require("module");
2130
2243
  var NODE_BUILTINS = /* @__PURE__ */ new Set([
2131
- ...import_node_module2.builtinModules,
2132
- ...import_node_module2.builtinModules.map((m) => `node:${m}`)
2244
+ ...import_node_module3.builtinModules,
2245
+ ...import_node_module3.builtinModules.map((m) => `node:${m}`)
2133
2246
  ]);
2134
2247
  var ELECTRON_MODULES = /* @__PURE__ */ new Set([
2135
2248
  "electron",
@@ -2165,16 +2278,16 @@ async function buildElectron(inlineConfig = {}) {
2165
2278
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2166
2279
  const startTime = performance.now();
2167
2280
  assertElectronVersion(config);
2168
- console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.3"}`));
2281
+ console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.5"}`));
2169
2282
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
2170
2283
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
2171
2284
  console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
2172
- const outDir = import_node_path8.default.resolve(config.root, config.build.outDir);
2285
+ const outDir = import_node_path9.default.resolve(config.root, config.build.outDir);
2173
2286
  if (config.build.emptyOutDir && import_node_fs7.default.existsSync(outDir)) {
2174
2287
  import_node_fs7.default.rmSync(outDir, { recursive: true, force: true });
2175
2288
  }
2176
2289
  import_node_fs7.default.mkdirSync(outDir, { recursive: true });
2177
- const rendererOutDir = import_node_path8.default.join(outDir, "renderer");
2290
+ const rendererOutDir = import_node_path9.default.join(outDir, "renderer");
2178
2291
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
2179
2292
  await build2({
2180
2293
  ...inlineConfig,
@@ -2185,7 +2298,7 @@ async function buildElectron(inlineConfig = {}) {
2185
2298
  emptyOutDir: false
2186
2299
  }
2187
2300
  });
2188
- const mainEntry = import_node_path8.default.resolve(config.root, config.electron.main);
2301
+ const mainEntry = import_node_path9.default.resolve(config.root, config.electron.main);
2189
2302
  if (!import_node_fs7.default.existsSync(mainEntry)) {
2190
2303
  throw new Error(
2191
2304
  `Electron main entry not found: ${config.electron.main}
@@ -2204,7 +2317,7 @@ async function buildElectron(inlineConfig = {}) {
2204
2317
  console.warn(import_picocolors2.default.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
2205
2318
  continue;
2206
2319
  }
2207
- const base = import_node_path8.default.basename(entry).replace(/\.[^.]+$/, "");
2320
+ const base = import_node_path9.default.basename(entry).replace(/\.[^.]+$/, "");
2208
2321
  const out = outFileName(outDir, base, config.electron.preloadFormat);
2209
2322
  await bundleNode(config, entry, {
2210
2323
  outFile: out,
@@ -2216,10 +2329,10 @@ async function buildElectron(inlineConfig = {}) {
2216
2329
  const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
2217
2330
  console.log(import_picocolors2.default.green(`
2218
2331
  \u2713 Electron build complete in ${elapsed}s`));
2219
- console.log(import_picocolors2.default.dim(` renderer: ${import_node_path8.default.relative(config.root, rendererOutDir)}/`));
2220
- console.log(import_picocolors2.default.dim(` main: ${import_node_path8.default.relative(config.root, mainFile)}`));
2332
+ console.log(import_picocolors2.default.dim(` renderer: ${import_node_path9.default.relative(config.root, rendererOutDir)}/`));
2333
+ console.log(import_picocolors2.default.dim(` main: ${import_node_path9.default.relative(config.root, mainFile)}`));
2221
2334
  for (const pf of preloadFiles) {
2222
- console.log(import_picocolors2.default.dim(` preload: ${import_node_path8.default.relative(config.root, pf)}`));
2335
+ console.log(import_picocolors2.default.dim(` preload: ${import_node_path9.default.relative(config.root, pf)}`));
2223
2336
  }
2224
2337
  console.log();
2225
2338
  return { rendererOutDir, mainFile, preloadFiles };
@@ -2243,14 +2356,16 @@ async function bundleNode(config, entry, opts) {
2243
2356
  return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
2244
2357
  }
2245
2358
  };
2359
+ const existingTransform = config.build.rolldownOptions?.transform;
2360
+ const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
2246
2361
  const bundle = await (0, import_rolldown2.rolldown)({
2247
2362
  input: entry,
2248
- define: envDefine,
2363
+ transform: { ...existingTransform, define: mergedDefine },
2249
2364
  platform: "node",
2250
2365
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
2251
2366
  ...config.build.rolldownOptions
2252
2367
  });
2253
- import_node_fs7.default.mkdirSync(import_node_path8.default.dirname(opts.outFile), { recursive: true });
2368
+ import_node_fs7.default.mkdirSync(import_node_path9.default.dirname(opts.outFile), { recursive: true });
2254
2369
  await bundle.write({
2255
2370
  file: opts.outFile,
2256
2371
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -2259,16 +2374,16 @@ async function bundleNode(config, entry, opts) {
2259
2374
  codeSplitting: false
2260
2375
  });
2261
2376
  await bundle.close();
2262
- console.log(import_picocolors2.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path8.default.relative(config.root, opts.outFile)}`));
2377
+ console.log(import_picocolors2.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path9.default.relative(config.root, opts.outFile)}`));
2263
2378
  return opts.outFile;
2264
2379
  }
2265
2380
  function outFileName(outDir, base, format) {
2266
2381
  const ext = format === "cjs" ? ".cjs" : ".mjs";
2267
- return import_node_path8.default.join(outDir, base + ext);
2382
+ return import_node_path9.default.join(outDir, base + ext);
2268
2383
  }
2269
2384
  function normalizePreload(preload, root) {
2270
2385
  const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
2271
- return list.map((p) => import_node_path8.default.resolve(root, p));
2386
+ return list.map((p) => import_node_path9.default.resolve(root, p));
2272
2387
  }
2273
2388
  function assertElectronVersion(config) {
2274
2389
  const min = config.electron.minVersion;
@@ -2283,7 +2398,7 @@ function assertElectronVersion(config) {
2283
2398
  }
2284
2399
  function detectInstalledElectron(root) {
2285
2400
  try {
2286
- const pkgPath = import_node_path8.default.resolve(root, "node_modules/electron/package.json");
2401
+ const pkgPath = import_node_path9.default.resolve(root, "node_modules/electron/package.json");
2287
2402
  if (!import_node_fs7.default.existsSync(pkgPath)) return null;
2288
2403
  const pkg = JSON.parse(import_node_fs7.default.readFileSync(pkgPath, "utf-8"));
2289
2404
  const major = parseInt(String(pkg.version).split(".")[0], 10);
@@ -2297,9 +2412,9 @@ function detectInstalledElectron(root) {
2297
2412
  init_server();
2298
2413
 
2299
2414
  // src/server/electron-dev.ts
2300
- var import_node_path12 = __toESM(require("path"), 1);
2415
+ var import_node_path13 = __toESM(require("path"), 1);
2301
2416
  var import_node_fs10 = __toESM(require("fs"), 1);
2302
- var import_node_module4 = require("module");
2417
+ var import_node_module5 = require("module");
2303
2418
  var import_node_child_process = require("child_process");
2304
2419
  var import_chokidar2 = __toESM(require("chokidar"), 1);
2305
2420
  var import_picocolors4 = __toESM(require("picocolors"), 1);
@@ -2312,17 +2427,17 @@ async function startElectronDev(inlineConfig = {}) {
2312
2427
  const { noSpawn, ...rest } = inlineConfig;
2313
2428
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2314
2429
  warnElectronVersion(config);
2315
- console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.3"}`));
2430
+ console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.5"}`));
2316
2431
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2317
2432
  const server = await createServer2({ ...rest, target: "electron" });
2318
2433
  await server.listen();
2319
2434
  const devUrl = `http://localhost:${server.config.server.port}/`;
2320
2435
  console.log(import_picocolors4.default.dim(` renderer: ${devUrl}`));
2321
- const stageDir = import_node_path12.default.resolve(config.root, ".nasti");
2436
+ const stageDir = import_node_path13.default.resolve(config.root, ".nasti");
2322
2437
  import_node_fs10.default.mkdirSync(stageDir, { recursive: true });
2323
- const mainEntry = import_node_path12.default.resolve(config.root, config.electron.main);
2438
+ const mainEntry = import_node_path13.default.resolve(config.root, config.electron.main);
2324
2439
  const preloadEntries = normalizePreload(config.electron.preload, config.root);
2325
- const builtMainFile = import_node_path12.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
2440
+ const builtMainFile = import_node_path13.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
2326
2441
  const builtPreloadFiles = [];
2327
2442
  const compileAll = async () => {
2328
2443
  await compileNode(config, mainEntry, {
@@ -2333,8 +2448,8 @@ async function startElectronDev(inlineConfig = {}) {
2333
2448
  builtPreloadFiles.length = 0;
2334
2449
  for (const entry of preloadEntries) {
2335
2450
  if (!import_node_fs10.default.existsSync(entry)) continue;
2336
- const base = import_node_path12.default.basename(entry).replace(/\.[^.]+$/, "");
2337
- const out = import_node_path12.default.join(stageDir, base + extFor(config.electron.preloadFormat));
2451
+ const base = import_node_path13.default.basename(entry).replace(/\.[^.]+$/, "");
2452
+ const out = import_node_path13.default.join(stageDir, base + extFor(config.electron.preloadFormat));
2338
2453
  await compileNode(config, entry, {
2339
2454
  outFile: out,
2340
2455
  format: config.electron.preloadFormat,
@@ -2449,7 +2564,7 @@ async function compileNode(config, entry, opts) {
2449
2564
  platform: "node",
2450
2565
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
2451
2566
  });
2452
- import_node_fs10.default.mkdirSync(import_node_path12.default.dirname(opts.outFile), { recursive: true });
2567
+ import_node_fs10.default.mkdirSync(import_node_path13.default.dirname(opts.outFile), { recursive: true });
2453
2568
  await bundle.write({
2454
2569
  file: opts.outFile,
2455
2570
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -2466,7 +2581,7 @@ function resolveElectronBinary(config) {
2466
2581
  return config.electron.electronPath;
2467
2582
  }
2468
2583
  try {
2469
- const require2 = (0, import_node_module4.createRequire)(import_node_path12.default.resolve(config.root, "package.json"));
2584
+ const require2 = (0, import_node_module5.createRequire)(import_node_path13.default.resolve(config.root, "package.json"));
2470
2585
  const pathFile = require2.resolve("electron");
2471
2586
  const electronModule = require2(pathFile);
2472
2587
  if (typeof electronModule === "string" && import_node_fs10.default.existsSync(electronModule)) {
@@ -2496,10 +2611,10 @@ function warnElectronVersion(config) {
2496
2611
  }
2497
2612
 
2498
2613
  // src/plugins/monaco-editor.ts
2499
- var import_node_path13 = __toESM(require("path"), 1);
2614
+ var import_node_path14 = __toESM(require("path"), 1);
2500
2615
  var import_node_fs11 = __toESM(require("fs"), 1);
2501
2616
  var import_node_crypto2 = __toESM(require("crypto"), 1);
2502
- var import_node_module5 = require("module");
2617
+ var import_node_module6 = require("module");
2503
2618
  var DEFAULT_WORKERS = {
2504
2619
  editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
2505
2620
  css: "monaco-editor/esm/vs/language/css/css.worker",
@@ -2518,7 +2633,7 @@ function normalizePublicPath(p) {
2518
2633
  }
2519
2634
  function readMonacoVersion(root) {
2520
2635
  try {
2521
- const require2 = (0, import_node_module5.createRequire)(import_node_path13.default.resolve(root, "package.json"));
2636
+ const require2 = (0, import_node_module6.createRequire)(import_node_path14.default.resolve(root, "package.json"));
2522
2637
  const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
2523
2638
  const pkg = JSON.parse(import_node_fs11.default.readFileSync(pkgJsonPath, "utf-8"));
2524
2639
  return typeof pkg.version === "string" ? pkg.version : "unknown";
@@ -2540,13 +2655,13 @@ function monacoEditorPlugin(options = {}) {
2540
2655
  let cacheDir = "";
2541
2656
  const building = /* @__PURE__ */ new Map();
2542
2657
  async function buildWorker(worker) {
2543
- const cacheFile = import_node_path13.default.join(cacheDir, `${worker.label}.worker.js`);
2658
+ const cacheFile = import_node_path14.default.join(cacheDir, `${worker.label}.worker.js`);
2544
2659
  if (import_node_fs11.default.existsSync(cacheFile)) return cacheFile;
2545
2660
  const existing = building.get(worker.label);
2546
2661
  if (existing) return existing;
2547
2662
  const task = (async () => {
2548
2663
  const { rolldown: rolldown4 } = await import("rolldown");
2549
- const require2 = (0, import_node_module5.createRequire)(import_node_path13.default.resolve(resolvedConfig.root, "package.json"));
2664
+ const require2 = (0, import_node_module6.createRequire)(import_node_path14.default.resolve(resolvedConfig.root, "package.json"));
2550
2665
  let entry;
2551
2666
  try {
2552
2667
  entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
@@ -2613,12 +2728,12 @@ function monacoEditorPlugin(options = {}) {
2613
2728
  resolvedConfig = config;
2614
2729
  const version = readMonacoVersion(config.root);
2615
2730
  const key = import_node_crypto2.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
2616
- cacheDir = import_node_path13.default.resolve(config.root, "node_modules/.nasti/monaco", key);
2731
+ cacheDir = import_node_path14.default.resolve(config.root, "node_modules/.nasti/monaco", key);
2617
2732
  },
2618
2733
  async configureServer(server) {
2619
2734
  const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
2620
2735
  const watcher = server.watcher;
2621
- const monacoDir = import_node_path13.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
2736
+ const monacoDir = import_node_path14.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
2622
2737
  try {
2623
2738
  watcher?.unwatch?.(monacoDir);
2624
2739
  } catch {
@@ -2683,7 +2798,7 @@ self.monaco = monaco;`,
2683
2798
  resolvedConfig.root,
2684
2799
  resolvedConfig.build.outDir,
2685
2800
  resolvedConfig.base
2686
- ) : isCDN(publicPath) ? import_node_path13.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path13.default.resolve(
2801
+ ) : isCDN(publicPath) ? import_node_path14.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path14.default.resolve(
2687
2802
  resolvedConfig.root,
2688
2803
  resolvedConfig.build.outDir,
2689
2804
  publicPath.replace(/^\//, "")
@@ -2692,7 +2807,7 @@ self.monaco = monaco;`,
2692
2807
  for (const worker of workers) {
2693
2808
  try {
2694
2809
  const cacheFile = await buildWorker(worker);
2695
- import_node_fs11.default.copyFileSync(cacheFile, import_node_path13.default.join(outDir, `${worker.label}.worker.js`));
2810
+ import_node_fs11.default.copyFileSync(cacheFile, import_node_path14.default.join(outDir, `${worker.label}.worker.js`));
2696
2811
  } catch (e) {
2697
2812
  throw new Error(
2698
2813
  `[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}