@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.cjs
CHANGED
|
@@ -56,7 +56,8 @@ var init_defaults = __esm({
|
|
|
56
56
|
sourcemap: false,
|
|
57
57
|
target: "es2022",
|
|
58
58
|
rolldownOptions: {},
|
|
59
|
-
emptyOutDir: true
|
|
59
|
+
emptyOutDir: true,
|
|
60
|
+
css: {}
|
|
60
61
|
};
|
|
61
62
|
defaultElectron = {
|
|
62
63
|
main: "src/electron/main.ts",
|
|
@@ -919,9 +920,9 @@ function transformMiddleware(ctx) {
|
|
|
919
920
|
async function transformRequest(url, ctx) {
|
|
920
921
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
921
922
|
const cleanReqUrl = url.split("?")[0];
|
|
922
|
-
const
|
|
923
|
-
if (
|
|
924
|
-
return
|
|
923
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
924
|
+
if (cached2?.transformResult) {
|
|
925
|
+
return cached2.transformResult;
|
|
925
926
|
}
|
|
926
927
|
if (cleanReqUrl === "/@react-refresh") {
|
|
927
928
|
return { code: getReactRefreshRuntimeEsm() };
|
|
@@ -1160,19 +1161,20 @@ function rewriteExternalRequires(code) {
|
|
|
1160
1161
|
}
|
|
1161
1162
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1162
1163
|
try {
|
|
1163
|
-
const { createRequire:
|
|
1164
|
-
const req =
|
|
1164
|
+
const { createRequire: createRequire5 } = await import("module");
|
|
1165
|
+
const req = createRequire5(entryFile);
|
|
1165
1166
|
const cjsExports = req(entryFile);
|
|
1166
1167
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1167
1168
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1168
1169
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1169
1170
|
);
|
|
1170
|
-
|
|
1171
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1172
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1171
1173
|
return code.replace(
|
|
1172
1174
|
/^export default (\w+\(\));?\s*$/m,
|
|
1173
1175
|
(_, call) => [
|
|
1174
1176
|
`const __cjsMod = ${call};`,
|
|
1175
|
-
`export default __cjsMod;`,
|
|
1177
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1176
1178
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1177
1179
|
].join("\n")
|
|
1178
1180
|
);
|
|
@@ -1584,20 +1586,29 @@ var init_hmr = __esm({
|
|
|
1584
1586
|
function resolvePlugin(config) {
|
|
1585
1587
|
const { alias, extensions } = config.resolve;
|
|
1586
1588
|
const require2 = (0, import_node_module2.createRequire)(import_node_path6.default.resolve(config.root, "package.json"));
|
|
1589
|
+
const aliasEntries = Object.entries(alias).sort(
|
|
1590
|
+
([a], [b]) => b.length - a.length
|
|
1591
|
+
);
|
|
1587
1592
|
return {
|
|
1588
1593
|
name: "nasti:resolve",
|
|
1589
1594
|
enforce: "pre",
|
|
1590
1595
|
resolveId(source, importer) {
|
|
1591
|
-
for (const [key, value] of
|
|
1596
|
+
for (const [key, value] of aliasEntries) {
|
|
1592
1597
|
if (source === key || source.startsWith(key + "/")) {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1598
|
+
const aliasBase = resolveAliasTarget2(value, config.root);
|
|
1599
|
+
const sub = source.slice(key.length).replace(/^\//, "");
|
|
1600
|
+
const target = sub ? import_node_path6.default.join(aliasBase, sub) : aliasBase;
|
|
1601
|
+
const resolved = tryResolveFile(target, extensions);
|
|
1602
|
+
if (resolved) return resolved;
|
|
1597
1603
|
break;
|
|
1598
1604
|
}
|
|
1599
1605
|
}
|
|
1600
|
-
if (
|
|
1606
|
+
if (source.startsWith("/") && !source.startsWith("//")) {
|
|
1607
|
+
const rootRelative = import_node_path6.default.join(config.root, source.slice(1));
|
|
1608
|
+
const resolved = tryResolveFile(rootRelative, extensions);
|
|
1609
|
+
if (resolved) return resolved;
|
|
1610
|
+
}
|
|
1611
|
+
if (import_node_path6.default.isAbsolute(source) && import_node_fs6.default.existsSync(source)) {
|
|
1601
1612
|
const resolved = tryResolveFile(source, extensions);
|
|
1602
1613
|
if (resolved) return resolved;
|
|
1603
1614
|
}
|
|
@@ -1620,6 +1631,7 @@ function resolvePlugin(config) {
|
|
|
1620
1631
|
return null;
|
|
1621
1632
|
},
|
|
1622
1633
|
load(id) {
|
|
1634
|
+
if (id.startsWith("\0")) return null;
|
|
1623
1635
|
if (!import_node_fs6.default.existsSync(id)) return null;
|
|
1624
1636
|
if (id.endsWith(".json")) {
|
|
1625
1637
|
const content = import_node_fs6.default.readFileSync(id, "utf-8");
|
|
@@ -1629,6 +1641,11 @@ function resolvePlugin(config) {
|
|
|
1629
1641
|
}
|
|
1630
1642
|
};
|
|
1631
1643
|
}
|
|
1644
|
+
function resolveAliasTarget2(value, root) {
|
|
1645
|
+
if (import_node_path6.default.isAbsolute(value) && import_node_fs6.default.existsSync(value)) return value;
|
|
1646
|
+
if (value.startsWith("/")) return import_node_path6.default.join(root, value.slice(1));
|
|
1647
|
+
return import_node_path6.default.resolve(root, value);
|
|
1648
|
+
}
|
|
1632
1649
|
function tryResolveFile(file, extensions) {
|
|
1633
1650
|
if (import_node_fs6.default.existsSync(file) && import_node_fs6.default.statSync(file).isFile()) {
|
|
1634
1651
|
return file;
|
|
@@ -1659,6 +1676,59 @@ var init_resolve = __esm({
|
|
|
1659
1676
|
}
|
|
1660
1677
|
});
|
|
1661
1678
|
|
|
1679
|
+
// src/plugins/tailwind.ts
|
|
1680
|
+
function hasTailwindDirectives(css) {
|
|
1681
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1682
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
1683
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
1684
|
+
}
|
|
1685
|
+
async function loadTailwind(projectRoot) {
|
|
1686
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
1687
|
+
const req = (0, import_node_module3.createRequire)(import_node_path7.default.join(projectRoot, "package.json"));
|
|
1688
|
+
let nodePath;
|
|
1689
|
+
let oxidePath;
|
|
1690
|
+
try {
|
|
1691
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
1692
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
1693
|
+
} catch {
|
|
1694
|
+
throw new Error(
|
|
1695
|
+
"[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"
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
const node = await import((0, import_node_url3.pathToFileURL)(nodePath).href);
|
|
1699
|
+
const oxide = await import((0, import_node_url3.pathToFileURL)(oxidePath).href);
|
|
1700
|
+
cached = { node, oxide };
|
|
1701
|
+
cachedRoot = projectRoot;
|
|
1702
|
+
return cached;
|
|
1703
|
+
}
|
|
1704
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
1705
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
1706
|
+
const dependencies = [];
|
|
1707
|
+
const compiler = await node.compile(css, {
|
|
1708
|
+
base: import_node_path7.default.dirname(fromFile),
|
|
1709
|
+
from: fromFile,
|
|
1710
|
+
onDependency: (p) => dependencies.push(p)
|
|
1711
|
+
});
|
|
1712
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
1713
|
+
const candidates = scanner.scan();
|
|
1714
|
+
return {
|
|
1715
|
+
css: compiler.build(candidates),
|
|
1716
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
var import_node_path7, import_node_module3, import_node_url3, TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
1720
|
+
var init_tailwind = __esm({
|
|
1721
|
+
"src/plugins/tailwind.ts"() {
|
|
1722
|
+
"use strict";
|
|
1723
|
+
import_node_path7 = __toESM(require("path"), 1);
|
|
1724
|
+
import_node_module3 = require("module");
|
|
1725
|
+
import_node_url3 = require("url");
|
|
1726
|
+
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)/;
|
|
1727
|
+
cached = null;
|
|
1728
|
+
cachedRoot = null;
|
|
1729
|
+
}
|
|
1730
|
+
});
|
|
1731
|
+
|
|
1662
1732
|
// src/plugins/css.ts
|
|
1663
1733
|
function cssPlugin(config) {
|
|
1664
1734
|
return {
|
|
@@ -1667,11 +1737,16 @@ function cssPlugin(config) {
|
|
|
1667
1737
|
if (source.endsWith(".css")) return null;
|
|
1668
1738
|
return null;
|
|
1669
1739
|
},
|
|
1670
|
-
transform(code, id) {
|
|
1740
|
+
async transform(code, id) {
|
|
1671
1741
|
if (!id.endsWith(".css")) return null;
|
|
1672
|
-
|
|
1742
|
+
let cssSource = code;
|
|
1743
|
+
if (hasTailwindDirectives(code)) {
|
|
1744
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
1745
|
+
cssSource = compiled.css;
|
|
1746
|
+
}
|
|
1747
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
1748
|
+
const escaped = JSON.stringify(rewritten);
|
|
1673
1749
|
if (config.command === "serve") {
|
|
1674
|
-
const escaped = JSON.stringify(rewritten);
|
|
1675
1750
|
return {
|
|
1676
1751
|
code: `
|
|
1677
1752
|
const css = ${escaped};
|
|
@@ -1695,7 +1770,42 @@ export default css;
|
|
|
1695
1770
|
`
|
|
1696
1771
|
};
|
|
1697
1772
|
}
|
|
1698
|
-
|
|
1773
|
+
const cssConfig = config.build.css || {};
|
|
1774
|
+
const nonce = cssConfig.nonce;
|
|
1775
|
+
const emitCssFile = cssConfig.emitCssFile;
|
|
1776
|
+
if (emitCssFile) {
|
|
1777
|
+
const fileName = `assets/${import_node_path8.default.basename(id, ".css")}.css`;
|
|
1778
|
+
this.emitFile({
|
|
1779
|
+
type: "asset",
|
|
1780
|
+
fileName,
|
|
1781
|
+
source: rewritten
|
|
1782
|
+
});
|
|
1783
|
+
return {
|
|
1784
|
+
code: `
|
|
1785
|
+
const link = document.createElement('link');
|
|
1786
|
+
link.rel = 'stylesheet';
|
|
1787
|
+
link.href = ${JSON.stringify("/" + fileName)};
|
|
1788
|
+
document.head.appendChild(link);
|
|
1789
|
+
|
|
1790
|
+
export default ${escaped};
|
|
1791
|
+
`,
|
|
1792
|
+
moduleType: "js"
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
const nonceAttr = nonce ? `style.setAttribute('nonce', ${JSON.stringify(nonce)});` : "";
|
|
1796
|
+
return {
|
|
1797
|
+
code: `
|
|
1798
|
+
const css = ${escaped};
|
|
1799
|
+
const style = document.createElement('style');
|
|
1800
|
+
style.setAttribute('data-nasti-css', ${JSON.stringify(id)});
|
|
1801
|
+
${nonceAttr}
|
|
1802
|
+
style.textContent = css;
|
|
1803
|
+
document.head.appendChild(style);
|
|
1804
|
+
|
|
1805
|
+
export default css;
|
|
1806
|
+
`,
|
|
1807
|
+
moduleType: "js"
|
|
1808
|
+
};
|
|
1699
1809
|
}
|
|
1700
1810
|
};
|
|
1701
1811
|
}
|
|
@@ -1704,16 +1814,17 @@ function rewriteCssUrls(css, from, root) {
|
|
|
1704
1814
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
1705
1815
|
return match;
|
|
1706
1816
|
}
|
|
1707
|
-
const resolved =
|
|
1708
|
-
const relative = "/" +
|
|
1817
|
+
const resolved = import_node_path8.default.resolve(import_node_path8.default.dirname(from), url);
|
|
1818
|
+
const relative = "/" + import_node_path8.default.relative(root, resolved);
|
|
1709
1819
|
return `url(${relative})`;
|
|
1710
1820
|
});
|
|
1711
1821
|
}
|
|
1712
|
-
var
|
|
1822
|
+
var import_node_path8;
|
|
1713
1823
|
var init_css = __esm({
|
|
1714
1824
|
"src/plugins/css.ts"() {
|
|
1715
1825
|
"use strict";
|
|
1716
|
-
|
|
1826
|
+
import_node_path8 = __toESM(require("path"), 1);
|
|
1827
|
+
init_tailwind();
|
|
1717
1828
|
}
|
|
1718
1829
|
});
|
|
1719
1830
|
|
|
@@ -1728,7 +1839,7 @@ function assetsPlugin(config) {
|
|
|
1728
1839
|
return null;
|
|
1729
1840
|
},
|
|
1730
1841
|
load(id) {
|
|
1731
|
-
const ext =
|
|
1842
|
+
const ext = import_node_path9.default.extname(id.replace(/\?.*$/, ""));
|
|
1732
1843
|
if (id.endsWith("?raw")) {
|
|
1733
1844
|
const file = id.slice(0, -4);
|
|
1734
1845
|
if (import_node_fs7.default.existsSync(file)) {
|
|
@@ -1740,12 +1851,12 @@ function assetsPlugin(config) {
|
|
|
1740
1851
|
const file = id.replace(/\?.*$/, "");
|
|
1741
1852
|
if (!import_node_fs7.default.existsSync(file)) return null;
|
|
1742
1853
|
if (config.command === "serve") {
|
|
1743
|
-
const url = "/" +
|
|
1854
|
+
const url = "/" + import_node_path9.default.relative(config.root, file);
|
|
1744
1855
|
return `export default ${JSON.stringify(url)}`;
|
|
1745
1856
|
}
|
|
1746
1857
|
const content = import_node_fs7.default.readFileSync(file);
|
|
1747
1858
|
const hash = import_node_crypto.default.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
1748
|
-
const basename =
|
|
1859
|
+
const basename = import_node_path9.default.basename(file, ext);
|
|
1749
1860
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
1750
1861
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
1751
1862
|
}
|
|
@@ -1753,11 +1864,11 @@ function assetsPlugin(config) {
|
|
|
1753
1864
|
}
|
|
1754
1865
|
};
|
|
1755
1866
|
}
|
|
1756
|
-
var
|
|
1867
|
+
var import_node_path9, import_node_fs7, import_node_crypto, ASSET_EXTENSIONS;
|
|
1757
1868
|
var init_assets = __esm({
|
|
1758
1869
|
"src/plugins/assets.ts"() {
|
|
1759
1870
|
"use strict";
|
|
1760
|
-
|
|
1871
|
+
import_node_path9 = __toESM(require("path"), 1);
|
|
1761
1872
|
import_node_fs7 = __toESM(require("fs"), 1);
|
|
1762
1873
|
import_node_crypto = __toESM(require("crypto"), 1);
|
|
1763
1874
|
ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -1810,20 +1921,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1810
1921
|
pluginContainer,
|
|
1811
1922
|
moduleGraph
|
|
1812
1923
|
}));
|
|
1813
|
-
const publicDir =
|
|
1924
|
+
const publicDir = import_node_path10.default.resolve(config.root, "public");
|
|
1814
1925
|
app.use((0, import_sirv.default)(publicDir, { dev: true, etag: true }));
|
|
1815
1926
|
app.use((0, import_sirv.default)(config.root, { dev: true, etag: true }));
|
|
1816
1927
|
const httpServer = import_node_http.default.createServer(app);
|
|
1817
1928
|
const ws = createWebSocketServer(httpServer);
|
|
1818
1929
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1819
|
-
const outDirAbs =
|
|
1930
|
+
const outDirAbs = import_node_path10.default.resolve(config.root, config.build.outDir);
|
|
1820
1931
|
const watcher = (0, import_chokidar.watch)(config.root, {
|
|
1821
1932
|
ignored: (filePath) => {
|
|
1822
1933
|
if (filePath === config.root) return false;
|
|
1823
|
-
if (filePath === outDirAbs || filePath.startsWith(outDirAbs +
|
|
1824
|
-
const rel =
|
|
1825
|
-
if (!rel || rel.startsWith("..") ||
|
|
1826
|
-
for (const seg of rel.split(
|
|
1934
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + import_node_path10.default.sep)) return true;
|
|
1935
|
+
const rel = import_node_path10.default.relative(config.root, filePath);
|
|
1936
|
+
if (!rel || rel.startsWith("..") || import_node_path10.default.isAbsolute(rel)) return false;
|
|
1937
|
+
for (const seg of rel.split(import_node_path10.default.sep)) {
|
|
1827
1938
|
if (ignoredSegments.has(seg)) return true;
|
|
1828
1939
|
}
|
|
1829
1940
|
return false;
|
|
@@ -1855,7 +1966,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1855
1966
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1856
1967
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1857
1968
|
console.log();
|
|
1858
|
-
console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.
|
|
1969
|
+
console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.5"}`));
|
|
1859
1970
|
console.log();
|
|
1860
1971
|
console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
|
|
1861
1972
|
if (networkUrl) {
|
|
@@ -1911,12 +2022,12 @@ function getNetworkAddress() {
|
|
|
1911
2022
|
}
|
|
1912
2023
|
return "localhost";
|
|
1913
2024
|
}
|
|
1914
|
-
var import_node_http,
|
|
2025
|
+
var import_node_http, import_node_path10, import_node_os, import_connect, import_sirv, import_chokidar, import_picocolors;
|
|
1915
2026
|
var init_server = __esm({
|
|
1916
2027
|
"src/server/index.ts"() {
|
|
1917
2028
|
"use strict";
|
|
1918
2029
|
import_node_http = __toESM(require("http"), 1);
|
|
1919
|
-
|
|
2030
|
+
import_node_path10 = __toESM(require("path"), 1);
|
|
1920
2031
|
import_node_os = __toESM(require("os"), 1);
|
|
1921
2032
|
import_connect = __toESM(require("connect"), 1);
|
|
1922
2033
|
import_sirv = __toESM(require("sirv"), 1);
|
|
@@ -1956,14 +2067,14 @@ function electronPlugin(config) {
|
|
|
1956
2067
|
}
|
|
1957
2068
|
};
|
|
1958
2069
|
}
|
|
1959
|
-
var
|
|
2070
|
+
var import_node_module4, NODE_BUILTINS, ELECTRON_MODULES;
|
|
1960
2071
|
var init_electron = __esm({
|
|
1961
2072
|
"src/plugins/electron.ts"() {
|
|
1962
2073
|
"use strict";
|
|
1963
|
-
|
|
2074
|
+
import_node_module4 = require("module");
|
|
1964
2075
|
NODE_BUILTINS = /* @__PURE__ */ new Set([
|
|
1965
|
-
...
|
|
1966
|
-
...
|
|
2076
|
+
...import_node_module4.builtinModules,
|
|
2077
|
+
...import_node_module4.builtinModules.map((m) => `node:${m}`)
|
|
1967
2078
|
]);
|
|
1968
2079
|
ELECTRON_MODULES = /* @__PURE__ */ new Set([
|
|
1969
2080
|
"electron",
|
|
@@ -1982,10 +2093,10 @@ __export(build_exports, {
|
|
|
1982
2093
|
async function build(inlineConfig = {}) {
|
|
1983
2094
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1984
2095
|
const startTime = performance.now();
|
|
1985
|
-
console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.
|
|
2096
|
+
console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.5"}`));
|
|
1986
2097
|
console.log(import_picocolors2.default.dim(` root: ${config.root}`));
|
|
1987
2098
|
console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
|
|
1988
|
-
const outDir =
|
|
2099
|
+
const outDir = import_node_path11.default.resolve(config.root, config.build.outDir);
|
|
1989
2100
|
if (config.build.emptyOutDir && import_node_fs8.default.existsSync(outDir)) {
|
|
1990
2101
|
import_node_fs8.default.rmSync(outDir, { recursive: true, force: true });
|
|
1991
2102
|
}
|
|
@@ -1997,14 +2108,14 @@ async function build(inlineConfig = {}) {
|
|
|
1997
2108
|
for (const match of scriptMatches) {
|
|
1998
2109
|
const src = match[1];
|
|
1999
2110
|
if (src && !src.startsWith("http")) {
|
|
2000
|
-
entryPoints.push(
|
|
2111
|
+
entryPoints.push(import_node_path11.default.resolve(config.root, src.replace(/^\//, "")));
|
|
2001
2112
|
}
|
|
2002
2113
|
}
|
|
2003
2114
|
}
|
|
2004
2115
|
if (entryPoints.length === 0) {
|
|
2005
2116
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
2006
2117
|
for (const entry of fallbackEntries) {
|
|
2007
|
-
const fullPath =
|
|
2118
|
+
const fullPath = import_node_path11.default.resolve(config.root, entry);
|
|
2008
2119
|
if (import_node_fs8.default.existsSync(fullPath)) {
|
|
2009
2120
|
entryPoints.push(fullPath);
|
|
2010
2121
|
break;
|
|
@@ -2036,9 +2147,11 @@ async function build(inlineConfig = {}) {
|
|
|
2036
2147
|
};
|
|
2037
2148
|
const env = loadEnv(config.mode, config.root, config.envPrefix);
|
|
2038
2149
|
const envDefine = buildEnvDefine(env, config.mode);
|
|
2150
|
+
const existingTransform = config.build.rolldownOptions?.transform;
|
|
2151
|
+
const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
|
|
2039
2152
|
const bundle = await (0, import_rolldown.rolldown)({
|
|
2040
2153
|
input: entryPoints,
|
|
2041
|
-
define:
|
|
2154
|
+
transform: { ...existingTransform, define: mergedDefine },
|
|
2042
2155
|
plugins: [
|
|
2043
2156
|
oxcTransformPlugin,
|
|
2044
2157
|
// 转换 Nasti 插件为 Rolldown 插件格式
|
|
@@ -2069,8 +2182,8 @@ async function build(inlineConfig = {}) {
|
|
|
2069
2182
|
await bundle.close();
|
|
2070
2183
|
await pluginContainer.buildEnd();
|
|
2071
2184
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
2072
|
-
const dest =
|
|
2073
|
-
import_node_fs8.default.mkdirSync(
|
|
2185
|
+
const dest = import_node_path11.default.resolve(outDir, ef.fileName);
|
|
2186
|
+
import_node_fs8.default.mkdirSync(import_node_path11.default.dirname(dest), { recursive: true });
|
|
2074
2187
|
import_node_fs8.default.writeFileSync(dest, ef.source);
|
|
2075
2188
|
}
|
|
2076
2189
|
if (html) {
|
|
@@ -2088,14 +2201,14 @@ async function build(inlineConfig = {}) {
|
|
|
2088
2201
|
}
|
|
2089
2202
|
for (const chunk of output) {
|
|
2090
2203
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
2091
|
-
const originalEntry =
|
|
2204
|
+
const originalEntry = import_node_path11.default.relative(config.root, chunk.facadeModuleId);
|
|
2092
2205
|
processedHtml = processedHtml.replace(
|
|
2093
2206
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
2094
2207
|
`$1${config.base}${chunk.fileName}$3`
|
|
2095
2208
|
);
|
|
2096
2209
|
}
|
|
2097
2210
|
}
|
|
2098
|
-
import_node_fs8.default.writeFileSync(
|
|
2211
|
+
import_node_fs8.default.writeFileSync(import_node_path11.default.resolve(outDir, "index.html"), processedHtml);
|
|
2099
2212
|
}
|
|
2100
2213
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2101
2214
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -2117,11 +2230,11 @@ function formatSize(bytes) {
|
|
|
2117
2230
|
function escapeRegExp(string) {
|
|
2118
2231
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2119
2232
|
}
|
|
2120
|
-
var
|
|
2233
|
+
var import_node_path11, import_node_fs8, import_rolldown, import_picocolors2;
|
|
2121
2234
|
var init_build = __esm({
|
|
2122
2235
|
"src/build/index.ts"() {
|
|
2123
2236
|
"use strict";
|
|
2124
|
-
|
|
2237
|
+
import_node_path11 = __toESM(require("path"), 1);
|
|
2125
2238
|
import_node_fs8 = __toESM(require("fs"), 1);
|
|
2126
2239
|
import_rolldown = require("rolldown");
|
|
2127
2240
|
init_config();
|
|
@@ -2147,16 +2260,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2147
2260
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2148
2261
|
const startTime = performance.now();
|
|
2149
2262
|
assertElectronVersion(config);
|
|
2150
|
-
console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.
|
|
2263
|
+
console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.5"}`));
|
|
2151
2264
|
console.log(import_picocolors3.default.dim(` root: ${config.root}`));
|
|
2152
2265
|
console.log(import_picocolors3.default.dim(` mode: ${config.mode}`));
|
|
2153
2266
|
console.log(import_picocolors3.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2154
|
-
const outDir =
|
|
2267
|
+
const outDir = import_node_path12.default.resolve(config.root, config.build.outDir);
|
|
2155
2268
|
if (config.build.emptyOutDir && import_node_fs9.default.existsSync(outDir)) {
|
|
2156
2269
|
import_node_fs9.default.rmSync(outDir, { recursive: true, force: true });
|
|
2157
2270
|
}
|
|
2158
2271
|
import_node_fs9.default.mkdirSync(outDir, { recursive: true });
|
|
2159
|
-
const rendererOutDir =
|
|
2272
|
+
const rendererOutDir = import_node_path12.default.join(outDir, "renderer");
|
|
2160
2273
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2161
2274
|
await build2({
|
|
2162
2275
|
...inlineConfig,
|
|
@@ -2167,7 +2280,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2167
2280
|
emptyOutDir: false
|
|
2168
2281
|
}
|
|
2169
2282
|
});
|
|
2170
|
-
const mainEntry =
|
|
2283
|
+
const mainEntry = import_node_path12.default.resolve(config.root, config.electron.main);
|
|
2171
2284
|
if (!import_node_fs9.default.existsSync(mainEntry)) {
|
|
2172
2285
|
throw new Error(
|
|
2173
2286
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2186,7 +2299,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2186
2299
|
console.warn(import_picocolors3.default.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2187
2300
|
continue;
|
|
2188
2301
|
}
|
|
2189
|
-
const base =
|
|
2302
|
+
const base = import_node_path12.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
2190
2303
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2191
2304
|
await bundleNode(config, entry, {
|
|
2192
2305
|
outFile: out,
|
|
@@ -2198,10 +2311,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2198
2311
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2199
2312
|
console.log(import_picocolors3.default.green(`
|
|
2200
2313
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2201
|
-
console.log(import_picocolors3.default.dim(` renderer: ${
|
|
2202
|
-
console.log(import_picocolors3.default.dim(` main: ${
|
|
2314
|
+
console.log(import_picocolors3.default.dim(` renderer: ${import_node_path12.default.relative(config.root, rendererOutDir)}/`));
|
|
2315
|
+
console.log(import_picocolors3.default.dim(` main: ${import_node_path12.default.relative(config.root, mainFile)}`));
|
|
2203
2316
|
for (const pf of preloadFiles) {
|
|
2204
|
-
console.log(import_picocolors3.default.dim(` preload: ${
|
|
2317
|
+
console.log(import_picocolors3.default.dim(` preload: ${import_node_path12.default.relative(config.root, pf)}`));
|
|
2205
2318
|
}
|
|
2206
2319
|
console.log();
|
|
2207
2320
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2225,14 +2338,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2225
2338
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
2226
2339
|
}
|
|
2227
2340
|
};
|
|
2341
|
+
const existingTransform = config.build.rolldownOptions?.transform;
|
|
2342
|
+
const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
|
|
2228
2343
|
const bundle = await (0, import_rolldown2.rolldown)({
|
|
2229
2344
|
input: entry,
|
|
2230
|
-
define:
|
|
2345
|
+
transform: { ...existingTransform, define: mergedDefine },
|
|
2231
2346
|
platform: "node",
|
|
2232
2347
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2233
2348
|
...config.build.rolldownOptions
|
|
2234
2349
|
});
|
|
2235
|
-
import_node_fs9.default.mkdirSync(
|
|
2350
|
+
import_node_fs9.default.mkdirSync(import_node_path12.default.dirname(opts.outFile), { recursive: true });
|
|
2236
2351
|
await bundle.write({
|
|
2237
2352
|
file: opts.outFile,
|
|
2238
2353
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2241,16 +2356,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2241
2356
|
codeSplitting: false
|
|
2242
2357
|
});
|
|
2243
2358
|
await bundle.close();
|
|
2244
|
-
console.log(import_picocolors3.default.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2359
|
+
console.log(import_picocolors3.default.dim(` \u2713 ${opts.label} \u2192 ${import_node_path12.default.relative(config.root, opts.outFile)}`));
|
|
2245
2360
|
return opts.outFile;
|
|
2246
2361
|
}
|
|
2247
2362
|
function outFileName(outDir, base, format) {
|
|
2248
2363
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2249
|
-
return
|
|
2364
|
+
return import_node_path12.default.join(outDir, base + ext);
|
|
2250
2365
|
}
|
|
2251
2366
|
function normalizePreload(preload, root) {
|
|
2252
2367
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2253
|
-
return list.map((p) =>
|
|
2368
|
+
return list.map((p) => import_node_path12.default.resolve(root, p));
|
|
2254
2369
|
}
|
|
2255
2370
|
function assertElectronVersion(config) {
|
|
2256
2371
|
const min = config.electron.minVersion;
|
|
@@ -2265,7 +2380,7 @@ function assertElectronVersion(config) {
|
|
|
2265
2380
|
}
|
|
2266
2381
|
function detectInstalledElectron(root) {
|
|
2267
2382
|
try {
|
|
2268
|
-
const pkgPath =
|
|
2383
|
+
const pkgPath = import_node_path12.default.resolve(root, "node_modules/electron/package.json");
|
|
2269
2384
|
if (!import_node_fs9.default.existsSync(pkgPath)) return null;
|
|
2270
2385
|
const pkg = JSON.parse(import_node_fs9.default.readFileSync(pkgPath, "utf-8"));
|
|
2271
2386
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2274,11 +2389,11 @@ function detectInstalledElectron(root) {
|
|
|
2274
2389
|
return null;
|
|
2275
2390
|
}
|
|
2276
2391
|
}
|
|
2277
|
-
var
|
|
2392
|
+
var import_node_path12, import_node_fs9, import_rolldown2, import_picocolors3;
|
|
2278
2393
|
var init_electron2 = __esm({
|
|
2279
2394
|
"src/build/electron.ts"() {
|
|
2280
2395
|
"use strict";
|
|
2281
|
-
|
|
2396
|
+
import_node_path12 = __toESM(require("path"), 1);
|
|
2282
2397
|
import_node_fs9 = __toESM(require("fs"), 1);
|
|
2283
2398
|
import_rolldown2 = require("rolldown");
|
|
2284
2399
|
import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
@@ -2299,17 +2414,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2299
2414
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2300
2415
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2301
2416
|
warnElectronVersion(config);
|
|
2302
|
-
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.
|
|
2417
|
+
console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.5"}`));
|
|
2303
2418
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2304
2419
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2305
2420
|
await server.listen();
|
|
2306
2421
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2307
2422
|
console.log(import_picocolors4.default.dim(` renderer: ${devUrl}`));
|
|
2308
|
-
const stageDir =
|
|
2423
|
+
const stageDir = import_node_path13.default.resolve(config.root, ".nasti");
|
|
2309
2424
|
import_node_fs10.default.mkdirSync(stageDir, { recursive: true });
|
|
2310
|
-
const mainEntry =
|
|
2425
|
+
const mainEntry = import_node_path13.default.resolve(config.root, config.electron.main);
|
|
2311
2426
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2312
|
-
const builtMainFile =
|
|
2427
|
+
const builtMainFile = import_node_path13.default.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2313
2428
|
const builtPreloadFiles = [];
|
|
2314
2429
|
const compileAll = async () => {
|
|
2315
2430
|
await compileNode(config, mainEntry, {
|
|
@@ -2320,8 +2435,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2320
2435
|
builtPreloadFiles.length = 0;
|
|
2321
2436
|
for (const entry of preloadEntries) {
|
|
2322
2437
|
if (!import_node_fs10.default.existsSync(entry)) continue;
|
|
2323
|
-
const base =
|
|
2324
|
-
const out =
|
|
2438
|
+
const base = import_node_path13.default.basename(entry).replace(/\.[^.]+$/, "");
|
|
2439
|
+
const out = import_node_path13.default.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2325
2440
|
await compileNode(config, entry, {
|
|
2326
2441
|
outFile: out,
|
|
2327
2442
|
format: config.electron.preloadFormat,
|
|
@@ -2436,7 +2551,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2436
2551
|
platform: "node",
|
|
2437
2552
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2438
2553
|
});
|
|
2439
|
-
import_node_fs10.default.mkdirSync(
|
|
2554
|
+
import_node_fs10.default.mkdirSync(import_node_path13.default.dirname(opts.outFile), { recursive: true });
|
|
2440
2555
|
await bundle.write({
|
|
2441
2556
|
file: opts.outFile,
|
|
2442
2557
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2453,7 +2568,7 @@ function resolveElectronBinary(config) {
|
|
|
2453
2568
|
return config.electron.electronPath;
|
|
2454
2569
|
}
|
|
2455
2570
|
try {
|
|
2456
|
-
const require2 = (0,
|
|
2571
|
+
const require2 = (0, import_node_module5.createRequire)(import_node_path13.default.resolve(config.root, "package.json"));
|
|
2457
2572
|
const pathFile = require2.resolve("electron");
|
|
2458
2573
|
const electronModule = require2(pathFile);
|
|
2459
2574
|
if (typeof electronModule === "string" && import_node_fs10.default.existsSync(electronModule)) {
|
|
@@ -2481,13 +2596,13 @@ function warnElectronVersion(config) {
|
|
|
2481
2596
|
);
|
|
2482
2597
|
}
|
|
2483
2598
|
}
|
|
2484
|
-
var
|
|
2599
|
+
var import_node_path13, import_node_fs10, import_node_module5, import_node_child_process, import_chokidar2, import_picocolors4, import_rolldown3;
|
|
2485
2600
|
var init_electron_dev = __esm({
|
|
2486
2601
|
"src/server/electron-dev.ts"() {
|
|
2487
2602
|
"use strict";
|
|
2488
|
-
|
|
2603
|
+
import_node_path13 = __toESM(require("path"), 1);
|
|
2489
2604
|
import_node_fs10 = __toESM(require("fs"), 1);
|
|
2490
|
-
|
|
2605
|
+
import_node_module5 = require("module");
|
|
2491
2606
|
import_node_child_process = require("child_process");
|
|
2492
2607
|
import_chokidar2 = __toESM(require("chokidar"), 1);
|
|
2493
2608
|
import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
@@ -2609,11 +2724,11 @@ cli.command("electron-build [root]", "Build Electron app for production").option
|
|
|
2609
2724
|
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) => {
|
|
2610
2725
|
try {
|
|
2611
2726
|
const http2 = await import("http");
|
|
2612
|
-
const
|
|
2727
|
+
const path14 = await import("path");
|
|
2613
2728
|
const sirv2 = (await import("sirv")).default;
|
|
2614
2729
|
const connect2 = (await import("connect")).default;
|
|
2615
|
-
const resolvedRoot =
|
|
2616
|
-
const outDir =
|
|
2730
|
+
const resolvedRoot = path14.resolve(root ?? ".");
|
|
2731
|
+
const outDir = path14.resolve(resolvedRoot, options.outDir);
|
|
2617
2732
|
const app = connect2();
|
|
2618
2733
|
app.use(sirv2(outDir, { single: true, etag: true, gzip: true, brotli: true }));
|
|
2619
2734
|
const port = options.port;
|
|
@@ -2634,6 +2749,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2634
2749
|
}
|
|
2635
2750
|
});
|
|
2636
2751
|
cli.help();
|
|
2637
|
-
cli.version("1.6.
|
|
2752
|
+
cli.version("1.6.5");
|
|
2638
2753
|
cli.parse();
|
|
2639
2754
|
//# sourceMappingURL=cli.cjs.map
|