@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.js CHANGED
@@ -35,7 +35,8 @@ var init_defaults = __esm({
35
35
  sourcemap: false,
36
36
  target: "es2022",
37
37
  rolldownOptions: {},
38
- emptyOutDir: true
38
+ emptyOutDir: true,
39
+ css: {}
39
40
  };
40
41
  defaultElectron = {
41
42
  main: "src/electron/main.ts",
@@ -282,20 +283,29 @@ import { createRequire } from "module";
282
283
  function resolvePlugin(config) {
283
284
  const { alias, extensions } = config.resolve;
284
285
  const require2 = createRequire(path2.resolve(config.root, "package.json"));
286
+ const aliasEntries = Object.entries(alias).sort(
287
+ ([a], [b]) => b.length - a.length
288
+ );
285
289
  return {
286
290
  name: "nasti:resolve",
287
291
  enforce: "pre",
288
292
  resolveId(source, importer) {
289
- for (const [key, value] of Object.entries(alias)) {
293
+ for (const [key, value] of aliasEntries) {
290
294
  if (source === key || source.startsWith(key + "/")) {
291
- source = source.replace(key, value);
292
- if (!path2.isAbsolute(source)) {
293
- source = path2.resolve(config.root, source);
294
- }
295
+ const aliasBase = resolveAliasTarget(value, config.root);
296
+ const sub = source.slice(key.length).replace(/^\//, "");
297
+ const target = sub ? path2.join(aliasBase, sub) : aliasBase;
298
+ const resolved = tryResolveFile(target, extensions);
299
+ if (resolved) return resolved;
295
300
  break;
296
301
  }
297
302
  }
298
- if (path2.isAbsolute(source)) {
303
+ if (source.startsWith("/") && !source.startsWith("//")) {
304
+ const rootRelative = path2.join(config.root, source.slice(1));
305
+ const resolved = tryResolveFile(rootRelative, extensions);
306
+ if (resolved) return resolved;
307
+ }
308
+ if (path2.isAbsolute(source) && fs2.existsSync(source)) {
299
309
  const resolved = tryResolveFile(source, extensions);
300
310
  if (resolved) return resolved;
301
311
  }
@@ -318,6 +328,7 @@ function resolvePlugin(config) {
318
328
  return null;
319
329
  },
320
330
  load(id) {
331
+ if (id.startsWith("\0")) return null;
321
332
  if (!fs2.existsSync(id)) return null;
322
333
  if (id.endsWith(".json")) {
323
334
  const content = fs2.readFileSync(id, "utf-8");
@@ -327,6 +338,11 @@ function resolvePlugin(config) {
327
338
  }
328
339
  };
329
340
  }
341
+ function resolveAliasTarget(value, root) {
342
+ if (path2.isAbsolute(value) && fs2.existsSync(value)) return value;
343
+ if (value.startsWith("/")) return path2.join(root, value.slice(1));
344
+ return path2.resolve(root, value);
345
+ }
330
346
  function tryResolveFile(file, extensions) {
331
347
  if (fs2.existsSync(file) && fs2.statSync(file).isFile()) {
332
348
  return file;
@@ -353,8 +369,61 @@ var init_resolve = __esm({
353
369
  }
354
370
  });
355
371
 
356
- // src/plugins/css.ts
372
+ // src/plugins/tailwind.ts
357
373
  import path3 from "path";
374
+ import { createRequire as createRequire2 } from "module";
375
+ import { pathToFileURL as pathToFileURL2 } from "url";
376
+ function hasTailwindDirectives(css) {
377
+ const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
378
+ const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
379
+ return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
380
+ }
381
+ async function loadTailwind(projectRoot) {
382
+ if (cached && cachedRoot === projectRoot) return cached;
383
+ const req = createRequire2(path3.join(projectRoot, "package.json"));
384
+ let nodePath;
385
+ let oxidePath;
386
+ try {
387
+ nodePath = req.resolve("@tailwindcss/node");
388
+ oxidePath = req.resolve("@tailwindcss/oxide");
389
+ } catch {
390
+ throw new Error(
391
+ "[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"
392
+ );
393
+ }
394
+ const node = await import(pathToFileURL2(nodePath).href);
395
+ const oxide = await import(pathToFileURL2(oxidePath).href);
396
+ cached = { node, oxide };
397
+ cachedRoot = projectRoot;
398
+ return cached;
399
+ }
400
+ async function compileTailwind(css, fromFile, projectRoot) {
401
+ const { node, oxide } = await loadTailwind(projectRoot);
402
+ const dependencies = [];
403
+ const compiler = await node.compile(css, {
404
+ base: path3.dirname(fromFile),
405
+ from: fromFile,
406
+ onDependency: (p) => dependencies.push(p)
407
+ });
408
+ const scanner = new oxide.Scanner({ sources: compiler.sources });
409
+ const candidates = scanner.scan();
410
+ return {
411
+ css: compiler.build(candidates),
412
+ dependencies: [...dependencies, ...scanner.files]
413
+ };
414
+ }
415
+ var TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
416
+ var init_tailwind = __esm({
417
+ "src/plugins/tailwind.ts"() {
418
+ "use strict";
419
+ 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)/;
420
+ cached = null;
421
+ cachedRoot = null;
422
+ }
423
+ });
424
+
425
+ // src/plugins/css.ts
426
+ import path4 from "path";
358
427
  function cssPlugin(config) {
359
428
  return {
360
429
  name: "nasti:css",
@@ -362,11 +431,16 @@ function cssPlugin(config) {
362
431
  if (source.endsWith(".css")) return null;
363
432
  return null;
364
433
  },
365
- transform(code, id) {
434
+ async transform(code, id) {
366
435
  if (!id.endsWith(".css")) return null;
367
- const rewritten = rewriteCssUrls(code, id, config.root);
436
+ let cssSource = code;
437
+ if (hasTailwindDirectives(code)) {
438
+ const compiled = await compileTailwind(code, id, config.root);
439
+ cssSource = compiled.css;
440
+ }
441
+ const rewritten = rewriteCssUrls(cssSource, id, config.root);
442
+ const escaped = JSON.stringify(rewritten);
368
443
  if (config.command === "serve") {
369
- const escaped = JSON.stringify(rewritten);
370
444
  return {
371
445
  code: `
372
446
  const css = ${escaped};
@@ -390,7 +464,42 @@ export default css;
390
464
  `
391
465
  };
392
466
  }
393
- return rewritten !== code ? { code: rewritten } : null;
467
+ const cssConfig = config.build.css || {};
468
+ const nonce = cssConfig.nonce;
469
+ const emitCssFile = cssConfig.emitCssFile;
470
+ if (emitCssFile) {
471
+ const fileName = `assets/${path4.basename(id, ".css")}.css`;
472
+ this.emitFile({
473
+ type: "asset",
474
+ fileName,
475
+ source: rewritten
476
+ });
477
+ return {
478
+ code: `
479
+ const link = document.createElement('link');
480
+ link.rel = 'stylesheet';
481
+ link.href = ${JSON.stringify("/" + fileName)};
482
+ document.head.appendChild(link);
483
+
484
+ export default ${escaped};
485
+ `,
486
+ moduleType: "js"
487
+ };
488
+ }
489
+ const nonceAttr = nonce ? `style.setAttribute('nonce', ${JSON.stringify(nonce)});` : "";
490
+ return {
491
+ code: `
492
+ const css = ${escaped};
493
+ const style = document.createElement('style');
494
+ style.setAttribute('data-nasti-css', ${JSON.stringify(id)});
495
+ ${nonceAttr}
496
+ style.textContent = css;
497
+ document.head.appendChild(style);
498
+
499
+ export default css;
500
+ `,
501
+ moduleType: "js"
502
+ };
394
503
  }
395
504
  };
396
505
  }
@@ -399,19 +508,20 @@ function rewriteCssUrls(css, from, root) {
399
508
  if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
400
509
  return match;
401
510
  }
402
- const resolved = path3.resolve(path3.dirname(from), url);
403
- const relative = "/" + path3.relative(root, resolved);
511
+ const resolved = path4.resolve(path4.dirname(from), url);
512
+ const relative = "/" + path4.relative(root, resolved);
404
513
  return `url(${relative})`;
405
514
  });
406
515
  }
407
516
  var init_css = __esm({
408
517
  "src/plugins/css.ts"() {
409
518
  "use strict";
519
+ init_tailwind();
410
520
  }
411
521
  });
412
522
 
413
523
  // src/plugins/assets.ts
414
- import path4 from "path";
524
+ import path5 from "path";
415
525
  import fs3 from "fs";
416
526
  import crypto from "crypto";
417
527
  function assetsPlugin(config) {
@@ -424,7 +534,7 @@ function assetsPlugin(config) {
424
534
  return null;
425
535
  },
426
536
  load(id) {
427
- const ext = path4.extname(id.replace(/\?.*$/, ""));
537
+ const ext = path5.extname(id.replace(/\?.*$/, ""));
428
538
  if (id.endsWith("?raw")) {
429
539
  const file = id.slice(0, -4);
430
540
  if (fs3.existsSync(file)) {
@@ -436,12 +546,12 @@ function assetsPlugin(config) {
436
546
  const file = id.replace(/\?.*$/, "");
437
547
  if (!fs3.existsSync(file)) return null;
438
548
  if (config.command === "serve") {
439
- const url = "/" + path4.relative(config.root, file);
549
+ const url = "/" + path5.relative(config.root, file);
440
550
  return `export default ${JSON.stringify(url)}`;
441
551
  }
442
552
  const content = fs3.readFileSync(file);
443
553
  const hash = crypto.createHash("sha256").update(content).digest("hex").slice(0, 8);
444
- const basename = path4.basename(file, ext);
554
+ const basename = path5.basename(file, ext);
445
555
  const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
446
556
  return `export default ${JSON.stringify(config.base + hashedName)}`;
447
557
  }
@@ -481,7 +591,7 @@ var init_assets = __esm({
481
591
  });
482
592
 
483
593
  // src/plugins/html.ts
484
- import path5 from "path";
594
+ import path6 from "path";
485
595
  import fs4 from "fs";
486
596
  function htmlPlugin(config) {
487
597
  return {
@@ -545,7 +655,7 @@ function serializeTag(tag) {
545
655
  return ` <${tag.tag}${attrs}>${children}</${tag.tag}>`;
546
656
  }
547
657
  async function readHtmlFile(root) {
548
- const htmlPath = path5.resolve(root, "index.html");
658
+ const htmlPath = path6.resolve(root, "index.html");
549
659
  if (!fs4.existsSync(htmlPath)) return null;
550
660
  return fs4.readFileSync(htmlPath, "utf-8");
551
661
  }
@@ -601,7 +711,7 @@ var init_transformer = __esm({
601
711
  });
602
712
 
603
713
  // src/core/env.ts
604
- import path6 from "path";
714
+ import path7 from "path";
605
715
  import fs5 from "fs";
606
716
  function loadEnv(mode, root, prefixes) {
607
717
  const envFiles = [
@@ -612,7 +722,7 @@ function loadEnv(mode, root, prefixes) {
612
722
  ];
613
723
  const raw = {};
614
724
  for (const file of envFiles) {
615
- const filePath = path6.resolve(root, file);
725
+ const filePath = path7.resolve(root, file);
616
726
  if (!fs5.existsSync(filePath)) continue;
617
727
  const content = fs5.readFileSync(filePath, "utf-8");
618
728
  for (const line of content.split("\n")) {
@@ -786,17 +896,17 @@ var build_exports = {};
786
896
  __export(build_exports, {
787
897
  build: () => build
788
898
  });
789
- import path7 from "path";
899
+ import path8 from "path";
790
900
  import fs6 from "fs";
791
901
  import { rolldown } from "rolldown";
792
902
  import pc from "picocolors";
793
903
  async function build(inlineConfig = {}) {
794
904
  const config = await resolveConfig(inlineConfig, "build");
795
905
  const startTime = performance.now();
796
- console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.3"}`));
906
+ console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.5"}`));
797
907
  console.log(pc.dim(` root: ${config.root}`));
798
908
  console.log(pc.dim(` mode: ${config.mode}`));
799
- const outDir = path7.resolve(config.root, config.build.outDir);
909
+ const outDir = path8.resolve(config.root, config.build.outDir);
800
910
  if (config.build.emptyOutDir && fs6.existsSync(outDir)) {
801
911
  fs6.rmSync(outDir, { recursive: true, force: true });
802
912
  }
@@ -808,14 +918,14 @@ async function build(inlineConfig = {}) {
808
918
  for (const match of scriptMatches) {
809
919
  const src = match[1];
810
920
  if (src && !src.startsWith("http")) {
811
- entryPoints.push(path7.resolve(config.root, src.replace(/^\//, "")));
921
+ entryPoints.push(path8.resolve(config.root, src.replace(/^\//, "")));
812
922
  }
813
923
  }
814
924
  }
815
925
  if (entryPoints.length === 0) {
816
926
  const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
817
927
  for (const entry of fallbackEntries) {
818
- const fullPath = path7.resolve(config.root, entry);
928
+ const fullPath = path8.resolve(config.root, entry);
819
929
  if (fs6.existsSync(fullPath)) {
820
930
  entryPoints.push(fullPath);
821
931
  break;
@@ -847,9 +957,11 @@ async function build(inlineConfig = {}) {
847
957
  };
848
958
  const env = loadEnv(config.mode, config.root, config.envPrefix);
849
959
  const envDefine = buildEnvDefine(env, config.mode);
960
+ const existingTransform = config.build.rolldownOptions?.transform;
961
+ const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
850
962
  const bundle = await rolldown({
851
963
  input: entryPoints,
852
- define: envDefine,
964
+ transform: { ...existingTransform, define: mergedDefine },
853
965
  plugins: [
854
966
  oxcTransformPlugin,
855
967
  // 转换 Nasti 插件为 Rolldown 插件格式
@@ -880,8 +992,8 @@ async function build(inlineConfig = {}) {
880
992
  await bundle.close();
881
993
  await pluginContainer.buildEnd();
882
994
  for (const ef of pluginContainer.getEmittedFiles()) {
883
- const dest = path7.resolve(outDir, ef.fileName);
884
- fs6.mkdirSync(path7.dirname(dest), { recursive: true });
995
+ const dest = path8.resolve(outDir, ef.fileName);
996
+ fs6.mkdirSync(path8.dirname(dest), { recursive: true });
885
997
  fs6.writeFileSync(dest, ef.source);
886
998
  }
887
999
  if (html) {
@@ -899,14 +1011,14 @@ async function build(inlineConfig = {}) {
899
1011
  }
900
1012
  for (const chunk of output) {
901
1013
  if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
902
- const originalEntry = path7.relative(config.root, chunk.facadeModuleId);
1014
+ const originalEntry = path8.relative(config.root, chunk.facadeModuleId);
903
1015
  processedHtml = processedHtml.replace(
904
1016
  new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
905
1017
  `$1${config.base}${chunk.fileName}$3`
906
1018
  );
907
1019
  }
908
1020
  }
909
- fs6.writeFileSync(path7.resolve(outDir, "index.html"), processedHtml);
1021
+ fs6.writeFileSync(path8.resolve(outDir, "index.html"), processedHtml);
910
1022
  }
911
1023
  const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
912
1024
  const totalSize = output.reduce((sum, chunk) => {
@@ -1118,18 +1230,18 @@ __export(middleware_exports, {
1118
1230
  transformMiddleware: () => transformMiddleware,
1119
1231
  transformRequest: () => transformRequest
1120
1232
  });
1121
- import path9 from "path";
1233
+ import path10 from "path";
1122
1234
  import fs8 from "fs";
1123
- import { createRequire as createRequire2 } from "module";
1124
- import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "url";
1235
+ import { createRequire as createRequire3 } from "module";
1236
+ import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "url";
1125
1237
  function getReactRefreshRuntimeEsm() {
1126
1238
  if (__refreshRuntimeCache) return __refreshRuntimeCache;
1127
1239
  let cjsPath;
1128
1240
  try {
1129
1241
  const pkgPath = __require.resolve("react-refresh/package.json");
1130
- cjsPath = path9.join(path9.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
1242
+ cjsPath = path10.join(path10.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
1131
1243
  } catch (err) {
1132
- cjsPath = path9.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
1244
+ cjsPath = path10.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
1133
1245
  if (!fs8.existsSync(cjsPath)) {
1134
1246
  const origMsg = err instanceof Error ? err.message : String(err);
1135
1247
  throw new Error(
@@ -1269,9 +1381,9 @@ function transformMiddleware(ctx) {
1269
1381
  async function transformRequest(url, ctx) {
1270
1382
  const { config, pluginContainer, moduleGraph } = ctx;
1271
1383
  const cleanReqUrl = url.split("?")[0];
1272
- const cached = moduleGraph.getModuleByUrl(url);
1273
- if (cached?.transformResult) {
1274
- return cached.transformResult;
1384
+ const cached2 = moduleGraph.getModuleByUrl(url);
1385
+ if (cached2?.transformResult) {
1386
+ return cached2.transformResult;
1275
1387
  }
1276
1388
  if (cleanReqUrl === "/@react-refresh") {
1277
1389
  return { code: getReactRefreshRuntimeEsm() };
@@ -1350,7 +1462,7 @@ async function loadVirtualModule(spec, ctx) {
1350
1462
  loadEnv(config.mode, config.root, config.envPrefix),
1351
1463
  config.mode
1352
1464
  ));
1353
- const anchor = path9.join(config.root, "__nasti_virtual__.ts");
1465
+ const anchor = path10.join(config.root, "__nasti_virtual__.ts");
1354
1466
  code = rewriteImports(code, config, anchor);
1355
1467
  return { id: resolvedId, result: { code } };
1356
1468
  }
@@ -1393,13 +1505,13 @@ async function doBundlePackage(entryFile) {
1393
1505
  return code;
1394
1506
  }
1395
1507
  async function tryGenerateSubpathShim(entryFile) {
1396
- const NM = `${path9.sep}node_modules${path9.sep}`;
1508
+ const NM = `${path10.sep}node_modules${path10.sep}`;
1397
1509
  if (!entryFile.includes(NM)) return null;
1398
1510
  let pkgDir = null;
1399
1511
  let pkgName = null;
1400
- let dir = path9.dirname(entryFile);
1512
+ let dir = path10.dirname(entryFile);
1401
1513
  while (true) {
1402
- const pkgJsonPath = path9.join(dir, "package.json");
1514
+ const pkgJsonPath = path10.join(dir, "package.json");
1403
1515
  if (fs8.existsSync(pkgJsonPath)) {
1404
1516
  try {
1405
1517
  const pkg = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf-8"));
@@ -1411,21 +1523,21 @@ async function tryGenerateSubpathShim(entryFile) {
1411
1523
  } catch {
1412
1524
  }
1413
1525
  }
1414
- const parent = path9.dirname(dir);
1526
+ const parent = path10.dirname(dir);
1415
1527
  if (parent === dir) return null;
1416
1528
  dir = parent;
1417
1529
  if (!dir.includes(NM)) return null;
1418
1530
  }
1419
1531
  if (!pkgDir || !pkgName) return null;
1420
- const entryExt = path9.extname(entryFile);
1532
+ const entryExt = path10.extname(entryFile);
1421
1533
  const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
1422
1534
  if (!mainEntry) return null;
1423
- if (path9.resolve(mainEntry) === path9.resolve(entryFile)) return null;
1535
+ if (path10.resolve(mainEntry) === path10.resolve(entryFile)) return null;
1424
1536
  let mainNs;
1425
1537
  let subNs;
1426
1538
  try {
1427
- mainNs = await import(pathToFileURL2(mainEntry).href);
1428
- subNs = await import(pathToFileURL2(entryFile).href);
1539
+ mainNs = await import(pathToFileURL3(mainEntry).href);
1540
+ subNs = await import(pathToFileURL3(entryFile).href);
1429
1541
  } catch {
1430
1542
  return null;
1431
1543
  }
@@ -1456,7 +1568,7 @@ async function tryGenerateSubpathShim(entryFile) {
1456
1568
  return lines.join("\n") + "\n";
1457
1569
  }
1458
1570
  function pickMainEntryByExtension(pkgDir, preferredExt) {
1459
- const pkgJsonPath = path9.join(pkgDir, "package.json");
1571
+ const pkgJsonPath = path10.join(pkgDir, "package.json");
1460
1572
  let pkg;
1461
1573
  try {
1462
1574
  pkg = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf-8"));
@@ -1478,13 +1590,13 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
1478
1590
  if (typeof pkg.module === "string") candidates.push(pkg.module);
1479
1591
  if (typeof pkg.main === "string") candidates.push(pkg.main);
1480
1592
  for (const cand of candidates) {
1481
- if (path9.extname(cand) === preferredExt) {
1482
- const full = path9.resolve(pkgDir, cand);
1593
+ if (path10.extname(cand) === preferredExt) {
1594
+ const full = path10.resolve(pkgDir, cand);
1483
1595
  if (fs8.existsSync(full)) return full;
1484
1596
  }
1485
1597
  }
1486
1598
  for (const cand of candidates) {
1487
- const full = path9.resolve(pkgDir, cand);
1599
+ const full = path10.resolve(pkgDir, cand);
1488
1600
  if (fs8.existsSync(full)) return full;
1489
1601
  }
1490
1602
  return null;
@@ -1510,19 +1622,20 @@ function rewriteExternalRequires(code) {
1510
1622
  }
1511
1623
  async function injectCjsNamedExports(code, entryFile) {
1512
1624
  try {
1513
- const { createRequire: createRequire5 } = await import("module");
1514
- const req = createRequire5(entryFile);
1625
+ const { createRequire: createRequire6 } = await import("module");
1626
+ const req = createRequire6(entryFile);
1515
1627
  const cjsExports = req(entryFile);
1516
1628
  if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
1517
1629
  const namedKeys = Object.keys(cjsExports).filter(
1518
1630
  (k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
1519
1631
  );
1520
- if (namedKeys.length === 0) return code;
1632
+ const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
1633
+ if (!hasEsmInterop && namedKeys.length === 0) return code;
1521
1634
  return code.replace(
1522
1635
  /^export default (\w+\(\));?\s*$/m,
1523
1636
  (_, call) => [
1524
1637
  `const __cjsMod = ${call};`,
1525
- `export default __cjsMod;`,
1638
+ hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
1526
1639
  ...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
1527
1640
  ].join("\n")
1528
1641
  );
@@ -1532,31 +1645,31 @@ async function injectCjsNamedExports(code, entryFile) {
1532
1645
  }
1533
1646
  function rewriteImports(code, config, filePath) {
1534
1647
  const root = config.root;
1535
- const fileDir = path9.dirname(filePath);
1648
+ const fileDir = path10.dirname(filePath);
1536
1649
  const aliasEntries = Object.entries(config.resolve.alias).sort(
1537
1650
  ([a], [b]) => b.length - a.length
1538
1651
  );
1539
- const toRootUrl = (abs) => "/" + path9.relative(root, abs).replace(/\\/g, "/");
1652
+ const toRootUrl = (abs) => "/" + path10.relative(root, abs).replace(/\\/g, "/");
1540
1653
  const transformSpec = (spec) => {
1541
1654
  const suffixMatch = spec.match(/[?#].*$/);
1542
1655
  const suffix = suffixMatch ? suffixMatch[0] : "";
1543
1656
  const baseSpec = suffix ? spec.slice(0, -suffix.length) : spec;
1544
1657
  for (const [key, value] of aliasEntries) {
1545
1658
  if (baseSpec === key || baseSpec.startsWith(key + "/")) {
1546
- const aliasBase = resolveAliasTarget(value, root);
1659
+ const aliasBase = resolveAliasTarget2(value, root);
1547
1660
  const sub = baseSpec.slice(key.length).replace(/^\//, "");
1548
- const target = sub ? path9.join(aliasBase, sub) : aliasBase;
1661
+ const target = sub ? path10.join(aliasBase, sub) : aliasBase;
1549
1662
  const resolved = tryResolveDiskPath(target);
1550
1663
  return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1551
1664
  }
1552
1665
  }
1553
1666
  if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
1554
- const target = path9.resolve(fileDir, baseSpec);
1667
+ const target = path10.resolve(fileDir, baseSpec);
1555
1668
  const resolved = tryResolveDiskPath(target);
1556
1669
  return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1557
1670
  }
1558
1671
  if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
1559
- const target = path9.join(root, baseSpec.replace(/^\//, ""));
1672
+ const target = path10.join(root, baseSpec.replace(/^\//, ""));
1560
1673
  const resolved = tryResolveDiskPath(target);
1561
1674
  return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
1562
1675
  }
@@ -1574,10 +1687,10 @@ function rewriteImports(code, config, filePath) {
1574
1687
  (_m, q, s) => `import(${q}${transformSpec(s)}${q})`
1575
1688
  );
1576
1689
  }
1577
- function resolveAliasTarget(value, root) {
1578
- if (path9.isAbsolute(value) && fs8.existsSync(value)) return value;
1579
- if (value.startsWith("/")) return path9.join(root, value.slice(1));
1580
- return path9.resolve(root, value);
1690
+ function resolveAliasTarget2(value, root) {
1691
+ if (path10.isAbsolute(value) && fs8.existsSync(value)) return value;
1692
+ if (value.startsWith("/")) return path10.join(root, value.slice(1));
1693
+ return path10.resolve(root, value);
1581
1694
  }
1582
1695
  function tryResolveDiskPath(target) {
1583
1696
  if (fs8.existsSync(target) && fs8.statSync(target).isFile()) return target;
@@ -1587,15 +1700,15 @@ function tryResolveDiskPath(target) {
1587
1700
  }
1588
1701
  if (fs8.existsSync(target) && fs8.statSync(target).isDirectory()) {
1589
1702
  for (const ext of RESOLVE_EXTENSIONS) {
1590
- const idx = path9.join(target, "index" + ext);
1703
+ const idx = path10.join(target, "index" + ext);
1591
1704
  if (fs8.existsSync(idx) && fs8.statSync(idx).isFile()) return idx;
1592
1705
  }
1593
1706
  }
1594
1707
  return null;
1595
1708
  }
1596
1709
  function isUnderRoot(abs, root) {
1597
- const rel = path9.relative(root, abs);
1598
- return !!rel && !rel.startsWith("..") && !path9.isAbsolute(rel);
1710
+ const rel = path10.relative(root, abs);
1711
+ return !!rel && !rel.startsWith("..") && !path10.isAbsolute(rel);
1599
1712
  }
1600
1713
  function resolveNodeModule(root, moduleName) {
1601
1714
  let pkgName;
@@ -1612,17 +1725,17 @@ function resolveNodeModule(root, moduleName) {
1612
1725
  let pkgDir = null;
1613
1726
  let dir = root;
1614
1727
  for (; ; ) {
1615
- const candidate = path9.join(dir, "node_modules", pkgName);
1728
+ const candidate = path10.join(dir, "node_modules", pkgName);
1616
1729
  if (fs8.existsSync(candidate)) {
1617
1730
  pkgDir = candidate;
1618
1731
  break;
1619
1732
  }
1620
- const parent = path9.dirname(dir);
1733
+ const parent = path10.dirname(dir);
1621
1734
  if (parent === dir) break;
1622
1735
  dir = parent;
1623
1736
  }
1624
1737
  if (!pkgDir) return null;
1625
- const pkgJsonPath = path9.join(pkgDir, "package.json");
1738
+ const pkgJsonPath = path10.join(pkgDir, "package.json");
1626
1739
  if (!fs8.existsSync(pkgJsonPath)) return null;
1627
1740
  let pkg;
1628
1741
  try {
@@ -1639,12 +1752,12 @@ function resolveNodeModule(root, moduleName) {
1639
1752
  const subDirs = [""];
1640
1753
  for (const field of ["module", "main"]) {
1641
1754
  if (typeof pkg[field] === "string") {
1642
- const dir2 = path9.dirname(pkg[field]);
1755
+ const dir2 = path10.dirname(pkg[field]);
1643
1756
  if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
1644
1757
  }
1645
1758
  }
1646
1759
  for (const dir2 of subDirs) {
1647
- const direct = path9.join(pkgDir, dir2, subpath);
1760
+ const direct = path10.join(pkgDir, dir2, subpath);
1648
1761
  if (fs8.existsSync(direct) && fs8.statSync(direct).isFile()) return direct;
1649
1762
  for (const ext of RESOLVE_EXTENSIONS) {
1650
1763
  if (fs8.existsSync(direct + ext)) return direct + ext;
@@ -1654,24 +1767,24 @@ function resolveNodeModule(root, moduleName) {
1654
1767
  }
1655
1768
  for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
1656
1769
  if (typeof pkg[field] === "string") {
1657
- const entry = path9.join(pkgDir, pkg[field]);
1770
+ const entry = path10.join(pkgDir, pkg[field]);
1658
1771
  if (fs8.existsSync(entry)) return entry;
1659
1772
  }
1660
1773
  }
1661
- const indexFallback = path9.join(pkgDir, "index.js");
1774
+ const indexFallback = path10.join(pkgDir, "index.js");
1662
1775
  if (fs8.existsSync(indexFallback)) return indexFallback;
1663
1776
  return null;
1664
1777
  }
1665
1778
  function resolvePackageExports(exports, key, pkgDir) {
1666
1779
  if (typeof exports === "string") {
1667
- return key === "." ? path9.join(pkgDir, exports) : null;
1780
+ return key === "." ? path10.join(pkgDir, exports) : null;
1668
1781
  }
1669
1782
  const entry = exports[key];
1670
1783
  if (entry === void 0) return null;
1671
1784
  return resolveExportValue(entry, pkgDir);
1672
1785
  }
1673
1786
  function resolveExportValue(value, pkgDir) {
1674
- if (typeof value === "string") return path9.join(pkgDir, value);
1787
+ if (typeof value === "string") return path10.join(pkgDir, value);
1675
1788
  if (Array.isArray(value)) {
1676
1789
  for (const item of value) {
1677
1790
  const r = resolveExportValue(item, pkgDir);
@@ -1695,7 +1808,7 @@ function resolveUrlToFile(url, root) {
1695
1808
  const moduleName = cleanUrl.slice("/@modules/".length);
1696
1809
  return resolveNodeModule(root, moduleName);
1697
1810
  }
1698
- const filePath = path9.resolve(root, cleanUrl.replace(/^\//, ""));
1811
+ const filePath = path10.resolve(root, cleanUrl.replace(/^\//, ""));
1699
1812
  if (fs8.existsSync(filePath) && fs8.statSync(filePath).isFile()) {
1700
1813
  return filePath;
1701
1814
  }
@@ -1704,7 +1817,7 @@ function resolveUrlToFile(url, root) {
1704
1817
  if (fs8.existsSync(withExt)) return withExt;
1705
1818
  }
1706
1819
  for (const ext of RESOLVE_EXTENSIONS) {
1707
- const indexFile = path9.join(filePath, "index" + ext);
1820
+ const indexFile = path10.join(filePath, "index" + ext);
1708
1821
  if (fs8.existsSync(indexFile)) return indexFile;
1709
1822
  }
1710
1823
  return null;
@@ -1713,7 +1826,7 @@ function isModuleRequest(url) {
1713
1826
  const cleanUrl = url.split("?")[0];
1714
1827
  if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
1715
1828
  if (cleanUrl.startsWith("/@modules/")) return true;
1716
- if (!path9.extname(cleanUrl)) return true;
1829
+ if (!path10.extname(cleanUrl)) return true;
1717
1830
  return false;
1718
1831
  }
1719
1832
  function getHmrClientCode() {
@@ -1851,8 +1964,8 @@ var init_middleware = __esm({
1851
1964
  init_transformer();
1852
1965
  init_html();
1853
1966
  init_env();
1854
- __dirname_esm = path9.dirname(fileURLToPath(import.meta.url));
1855
- __require = createRequire2(import.meta.url);
1967
+ __dirname_esm = path10.dirname(fileURLToPath(import.meta.url));
1968
+ __require = createRequire3(import.meta.url);
1856
1969
  __refreshRuntimeCache = null;
1857
1970
  REACT_REFRESH_GLOBAL_PREAMBLE = `
1858
1971
  import RefreshRuntime from "/@react-refresh";
@@ -1869,11 +1982,11 @@ window.__vite_plugin_react_preamble_installed__ = true;
1869
1982
  });
1870
1983
 
1871
1984
  // src/server/hmr.ts
1872
- import path10 from "path";
1985
+ import path11 from "path";
1873
1986
  import fs9 from "fs";
1874
1987
  async function handleFileChange(file, server) {
1875
1988
  const { moduleGraph, ws, config } = server;
1876
- const relativePath = "/" + path10.relative(config.root, file);
1989
+ const relativePath = "/" + path11.relative(config.root, file);
1877
1990
  const mods = moduleGraph.getModulesByFile(file);
1878
1991
  if (!mods || mods.size === 0) {
1879
1992
  return;
@@ -1930,7 +2043,7 @@ __export(server_exports, {
1930
2043
  createServer: () => createServer
1931
2044
  });
1932
2045
  import http from "http";
1933
- import path11 from "path";
2046
+ import path12 from "path";
1934
2047
  import os from "os";
1935
2048
  import connect from "connect";
1936
2049
  import sirv from "sirv";
@@ -1954,20 +2067,20 @@ async function createServer(inlineConfig = {}) {
1954
2067
  pluginContainer,
1955
2068
  moduleGraph
1956
2069
  }));
1957
- const publicDir = path11.resolve(config.root, "public");
2070
+ const publicDir = path12.resolve(config.root, "public");
1958
2071
  app.use(sirv(publicDir, { dev: true, etag: true }));
1959
2072
  app.use(sirv(config.root, { dev: true, etag: true }));
1960
2073
  const httpServer = http.createServer(app);
1961
2074
  const ws = createWebSocketServer(httpServer);
1962
2075
  const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
1963
- const outDirAbs = path11.resolve(config.root, config.build.outDir);
2076
+ const outDirAbs = path12.resolve(config.root, config.build.outDir);
1964
2077
  const watcher = watch(config.root, {
1965
2078
  ignored: (filePath) => {
1966
2079
  if (filePath === config.root) return false;
1967
- if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path11.sep)) return true;
1968
- const rel = path11.relative(config.root, filePath);
1969
- if (!rel || rel.startsWith("..") || path11.isAbsolute(rel)) return false;
1970
- for (const seg of rel.split(path11.sep)) {
2080
+ if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path12.sep)) return true;
2081
+ const rel = path12.relative(config.root, filePath);
2082
+ if (!rel || rel.startsWith("..") || path12.isAbsolute(rel)) return false;
2083
+ for (const seg of rel.split(path12.sep)) {
1971
2084
  if (ignoredSegments.has(seg)) return true;
1972
2085
  }
1973
2086
  return false;
@@ -1999,7 +2112,7 @@ async function createServer(inlineConfig = {}) {
1999
2112
  const localUrl = `http://localhost:${actualPort}`;
2000
2113
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
2001
2114
  console.log();
2002
- console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.3"}`));
2115
+ console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.5"}`));
2003
2116
  console.log();
2004
2117
  console.log(` ${pc3.green(">")} Local: ${pc3.cyan(localUrl)}`);
2005
2118
  if (networkUrl) {
@@ -2078,7 +2191,7 @@ init_build();
2078
2191
  // src/build/electron.ts
2079
2192
  init_config();
2080
2193
  init_resolve();
2081
- import path8 from "path";
2194
+ import path9 from "path";
2082
2195
  import fs7 from "fs";
2083
2196
  import { rolldown as rolldown2 } from "rolldown";
2084
2197
  import pc2 from "picocolors";
@@ -2123,16 +2236,16 @@ async function buildElectron(inlineConfig = {}) {
2123
2236
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2124
2237
  const startTime = performance.now();
2125
2238
  assertElectronVersion(config);
2126
- console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.3"}`));
2239
+ console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.5"}`));
2127
2240
  console.log(pc2.dim(` root: ${config.root}`));
2128
2241
  console.log(pc2.dim(` mode: ${config.mode}`));
2129
2242
  console.log(pc2.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
2130
- const outDir = path8.resolve(config.root, config.build.outDir);
2243
+ const outDir = path9.resolve(config.root, config.build.outDir);
2131
2244
  if (config.build.emptyOutDir && fs7.existsSync(outDir)) {
2132
2245
  fs7.rmSync(outDir, { recursive: true, force: true });
2133
2246
  }
2134
2247
  fs7.mkdirSync(outDir, { recursive: true });
2135
- const rendererOutDir = path8.join(outDir, "renderer");
2248
+ const rendererOutDir = path9.join(outDir, "renderer");
2136
2249
  const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
2137
2250
  await build2({
2138
2251
  ...inlineConfig,
@@ -2143,7 +2256,7 @@ async function buildElectron(inlineConfig = {}) {
2143
2256
  emptyOutDir: false
2144
2257
  }
2145
2258
  });
2146
- const mainEntry = path8.resolve(config.root, config.electron.main);
2259
+ const mainEntry = path9.resolve(config.root, config.electron.main);
2147
2260
  if (!fs7.existsSync(mainEntry)) {
2148
2261
  throw new Error(
2149
2262
  `Electron main entry not found: ${config.electron.main}
@@ -2162,7 +2275,7 @@ async function buildElectron(inlineConfig = {}) {
2162
2275
  console.warn(pc2.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
2163
2276
  continue;
2164
2277
  }
2165
- const base = path8.basename(entry).replace(/\.[^.]+$/, "");
2278
+ const base = path9.basename(entry).replace(/\.[^.]+$/, "");
2166
2279
  const out = outFileName(outDir, base, config.electron.preloadFormat);
2167
2280
  await bundleNode(config, entry, {
2168
2281
  outFile: out,
@@ -2174,10 +2287,10 @@ async function buildElectron(inlineConfig = {}) {
2174
2287
  const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
2175
2288
  console.log(pc2.green(`
2176
2289
  \u2713 Electron build complete in ${elapsed}s`));
2177
- console.log(pc2.dim(` renderer: ${path8.relative(config.root, rendererOutDir)}/`));
2178
- console.log(pc2.dim(` main: ${path8.relative(config.root, mainFile)}`));
2290
+ console.log(pc2.dim(` renderer: ${path9.relative(config.root, rendererOutDir)}/`));
2291
+ console.log(pc2.dim(` main: ${path9.relative(config.root, mainFile)}`));
2179
2292
  for (const pf of preloadFiles) {
2180
- console.log(pc2.dim(` preload: ${path8.relative(config.root, pf)}`));
2293
+ console.log(pc2.dim(` preload: ${path9.relative(config.root, pf)}`));
2181
2294
  }
2182
2295
  console.log();
2183
2296
  return { rendererOutDir, mainFile, preloadFiles };
@@ -2201,14 +2314,16 @@ async function bundleNode(config, entry, opts) {
2201
2314
  return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
2202
2315
  }
2203
2316
  };
2317
+ const existingTransform = config.build.rolldownOptions?.transform;
2318
+ const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
2204
2319
  const bundle = await rolldown2({
2205
2320
  input: entry,
2206
- define: envDefine,
2321
+ transform: { ...existingTransform, define: mergedDefine },
2207
2322
  platform: "node",
2208
2323
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
2209
2324
  ...config.build.rolldownOptions
2210
2325
  });
2211
- fs7.mkdirSync(path8.dirname(opts.outFile), { recursive: true });
2326
+ fs7.mkdirSync(path9.dirname(opts.outFile), { recursive: true });
2212
2327
  await bundle.write({
2213
2328
  file: opts.outFile,
2214
2329
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -2217,16 +2332,16 @@ async function bundleNode(config, entry, opts) {
2217
2332
  codeSplitting: false
2218
2333
  });
2219
2334
  await bundle.close();
2220
- console.log(pc2.dim(` \u2713 ${opts.label} \u2192 ${path8.relative(config.root, opts.outFile)}`));
2335
+ console.log(pc2.dim(` \u2713 ${opts.label} \u2192 ${path9.relative(config.root, opts.outFile)}`));
2221
2336
  return opts.outFile;
2222
2337
  }
2223
2338
  function outFileName(outDir, base, format) {
2224
2339
  const ext = format === "cjs" ? ".cjs" : ".mjs";
2225
- return path8.join(outDir, base + ext);
2340
+ return path9.join(outDir, base + ext);
2226
2341
  }
2227
2342
  function normalizePreload(preload, root) {
2228
2343
  const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
2229
- return list.map((p) => path8.resolve(root, p));
2344
+ return list.map((p) => path9.resolve(root, p));
2230
2345
  }
2231
2346
  function assertElectronVersion(config) {
2232
2347
  const min = config.electron.minVersion;
@@ -2241,7 +2356,7 @@ function assertElectronVersion(config) {
2241
2356
  }
2242
2357
  function detectInstalledElectron(root) {
2243
2358
  try {
2244
- const pkgPath = path8.resolve(root, "node_modules/electron/package.json");
2359
+ const pkgPath = path9.resolve(root, "node_modules/electron/package.json");
2245
2360
  if (!fs7.existsSync(pkgPath)) return null;
2246
2361
  const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
2247
2362
  const major = parseInt(String(pkg.version).split(".")[0], 10);
@@ -2256,9 +2371,9 @@ init_server();
2256
2371
 
2257
2372
  // src/server/electron-dev.ts
2258
2373
  init_config();
2259
- import path12 from "path";
2374
+ import path13 from "path";
2260
2375
  import fs10 from "fs";
2261
- import { createRequire as createRequire3 } from "module";
2376
+ import { createRequire as createRequire4 } from "module";
2262
2377
  import { spawn } from "child_process";
2263
2378
  import chokidar from "chokidar";
2264
2379
  import pc4 from "picocolors";
@@ -2270,17 +2385,17 @@ async function startElectronDev(inlineConfig = {}) {
2270
2385
  const { noSpawn, ...rest } = inlineConfig;
2271
2386
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2272
2387
  warnElectronVersion(config);
2273
- console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.3"}`));
2388
+ console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.5"}`));
2274
2389
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2275
2390
  const server = await createServer2({ ...rest, target: "electron" });
2276
2391
  await server.listen();
2277
2392
  const devUrl = `http://localhost:${server.config.server.port}/`;
2278
2393
  console.log(pc4.dim(` renderer: ${devUrl}`));
2279
- const stageDir = path12.resolve(config.root, ".nasti");
2394
+ const stageDir = path13.resolve(config.root, ".nasti");
2280
2395
  fs10.mkdirSync(stageDir, { recursive: true });
2281
- const mainEntry = path12.resolve(config.root, config.electron.main);
2396
+ const mainEntry = path13.resolve(config.root, config.electron.main);
2282
2397
  const preloadEntries = normalizePreload(config.electron.preload, config.root);
2283
- const builtMainFile = path12.join(stageDir, "main" + extFor(config.electron.mainFormat));
2398
+ const builtMainFile = path13.join(stageDir, "main" + extFor(config.electron.mainFormat));
2284
2399
  const builtPreloadFiles = [];
2285
2400
  const compileAll = async () => {
2286
2401
  await compileNode(config, mainEntry, {
@@ -2291,8 +2406,8 @@ async function startElectronDev(inlineConfig = {}) {
2291
2406
  builtPreloadFiles.length = 0;
2292
2407
  for (const entry of preloadEntries) {
2293
2408
  if (!fs10.existsSync(entry)) continue;
2294
- const base = path12.basename(entry).replace(/\.[^.]+$/, "");
2295
- const out = path12.join(stageDir, base + extFor(config.electron.preloadFormat));
2409
+ const base = path13.basename(entry).replace(/\.[^.]+$/, "");
2410
+ const out = path13.join(stageDir, base + extFor(config.electron.preloadFormat));
2296
2411
  await compileNode(config, entry, {
2297
2412
  outFile: out,
2298
2413
  format: config.electron.preloadFormat,
@@ -2407,7 +2522,7 @@ async function compileNode(config, entry, opts) {
2407
2522
  platform: "node",
2408
2523
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
2409
2524
  });
2410
- fs10.mkdirSync(path12.dirname(opts.outFile), { recursive: true });
2525
+ fs10.mkdirSync(path13.dirname(opts.outFile), { recursive: true });
2411
2526
  await bundle.write({
2412
2527
  file: opts.outFile,
2413
2528
  format: opts.format === "cjs" ? "cjs" : "esm",
@@ -2424,7 +2539,7 @@ function resolveElectronBinary(config) {
2424
2539
  return config.electron.electronPath;
2425
2540
  }
2426
2541
  try {
2427
- const require2 = createRequire3(path12.resolve(config.root, "package.json"));
2542
+ const require2 = createRequire4(path13.resolve(config.root, "package.json"));
2428
2543
  const pathFile = require2.resolve("electron");
2429
2544
  const electronModule = require2(pathFile);
2430
2545
  if (typeof electronModule === "string" && fs10.existsSync(electronModule)) {
@@ -2454,10 +2569,10 @@ function warnElectronVersion(config) {
2454
2569
  }
2455
2570
 
2456
2571
  // src/plugins/monaco-editor.ts
2457
- import path13 from "path";
2572
+ import path14 from "path";
2458
2573
  import fs11 from "fs";
2459
2574
  import crypto2 from "crypto";
2460
- import { createRequire as createRequire4 } from "module";
2575
+ import { createRequire as createRequire5 } from "module";
2461
2576
  var DEFAULT_WORKERS = {
2462
2577
  editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
2463
2578
  css: "monaco-editor/esm/vs/language/css/css.worker",
@@ -2476,7 +2591,7 @@ function normalizePublicPath(p) {
2476
2591
  }
2477
2592
  function readMonacoVersion(root) {
2478
2593
  try {
2479
- const require2 = createRequire4(path13.resolve(root, "package.json"));
2594
+ const require2 = createRequire5(path14.resolve(root, "package.json"));
2480
2595
  const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
2481
2596
  const pkg = JSON.parse(fs11.readFileSync(pkgJsonPath, "utf-8"));
2482
2597
  return typeof pkg.version === "string" ? pkg.version : "unknown";
@@ -2498,13 +2613,13 @@ function monacoEditorPlugin(options = {}) {
2498
2613
  let cacheDir = "";
2499
2614
  const building = /* @__PURE__ */ new Map();
2500
2615
  async function buildWorker(worker) {
2501
- const cacheFile = path13.join(cacheDir, `${worker.label}.worker.js`);
2616
+ const cacheFile = path14.join(cacheDir, `${worker.label}.worker.js`);
2502
2617
  if (fs11.existsSync(cacheFile)) return cacheFile;
2503
2618
  const existing = building.get(worker.label);
2504
2619
  if (existing) return existing;
2505
2620
  const task = (async () => {
2506
2621
  const { rolldown: rolldown4 } = await import("rolldown");
2507
- const require2 = createRequire4(path13.resolve(resolvedConfig.root, "package.json"));
2622
+ const require2 = createRequire5(path14.resolve(resolvedConfig.root, "package.json"));
2508
2623
  let entry;
2509
2624
  try {
2510
2625
  entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
@@ -2571,12 +2686,12 @@ function monacoEditorPlugin(options = {}) {
2571
2686
  resolvedConfig = config;
2572
2687
  const version = readMonacoVersion(config.root);
2573
2688
  const key = crypto2.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
2574
- cacheDir = path13.resolve(config.root, "node_modules/.nasti/monaco", key);
2689
+ cacheDir = path14.resolve(config.root, "node_modules/.nasti/monaco", key);
2575
2690
  },
2576
2691
  async configureServer(server) {
2577
2692
  const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
2578
2693
  const watcher = server.watcher;
2579
- const monacoDir = path13.resolve(resolvedConfig.root, "node_modules/monaco-editor");
2694
+ const monacoDir = path14.resolve(resolvedConfig.root, "node_modules/monaco-editor");
2580
2695
  try {
2581
2696
  watcher?.unwatch?.(monacoDir);
2582
2697
  } catch {
@@ -2641,7 +2756,7 @@ self.monaco = monaco;`,
2641
2756
  resolvedConfig.root,
2642
2757
  resolvedConfig.build.outDir,
2643
2758
  resolvedConfig.base
2644
- ) : isCDN(publicPath) ? path13.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : path13.resolve(
2759
+ ) : isCDN(publicPath) ? path14.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : path14.resolve(
2645
2760
  resolvedConfig.root,
2646
2761
  resolvedConfig.build.outDir,
2647
2762
  publicPath.replace(/^\//, "")
@@ -2650,7 +2765,7 @@ self.monaco = monaco;`,
2650
2765
  for (const worker of workers) {
2651
2766
  try {
2652
2767
  const cacheFile = await buildWorker(worker);
2653
- fs11.copyFileSync(cacheFile, path13.join(outDir, `${worker.label}.worker.js`));
2768
+ fs11.copyFileSync(cacheFile, path14.join(outDir, `${worker.label}.worker.js`));
2654
2769
  } catch (e) {
2655
2770
  throw new Error(
2656
2771
  `[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}