@nasti-toolchain/nasti 1.3.6 → 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/index.cjs CHANGED
@@ -269,15 +269,18 @@ function transformMiddleware(ctx) {
269
269
  }
270
270
  async function transformRequest(url, ctx) {
271
271
  const { config, pluginContainer, moduleGraph } = ctx;
272
+ const cleanReqUrl = url.split("?")[0];
272
273
  const cached = moduleGraph.getModuleByUrl(url);
273
274
  if (cached?.transformResult) {
274
275
  return cached.transformResult;
275
276
  }
277
+ if (cleanReqUrl === "/@react-refresh") {
278
+ return { code: REACT_REFRESH_RUNTIME };
279
+ }
276
280
  const filePath = resolveUrlToFile(url, config.root);
277
281
  if (!filePath || !import_node_fs7.default.existsSync(filePath)) return null;
278
282
  const mod = await moduleGraph.ensureEntryFromUrl(url);
279
283
  moduleGraph.registerModule(mod, filePath);
280
- const cleanReqUrl = url.split("?")[0];
281
284
  if (cleanReqUrl.startsWith("/@modules/")) {
282
285
  const code2 = await bundlePackageAsEsm(filePath);
283
286
  const transformResult2 = { code: code2 };
@@ -290,13 +293,18 @@ async function transformRequest(url, ctx) {
290
293
  code = typeof pluginResult === "string" ? pluginResult : pluginResult.code;
291
294
  }
292
295
  if (shouldTransform(filePath)) {
296
+ const isJsx = /\.[jt]sx$/.test(filePath);
297
+ const useRefresh = isJsx && config.framework !== "vue";
293
298
  const result = transformCode(filePath, code, {
294
299
  sourcemap: true,
295
300
  jsxRuntime: "automatic",
296
301
  jsxImportSource: config.framework === "vue" ? "vue" : "react",
297
- reactRefresh: config.framework !== "vue"
302
+ reactRefresh: useRefresh
298
303
  });
299
304
  code = result.code;
305
+ if (useRefresh) {
306
+ code = REACT_REFRESH_PREAMBLE + code + REACT_REFRESH_FOOTER;
307
+ }
300
308
  }
301
309
  const envDefine = ctx.envDefine ?? buildEnvDefine(
302
310
  loadEnv(config.mode, config.root, config.envPrefix),
@@ -456,6 +464,8 @@ function resolveNodeModule(root, moduleName) {
456
464
  if (import_node_fs7.default.existsSync(entry)) return entry;
457
465
  }
458
466
  }
467
+ const indexFallback = import_node_path8.default.join(pkgDir, "index.js");
468
+ if (import_node_fs7.default.existsSync(indexFallback)) return indexFallback;
459
469
  return null;
460
470
  }
461
471
  function resolvePackageExports(exports2, key, pkgDir) {
@@ -610,7 +620,7 @@ if (!window.__nasti_hot_map) window.__nasti_hot_map = new Map();
610
620
  window.__NASTI_HMR__ = { createHotContext };
611
621
  `;
612
622
  }
613
- var import_node_path8, import_node_fs7, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
623
+ var import_node_path8, import_node_fs7, REACT_REFRESH_RUNTIME, REACT_REFRESH_PREAMBLE, REACT_REFRESH_FOOTER, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
614
624
  var init_middleware = __esm({
615
625
  "src/server/middleware.ts"() {
616
626
  "use strict";
@@ -619,6 +629,25 @@ var init_middleware = __esm({
619
629
  init_transformer();
620
630
  init_html();
621
631
  init_env();
632
+ REACT_REFRESH_RUNTIME = `
633
+ export function createSignatureFunctionForTransform() {
634
+ return function(type, key, forceReset, getCustomHooks) { return type; };
635
+ }
636
+ export function register(type, id) {}
637
+ export default { createSignatureFunctionForTransform, register };
638
+ `;
639
+ REACT_REFRESH_PREAMBLE = `
640
+ import RefreshRuntime from '/@react-refresh';
641
+ if (!window.$RefreshReg$) {
642
+ window.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, import.meta.url + ' ' + id);
643
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
644
+ }
645
+ `;
646
+ REACT_REFRESH_FOOTER = `
647
+ if (import.meta.hot) {
648
+ import.meta.hot.accept();
649
+ }
650
+ `;
622
651
  esmBundleCache = /* @__PURE__ */ new Map();
623
652
  VALID_IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
624
653
  RESOLVE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".json", ".vue"];
@@ -1118,7 +1147,7 @@ var import_picocolors = __toESM(require("picocolors"), 1);
1118
1147
  async function build(inlineConfig = {}) {
1119
1148
  const config = await resolveConfig(inlineConfig, "build");
1120
1149
  const startTime = performance.now();
1121
- console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.3.6"}`));
1150
+ console.log(import_picocolors.default.cyan("\n\u{1F528} nasti build") + import_picocolors.default.dim(` v${"1.3.8"}`));
1122
1151
  console.log(import_picocolors.default.dim(` root: ${config.root}`));
1123
1152
  console.log(import_picocolors.default.dim(` mode: ${config.mode}`));
1124
1153
  const outDir = import_node_path7.default.resolve(config.root, config.build.outDir);
@@ -1524,7 +1553,7 @@ async function createServer(inlineConfig = {}) {
1524
1553
  const localUrl = `http://localhost:${actualPort}`;
1525
1554
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1526
1555
  console.log();
1527
- console.log(import_picocolors2.default.cyan(" nasti dev server") + import_picocolors2.default.dim(` v${"1.3.6"}`));
1556
+ console.log(import_picocolors2.default.cyan(" nasti dev server") + import_picocolors2.default.dim(` v${"1.3.8"}`));
1528
1557
  console.log();
1529
1558
  console.log(` ${import_picocolors2.default.green(">")} Local: ${import_picocolors2.default.cyan(localUrl)}`);
1530
1559
  if (networkUrl) {