@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 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",
@@ -1585,20 +1586,29 @@ var init_hmr = __esm({
1585
1586
  function resolvePlugin(config) {
1586
1587
  const { alias, extensions } = config.resolve;
1587
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
+ );
1588
1592
  return {
1589
1593
  name: "nasti:resolve",
1590
1594
  enforce: "pre",
1591
1595
  resolveId(source, importer) {
1592
- for (const [key, value] of Object.entries(alias)) {
1596
+ for (const [key, value] of aliasEntries) {
1593
1597
  if (source === key || source.startsWith(key + "/")) {
1594
- source = source.replace(key, value);
1595
- if (!import_node_path6.default.isAbsolute(source)) {
1596
- source = import_node_path6.default.resolve(config.root, source);
1597
- }
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;
1598
1603
  break;
1599
1604
  }
1600
1605
  }
1601
- if (import_node_path6.default.isAbsolute(source)) {
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)) {
1602
1612
  const resolved = tryResolveFile(source, extensions);
1603
1613
  if (resolved) return resolved;
1604
1614
  }
@@ -1621,6 +1631,7 @@ function resolvePlugin(config) {
1621
1631
  return null;
1622
1632
  },
1623
1633
  load(id) {
1634
+ if (id.startsWith("\0")) return null;
1624
1635
  if (!import_node_fs6.default.existsSync(id)) return null;
1625
1636
  if (id.endsWith(".json")) {
1626
1637
  const content = import_node_fs6.default.readFileSync(id, "utf-8");
@@ -1630,6 +1641,11 @@ function resolvePlugin(config) {
1630
1641
  }
1631
1642
  };
1632
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
+ }
1633
1649
  function tryResolveFile(file, extensions) {
1634
1650
  if (import_node_fs6.default.existsSync(file) && import_node_fs6.default.statSync(file).isFile()) {
1635
1651
  return file;
@@ -1729,8 +1745,8 @@ function cssPlugin(config) {
1729
1745
  cssSource = compiled.css;
1730
1746
  }
1731
1747
  const rewritten = rewriteCssUrls(cssSource, id, config.root);
1748
+ const escaped = JSON.stringify(rewritten);
1732
1749
  if (config.command === "serve") {
1733
- const escaped = JSON.stringify(rewritten);
1734
1750
  return {
1735
1751
  code: `
1736
1752
  const css = ${escaped};
@@ -1754,7 +1770,42 @@ export default css;
1754
1770
  `
1755
1771
  };
1756
1772
  }
1757
- return rewritten !== code ? { code: rewritten } : null;
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
+ };
1758
1809
  }
1759
1810
  };
1760
1811
  }
@@ -1915,7 +1966,7 @@ async function createServer(inlineConfig = {}) {
1915
1966
  const localUrl = `http://localhost:${actualPort}`;
1916
1967
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1917
1968
  console.log();
1918
- console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.4"}`));
1969
+ console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.5"}`));
1919
1970
  console.log();
1920
1971
  console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
1921
1972
  if (networkUrl) {
@@ -2042,7 +2093,7 @@ __export(build_exports, {
2042
2093
  async function build(inlineConfig = {}) {
2043
2094
  const config = await resolveConfig(inlineConfig, "build");
2044
2095
  const startTime = performance.now();
2045
- console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.4"}`));
2096
+ console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.5"}`));
2046
2097
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
2047
2098
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
2048
2099
  const outDir = import_node_path11.default.resolve(config.root, config.build.outDir);
@@ -2096,9 +2147,11 @@ async function build(inlineConfig = {}) {
2096
2147
  };
2097
2148
  const env = loadEnv(config.mode, config.root, config.envPrefix);
2098
2149
  const envDefine = buildEnvDefine(env, config.mode);
2150
+ const existingTransform = config.build.rolldownOptions?.transform;
2151
+ const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
2099
2152
  const bundle = await (0, import_rolldown.rolldown)({
2100
2153
  input: entryPoints,
2101
- define: envDefine,
2154
+ transform: { ...existingTransform, define: mergedDefine },
2102
2155
  plugins: [
2103
2156
  oxcTransformPlugin,
2104
2157
  // 转换 Nasti 插件为 Rolldown 插件格式
@@ -2207,7 +2260,7 @@ async function buildElectron(inlineConfig = {}) {
2207
2260
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2208
2261
  const startTime = performance.now();
2209
2262
  assertElectronVersion(config);
2210
- console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.4"}`));
2263
+ console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.5"}`));
2211
2264
  console.log(import_picocolors3.default.dim(` root: ${config.root}`));
2212
2265
  console.log(import_picocolors3.default.dim(` mode: ${config.mode}`));
2213
2266
  console.log(import_picocolors3.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -2285,9 +2338,11 @@ async function bundleNode(config, entry, opts) {
2285
2338
  return { code: result.code, map: result.map ? JSON.parse(result.map) : void 0 };
2286
2339
  }
2287
2340
  };
2341
+ const existingTransform = config.build.rolldownOptions?.transform;
2342
+ const mergedDefine = { ...existingTransform?.define ?? {}, ...envDefine };
2288
2343
  const bundle = await (0, import_rolldown2.rolldown)({
2289
2344
  input: entry,
2290
- define: envDefine,
2345
+ transform: { ...existingTransform, define: mergedDefine },
2291
2346
  platform: "node",
2292
2347
  plugins: [oxcTransformPlugin, electronPlugin(config), resolvePlugin(config)],
2293
2348
  ...config.build.rolldownOptions
@@ -2359,7 +2414,7 @@ async function startElectronDev(inlineConfig = {}) {
2359
2414
  const { noSpawn, ...rest } = inlineConfig;
2360
2415
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2361
2416
  warnElectronVersion(config);
2362
- console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.4"}`));
2417
+ console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.5"}`));
2363
2418
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2364
2419
  const server = await createServer2({ ...rest, target: "electron" });
2365
2420
  await server.listen();
@@ -2694,6 +2749,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
2694
2749
  }
2695
2750
  });
2696
2751
  cli.help();
2697
- cli.version("1.6.4");
2752
+ cli.version("1.6.5");
2698
2753
  cli.parse();
2699
2754
  //# sourceMappingURL=cli.cjs.map