@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/cli.js
CHANGED
|
@@ -443,6 +443,19 @@ var init_module_graph = __esm({
|
|
|
443
443
|
}
|
|
444
444
|
mods.add(mod);
|
|
445
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Reindex a module under a plugin-provided canonical id (e.g. a `\0virtual:foo`
|
|
448
|
+
* id returned from `resolveId`). Plugins look up their own virtual modules via
|
|
449
|
+
* `getModuleById(RESOLVED_ID)` to invalidate them on watcher events; without
|
|
450
|
+
* this remap they'd never find the node because `ensureEntryFromUrl` keys by
|
|
451
|
+
* the public URL only.
|
|
452
|
+
*/
|
|
453
|
+
setModuleId(mod, id) {
|
|
454
|
+
if (mod.id === id) return;
|
|
455
|
+
this.idToModuleMap.delete(mod.id);
|
|
456
|
+
mod.id = id;
|
|
457
|
+
this.idToModuleMap.set(id, mod);
|
|
458
|
+
}
|
|
446
459
|
/** 更新模块依赖关系 */
|
|
447
460
|
updateModuleImports(mod, importedIds) {
|
|
448
461
|
for (const imported of mod.importedModules) {
|
|
@@ -887,13 +900,23 @@ function transformMiddleware(ctx) {
|
|
|
887
900
|
async function transformRequest(url, ctx) {
|
|
888
901
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
889
902
|
const cleanReqUrl = url.split("?")[0];
|
|
890
|
-
const
|
|
891
|
-
if (
|
|
892
|
-
return
|
|
903
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
904
|
+
if (cached2?.transformResult) {
|
|
905
|
+
return cached2.transformResult;
|
|
893
906
|
}
|
|
894
907
|
if (cleanReqUrl === "/@react-refresh") {
|
|
895
908
|
return { code: getReactRefreshRuntimeEsm() };
|
|
896
909
|
}
|
|
910
|
+
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
911
|
+
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
912
|
+
const virtual = await loadVirtualModule(spec, ctx);
|
|
913
|
+
if (virtual) {
|
|
914
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
915
|
+
moduleGraph.setModuleId(mod2, virtual.id);
|
|
916
|
+
mod2.transformResult = virtual.result;
|
|
917
|
+
return virtual.result;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
897
920
|
const filePath = resolveUrlToFile(url, config.root);
|
|
898
921
|
if (!filePath || !fs4.existsSync(filePath)) return null;
|
|
899
922
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
@@ -940,6 +963,28 @@ async function transformRequest(url, ctx) {
|
|
|
940
963
|
mod.transformResult = transformResult;
|
|
941
964
|
return transformResult;
|
|
942
965
|
}
|
|
966
|
+
async function loadVirtualModule(spec, ctx) {
|
|
967
|
+
const { config, pluginContainer } = ctx;
|
|
968
|
+
const resolved = await pluginContainer.resolveId(spec);
|
|
969
|
+
if (resolved == null) return null;
|
|
970
|
+
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
971
|
+
const looksVirtual = resolvedId.startsWith("\0") || !fs4.existsSync(resolvedId);
|
|
972
|
+
if (!looksVirtual) return null;
|
|
973
|
+
const loadResult = await pluginContainer.load(resolvedId);
|
|
974
|
+
if (loadResult == null) return null;
|
|
975
|
+
let code = typeof loadResult === "string" ? loadResult : loadResult.code;
|
|
976
|
+
const transformed = await pluginContainer.transform(code, resolvedId);
|
|
977
|
+
if (transformed != null) {
|
|
978
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
979
|
+
}
|
|
980
|
+
code = replaceEnvInCode(code, ctx.envDefine ?? buildEnvDefine(
|
|
981
|
+
loadEnv(config.mode, config.root, config.envPrefix),
|
|
982
|
+
config.mode
|
|
983
|
+
));
|
|
984
|
+
const anchor = path4.join(config.root, "__nasti_virtual__.ts");
|
|
985
|
+
code = rewriteImports(code, config, anchor);
|
|
986
|
+
return { id: resolvedId, result: { code } };
|
|
987
|
+
}
|
|
943
988
|
async function bundlePackageAsEsm(entryFile) {
|
|
944
989
|
if (!esmBundleCache.has(entryFile)) {
|
|
945
990
|
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
@@ -1096,19 +1141,20 @@ function rewriteExternalRequires(code) {
|
|
|
1096
1141
|
}
|
|
1097
1142
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1098
1143
|
try {
|
|
1099
|
-
const { createRequire:
|
|
1100
|
-
const req =
|
|
1144
|
+
const { createRequire: createRequire5 } = await import("module");
|
|
1145
|
+
const req = createRequire5(entryFile);
|
|
1101
1146
|
const cjsExports = req(entryFile);
|
|
1102
1147
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1103
1148
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1104
1149
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1105
1150
|
);
|
|
1106
|
-
|
|
1151
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1152
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1107
1153
|
return code.replace(
|
|
1108
1154
|
/^export default (\w+\(\));?\s*$/m,
|
|
1109
1155
|
(_, call) => [
|
|
1110
1156
|
`const __cjsMod = ${call};`,
|
|
1111
|
-
`export default __cjsMod;`,
|
|
1157
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1112
1158
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1113
1159
|
].join("\n")
|
|
1114
1160
|
);
|
|
@@ -1588,8 +1634,61 @@ var init_resolve = __esm({
|
|
|
1588
1634
|
}
|
|
1589
1635
|
});
|
|
1590
1636
|
|
|
1591
|
-
// src/plugins/
|
|
1637
|
+
// src/plugins/tailwind.ts
|
|
1592
1638
|
import path7 from "path";
|
|
1639
|
+
import { createRequire as createRequire3 } from "module";
|
|
1640
|
+
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
1641
|
+
function hasTailwindDirectives(css) {
|
|
1642
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1643
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
1644
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
1645
|
+
}
|
|
1646
|
+
async function loadTailwind(projectRoot) {
|
|
1647
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
1648
|
+
const req = createRequire3(path7.join(projectRoot, "package.json"));
|
|
1649
|
+
let nodePath;
|
|
1650
|
+
let oxidePath;
|
|
1651
|
+
try {
|
|
1652
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
1653
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
1654
|
+
} catch {
|
|
1655
|
+
throw new Error(
|
|
1656
|
+
"[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"
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
const node = await import(pathToFileURL3(nodePath).href);
|
|
1660
|
+
const oxide = await import(pathToFileURL3(oxidePath).href);
|
|
1661
|
+
cached = { node, oxide };
|
|
1662
|
+
cachedRoot = projectRoot;
|
|
1663
|
+
return cached;
|
|
1664
|
+
}
|
|
1665
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
1666
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
1667
|
+
const dependencies = [];
|
|
1668
|
+
const compiler = await node.compile(css, {
|
|
1669
|
+
base: path7.dirname(fromFile),
|
|
1670
|
+
from: fromFile,
|
|
1671
|
+
onDependency: (p) => dependencies.push(p)
|
|
1672
|
+
});
|
|
1673
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
1674
|
+
const candidates = scanner.scan();
|
|
1675
|
+
return {
|
|
1676
|
+
css: compiler.build(candidates),
|
|
1677
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
var TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
1681
|
+
var init_tailwind = __esm({
|
|
1682
|
+
"src/plugins/tailwind.ts"() {
|
|
1683
|
+
"use strict";
|
|
1684
|
+
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)/;
|
|
1685
|
+
cached = null;
|
|
1686
|
+
cachedRoot = null;
|
|
1687
|
+
}
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
// src/plugins/css.ts
|
|
1691
|
+
import path8 from "path";
|
|
1593
1692
|
function cssPlugin(config) {
|
|
1594
1693
|
return {
|
|
1595
1694
|
name: "nasti:css",
|
|
@@ -1597,9 +1696,14 @@ function cssPlugin(config) {
|
|
|
1597
1696
|
if (source.endsWith(".css")) return null;
|
|
1598
1697
|
return null;
|
|
1599
1698
|
},
|
|
1600
|
-
transform(code, id) {
|
|
1699
|
+
async transform(code, id) {
|
|
1601
1700
|
if (!id.endsWith(".css")) return null;
|
|
1602
|
-
|
|
1701
|
+
let cssSource = code;
|
|
1702
|
+
if (hasTailwindDirectives(code)) {
|
|
1703
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
1704
|
+
cssSource = compiled.css;
|
|
1705
|
+
}
|
|
1706
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
1603
1707
|
if (config.command === "serve") {
|
|
1604
1708
|
const escaped = JSON.stringify(rewritten);
|
|
1605
1709
|
return {
|
|
@@ -1634,19 +1738,20 @@ function rewriteCssUrls(css, from, root) {
|
|
|
1634
1738
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
1635
1739
|
return match;
|
|
1636
1740
|
}
|
|
1637
|
-
const resolved =
|
|
1638
|
-
const relative = "/" +
|
|
1741
|
+
const resolved = path8.resolve(path8.dirname(from), url);
|
|
1742
|
+
const relative = "/" + path8.relative(root, resolved);
|
|
1639
1743
|
return `url(${relative})`;
|
|
1640
1744
|
});
|
|
1641
1745
|
}
|
|
1642
1746
|
var init_css = __esm({
|
|
1643
1747
|
"src/plugins/css.ts"() {
|
|
1644
1748
|
"use strict";
|
|
1749
|
+
init_tailwind();
|
|
1645
1750
|
}
|
|
1646
1751
|
});
|
|
1647
1752
|
|
|
1648
1753
|
// src/plugins/assets.ts
|
|
1649
|
-
import
|
|
1754
|
+
import path9 from "path";
|
|
1650
1755
|
import fs7 from "fs";
|
|
1651
1756
|
import crypto from "crypto";
|
|
1652
1757
|
function assetsPlugin(config) {
|
|
@@ -1659,7 +1764,7 @@ function assetsPlugin(config) {
|
|
|
1659
1764
|
return null;
|
|
1660
1765
|
},
|
|
1661
1766
|
load(id) {
|
|
1662
|
-
const ext =
|
|
1767
|
+
const ext = path9.extname(id.replace(/\?.*$/, ""));
|
|
1663
1768
|
if (id.endsWith("?raw")) {
|
|
1664
1769
|
const file = id.slice(0, -4);
|
|
1665
1770
|
if (fs7.existsSync(file)) {
|
|
@@ -1671,12 +1776,12 @@ function assetsPlugin(config) {
|
|
|
1671
1776
|
const file = id.replace(/\?.*$/, "");
|
|
1672
1777
|
if (!fs7.existsSync(file)) return null;
|
|
1673
1778
|
if (config.command === "serve") {
|
|
1674
|
-
const url = "/" +
|
|
1779
|
+
const url = "/" + path9.relative(config.root, file);
|
|
1675
1780
|
return `export default ${JSON.stringify(url)}`;
|
|
1676
1781
|
}
|
|
1677
1782
|
const content = fs7.readFileSync(file);
|
|
1678
1783
|
const hash = crypto.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
1679
|
-
const basename =
|
|
1784
|
+
const basename = path9.basename(file, ext);
|
|
1680
1785
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
1681
1786
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
1682
1787
|
}
|
|
@@ -1721,7 +1826,7 @@ __export(server_exports, {
|
|
|
1721
1826
|
createServer: () => createServer
|
|
1722
1827
|
});
|
|
1723
1828
|
import http from "http";
|
|
1724
|
-
import
|
|
1829
|
+
import path10 from "path";
|
|
1725
1830
|
import os from "os";
|
|
1726
1831
|
import connect from "connect";
|
|
1727
1832
|
import sirv from "sirv";
|
|
@@ -1745,20 +1850,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1745
1850
|
pluginContainer,
|
|
1746
1851
|
moduleGraph
|
|
1747
1852
|
}));
|
|
1748
|
-
const publicDir =
|
|
1853
|
+
const publicDir = path10.resolve(config.root, "public");
|
|
1749
1854
|
app.use(sirv(publicDir, { dev: true, etag: true }));
|
|
1750
1855
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
1751
1856
|
const httpServer = http.createServer(app);
|
|
1752
1857
|
const ws = createWebSocketServer(httpServer);
|
|
1753
1858
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1754
|
-
const outDirAbs =
|
|
1859
|
+
const outDirAbs = path10.resolve(config.root, config.build.outDir);
|
|
1755
1860
|
const watcher = watch(config.root, {
|
|
1756
1861
|
ignored: (filePath) => {
|
|
1757
1862
|
if (filePath === config.root) return false;
|
|
1758
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
1759
|
-
const rel =
|
|
1760
|
-
if (!rel || rel.startsWith("..") ||
|
|
1761
|
-
for (const seg of rel.split(
|
|
1863
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path10.sep)) return true;
|
|
1864
|
+
const rel = path10.relative(config.root, filePath);
|
|
1865
|
+
if (!rel || rel.startsWith("..") || path10.isAbsolute(rel)) return false;
|
|
1866
|
+
for (const seg of rel.split(path10.sep)) {
|
|
1762
1867
|
if (ignoredSegments.has(seg)) return true;
|
|
1763
1868
|
}
|
|
1764
1869
|
return false;
|
|
@@ -1790,7 +1895,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1790
1895
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1791
1896
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1792
1897
|
console.log();
|
|
1793
|
-
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.
|
|
1898
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.4"}`));
|
|
1794
1899
|
console.log();
|
|
1795
1900
|
console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
|
|
1796
1901
|
if (networkUrl) {
|
|
@@ -1906,17 +2011,17 @@ var build_exports = {};
|
|
|
1906
2011
|
__export(build_exports, {
|
|
1907
2012
|
build: () => build
|
|
1908
2013
|
});
|
|
1909
|
-
import
|
|
2014
|
+
import path11 from "path";
|
|
1910
2015
|
import fs8 from "fs";
|
|
1911
2016
|
import { rolldown } from "rolldown";
|
|
1912
2017
|
import pc2 from "picocolors";
|
|
1913
2018
|
async function build(inlineConfig = {}) {
|
|
1914
2019
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1915
2020
|
const startTime = performance.now();
|
|
1916
|
-
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.
|
|
2021
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.4"}`));
|
|
1917
2022
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1918
2023
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1919
|
-
const outDir =
|
|
2024
|
+
const outDir = path11.resolve(config.root, config.build.outDir);
|
|
1920
2025
|
if (config.build.emptyOutDir && fs8.existsSync(outDir)) {
|
|
1921
2026
|
fs8.rmSync(outDir, { recursive: true, force: true });
|
|
1922
2027
|
}
|
|
@@ -1928,14 +2033,14 @@ async function build(inlineConfig = {}) {
|
|
|
1928
2033
|
for (const match of scriptMatches) {
|
|
1929
2034
|
const src = match[1];
|
|
1930
2035
|
if (src && !src.startsWith("http")) {
|
|
1931
|
-
entryPoints.push(
|
|
2036
|
+
entryPoints.push(path11.resolve(config.root, src.replace(/^\//, "")));
|
|
1932
2037
|
}
|
|
1933
2038
|
}
|
|
1934
2039
|
}
|
|
1935
2040
|
if (entryPoints.length === 0) {
|
|
1936
2041
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
1937
2042
|
for (const entry of fallbackEntries) {
|
|
1938
|
-
const fullPath =
|
|
2043
|
+
const fullPath = path11.resolve(config.root, entry);
|
|
1939
2044
|
if (fs8.existsSync(fullPath)) {
|
|
1940
2045
|
entryPoints.push(fullPath);
|
|
1941
2046
|
break;
|
|
@@ -1979,7 +2084,11 @@ async function build(inlineConfig = {}) {
|
|
|
1979
2084
|
load: p.load,
|
|
1980
2085
|
transform: p.transform,
|
|
1981
2086
|
buildStart: p.buildStart,
|
|
1982
|
-
buildEnd: p.buildEnd
|
|
2087
|
+
buildEnd: p.buildEnd,
|
|
2088
|
+
// Forward `closeBundle` to Rolldown — it invokes the hook during
|
|
2089
|
+
// `bundle.close()` below. This is the hook Vite plugins (e.g. PWA
|
|
2090
|
+
// manifest/SW writers) rely on for final-stage artifact emission.
|
|
2091
|
+
closeBundle: p.closeBundle
|
|
1983
2092
|
}))
|
|
1984
2093
|
],
|
|
1985
2094
|
...config.build.rolldownOptions
|
|
@@ -1996,8 +2105,8 @@ async function build(inlineConfig = {}) {
|
|
|
1996
2105
|
await bundle.close();
|
|
1997
2106
|
await pluginContainer.buildEnd();
|
|
1998
2107
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
1999
|
-
const dest =
|
|
2000
|
-
fs8.mkdirSync(
|
|
2108
|
+
const dest = path11.resolve(outDir, ef.fileName);
|
|
2109
|
+
fs8.mkdirSync(path11.dirname(dest), { recursive: true });
|
|
2001
2110
|
fs8.writeFileSync(dest, ef.source);
|
|
2002
2111
|
}
|
|
2003
2112
|
if (html) {
|
|
@@ -2015,14 +2124,14 @@ async function build(inlineConfig = {}) {
|
|
|
2015
2124
|
}
|
|
2016
2125
|
for (const chunk of output) {
|
|
2017
2126
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
2018
|
-
const originalEntry =
|
|
2127
|
+
const originalEntry = path11.relative(config.root, chunk.facadeModuleId);
|
|
2019
2128
|
processedHtml = processedHtml.replace(
|
|
2020
2129
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
2021
2130
|
`$1${config.base}${chunk.fileName}$3`
|
|
2022
2131
|
);
|
|
2023
2132
|
}
|
|
2024
2133
|
}
|
|
2025
|
-
fs8.writeFileSync(
|
|
2134
|
+
fs8.writeFileSync(path11.resolve(outDir, "index.html"), processedHtml);
|
|
2026
2135
|
}
|
|
2027
2136
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2028
2137
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -2065,7 +2174,7 @@ __export(electron_exports, {
|
|
|
2065
2174
|
detectInstalledElectron: () => detectInstalledElectron,
|
|
2066
2175
|
normalizePreload: () => normalizePreload
|
|
2067
2176
|
});
|
|
2068
|
-
import
|
|
2177
|
+
import path12 from "path";
|
|
2069
2178
|
import fs9 from "fs";
|
|
2070
2179
|
import { rolldown as rolldown2 } from "rolldown";
|
|
2071
2180
|
import pc3 from "picocolors";
|
|
@@ -2073,16 +2182,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2073
2182
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2074
2183
|
const startTime = performance.now();
|
|
2075
2184
|
assertElectronVersion(config);
|
|
2076
|
-
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.
|
|
2185
|
+
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.4"}`));
|
|
2077
2186
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
2078
2187
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
2079
2188
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2080
|
-
const outDir =
|
|
2189
|
+
const outDir = path12.resolve(config.root, config.build.outDir);
|
|
2081
2190
|
if (config.build.emptyOutDir && fs9.existsSync(outDir)) {
|
|
2082
2191
|
fs9.rmSync(outDir, { recursive: true, force: true });
|
|
2083
2192
|
}
|
|
2084
2193
|
fs9.mkdirSync(outDir, { recursive: true });
|
|
2085
|
-
const rendererOutDir =
|
|
2194
|
+
const rendererOutDir = path12.join(outDir, "renderer");
|
|
2086
2195
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2087
2196
|
await build2({
|
|
2088
2197
|
...inlineConfig,
|
|
@@ -2093,7 +2202,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2093
2202
|
emptyOutDir: false
|
|
2094
2203
|
}
|
|
2095
2204
|
});
|
|
2096
|
-
const mainEntry =
|
|
2205
|
+
const mainEntry = path12.resolve(config.root, config.electron.main);
|
|
2097
2206
|
if (!fs9.existsSync(mainEntry)) {
|
|
2098
2207
|
throw new Error(
|
|
2099
2208
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2112,7 +2221,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2112
2221
|
console.warn(pc3.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2113
2222
|
continue;
|
|
2114
2223
|
}
|
|
2115
|
-
const base =
|
|
2224
|
+
const base = path12.basename(entry).replace(/\.[^.]+$/, "");
|
|
2116
2225
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2117
2226
|
await bundleNode(config, entry, {
|
|
2118
2227
|
outFile: out,
|
|
@@ -2124,10 +2233,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2124
2233
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2125
2234
|
console.log(pc3.green(`
|
|
2126
2235
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2127
|
-
console.log(pc3.dim(` renderer: ${
|
|
2128
|
-
console.log(pc3.dim(` main: ${
|
|
2236
|
+
console.log(pc3.dim(` renderer: ${path12.relative(config.root, rendererOutDir)}/`));
|
|
2237
|
+
console.log(pc3.dim(` main: ${path12.relative(config.root, mainFile)}`));
|
|
2129
2238
|
for (const pf of preloadFiles) {
|
|
2130
|
-
console.log(pc3.dim(` preload: ${
|
|
2239
|
+
console.log(pc3.dim(` preload: ${path12.relative(config.root, pf)}`));
|
|
2131
2240
|
}
|
|
2132
2241
|
console.log();
|
|
2133
2242
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2158,7 +2267,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2158
2267
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2159
2268
|
...config.build.rolldownOptions
|
|
2160
2269
|
});
|
|
2161
|
-
fs9.mkdirSync(
|
|
2270
|
+
fs9.mkdirSync(path12.dirname(opts.outFile), { recursive: true });
|
|
2162
2271
|
await bundle.write({
|
|
2163
2272
|
file: opts.outFile,
|
|
2164
2273
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2167,16 +2276,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2167
2276
|
codeSplitting: false
|
|
2168
2277
|
});
|
|
2169
2278
|
await bundle.close();
|
|
2170
|
-
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2279
|
+
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${path12.relative(config.root, opts.outFile)}`));
|
|
2171
2280
|
return opts.outFile;
|
|
2172
2281
|
}
|
|
2173
2282
|
function outFileName(outDir, base, format) {
|
|
2174
2283
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2175
|
-
return
|
|
2284
|
+
return path12.join(outDir, base + ext);
|
|
2176
2285
|
}
|
|
2177
2286
|
function normalizePreload(preload, root) {
|
|
2178
2287
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2179
|
-
return list.map((p) =>
|
|
2288
|
+
return list.map((p) => path12.resolve(root, p));
|
|
2180
2289
|
}
|
|
2181
2290
|
function assertElectronVersion(config) {
|
|
2182
2291
|
const min = config.electron.minVersion;
|
|
@@ -2191,7 +2300,7 @@ function assertElectronVersion(config) {
|
|
|
2191
2300
|
}
|
|
2192
2301
|
function detectInstalledElectron(root) {
|
|
2193
2302
|
try {
|
|
2194
|
-
const pkgPath =
|
|
2303
|
+
const pkgPath = path12.resolve(root, "node_modules/electron/package.json");
|
|
2195
2304
|
if (!fs9.existsSync(pkgPath)) return null;
|
|
2196
2305
|
const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf-8"));
|
|
2197
2306
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2216,9 +2325,9 @@ var electron_dev_exports = {};
|
|
|
2216
2325
|
__export(electron_dev_exports, {
|
|
2217
2326
|
startElectronDev: () => startElectronDev
|
|
2218
2327
|
});
|
|
2219
|
-
import
|
|
2328
|
+
import path13 from "path";
|
|
2220
2329
|
import fs10 from "fs";
|
|
2221
|
-
import { createRequire as
|
|
2330
|
+
import { createRequire as createRequire4 } from "module";
|
|
2222
2331
|
import { spawn } from "child_process";
|
|
2223
2332
|
import chokidar from "chokidar";
|
|
2224
2333
|
import pc4 from "picocolors";
|
|
@@ -2227,17 +2336,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2227
2336
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2228
2337
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2229
2338
|
warnElectronVersion(config);
|
|
2230
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.
|
|
2339
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.4"}`));
|
|
2231
2340
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2232
2341
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2233
2342
|
await server.listen();
|
|
2234
2343
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2235
2344
|
console.log(pc4.dim(` renderer: ${devUrl}`));
|
|
2236
|
-
const stageDir =
|
|
2345
|
+
const stageDir = path13.resolve(config.root, ".nasti");
|
|
2237
2346
|
fs10.mkdirSync(stageDir, { recursive: true });
|
|
2238
|
-
const mainEntry =
|
|
2347
|
+
const mainEntry = path13.resolve(config.root, config.electron.main);
|
|
2239
2348
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2240
|
-
const builtMainFile =
|
|
2349
|
+
const builtMainFile = path13.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2241
2350
|
const builtPreloadFiles = [];
|
|
2242
2351
|
const compileAll = async () => {
|
|
2243
2352
|
await compileNode(config, mainEntry, {
|
|
@@ -2248,8 +2357,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2248
2357
|
builtPreloadFiles.length = 0;
|
|
2249
2358
|
for (const entry of preloadEntries) {
|
|
2250
2359
|
if (!fs10.existsSync(entry)) continue;
|
|
2251
|
-
const base =
|
|
2252
|
-
const out =
|
|
2360
|
+
const base = path13.basename(entry).replace(/\.[^.]+$/, "");
|
|
2361
|
+
const out = path13.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2253
2362
|
await compileNode(config, entry, {
|
|
2254
2363
|
outFile: out,
|
|
2255
2364
|
format: config.electron.preloadFormat,
|
|
@@ -2364,7 +2473,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2364
2473
|
platform: "node",
|
|
2365
2474
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2366
2475
|
});
|
|
2367
|
-
fs10.mkdirSync(
|
|
2476
|
+
fs10.mkdirSync(path13.dirname(opts.outFile), { recursive: true });
|
|
2368
2477
|
await bundle.write({
|
|
2369
2478
|
file: opts.outFile,
|
|
2370
2479
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2381,7 +2490,7 @@ function resolveElectronBinary(config) {
|
|
|
2381
2490
|
return config.electron.electronPath;
|
|
2382
2491
|
}
|
|
2383
2492
|
try {
|
|
2384
|
-
const require2 =
|
|
2493
|
+
const require2 = createRequire4(path13.resolve(config.root, "package.json"));
|
|
2385
2494
|
const pathFile = require2.resolve("electron");
|
|
2386
2495
|
const electronModule = require2(pathFile);
|
|
2387
2496
|
if (typeof electronModule === "string" && fs10.existsSync(electronModule)) {
|
|
@@ -2529,11 +2638,11 @@ cli.command("electron-build [root]", "Build Electron app for production").option
|
|
|
2529
2638
|
cli.command("preview [root]", "Preview production build").option("--port <port>", "Port number", { default: 4173 }).option("--host [host]", "Hostname").option("--outDir <dir>", "Output directory to serve", { default: "dist" }).action(async (root, options) => {
|
|
2530
2639
|
try {
|
|
2531
2640
|
const http2 = await import("http");
|
|
2532
|
-
const
|
|
2641
|
+
const path14 = await import("path");
|
|
2533
2642
|
const sirv2 = (await import("sirv")).default;
|
|
2534
2643
|
const connect2 = (await import("connect")).default;
|
|
2535
|
-
const resolvedRoot =
|
|
2536
|
-
const outDir =
|
|
2644
|
+
const resolvedRoot = path14.resolve(root ?? ".");
|
|
2645
|
+
const outDir = path14.resolve(resolvedRoot, options.outDir);
|
|
2537
2646
|
const app = connect2();
|
|
2538
2647
|
app.use(sirv2(outDir, { single: true, etag: true, gzip: true, brotli: true }));
|
|
2539
2648
|
const port = options.port;
|
|
@@ -2554,6 +2663,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2554
2663
|
}
|
|
2555
2664
|
});
|
|
2556
2665
|
cli.help();
|
|
2557
|
-
cli.version("1.6.
|
|
2666
|
+
cli.version("1.6.4");
|
|
2558
2667
|
cli.parse();
|
|
2559
2668
|
//# sourceMappingURL=cli.js.map
|