@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.js CHANGED
@@ -2877,7 +2877,7 @@ async function build(inlineConfig = {}) {
2877
2877
  const startTime = performance.now();
2878
2878
  logger.info(
2879
2879
  pc4.cyan(`
2880
- nasti v${"2.0.2"} `) + pc4.green(`building for ${config.mode}...`)
2880
+ nasti v${"2.2.0"} `) + pc4.green(`building for ${config.mode}...`)
2881
2881
  );
2882
2882
  debug4?.(`root: ${config.root}`);
2883
2883
  const buildableNames = Object.keys(config.environments).filter(
@@ -3776,7 +3776,7 @@ const hotModulesMap = new Map();
3776
3776
  const disposeMap = new Map();
3777
3777
  const pruneMap = new Map();
3778
3778
 
3779
- socket.addEventListener('message', ({ data }) => {
3779
+ socket.addEventListener('message', async ({ data }) => {
3780
3780
  const payload = JSON.parse(data);
3781
3781
  switch (payload.type) {
3782
3782
  case 'connected':
@@ -3784,14 +3784,21 @@ socket.addEventListener('message', ({ data }) => {
3784
3784
  clearErrorOverlay();
3785
3785
  break;
3786
3786
  case 'update':
3787
- payload.updates.forEach((update) => {
3788
- if (update.type === 'js-update') {
3789
- fetchUpdate(update);
3790
- } else if (update.type === 'css-update') {
3791
- updateCss(update.path);
3792
- }
3793
- });
3794
- clearErrorOverlay();
3787
+ try {
3788
+ await Promise.all(payload.updates.map((update) => {
3789
+ if (update.type === 'js-update') {
3790
+ return fetchUpdate(update);
3791
+ } else if (update.type === 'css-update') {
3792
+ return updateCss(update.path);
3793
+ }
3794
+ }));
3795
+ clearErrorOverlay();
3796
+ console.log('[nasti] HMR update complete, reloading page');
3797
+ location.reload();
3798
+ } catch (err) {
3799
+ console.error('[nasti] HMR update failed:', err);
3800
+ showErrorOverlay(err);
3801
+ }
3795
3802
  break;
3796
3803
  case 'full-reload':
3797
3804
  console.log('[nasti] full reload');
@@ -3833,7 +3840,7 @@ async function fetchUpdate(update) {
3833
3840
  function updateCss(path) {
3834
3841
  const el = document.querySelector(\`style[data-nasti-css="\${path}"]\`);
3835
3842
  if (el) {
3836
- fetch(path + '?t=' + Date.now())
3843
+ return fetch(path + '?t=' + Date.now())
3837
3844
  .then(r => r.text())
3838
3845
  .then(css => { el.textContent = css; });
3839
3846
  }
@@ -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
  }
@@ -4758,7 +4768,7 @@ async function createServer(inlineConfig = {}) {
4758
4768
  const readyIn = Math.ceil(performance.now() - startTime);
4759
4769
  logger.info(
4760
4770
  `
4761
- ${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.0.2"}`)} ${pc9.dim("ready in")} ${pc9.bold(readyIn)} ${pc9.dim("ms")}
4771
+ ${pc9.cyan(pc9.bold("NASTI"))} ${pc9.cyan(`v${"2.2.0"}`)} ${pc9.dim("ready in")} ${pc9.bold(readyIn)} ${pc9.dim("ms")}
4762
4772
  `
4763
4773
  );
4764
4774
  printServerUrls(
@@ -4886,7 +4896,7 @@ async function buildElectron(inlineConfig = {}) {
4886
4896
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
4887
4897
  const startTime = performance.now();
4888
4898
  assertElectronVersion(config);
4889
- console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.0.2"}`));
4899
+ console.log(pc5.cyan("\n\u26A1 nasti build (electron)") + pc5.dim(` v${"2.2.0"}`));
4890
4900
  console.log(pc5.dim(` root: ${config.root}`));
4891
4901
  console.log(pc5.dim(` mode: ${config.mode}`));
4892
4902
  console.log(pc5.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -5037,7 +5047,7 @@ async function startElectronDev(inlineConfig = {}) {
5037
5047
  const { noSpawn, ...rest } = inlineConfig;
5038
5048
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
5039
5049
  warnElectronVersion(config);
5040
- console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.0.2"}`));
5050
+ console.log(pc10.cyan("\n\u26A1 nasti electron dev") + pc10.dim(` v${"2.2.0"}`));
5041
5051
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
5042
5052
  const server = await createServer2({ ...rest, target: "electron" });
5043
5053
  await server.listen();
@@ -5161,7 +5171,7 @@ async function compileNode(config, entry, opts) {
5161
5171
  transform(code, id) {
5162
5172
  if (!shouldTransform(id)) return null;
5163
5173
  const result = transformCode(id, code, {
5164
- sourcemap: !!config.build.sourcemap,
5174
+ sourcemap: true,
5165
5175
  jsxRuntime: "automatic",
5166
5176
  jsxImportSource: config.framework === "vue" ? "vue" : "react"
5167
5177
  });
@@ -5178,7 +5188,7 @@ async function compileNode(config, entry, opts) {
5178
5188
  await bundle2.write({
5179
5189
  file: opts.outFile,
5180
5190
  format: opts.format === "cjs" ? "cjs" : "esm",
5181
- sourcemap: false,
5191
+ sourcemap: true,
5182
5192
  minify: false,
5183
5193
  // rolldown 已弃用 inlineDynamicImports,改用 codeSplitting:false 表达
5184
5194
  // 同样语义(单 chunk、内联 dynamic import)