@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.cjs
CHANGED
|
@@ -464,6 +464,19 @@ var init_module_graph = __esm({
|
|
|
464
464
|
}
|
|
465
465
|
mods.add(mod);
|
|
466
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* Reindex a module under a plugin-provided canonical id (e.g. a `\0virtual:foo`
|
|
469
|
+
* id returned from `resolveId`). Plugins look up their own virtual modules via
|
|
470
|
+
* `getModuleById(RESOLVED_ID)` to invalidate them on watcher events; without
|
|
471
|
+
* this remap they'd never find the node because `ensureEntryFromUrl` keys by
|
|
472
|
+
* the public URL only.
|
|
473
|
+
*/
|
|
474
|
+
setModuleId(mod, id) {
|
|
475
|
+
if (mod.id === id) return;
|
|
476
|
+
this.idToModuleMap.delete(mod.id);
|
|
477
|
+
mod.id = id;
|
|
478
|
+
this.idToModuleMap.set(id, mod);
|
|
479
|
+
}
|
|
467
480
|
/** 更新模块依赖关系 */
|
|
468
481
|
updateModuleImports(mod, importedIds) {
|
|
469
482
|
for (const imported of mod.importedModules) {
|
|
@@ -906,13 +919,23 @@ function transformMiddleware(ctx) {
|
|
|
906
919
|
async function transformRequest(url, ctx) {
|
|
907
920
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
908
921
|
const cleanReqUrl = url.split("?")[0];
|
|
909
|
-
const
|
|
910
|
-
if (
|
|
911
|
-
return
|
|
922
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
923
|
+
if (cached2?.transformResult) {
|
|
924
|
+
return cached2.transformResult;
|
|
912
925
|
}
|
|
913
926
|
if (cleanReqUrl === "/@react-refresh") {
|
|
914
927
|
return { code: getReactRefreshRuntimeEsm() };
|
|
915
928
|
}
|
|
929
|
+
if (cleanReqUrl.startsWith("/@modules/")) {
|
|
930
|
+
const spec = cleanReqUrl.slice("/@modules/".length);
|
|
931
|
+
const virtual = await loadVirtualModule(spec, ctx);
|
|
932
|
+
if (virtual) {
|
|
933
|
+
const mod2 = await moduleGraph.ensureEntryFromUrl(url);
|
|
934
|
+
moduleGraph.setModuleId(mod2, virtual.id);
|
|
935
|
+
mod2.transformResult = virtual.result;
|
|
936
|
+
return virtual.result;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
916
939
|
const filePath = resolveUrlToFile(url, config.root);
|
|
917
940
|
if (!filePath || !import_node_fs4.default.existsSync(filePath)) return null;
|
|
918
941
|
const mod = await moduleGraph.ensureEntryFromUrl(url);
|
|
@@ -959,6 +982,28 @@ async function transformRequest(url, ctx) {
|
|
|
959
982
|
mod.transformResult = transformResult;
|
|
960
983
|
return transformResult;
|
|
961
984
|
}
|
|
985
|
+
async function loadVirtualModule(spec, ctx) {
|
|
986
|
+
const { config, pluginContainer } = ctx;
|
|
987
|
+
const resolved = await pluginContainer.resolveId(spec);
|
|
988
|
+
if (resolved == null) return null;
|
|
989
|
+
const resolvedId = typeof resolved === "string" ? resolved : resolved.id;
|
|
990
|
+
const looksVirtual = resolvedId.startsWith("\0") || !import_node_fs4.default.existsSync(resolvedId);
|
|
991
|
+
if (!looksVirtual) return null;
|
|
992
|
+
const loadResult = await pluginContainer.load(resolvedId);
|
|
993
|
+
if (loadResult == null) return null;
|
|
994
|
+
let code = typeof loadResult === "string" ? loadResult : loadResult.code;
|
|
995
|
+
const transformed = await pluginContainer.transform(code, resolvedId);
|
|
996
|
+
if (transformed != null) {
|
|
997
|
+
code = typeof transformed === "string" ? transformed : transformed.code;
|
|
998
|
+
}
|
|
999
|
+
code = replaceEnvInCode(code, ctx.envDefine ?? buildEnvDefine(
|
|
1000
|
+
loadEnv(config.mode, config.root, config.envPrefix),
|
|
1001
|
+
config.mode
|
|
1002
|
+
));
|
|
1003
|
+
const anchor = import_node_path4.default.join(config.root, "__nasti_virtual__.ts");
|
|
1004
|
+
code = rewriteImports(code, config, anchor);
|
|
1005
|
+
return { id: resolvedId, result: { code } };
|
|
1006
|
+
}
|
|
962
1007
|
async function bundlePackageAsEsm(entryFile) {
|
|
963
1008
|
if (!esmBundleCache.has(entryFile)) {
|
|
964
1009
|
esmBundleCache.set(entryFile, doBundlePackage(entryFile));
|
|
@@ -1115,19 +1160,20 @@ function rewriteExternalRequires(code) {
|
|
|
1115
1160
|
}
|
|
1116
1161
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1117
1162
|
try {
|
|
1118
|
-
const { createRequire:
|
|
1119
|
-
const req =
|
|
1163
|
+
const { createRequire: createRequire5 } = await import("module");
|
|
1164
|
+
const req = createRequire5(entryFile);
|
|
1120
1165
|
const cjsExports = req(entryFile);
|
|
1121
1166
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1122
1167
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1123
1168
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1124
1169
|
);
|
|
1125
|
-
|
|
1170
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1171
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1126
1172
|
return code.replace(
|
|
1127
1173
|
/^export default (\w+\(\));?\s*$/m,
|
|
1128
1174
|
(_, call) => [
|
|
1129
1175
|
`const __cjsMod = ${call};`,
|
|
1130
|
-
`export default __cjsMod;`,
|
|
1176
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1131
1177
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1132
1178
|
].join("\n")
|
|
1133
1179
|
);
|
|
@@ -1614,6 +1660,59 @@ var init_resolve = __esm({
|
|
|
1614
1660
|
}
|
|
1615
1661
|
});
|
|
1616
1662
|
|
|
1663
|
+
// src/plugins/tailwind.ts
|
|
1664
|
+
function hasTailwindDirectives(css) {
|
|
1665
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1666
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
1667
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
1668
|
+
}
|
|
1669
|
+
async function loadTailwind(projectRoot) {
|
|
1670
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
1671
|
+
const req = (0, import_node_module3.createRequire)(import_node_path7.default.join(projectRoot, "package.json"));
|
|
1672
|
+
let nodePath;
|
|
1673
|
+
let oxidePath;
|
|
1674
|
+
try {
|
|
1675
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
1676
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
1677
|
+
} catch {
|
|
1678
|
+
throw new Error(
|
|
1679
|
+
"[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"
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
const node = await import((0, import_node_url3.pathToFileURL)(nodePath).href);
|
|
1683
|
+
const oxide = await import((0, import_node_url3.pathToFileURL)(oxidePath).href);
|
|
1684
|
+
cached = { node, oxide };
|
|
1685
|
+
cachedRoot = projectRoot;
|
|
1686
|
+
return cached;
|
|
1687
|
+
}
|
|
1688
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
1689
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
1690
|
+
const dependencies = [];
|
|
1691
|
+
const compiler = await node.compile(css, {
|
|
1692
|
+
base: import_node_path7.default.dirname(fromFile),
|
|
1693
|
+
from: fromFile,
|
|
1694
|
+
onDependency: (p) => dependencies.push(p)
|
|
1695
|
+
});
|
|
1696
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
1697
|
+
const candidates = scanner.scan();
|
|
1698
|
+
return {
|
|
1699
|
+
css: compiler.build(candidates),
|
|
1700
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
var import_node_path7, import_node_module3, import_node_url3, TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
1704
|
+
var init_tailwind = __esm({
|
|
1705
|
+
"src/plugins/tailwind.ts"() {
|
|
1706
|
+
"use strict";
|
|
1707
|
+
import_node_path7 = __toESM(require("path"), 1);
|
|
1708
|
+
import_node_module3 = require("module");
|
|
1709
|
+
import_node_url3 = require("url");
|
|
1710
|
+
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)/;
|
|
1711
|
+
cached = null;
|
|
1712
|
+
cachedRoot = null;
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
|
|
1617
1716
|
// src/plugins/css.ts
|
|
1618
1717
|
function cssPlugin(config) {
|
|
1619
1718
|
return {
|
|
@@ -1622,9 +1721,14 @@ function cssPlugin(config) {
|
|
|
1622
1721
|
if (source.endsWith(".css")) return null;
|
|
1623
1722
|
return null;
|
|
1624
1723
|
},
|
|
1625
|
-
transform(code, id) {
|
|
1724
|
+
async transform(code, id) {
|
|
1626
1725
|
if (!id.endsWith(".css")) return null;
|
|
1627
|
-
|
|
1726
|
+
let cssSource = code;
|
|
1727
|
+
if (hasTailwindDirectives(code)) {
|
|
1728
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
1729
|
+
cssSource = compiled.css;
|
|
1730
|
+
}
|
|
1731
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
1628
1732
|
if (config.command === "serve") {
|
|
1629
1733
|
const escaped = JSON.stringify(rewritten);
|
|
1630
1734
|
return {
|
|
@@ -1659,16 +1763,17 @@ function rewriteCssUrls(css, from, root) {
|
|
|
1659
1763
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
1660
1764
|
return match;
|
|
1661
1765
|
}
|
|
1662
|
-
const resolved =
|
|
1663
|
-
const relative = "/" +
|
|
1766
|
+
const resolved = import_node_path8.default.resolve(import_node_path8.default.dirname(from), url);
|
|
1767
|
+
const relative = "/" + import_node_path8.default.relative(root, resolved);
|
|
1664
1768
|
return `url(${relative})`;
|
|
1665
1769
|
});
|
|
1666
1770
|
}
|
|
1667
|
-
var
|
|
1771
|
+
var import_node_path8;
|
|
1668
1772
|
var init_css = __esm({
|
|
1669
1773
|
"src/plugins/css.ts"() {
|
|
1670
1774
|
"use strict";
|
|
1671
|
-
|
|
1775
|
+
import_node_path8 = __toESM(require("path"), 1);
|
|
1776
|
+
init_tailwind();
|
|
1672
1777
|
}
|
|
1673
1778
|
});
|
|
1674
1779
|
|
|
@@ -1683,7 +1788,7 @@ function assetsPlugin(config) {
|
|
|
1683
1788
|
return null;
|
|
1684
1789
|
},
|
|
1685
1790
|
load(id) {
|
|
1686
|
-
const ext =
|
|
1791
|
+
const ext = import_node_path9.default.extname(id.replace(/\?.*$/, ""));
|
|
1687
1792
|
if (id.endsWith("?raw")) {
|
|
1688
1793
|
const file = id.slice(0, -4);
|
|
1689
1794
|
if (import_node_fs7.default.existsSync(file)) {
|
|
@@ -1695,12 +1800,12 @@ function assetsPlugin(config) {
|
|
|
1695
1800
|
const file = id.replace(/\?.*$/, "");
|
|
1696
1801
|
if (!import_node_fs7.default.existsSync(file)) return null;
|
|
1697
1802
|
if (config.command === "serve") {
|
|
1698
|
-
const url = "/" +
|
|
1803
|
+
const url = "/" + import_node_path9.default.relative(config.root, file);
|
|
1699
1804
|
return `export default ${JSON.stringify(url)}`;
|
|
1700
1805
|
}
|
|
1701
1806
|
const content = import_node_fs7.default.readFileSync(file);
|
|
1702
1807
|
const hash = import_node_crypto.default.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
1703
|
-
const basename =
|
|
1808
|
+
const basename = import_node_path9.default.basename(file, ext);
|
|
1704
1809
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
1705
1810
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
1706
1811
|
}
|
|
@@ -1708,11 +1813,11 @@ function assetsPlugin(config) {
|
|
|
1708
1813
|
}
|
|
1709
1814
|
};
|
|
1710
1815
|
}
|
|
1711
|
-
var
|
|
1816
|
+
var import_node_path9, import_node_fs7, import_node_crypto, ASSET_EXTENSIONS;
|
|
1712
1817
|
var init_assets = __esm({
|
|
1713
1818
|
"src/plugins/assets.ts"() {
|
|
1714
1819
|
"use strict";
|
|
1715
|
-
|
|
1820
|
+
import_node_path9 = __toESM(require("path"), 1);
|
|
1716
1821
|
import_node_fs7 = __toESM(require("fs"), 1);
|
|
1717
1822
|
import_node_crypto = __toESM(require("crypto"), 1);
|
|
1718
1823
|
ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -1765,20 +1870,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1765
1870
|
pluginContainer,
|
|
1766
1871
|
moduleGraph
|
|
1767
1872
|
}));
|
|
1768
|
-
const publicDir =
|
|
1873
|
+
const publicDir = import_node_path10.default.resolve(config.root, "public");
|
|
1769
1874
|
app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
|
|
1770
1875
|
app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
|
|
1771
1876
|
const httpServer = import_node_http.default.createServer(app);
|
|
1772
1877
|
const ws = createWebSocketServer(httpServer);
|
|
1773
1878
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1774
|
-
const outDirAbs =
|
|
1879
|
+
const outDirAbs = import_node_path10.default.resolve(config.root, config.build.outDir);
|
|
1775
1880
|
const watcher = (0, import_chokidar.watch)(config.root, {
|
|
1776
1881
|
ignored: (filePath) => {
|
|
1777
1882
|
if (filePath === config.root) return false;
|
|
1778
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
1779
|
-
const rel =
|
|
1780
|
-
if (!rel || rel.startsWith("..") ||
|
|
1781
|
-
for (const seg of rel.split(
|
|
1883
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path10.default.sep)) return true;
|
|
1884
|
+
const rel = import_node_path10.default.relative(config.root, filePath);
|
|
1885
|
+
if (!rel || rel.startsWith("..") || import_node_path10.default.isAbsolute(rel)) return false;
|
|
1886
|
+
for (const seg of rel.split(import_node_path10.default.sep)) {
|
|
1782
1887
|
if (ignoredSegments.has(seg)) return true;
|
|
1783
1888
|
}
|
|
1784
1889
|
return false;
|
|
@@ -1810,7 +1915,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1810
1915
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1811
1916
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1812
1917
|
console.log();
|
|
1813
|
-
console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.
|
|
1918
|
+
console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.4"}`));
|
|
1814
1919
|
console.log();
|
|
1815
1920
|
console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
|
|
1816
1921
|
if (networkUrl) {
|
|
@@ -1866,12 +1971,12 @@ function getNetworkAddress() {
|
|
|
1866
1971
|
}
|
|
1867
1972
|
return "localhost";
|
|
1868
1973
|
}
|
|
1869
|
-
var import_node_http,
|
|
1974
|
+
var import_node_http, import_node_path10, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors;
|
|
1870
1975
|
var init_server = __esm({
|
|
1871
1976
|
"src/server/index.ts"() {
|
|
1872
1977
|
"use strict";
|
|
1873
1978
|
import_node_http = __toESM(require("http"), 1);
|
|
1874
|
-
|
|
1979
|
+
import_node_path10 = __toESM(require("path"), 1);
|
|
1875
1980
|
import_node_os = __toESM(require("os"), 1);
|
|
1876
1981
|
import_connect = __toESM(require("connect"), 1);
|
|
1877
1982
|
import_sirv = __toESM(require("sirv"), 1);
|
|
@@ -1911,14 +2016,14 @@ function electronPlugin(config) {
|
|
|
1911
2016
|
}
|
|
1912
2017
|
};
|
|
1913
2018
|
}
|
|
1914
|
-
var
|
|
2019
|
+
var import_node_module4, NODE_BUILTINS, ELECTRON_MODULES;
|
|
1915
2020
|
var init_electron = __esm({
|
|
1916
2021
|
"src/plugins/electron.ts"() {
|
|
1917
2022
|
"use strict";
|
|
1918
|
-
|
|
2023
|
+
import_node_module4 = require("module");
|
|
1919
2024
|
NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
1920
|
-
...
|
|
1921
|
-
...
|
|
2025
|
+
...import_node_module4.builtinModules,
|
|
2026
|
+
...import_node_module4.builtinModules.map((m) => `node:${m}`)
|
|
1922
2027
|
]);
|
|
1923
2028
|
ELECTRON_MODULES = /* @__PURE__ */ new Set([
|
|
1924
2029
|
"electron",
|
|
@@ -1937,10 +2042,10 @@ __export(build_exports, {
|
|
|
1937
2042
|
async function build(inlineConfig = {}) {
|
|
1938
2043
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1939
2044
|
const startTime = performance.now();
|
|
1940
|
-
console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.
|
|
2045
|
+
console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.4"}`));
|
|
1941
2046
|
console.log(import_picocolors2.default.dim(` root: ${config.root}`));
|
|
1942
2047
|
console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
|
|
1943
|
-
const outDir =
|
|
2048
|
+
const outDir = import_node_path11.default.resolve(config.root, config.build.outDir);
|
|
1944
2049
|
if (config.build.emptyOutDir && import_node_fs8.default.existsSync(outDir)) {
|
|
1945
2050
|
import_node_fs8.default.rmSync(outDir, { recursive: true, force: true });
|
|
1946
2051
|
}
|
|
@@ -1952,14 +2057,14 @@ async function build(inlineConfig = {}) {
|
|
|
1952
2057
|
for (const match of scriptMatches) {
|
|
1953
2058
|
const src = match[1];
|
|
1954
2059
|
if (src && !src.startsWith("http")) {
|
|
1955
|
-
entryPoints.push(
|
|
2060
|
+
entryPoints.push(import_node_path11.default.resolve(config.root, src.replace(/^\//, "")));
|
|
1956
2061
|
}
|
|
1957
2062
|
}
|
|
1958
2063
|
}
|
|
1959
2064
|
if (entryPoints.length === 0) {
|
|
1960
2065
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
1961
2066
|
for (const entry of fallbackEntries) {
|
|
1962
|
-
const fullPath =
|
|
2067
|
+
const fullPath = import_node_path11.default.resolve(config.root, entry);
|
|
1963
2068
|
if (import_node_fs8.default.existsSync(fullPath)) {
|
|
1964
2069
|
entryPoints.push(fullPath);
|
|
1965
2070
|
break;
|
|
@@ -2003,7 +2108,11 @@ async function build(inlineConfig = {}) {
|
|
|
2003
2108
|
load: p.load,
|
|
2004
2109
|
transform: p.transform,
|
|
2005
2110
|
buildStart: p.buildStart,
|
|
2006
|
-
buildEnd: p.buildEnd
|
|
2111
|
+
buildEnd: p.buildEnd,
|
|
2112
|
+
// Forward `closeBundle` to Rolldown — it invokes the hook during
|
|
2113
|
+
// `bundle.close()` below. This is the hook Vite plugins (e.g. PWA
|
|
2114
|
+
// manifest/SW writers) rely on for final-stage artifact emission.
|
|
2115
|
+
closeBundle: p.closeBundle
|
|
2007
2116
|
}))
|
|
2008
2117
|
],
|
|
2009
2118
|
...config.build.rolldownOptions
|
|
@@ -2020,8 +2129,8 @@ async function build(inlineConfig = {}) {
|
|
|
2020
2129
|
await bundle.close();
|
|
2021
2130
|
await pluginContainer.buildEnd();
|
|
2022
2131
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
2023
|
-
const dest =
|
|
2024
|
-
import_node_fs8.default.mkdirSync(
|
|
2132
|
+
const dest = import_node_path11.default.resolve(outDir, ef.fileName);
|
|
2133
|
+
import_node_fs8.default.mkdirSync(import_node_path11.default.dirname(dest), { recursive: true });
|
|
2025
2134
|
import_node_fs8.default.writeFileSync(dest, ef.source);
|
|
2026
2135
|
}
|
|
2027
2136
|
if (html) {
|
|
@@ -2039,14 +2148,14 @@ async function build(inlineConfig = {}) {
|
|
|
2039
2148
|
}
|
|
2040
2149
|
for (const chunk of output) {
|
|
2041
2150
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
2042
|
-
const originalEntry =
|
|
2151
|
+
const originalEntry = import_node_path11.default.relative(config.root, chunk.facadeModuleId);
|
|
2043
2152
|
processedHtml = processedHtml.replace(
|
|
2044
2153
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
2045
2154
|
`$1${config.base}${chunk.fileName}$3`
|
|
2046
2155
|
);
|
|
2047
2156
|
}
|
|
2048
2157
|
}
|
|
2049
|
-
import_node_fs8.default.writeFileSync(
|
|
2158
|
+
import_node_fs8.default.writeFileSync(import_node_path11.default.resolve(outDir, "index.html"), processedHtml);
|
|
2050
2159
|
}
|
|
2051
2160
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2052
2161
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -2068,11 +2177,11 @@ function formatSize(bytes) {
|
|
|
2068
2177
|
function escapeRegExp(string) {
|
|
2069
2178
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2070
2179
|
}
|
|
2071
|
-
var
|
|
2180
|
+
var import_node_path11, import_node_fs8, import_rolldown, import_picocolors2;
|
|
2072
2181
|
var init_build = __esm({
|
|
2073
2182
|
"src/build/index.ts"() {
|
|
2074
2183
|
"use strict";
|
|
2075
|
-
|
|
2184
|
+
import_node_path11 = __toESM(require("path"), 1);
|
|
2076
2185
|
import_node_fs8 = __toESM(require("fs"), 1);
|
|
2077
2186
|
import_rolldown = require("rolldown");
|
|
2078
2187
|
init_config();
|
|
@@ -2098,16 +2207,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2098
2207
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2099
2208
|
const startTime = performance.now();
|
|
2100
2209
|
assertElectronVersion(config);
|
|
2101
|
-
console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.
|
|
2210
|
+
console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.4"}`));
|
|
2102
2211
|
console.log(import_picocolors3.default.dim(` root: ${config.root}`));
|
|
2103
2212
|
console.log(import_picocolors3.default.dim(` mode: ${config.mode}`));
|
|
2104
2213
|
console.log(import_picocolors3.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2105
|
-
const outDir =
|
|
2214
|
+
const outDir = import_node_path12.default.resolve(config.root, config.build.outDir);
|
|
2106
2215
|
if (config.build.emptyOutDir && import_node_fs9.default.existsSync(outDir)) {
|
|
2107
2216
|
import_node_fs9.default.rmSync(outDir, { recursive: true, force: true });
|
|
2108
2217
|
}
|
|
2109
2218
|
import_node_fs9.default.mkdirSync(outDir, { recursive: true });
|
|
2110
|
-
const rendererOutDir =
|
|
2219
|
+
const rendererOutDir = import_node_path12.default.join(outDir, "renderer");
|
|
2111
2220
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2112
2221
|
await build2({
|
|
2113
2222
|
...inlineConfig,
|
|
@@ -2118,7 +2227,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2118
2227
|
emptyOutDir: false
|
|
2119
2228
|
}
|
|
2120
2229
|
});
|
|
2121
|
-
const mainEntry =
|
|
2230
|
+
const mainEntry = import_node_path12.default.resolve(config.root, config.electron.main);
|
|
2122
2231
|
if (!import_node_fs9.default.existsSync(mainEntry)) {
|
|
2123
2232
|
throw new Error(
|
|
2124
2233
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2137,7 +2246,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2137
2246
|
console.warn(import_picocolors3.default.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2138
2247
|
continue;
|
|
2139
2248
|
}
|
|
2140
|
-
const base =
|
|
2249
|
+
const base = import_node_path12.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
2141
2250
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2142
2251
|
await bundleNode(config, entry, {
|
|
2143
2252
|
outFile: out,
|
|
@@ -2149,10 +2258,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2149
2258
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2150
2259
|
console.log(import_picocolors3.default.green(`
|
|
2151
2260
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2152
|
-
console.log(import_picocolors3.default.dim(` renderer: ${
|
|
2153
|
-
console.log(import_picocolors3.default.dim(` main: ${
|
|
2261
|
+
console.log(import_picocolors3.default.dim(` renderer: ${import_node_path12.default.relative(config.root, rendererOutDir)}/`));
|
|
2262
|
+
console.log(import_picocolors3.default.dim(` main: ${import_node_path12.default.relative(config.root, mainFile)}`));
|
|
2154
2263
|
for (const pf of preloadFiles) {
|
|
2155
|
-
console.log(import_picocolors3.default.dim(` preload: ${
|
|
2264
|
+
console.log(import_picocolors3.default.dim(` preload: ${import_node_path12.default.relative(config.root, pf)}`));
|
|
2156
2265
|
}
|
|
2157
2266
|
console.log();
|
|
2158
2267
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2183,7 +2292,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2183
2292
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2184
2293
|
...config.build.rolldownOptions
|
|
2185
2294
|
});
|
|
2186
|
-
import_node_fs9.default.mkdirSync(
|
|
2295
|
+
import_node_fs9.default.mkdirSync(import_node_path12.default.dirname(opts.outFile), { recursive: true });
|
|
2187
2296
|
await bundle.write({
|
|
2188
2297
|
file: opts.outFile,
|
|
2189
2298
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2192,16 +2301,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2192
2301
|
codeSplitting: false
|
|
2193
2302
|
});
|
|
2194
2303
|
await bundle.close();
|
|
2195
|
-
console.log(import_picocolors3.default.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2304
|
+
console.log(import_picocolors3.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path12.default.relative(config.root, opts.outFile)}`));
|
|
2196
2305
|
return opts.outFile;
|
|
2197
2306
|
}
|
|
2198
2307
|
function outFileName(outDir, base, format) {
|
|
2199
2308
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2200
|
-
return
|
|
2309
|
+
return import_node_path12.default.join(outDir, base + ext);
|
|
2201
2310
|
}
|
|
2202
2311
|
function normalizePreload(preload, root) {
|
|
2203
2312
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2204
|
-
return list.map((p) =>
|
|
2313
|
+
return list.map((p) => import_node_path12.default.resolve(root, p));
|
|
2205
2314
|
}
|
|
2206
2315
|
function assertElectronVersion(config) {
|
|
2207
2316
|
const min = config.electron.minVersion;
|
|
@@ -2216,7 +2325,7 @@ function assertElectronVersion(config) {
|
|
|
2216
2325
|
}
|
|
2217
2326
|
function detectInstalledElectron(root) {
|
|
2218
2327
|
try {
|
|
2219
|
-
const pkgPath =
|
|
2328
|
+
const pkgPath = import_node_path12.default.resolve(root, "node_modules/electron/package.json");
|
|
2220
2329
|
if (!import_node_fs9.default.existsSync(pkgPath)) return null;
|
|
2221
2330
|
const pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgPath, "utf-8"));
|
|
2222
2331
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2225,11 +2334,11 @@ function detectInstalledElectron(root) {
|
|
|
2225
2334
|
return null;
|
|
2226
2335
|
}
|
|
2227
2336
|
}
|
|
2228
|
-
var
|
|
2337
|
+
var import_node_path12, import_node_fs9, import_rolldown2, import_picocolors3;
|
|
2229
2338
|
var init_electron2 = __esm({
|
|
2230
2339
|
"src/build/electron.ts"() {
|
|
2231
2340
|
"use strict";
|
|
2232
|
-
|
|
2341
|
+
import_node_path12 = __toESM(require("path"), 1);
|
|
2233
2342
|
import_node_fs9 = __toESM(require("fs"), 1);
|
|
2234
2343
|
import_rolldown2 = require("rolldown");
|
|
2235
2344
|
import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
@@ -2250,17 +2359,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2250
2359
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2251
2360
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2252
2361
|
warnElectronVersion(config);
|
|
2253
|
-
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.
|
|
2362
|
+
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.4"}`));
|
|
2254
2363
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2255
2364
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2256
2365
|
await server.listen();
|
|
2257
2366
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2258
2367
|
console.log(import_picocolors4.default.dim(` renderer: ${devUrl}`));
|
|
2259
|
-
const stageDir =
|
|
2368
|
+
const stageDir = import_node_path13.default.resolve(config.root, ".nasti");
|
|
2260
2369
|
import_node_fs10.default.mkdirSync(stageDir, { recursive: true });
|
|
2261
|
-
const mainEntry =
|
|
2370
|
+
const mainEntry = import_node_path13.default.resolve(config.root, config.electron.main);
|
|
2262
2371
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2263
|
-
const builtMainFile =
|
|
2372
|
+
const builtMainFile = import_node_path13.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2264
2373
|
const builtPreloadFiles = [];
|
|
2265
2374
|
const compileAll = async () => {
|
|
2266
2375
|
await compileNode(config, mainEntry, {
|
|
@@ -2271,8 +2380,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2271
2380
|
builtPreloadFiles.length = 0;
|
|
2272
2381
|
for (const entry of preloadEntries) {
|
|
2273
2382
|
if (!import_node_fs10.default.existsSync(entry)) continue;
|
|
2274
|
-
const base =
|
|
2275
|
-
const out =
|
|
2383
|
+
const base = import_node_path13.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
2384
|
+
const out = import_node_path13.default.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2276
2385
|
await compileNode(config, entry, {
|
|
2277
2386
|
outFile: out,
|
|
2278
2387
|
format: config.electron.preloadFormat,
|
|
@@ -2387,7 +2496,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2387
2496
|
platform: "node",
|
|
2388
2497
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2389
2498
|
});
|
|
2390
|
-
import_node_fs10.default.mkdirSync(
|
|
2499
|
+
import_node_fs10.default.mkdirSync(import_node_path13.default.dirname(opts.outFile), { recursive: true });
|
|
2391
2500
|
await bundle.write({
|
|
2392
2501
|
file: opts.outFile,
|
|
2393
2502
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2404,7 +2513,7 @@ function resolveElectronBinary(config) {
|
|
|
2404
2513
|
return config.electron.electronPath;
|
|
2405
2514
|
}
|
|
2406
2515
|
try {
|
|
2407
|
-
const require2 = (0,
|
|
2516
|
+
const require2 = (0, import_node_module5.createRequire)(import_node_path13.default.resolve(config.root, "package.json"));
|
|
2408
2517
|
const pathFile = require2.resolve("electron");
|
|
2409
2518
|
const electronModule = require2(pathFile);
|
|
2410
2519
|
if (typeof electronModule === "string" && import_node_fs10.default.existsSync(electronModule)) {
|
|
@@ -2432,13 +2541,13 @@ function warnElectronVersion(config) {
|
|
|
2432
2541
|
);
|
|
2433
2542
|
}
|
|
2434
2543
|
}
|
|
2435
|
-
var
|
|
2544
|
+
var import_node_path13, import_node_fs10, import_node_module5, import_node_child_process, import_chokidar2, import_picocolors4, import_rolldown3;
|
|
2436
2545
|
var init_electron_dev = __esm({
|
|
2437
2546
|
"src/server/electron-dev.ts"() {
|
|
2438
2547
|
"use strict";
|
|
2439
|
-
|
|
2548
|
+
import_node_path13 = __toESM(require("path"), 1);
|
|
2440
2549
|
import_node_fs10 = __toESM(require("fs"), 1);
|
|
2441
|
-
|
|
2550
|
+
import_node_module5 = require("module");
|
|
2442
2551
|
import_node_child_process = require("child_process");
|
|
2443
2552
|
import_chokidar2 = __toESM(require("chokidar"), 1);
|
|
2444
2553
|
import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
@@ -2560,11 +2669,11 @@ cli.command("electron-build [root]", "Build Electron app for production").option
|
|
|
2560
2669
|
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) => {
|
|
2561
2670
|
try {
|
|
2562
2671
|
const http2 = await import("http");
|
|
2563
|
-
const
|
|
2672
|
+
const path14 = await import("path");
|
|
2564
2673
|
const sirv2 = (await import("sirv")).default;
|
|
2565
2674
|
const connect2 = (await import("connect")).default;
|
|
2566
|
-
const resolvedRoot =
|
|
2567
|
-
const outDir =
|
|
2675
|
+
const resolvedRoot = path14.resolve(root ?? ".");
|
|
2676
|
+
const outDir = path14.resolve(resolvedRoot, options.outDir);
|
|
2568
2677
|
const app = connect2();
|
|
2569
2678
|
app.use(sirv2(outDir, { single: true, etag: true, gzip: true, brotli: true }));
|
|
2570
2679
|
const port = options.port;
|
|
@@ -2585,6 +2694,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2585
2694
|
}
|
|
2586
2695
|
});
|
|
2587
2696
|
cli.help();
|
|
2588
|
-
cli.version("1.6.
|
|
2697
|
+
cli.version("1.6.4");
|
|
2589
2698
|
cli.parse();
|
|
2590
2699
|
//# sourceMappingURL=cli.cjs.map
|