@nasti-toolchain/nasti 1.6.2 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +181 -72
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +171 -62
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +235 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +224 -115
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -376,6 +376,59 @@ var init_resolve = __esm({
|
|
|
376
376
|
}
|
|
377
377
|
});
|
|
378
378
|
|
|
379
|
+
// src/plugins/tailwind.ts
|
|
380
|
+
function hasTailwindDirectives(css) {
|
|
381
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
382
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
383
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
384
|
+
}
|
|
385
|
+
async function loadTailwind(projectRoot) {
|
|
386
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
387
|
+
const req = (0, import_node_module2.createRequire)(import_node_path3.default.join(projectRoot, "package.json"));
|
|
388
|
+
let nodePath;
|
|
389
|
+
let oxidePath;
|
|
390
|
+
try {
|
|
391
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
392
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
393
|
+
} catch {
|
|
394
|
+
throw new Error(
|
|
395
|
+
"[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"
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
const node = await import((0, import_node_url2.pathToFileURL)(nodePath).href);
|
|
399
|
+
const oxide = await import((0, import_node_url2.pathToFileURL)(oxidePath).href);
|
|
400
|
+
cached = { node, oxide };
|
|
401
|
+
cachedRoot = projectRoot;
|
|
402
|
+
return cached;
|
|
403
|
+
}
|
|
404
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
405
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
406
|
+
const dependencies = [];
|
|
407
|
+
const compiler = await node.compile(css, {
|
|
408
|
+
base: import_node_path3.default.dirname(fromFile),
|
|
409
|
+
from: fromFile,
|
|
410
|
+
onDependency: (p) => dependencies.push(p)
|
|
411
|
+
});
|
|
412
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
413
|
+
const candidates = scanner.scan();
|
|
414
|
+
return {
|
|
415
|
+
css: compiler.build(candidates),
|
|
416
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
var import_node_path3, import_node_module2, import_node_url2, TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
420
|
+
var init_tailwind = __esm({
|
|
421
|
+
"src/plugins/tailwind.ts"() {
|
|
422
|
+
"use strict";
|
|
423
|
+
import_node_path3 = __toESM(require("path"), 1);
|
|
424
|
+
import_node_module2 = require("module");
|
|
425
|
+
import_node_url2 = require("url");
|
|
426
|
+
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)/;
|
|
427
|
+
cached = null;
|
|
428
|
+
cachedRoot = null;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
379
432
|
// src/plugins/css.ts
|
|
380
433
|
function cssPlugin(config) {
|
|
381
434
|
return {
|
|
@@ -384,9 +437,14 @@ function cssPlugin(config) {
|
|
|
384
437
|
if (source.endsWith(".css")) return null;
|
|
385
438
|
return null;
|
|
386
439
|
},
|
|
387
|
-
transform(code, id) {
|
|
440
|
+
async transform(code, id) {
|
|
388
441
|
if (!id.endsWith(".css")) return null;
|
|
389
|
-
|
|
442
|
+
let cssSource = code;
|
|
443
|
+
if (hasTailwindDirectives(code)) {
|
|
444
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
445
|
+
cssSource = compiled.css;
|
|
446
|
+
}
|
|
447
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
390
448
|
if (config.command === "serve") {
|
|
391
449
|
const escaped = JSON.stringify(rewritten);
|
|
392
450
|
return {
|
|
@@ -421,16 +479,17 @@ function rewriteCssUrls(css, from, root) {
|
|
|
421
479
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
422
480
|
return match;
|
|
423
481
|
}
|
|
424
|
-
const resolved =
|
|
425
|
-
const relative = "/" +
|
|
482
|
+
const resolved = import_node_path4.default.resolve(import_node_path4.default.dirname(from), url);
|
|
483
|
+
const relative = "/" + import_node_path4.default.relative(root, resolved);
|
|
426
484
|
return `url(${relative})`;
|
|
427
485
|
});
|
|
428
486
|
}
|
|
429
|
-
var
|
|
487
|
+
var import_node_path4;
|
|
430
488
|
var init_css = __esm({
|
|
431
489
|
"src/plugins/css.ts"() {
|
|
432
490
|
"use strict";
|
|
433
|
-
|
|
491
|
+
import_node_path4 = __toESM(require("path"), 1);
|
|
492
|
+
init_tailwind();
|
|
434
493
|
}
|
|
435
494
|
});
|
|
436
495
|
|
|
@@ -445,7 +504,7 @@ function assetsPlugin(config) {
|
|
|
445
504
|
return null;
|
|
446
505
|
},
|
|
447
506
|
load(id) {
|
|
448
|
-
const ext =
|
|
507
|
+
const ext = import_node_path5.default.extname(id.replace(/\?.*$/, ""));
|
|
449
508
|
if (id.endsWith("?raw")) {
|
|
450
509
|
const file = id.slice(0, -4);
|
|
451
510
|
if (import_node_fs3.default.existsSync(file)) {
|
|
@@ -457,12 +516,12 @@ function assetsPlugin(config) {
|
|
|
457
516
|
const file = id.replace(/\?.*$/, "");
|
|
458
517
|
if (!import_node_fs3.default.existsSync(file)) return null;
|
|
459
518
|
if (config.command === "serve") {
|
|
460
|
-
const url = "/" +
|
|
519
|
+
const url = "/" + import_node_path5.default.relative(config.root, file);
|
|
461
520
|
return `export default ${JSON.stringify(url)}`;
|
|
462
521
|
}
|
|
463
522
|
const content = import_node_fs3.default.readFileSync(file);
|
|
464
523
|
const hash = import_node_crypto.default.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
465
|
-
const basename =
|
|
524
|
+
const basename = import_node_path5.default.basename(file, ext);
|
|
466
525
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
467
526
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
468
527
|
}
|
|
@@ -470,11 +529,11 @@ function assetsPlugin(config) {
|
|
|
470
529
|
}
|
|
471
530
|
};
|
|
472
531
|
}
|
|
473
|
-
var
|
|
532
|
+
var import_node_path5, import_node_fs3, import_node_crypto, ASSET_EXTENSIONS;
|
|
474
533
|
var init_assets = __esm({
|
|
475
534
|
"src/plugins/assets.ts"() {
|
|
476
535
|
"use strict";
|
|
477
|
-
|
|
536
|
+
import_node_path5 = __toESM(require("path"), 1);
|
|
478
537
|
import_node_fs3 = __toESM(require("fs"), 1);
|
|
479
538
|
import_node_crypto = __toESM(require("crypto"), 1);
|
|
480
539
|
ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -567,15 +626,15 @@ function serializeTag(tag) {
|
|
|
567
626
|
return ` <${tag.tag}${attrs}>${children}</${tag.tag}>`;
|
|
568
627
|
}
|
|
569
628
|
async function readHtmlFile(root) {
|
|
570
|
-
const htmlPath =
|
|
629
|
+
const htmlPath = import_node_path6.default.resolve(root, "index.html");
|
|
571
630
|
if (!import_node_fs4.default.existsSync(htmlPath)) return null;
|
|
572
631
|
return import_node_fs4.default.readFileSync(htmlPath, "utf-8");
|
|
573
632
|
}
|
|
574
|
-
var
|
|
633
|
+
var import_node_path6, import_node_fs4, REACT_REFRESH_HTML_PREAMBLE;
|
|
575
634
|
var init_html = __esm({
|
|
576
635
|
"src/plugins/html.ts"() {
|
|
577
636
|
"use strict";
|
|
578
|
-
|
|
637
|
+
import_node_path6 = __toESM(require("path"), 1);
|
|
579
638
|
import_node_fs4 = __toESM(require("fs"), 1);
|
|
580
639
|
REACT_REFRESH_HTML_PREAMBLE = `
|
|
581
640
|
import RefreshRuntime from "/@react-refresh";
|
|
@@ -634,7 +693,7 @@ function loadEnv(mode, root, prefixes) {
|
|
|
634
693
|
];
|
|
635
694
|
const raw = {};
|
|
636
695
|
for (const file of envFiles) {
|
|
637
|
-
const filePath =
|
|
696
|
+
const filePath = import_node_path7.default.resolve(root, file);
|
|
638
697
|
if (!import_node_fs5.default.existsSync(filePath)) continue;
|
|
639
698
|
const content = import_node_fs5.default.readFileSync(filePath, "utf-8");
|
|
640
699
|
for (const line of content.split("\n")) {
|
|
@@ -677,11 +736,11 @@ function replaceEnvInCode(code, define) {
|
|
|
677
736
|
}
|
|
678
737
|
return result;
|
|
679
738
|
}
|
|
680
|
-
var
|
|
739
|
+
var import_node_path7, import_node_fs5;
|
|
681
740
|
var init_env = __esm({
|
|
682
741
|
"src/core/env.ts"() {
|
|
683
742
|
"use strict";
|
|
684
|
-
|
|
743
|
+
import_node_path7 = __toESM(require("path"), 1);
|
|
685
744
|
import_node_fs5 = __toESM(require("fs"), 1);
|
|
686
745
|
}
|
|
687
746
|
});
|
|
@@ -814,10 +873,10 @@ __export(build_exports, {
|
|
|
814
873
|
async function build(inlineConfig = {}) {
|
|
815
874
|
const config = await resolveConfig(inlineConfig, "build");
|
|
816
875
|
const startTime = performance.now();
|
|
817
|
-
console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.
|
|
876
|
+
console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.6.4"}`));
|
|
818
877
|
console.log(import_picocolors.default.dim(` root: ${config.root}`));
|
|
819
878
|
console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
|
|
820
|
-
const outDir =
|
|
879
|
+
const outDir = import_node_path8.default.resolve(config.root, config.build.outDir);
|
|
821
880
|
if (config.build.emptyOutDir && import_node_fs6.default.existsSync(outDir)) {
|
|
822
881
|
import_node_fs6.default.rmSync(outDir, { recursive: true, force: true });
|
|
823
882
|
}
|
|
@@ -829,14 +888,14 @@ async function build(inlineConfig = {}) {
|
|
|
829
888
|
for (const match of scriptMatches) {
|
|
830
889
|
const src = match[1];
|
|
831
890
|
if (src && !src.startsWith("http")) {
|
|
832
|
-
entryPoints.push(
|
|
891
|
+
entryPoints.push(import_node_path8.default.resolve(config.root, src.replace(/^\//, "")));
|
|
833
892
|
}
|
|
834
893
|
}
|
|
835
894
|
}
|
|
836
895
|
if (entryPoints.length === 0) {
|
|
837
896
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
838
897
|
for (const entry of fallbackEntries) {
|
|
839
|
-
const fullPath =
|
|
898
|
+
const fullPath = import_node_path8.default.resolve(config.root, entry);
|
|
840
899
|
if (import_node_fs6.default.existsSync(fullPath)) {
|
|
841
900
|
entryPoints.push(fullPath);
|
|
842
901
|
break;
|
|
@@ -880,7 +939,11 @@ async function build(inlineConfig = {}) {
|
|
|
880
939
|
load: p.load,
|
|
881
940
|
transform: p.transform,
|
|
882
941
|
buildStart: p.buildStart,
|
|
883
|
-
buildEnd: p.buildEnd
|
|
942
|
+
buildEnd: p.buildEnd,
|
|
943
|
+
// Forward `closeBundle` to Rolldown — it invokes the hook during
|
|
944
|
+
// `bundle.close()` below. This is the hook Vite plugins (e.g. PWA
|
|
945
|
+
// manifest/SW writers) rely on for final-stage artifact emission.
|
|
946
|
+
closeBundle: p.closeBundle
|
|
884
947
|
}))
|
|
885
948
|
],
|
|
886
949
|
...config.build.rolldownOptions
|
|
@@ -897,8 +960,8 @@ async function build(inlineConfig = {}) {
|
|
|
897
960
|
await bundle.close();
|
|
898
961
|
await pluginContainer.buildEnd();
|
|
899
962
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
900
|
-
const dest =
|
|
901
|
-
import_node_fs6.default.mkdirSync(
|
|
963
|
+
const dest = import_node_path8.default.resolve(outDir, ef.fileName);
|
|
964
|
+
import_node_fs6.default.mkdirSync(import_node_path8.default.dirname(dest), { recursive: true });
|
|
902
965
|
import_node_fs6.default.writeFileSync(dest, ef.source);
|
|
903
966
|
}
|
|
904
967
|
if (html) {
|
|
@@ -916,14 +979,14 @@ async function build(inlineConfig = {}) {
|
|
|
916
979
|
}
|
|
917
980
|
for (const chunk of output) {
|
|
918
981
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
919
|
-
const originalEntry =
|
|
982
|
+
const originalEntry = import_node_path8.default.relative(config.root, chunk.facadeModuleId);
|
|
920
983
|
processedHtml = processedHtml.replace(
|
|
921
984
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
922
985
|
`$1${config.base}${chunk.fileName}$3`
|
|
923
986
|
);
|
|
924
987
|
}
|
|
925
988
|
}
|
|
926
|
-
import_node_fs6.default.writeFileSync(
|
|
989
|
+
import_node_fs6.default.writeFileSync(import_node_path8.default.resolve(outDir, "index.html"), processedHtml);
|
|
927
990
|
}
|
|
928
991
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
929
992
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -945,11 +1008,11 @@ function formatSize(bytes) {
|
|
|
945
1008
|
function escapeRegExp(string) {
|
|
946
1009
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
947
1010
|
}
|
|
948
|
-
var
|
|
1011
|
+
var import_node_path8, import_node_fs6, import_rolldown, import_picocolors;
|
|
949
1012
|
var init_build = __esm({
|
|
950
1013
|
"src/build/index.ts"() {
|
|
951
1014
|
"use strict";
|
|
952
|
-
|
|
1015
|
+
import_node_path8 = __toESM(require("path"), 1);
|
|
953
1016
|
import_node_fs6 = __toESM(require("fs"), 1);
|
|
954
1017
|
import_rolldown = require("rolldown");
|
|
955
1018
|
init_config();
|
|
@@ -1015,6 +1078,19 @@ var init_module_graph = __esm({
|
|
|
1015
1078
|
}
|
|
1016
1079
|
mods.add(mod);
|
|
1017
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Reindex a module under a plugin-provided canonical id (e.g. a `\0virtual:foo`
|
|
1083
|
+
* id returned from `resolveId`). Plugins look up their own virtual modules via
|
|
1084
|
+
* `getModuleById(RESOLVED_ID)` to invalidate them on watcher events; without
|
|
1085
|
+
* this remap they'd never find the node because `ensureEntryFromUrl` keys by
|
|
1086
|
+
* the public URL only.
|
|
1087
|
+
*/
|
|
1088
|
+
setModuleId(mod, id) {
|
|
1089
|
+
if (mod.id === id) return;
|
|
1090
|
+
this.idToModuleMap.delete(mod.id);
|
|
1091
|
+
mod.id = id;
|
|
1092
|
+
this.idToModuleMap.set(id, mod);
|
|
1093
|
+
}
|
|
1018
1094
|
/** 更新模块依赖关系 */
|
|
1019
1095
|
updateModuleImports(mod, importedIds) {
|
|
1020
1096
|
for (const imported of mod.importedModules) {
|
|
@@ -1133,9 +1209,9 @@ function getReactRefreshRuntimeEsm() {
|
|
|
1133
1209
|
let cjsPath;
|
|
1134
1210
|
try {
|
|
1135
1211
|
const pkgPath = __require.resolve("react-refresh/package.json");
|
|
1136
|
-
cjsPath =
|
|
1212
|
+
cjsPath = import_node_path10.default.join(import_node_path10.default.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
|
|
1137
1213
|
} catch (err) {
|
|
1138
|
-
cjsPath =
|
|
1214
|
+
cjsPath = import_node_path10.default.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
|
|
1139
1215
|
if (!import_node_fs8.default.existsSync(cjsPath)) {
|
|
1140
1216
|
const origMsg = err instanceof Error ? err.message : String(err);
|
|
1141
1217
|
throw new Error(
|
|
@@ -1275,13 +1351,23 @@ function transformMiddleware(ctx) {
|
|
|
1275
1351
|
async function transformRequest(url, ctx) {
|
|
1276
1352
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
1277
1353
|
const cleanReqUrl = url.split("?")[0];
|
|
1278
|
-
const
|
|
1279
|
-
if (
|
|
1280
|
-
return
|
|
1354
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
1355
|
+
if (cached2?.transformResult) {
|
|
1356
|
+
return cached2.transformResult;
|
|
1281
1357
|
}
|
|
1282
1358
|
if (cleanReqUrl === "/@react-refresh") {
|
|
1283
1359
|
return { code: getReactRefreshRuntimeEsm() };
|
|
1284
1360
|
}
|
|
1361
|
+
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1362
|
+
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
1363
|
+
const virtual = await loadVirtualModule(spec, ctx);
|
|
1364
|
+
if (virtual) {
|
|
1365
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
1366
|
+
moduleGraph.setModuleId(mod2, virtual.id);
|
|
1367
|
+
mod2.transformResult = virtual.result;
|
|
1368
|
+
return virtual.result;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1285
1371
|
const filePath = resolveUrlToFile(url, config.root);
|
|
1286
1372
|
if (!filePath || !import_node_fs8.default.existsSync(filePath)) return null;
|
|
1287
1373
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
@@ -1328,6 +1414,28 @@ async function transformRequest(url, ctx) {
|
|
|
1328
1414
|
mod.transformResult = transformResult;
|
|
1329
1415
|
return transformResult;
|
|
1330
1416
|
}
|
|
1417
|
+
async function loadVirtualModule(spec, ctx) {
|
|
1418
|
+
const { config, pluginContainer } = ctx;
|
|
1419
|
+
const resolved = await pluginContainer.resolveId(spec);
|
|
1420
|
+
if (resolved == null) return null;
|
|
1421
|
+
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
1422
|
+
const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs8.default.existsSync(resolvedId);
|
|
1423
|
+
if (!looksVirtual) return null;
|
|
1424
|
+
const loadResult = await pluginContainer.load(resolvedId);
|
|
1425
|
+
if (loadResult == null) return null;
|
|
1426
|
+
let code = typeof loadResult === "string" ? loadResult : loadResult.code;
|
|
1427
|
+
const transformed = await pluginContainer.transform(code, resolvedId);
|
|
1428
|
+
if (transformed != null) {
|
|
1429
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
1430
|
+
}
|
|
1431
|
+
code = replaceEnvInCode(code, ctx.envDefine ?? buildEnvDefine(
|
|
1432
|
+
loadEnv(config.mode, config.root, config.envPrefix),
|
|
1433
|
+
config.mode
|
|
1434
|
+
));
|
|
1435
|
+
const anchor = import_node_path10.default.join(config.root, "__nasti_virtual__.ts");
|
|
1436
|
+
code = rewriteImports(code, config, anchor);
|
|
1437
|
+
return { id: resolvedId, result: { code } };
|
|
1438
|
+
}
|
|
1331
1439
|
async function bundlePackageAsEsm(entryFile) {
|
|
1332
1440
|
if (!esmBundleCache.has(entryFile)) {
|
|
1333
1441
|
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
@@ -1367,13 +1475,13 @@ async function doBundlePackage(entryFile) {
|
|
|
1367
1475
|
return code;
|
|
1368
1476
|
}
|
|
1369
1477
|
async function tryGenerateSubpathShim(entryFile) {
|
|
1370
|
-
const NM = `${
|
|
1478
|
+
const NM = `${import_node_path10.default.sep}node_modules${import_node_path10.default.sep}`;
|
|
1371
1479
|
if (!entryFile.includes(NM)) return null;
|
|
1372
1480
|
let pkgDir = null;
|
|
1373
1481
|
let pkgName = null;
|
|
1374
|
-
let dir =
|
|
1482
|
+
let dir = import_node_path10.default.dirname(entryFile);
|
|
1375
1483
|
while (true) {
|
|
1376
|
-
const pkgJsonPath =
|
|
1484
|
+
const pkgJsonPath = import_node_path10.default.join(dir, "package.json");
|
|
1377
1485
|
if (import_node_fs8.default.existsSync(pkgJsonPath)) {
|
|
1378
1486
|
try {
|
|
1379
1487
|
const pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
@@ -1385,21 +1493,21 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
1385
1493
|
} catch {
|
|
1386
1494
|
}
|
|
1387
1495
|
}
|
|
1388
|
-
const parent =
|
|
1496
|
+
const parent = import_node_path10.default.dirname(dir);
|
|
1389
1497
|
if (parent === dir) return null;
|
|
1390
1498
|
dir = parent;
|
|
1391
1499
|
if (!dir.includes(NM)) return null;
|
|
1392
1500
|
}
|
|
1393
1501
|
if (!pkgDir || !pkgName) return null;
|
|
1394
|
-
const entryExt =
|
|
1502
|
+
const entryExt = import_node_path10.default.extname(entryFile);
|
|
1395
1503
|
const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
|
|
1396
1504
|
if (!mainEntry) return null;
|
|
1397
|
-
if (
|
|
1505
|
+
if (import_node_path10.default.resolve(mainEntry) === import_node_path10.default.resolve(entryFile)) return null;
|
|
1398
1506
|
let mainNs;
|
|
1399
1507
|
let subNs;
|
|
1400
1508
|
try {
|
|
1401
|
-
mainNs = await import((0,
|
|
1402
|
-
subNs = await import((0,
|
|
1509
|
+
mainNs = await import((0, import_node_url3.pathToFileURL)(mainEntry).href);
|
|
1510
|
+
subNs = await import((0, import_node_url3.pathToFileURL)(entryFile).href);
|
|
1403
1511
|
} catch {
|
|
1404
1512
|
return null;
|
|
1405
1513
|
}
|
|
@@ -1430,7 +1538,7 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
1430
1538
|
return lines.join("\n") + "\n";
|
|
1431
1539
|
}
|
|
1432
1540
|
function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
1433
|
-
const pkgJsonPath =
|
|
1541
|
+
const pkgJsonPath = import_node_path10.default.join(pkgDir, "package.json");
|
|
1434
1542
|
let pkg;
|
|
1435
1543
|
try {
|
|
1436
1544
|
pkg = JSON.parse(import_node_fs8.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
@@ -1452,13 +1560,13 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
1452
1560
|
if (typeof pkg.module === "string") candidates.push(pkg.module);
|
|
1453
1561
|
if (typeof pkg.main === "string") candidates.push(pkg.main);
|
|
1454
1562
|
for (const cand of candidates) {
|
|
1455
|
-
if (
|
|
1456
|
-
const full =
|
|
1563
|
+
if (import_node_path10.default.extname(cand) === preferredExt) {
|
|
1564
|
+
const full = import_node_path10.default.resolve(pkgDir, cand);
|
|
1457
1565
|
if (import_node_fs8.default.existsSync(full)) return full;
|
|
1458
1566
|
}
|
|
1459
1567
|
}
|
|
1460
1568
|
for (const cand of candidates) {
|
|
1461
|
-
const full =
|
|
1569
|
+
const full = import_node_path10.default.resolve(pkgDir, cand);
|
|
1462
1570
|
if (import_node_fs8.default.existsSync(full)) return full;
|
|
1463
1571
|
}
|
|
1464
1572
|
return null;
|
|
@@ -1484,19 +1592,20 @@ function rewriteExternalRequires(code) {
|
|
|
1484
1592
|
}
|
|
1485
1593
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1486
1594
|
try {
|
|
1487
|
-
const { createRequire:
|
|
1488
|
-
const req =
|
|
1595
|
+
const { createRequire: createRequire6 } = await import("module");
|
|
1596
|
+
const req = createRequire6(entryFile);
|
|
1489
1597
|
const cjsExports = req(entryFile);
|
|
1490
1598
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1491
1599
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1492
1600
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1493
1601
|
);
|
|
1494
|
-
|
|
1602
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1603
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1495
1604
|
return code.replace(
|
|
1496
1605
|
/^export default (\w+\(\));?\s*$/m,
|
|
1497
1606
|
(_, call) => [
|
|
1498
1607
|
`const __cjsMod = ${call};`,
|
|
1499
|
-
`export default __cjsMod;`,
|
|
1608
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1500
1609
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1501
1610
|
].join("\n")
|
|
1502
1611
|
);
|
|
@@ -1506,11 +1615,11 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1506
1615
|
}
|
|
1507
1616
|
function rewriteImports(code, config, filePath) {
|
|
1508
1617
|
const root = config.root;
|
|
1509
|
-
const fileDir =
|
|
1618
|
+
const fileDir = import_node_path10.default.dirname(filePath);
|
|
1510
1619
|
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1511
1620
|
([a], [b]) => b.length - a.length
|
|
1512
1621
|
);
|
|
1513
|
-
const toRootUrl = (abs) => "/" +
|
|
1622
|
+
const toRootUrl = (abs) => "/" + import_node_path10.default.relative(root, abs).replace(/\\/g, "/");
|
|
1514
1623
|
const transformSpec = (spec) => {
|
|
1515
1624
|
const suffixMatch = spec.match(/[?#].*$/);
|
|
1516
1625
|
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
@@ -1519,18 +1628,18 @@ function rewriteImports(code, config, filePath) {
|
|
|
1519
1628
|
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1520
1629
|
const aliasBase = resolveAliasTarget(value, root);
|
|
1521
1630
|
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1522
|
-
const target = sub ?
|
|
1631
|
+
const target = sub ? import_node_path10.default.join(aliasBase, sub) : aliasBase;
|
|
1523
1632
|
const resolved = tryResolveDiskPath(target);
|
|
1524
1633
|
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1525
1634
|
}
|
|
1526
1635
|
}
|
|
1527
1636
|
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1528
|
-
const target =
|
|
1637
|
+
const target = import_node_path10.default.resolve(fileDir, baseSpec);
|
|
1529
1638
|
const resolved = tryResolveDiskPath(target);
|
|
1530
1639
|
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1531
1640
|
}
|
|
1532
1641
|
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1533
|
-
const target =
|
|
1642
|
+
const target = import_node_path10.default.join(root, baseSpec.replace(/^\//, ""));
|
|
1534
1643
|
const resolved = tryResolveDiskPath(target);
|
|
1535
1644
|
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1536
1645
|
}
|
|
@@ -1549,9 +1658,9 @@ function rewriteImports(code, config, filePath) {
|
|
|
1549
1658
|
);
|
|
1550
1659
|
}
|
|
1551
1660
|
function resolveAliasTarget(value, root) {
|
|
1552
|
-
if (
|
|
1553
|
-
if (value.startsWith("/")) return
|
|
1554
|
-
return
|
|
1661
|
+
if (import_node_path10.default.isAbsolute(value) && import_node_fs8.default.existsSync(value)) return value;
|
|
1662
|
+
if (value.startsWith("/")) return import_node_path10.default.join(root, value.slice(1));
|
|
1663
|
+
return import_node_path10.default.resolve(root, value);
|
|
1555
1664
|
}
|
|
1556
1665
|
function tryResolveDiskPath(target) {
|
|
1557
1666
|
if (import_node_fs8.default.existsSync(target) && import_node_fs8.default.statSync(target).isFile()) return target;
|
|
@@ -1561,15 +1670,15 @@ function tryResolveDiskPath(target) {
|
|
|
1561
1670
|
}
|
|
1562
1671
|
if (import_node_fs8.default.existsSync(target) && import_node_fs8.default.statSync(target).isDirectory()) {
|
|
1563
1672
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1564
|
-
const idx =
|
|
1673
|
+
const idx = import_node_path10.default.join(target, "index" + ext);
|
|
1565
1674
|
if (import_node_fs8.default.existsSync(idx) && import_node_fs8.default.statSync(idx).isFile()) return idx;
|
|
1566
1675
|
}
|
|
1567
1676
|
}
|
|
1568
1677
|
return null;
|
|
1569
1678
|
}
|
|
1570
1679
|
function isUnderRoot(abs, root) {
|
|
1571
|
-
const rel =
|
|
1572
|
-
return !!rel && !rel.startsWith("..") && !
|
|
1680
|
+
const rel = import_node_path10.default.relative(root, abs);
|
|
1681
|
+
return !!rel && !rel.startsWith("..") && !import_node_path10.default.isAbsolute(rel);
|
|
1573
1682
|
}
|
|
1574
1683
|
function resolveNodeModule(root, moduleName) {
|
|
1575
1684
|
let pkgName;
|
|
@@ -1586,17 +1695,17 @@ function resolveNodeModule(root, moduleName) {
|
|
|
1586
1695
|
let pkgDir = null;
|
|
1587
1696
|
let dir = root;
|
|
1588
1697
|
for (; ; ) {
|
|
1589
|
-
const candidate =
|
|
1698
|
+
const candidate = import_node_path10.default.join(dir, "node_modules", pkgName);
|
|
1590
1699
|
if (import_node_fs8.default.existsSync(candidate)) {
|
|
1591
1700
|
pkgDir = candidate;
|
|
1592
1701
|
break;
|
|
1593
1702
|
}
|
|
1594
|
-
const parent =
|
|
1703
|
+
const parent = import_node_path10.default.dirname(dir);
|
|
1595
1704
|
if (parent === dir) break;
|
|
1596
1705
|
dir = parent;
|
|
1597
1706
|
}
|
|
1598
1707
|
if (!pkgDir) return null;
|
|
1599
|
-
const pkgJsonPath =
|
|
1708
|
+
const pkgJsonPath = import_node_path10.default.join(pkgDir, "package.json");
|
|
1600
1709
|
if (!import_node_fs8.default.existsSync(pkgJsonPath)) return null;
|
|
1601
1710
|
let pkg;
|
|
1602
1711
|
try {
|
|
@@ -1613,12 +1722,12 @@ function resolveNodeModule(root, moduleName) {
|
|
|
1613
1722
|
const subDirs = [""];
|
|
1614
1723
|
for (const field of ["module", "main"]) {
|
|
1615
1724
|
if (typeof pkg[field] === "string") {
|
|
1616
|
-
const dir2 =
|
|
1725
|
+
const dir2 = import_node_path10.default.dirname(pkg[field]);
|
|
1617
1726
|
if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
|
|
1618
1727
|
}
|
|
1619
1728
|
}
|
|
1620
1729
|
for (const dir2 of subDirs) {
|
|
1621
|
-
const direct =
|
|
1730
|
+
const direct = import_node_path10.default.join(pkgDir, dir2, subpath);
|
|
1622
1731
|
if (import_node_fs8.default.existsSync(direct) && import_node_fs8.default.statSync(direct).isFile()) return direct;
|
|
1623
1732
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1624
1733
|
if (import_node_fs8.default.existsSync(direct + ext)) return direct + ext;
|
|
@@ -1628,24 +1737,24 @@ function resolveNodeModule(root, moduleName) {
|
|
|
1628
1737
|
}
|
|
1629
1738
|
for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
|
|
1630
1739
|
if (typeof pkg[field] === "string") {
|
|
1631
|
-
const entry =
|
|
1740
|
+
const entry = import_node_path10.default.join(pkgDir, pkg[field]);
|
|
1632
1741
|
if (import_node_fs8.default.existsSync(entry)) return entry;
|
|
1633
1742
|
}
|
|
1634
1743
|
}
|
|
1635
|
-
const indexFallback =
|
|
1744
|
+
const indexFallback = import_node_path10.default.join(pkgDir, "index.js");
|
|
1636
1745
|
if (import_node_fs8.default.existsSync(indexFallback)) return indexFallback;
|
|
1637
1746
|
return null;
|
|
1638
1747
|
}
|
|
1639
1748
|
function resolvePackageExports(exports2, key, pkgDir) {
|
|
1640
1749
|
if (typeof exports2 === "string") {
|
|
1641
|
-
return key === "." ?
|
|
1750
|
+
return key === "." ? import_node_path10.default.join(pkgDir, exports2) : null;
|
|
1642
1751
|
}
|
|
1643
1752
|
const entry = exports2[key];
|
|
1644
1753
|
if (entry === void 0) return null;
|
|
1645
1754
|
return resolveExportValue(entry, pkgDir);
|
|
1646
1755
|
}
|
|
1647
1756
|
function resolveExportValue(value, pkgDir) {
|
|
1648
|
-
if (typeof value === "string") return
|
|
1757
|
+
if (typeof value === "string") return import_node_path10.default.join(pkgDir, value);
|
|
1649
1758
|
if (Array.isArray(value)) {
|
|
1650
1759
|
for (const item of value) {
|
|
1651
1760
|
const r = resolveExportValue(item, pkgDir);
|
|
@@ -1669,7 +1778,7 @@ function resolveUrlToFile(url, root) {
|
|
|
1669
1778
|
const moduleName = cleanUrl.slice("/@modules/".length);
|
|
1670
1779
|
return resolveNodeModule(root, moduleName);
|
|
1671
1780
|
}
|
|
1672
|
-
const filePath =
|
|
1781
|
+
const filePath = import_node_path10.default.resolve(root, cleanUrl.replace(/^\//, ""));
|
|
1673
1782
|
if (import_node_fs8.default.existsSync(filePath) && import_node_fs8.default.statSync(filePath).isFile()) {
|
|
1674
1783
|
return filePath;
|
|
1675
1784
|
}
|
|
@@ -1678,7 +1787,7 @@ function resolveUrlToFile(url, root) {
|
|
|
1678
1787
|
if (import_node_fs8.default.existsSync(withExt)) return withExt;
|
|
1679
1788
|
}
|
|
1680
1789
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1681
|
-
const indexFile =
|
|
1790
|
+
const indexFile = import_node_path10.default.join(filePath, "index" + ext);
|
|
1682
1791
|
if (import_node_fs8.default.existsSync(indexFile)) return indexFile;
|
|
1683
1792
|
}
|
|
1684
1793
|
return null;
|
|
@@ -1687,7 +1796,7 @@ function isModuleRequest(url) {
|
|
|
1687
1796
|
const cleanUrl = url.split("?")[0];
|
|
1688
1797
|
if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
|
|
1689
1798
|
if (cleanUrl.startsWith("/@modules/")) return true;
|
|
1690
|
-
if (!
|
|
1799
|
+
if (!import_node_path10.default.extname(cleanUrl)) return true;
|
|
1691
1800
|
return false;
|
|
1692
1801
|
}
|
|
1693
1802
|
function getHmrClientCode() {
|
|
@@ -1818,20 +1927,20 @@ export function createHotContext(ownerPath) {
|
|
|
1818
1927
|
}
|
|
1819
1928
|
`;
|
|
1820
1929
|
}
|
|
1821
|
-
var
|
|
1930
|
+
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;
|
|
1822
1931
|
var init_middleware = __esm({
|
|
1823
1932
|
"src/server/middleware.ts"() {
|
|
1824
1933
|
"use strict";
|
|
1825
|
-
|
|
1934
|
+
import_node_path10 = __toESM(require("path"), 1);
|
|
1826
1935
|
import_node_fs8 = __toESM(require("fs"), 1);
|
|
1827
|
-
|
|
1828
|
-
|
|
1936
|
+
import_node_module4 = require("module");
|
|
1937
|
+
import_node_url3 = require("url");
|
|
1829
1938
|
init_transformer();
|
|
1830
1939
|
init_html();
|
|
1831
1940
|
init_env();
|
|
1832
1941
|
import_meta = {};
|
|
1833
|
-
__dirname_esm =
|
|
1834
|
-
__require = (0,
|
|
1942
|
+
__dirname_esm = import_node_path10.default.dirname((0, import_node_url3.fileURLToPath)(import_meta.url));
|
|
1943
|
+
__require = (0, import_node_module4.createRequire)(import_meta.url);
|
|
1835
1944
|
__refreshRuntimeCache = null;
|
|
1836
1945
|
REACT_REFRESH_GLOBAL_PREAMBLE = `
|
|
1837
1946
|
import RefreshRuntime from "/@react-refresh";
|
|
@@ -1850,7 +1959,7 @@ window.__vite_plugin_react_preamble_installed__ = true;
|
|
|
1850
1959
|
// src/server/hmr.ts
|
|
1851
1960
|
async function handleFileChange(file, server) {
|
|
1852
1961
|
const { moduleGraph, ws, config } = server;
|
|
1853
|
-
const relativePath = "/" +
|
|
1962
|
+
const relativePath = "/" + import_node_path11.default.relative(config.root, file);
|
|
1854
1963
|
const mods = moduleGraph.getModulesByFile(file);
|
|
1855
1964
|
if (!mods || mods.size === 0) {
|
|
1856
1965
|
return;
|
|
@@ -1895,11 +2004,11 @@ async function handleFileChange(file, server) {
|
|
|
1895
2004
|
ws.send({ type: "update", updates });
|
|
1896
2005
|
}
|
|
1897
2006
|
}
|
|
1898
|
-
var
|
|
2007
|
+
var import_node_path11, import_node_fs9;
|
|
1899
2008
|
var init_hmr = __esm({
|
|
1900
2009
|
"src/server/hmr.ts"() {
|
|
1901
2010
|
"use strict";
|
|
1902
|
-
|
|
2011
|
+
import_node_path11 = __toESM(require("path"), 1);
|
|
1903
2012
|
import_node_fs9 = __toESM(require("fs"), 1);
|
|
1904
2013
|
}
|
|
1905
2014
|
});
|
|
@@ -1927,20 +2036,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1927
2036
|
pluginContainer,
|
|
1928
2037
|
moduleGraph
|
|
1929
2038
|
}));
|
|
1930
|
-
const publicDir =
|
|
2039
|
+
const publicDir = import_node_path12.default.resolve(config.root, "public");
|
|
1931
2040
|
app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
|
|
1932
2041
|
app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
|
|
1933
2042
|
const httpServer = import_node_http.default.createServer(app);
|
|
1934
2043
|
const ws = createWebSocketServer(httpServer);
|
|
1935
2044
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1936
|
-
const outDirAbs =
|
|
2045
|
+
const outDirAbs = import_node_path12.default.resolve(config.root, config.build.outDir);
|
|
1937
2046
|
const watcher = (0, import_chokidar.watch)(config.root, {
|
|
1938
2047
|
ignored: (filePath) => {
|
|
1939
2048
|
if (filePath === config.root) return false;
|
|
1940
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
1941
|
-
const rel =
|
|
1942
|
-
if (!rel || rel.startsWith("..") ||
|
|
1943
|
-
for (const seg of rel.split(
|
|
2049
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path12.default.sep)) return true;
|
|
2050
|
+
const rel = import_node_path12.default.relative(config.root, filePath);
|
|
2051
|
+
if (!rel || rel.startsWith("..") || import_node_path12.default.isAbsolute(rel)) return false;
|
|
2052
|
+
for (const seg of rel.split(import_node_path12.default.sep)) {
|
|
1944
2053
|
if (ignoredSegments.has(seg)) return true;
|
|
1945
2054
|
}
|
|
1946
2055
|
return false;
|
|
@@ -1972,7 +2081,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1972
2081
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1973
2082
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1974
2083
|
console.log();
|
|
1975
|
-
console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.
|
|
2084
|
+
console.log(import_picocolors3.default.cyan(" nasti dev server") + import_picocolors3.default.dim(` v${"1.6.4"}`));
|
|
1976
2085
|
console.log();
|
|
1977
2086
|
console.log(` ${import_picocolors3.default.green(">")} Local: ${import_picocolors3.default.cyan(localUrl)}`);
|
|
1978
2087
|
if (networkUrl) {
|
|
@@ -2028,12 +2137,12 @@ function getNetworkAddress() {
|
|
|
2028
2137
|
}
|
|
2029
2138
|
return "localhost";
|
|
2030
2139
|
}
|
|
2031
|
-
var import_node_http,
|
|
2140
|
+
var import_node_http, import_node_path12, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors3;
|
|
2032
2141
|
var init_server = __esm({
|
|
2033
2142
|
"src/server/index.ts"() {
|
|
2034
2143
|
"use strict";
|
|
2035
2144
|
import_node_http = __toESM(require("http"), 1);
|
|
2036
|
-
|
|
2145
|
+
import_node_path12 = __toESM(require("path"), 1);
|
|
2037
2146
|
import_node_os = __toESM(require("os"), 1);
|
|
2038
2147
|
import_connect = __toESM(require("connect"), 1);
|
|
2039
2148
|
import_sirv = __toESM(require("sirv"), 1);
|
|
@@ -2069,7 +2178,7 @@ init_config();
|
|
|
2069
2178
|
init_build();
|
|
2070
2179
|
|
|
2071
2180
|
// src/build/electron.ts
|
|
2072
|
-
var
|
|
2181
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
2073
2182
|
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
2074
2183
|
var import_rolldown2 = require("rolldown");
|
|
2075
2184
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
@@ -2077,10 +2186,10 @@ init_config();
|
|
|
2077
2186
|
init_resolve();
|
|
2078
2187
|
|
|
2079
2188
|
// src/plugins/electron.ts
|
|
2080
|
-
var
|
|
2189
|
+
var import_node_module3 = require("module");
|
|
2081
2190
|
var NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
2082
|
-
...
|
|
2083
|
-
...
|
|
2191
|
+
...import_node_module3.builtinModules,
|
|
2192
|
+
...import_node_module3.builtinModules.map((m) => `node:${m}`)
|
|
2084
2193
|
]);
|
|
2085
2194
|
var ELECTRON_MODULES = /* @__PURE__ */ new Set([
|
|
2086
2195
|
"electron",
|
|
@@ -2116,16 +2225,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2116
2225
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2117
2226
|
const startTime = performance.now();
|
|
2118
2227
|
assertElectronVersion(config);
|
|
2119
|
-
console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.
|
|
2228
|
+
console.log(import_picocolors2.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors2.default.dim(` v${"1.6.4"}`));
|
|
2120
2229
|
console.log(import_picocolors2.default.dim(` root: ${config.root}`));
|
|
2121
2230
|
console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
|
|
2122
2231
|
console.log(import_picocolors2.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2123
|
-
const outDir =
|
|
2232
|
+
const outDir = import_node_path9.default.resolve(config.root, config.build.outDir);
|
|
2124
2233
|
if (config.build.emptyOutDir && import_node_fs7.default.existsSync(outDir)) {
|
|
2125
2234
|
import_node_fs7.default.rmSync(outDir, { recursive: true, force: true });
|
|
2126
2235
|
}
|
|
2127
2236
|
import_node_fs7.default.mkdirSync(outDir, { recursive: true });
|
|
2128
|
-
const rendererOutDir =
|
|
2237
|
+
const rendererOutDir = import_node_path9.default.join(outDir, "renderer");
|
|
2129
2238
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2130
2239
|
await build2({
|
|
2131
2240
|
...inlineConfig,
|
|
@@ -2136,7 +2245,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2136
2245
|
emptyOutDir: false
|
|
2137
2246
|
}
|
|
2138
2247
|
});
|
|
2139
|
-
const mainEntry =
|
|
2248
|
+
const mainEntry = import_node_path9.default.resolve(config.root, config.electron.main);
|
|
2140
2249
|
if (!import_node_fs7.default.existsSync(mainEntry)) {
|
|
2141
2250
|
throw new Error(
|
|
2142
2251
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2155,7 +2264,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2155
2264
|
console.warn(import_picocolors2.default.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2156
2265
|
continue;
|
|
2157
2266
|
}
|
|
2158
|
-
const base =
|
|
2267
|
+
const base = import_node_path9.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
2159
2268
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2160
2269
|
await bundleNode(config, entry, {
|
|
2161
2270
|
outFile: out,
|
|
@@ -2167,10 +2276,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2167
2276
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2168
2277
|
console.log(import_picocolors2.default.green(`
|
|
2169
2278
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2170
|
-
console.log(import_picocolors2.default.dim(` renderer: ${
|
|
2171
|
-
console.log(import_picocolors2.default.dim(` main: ${
|
|
2279
|
+
console.log(import_picocolors2.default.dim(` renderer: ${import_node_path9.default.relative(config.root, rendererOutDir)}/`));
|
|
2280
|
+
console.log(import_picocolors2.default.dim(` main: ${import_node_path9.default.relative(config.root, mainFile)}`));
|
|
2172
2281
|
for (const pf of preloadFiles) {
|
|
2173
|
-
console.log(import_picocolors2.default.dim(` preload: ${
|
|
2282
|
+
console.log(import_picocolors2.default.dim(` preload: ${import_node_path9.default.relative(config.root, pf)}`));
|
|
2174
2283
|
}
|
|
2175
2284
|
console.log();
|
|
2176
2285
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2201,7 +2310,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2201
2310
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2202
2311
|
...config.build.rolldownOptions
|
|
2203
2312
|
});
|
|
2204
|
-
import_node_fs7.default.mkdirSync(
|
|
2313
|
+
import_node_fs7.default.mkdirSync(import_node_path9.default.dirname(opts.outFile), { recursive: true });
|
|
2205
2314
|
await bundle.write({
|
|
2206
2315
|
file: opts.outFile,
|
|
2207
2316
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2210,16 +2319,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2210
2319
|
codeSplitting: false
|
|
2211
2320
|
});
|
|
2212
2321
|
await bundle.close();
|
|
2213
|
-
console.log(import_picocolors2.default.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2322
|
+
console.log(import_picocolors2.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path9.default.relative(config.root, opts.outFile)}`));
|
|
2214
2323
|
return opts.outFile;
|
|
2215
2324
|
}
|
|
2216
2325
|
function outFileName(outDir, base, format) {
|
|
2217
2326
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2218
|
-
return
|
|
2327
|
+
return import_node_path9.default.join(outDir, base + ext);
|
|
2219
2328
|
}
|
|
2220
2329
|
function normalizePreload(preload, root) {
|
|
2221
2330
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2222
|
-
return list.map((p) =>
|
|
2331
|
+
return list.map((p) => import_node_path9.default.resolve(root, p));
|
|
2223
2332
|
}
|
|
2224
2333
|
function assertElectronVersion(config) {
|
|
2225
2334
|
const min = config.electron.minVersion;
|
|
@@ -2234,7 +2343,7 @@ function assertElectronVersion(config) {
|
|
|
2234
2343
|
}
|
|
2235
2344
|
function detectInstalledElectron(root) {
|
|
2236
2345
|
try {
|
|
2237
|
-
const pkgPath =
|
|
2346
|
+
const pkgPath = import_node_path9.default.resolve(root, "node_modules/electron/package.json");
|
|
2238
2347
|
if (!import_node_fs7.default.existsSync(pkgPath)) return null;
|
|
2239
2348
|
const pkg = JSON.parse(import_node_fs7.default.readFileSync(pkgPath, "utf-8"));
|
|
2240
2349
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2248,9 +2357,9 @@ function detectInstalledElectron(root) {
|
|
|
2248
2357
|
init_server();
|
|
2249
2358
|
|
|
2250
2359
|
// src/server/electron-dev.ts
|
|
2251
|
-
var
|
|
2360
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
2252
2361
|
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
2253
|
-
var
|
|
2362
|
+
var import_node_module5 = require("module");
|
|
2254
2363
|
var import_node_child_process = require("child_process");
|
|
2255
2364
|
var import_chokidar2 = __toESM(require("chokidar"), 1);
|
|
2256
2365
|
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
@@ -2263,17 +2372,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2263
2372
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2264
2373
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2265
2374
|
warnElectronVersion(config);
|
|
2266
|
-
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.
|
|
2375
|
+
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.4"}`));
|
|
2267
2376
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2268
2377
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2269
2378
|
await server.listen();
|
|
2270
2379
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2271
2380
|
console.log(import_picocolors4.default.dim(` renderer: ${devUrl}`));
|
|
2272
|
-
const stageDir =
|
|
2381
|
+
const stageDir = import_node_path13.default.resolve(config.root, ".nasti");
|
|
2273
2382
|
import_node_fs10.default.mkdirSync(stageDir, { recursive: true });
|
|
2274
|
-
const mainEntry =
|
|
2383
|
+
const mainEntry = import_node_path13.default.resolve(config.root, config.electron.main);
|
|
2275
2384
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2276
|
-
const builtMainFile =
|
|
2385
|
+
const builtMainFile = import_node_path13.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2277
2386
|
const builtPreloadFiles = [];
|
|
2278
2387
|
const compileAll = async () => {
|
|
2279
2388
|
await compileNode(config, mainEntry, {
|
|
@@ -2284,8 +2393,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2284
2393
|
builtPreloadFiles.length = 0;
|
|
2285
2394
|
for (const entry of preloadEntries) {
|
|
2286
2395
|
if (!import_node_fs10.default.existsSync(entry)) continue;
|
|
2287
|
-
const base =
|
|
2288
|
-
const out =
|
|
2396
|
+
const base = import_node_path13.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
2397
|
+
const out = import_node_path13.default.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2289
2398
|
await compileNode(config, entry, {
|
|
2290
2399
|
outFile: out,
|
|
2291
2400
|
format: config.electron.preloadFormat,
|
|
@@ -2400,7 +2509,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2400
2509
|
platform: "node",
|
|
2401
2510
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2402
2511
|
});
|
|
2403
|
-
import_node_fs10.default.mkdirSync(
|
|
2512
|
+
import_node_fs10.default.mkdirSync(import_node_path13.default.dirname(opts.outFile), { recursive: true });
|
|
2404
2513
|
await bundle.write({
|
|
2405
2514
|
file: opts.outFile,
|
|
2406
2515
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2417,7 +2526,7 @@ function resolveElectronBinary(config) {
|
|
|
2417
2526
|
return config.electron.electronPath;
|
|
2418
2527
|
}
|
|
2419
2528
|
try {
|
|
2420
|
-
const require2 = (0,
|
|
2529
|
+
const require2 = (0, import_node_module5.createRequire)(import_node_path13.default.resolve(config.root, "package.json"));
|
|
2421
2530
|
const pathFile = require2.resolve("electron");
|
|
2422
2531
|
const electronModule = require2(pathFile);
|
|
2423
2532
|
if (typeof electronModule === "string" && import_node_fs10.default.existsSync(electronModule)) {
|
|
@@ -2447,10 +2556,10 @@ function warnElectronVersion(config) {
|
|
|
2447
2556
|
}
|
|
2448
2557
|
|
|
2449
2558
|
// src/plugins/monaco-editor.ts
|
|
2450
|
-
var
|
|
2559
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
2451
2560
|
var import_node_fs11 = __toESM(require("fs"), 1);
|
|
2452
2561
|
var import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
2453
|
-
var
|
|
2562
|
+
var import_node_module6 = require("module");
|
|
2454
2563
|
var DEFAULT_WORKERS = {
|
|
2455
2564
|
editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
|
|
2456
2565
|
css: "monaco-editor/esm/vs/language/css/css.worker",
|
|
@@ -2469,7 +2578,7 @@ function normalizePublicPath(p) {
|
|
|
2469
2578
|
}
|
|
2470
2579
|
function readMonacoVersion(root) {
|
|
2471
2580
|
try {
|
|
2472
|
-
const require2 = (0,
|
|
2581
|
+
const require2 = (0, import_node_module6.createRequire)(import_node_path14.default.resolve(root, "package.json"));
|
|
2473
2582
|
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
2474
2583
|
const pkg = JSON.parse(import_node_fs11.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
2475
2584
|
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
@@ -2491,13 +2600,13 @@ function monacoEditorPlugin(options = {}) {
|
|
|
2491
2600
|
let cacheDir = "";
|
|
2492
2601
|
const building = /* @__PURE__ */ new Map();
|
|
2493
2602
|
async function buildWorker(worker) {
|
|
2494
|
-
const cacheFile =
|
|
2603
|
+
const cacheFile = import_node_path14.default.join(cacheDir, `${worker.label}.worker.js`);
|
|
2495
2604
|
if (import_node_fs11.default.existsSync(cacheFile)) return cacheFile;
|
|
2496
2605
|
const existing = building.get(worker.label);
|
|
2497
2606
|
if (existing) return existing;
|
|
2498
2607
|
const task = (async () => {
|
|
2499
2608
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
2500
|
-
const require2 = (0,
|
|
2609
|
+
const require2 = (0, import_node_module6.createRequire)(import_node_path14.default.resolve(resolvedConfig.root, "package.json"));
|
|
2501
2610
|
let entry;
|
|
2502
2611
|
try {
|
|
2503
2612
|
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
@@ -2564,12 +2673,12 @@ function monacoEditorPlugin(options = {}) {
|
|
|
2564
2673
|
resolvedConfig = config;
|
|
2565
2674
|
const version = readMonacoVersion(config.root);
|
|
2566
2675
|
const key = import_node_crypto2.default.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
2567
|
-
cacheDir =
|
|
2676
|
+
cacheDir = import_node_path14.default.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
2568
2677
|
},
|
|
2569
2678
|
async configureServer(server) {
|
|
2570
2679
|
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
2571
2680
|
const watcher = server.watcher;
|
|
2572
|
-
const monacoDir =
|
|
2681
|
+
const monacoDir = import_node_path14.default.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
2573
2682
|
try {
|
|
2574
2683
|
watcher?.unwatch?.(monacoDir);
|
|
2575
2684
|
} catch {
|
|
@@ -2634,7 +2743,7 @@ self.monaco = monaco;`,
|
|
|
2634
2743
|
resolvedConfig.root,
|
|
2635
2744
|
resolvedConfig.build.outDir,
|
|
2636
2745
|
resolvedConfig.base
|
|
2637
|
-
) : isCDN(publicPath) ?
|
|
2746
|
+
) : isCDN(publicPath) ? import_node_path14.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : import_node_path14.default.resolve(
|
|
2638
2747
|
resolvedConfig.root,
|
|
2639
2748
|
resolvedConfig.build.outDir,
|
|
2640
2749
|
publicPath.replace(/^\//, "")
|
|
@@ -2643,7 +2752,7 @@ self.monaco = monaco;`,
|
|
|
2643
2752
|
for (const worker of workers) {
|
|
2644
2753
|
try {
|
|
2645
2754
|
const cacheFile = await buildWorker(worker);
|
|
2646
|
-
import_node_fs11.default.copyFileSync(cacheFile,
|
|
2755
|
+
import_node_fs11.default.copyFileSync(cacheFile, import_node_path14.default.join(outDir, `${worker.label}.worker.js`));
|
|
2647
2756
|
} catch (e) {
|
|
2648
2757
|
throw new Error(
|
|
2649
2758
|
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|