@nasti-toolchain/nasti 1.6.4 → 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 +71 -16
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +71 -16
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +72 -17
- 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 +72 -17
- 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.6.
|
|
1949
|
+
console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.6.5"}`));
|
|
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.6.
|
|
2072
|
+
console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.6.5"}`));
|
|
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,11 @@ 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 existingTransform = config.build.rolldownOptions?.transform;
|
|
2127
|
+
const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
|
|
2075
2128
|
const bundle = await rolldown({
|
|
2076
2129
|
input: entryPoints,
|
|
2077
|
-
define:
|
|
2130
|
+
transform: { ...existingTransform, define: mergedDefine },
|
|
2078
2131
|
plugins: [
|
|
2079
2132
|
oxcTransformPlugin,
|
|
2080
2133
|
// 转换 Nasti 插件为 Rolldown 插件格式
|
|
@@ -2182,7 +2235,7 @@ async function buildElectron(inlineConfig = {}) {
|
|
|
2182
2235
|
const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
|
|
2183
2236
|
const startTime = performance.now();
|
|
2184
2237
|
assertElectronVersion(config);
|
|
2185
|
-
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"}`));
|
|
2186
2239
|
console.log(pc3.dim(` root: ${config.root}`));
|
|
2187
2240
|
console.log(pc3.dim(` mode: ${config.mode}`));
|
|
2188
2241
|
console.log(pc3.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
|
|
@@ -2260,9 +2313,11 @@ async function bundleNode(config, entry, opts) {
|
|
|
2260
2313
|
return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
|
|
2261
2314
|
}
|
|
2262
2315
|
};
|
|
2316
|
+
const existingTransform = config.build.rolldownOptions?.transform;
|
|
2317
|
+
const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
|
|
2263
2318
|
const bundle = await rolldown2({
|
|
2264
2319
|
input: entry,
|
|
2265
|
-
define:
|
|
2320
|
+
transform: { ...existingTransform, define: mergedDefine },
|
|
2266
2321
|
platform: "node",
|
|
2267
2322
|
plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
|
|
2268
2323
|
...config.build.rolldownOptions
|
|
@@ -2336,7 +2391,7 @@ async function startElectronDev(inlineConfig = {}) {
|
|
|
2336
2391
|
const { noSpawn, ...rest } = inlineConfig;
|
|
2337
2392
|
const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
|
|
2338
2393
|
warnElectronVersion(config);
|
|
2339
|
-
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"}`));
|
|
2340
2395
|
const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
|
|
2341
2396
|
const server = await createServer2({ ...rest, target: "electron" });
|
|
2342
2397
|
await server.listen();
|
|
@@ -2663,6 +2718,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
|
|
|
2663
2718
|
}
|
|
2664
2719
|
});
|
|
2665
2720
|
cli.help();
|
|
2666
|
-
cli.version("1.6.
|
|
2721
|
+
cli.version("1.6.5");
|
|
2667
2722
|
cli.parse();
|
|
2668
2723
|
//# sourceMappingURL=cli.js.map
|