@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/index.cjs CHANGED
@@ -2871,7 +2871,7 @@ async function build(inlineConfig = {}) {
2871
2871
  const startTime = performance.now();
2872
2872
  logger.info(
2873
2873
  import_picocolors4.default.cyan(`
2874
- nasti v${"2.0.2"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
2874
+ nasti v${"2.2.0"} `) + import_picocolors4.default.green(`building for ${config.mode}...`)
2875
2875
  );
2876
2876
  debug4?.(`root: ${config.root}`);
2877
2877
  const buildableNames = Object.keys(config.environments).filter(
@@ -3771,7 +3771,7 @@ const hotModulesMap = new Map();
3771
3771
  const disposeMap = new Map();
3772
3772
  const pruneMap = new Map();
3773
3773
 
3774
- socket.addEventListener('message', ({ data }) => {
3774
+ socket.addEventListener('message', async ({ data }) => {
3775
3775
  const payload = JSON.parse(data);
3776
3776
  switch (payload.type) {
3777
3777
  case 'connected':
@@ -3779,14 +3779,21 @@ socket.addEventListener('message', ({ data }) => {
3779
3779
  clearErrorOverlay();
3780
3780
  break;
3781
3781
  case 'update':
3782
- payload.updates.forEach((update) => {
3783
- if (update.type === 'js-update') {
3784
- fetchUpdate(update);
3785
- } else if (update.type === 'css-update') {
3786
- updateCss(update.path);
3787
- }
3788
- });
3789
- clearErrorOverlay();
3782
+ try {
3783
+ await Promise.all(payload.updates.map((update) => {
3784
+ if (update.type === 'js-update') {
3785
+ return fetchUpdate(update);
3786
+ } else if (update.type === 'css-update') {
3787
+ return updateCss(update.path);
3788
+ }
3789
+ }));
3790
+ clearErrorOverlay();
3791
+ console.log('[nasti] HMR update complete, reloading page');
3792
+ location.reload();
3793
+ } catch (err) {
3794
+ console.error('[nasti] HMR update failed:', err);
3795
+ showErrorOverlay(err);
3796
+ }
3790
3797
  break;
3791
3798
  case 'full-reload':
3792
3799
  console.log('[nasti] full reload');
@@ -3828,7 +3835,7 @@ async function fetchUpdate(update) {
3828
3835
  function updateCss(path) {
3829
3836
  const el = document.querySelector(\`style[data-nasti-css="\${path}"]\`);
3830
3837
  if (el) {
3831
- fetch(path + '?t=' + Date.now())
3838
+ return fetch(path + '?t=' + Date.now())
3832
3839
  .then(r => r.text())
3833
3840
  .then(css => { el.textContent = css; });
3834
3841
  }
@@ -4283,7 +4290,10 @@ async function createBundledDevServer(opts) {
4283
4290
  continue;
4284
4291
  }
4285
4292
  const patchPath = `__nasti_patch/${update.filename}`;
4286
- patches.set(patchPath, update.code + "\n;export {}");
4293
+ patches.set(
4294
+ patchPath,
4295
+ update.code + "\n;globalThis.location?.reload();\n;export {}"
4296
+ );
4287
4297
  if (update.sourcemap && update.sourcemapFilename) {
4288
4298
  patches.set(`__nasti_patch/${update.sourcemapFilename}`, update.sourcemap);
4289
4299
  }
@@ -4753,7 +4763,7 @@ async function createServer(inlineConfig = {}) {
4753
4763
  const readyIn = Math.ceil(performance.now() - startTime);
4754
4764
  logger.info(
4755
4765
  `
4756
- ${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.0.2"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
4766
+ ${import_picocolors9.default.cyan(import_picocolors9.default.bold("NASTI"))} ${import_picocolors9.default.cyan(`v${"2.2.0"}`)} ${import_picocolors9.default.dim("ready in")} ${import_picocolors9.default.bold(readyIn)} ${import_picocolors9.default.dim("ms")}
4757
4767
  `
4758
4768
  );
4759
4769
  printServerUrls(
@@ -4912,7 +4922,7 @@ async function buildElectron(inlineConfig = {}) {
4912
4922
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
4913
4923
  const startTime = performance.now();
4914
4924
  assertElectronVersion(config);
4915
- console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.0.2"}`));
4925
+ console.log(import_picocolors5.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors5.default.dim(` v${"2.2.0"}`));
4916
4926
  console.log(import_picocolors5.default.dim(` root: ${config.root}`));
4917
4927
  console.log(import_picocolors5.default.dim(` mode: ${config.mode}`));
4918
4928
  console.log(import_picocolors5.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -5063,7 +5073,7 @@ async function startElectronDev(inlineConfig = {}) {
5063
5073
  const { noSpawn, ...rest } = inlineConfig;
5064
5074
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
5065
5075
  warnElectronVersion(config);
5066
- console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.0.2"}`));
5076
+ console.log(import_picocolors10.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors10.default.dim(` v${"2.2.0"}`));
5067
5077
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
5068
5078
  const server = await createServer2({ ...rest, target: "electron" });
5069
5079
  await server.listen();
@@ -5187,7 +5197,7 @@ async function compileNode(config, entry, opts) {
5187
5197
  transform(code, id) {
5188
5198
  if (!shouldTransform(id)) return null;
5189
5199
  const result = transformCode(id, code, {
5190
- sourcemap: !!config.build.sourcemap,
5200
+ sourcemap: true,
5191
5201
  jsxRuntime: "automatic",
5192
5202
  jsxImportSource: config.framework === "vue" ? "vue" : "react"
5193
5203
  });
@@ -5204,7 +5214,7 @@ async function compileNode(config, entry, opts) {
5204
5214
  await bundle2.write({
5205
5215
  file: opts.outFile,
5206
5216
  format: opts.format === "cjs" ? "cjs" : "esm",
5207
- sourcemap: false,
5217
+ sourcemap: true,
5208
5218
  minify: false,
5209
5219
  // rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
5210
5220
  // 同样语义(单 chunk、内联 dynamic import)