@nasti-toolchain/nasti 2.0.2 → 2.2.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/dist/cli.cjs CHANGED
@@ -1859,7 +1859,7 @@ const hotModulesMap = new Map();
1859
1859
  const disposeMap = new Map();
1860
1860
  const pruneMap = new Map();
1861
1861
 
1862
- socket.addEventListener('message', ({ data }) => {
1862
+ socket.addEventListener('message', async ({ data }) => {
1863
1863
  const payload = JSON.parse(data);
1864
1864
  switch (payload.type) {
1865
1865
  case 'connected':
@@ -1867,14 +1867,21 @@ socket.addEventListener('message', ({ data }) => {
1867
1867
  clearErrorOverlay();
1868
1868
  break;
1869
1869
  case 'update':
1870
- payload.updates.forEach((update) => {
1871
- if (update.type === 'js-update') {
1872
- fetchUpdate(update);
1873
- } else if (update.type === 'css-update') {
1874
- updateCss(update.path);
1875
- }
1876
- });
1877
- clearErrorOverlay();
1870
+ try {
1871
+ await Promise.all(payload.updates.map((update) => {
1872
+ if (update.type === 'js-update') {
1873
+ return fetchUpdate(update);
1874
+ } else if (update.type === 'css-update') {
1875
+ return updateCss(update.path);
1876
+ }
1877
+ }));
1878
+ clearErrorOverlay();
1879
+ console.log('[nasti] HMR update complete, reloading page');
1880
+ location.reload();
1881
+ } catch (err) {
1882
+ console.error('[nasti] HMR update failed:', err);
1883
+ showErrorOverlay(err);
1884
+ }
1878
1885
  break;
1879
1886
  case 'full-reload':
1880
1887
  console.log('[nasti] full reload');
@@ -1916,7 +1923,7 @@ async function fetchUpdate(update) {
1916
1923
  function updateCss(path) {
1917
1924
  const el = document.querySelector(\`style[data-nasti-css="\${path}"]\`);
1918
1925
  if (el) {
1919
- fetch(path + '?t=' + Date.now())
1926
+ return fetch(path + '?t=' + Date.now())
1920
1927
  .then(r => r.text())
1921
1928
  .then(css => { el.textContent = css; });
1922
1929
  }
@@ -4036,7 +4043,7 @@ async function build(inlineConfig = {}) {
4036
4043
  const startTime = performance.now();
4037
4044
  logger.info(
4038
4045
  import_picocolors6.default.cyan(`
4039
- nasti v${"2.0.2"} `) + import_picocolors6.default.green(`building for ${config.mode}...`)
4046
+ nasti v${"2.2.0"} `) + import_picocolors6.default.green(`building for ${config.mode}...`)
4040
4047
  );
4041
4048
  debug5?.(`root: ${config.root}`);
4042
4049
  const buildableNames = Object.keys(config.environments).filter(
@@ -4285,7 +4292,10 @@ async function createBundledDevServer(opts) {
4285
4292
  continue;
4286
4293
  }
4287
4294
  const patchPath = `__nasti_patch/${update.filename}`;
4288
- patches.set(patchPath, update.code + "\n;export {}");
4295
+ patches.set(
4296
+ patchPath,
4297
+ update.code + "\n;globalThis.location?.reload();\n;export {}"
4298
+ );
4289
4299
  if (update.sourcemap && update.sourcemapFilename) {
4290
4300
  patches.set(`__nasti_patch/${update.sourcemapFilename}`, update.sourcemap);
4291
4301
  }
@@ -4755,7 +4765,7 @@ async function createServer(inlineConfig = {}) {
4755
4765
  const readyIn = Math.ceil(performance.now() - startTime);
4756
4766
  logger.info(
4757
4767
  `
4758
- ${import_picocolors8.default.cyan(import_picocolors8.default.bold("NASTI"))} ${import_picocolors8.default.cyan(`v${"2.0.2"}`)} ${import_picocolors8.default.dim("ready in")} ${import_picocolors8.default.bold(readyIn)} ${import_picocolors8.default.dim("ms")}
4768
+ ${import_picocolors8.default.cyan(import_picocolors8.default.bold("NASTI"))} ${import_picocolors8.default.cyan(`v${"2.2.0"}`)} ${import_picocolors8.default.dim("ready in")} ${import_picocolors8.default.bold(readyIn)} ${import_picocolors8.default.dim("ms")}
4759
4769
  `
4760
4770
  );
4761
4771
  printServerUrls(
@@ -4889,7 +4899,7 @@ async function buildElectron(inlineConfig = {}) {
4889
4899
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
4890
4900
  const startTime = performance.now();
4891
4901
  assertElectronVersion(config);
4892
- console.log(import_picocolors9.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors9.default.dim(` v${"2.0.2"}`));
4902
+ console.log(import_picocolors9.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors9.default.dim(` v${"2.2.0"}`));
4893
4903
  console.log(import_picocolors9.default.dim(` root: ${config.root}`));
4894
4904
  console.log(import_picocolors9.default.dim(` mode: ${config.mode}`));
4895
4905
  console.log(import_picocolors9.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -5045,7 +5055,7 @@ async function startElectronDev(inlineConfig = {}) {
5045
5055
  const { noSpawn, ...rest } = inlineConfig;
5046
5056
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
5047
5057
  warnElectronVersion(config);
5048
- console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.0.2"}`));
5058
+ console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.2.0"}`));
5049
5059
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
5050
5060
  const server = await createServer2({ ...rest, target: "electron" });
5051
5061
  await server.listen();
@@ -5169,7 +5179,7 @@ async function compileNode(config, entry, opts) {
5169
5179
  transform(code, id) {
5170
5180
  if (!shouldTransform(id)) return null;
5171
5181
  const result = transformCode(id, code, {
5172
- sourcemap: !!config.build.sourcemap,
5182
+ sourcemap: true,
5173
5183
  jsxRuntime: "automatic",
5174
5184
  jsxImportSource: config.framework === "vue" ? "vue" : "react"
5175
5185
  });
@@ -5186,7 +5196,7 @@ async function compileNode(config, entry, opts) {
5186
5196
  await bundle2.write({
5187
5197
  file: opts.outFile,
5188
5198
  format: opts.format === "cjs" ? "cjs" : "esm",
5189
- sourcemap: false,
5199
+ sourcemap: true,
5190
5200
  minify: false,
5191
5201
  // rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
5192
5202
  // 同样语义(单 chunk、内联 dynamic import)
@@ -5398,7 +5408,7 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
5398
5408
  const host = options.host === true ? "0.0.0.0" : options.host ?? "localhost";
5399
5409
  http2.createServer(app).listen(port, host, () => {
5400
5410
  logger.info(`
5401
- ${import_picocolors11.default.cyan(import_picocolors11.default.bold("NASTI"))} ${import_picocolors11.default.cyan(`v${"2.0.2"}`)} ${import_picocolors11.default.dim("preview")}
5411
+ ${import_picocolors11.default.cyan(import_picocolors11.default.bold("NASTI"))} ${import_picocolors11.default.cyan(`v${"2.2.0"}`)} ${import_picocolors11.default.dim("preview")}
5402
5412
  `);
5403
5413
  printServerUrls2(
5404
5414
  {
@@ -5415,6 +5425,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
5415
5425
  }
5416
5426
  });
5417
5427
  cli.help();
5418
- cli.version("2.0.2");
5428
+ cli.version("2.2.0");
5419
5429
  cli.parse();
5420
5430
  //# sourceMappingURL=cli.cjs.map