@nasti-toolchain/nasti 1.6.3 → 1.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +197 -82
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +187 -72
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +254 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +243 -128
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/cli.js
CHANGED
|
@@ -35,7 +35,8 @@ var init_defaults = __esm({
|
|
|
35
35
|
sourcemap: false,
|
|
36
36
|
target: "es2022",
|
|
37
37
|
rolldownOptions: {},
|
|
38
|
-
emptyOutDir: true
|
|
38
|
+
emptyOutDir: true,
|
|
39
|
+
css: {}
|
|
39
40
|
};
|
|
40
41
|
defaultElectron = {
|
|
41
42
|
main: "src/electron/main.ts",
|
|
@@ -900,9 +901,9 @@ function transformMiddleware(ctx) {
|
|
|
900
901
|
async function transformRequest(url, ctx) {
|
|
901
902
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
902
903
|
const cleanReqUrl = url.split("?")[0];
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
905
|
-
return
|
|
904
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
905
|
+
if (cached2?.transformResult) {
|
|
906
|
+
return cached2.transformResult;
|
|
906
907
|
}
|
|
907
908
|
if (cleanReqUrl === "/@react-refresh") {
|
|
908
909
|
return { code: getReactRefreshRuntimeEsm() };
|
|
@@ -1141,19 +1142,20 @@ function rewriteExternalRequires(code) {
|
|
|
1141
1142
|
}
|
|
1142
1143
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1143
1144
|
try {
|
|
1144
|
-
const { createRequire:
|
|
1145
|
-
const req =
|
|
1145
|
+
const { createRequire: createRequire5 } = await import("module");
|
|
1146
|
+
const req = createRequire5(entryFile);
|
|
1146
1147
|
const cjsExports = req(entryFile);
|
|
1147
1148
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1148
1149
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1149
1150
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1150
1151
|
);
|
|
1151
|
-
|
|
1152
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1153
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1152
1154
|
return code.replace(
|
|
1153
1155
|
/^export default (\w+\(\));?\s*$/m,
|
|
1154
1156
|
(_, call) => [
|
|
1155
1157
|
`const __cjsMod = ${call};`,
|
|
1156
|
-
`export default __cjsMod;`,
|
|
1158
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1157
1159
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1158
1160
|
].join("\n")
|
|
1159
1161
|
);
|
|
@@ -1562,20 +1564,29 @@ import { createRequire as createRequire2 } from "module";
|
|
|
1562
1564
|
function resolvePlugin(config) {
|
|
1563
1565
|
const { alias, extensions } = config.resolve;
|
|
1564
1566
|
const require2 = createRequire2(path6.resolve(config.root, "package.json"));
|
|
1567
|
+
const aliasEntries = Object.entries(alias).sort(
|
|
1568
|
+
([a], [b]) => b.length - a.length
|
|
1569
|
+
);
|
|
1565
1570
|
return {
|
|
1566
1571
|
name: "nasti:resolve",
|
|
1567
1572
|
enforce: "pre",
|
|
1568
1573
|
resolveId(source, importer) {
|
|
1569
|
-
for (const [key, value] of
|
|
1574
|
+
for (const [key, value] of aliasEntries) {
|
|
1570
1575
|
if (source === key || source.startsWith(key + "/")) {
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1576
|
+
const aliasBase = resolveAliasTarget2(value, config.root);
|
|
1577
|
+
const sub = source.slice(key.length).replace(/^\//, "");
|
|
1578
|
+
const target = sub ? path6.join(aliasBase, sub) : aliasBase;
|
|
1579
|
+
const resolved = tryResolveFile(target, extensions);
|
|
1580
|
+
if (resolved) return resolved;
|
|
1575
1581
|
break;
|
|
1576
1582
|
}
|
|
1577
1583
|
}
|
|
1578
|
-
if (
|
|
1584
|
+
if (source.startsWith("/") && !source.startsWith("//")) {
|
|
1585
|
+
const rootRelative = path6.join(config.root, source.slice(1));
|
|
1586
|
+
const resolved = tryResolveFile(rootRelative, extensions);
|
|
1587
|
+
if (resolved) return resolved;
|
|
1588
|
+
}
|
|
1589
|
+
if (path6.isAbsolute(source) && fs6.existsSync(source)) {
|
|
1579
1590
|
const resolved = tryResolveFile(source, extensions);
|
|
1580
1591
|
if (resolved) return resolved;
|
|
1581
1592
|
}
|
|
@@ -1598,6 +1609,7 @@ function resolvePlugin(config) {
|
|
|
1598
1609
|
return null;
|
|
1599
1610
|
},
|
|
1600
1611
|
load(id) {
|
|
1612
|
+
if (id.startsWith("\0")) return null;
|
|
1601
1613
|
if (!fs6.existsSync(id)) return null;
|
|
1602
1614
|
if (id.endsWith(".json")) {
|
|
1603
1615
|
const content = fs6.readFileSync(id, "utf-8");
|
|
@@ -1607,6 +1619,11 @@ function resolvePlugin(config) {
|
|
|
1607
1619
|
}
|
|
1608
1620
|
};
|
|
1609
1621
|
}
|
|
1622
|
+
function resolveAliasTarget2(value, root) {
|
|
1623
|
+
if (path6.isAbsolute(value) && fs6.existsSync(value)) return value;
|
|
1624
|
+
if (value.startsWith("/")) return path6.join(root, value.slice(1));
|
|
1625
|
+
return path6.resolve(root, value);
|
|
1626
|
+
}
|
|
1610
1627
|
function tryResolveFile(file, extensions) {
|
|
1611
1628
|
if (fs6.existsSync(file) && fs6.statSync(file).isFile()) {
|
|
1612
1629
|
return file;
|
|
@@ -1633,8 +1650,61 @@ var init_resolve = __esm({
|
|
|
1633
1650
|
}
|
|
1634
1651
|
});
|
|
1635
1652
|
|
|
1636
|
-
// src/plugins/
|
|
1653
|
+
// src/plugins/tailwind.ts
|
|
1637
1654
|
import path7 from "path";
|
|
1655
|
+
import { createRequire as createRequire3 } from "module";
|
|
1656
|
+
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
1657
|
+
function hasTailwindDirectives(css) {
|
|
1658
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1659
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
1660
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
1661
|
+
}
|
|
1662
|
+
async function loadTailwind(projectRoot) {
|
|
1663
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
1664
|
+
const req = createRequire3(path7.join(projectRoot, "package.json"));
|
|
1665
|
+
let nodePath;
|
|
1666
|
+
let oxidePath;
|
|
1667
|
+
try {
|
|
1668
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
1669
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
1670
|
+
} catch {
|
|
1671
|
+
throw new Error(
|
|
1672
|
+
"[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"
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1675
|
+
const node = await import(pathToFileURL3(nodePath).href);
|
|
1676
|
+
const oxide = await import(pathToFileURL3(oxidePath).href);
|
|
1677
|
+
cached = { node, oxide };
|
|
1678
|
+
cachedRoot = projectRoot;
|
|
1679
|
+
return cached;
|
|
1680
|
+
}
|
|
1681
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
1682
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
1683
|
+
const dependencies = [];
|
|
1684
|
+
const compiler = await node.compile(css, {
|
|
1685
|
+
base: path7.dirname(fromFile),
|
|
1686
|
+
from: fromFile,
|
|
1687
|
+
onDependency: (p) => dependencies.push(p)
|
|
1688
|
+
});
|
|
1689
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
1690
|
+
const candidates = scanner.scan();
|
|
1691
|
+
return {
|
|
1692
|
+
css: compiler.build(candidates),
|
|
1693
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
var TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
1697
|
+
var init_tailwind = __esm({
|
|
1698
|
+
"src/plugins/tailwind.ts"() {
|
|
1699
|
+
"use strict";
|
|
1700
|
+
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)/;
|
|
1701
|
+
cached = null;
|
|
1702
|
+
cachedRoot = null;
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
|
|
1706
|
+
// src/plugins/css.ts
|
|
1707
|
+
import path8 from "path";
|
|
1638
1708
|
function cssPlugin(config) {
|
|
1639
1709
|
return {
|
|
1640
1710
|
name: "nasti:css",
|
|
@@ -1642,11 +1712,16 @@ function cssPlugin(config) {
|
|
|
1642
1712
|
if (source.endsWith(".css")) return null;
|
|
1643
1713
|
return null;
|
|
1644
1714
|
},
|
|
1645
|
-
transform(code, id) {
|
|
1715
|
+
async transform(code, id) {
|
|
1646
1716
|
if (!id.endsWith(".css")) return null;
|
|
1647
|
-
|
|
1717
|
+
let cssSource = code;
|
|
1718
|
+
if (hasTailwindDirectives(code)) {
|
|
1719
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
1720
|
+
cssSource = compiled.css;
|
|
1721
|
+
}
|
|
1722
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
1723
|
+
const escaped = JSON.stringify(rewritten);
|
|
1648
1724
|
if (config.command === "serve") {
|
|
1649
|
-
const escaped = JSON.stringify(rewritten);
|
|
1650
1725
|
return {
|
|
1651
1726
|
code: `
|
|
1652
1727
|
const css = ${escaped};
|
|
@@ -1670,7 +1745,42 @@ export default css;
|
|
|
1670
1745
|
`
|
|
1671
1746
|
};
|
|
1672
1747
|
}
|
|
1673
|
-
|
|
1748
|
+
const cssConfig = config.build.css || {};
|
|
1749
|
+
const nonce = cssConfig.nonce;
|
|
1750
|
+
const emitCssFile = cssConfig.emitCssFile;
|
|
1751
|
+
if (emitCssFile) {
|
|
1752
|
+
const fileName = `assets/${path8.basename(id, ".css")}.css`;
|
|
1753
|
+
this.emitFile({
|
|
1754
|
+
type: "asset",
|
|
1755
|
+
fileName,
|
|
1756
|
+
source: rewritten
|
|
1757
|
+
});
|
|
1758
|
+
return {
|
|
1759
|
+
code: `
|
|
1760
|
+
const link = document.createElement('link');
|
|
1761
|
+
link.rel = 'stylesheet';
|
|
1762
|
+
link.href = ${JSON.stringify("/" + fileName)};
|
|
1763
|
+
document.head.appendChild(link);
|
|
1764
|
+
|
|
1765
|
+
export default ${escaped};
|
|
1766
|
+
`,
|
|
1767
|
+
moduleType: "js"
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
const nonceAttr = nonce ? `style.setAttribute('nonce', ${JSON.stringify(nonce)});` : "";
|
|
1771
|
+
return {
|
|
1772
|
+
code: `
|
|
1773
|
+
const css = ${escaped};
|
|
1774
|
+
const style = document.createElement('style');
|
|
1775
|
+
style.setAttribute('data-nasti-css', ${JSON.stringify(id)});
|
|
1776
|
+
${nonceAttr}
|
|
1777
|
+
style.textContent = css;
|
|
1778
|
+
document.head.appendChild(style);
|
|
1779
|
+
|
|
1780
|
+
export default css;
|
|
1781
|
+
`,
|
|
1782
|
+
moduleType: "js"
|
|
1783
|
+
};
|
|
1674
1784
|
}
|
|
1675
1785
|
};
|
|
1676
1786
|
}
|
|
@@ -1679,19 +1789,20 @@ function rewriteCssUrls(css, from, root) {
|
|
|
1679
1789
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
1680
1790
|
return match;
|
|
1681
1791
|
}
|
|
1682
|
-
const resolved =
|
|
1683
|
-
const relative = "/" +
|
|
1792
|
+
const resolved = path8.resolve(path8.dirname(from), url);
|
|
1793
|
+
const relative = "/" + path8.relative(root, resolved);
|
|
1684
1794
|
return `url(${relative})`;
|
|
1685
1795
|
});
|
|
1686
1796
|
}
|
|
1687
1797
|
var init_css = __esm({
|
|
1688
1798
|
"src/plugins/css.ts"() {
|
|
1689
1799
|
"use strict";
|
|
1800
|
+
init_tailwind();
|
|
1690
1801
|
}
|
|
1691
1802
|
});
|
|
1692
1803
|
|
|
1693
1804
|
// src/plugins/assets.ts
|
|
1694
|
-
import
|
|
1805
|
+
import path9 from "path";
|
|
1695
1806
|
import fs7 from "fs";
|
|
1696
1807
|
import crypto from "crypto";
|
|
1697
1808
|
function assetsPlugin(config) {
|
|
@@ -1704,7 +1815,7 @@ function assetsPlugin(config) {
|
|
|
1704
1815
|
return null;
|
|
1705
1816
|
},
|
|
1706
1817
|
load(id) {
|
|
1707
|
-
const ext =
|
|
1818
|
+
const ext = path9.extname(id.replace(/\?.*$/, ""));
|
|
1708
1819
|
if (id.endsWith("?raw")) {
|
|
1709
1820
|
const file = id.slice(0, -4);
|
|
1710
1821
|
if (fs7.existsSync(file)) {
|
|
@@ -1716,12 +1827,12 @@ function assetsPlugin(config) {
|
|
|
1716
1827
|
const file = id.replace(/\?.*$/, "");
|
|
1717
1828
|
if (!fs7.existsSync(file)) return null;
|
|
1718
1829
|
if (config.command === "serve") {
|
|
1719
|
-
const url = "/" +
|
|
1830
|
+
const url = "/" + path9.relative(config.root, file);
|
|
1720
1831
|
return `export default ${JSON.stringify(url)}`;
|
|
1721
1832
|
}
|
|
1722
1833
|
const content = fs7.readFileSync(file);
|
|
1723
1834
|
const hash = crypto.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
1724
|
-
const basename =
|
|
1835
|
+
const basename = path9.basename(file, ext);
|
|
1725
1836
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
1726
1837
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
1727
1838
|
}
|
|
@@ -1766,7 +1877,7 @@ __export(server_exports, {
|
|
|
1766
1877
|
createServer: () => createServer
|
|
1767
1878
|
});
|
|
1768
1879
|
import http from "http";
|
|
1769
|
-
import
|
|
1880
|
+
import path10 from "path";
|
|
1770
1881
|
import os from "os";
|
|
1771
1882
|
import connect from "connect";
|
|
1772
1883
|
import sirv from "sirv";
|
|
@@ -1790,20 +1901,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1790
1901
|
pluginContainer,
|
|
1791
1902
|
moduleGraph
|
|
1792
1903
|
}));
|
|
1793
|
-
const publicDir =
|
|
1904
|
+
const publicDir = path10.resolve(config.root, "public");
|
|
1794
1905
|
app.use(sirv(publicDir, { dev: true, etag: true }));
|
|
1795
1906
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
1796
1907
|
const httpServer = http.createServer(app);
|
|
1797
1908
|
const ws = createWebSocketServer(httpServer);
|
|
1798
1909
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1799
|
-
const outDirAbs =
|
|
1910
|
+
const outDirAbs = path10.resolve(config.root, config.build.outDir);
|
|
1800
1911
|
const watcher = watch(config.root, {
|
|
1801
1912
|
ignored: (filePath) => {
|
|
1802
1913
|
if (filePath === config.root) return false;
|
|
1803
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
1804
|
-
const rel =
|
|
1805
|
-
if (!rel || rel.startsWith("..") ||
|
|
1806
|
-
for (const seg of rel.split(
|
|
1914
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path10.sep)) return true;
|
|
1915
|
+
const rel = path10.relative(config.root, filePath);
|
|
1916
|
+
if (!rel || rel.startsWith("..") || path10.isAbsolute(rel)) return false;
|
|
1917
|
+
for (const seg of rel.split(path10.sep)) {
|
|
1807
1918
|
if (ignoredSegments.has(seg)) return true;
|
|
1808
1919
|
}
|
|
1809
1920
|
return false;
|
|
@@ -1835,7 +1946,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1835
1946
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1836
1947
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1837
1948
|
console.log();
|
|
1838
|
-
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.
|
|
1949
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.5"}`));
|
|
1839
1950
|
console.log();
|
|
1840
1951
|
console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
|
|
1841
1952
|
if (networkUrl) {
|
|
@@ -1951,17 +2062,17 @@ var build_exports = {};
|
|
|
1951
2062
|
__export(build_exports, {
|
|
1952
2063
|
build: () => build
|
|
1953
2064
|
});
|
|
1954
|
-
import
|
|
2065
|
+
import path11 from "path";
|
|
1955
2066
|
import fs8 from "fs";
|
|
1956
2067
|
import { rolldown } from "rolldown";
|
|
1957
2068
|
import pc2 from "picocolors";
|
|
1958
2069
|
async function build(inlineConfig = {}) {
|
|
1959
2070
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1960
2071
|
const startTime = performance.now();
|
|
1961
|
-
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.
|
|
2072
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.5"}`));
|
|
1962
2073
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1963
2074
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1964
|
-
const outDir =
|
|
2075
|
+
const outDir = path11.resolve(config.root, config.build.outDir);
|
|
1965
2076
|
if (config.build.emptyOutDir && fs8.existsSync(outDir)) {
|
|
1966
2077
|
fs8.rmSync(outDir, { recursive: true, force: true });
|
|
1967
2078
|
}
|
|
@@ -1973,14 +2084,14 @@ async function build(inlineConfig = {}) {
|
|
|
1973
2084
|
for (const match of scriptMatches) {
|
|
1974
2085
|
const src = match[1];
|
|
1975
2086
|
if (src && !src.startsWith("http")) {
|
|
1976
|
-
entryPoints.push(
|
|
2087
|
+
entryPoints.push(path11.resolve(config.root, src.replace(/^\//, "")));
|
|
1977
2088
|
}
|
|
1978
2089
|
}
|
|
1979
2090
|
}
|
|
1980
2091
|
if (entryPoints.length === 0) {
|
|
1981
2092
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
1982
2093
|
for (const entry of fallbackEntries) {
|
|
1983
|
-
const fullPath =
|
|
2094
|
+
const fullPath = path11.resolve(config.root, entry);
|
|
1984
2095
|
if (fs8.existsSync(fullPath)) {
|
|
1985
2096
|
entryPoints.push(fullPath);
|
|
1986
2097
|
break;
|
|
@@ -2012,9 +2123,11 @@ async function build(inlineConfig = {}) {
|
|
|
2012
2123
|
};
|
|
2013
2124
|
const env = loadEnv(config.mode, config.root, config.envPrefix);
|
|
2014
2125
|
const envDefine = buildEnvDefine(env, config.mode);
|
|
2126
|
+
const existingTransform = config.build.rolldownOptions?.transform;
|
|
2127
|
+
const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
|
|
2015
2128
|
const bundle = await rolldown({
|
|
2016
2129
|
input: entryPoints,
|
|
2017
|
-
define:
|
|
2130
|
+
transform: { ...existingTransform, define: mergedDefine },
|
|
2018
2131
|
plugins: [
|
|
2019
2132
|
oxcTransformPlugin,
|
|
2020
2133
|
// 转换 Nasti 插件为 Rolldown 插件格式
|
|
@@ -2045,8 +2158,8 @@ async function build(inlineConfig = {}) {
|
|
|
2045
2158
|
await bundle.close();
|
|
2046
2159
|
await pluginContainer.buildEnd();
|
|
2047
2160
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
2048
|
-
const dest =
|
|
2049
|
-
fs8.mkdirSync(
|
|
2161
|
+
const dest = path11.resolve(outDir, ef.fileName);
|
|
2162
|
+
fs8.mkdirSync(path11.dirname(dest), { recursive: true });
|
|
2050
2163
|
fs8.writeFileSync(dest, ef.source);
|
|
2051
2164
|
}
|
|
2052
2165
|
if (html) {
|
|
@@ -2064,14 +2177,14 @@ async function build(inlineConfig = {}) {
|
|
|
2064
2177
|
}
|
|
2065
2178
|
for (const chunk of output) {
|
|
2066
2179
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
2067
|
-
const originalEntry =
|
|
2180
|
+
const originalEntry = path11.relative(config.root, chunk.facadeModuleId);
|
|
2068
2181
|
processedHtml = processedHtml.replace(
|
|
2069
2182
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
2070
2183
|
`$1${config.base}${chunk.fileName}$3`
|
|
2071
2184
|
);
|
|
2072
2185
|
}
|
|
2073
2186
|
}
|
|
2074
|
-
fs8.writeFileSync(
|
|
2187
|
+
fs8.writeFileSync(path11.resolve(outDir, "index.html"), processedHtml);
|
|
2075
2188
|
}
|
|
2076
2189
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2077
2190
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -2114,7 +2227,7 @@ __export(electron_exports, {
|
|
|
2114
2227
|
detectInstalledElectron: () => detectInstalledElectron,
|
|
2115
2228
|
normalizePreload: () => normalizePreload
|
|
2116
2229
|
});
|
|
2117
|
-
import
|
|
2230
|
+
import path12 from "path";
|
|
2118
2231
|
import fs9 from "fs";
|
|
2119
2232
|
import { rolldown as rolldown2 } from "rolldown";
|
|
2120
2233
|
import pc3 from "picocolors";
|
|
@@ -2122,16 +2235,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2122
2235
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2123
2236
|
const startTime = performance.now();
|
|
2124
2237
|
assertElectronVersion(config);
|
|
2125
|
-
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.
|
|
2238
|
+
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.5"}`));
|
|
2126
2239
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
2127
2240
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
2128
2241
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2129
|
-
const outDir =
|
|
2242
|
+
const outDir = path12.resolve(config.root, config.build.outDir);
|
|
2130
2243
|
if (config.build.emptyOutDir && fs9.existsSync(outDir)) {
|
|
2131
2244
|
fs9.rmSync(outDir, { recursive: true, force: true });
|
|
2132
2245
|
}
|
|
2133
2246
|
fs9.mkdirSync(outDir, { recursive: true });
|
|
2134
|
-
const rendererOutDir =
|
|
2247
|
+
const rendererOutDir = path12.join(outDir, "renderer");
|
|
2135
2248
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2136
2249
|
await build2({
|
|
2137
2250
|
...inlineConfig,
|
|
@@ -2142,7 +2255,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2142
2255
|
emptyOutDir: false
|
|
2143
2256
|
}
|
|
2144
2257
|
});
|
|
2145
|
-
const mainEntry =
|
|
2258
|
+
const mainEntry = path12.resolve(config.root, config.electron.main);
|
|
2146
2259
|
if (!fs9.existsSync(mainEntry)) {
|
|
2147
2260
|
throw new Error(
|
|
2148
2261
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2161,7 +2274,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2161
2274
|
console.warn(pc3.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2162
2275
|
continue;
|
|
2163
2276
|
}
|
|
2164
|
-
const base =
|
|
2277
|
+
const base = path12.basename(entry).replace(/\.[^.]+$/, "");
|
|
2165
2278
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2166
2279
|
await bundleNode(config, entry, {
|
|
2167
2280
|
outFile: out,
|
|
@@ -2173,10 +2286,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2173
2286
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2174
2287
|
console.log(pc3.green(`
|
|
2175
2288
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2176
|
-
console.log(pc3.dim(` renderer: ${
|
|
2177
|
-
console.log(pc3.dim(` main: ${
|
|
2289
|
+
console.log(pc3.dim(` renderer: ${path12.relative(config.root, rendererOutDir)}/`));
|
|
2290
|
+
console.log(pc3.dim(` main: ${path12.relative(config.root, mainFile)}`));
|
|
2178
2291
|
for (const pf of preloadFiles) {
|
|
2179
|
-
console.log(pc3.dim(` preload: ${
|
|
2292
|
+
console.log(pc3.dim(` preload: ${path12.relative(config.root, pf)}`));
|
|
2180
2293
|
}
|
|
2181
2294
|
console.log();
|
|
2182
2295
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2200,14 +2313,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2200
2313
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
2201
2314
|
}
|
|
2202
2315
|
};
|
|
2316
|
+
const existingTransform = config.build.rolldownOptions?.transform;
|
|
2317
|
+
const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
|
|
2203
2318
|
const bundle = await rolldown2({
|
|
2204
2319
|
input: entry,
|
|
2205
|
-
define:
|
|
2320
|
+
transform: { ...existingTransform, define: mergedDefine },
|
|
2206
2321
|
platform: "node",
|
|
2207
2322
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2208
2323
|
...config.build.rolldownOptions
|
|
2209
2324
|
});
|
|
2210
|
-
fs9.mkdirSync(
|
|
2325
|
+
fs9.mkdirSync(path12.dirname(opts.outFile), { recursive: true });
|
|
2211
2326
|
await bundle.write({
|
|
2212
2327
|
file: opts.outFile,
|
|
2213
2328
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2216,16 +2331,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2216
2331
|
codeSplitting: false
|
|
2217
2332
|
});
|
|
2218
2333
|
await bundle.close();
|
|
2219
|
-
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2334
|
+
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${path12.relative(config.root, opts.outFile)}`));
|
|
2220
2335
|
return opts.outFile;
|
|
2221
2336
|
}
|
|
2222
2337
|
function outFileName(outDir, base, format) {
|
|
2223
2338
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2224
|
-
return
|
|
2339
|
+
return path12.join(outDir, base + ext);
|
|
2225
2340
|
}
|
|
2226
2341
|
function normalizePreload(preload, root) {
|
|
2227
2342
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2228
|
-
return list.map((p) =>
|
|
2343
|
+
return list.map((p) => path12.resolve(root, p));
|
|
2229
2344
|
}
|
|
2230
2345
|
function assertElectronVersion(config) {
|
|
2231
2346
|
const min = config.electron.minVersion;
|
|
@@ -2240,7 +2355,7 @@ function assertElectronVersion(config) {
|
|
|
2240
2355
|
}
|
|
2241
2356
|
function detectInstalledElectron(root) {
|
|
2242
2357
|
try {
|
|
2243
|
-
const pkgPath =
|
|
2358
|
+
const pkgPath = path12.resolve(root, "node_modules/electron/package.json");
|
|
2244
2359
|
if (!fs9.existsSync(pkgPath)) return null;
|
|
2245
2360
|
const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf-8"));
|
|
2246
2361
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2265,9 +2380,9 @@ var electron_dev_exports = {};
|
|
|
2265
2380
|
__export(electron_dev_exports, {
|
|
2266
2381
|
startElectronDev: () => startElectronDev
|
|
2267
2382
|
});
|
|
2268
|
-
import
|
|
2383
|
+
import path13 from "path";
|
|
2269
2384
|
import fs10 from "fs";
|
|
2270
|
-
import { createRequire as
|
|
2385
|
+
import { createRequire as createRequire4 } from "module";
|
|
2271
2386
|
import { spawn } from "child_process";
|
|
2272
2387
|
import chokidar from "chokidar";
|
|
2273
2388
|
import pc4 from "picocolors";
|
|
@@ -2276,17 +2391,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2276
2391
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2277
2392
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2278
2393
|
warnElectronVersion(config);
|
|
2279
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.
|
|
2394
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.5"}`));
|
|
2280
2395
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2281
2396
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2282
2397
|
await server.listen();
|
|
2283
2398
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2284
2399
|
console.log(pc4.dim(` renderer: ${devUrl}`));
|
|
2285
|
-
const stageDir =
|
|
2400
|
+
const stageDir = path13.resolve(config.root, ".nasti");
|
|
2286
2401
|
fs10.mkdirSync(stageDir, { recursive: true });
|
|
2287
|
-
const mainEntry =
|
|
2402
|
+
const mainEntry = path13.resolve(config.root, config.electron.main);
|
|
2288
2403
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2289
|
-
const builtMainFile =
|
|
2404
|
+
const builtMainFile = path13.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2290
2405
|
const builtPreloadFiles = [];
|
|
2291
2406
|
const compileAll = async () => {
|
|
2292
2407
|
await compileNode(config, mainEntry, {
|
|
@@ -2297,8 +2412,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2297
2412
|
builtPreloadFiles.length = 0;
|
|
2298
2413
|
for (const entry of preloadEntries) {
|
|
2299
2414
|
if (!fs10.existsSync(entry)) continue;
|
|
2300
|
-
const base =
|
|
2301
|
-
const out =
|
|
2415
|
+
const base = path13.basename(entry).replace(/\.[^.]+$/, "");
|
|
2416
|
+
const out = path13.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2302
2417
|
await compileNode(config, entry, {
|
|
2303
2418
|
outFile: out,
|
|
2304
2419
|
format: config.electron.preloadFormat,
|
|
@@ -2413,7 +2528,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2413
2528
|
platform: "node",
|
|
2414
2529
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2415
2530
|
});
|
|
2416
|
-
fs10.mkdirSync(
|
|
2531
|
+
fs10.mkdirSync(path13.dirname(opts.outFile), { recursive: true });
|
|
2417
2532
|
await bundle.write({
|
|
2418
2533
|
file: opts.outFile,
|
|
2419
2534
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2430,7 +2545,7 @@ function resolveElectronBinary(config) {
|
|
|
2430
2545
|
return config.electron.electronPath;
|
|
2431
2546
|
}
|
|
2432
2547
|
try {
|
|
2433
|
-
const require2 =
|
|
2548
|
+
const require2 = createRequire4(path13.resolve(config.root, "package.json"));
|
|
2434
2549
|
const pathFile = require2.resolve("electron");
|
|
2435
2550
|
const electronModule = require2(pathFile);
|
|
2436
2551
|
if (typeof electronModule === "string" && fs10.existsSync(electronModule)) {
|
|
@@ -2578,11 +2693,11 @@ cli.command("electron-build [root]", "Build Electron app for production").option
|
|
|
2578
2693
|
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) => {
|
|
2579
2694
|
try {
|
|
2580
2695
|
const http2 = await import("http");
|
|
2581
|
-
const
|
|
2696
|
+
const path14 = await import("path");
|
|
2582
2697
|
const sirv2 = (await import("sirv")).default;
|
|
2583
2698
|
const connect2 = (await import("connect")).default;
|
|
2584
|
-
const resolvedRoot =
|
|
2585
|
-
const outDir =
|
|
2699
|
+
const resolvedRoot = path14.resolve(root ?? ".");
|
|
2700
|
+
const outDir = path14.resolve(resolvedRoot, options.outDir);
|
|
2586
2701
|
const app = connect2();
|
|
2587
2702
|
app.use(sirv2(outDir, { single: true, etag: true, gzip: true, brotli: true }));
|
|
2588
2703
|
const port = options.port;
|
|
@@ -2603,6 +2718,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2603
2718
|
}
|
|
2604
2719
|
});
|
|
2605
2720
|
cli.help();
|
|
2606
|
-
cli.version("1.6.
|
|
2721
|
+
cli.version("1.6.5");
|
|
2607
2722
|
cli.parse();
|
|
2608
2723
|
//# sourceMappingURL=cli.js.map
|