@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.js
CHANGED
|
@@ -353,8 +353,61 @@ var init_resolve = __esm({
|
|
|
353
353
|
}
|
|
354
354
|
});
|
|
355
355
|
|
|
356
|
-
// src/plugins/
|
|
356
|
+
// src/plugins/tailwind.ts
|
|
357
357
|
import path3 from "path";
|
|
358
|
+
import { createRequire as createRequire2 } from "module";
|
|
359
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
360
|
+
function hasTailwindDirectives(css) {
|
|
361
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
362
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
363
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
364
|
+
}
|
|
365
|
+
async function loadTailwind(projectRoot) {
|
|
366
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
367
|
+
const req = createRequire2(path3.join(projectRoot, "package.json"));
|
|
368
|
+
let nodePath;
|
|
369
|
+
let oxidePath;
|
|
370
|
+
try {
|
|
371
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
372
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
373
|
+
} catch {
|
|
374
|
+
throw new Error(
|
|
375
|
+
"[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"
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
const node = await import(pathToFileURL2(nodePath).href);
|
|
379
|
+
const oxide = await import(pathToFileURL2(oxidePath).href);
|
|
380
|
+
cached = { node, oxide };
|
|
381
|
+
cachedRoot = projectRoot;
|
|
382
|
+
return cached;
|
|
383
|
+
}
|
|
384
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
385
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
386
|
+
const dependencies = [];
|
|
387
|
+
const compiler = await node.compile(css, {
|
|
388
|
+
base: path3.dirname(fromFile),
|
|
389
|
+
from: fromFile,
|
|
390
|
+
onDependency: (p) => dependencies.push(p)
|
|
391
|
+
});
|
|
392
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
393
|
+
const candidates = scanner.scan();
|
|
394
|
+
return {
|
|
395
|
+
css: compiler.build(candidates),
|
|
396
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
var TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
400
|
+
var init_tailwind = __esm({
|
|
401
|
+
"src/plugins/tailwind.ts"() {
|
|
402
|
+
"use strict";
|
|
403
|
+
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)/;
|
|
404
|
+
cached = null;
|
|
405
|
+
cachedRoot = null;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
// src/plugins/css.ts
|
|
410
|
+
import path4 from "path";
|
|
358
411
|
function cssPlugin(config) {
|
|
359
412
|
return {
|
|
360
413
|
name: "nasti:css",
|
|
@@ -362,9 +415,14 @@ function cssPlugin(config) {
|
|
|
362
415
|
if (source.endsWith(".css")) return null;
|
|
363
416
|
return null;
|
|
364
417
|
},
|
|
365
|
-
transform(code, id) {
|
|
418
|
+
async transform(code, id) {
|
|
366
419
|
if (!id.endsWith(".css")) return null;
|
|
367
|
-
|
|
420
|
+
let cssSource = code;
|
|
421
|
+
if (hasTailwindDirectives(code)) {
|
|
422
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
423
|
+
cssSource = compiled.css;
|
|
424
|
+
}
|
|
425
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
368
426
|
if (config.command === "serve") {
|
|
369
427
|
const escaped = JSON.stringify(rewritten);
|
|
370
428
|
return {
|
|
@@ -399,19 +457,20 @@ function rewriteCssUrls(css, from, root) {
|
|
|
399
457
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
400
458
|
return match;
|
|
401
459
|
}
|
|
402
|
-
const resolved =
|
|
403
|
-
const relative = "/" +
|
|
460
|
+
const resolved = path4.resolve(path4.dirname(from), url);
|
|
461
|
+
const relative = "/" + path4.relative(root, resolved);
|
|
404
462
|
return `url(${relative})`;
|
|
405
463
|
});
|
|
406
464
|
}
|
|
407
465
|
var init_css = __esm({
|
|
408
466
|
"src/plugins/css.ts"() {
|
|
409
467
|
"use strict";
|
|
468
|
+
init_tailwind();
|
|
410
469
|
}
|
|
411
470
|
});
|
|
412
471
|
|
|
413
472
|
// src/plugins/assets.ts
|
|
414
|
-
import
|
|
473
|
+
import path5 from "path";
|
|
415
474
|
import fs3 from "fs";
|
|
416
475
|
import crypto from "crypto";
|
|
417
476
|
function assetsPlugin(config) {
|
|
@@ -424,7 +483,7 @@ function assetsPlugin(config) {
|
|
|
424
483
|
return null;
|
|
425
484
|
},
|
|
426
485
|
load(id) {
|
|
427
|
-
const ext =
|
|
486
|
+
const ext = path5.extname(id.replace(/\?.*$/, ""));
|
|
428
487
|
if (id.endsWith("?raw")) {
|
|
429
488
|
const file = id.slice(0, -4);
|
|
430
489
|
if (fs3.existsSync(file)) {
|
|
@@ -436,12 +495,12 @@ function assetsPlugin(config) {
|
|
|
436
495
|
const file = id.replace(/\?.*$/, "");
|
|
437
496
|
if (!fs3.existsSync(file)) return null;
|
|
438
497
|
if (config.command === "serve") {
|
|
439
|
-
const url = "/" +
|
|
498
|
+
const url = "/" + path5.relative(config.root, file);
|
|
440
499
|
return `export default ${JSON.stringify(url)}`;
|
|
441
500
|
}
|
|
442
501
|
const content = fs3.readFileSync(file);
|
|
443
502
|
const hash = crypto.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
444
|
-
const basename =
|
|
503
|
+
const basename = path5.basename(file, ext);
|
|
445
504
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
446
505
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
447
506
|
}
|
|
@@ -481,7 +540,7 @@ var init_assets = __esm({
|
|
|
481
540
|
});
|
|
482
541
|
|
|
483
542
|
// src/plugins/html.ts
|
|
484
|
-
import
|
|
543
|
+
import path6 from "path";
|
|
485
544
|
import fs4 from "fs";
|
|
486
545
|
function htmlPlugin(config) {
|
|
487
546
|
return {
|
|
@@ -545,7 +604,7 @@ function serializeTag(tag) {
|
|
|
545
604
|
return ` <${tag.tag}${attrs}>${children}</${tag.tag}>`;
|
|
546
605
|
}
|
|
547
606
|
async function readHtmlFile(root) {
|
|
548
|
-
const htmlPath =
|
|
607
|
+
const htmlPath = path6.resolve(root, "index.html");
|
|
549
608
|
if (!fs4.existsSync(htmlPath)) return null;
|
|
550
609
|
return fs4.readFileSync(htmlPath, "utf-8");
|
|
551
610
|
}
|
|
@@ -601,7 +660,7 @@ var init_transformer = __esm({
|
|
|
601
660
|
});
|
|
602
661
|
|
|
603
662
|
// src/core/env.ts
|
|
604
|
-
import
|
|
663
|
+
import path7 from "path";
|
|
605
664
|
import fs5 from "fs";
|
|
606
665
|
function loadEnv(mode, root, prefixes) {
|
|
607
666
|
const envFiles = [
|
|
@@ -612,7 +671,7 @@ function loadEnv(mode, root, prefixes) {
|
|
|
612
671
|
];
|
|
613
672
|
const raw = {};
|
|
614
673
|
for (const file of envFiles) {
|
|
615
|
-
const filePath =
|
|
674
|
+
const filePath = path7.resolve(root, file);
|
|
616
675
|
if (!fs5.existsSync(filePath)) continue;
|
|
617
676
|
const content = fs5.readFileSync(filePath, "utf-8");
|
|
618
677
|
for (const line of content.split("\n")) {
|
|
@@ -786,17 +845,17 @@ var build_exports = {};
|
|
|
786
845
|
__export(build_exports, {
|
|
787
846
|
build: () => build
|
|
788
847
|
});
|
|
789
|
-
import
|
|
848
|
+
import path8 from "path";
|
|
790
849
|
import fs6 from "fs";
|
|
791
850
|
import { rolldown } from "rolldown";
|
|
792
851
|
import pc from "picocolors";
|
|
793
852
|
async function build(inlineConfig = {}) {
|
|
794
853
|
const config = await resolveConfig(inlineConfig, "build");
|
|
795
854
|
const startTime = performance.now();
|
|
796
|
-
console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.
|
|
855
|
+
console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.6.4"}`));
|
|
797
856
|
console.log(pc.dim(` root: ${config.root}`));
|
|
798
857
|
console.log(pc.dim(` mode: ${config.mode}`));
|
|
799
|
-
const outDir =
|
|
858
|
+
const outDir = path8.resolve(config.root, config.build.outDir);
|
|
800
859
|
if (config.build.emptyOutDir && fs6.existsSync(outDir)) {
|
|
801
860
|
fs6.rmSync(outDir, { recursive: true, force: true });
|
|
802
861
|
}
|
|
@@ -808,14 +867,14 @@ async function build(inlineConfig = {}) {
|
|
|
808
867
|
for (const match of scriptMatches) {
|
|
809
868
|
const src = match[1];
|
|
810
869
|
if (src && !src.startsWith("http")) {
|
|
811
|
-
entryPoints.push(
|
|
870
|
+
entryPoints.push(path8.resolve(config.root, src.replace(/^\//, "")));
|
|
812
871
|
}
|
|
813
872
|
}
|
|
814
873
|
}
|
|
815
874
|
if (entryPoints.length === 0) {
|
|
816
875
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
817
876
|
for (const entry of fallbackEntries) {
|
|
818
|
-
const fullPath =
|
|
877
|
+
const fullPath = path8.resolve(config.root, entry);
|
|
819
878
|
if (fs6.existsSync(fullPath)) {
|
|
820
879
|
entryPoints.push(fullPath);
|
|
821
880
|
break;
|
|
@@ -859,7 +918,11 @@ async function build(inlineConfig = {}) {
|
|
|
859
918
|
load: p.load,
|
|
860
919
|
transform: p.transform,
|
|
861
920
|
buildStart: p.buildStart,
|
|
862
|
-
buildEnd: p.buildEnd
|
|
921
|
+
buildEnd: p.buildEnd,
|
|
922
|
+
// Forward `closeBundle` to Rolldown — it invokes the hook during
|
|
923
|
+
// `bundle.close()` below. This is the hook Vite plugins (e.g. PWA
|
|
924
|
+
// manifest/SW writers) rely on for final-stage artifact emission.
|
|
925
|
+
closeBundle: p.closeBundle
|
|
863
926
|
}))
|
|
864
927
|
],
|
|
865
928
|
...config.build.rolldownOptions
|
|
@@ -876,8 +939,8 @@ async function build(inlineConfig = {}) {
|
|
|
876
939
|
await bundle.close();
|
|
877
940
|
await pluginContainer.buildEnd();
|
|
878
941
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
879
|
-
const dest =
|
|
880
|
-
fs6.mkdirSync(
|
|
942
|
+
const dest = path8.resolve(outDir, ef.fileName);
|
|
943
|
+
fs6.mkdirSync(path8.dirname(dest), { recursive: true });
|
|
881
944
|
fs6.writeFileSync(dest, ef.source);
|
|
882
945
|
}
|
|
883
946
|
if (html) {
|
|
@@ -895,14 +958,14 @@ async function build(inlineConfig = {}) {
|
|
|
895
958
|
}
|
|
896
959
|
for (const chunk of output) {
|
|
897
960
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
898
|
-
const originalEntry =
|
|
961
|
+
const originalEntry = path8.relative(config.root, chunk.facadeModuleId);
|
|
899
962
|
processedHtml = processedHtml.replace(
|
|
900
963
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
901
964
|
`$1${config.base}${chunk.fileName}$3`
|
|
902
965
|
);
|
|
903
966
|
}
|
|
904
967
|
}
|
|
905
|
-
fs6.writeFileSync(
|
|
968
|
+
fs6.writeFileSync(path8.resolve(outDir, "index.html"), processedHtml);
|
|
906
969
|
}
|
|
907
970
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
908
971
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -989,6 +1052,19 @@ var init_module_graph = __esm({
|
|
|
989
1052
|
}
|
|
990
1053
|
mods.add(mod);
|
|
991
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Reindex a module under a plugin-provided canonical id (e.g. a `\0virtual:foo`
|
|
1057
|
+
* id returned from `resolveId`). Plugins look up their own virtual modules via
|
|
1058
|
+
* `getModuleById(RESOLVED_ID)` to invalidate them on watcher events; without
|
|
1059
|
+
* this remap they'd never find the node because `ensureEntryFromUrl` keys by
|
|
1060
|
+
* the public URL only.
|
|
1061
|
+
*/
|
|
1062
|
+
setModuleId(mod, id) {
|
|
1063
|
+
if (mod.id === id) return;
|
|
1064
|
+
this.idToModuleMap.delete(mod.id);
|
|
1065
|
+
mod.id = id;
|
|
1066
|
+
this.idToModuleMap.set(id, mod);
|
|
1067
|
+
}
|
|
992
1068
|
/** 更新模块依赖关系 */
|
|
993
1069
|
updateModuleImports(mod, importedIds) {
|
|
994
1070
|
for (const imported of mod.importedModules) {
|
|
@@ -1101,18 +1177,18 @@ __export(middleware_exports, {
|
|
|
1101
1177
|
transformMiddleware: () => transformMiddleware,
|
|
1102
1178
|
transformRequest: () => transformRequest
|
|
1103
1179
|
});
|
|
1104
|
-
import
|
|
1180
|
+
import path10 from "path";
|
|
1105
1181
|
import fs8 from "fs";
|
|
1106
|
-
import { createRequire as
|
|
1107
|
-
import { fileURLToPath, pathToFileURL as
|
|
1182
|
+
import { createRequire as createRequire3 } from "module";
|
|
1183
|
+
import { fileURLToPath, pathToFileURL as pathToFileURL3 } from "url";
|
|
1108
1184
|
function getReactRefreshRuntimeEsm() {
|
|
1109
1185
|
if (__refreshRuntimeCache) return __refreshRuntimeCache;
|
|
1110
1186
|
let cjsPath;
|
|
1111
1187
|
try {
|
|
1112
1188
|
const pkgPath = __require.resolve("react-refresh/package.json");
|
|
1113
|
-
cjsPath =
|
|
1189
|
+
cjsPath = path10.join(path10.dirname(pkgPath), "cjs", "react-refresh-runtime.development.js");
|
|
1114
1190
|
} catch (err) {
|
|
1115
|
-
cjsPath =
|
|
1191
|
+
cjsPath = path10.resolve(__dirname_esm, "../../node_modules/react-refresh/cjs/react-refresh-runtime.development.js");
|
|
1116
1192
|
if (!fs8.existsSync(cjsPath)) {
|
|
1117
1193
|
const origMsg = err instanceof Error ? err.message : String(err);
|
|
1118
1194
|
throw new Error(
|
|
@@ -1252,13 +1328,23 @@ function transformMiddleware(ctx) {
|
|
|
1252
1328
|
async function transformRequest(url, ctx) {
|
|
1253
1329
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
1254
1330
|
const cleanReqUrl = url.split("?")[0];
|
|
1255
|
-
const
|
|
1256
|
-
if (
|
|
1257
|
-
return
|
|
1331
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
1332
|
+
if (cached2?.transformResult) {
|
|
1333
|
+
return cached2.transformResult;
|
|
1258
1334
|
}
|
|
1259
1335
|
if (cleanReqUrl === "/@react-refresh") {
|
|
1260
1336
|
return { code: getReactRefreshRuntimeEsm() };
|
|
1261
1337
|
}
|
|
1338
|
+
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
1339
|
+
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
1340
|
+
const virtual = await loadVirtualModule(spec, ctx);
|
|
1341
|
+
if (virtual) {
|
|
1342
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
1343
|
+
moduleGraph.setModuleId(mod2, virtual.id);
|
|
1344
|
+
mod2.transformResult = virtual.result;
|
|
1345
|
+
return virtual.result;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1262
1348
|
const filePath = resolveUrlToFile(url, config.root);
|
|
1263
1349
|
if (!filePath || !fs8.existsSync(filePath)) return null;
|
|
1264
1350
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
@@ -1305,6 +1391,28 @@ async function transformRequest(url, ctx) {
|
|
|
1305
1391
|
mod.transformResult = transformResult;
|
|
1306
1392
|
return transformResult;
|
|
1307
1393
|
}
|
|
1394
|
+
async function loadVirtualModule(spec, ctx) {
|
|
1395
|
+
const { config, pluginContainer } = ctx;
|
|
1396
|
+
const resolved = await pluginContainer.resolveId(spec);
|
|
1397
|
+
if (resolved == null) return null;
|
|
1398
|
+
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
1399
|
+
const looksVirtual = resolvedId.startsWith("\0") || !fs8.existsSync(resolvedId);
|
|
1400
|
+
if (!looksVirtual) return null;
|
|
1401
|
+
const loadResult = await pluginContainer.load(resolvedId);
|
|
1402
|
+
if (loadResult == null) return null;
|
|
1403
|
+
let code = typeof loadResult === "string" ? loadResult : loadResult.code;
|
|
1404
|
+
const transformed = await pluginContainer.transform(code, resolvedId);
|
|
1405
|
+
if (transformed != null) {
|
|
1406
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
1407
|
+
}
|
|
1408
|
+
code = replaceEnvInCode(code, ctx.envDefine ?? buildEnvDefine(
|
|
1409
|
+
loadEnv(config.mode, config.root, config.envPrefix),
|
|
1410
|
+
config.mode
|
|
1411
|
+
));
|
|
1412
|
+
const anchor = path10.join(config.root, "__nasti_virtual__.ts");
|
|
1413
|
+
code = rewriteImports(code, config, anchor);
|
|
1414
|
+
return { id: resolvedId, result: { code } };
|
|
1415
|
+
}
|
|
1308
1416
|
async function bundlePackageAsEsm(entryFile) {
|
|
1309
1417
|
if (!esmBundleCache.has(entryFile)) {
|
|
1310
1418
|
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
@@ -1344,13 +1452,13 @@ async function doBundlePackage(entryFile) {
|
|
|
1344
1452
|
return code;
|
|
1345
1453
|
}
|
|
1346
1454
|
async function tryGenerateSubpathShim(entryFile) {
|
|
1347
|
-
const NM = `${
|
|
1455
|
+
const NM = `${path10.sep}node_modules${path10.sep}`;
|
|
1348
1456
|
if (!entryFile.includes(NM)) return null;
|
|
1349
1457
|
let pkgDir = null;
|
|
1350
1458
|
let pkgName = null;
|
|
1351
|
-
let dir =
|
|
1459
|
+
let dir = path10.dirname(entryFile);
|
|
1352
1460
|
while (true) {
|
|
1353
|
-
const pkgJsonPath =
|
|
1461
|
+
const pkgJsonPath = path10.join(dir, "package.json");
|
|
1354
1462
|
if (fs8.existsSync(pkgJsonPath)) {
|
|
1355
1463
|
try {
|
|
1356
1464
|
const pkg = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf-8"));
|
|
@@ -1362,21 +1470,21 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
1362
1470
|
} catch {
|
|
1363
1471
|
}
|
|
1364
1472
|
}
|
|
1365
|
-
const parent =
|
|
1473
|
+
const parent = path10.dirname(dir);
|
|
1366
1474
|
if (parent === dir) return null;
|
|
1367
1475
|
dir = parent;
|
|
1368
1476
|
if (!dir.includes(NM)) return null;
|
|
1369
1477
|
}
|
|
1370
1478
|
if (!pkgDir || !pkgName) return null;
|
|
1371
|
-
const entryExt =
|
|
1479
|
+
const entryExt = path10.extname(entryFile);
|
|
1372
1480
|
const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
|
|
1373
1481
|
if (!mainEntry) return null;
|
|
1374
|
-
if (
|
|
1482
|
+
if (path10.resolve(mainEntry) === path10.resolve(entryFile)) return null;
|
|
1375
1483
|
let mainNs;
|
|
1376
1484
|
let subNs;
|
|
1377
1485
|
try {
|
|
1378
|
-
mainNs = await import(
|
|
1379
|
-
subNs = await import(
|
|
1486
|
+
mainNs = await import(pathToFileURL3(mainEntry).href);
|
|
1487
|
+
subNs = await import(pathToFileURL3(entryFile).href);
|
|
1380
1488
|
} catch {
|
|
1381
1489
|
return null;
|
|
1382
1490
|
}
|
|
@@ -1407,7 +1515,7 @@ async function tryGenerateSubpathShim(entryFile) {
|
|
|
1407
1515
|
return lines.join("\n") + "\n";
|
|
1408
1516
|
}
|
|
1409
1517
|
function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
1410
|
-
const pkgJsonPath =
|
|
1518
|
+
const pkgJsonPath = path10.join(pkgDir, "package.json");
|
|
1411
1519
|
let pkg;
|
|
1412
1520
|
try {
|
|
1413
1521
|
pkg = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf-8"));
|
|
@@ -1429,13 +1537,13 @@ function pickMainEntryByExtension(pkgDir, preferredExt) {
|
|
|
1429
1537
|
if (typeof pkg.module === "string") candidates.push(pkg.module);
|
|
1430
1538
|
if (typeof pkg.main === "string") candidates.push(pkg.main);
|
|
1431
1539
|
for (const cand of candidates) {
|
|
1432
|
-
if (
|
|
1433
|
-
const full =
|
|
1540
|
+
if (path10.extname(cand) === preferredExt) {
|
|
1541
|
+
const full = path10.resolve(pkgDir, cand);
|
|
1434
1542
|
if (fs8.existsSync(full)) return full;
|
|
1435
1543
|
}
|
|
1436
1544
|
}
|
|
1437
1545
|
for (const cand of candidates) {
|
|
1438
|
-
const full =
|
|
1546
|
+
const full = path10.resolve(pkgDir, cand);
|
|
1439
1547
|
if (fs8.existsSync(full)) return full;
|
|
1440
1548
|
}
|
|
1441
1549
|
return null;
|
|
@@ -1461,19 +1569,20 @@ function rewriteExternalRequires(code) {
|
|
|
1461
1569
|
}
|
|
1462
1570
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1463
1571
|
try {
|
|
1464
|
-
const { createRequire:
|
|
1465
|
-
const req =
|
|
1572
|
+
const { createRequire: createRequire6 } = await import("module");
|
|
1573
|
+
const req = createRequire6(entryFile);
|
|
1466
1574
|
const cjsExports = req(entryFile);
|
|
1467
1575
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1468
1576
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1469
1577
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1470
1578
|
);
|
|
1471
|
-
|
|
1579
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1580
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1472
1581
|
return code.replace(
|
|
1473
1582
|
/^export default (\w+\(\));?\s*$/m,
|
|
1474
1583
|
(_, call) => [
|
|
1475
1584
|
`const __cjsMod = ${call};`,
|
|
1476
|
-
`export default __cjsMod;`,
|
|
1585
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1477
1586
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1478
1587
|
].join("\n")
|
|
1479
1588
|
);
|
|
@@ -1483,11 +1592,11 @@ async function injectCjsNamedExports(code, entryFile) {
|
|
|
1483
1592
|
}
|
|
1484
1593
|
function rewriteImports(code, config, filePath) {
|
|
1485
1594
|
const root = config.root;
|
|
1486
|
-
const fileDir =
|
|
1595
|
+
const fileDir = path10.dirname(filePath);
|
|
1487
1596
|
const aliasEntries = Object.entries(config.resolve.alias).sort(
|
|
1488
1597
|
([a], [b]) => b.length - a.length
|
|
1489
1598
|
);
|
|
1490
|
-
const toRootUrl = (abs) => "/" +
|
|
1599
|
+
const toRootUrl = (abs) => "/" + path10.relative(root, abs).replace(/\\/g, "/");
|
|
1491
1600
|
const transformSpec = (spec) => {
|
|
1492
1601
|
const suffixMatch = spec.match(/[?#].*$/);
|
|
1493
1602
|
const suffix = suffixMatch ? suffixMatch[0] : "";
|
|
@@ -1496,18 +1605,18 @@ function rewriteImports(code, config, filePath) {
|
|
|
1496
1605
|
if (baseSpec === key || baseSpec.startsWith(key + "/")) {
|
|
1497
1606
|
const aliasBase = resolveAliasTarget(value, root);
|
|
1498
1607
|
const sub = baseSpec.slice(key.length).replace(/^\//, "");
|
|
1499
|
-
const target = sub ?
|
|
1608
|
+
const target = sub ? path10.join(aliasBase, sub) : aliasBase;
|
|
1500
1609
|
const resolved = tryResolveDiskPath(target);
|
|
1501
1610
|
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1502
1611
|
}
|
|
1503
1612
|
}
|
|
1504
1613
|
if (baseSpec.startsWith("./") || baseSpec.startsWith("../")) {
|
|
1505
|
-
const target =
|
|
1614
|
+
const target = path10.resolve(fileDir, baseSpec);
|
|
1506
1615
|
const resolved = tryResolveDiskPath(target);
|
|
1507
1616
|
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1508
1617
|
}
|
|
1509
1618
|
if (baseSpec.startsWith("/") && !baseSpec.startsWith("/@")) {
|
|
1510
|
-
const target =
|
|
1619
|
+
const target = path10.join(root, baseSpec.replace(/^\//, ""));
|
|
1511
1620
|
const resolved = tryResolveDiskPath(target);
|
|
1512
1621
|
return resolved && isUnderRoot(resolved, root) ? toRootUrl(resolved) + suffix : spec;
|
|
1513
1622
|
}
|
|
@@ -1526,9 +1635,9 @@ function rewriteImports(code, config, filePath) {
|
|
|
1526
1635
|
);
|
|
1527
1636
|
}
|
|
1528
1637
|
function resolveAliasTarget(value, root) {
|
|
1529
|
-
if (
|
|
1530
|
-
if (value.startsWith("/")) return
|
|
1531
|
-
return
|
|
1638
|
+
if (path10.isAbsolute(value) && fs8.existsSync(value)) return value;
|
|
1639
|
+
if (value.startsWith("/")) return path10.join(root, value.slice(1));
|
|
1640
|
+
return path10.resolve(root, value);
|
|
1532
1641
|
}
|
|
1533
1642
|
function tryResolveDiskPath(target) {
|
|
1534
1643
|
if (fs8.existsSync(target) && fs8.statSync(target).isFile()) return target;
|
|
@@ -1538,15 +1647,15 @@ function tryResolveDiskPath(target) {
|
|
|
1538
1647
|
}
|
|
1539
1648
|
if (fs8.existsSync(target) && fs8.statSync(target).isDirectory()) {
|
|
1540
1649
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1541
|
-
const idx =
|
|
1650
|
+
const idx = path10.join(target, "index" + ext);
|
|
1542
1651
|
if (fs8.existsSync(idx) && fs8.statSync(idx).isFile()) return idx;
|
|
1543
1652
|
}
|
|
1544
1653
|
}
|
|
1545
1654
|
return null;
|
|
1546
1655
|
}
|
|
1547
1656
|
function isUnderRoot(abs, root) {
|
|
1548
|
-
const rel =
|
|
1549
|
-
return !!rel && !rel.startsWith("..") && !
|
|
1657
|
+
const rel = path10.relative(root, abs);
|
|
1658
|
+
return !!rel && !rel.startsWith("..") && !path10.isAbsolute(rel);
|
|
1550
1659
|
}
|
|
1551
1660
|
function resolveNodeModule(root, moduleName) {
|
|
1552
1661
|
let pkgName;
|
|
@@ -1563,17 +1672,17 @@ function resolveNodeModule(root, moduleName) {
|
|
|
1563
1672
|
let pkgDir = null;
|
|
1564
1673
|
let dir = root;
|
|
1565
1674
|
for (; ; ) {
|
|
1566
|
-
const candidate =
|
|
1675
|
+
const candidate = path10.join(dir, "node_modules", pkgName);
|
|
1567
1676
|
if (fs8.existsSync(candidate)) {
|
|
1568
1677
|
pkgDir = candidate;
|
|
1569
1678
|
break;
|
|
1570
1679
|
}
|
|
1571
|
-
const parent =
|
|
1680
|
+
const parent = path10.dirname(dir);
|
|
1572
1681
|
if (parent === dir) break;
|
|
1573
1682
|
dir = parent;
|
|
1574
1683
|
}
|
|
1575
1684
|
if (!pkgDir) return null;
|
|
1576
|
-
const pkgJsonPath =
|
|
1685
|
+
const pkgJsonPath = path10.join(pkgDir, "package.json");
|
|
1577
1686
|
if (!fs8.existsSync(pkgJsonPath)) return null;
|
|
1578
1687
|
let pkg;
|
|
1579
1688
|
try {
|
|
@@ -1590,12 +1699,12 @@ function resolveNodeModule(root, moduleName) {
|
|
|
1590
1699
|
const subDirs = [""];
|
|
1591
1700
|
for (const field of ["module", "main"]) {
|
|
1592
1701
|
if (typeof pkg[field] === "string") {
|
|
1593
|
-
const dir2 =
|
|
1702
|
+
const dir2 = path10.dirname(pkg[field]);
|
|
1594
1703
|
if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
|
|
1595
1704
|
}
|
|
1596
1705
|
}
|
|
1597
1706
|
for (const dir2 of subDirs) {
|
|
1598
|
-
const direct =
|
|
1707
|
+
const direct = path10.join(pkgDir, dir2, subpath);
|
|
1599
1708
|
if (fs8.existsSync(direct) && fs8.statSync(direct).isFile()) return direct;
|
|
1600
1709
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1601
1710
|
if (fs8.existsSync(direct + ext)) return direct + ext;
|
|
@@ -1605,24 +1714,24 @@ function resolveNodeModule(root, moduleName) {
|
|
|
1605
1714
|
}
|
|
1606
1715
|
for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
|
|
1607
1716
|
if (typeof pkg[field] === "string") {
|
|
1608
|
-
const entry =
|
|
1717
|
+
const entry = path10.join(pkgDir, pkg[field]);
|
|
1609
1718
|
if (fs8.existsSync(entry)) return entry;
|
|
1610
1719
|
}
|
|
1611
1720
|
}
|
|
1612
|
-
const indexFallback =
|
|
1721
|
+
const indexFallback = path10.join(pkgDir, "index.js");
|
|
1613
1722
|
if (fs8.existsSync(indexFallback)) return indexFallback;
|
|
1614
1723
|
return null;
|
|
1615
1724
|
}
|
|
1616
1725
|
function resolvePackageExports(exports, key, pkgDir) {
|
|
1617
1726
|
if (typeof exports === "string") {
|
|
1618
|
-
return key === "." ?
|
|
1727
|
+
return key === "." ? path10.join(pkgDir, exports) : null;
|
|
1619
1728
|
}
|
|
1620
1729
|
const entry = exports[key];
|
|
1621
1730
|
if (entry === void 0) return null;
|
|
1622
1731
|
return resolveExportValue(entry, pkgDir);
|
|
1623
1732
|
}
|
|
1624
1733
|
function resolveExportValue(value, pkgDir) {
|
|
1625
|
-
if (typeof value === "string") return
|
|
1734
|
+
if (typeof value === "string") return path10.join(pkgDir, value);
|
|
1626
1735
|
if (Array.isArray(value)) {
|
|
1627
1736
|
for (const item of value) {
|
|
1628
1737
|
const r = resolveExportValue(item, pkgDir);
|
|
@@ -1646,7 +1755,7 @@ function resolveUrlToFile(url, root) {
|
|
|
1646
1755
|
const moduleName = cleanUrl.slice("/@modules/".length);
|
|
1647
1756
|
return resolveNodeModule(root, moduleName);
|
|
1648
1757
|
}
|
|
1649
|
-
const filePath =
|
|
1758
|
+
const filePath = path10.resolve(root, cleanUrl.replace(/^\//, ""));
|
|
1650
1759
|
if (fs8.existsSync(filePath) && fs8.statSync(filePath).isFile()) {
|
|
1651
1760
|
return filePath;
|
|
1652
1761
|
}
|
|
@@ -1655,7 +1764,7 @@ function resolveUrlToFile(url, root) {
|
|
|
1655
1764
|
if (fs8.existsSync(withExt)) return withExt;
|
|
1656
1765
|
}
|
|
1657
1766
|
for (const ext of RESOLVE_EXTENSIONS) {
|
|
1658
|
-
const indexFile =
|
|
1767
|
+
const indexFile = path10.join(filePath, "index" + ext);
|
|
1659
1768
|
if (fs8.existsSync(indexFile)) return indexFile;
|
|
1660
1769
|
}
|
|
1661
1770
|
return null;
|
|
@@ -1664,7 +1773,7 @@ function isModuleRequest(url) {
|
|
|
1664
1773
|
const cleanUrl = url.split("?")[0];
|
|
1665
1774
|
if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
|
|
1666
1775
|
if (cleanUrl.startsWith("/@modules/")) return true;
|
|
1667
|
-
if (!
|
|
1776
|
+
if (!path10.extname(cleanUrl)) return true;
|
|
1668
1777
|
return false;
|
|
1669
1778
|
}
|
|
1670
1779
|
function getHmrClientCode() {
|
|
@@ -1802,8 +1911,8 @@ var init_middleware = __esm({
|
|
|
1802
1911
|
init_transformer();
|
|
1803
1912
|
init_html();
|
|
1804
1913
|
init_env();
|
|
1805
|
-
__dirname_esm =
|
|
1806
|
-
__require =
|
|
1914
|
+
__dirname_esm = path10.dirname(fileURLToPath(import.meta.url));
|
|
1915
|
+
__require = createRequire3(import.meta.url);
|
|
1807
1916
|
__refreshRuntimeCache = null;
|
|
1808
1917
|
REACT_REFRESH_GLOBAL_PREAMBLE = `
|
|
1809
1918
|
import RefreshRuntime from "/@react-refresh";
|
|
@@ -1820,11 +1929,11 @@ window.__vite_plugin_react_preamble_installed__ = true;
|
|
|
1820
1929
|
});
|
|
1821
1930
|
|
|
1822
1931
|
// src/server/hmr.ts
|
|
1823
|
-
import
|
|
1932
|
+
import path11 from "path";
|
|
1824
1933
|
import fs9 from "fs";
|
|
1825
1934
|
async function handleFileChange(file, server) {
|
|
1826
1935
|
const { moduleGraph, ws, config } = server;
|
|
1827
|
-
const relativePath = "/" +
|
|
1936
|
+
const relativePath = "/" + path11.relative(config.root, file);
|
|
1828
1937
|
const mods = moduleGraph.getModulesByFile(file);
|
|
1829
1938
|
if (!mods || mods.size === 0) {
|
|
1830
1939
|
return;
|
|
@@ -1881,7 +1990,7 @@ __export(server_exports, {
|
|
|
1881
1990
|
createServer: () => createServer
|
|
1882
1991
|
});
|
|
1883
1992
|
import http from "http";
|
|
1884
|
-
import
|
|
1993
|
+
import path12 from "path";
|
|
1885
1994
|
import os from "os";
|
|
1886
1995
|
import connect from "connect";
|
|
1887
1996
|
import sirv from "sirv";
|
|
@@ -1905,20 +2014,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1905
2014
|
pluginContainer,
|
|
1906
2015
|
moduleGraph
|
|
1907
2016
|
}));
|
|
1908
|
-
const publicDir =
|
|
2017
|
+
const publicDir = path12.resolve(config.root, "public");
|
|
1909
2018
|
app.use(sirv(publicDir, { dev: true, etag: true }));
|
|
1910
2019
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
1911
2020
|
const httpServer = http.createServer(app);
|
|
1912
2021
|
const ws = createWebSocketServer(httpServer);
|
|
1913
2022
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1914
|
-
const outDirAbs =
|
|
2023
|
+
const outDirAbs = path12.resolve(config.root, config.build.outDir);
|
|
1915
2024
|
const watcher = watch(config.root, {
|
|
1916
2025
|
ignored: (filePath) => {
|
|
1917
2026
|
if (filePath === config.root) return false;
|
|
1918
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
1919
|
-
const rel =
|
|
1920
|
-
if (!rel || rel.startsWith("..") ||
|
|
1921
|
-
for (const seg of rel.split(
|
|
2027
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path12.sep)) return true;
|
|
2028
|
+
const rel = path12.relative(config.root, filePath);
|
|
2029
|
+
if (!rel || rel.startsWith("..") || path12.isAbsolute(rel)) return false;
|
|
2030
|
+
for (const seg of rel.split(path12.sep)) {
|
|
1922
2031
|
if (ignoredSegments.has(seg)) return true;
|
|
1923
2032
|
}
|
|
1924
2033
|
return false;
|
|
@@ -1950,7 +2059,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1950
2059
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1951
2060
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1952
2061
|
console.log();
|
|
1953
|
-
console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.
|
|
2062
|
+
console.log(pc3.cyan(" nasti dev server") + pc3.dim(` v${"1.6.4"}`));
|
|
1954
2063
|
console.log();
|
|
1955
2064
|
console.log(` ${pc3.green(">")} Local: ${pc3.cyan(localUrl)}`);
|
|
1956
2065
|
if (networkUrl) {
|
|
@@ -2029,7 +2138,7 @@ init_build();
|
|
|
2029
2138
|
// src/build/electron.ts
|
|
2030
2139
|
init_config();
|
|
2031
2140
|
init_resolve();
|
|
2032
|
-
import
|
|
2141
|
+
import path9 from "path";
|
|
2033
2142
|
import fs7 from "fs";
|
|
2034
2143
|
import { rolldown as rolldown2 } from "rolldown";
|
|
2035
2144
|
import pc2 from "picocolors";
|
|
@@ -2074,16 +2183,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2074
2183
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2075
2184
|
const startTime = performance.now();
|
|
2076
2185
|
assertElectronVersion(config);
|
|
2077
|
-
console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.
|
|
2186
|
+
console.log(pc2.cyan("\n\u26A1 nasti build (electron)") + pc2.dim(` v${"1.6.4"}`));
|
|
2078
2187
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
2079
2188
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
2080
2189
|
console.log(pc2.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2081
|
-
const outDir =
|
|
2190
|
+
const outDir = path9.resolve(config.root, config.build.outDir);
|
|
2082
2191
|
if (config.build.emptyOutDir && fs7.existsSync(outDir)) {
|
|
2083
2192
|
fs7.rmSync(outDir, { recursive: true, force: true });
|
|
2084
2193
|
}
|
|
2085
2194
|
fs7.mkdirSync(outDir, { recursive: true });
|
|
2086
|
-
const rendererOutDir =
|
|
2195
|
+
const rendererOutDir = path9.join(outDir, "renderer");
|
|
2087
2196
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2088
2197
|
await build2({
|
|
2089
2198
|
...inlineConfig,
|
|
@@ -2094,7 +2203,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2094
2203
|
emptyOutDir: false
|
|
2095
2204
|
}
|
|
2096
2205
|
});
|
|
2097
|
-
const mainEntry =
|
|
2206
|
+
const mainEntry = path9.resolve(config.root, config.electron.main);
|
|
2098
2207
|
if (!fs7.existsSync(mainEntry)) {
|
|
2099
2208
|
throw new Error(
|
|
2100
2209
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2113,7 +2222,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2113
2222
|
console.warn(pc2.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2114
2223
|
continue;
|
|
2115
2224
|
}
|
|
2116
|
-
const base =
|
|
2225
|
+
const base = path9.basename(entry).replace(/\.[^.]+$/, "");
|
|
2117
2226
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2118
2227
|
await bundleNode(config, entry, {
|
|
2119
2228
|
outFile: out,
|
|
@@ -2125,10 +2234,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2125
2234
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2126
2235
|
console.log(pc2.green(`
|
|
2127
2236
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2128
|
-
console.log(pc2.dim(` renderer: ${
|
|
2129
|
-
console.log(pc2.dim(` main: ${
|
|
2237
|
+
console.log(pc2.dim(` renderer: ${path9.relative(config.root, rendererOutDir)}/`));
|
|
2238
|
+
console.log(pc2.dim(` main: ${path9.relative(config.root, mainFile)}`));
|
|
2130
2239
|
for (const pf of preloadFiles) {
|
|
2131
|
-
console.log(pc2.dim(` preload: ${
|
|
2240
|
+
console.log(pc2.dim(` preload: ${path9.relative(config.root, pf)}`));
|
|
2132
2241
|
}
|
|
2133
2242
|
console.log();
|
|
2134
2243
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2159,7 +2268,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2159
2268
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2160
2269
|
...config.build.rolldownOptions
|
|
2161
2270
|
});
|
|
2162
|
-
fs7.mkdirSync(
|
|
2271
|
+
fs7.mkdirSync(path9.dirname(opts.outFile), { recursive: true });
|
|
2163
2272
|
await bundle.write({
|
|
2164
2273
|
file: opts.outFile,
|
|
2165
2274
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2168,16 +2277,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2168
2277
|
codeSplitting: false
|
|
2169
2278
|
});
|
|
2170
2279
|
await bundle.close();
|
|
2171
|
-
console.log(pc2.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2280
|
+
console.log(pc2.dim(` \u2713 ${opts.label} \u2192 ${path9.relative(config.root, opts.outFile)}`));
|
|
2172
2281
|
return opts.outFile;
|
|
2173
2282
|
}
|
|
2174
2283
|
function outFileName(outDir, base, format) {
|
|
2175
2284
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2176
|
-
return
|
|
2285
|
+
return path9.join(outDir, base + ext);
|
|
2177
2286
|
}
|
|
2178
2287
|
function normalizePreload(preload, root) {
|
|
2179
2288
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2180
|
-
return list.map((p) =>
|
|
2289
|
+
return list.map((p) => path9.resolve(root, p));
|
|
2181
2290
|
}
|
|
2182
2291
|
function assertElectronVersion(config) {
|
|
2183
2292
|
const min = config.electron.minVersion;
|
|
@@ -2192,7 +2301,7 @@ function assertElectronVersion(config) {
|
|
|
2192
2301
|
}
|
|
2193
2302
|
function detectInstalledElectron(root) {
|
|
2194
2303
|
try {
|
|
2195
|
-
const pkgPath =
|
|
2304
|
+
const pkgPath = path9.resolve(root, "node_modules/electron/package.json");
|
|
2196
2305
|
if (!fs7.existsSync(pkgPath)) return null;
|
|
2197
2306
|
const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
|
|
2198
2307
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2207,9 +2316,9 @@ init_server();
|
|
|
2207
2316
|
|
|
2208
2317
|
// src/server/electron-dev.ts
|
|
2209
2318
|
init_config();
|
|
2210
|
-
import
|
|
2319
|
+
import path13 from "path";
|
|
2211
2320
|
import fs10 from "fs";
|
|
2212
|
-
import { createRequire as
|
|
2321
|
+
import { createRequire as createRequire4 } from "module";
|
|
2213
2322
|
import { spawn } from "child_process";
|
|
2214
2323
|
import chokidar from "chokidar";
|
|
2215
2324
|
import pc4 from "picocolors";
|
|
@@ -2221,17 +2330,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2221
2330
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2222
2331
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2223
2332
|
warnElectronVersion(config);
|
|
2224
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.
|
|
2333
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.4"}`));
|
|
2225
2334
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2226
2335
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2227
2336
|
await server.listen();
|
|
2228
2337
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2229
2338
|
console.log(pc4.dim(` renderer: ${devUrl}`));
|
|
2230
|
-
const stageDir =
|
|
2339
|
+
const stageDir = path13.resolve(config.root, ".nasti");
|
|
2231
2340
|
fs10.mkdirSync(stageDir, { recursive: true });
|
|
2232
|
-
const mainEntry =
|
|
2341
|
+
const mainEntry = path13.resolve(config.root, config.electron.main);
|
|
2233
2342
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2234
|
-
const builtMainFile =
|
|
2343
|
+
const builtMainFile = path13.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2235
2344
|
const builtPreloadFiles = [];
|
|
2236
2345
|
const compileAll = async () => {
|
|
2237
2346
|
await compileNode(config, mainEntry, {
|
|
@@ -2242,8 +2351,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2242
2351
|
builtPreloadFiles.length = 0;
|
|
2243
2352
|
for (const entry of preloadEntries) {
|
|
2244
2353
|
if (!fs10.existsSync(entry)) continue;
|
|
2245
|
-
const base =
|
|
2246
|
-
const out =
|
|
2354
|
+
const base = path13.basename(entry).replace(/\.[^.]+$/, "");
|
|
2355
|
+
const out = path13.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2247
2356
|
await compileNode(config, entry, {
|
|
2248
2357
|
outFile: out,
|
|
2249
2358
|
format: config.electron.preloadFormat,
|
|
@@ -2358,7 +2467,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2358
2467
|
platform: "node",
|
|
2359
2468
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2360
2469
|
});
|
|
2361
|
-
fs10.mkdirSync(
|
|
2470
|
+
fs10.mkdirSync(path13.dirname(opts.outFile), { recursive: true });
|
|
2362
2471
|
await bundle.write({
|
|
2363
2472
|
file: opts.outFile,
|
|
2364
2473
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2375,7 +2484,7 @@ function resolveElectronBinary(config) {
|
|
|
2375
2484
|
return config.electron.electronPath;
|
|
2376
2485
|
}
|
|
2377
2486
|
try {
|
|
2378
|
-
const require2 =
|
|
2487
|
+
const require2 = createRequire4(path13.resolve(config.root, "package.json"));
|
|
2379
2488
|
const pathFile = require2.resolve("electron");
|
|
2380
2489
|
const electronModule = require2(pathFile);
|
|
2381
2490
|
if (typeof electronModule === "string" && fs10.existsSync(electronModule)) {
|
|
@@ -2405,10 +2514,10 @@ function warnElectronVersion(config) {
|
|
|
2405
2514
|
}
|
|
2406
2515
|
|
|
2407
2516
|
// src/plugins/monaco-editor.ts
|
|
2408
|
-
import
|
|
2517
|
+
import path14 from "path";
|
|
2409
2518
|
import fs11 from "fs";
|
|
2410
2519
|
import crypto2 from "crypto";
|
|
2411
|
-
import { createRequire as
|
|
2520
|
+
import { createRequire as createRequire5 } from "module";
|
|
2412
2521
|
var DEFAULT_WORKERS = {
|
|
2413
2522
|
editorWorkerService: "monaco-editor/esm/vs/editor/editor.worker",
|
|
2414
2523
|
css: "monaco-editor/esm/vs/language/css/css.worker",
|
|
@@ -2427,7 +2536,7 @@ function normalizePublicPath(p) {
|
|
|
2427
2536
|
}
|
|
2428
2537
|
function readMonacoVersion(root) {
|
|
2429
2538
|
try {
|
|
2430
|
-
const require2 =
|
|
2539
|
+
const require2 = createRequire5(path14.resolve(root, "package.json"));
|
|
2431
2540
|
const pkgJsonPath = require2.resolve("monaco-editor/package.json", { paths: [root] });
|
|
2432
2541
|
const pkg = JSON.parse(fs11.readFileSync(pkgJsonPath, "utf-8"));
|
|
2433
2542
|
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
@@ -2449,13 +2558,13 @@ function monacoEditorPlugin(options = {}) {
|
|
|
2449
2558
|
let cacheDir = "";
|
|
2450
2559
|
const building = /* @__PURE__ */ new Map();
|
|
2451
2560
|
async function buildWorker(worker) {
|
|
2452
|
-
const cacheFile =
|
|
2561
|
+
const cacheFile = path14.join(cacheDir, `${worker.label}.worker.js`);
|
|
2453
2562
|
if (fs11.existsSync(cacheFile)) return cacheFile;
|
|
2454
2563
|
const existing = building.get(worker.label);
|
|
2455
2564
|
if (existing) return existing;
|
|
2456
2565
|
const task = (async () => {
|
|
2457
2566
|
const { rolldown: rolldown4 } = await import("rolldown");
|
|
2458
|
-
const require2 =
|
|
2567
|
+
const require2 = createRequire5(path14.resolve(resolvedConfig.root, "package.json"));
|
|
2459
2568
|
let entry;
|
|
2460
2569
|
try {
|
|
2461
2570
|
entry = require2.resolve(worker.entry, { paths: [resolvedConfig.root] });
|
|
@@ -2522,12 +2631,12 @@ function monacoEditorPlugin(options = {}) {
|
|
|
2522
2631
|
resolvedConfig = config;
|
|
2523
2632
|
const version = readMonacoVersion(config.root);
|
|
2524
2633
|
const key = crypto2.createHash("sha1").update(version + "|" + publicPath).digest("hex").slice(0, 8);
|
|
2525
|
-
cacheDir =
|
|
2634
|
+
cacheDir = path14.resolve(config.root, "node_modules/.nasti/monaco", key);
|
|
2526
2635
|
},
|
|
2527
2636
|
async configureServer(server) {
|
|
2528
2637
|
const shouldBuild = !isCDN(publicPath) || forceBuildCDN;
|
|
2529
2638
|
const watcher = server.watcher;
|
|
2530
|
-
const monacoDir =
|
|
2639
|
+
const monacoDir = path14.resolve(resolvedConfig.root, "node_modules/monaco-editor");
|
|
2531
2640
|
try {
|
|
2532
2641
|
watcher?.unwatch?.(monacoDir);
|
|
2533
2642
|
} catch {
|
|
@@ -2592,7 +2701,7 @@ self.monaco = monaco;`,
|
|
|
2592
2701
|
resolvedConfig.root,
|
|
2593
2702
|
resolvedConfig.build.outDir,
|
|
2594
2703
|
resolvedConfig.base
|
|
2595
|
-
) : isCDN(publicPath) ?
|
|
2704
|
+
) : isCDN(publicPath) ? path14.resolve(resolvedConfig.root, resolvedConfig.build.outDir, "monaco") : path14.resolve(
|
|
2596
2705
|
resolvedConfig.root,
|
|
2597
2706
|
resolvedConfig.build.outDir,
|
|
2598
2707
|
publicPath.replace(/^\//, "")
|
|
@@ -2601,7 +2710,7 @@ self.monaco = monaco;`,
|
|
|
2601
2710
|
for (const worker of workers) {
|
|
2602
2711
|
try {
|
|
2603
2712
|
const cacheFile = await buildWorker(worker);
|
|
2604
|
-
fs11.copyFileSync(cacheFile,
|
|
2713
|
+
fs11.copyFileSync(cacheFile, path14.join(outDir, `${worker.label}.worker.js`));
|
|
2605
2714
|
} catch (e) {
|
|
2606
2715
|
throw new Error(
|
|
2607
2716
|
`[nasti:monaco-editor] worker build failed for "${worker.label}": ${e.message}
|