@nasti-toolchain/nasti 1.3.7 → 1.3.8

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
@@ -717,15 +717,18 @@ function transformMiddleware(ctx) {
717
717
  }
718
718
  async function transformRequest(url, ctx) {
719
719
  const { config, pluginContainer, moduleGraph } = ctx;
720
+ const cleanReqUrl = url.split("?")[0];
720
721
  const cached = moduleGraph.getModuleByUrl(url);
721
722
  if (cached?.transformResult) {
722
723
  return cached.transformResult;
723
724
  }
725
+ if (cleanReqUrl === "/@react-refresh") {
726
+ return { code: REACT_REFRESH_RUNTIME };
727
+ }
724
728
  const filePath = resolveUrlToFile(url, config.root);
725
729
  if (!filePath || !import_node_fs4.default.existsSync(filePath)) return null;
726
730
  const mod = await moduleGraph.ensureEntryFromUrl(url);
727
731
  moduleGraph.registerModule(mod, filePath);
728
- const cleanReqUrl = url.split("?")[0];
729
732
  if (cleanReqUrl.startsWith("/@modules/")) {
730
733
  const code2 = await bundlePackageAsEsm(filePath);
731
734
  const transformResult2 = { code: code2 };
@@ -738,13 +741,18 @@ async function transformRequest(url, ctx) {
738
741
  code = typeof pluginResult === "string" ? pluginResult : pluginResult.code;
739
742
  }
740
743
  if (shouldTransform(filePath)) {
744
+ const isJsx = /\.[jt]sx$/.test(filePath);
745
+ const useRefresh = isJsx && config.framework !== "vue";
741
746
  const result = transformCode(filePath, code, {
742
747
  sourcemap: true,
743
748
  jsxRuntime: "automatic",
744
749
  jsxImportSource: config.framework === "vue" ? "vue" : "react",
745
- reactRefresh: config.framework !== "vue"
750
+ reactRefresh: useRefresh
746
751
  });
747
752
  code = result.code;
753
+ if (useRefresh) {
754
+ code = REACT_REFRESH_PREAMBLE + code + REACT_REFRESH_FOOTER;
755
+ }
748
756
  }
749
757
  const envDefine = ctx.envDefine ?? buildEnvDefine(
750
758
  loadEnv(config.mode, config.root, config.envPrefix),
@@ -1060,7 +1068,7 @@ if (!window.__nasti_hot_map) window.__nasti_hot_map = new Map();
1060
1068
  window.__NASTI_HMR__ = { createHotContext };
1061
1069
  `;
1062
1070
  }
1063
- var import_node_path4, import_node_fs4, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
1071
+ var import_node_path4, import_node_fs4, REACT_REFRESH_RUNTIME, REACT_REFRESH_PREAMBLE, REACT_REFRESH_FOOTER, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
1064
1072
  var init_middleware = __esm({
1065
1073
  "src/server/middleware.ts"() {
1066
1074
  "use strict";
@@ -1069,6 +1077,25 @@ var init_middleware = __esm({
1069
1077
  init_transformer();
1070
1078
  init_html();
1071
1079
  init_env();
1080
+ REACT_REFRESH_RUNTIME = `
1081
+ export function createSignatureFunctionForTransform() {
1082
+ return function(type, key, forceReset, getCustomHooks) { return type; };
1083
+ }
1084
+ export function register(type, id) {}
1085
+ export default { createSignatureFunctionForTransform, register };
1086
+ `;
1087
+ REACT_REFRESH_PREAMBLE = `
1088
+ import RefreshRuntime from '/@react-refresh';
1089
+ if (!window.$RefreshReg$) {
1090
+ window.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, import.meta.url + ' ' + id);
1091
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
1092
+ }
1093
+ `;
1094
+ REACT_REFRESH_FOOTER = `
1095
+ if (import.meta.hot) {
1096
+ import.meta.hot.accept();
1097
+ }
1098
+ `;
1072
1099
  esmBundleCache = /* @__PURE__ */ new Map();
1073
1100
  VALID_IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
1074
1101
  RESOLVE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".json", ".vue"];
@@ -1409,7 +1436,7 @@ async function createServer(inlineConfig = {}) {
1409
1436
  const localUrl = `http://localhost:${actualPort}`;
1410
1437
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1411
1438
  console.log();
1412
- console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.3.7"}`));
1439
+ console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.3.8"}`));
1413
1440
  console.log();
1414
1441
  console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
1415
1442
  if (networkUrl) {
@@ -1487,7 +1514,7 @@ __export(build_exports, {
1487
1514
  async function build(inlineConfig = {}) {
1488
1515
  const config = await resolveConfig(inlineConfig, "build");
1489
1516
  const startTime = performance.now();
1490
- console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.3.7"}`));
1517
+ console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.3.8"}`));
1491
1518
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
1492
1519
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
1493
1520
  const outDir = import_node_path10.default.resolve(config.root, config.build.outDir);
@@ -1712,6 +1739,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
1712
1739
  }
1713
1740
  });
1714
1741
  cli.help();
1715
- cli.version("1.3.7");
1742
+ cli.version("1.3.8");
1716
1743
  cli.parse();
1717
1744
  //# sourceMappingURL=cli.cjs.map