@nasti-toolchain/nasti 1.6.4 → 1.7.0
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/README.md +25 -0
- package/dist/cli.cjs +84 -24
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +84 -24
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +85 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +85 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -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",
|
|
@@ -1563,20 +1564,29 @@ import { createRequire as createRequire2 } from "module";
|
|
|
1563
1564
|
function resolvePlugin(config) {
|
|
1564
1565
|
const { alias, extensions } = config.resolve;
|
|
1565
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
|
+
);
|
|
1566
1570
|
return {
|
|
1567
1571
|
name: "nasti:resolve",
|
|
1568
1572
|
enforce: "pre",
|
|
1569
1573
|
resolveId(source, importer) {
|
|
1570
|
-
for (const [key, value] of
|
|
1574
|
+
for (const [key, value] of aliasEntries) {
|
|
1571
1575
|
if (source === key || source.startsWith(key + "/")) {
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
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;
|
|
1576
1581
|
break;
|
|
1577
1582
|
}
|
|
1578
1583
|
}
|
|
1579
|
-
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)) {
|
|
1580
1590
|
const resolved = tryResolveFile(source, extensions);
|
|
1581
1591
|
if (resolved) return resolved;
|
|
1582
1592
|
}
|
|
@@ -1599,6 +1609,7 @@ function resolvePlugin(config) {
|
|
|
1599
1609
|
return null;
|
|
1600
1610
|
},
|
|
1601
1611
|
load(id) {
|
|
1612
|
+
if (id.startsWith("\0")) return null;
|
|
1602
1613
|
if (!fs6.existsSync(id)) return null;
|
|
1603
1614
|
if (id.endsWith(".json")) {
|
|
1604
1615
|
const content = fs6.readFileSync(id, "utf-8");
|
|
@@ -1608,6 +1619,11 @@ function resolvePlugin(config) {
|
|
|
1608
1619
|
}
|
|
1609
1620
|
};
|
|
1610
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
|
+
}
|
|
1611
1627
|
function tryResolveFile(file, extensions) {
|
|
1612
1628
|
if (fs6.existsSync(file) && fs6.statSync(file).isFile()) {
|
|
1613
1629
|
return file;
|
|
@@ -1704,8 +1720,8 @@ function cssPlugin(config) {
|
|
|
1704
1720
|
cssSource = compiled.css;
|
|
1705
1721
|
}
|
|
1706
1722
|
const rewritten = rewriteCssUrls(cssSource, id, config.root);
|
|
1723
|
+
const escaped = JSON.stringify(rewritten);
|
|
1707
1724
|
if (config.command === "serve") {
|
|
1708
|
-
const escaped = JSON.stringify(rewritten);
|
|
1709
1725
|
return {
|
|
1710
1726
|
code: `
|
|
1711
1727
|
const css = ${escaped};
|
|
@@ -1729,7 +1745,42 @@ export default css;
|
|
|
1729
1745
|
`
|
|
1730
1746
|
};
|
|
1731
1747
|
}
|
|
1732
|
-
|
|
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
|
+
};
|
|
1733
1784
|
}
|
|
1734
1785
|
};
|
|
1735
1786
|
}
|
|
@@ -1895,7 +1946,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
1895
1946
|
const localUrl = `http://localhost:${actualPort}`;
|
|
1896
1947
|
const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
|
|
1897
1948
|
console.log();
|
|
1898
|
-
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.
|
|
1949
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.7.0"}`));
|
|
1899
1950
|
console.log();
|
|
1900
1951
|
console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
|
|
1901
1952
|
if (networkUrl) {
|
|
@@ -2018,7 +2069,7 @@ import pc2 from "picocolors";
|
|
|
2018
2069
|
async function build(inlineConfig = {}) {
|
|
2019
2070
|
const config = await resolveConfig(inlineConfig, "build");
|
|
2020
2071
|
const startTime = performance.now();
|
|
2021
|
-
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.
|
|
2072
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.7.0"}`));
|
|
2022
2073
|
console.log(pc2.dim(` root: ${config.root}`));
|
|
2023
2074
|
console.log(pc2.dim(` mode: ${config.mode}`));
|
|
2024
2075
|
const outDir = path11.resolve(config.root, config.build.outDir);
|
|
@@ -2072,9 +2123,12 @@ async function build(inlineConfig = {}) {
|
|
|
2072
2123
|
};
|
|
2073
2124
|
const env = loadEnv(config.mode, config.root, config.envPrefix);
|
|
2074
2125
|
const envDefine = buildEnvDefine(env, config.mode);
|
|
2126
|
+
const { output: userOutput, transform: userTransform, ...restInputOptions } = config.build.rolldownOptions;
|
|
2127
|
+
const mergedDefine = { ...userTransform?.define ?? {}, ...envDefine };
|
|
2075
2128
|
const bundle = await rolldown({
|
|
2129
|
+
...restInputOptions,
|
|
2076
2130
|
input: entryPoints,
|
|
2077
|
-
define:
|
|
2131
|
+
transform: { ...userTransform, define: mergedDefine },
|
|
2078
2132
|
plugins: [
|
|
2079
2133
|
oxcTransformPlugin,
|
|
2080
2134
|
// 转换 Nasti 插件为 Rolldown 插件格式
|
|
@@ -2090,17 +2144,19 @@ async function build(inlineConfig = {}) {
|
|
|
2090
2144
|
// manifest/SW writers) rely on for final-stage artifact emission.
|
|
2091
2145
|
closeBundle: p.closeBundle
|
|
2092
2146
|
}))
|
|
2093
|
-
]
|
|
2094
|
-
...config.build.rolldownOptions
|
|
2147
|
+
]
|
|
2095
2148
|
});
|
|
2096
2149
|
const { output } = await bundle.write({
|
|
2097
|
-
dir: outDir,
|
|
2098
2150
|
format: "esm",
|
|
2099
2151
|
sourcemap: !!config.build.sourcemap,
|
|
2100
2152
|
minify: !!config.build.minify,
|
|
2101
2153
|
entryFileNames: "assets/[name].[hash].js",
|
|
2102
2154
|
chunkFileNames: "assets/[name].[hash].js",
|
|
2103
|
-
assetFileNames: "assets/[name].[hash][extname]"
|
|
2155
|
+
assetFileNames: "assets/[name].[hash][extname]",
|
|
2156
|
+
// 用户可覆盖默认输出:代码拆分(advancedChunks / codeSplitting)、chunk 命名等
|
|
2157
|
+
...userOutput,
|
|
2158
|
+
// dir 始终由 Nasti 掌管 —— 下方 HTML 改写依赖固定的产物目录,故放在最后强制生效
|
|
2159
|
+
dir: outDir
|
|
2104
2160
|
});
|
|
2105
2161
|
await bundle.close();
|
|
2106
2162
|
await pluginContainer.buildEnd();
|
|
@@ -2182,7 +2238,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2182
2238
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2183
2239
|
const startTime = performance.now();
|
|
2184
2240
|
assertElectronVersion(config);
|
|
2185
|
-
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.
|
|
2241
|
+
console.log(pc3.cyan("\n\u26A1 nasti build (electron)") + pc3.dim(` v${"1.7.0"}`));
|
|
2186
2242
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
2187
2243
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
2188
2244
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2260,19 +2316,23 @@ async function bundleNode(config, entry, opts) {
|
|
|
2260
2316
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
2261
2317
|
}
|
|
2262
2318
|
};
|
|
2319
|
+
const { output: userOutput, transform: userTransform, ...restInputOptions } = config.build.rolldownOptions;
|
|
2320
|
+
const mergedDefine = { ...userTransform?.define ?? {}, ...envDefine };
|
|
2263
2321
|
const bundle = await rolldown2({
|
|
2322
|
+
...restInputOptions,
|
|
2264
2323
|
input: entry,
|
|
2265
|
-
define: envDefine,
|
|
2266
2324
|
platform: "node",
|
|
2267
|
-
|
|
2268
|
-
|
|
2325
|
+
transform: { ...userTransform, define: mergedDefine },
|
|
2326
|
+
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)]
|
|
2269
2327
|
});
|
|
2270
2328
|
fs9.mkdirSync(path12.dirname(opts.outFile), { recursive: true });
|
|
2271
2329
|
await bundle.write({
|
|
2272
|
-
file: opts.outFile,
|
|
2273
|
-
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2274
2330
|
sourcemap: !!config.build.sourcemap,
|
|
2275
2331
|
minify: !!config.build.minify,
|
|
2332
|
+
// 允许用户微调 output;但主进程 / preload 的单文件约束由下方键强制保证
|
|
2333
|
+
...userOutput,
|
|
2334
|
+
file: opts.outFile,
|
|
2335
|
+
format: opts.format === "cjs" ? "cjs" : "esm",
|
|
2276
2336
|
codeSplitting: false
|
|
2277
2337
|
});
|
|
2278
2338
|
await bundle.close();
|
|
@@ -2336,7 +2396,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2336
2396
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2337
2397
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2338
2398
|
warnElectronVersion(config);
|
|
2339
|
-
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.
|
|
2399
|
+
console.log(pc4.cyan("\n\u26A1 nasti electron dev") + pc4.dim(` v${"1.7.0"}`));
|
|
2340
2400
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2341
2401
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2342
2402
|
await server.listen();
|
|
@@ -2663,6 +2723,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2663
2723
|
}
|
|
2664
2724
|
});
|
|
2665
2725
|
cli.help();
|
|
2666
|
-
cli.version("1.
|
|
2726
|
+
cli.version("1.7.0");
|
|
2667
2727
|
cli.parse();
|
|
2668
2728
|
//# sourceMappingURL=cli.js.map
|