@nasti-toolchain/nasti 1.6.3 → 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 +131 -71
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +121 -61
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +186 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +175 -115
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/cli.js
CHANGED
|
@@ -900,9 +900,9 @@ function transformMiddleware(ctx) {
|
|
|
900
900
|
async function transformRequest(url, ctx) {
|
|
901
901
|
const { config, pluginContainer, moduleGraph } = ctx;
|
|
902
902
|
const cleanReqUrl = url.split("?")[0];
|
|
903
|
-
const
|
|
904
|
-
if (
|
|
905
|
-
return
|
|
903
|
+
const cached2 = moduleGraph.getModuleByUrl(url);
|
|
904
|
+
if (cached2?.transformResult) {
|
|
905
|
+
return cached2.transformResult;
|
|
906
906
|
}
|
|
907
907
|
if (cleanReqUrl === "/@react-refresh") {
|
|
908
908
|
return { code: getReactRefreshRuntimeEsm() };
|
|
@@ -1141,19 +1141,20 @@ function rewriteExternalRequires(code) {
|
|
|
1141
1141
|
}
|
|
1142
1142
|
async function injectCjsNamedExports(code, entryFile) {
|
|
1143
1143
|
try {
|
|
1144
|
-
const { createRequire:
|
|
1145
|
-
const req =
|
|
1144
|
+
const { createRequire: createRequire5 } = await import("module");
|
|
1145
|
+
const req = createRequire5(entryFile);
|
|
1146
1146
|
const cjsExports = req(entryFile);
|
|
1147
1147
|
if (!cjsExports || typeof cjsExports !== "object" && typeof cjsExports !== "function" || Array.isArray(cjsExports)) return code;
|
|
1148
1148
|
const namedKeys = Object.keys(cjsExports).filter(
|
|
1149
1149
|
(k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
|
|
1150
1150
|
);
|
|
1151
|
-
|
|
1151
|
+
const hasEsmInterop = cjsExports.__esModule === true && "default" in cjsExports;
|
|
1152
|
+
if (!hasEsmInterop && namedKeys.length === 0) return code;
|
|
1152
1153
|
return code.replace(
|
|
1153
1154
|
/^export default (\w+\(\));?\s*$/m,
|
|
1154
1155
|
(_, call) => [
|
|
1155
1156
|
`const __cjsMod = ${call};`,
|
|
1156
|
-
`export default __cjsMod;`,
|
|
1157
|
+
hasEsmInterop ? `export default __cjsMod.default;` : `export default __cjsMod;`,
|
|
1157
1158
|
...namedKeys.map((k) => `export const ${k} = __cjsMod[${JSON.stringify(k)}];`)
|
|
1158
1159
|
].join("\n")
|
|
1159
1160
|
);
|
|
@@ -1633,8 +1634,61 @@ var init_resolve = __esm({
|
|
|
1633
1634
|
}
|
|
1634
1635
|
});
|
|
1635
1636
|
|
|
1636
|
-
// src/plugins/
|
|
1637
|
+
// src/plugins/tailwind.ts
|
|
1637
1638
|
import path7 from "path";
|
|
1639
|
+
import { createRequire as createRequire3 } from "module";
|
|
1640
|
+
import { pathToFileURL as pathToFileURL3 } from "url";
|
|
1641
|
+
function hasTailwindDirectives(css) {
|
|
1642
|
+
const withoutBlockComments = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
1643
|
+
const withoutLineComments = withoutBlockComments.replace(/\/\/.*$/gm, "");
|
|
1644
|
+
return TAILWIND_DIRECTIVE_RE.test(withoutLineComments);
|
|
1645
|
+
}
|
|
1646
|
+
async function loadTailwind(projectRoot) {
|
|
1647
|
+
if (cached && cachedRoot === projectRoot) return cached;
|
|
1648
|
+
const req = createRequire3(path7.join(projectRoot, "package.json"));
|
|
1649
|
+
let nodePath;
|
|
1650
|
+
let oxidePath;
|
|
1651
|
+
try {
|
|
1652
|
+
nodePath = req.resolve("@tailwindcss/node");
|
|
1653
|
+
oxidePath = req.resolve("@tailwindcss/oxide");
|
|
1654
|
+
} catch {
|
|
1655
|
+
throw new Error(
|
|
1656
|
+
"[nasti] CSS contains Tailwind v4 directives but `@tailwindcss/node` and/or `@tailwindcss/oxide` are not installed in this project. Install them with: npm i -D tailwindcss @tailwindcss/node @tailwindcss/oxide"
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
const node = await import(pathToFileURL3(nodePath).href);
|
|
1660
|
+
const oxide = await import(pathToFileURL3(oxidePath).href);
|
|
1661
|
+
cached = { node, oxide };
|
|
1662
|
+
cachedRoot = projectRoot;
|
|
1663
|
+
return cached;
|
|
1664
|
+
}
|
|
1665
|
+
async function compileTailwind(css, fromFile, projectRoot) {
|
|
1666
|
+
const { node, oxide } = await loadTailwind(projectRoot);
|
|
1667
|
+
const dependencies = [];
|
|
1668
|
+
const compiler = await node.compile(css, {
|
|
1669
|
+
base: path7.dirname(fromFile),
|
|
1670
|
+
from: fromFile,
|
|
1671
|
+
onDependency: (p) => dependencies.push(p)
|
|
1672
|
+
});
|
|
1673
|
+
const scanner = new oxide.Scanner({ sources: compiler.sources });
|
|
1674
|
+
const candidates = scanner.scan();
|
|
1675
|
+
return {
|
|
1676
|
+
css: compiler.build(candidates),
|
|
1677
|
+
dependencies: [...dependencies, ...scanner.files]
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
var TAILWIND_DIRECTIVE_RE, cached, cachedRoot;
|
|
1681
|
+
var init_tailwind = __esm({
|
|
1682
|
+
"src/plugins/tailwind.ts"() {
|
|
1683
|
+
"use strict";
|
|
1684
|
+
TAILWIND_DIRECTIVE_RE = /@(?:import\s+["']tailwindcss(?:\b|\/)|tailwind\b|theme\b|apply\b|plugin\b|source\b|utility\b|variant\b|custom-variant\b|reference\b)/;
|
|
1685
|
+
cached = null;
|
|
1686
|
+
cachedRoot = null;
|
|
1687
|
+
}
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
// src/plugins/css.ts
|
|
1691
|
+
import path8 from "path";
|
|
1638
1692
|
function cssPlugin(config) {
|
|
1639
1693
|
return {
|
|
1640
1694
|
name: "nasti:css",
|
|
@@ -1642,9 +1696,14 @@ function cssPlugin(config) {
|
|
|
1642
1696
|
if (source.endsWith(".css")) return null;
|
|
1643
1697
|
return null;
|
|
1644
1698
|
},
|
|
1645
|
-
transform(code, id) {
|
|
1699
|
+
async transform(code, id) {
|
|
1646
1700
|
if (!id.endsWith(".css")) return null;
|
|
1647
|
-
|
|
1701
|
+
let cssSource = code;
|
|
1702
|
+
if (hasTailwindDirectives(code)) {
|
|
1703
|
+
const compiled = await compileTailwind(code, id, config.root);
|
|
1704
|
+
cssSource = compiled.css;
|
|
1705
|
+
}
|
|
1706
|
+
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
1648
1707
|
if (config.command === "serve") {
|
|
1649
1708
|
const escaped = JSON.stringify(rewritten);
|
|
1650
1709
|
return {
|
|
@@ -1679,19 +1738,20 @@ function rewriteCssUrls(css, from, root) {
|
|
|
1679
1738
|
if (url.startsWith("/") || url.startsWith("data:") || url.startsWith("http")) {
|
|
1680
1739
|
return match;
|
|
1681
1740
|
}
|
|
1682
|
-
const resolved =
|
|
1683
|
-
const relative = "/" +
|
|
1741
|
+
const resolved = path8.resolve(path8.dirname(from), url);
|
|
1742
|
+
const relative = "/" + path8.relative(root, resolved);
|
|
1684
1743
|
return `url(${relative})`;
|
|
1685
1744
|
});
|
|
1686
1745
|
}
|
|
1687
1746
|
var init_css = __esm({
|
|
1688
1747
|
"src/plugins/css.ts"() {
|
|
1689
1748
|
"use strict";
|
|
1749
|
+
init_tailwind();
|
|
1690
1750
|
}
|
|
1691
1751
|
});
|
|
1692
1752
|
|
|
1693
1753
|
// src/plugins/assets.ts
|
|
1694
|
-
import
|
|
1754
|
+
import path9 from "path";
|
|
1695
1755
|
import fs7 from "fs";
|
|
1696
1756
|
import crypto from "crypto";
|
|
1697
1757
|
function assetsPlugin(config) {
|
|
@@ -1704,7 +1764,7 @@ function assetsPlugin(config) {
|
|
|
1704
1764
|
return null;
|
|
1705
1765
|
},
|
|
1706
1766
|
load(id) {
|
|
1707
|
-
const ext =
|
|
1767
|
+
const ext = path9.extname(id.replace(/\?.*$/, ""));
|
|
1708
1768
|
if (id.endsWith("?raw")) {
|
|
1709
1769
|
const file = id.slice(0, -4);
|
|
1710
1770
|
if (fs7.existsSync(file)) {
|
|
@@ -1716,12 +1776,12 @@ function assetsPlugin(config) {
|
|
|
1716
1776
|
const file = id.replace(/\?.*$/, "");
|
|
1717
1777
|
if (!fs7.existsSync(file)) return null;
|
|
1718
1778
|
if (config.command === "serve") {
|
|
1719
|
-
const url = "/" +
|
|
1779
|
+
const url = "/" + path9.relative(config.root, file);
|
|
1720
1780
|
return `export default ${JSON.stringify(url)}`;
|
|
1721
1781
|
}
|
|
1722
1782
|
const content = fs7.readFileSync(file);
|
|
1723
1783
|
const hash = crypto.createHash("sha256").update(content).digest("hex").slice(0, 8);
|
|
1724
|
-
const basename =
|
|
1784
|
+
const basename = path9.basename(file, ext);
|
|
1725
1785
|
const hashedName = `${config.build.assetsDir}/${basename}.${hash}${ext}`;
|
|
1726
1786
|
return `export default ${JSON.stringify(config.base + hashedName)}`;
|
|
1727
1787
|
}
|
|
@@ -1766,7 +1826,7 @@ __export(server_exports, {
|
|
|
1766
1826
|
createServer: () => createServer
|
|
1767
1827
|
});
|
|
1768
1828
|
import http from "http";
|
|
1769
|
-
import
|
|
1829
|
+
import path10 from "path";
|
|
1770
1830
|
import os from "os";
|
|
1771
1831
|
import connect from "connect";
|
|
1772
1832
|
import sirv from "sirv";
|
|
@@ -1790,20 +1850,20 @@ async function createServer(inlineConfig = {}) {
|
|
|
1790
1850
|
pluginContainer,
|
|
1791
1851
|
moduleGraph
|
|
1792
1852
|
}));
|
|
1793
|
-
const publicDir =
|
|
1853
|
+
const publicDir = path10.resolve(config.root, "public");
|
|
1794
1854
|
app.use(sirv(publicDir, { dev: true, etag: true }));
|
|
1795
1855
|
app.use(sirv(config.root, { dev: true, etag: true }));
|
|
1796
1856
|
const httpServer = http.createServer(app);
|
|
1797
1857
|
const ws = createWebSocketServer(httpServer);
|
|
1798
1858
|
const ignoredSegments = /* @__PURE__ */ new Set(["node_modules", ".git", ".nasti"]);
|
|
1799
|
-
const outDirAbs =
|
|
1859
|
+
const outDirAbs = path10.resolve(config.root, config.build.outDir);
|
|
1800
1860
|
const watcher = watch(config.root, {
|
|
1801
1861
|
ignored: (filePath) => {
|
|
1802
1862
|
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(
|
|
1863
|
+
if (filePath === outDirAbs || filePath.startsWith(outDirAbs + path10.sep)) return true;
|
|
1864
|
+
const rel = path10.relative(config.root, filePath);
|
|
1865
|
+
if (!rel || rel.startsWith("..") || path10.isAbsolute(rel)) return false;
|
|
1866
|
+
for (const seg of rel.split(path10.sep)) {
|
|
1807
1867
|
if (ignoredSegments.has(seg)) return true;
|
|
1808
1868
|
}
|
|
1809
1869
|
return false;
|
|
@@ -1835,7 +1895,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1835
1895
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1836
1896
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1837
1897
|
console.log();
|
|
1838
|
-
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.
|
|
1898
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.4"}`));
|
|
1839
1899
|
console.log();
|
|
1840
1900
|
console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
|
|
1841
1901
|
if (networkUrl) {
|
|
@@ -1951,17 +2011,17 @@ var build_exports = {};
|
|
|
1951
2011
|
__export(build_exports, {
|
|
1952
2012
|
build: () => build
|
|
1953
2013
|
});
|
|
1954
|
-
import
|
|
2014
|
+
import path11 from "path";
|
|
1955
2015
|
import fs8 from "fs";
|
|
1956
2016
|
import { rolldown } from "rolldown";
|
|
1957
2017
|
import pc2 from "picocolors";
|
|
1958
2018
|
async function build(inlineConfig = {}) {
|
|
1959
2019
|
const config = await resolveConfig(inlineConfig, "build");
|
|
1960
2020
|
const startTime = performance.now();
|
|
1961
|
-
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.
|
|
2021
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.4"}`));
|
|
1962
2022
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
1963
2023
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
1964
|
-
const outDir =
|
|
2024
|
+
const outDir = path11.resolve(config.root, config.build.outDir);
|
|
1965
2025
|
if (config.build.emptyOutDir && fs8.existsSync(outDir)) {
|
|
1966
2026
|
fs8.rmSync(outDir, { recursive: true, force: true });
|
|
1967
2027
|
}
|
|
@@ -1973,14 +2033,14 @@ async function build(inlineConfig = {}) {
|
|
|
1973
2033
|
for (const match of scriptMatches) {
|
|
1974
2034
|
const src = match[1];
|
|
1975
2035
|
if (src && !src.startsWith("http")) {
|
|
1976
|
-
entryPoints.push(
|
|
2036
|
+
entryPoints.push(path11.resolve(config.root, src.replace(/^\//, "")));
|
|
1977
2037
|
}
|
|
1978
2038
|
}
|
|
1979
2039
|
}
|
|
1980
2040
|
if (entryPoints.length === 0) {
|
|
1981
2041
|
const fallbackEntries = ["src/main.ts", "src/main.tsx", "src/main.js", "src/index.ts", "src/index.tsx", "src/index.js"];
|
|
1982
2042
|
for (const entry of fallbackEntries) {
|
|
1983
|
-
const fullPath =
|
|
2043
|
+
const fullPath = path11.resolve(config.root, entry);
|
|
1984
2044
|
if (fs8.existsSync(fullPath)) {
|
|
1985
2045
|
entryPoints.push(fullPath);
|
|
1986
2046
|
break;
|
|
@@ -2045,8 +2105,8 @@ async function build(inlineConfig = {}) {
|
|
|
2045
2105
|
await bundle.close();
|
|
2046
2106
|
await pluginContainer.buildEnd();
|
|
2047
2107
|
for (const ef of pluginContainer.getEmittedFiles()) {
|
|
2048
|
-
const dest =
|
|
2049
|
-
fs8.mkdirSync(
|
|
2108
|
+
const dest = path11.resolve(outDir, ef.fileName);
|
|
2109
|
+
fs8.mkdirSync(path11.dirname(dest), { recursive: true });
|
|
2050
2110
|
fs8.writeFileSync(dest, ef.source);
|
|
2051
2111
|
}
|
|
2052
2112
|
if (html) {
|
|
@@ -2064,14 +2124,14 @@ async function build(inlineConfig = {}) {
|
|
|
2064
2124
|
}
|
|
2065
2125
|
for (const chunk of output) {
|
|
2066
2126
|
if (chunk.type === "chunk" && chunk.isEntry && chunk.facadeModuleId) {
|
|
2067
|
-
const originalEntry =
|
|
2127
|
+
const originalEntry = path11.relative(config.root, chunk.facadeModuleId);
|
|
2068
2128
|
processedHtml = processedHtml.replace(
|
|
2069
2129
|
new RegExp(`(src=["'])/?(${escapeRegExp(originalEntry)})(["'])`, "g"),
|
|
2070
2130
|
`$1${config.base}${chunk.fileName}$3`
|
|
2071
2131
|
);
|
|
2072
2132
|
}
|
|
2073
2133
|
}
|
|
2074
|
-
fs8.writeFileSync(
|
|
2134
|
+
fs8.writeFileSync(path11.resolve(outDir, "index.html"), processedHtml);
|
|
2075
2135
|
}
|
|
2076
2136
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2077
2137
|
const totalSize = output.reduce((sum, chunk) => {
|
|
@@ -2114,7 +2174,7 @@ __export(electron_exports, {
|
|
|
2114
2174
|
detectInstalledElectron: () => detectInstalledElectron,
|
|
2115
2175
|
normalizePreload: () => normalizePreload
|
|
2116
2176
|
});
|
|
2117
|
-
import
|
|
2177
|
+
import path12 from "path";
|
|
2118
2178
|
import fs9 from "fs";
|
|
2119
2179
|
import { rolldown as rolldown2 } from "rolldown";
|
|
2120
2180
|
import pc3 from "picocolors";
|
|
@@ -2122,16 +2182,16 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2122
2182
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2123
2183
|
const startTime = performance.now();
|
|
2124
2184
|
assertElectronVersion(config);
|
|
2125
|
-
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.
|
|
2185
|
+
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.6.4"}`));
|
|
2126
2186
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
2127
2187
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
2128
2188
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
2129
|
-
const outDir =
|
|
2189
|
+
const outDir = path12.resolve(config.root, config.build.outDir);
|
|
2130
2190
|
if (config.build.emptyOutDir && fs9.existsSync(outDir)) {
|
|
2131
2191
|
fs9.rmSync(outDir, { recursive: true, force: true });
|
|
2132
2192
|
}
|
|
2133
2193
|
fs9.mkdirSync(outDir, { recursive: true });
|
|
2134
|
-
const rendererOutDir =
|
|
2194
|
+
const rendererOutDir = path12.join(outDir, "renderer");
|
|
2135
2195
|
const { build: build2 } = await Promise.resolve().then(() => (init_build(), build_exports));
|
|
2136
2196
|
await build2({
|
|
2137
2197
|
...inlineConfig,
|
|
@@ -2142,7 +2202,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2142
2202
|
emptyOutDir: false
|
|
2143
2203
|
}
|
|
2144
2204
|
});
|
|
2145
|
-
const mainEntry =
|
|
2205
|
+
const mainEntry = path12.resolve(config.root, config.electron.main);
|
|
2146
2206
|
if (!fs9.existsSync(mainEntry)) {
|
|
2147
2207
|
throw new Error(
|
|
2148
2208
|
`Electron main entry not found: ${config.electron.main}
|
|
@@ -2161,7 +2221,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2161
2221
|
console.warn(pc3.yellow(` \u26A0 preload entry not found, skipped: ${entry}`));
|
|
2162
2222
|
continue;
|
|
2163
2223
|
}
|
|
2164
|
-
const base =
|
|
2224
|
+
const base = path12.basename(entry).replace(/\.[^.]+$/, "");
|
|
2165
2225
|
const out = outFileName(outDir, base, config.electron.preloadFormat);
|
|
2166
2226
|
await bundleNode(config, entry, {
|
|
2167
2227
|
outFile: out,
|
|
@@ -2173,10 +2233,10 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2173
2233
|
const elapsed = ((performance.now() - startTime) / 1e3).toFixed(2);
|
|
2174
2234
|
console.log(pc3.green(`
|
|
2175
2235
|
\u2713 Electron build complete in ${elapsed}s`));
|
|
2176
|
-
console.log(pc3.dim(` renderer: ${
|
|
2177
|
-
console.log(pc3.dim(` main: ${
|
|
2236
|
+
console.log(pc3.dim(` renderer: ${path12.relative(config.root, rendererOutDir)}/`));
|
|
2237
|
+
console.log(pc3.dim(` main: ${path12.relative(config.root, mainFile)}`));
|
|
2178
2238
|
for (const pf of preloadFiles) {
|
|
2179
|
-
console.log(pc3.dim(` preload: ${
|
|
2239
|
+
console.log(pc3.dim(` preload: ${path12.relative(config.root, pf)}`));
|
|
2180
2240
|
}
|
|
2181
2241
|
console.log();
|
|
2182
2242
|
return { rendererOutDir, mainFile, preloadFiles };
|
|
@@ -2207,7 +2267,7 @@ async function bundleNode(config, entry, opts) {
|
|
|
2207
2267
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2208
2268
|
...config.build.rolldownOptions
|
|
2209
2269
|
});
|
|
2210
|
-
fs9.mkdirSync(
|
|
2270
|
+
fs9.mkdirSync(path12.dirname(opts.outFile), { recursive: true });
|
|
2211
2271
|
await bundle.write({
|
|
2212
2272
|
file: opts.outFile,
|
|
2213
2273
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2216,16 +2276,16 @@ async function bundleNode(config, entry, opts) {
|
|
|
2216
2276
|
codeSplitting: false
|
|
2217
2277
|
});
|
|
2218
2278
|
await bundle.close();
|
|
2219
|
-
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${
|
|
2279
|
+
console.log(pc3.dim(` \u2713 ${opts.label} \u2192 ${path12.relative(config.root, opts.outFile)}`));
|
|
2220
2280
|
return opts.outFile;
|
|
2221
2281
|
}
|
|
2222
2282
|
function outFileName(outDir, base, format) {
|
|
2223
2283
|
const ext = format === "cjs" ? ".cjs" : ".mjs";
|
|
2224
|
-
return
|
|
2284
|
+
return path12.join(outDir, base + ext);
|
|
2225
2285
|
}
|
|
2226
2286
|
function normalizePreload(preload, root) {
|
|
2227
2287
|
const list = Array.isArray(preload) ? preload : preload ? [preload] : [];
|
|
2228
|
-
return list.map((p) =>
|
|
2288
|
+
return list.map((p) => path12.resolve(root, p));
|
|
2229
2289
|
}
|
|
2230
2290
|
function assertElectronVersion(config) {
|
|
2231
2291
|
const min = config.electron.minVersion;
|
|
@@ -2240,7 +2300,7 @@ function assertElectronVersion(config) {
|
|
|
2240
2300
|
}
|
|
2241
2301
|
function detectInstalledElectron(root) {
|
|
2242
2302
|
try {
|
|
2243
|
-
const pkgPath =
|
|
2303
|
+
const pkgPath = path12.resolve(root, "node_modules/electron/package.json");
|
|
2244
2304
|
if (!fs9.existsSync(pkgPath)) return null;
|
|
2245
2305
|
const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf-8"));
|
|
2246
2306
|
const major = parseInt(String(pkg.version).split(".")[0], 10);
|
|
@@ -2265,9 +2325,9 @@ var electron_dev_exports = {};
|
|
|
2265
2325
|
__export(electron_dev_exports, {
|
|
2266
2326
|
startElectronDev: () => startElectronDev
|
|
2267
2327
|
});
|
|
2268
|
-
import
|
|
2328
|
+
import path13 from "path";
|
|
2269
2329
|
import fs10 from "fs";
|
|
2270
|
-
import { createRequire as
|
|
2330
|
+
import { createRequire as createRequire4 } from "module";
|
|
2271
2331
|
import { spawn } from "child_process";
|
|
2272
2332
|
import chokidar from "chokidar";
|
|
2273
2333
|
import pc4 from "picocolors";
|
|
@@ -2276,17 +2336,17 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2276
2336
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2277
2337
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2278
2338
|
warnElectronVersion(config);
|
|
2279
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.
|
|
2339
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.6.4"}`));
|
|
2280
2340
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2281
2341
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2282
2342
|
await server.listen();
|
|
2283
2343
|
const devUrl = `http://localhost:${server.config.server.port}/`;
|
|
2284
2344
|
console.log(pc4.dim(` renderer: ${devUrl}`));
|
|
2285
|
-
const stageDir =
|
|
2345
|
+
const stageDir = path13.resolve(config.root, ".nasti");
|
|
2286
2346
|
fs10.mkdirSync(stageDir, { recursive: true });
|
|
2287
|
-
const mainEntry =
|
|
2347
|
+
const mainEntry = path13.resolve(config.root, config.electron.main);
|
|
2288
2348
|
const preloadEntries = normalizePreload(config.electron.preload, config.root);
|
|
2289
|
-
const builtMainFile =
|
|
2349
|
+
const builtMainFile = path13.join(stageDir, "main" + extFor(config.electron.mainFormat));
|
|
2290
2350
|
const builtPreloadFiles = [];
|
|
2291
2351
|
const compileAll = async () => {
|
|
2292
2352
|
await compileNode(config, mainEntry, {
|
|
@@ -2297,8 +2357,8 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2297
2357
|
builtPreloadFiles.length = 0;
|
|
2298
2358
|
for (const entry of preloadEntries) {
|
|
2299
2359
|
if (!fs10.existsSync(entry)) continue;
|
|
2300
|
-
const base =
|
|
2301
|
-
const out =
|
|
2360
|
+
const base = path13.basename(entry).replace(/\.[^.]+$/, "");
|
|
2361
|
+
const out = path13.join(stageDir, base + extFor(config.electron.preloadFormat));
|
|
2302
2362
|
await compileNode(config, entry, {
|
|
2303
2363
|
outFile: out,
|
|
2304
2364
|
format: config.electron.preloadFormat,
|
|
@@ -2413,7 +2473,7 @@ async function compileNode(config, entry, opts) {
|
|
|
2413
2473
|
platform: "node",
|
|
2414
2474
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2415
2475
|
});
|
|
2416
|
-
fs10.mkdirSync(
|
|
2476
|
+
fs10.mkdirSync(path13.dirname(opts.outFile), { recursive: true });
|
|
2417
2477
|
await bundle.write({
|
|
2418
2478
|
file: opts.outFile,
|
|
2419
2479
|
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
@@ -2430,7 +2490,7 @@ function resolveElectronBinary(config) {
|
|
|
2430
2490
|
return config.electron.electronPath;
|
|
2431
2491
|
}
|
|
2432
2492
|
try {
|
|
2433
|
-
const require2 =
|
|
2493
|
+
const require2 = createRequire4(path13.resolve(config.root, "package.json"));
|
|
2434
2494
|
const pathFile = require2.resolve("electron");
|
|
2435
2495
|
const electronModule = require2(pathFile);
|
|
2436
2496
|
if (typeof electronModule === "string" && fs10.existsSync(electronModule)) {
|
|
@@ -2578,11 +2638,11 @@ cli.command("electron-build [root]", "Build Electron app for production").option
|
|
|
2578
2638
|
cli.command("preview [root]", "Preview production build").option("--port <port>", "Port number", { default: 4173 }).option("--host [host]", "Hostname").option("--outDir <dir>", "Output directory to serve", { default: "dist" }).action(async (root, options) => {
|
|
2579
2639
|
try {
|
|
2580
2640
|
const http2 = await import("http");
|
|
2581
|
-
const
|
|
2641
|
+
const path14 = await import("path");
|
|
2582
2642
|
const sirv2 = (await import("sirv")).default;
|
|
2583
2643
|
const connect2 = (await import("connect")).default;
|
|
2584
|
-
const resolvedRoot =
|
|
2585
|
-
const outDir =
|
|
2644
|
+
const resolvedRoot = path14.resolve(root ?? ".");
|
|
2645
|
+
const outDir = path14.resolve(resolvedRoot, options.outDir);
|
|
2586
2646
|
const app = connect2();
|
|
2587
2647
|
app.use(sirv2(outDir, { single: true, etag: true, gzip: true, brotli: true }));
|
|
2588
2648
|
const port = options.port;
|
|
@@ -2603,6 +2663,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2603
2663
|
}
|
|
2604
2664
|
});
|
|
2605
2665
|
cli.help();
|
|
2606
|
-
cli.version("1.6.
|
|
2666
|
+
cli.version("1.6.4");
|
|
2607
2667
|
cli.parse();
|
|
2608
2668
|
//# sourceMappingURL=cli.js.map
|