@nasti-toolchain/nasti 1.3.7 → 1.3.9

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
@@ -247,15 +247,18 @@ function transformMiddleware(ctx) {
247
247
  }
248
248
  async function transformRequest(url, ctx) {
249
249
  const { config, pluginContainer, moduleGraph } = ctx;
250
+ const cleanReqUrl = url.split("?")[0];
250
251
  const cached = moduleGraph.getModuleByUrl(url);
251
252
  if (cached?.transformResult) {
252
253
  return cached.transformResult;
253
254
  }
255
+ if (cleanReqUrl === "/@react-refresh") {
256
+ return { code: REACT_REFRESH_RUNTIME };
257
+ }
254
258
  const filePath = resolveUrlToFile(url, config.root);
255
259
  if (!filePath || !fs7.existsSync(filePath)) return null;
256
260
  const mod = await moduleGraph.ensureEntryFromUrl(url);
257
261
  moduleGraph.registerModule(mod, filePath);
258
- const cleanReqUrl = url.split("?")[0];
259
262
  if (cleanReqUrl.startsWith("/@modules/")) {
260
263
  const code2 = await bundlePackageAsEsm(filePath);
261
264
  const transformResult2 = { code: code2 };
@@ -268,13 +271,18 @@ async function transformRequest(url, ctx) {
268
271
  code = typeof pluginResult === "string" ? pluginResult : pluginResult.code;
269
272
  }
270
273
  if (shouldTransform(filePath)) {
274
+ const isJsx = /\.[jt]sx$/.test(filePath);
275
+ const useRefresh = isJsx && config.framework !== "vue";
271
276
  const result = transformCode(filePath, code, {
272
277
  sourcemap: true,
273
278
  jsxRuntime: "automatic",
274
279
  jsxImportSource: config.framework === "vue" ? "vue" : "react",
275
- reactRefresh: config.framework !== "vue"
280
+ reactRefresh: useRefresh
276
281
  });
277
282
  code = result.code;
283
+ if (useRefresh) {
284
+ code = REACT_REFRESH_PREAMBLE + code + REACT_REFRESH_FOOTER;
285
+ }
278
286
  }
279
287
  const envDefine = ctx.envDefine ?? buildEnvDefine(
280
288
  loadEnv(config.mode, config.root, config.envPrefix),
@@ -421,10 +429,19 @@ function resolveNodeModule(root, moduleName) {
421
429
  if (resolved) return resolved;
422
430
  }
423
431
  if (subpath) {
424
- const direct = path8.join(pkgDir, subpath);
425
- if (fs7.existsSync(direct) && fs7.statSync(direct).isFile()) return direct;
426
- for (const ext of RESOLVE_EXTENSIONS) {
427
- if (fs7.existsSync(direct + ext)) return direct + ext;
432
+ const subDirs = [""];
433
+ for (const field of ["module", "main"]) {
434
+ if (typeof pkg[field] === "string") {
435
+ const dir2 = path8.dirname(pkg[field]);
436
+ if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
437
+ }
438
+ }
439
+ for (const dir2 of subDirs) {
440
+ const direct = path8.join(pkgDir, dir2, subpath);
441
+ if (fs7.existsSync(direct) && fs7.statSync(direct).isFile()) return direct;
442
+ for (const ext of RESOLVE_EXTENSIONS) {
443
+ if (fs7.existsSync(direct + ext)) return direct + ext;
444
+ }
428
445
  }
429
446
  return null;
430
447
  }
@@ -590,13 +607,32 @@ if (!window.__nasti_hot_map) window.__nasti_hot_map = new Map();
590
607
  window.__NASTI_HMR__ = { createHotContext };
591
608
  `;
592
609
  }
593
- var esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
610
+ var REACT_REFRESH_RUNTIME, REACT_REFRESH_PREAMBLE, REACT_REFRESH_FOOTER, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
594
611
  var init_middleware = __esm({
595
612
  "src/server/middleware.ts"() {
596
613
  "use strict";
597
614
  init_transformer();
598
615
  init_html();
599
616
  init_env();
617
+ REACT_REFRESH_RUNTIME = `
618
+ export function createSignatureFunctionForTransform() {
619
+ return function(type, key, forceReset, getCustomHooks) { return type; };
620
+ }
621
+ export function register(type, id) {}
622
+ export default { createSignatureFunctionForTransform, register };
623
+ `;
624
+ REACT_REFRESH_PREAMBLE = `
625
+ import RefreshRuntime from '/@react-refresh';
626
+ if (!window.$RefreshReg$) {
627
+ window.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, import.meta.url + ' ' + id);
628
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
629
+ }
630
+ `;
631
+ REACT_REFRESH_FOOTER = `
632
+ if (import.meta.hot) {
633
+ import.meta.hot.accept();
634
+ }
635
+ `;
600
636
  esmBundleCache = /* @__PURE__ */ new Map();
601
637
  VALID_IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
602
638
  RESOLVE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".json", ".vue"];
@@ -1086,7 +1122,7 @@ import pc from "picocolors";
1086
1122
  async function build(inlineConfig = {}) {
1087
1123
  const config = await resolveConfig(inlineConfig, "build");
1088
1124
  const startTime = performance.now();
1089
- console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.3.7"}`));
1125
+ console.log(pc.cyan("\n\u{1F528} nasti build") + pc.dim(` v${"1.3.9"}`));
1090
1126
  console.log(pc.dim(` root: ${config.root}`));
1091
1127
  console.log(pc.dim(` mode: ${config.mode}`));
1092
1128
  const outDir = path7.resolve(config.root, config.build.outDir);
@@ -1492,7 +1528,7 @@ async function createServer(inlineConfig = {}) {
1492
1528
  const localUrl = `http://localhost:${actualPort}`;
1493
1529
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1494
1530
  console.log();
1495
- console.log(pc2.cyan(" nasti dev server") + pc2.dim(` v${"1.3.7"}`));
1531
+ console.log(pc2.cyan(" nasti dev server") + pc2.dim(` v${"1.3.9"}`));
1496
1532
  console.log();
1497
1533
  console.log(` ${pc2.green(">")} Local: ${pc2.cyan(localUrl)}`);
1498
1534
  if (networkUrl) {