@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/cli.js CHANGED
@@ -695,15 +695,18 @@ function transformMiddleware(ctx) {
695
695
  }
696
696
  async function transformRequest(url, ctx) {
697
697
  const { config, pluginContainer, moduleGraph } = ctx;
698
+ const cleanReqUrl = url.split("?")[0];
698
699
  const cached = moduleGraph.getModuleByUrl(url);
699
700
  if (cached?.transformResult) {
700
701
  return cached.transformResult;
701
702
  }
703
+ if (cleanReqUrl === "/@react-refresh") {
704
+ return { code: REACT_REFRESH_RUNTIME };
705
+ }
702
706
  const filePath = resolveUrlToFile(url, config.root);
703
707
  if (!filePath || !fs4.existsSync(filePath)) return null;
704
708
  const mod = await moduleGraph.ensureEntryFromUrl(url);
705
709
  moduleGraph.registerModule(mod, filePath);
706
- const cleanReqUrl = url.split("?")[0];
707
710
  if (cleanReqUrl.startsWith("/@modules/")) {
708
711
  const code2 = await bundlePackageAsEsm(filePath);
709
712
  const transformResult2 = { code: code2 };
@@ -716,13 +719,18 @@ async function transformRequest(url, ctx) {
716
719
  code = typeof pluginResult === "string" ? pluginResult : pluginResult.code;
717
720
  }
718
721
  if (shouldTransform(filePath)) {
722
+ const isJsx = /\.[jt]sx$/.test(filePath);
723
+ const useRefresh = isJsx && config.framework !== "vue";
719
724
  const result = transformCode(filePath, code, {
720
725
  sourcemap: true,
721
726
  jsxRuntime: "automatic",
722
727
  jsxImportSource: config.framework === "vue" ? "vue" : "react",
723
- reactRefresh: config.framework !== "vue"
728
+ reactRefresh: useRefresh
724
729
  });
725
730
  code = result.code;
731
+ if (useRefresh) {
732
+ code = REACT_REFRESH_PREAMBLE + code + REACT_REFRESH_FOOTER;
733
+ }
726
734
  }
727
735
  const envDefine = ctx.envDefine ?? buildEnvDefine(
728
736
  loadEnv(config.mode, config.root, config.envPrefix),
@@ -869,10 +877,19 @@ function resolveNodeModule(root, moduleName) {
869
877
  if (resolved) return resolved;
870
878
  }
871
879
  if (subpath) {
872
- const direct = path4.join(pkgDir, subpath);
873
- if (fs4.existsSync(direct) && fs4.statSync(direct).isFile()) return direct;
874
- for (const ext of RESOLVE_EXTENSIONS) {
875
- if (fs4.existsSync(direct + ext)) return direct + ext;
880
+ const subDirs = [""];
881
+ for (const field of ["module", "main"]) {
882
+ if (typeof pkg[field] === "string") {
883
+ const dir2 = path4.dirname(pkg[field]);
884
+ if (dir2 && dir2 !== "." && !subDirs.includes(dir2)) subDirs.push(dir2);
885
+ }
886
+ }
887
+ for (const dir2 of subDirs) {
888
+ const direct = path4.join(pkgDir, dir2, subpath);
889
+ if (fs4.existsSync(direct) && fs4.statSync(direct).isFile()) return direct;
890
+ for (const ext of RESOLVE_EXTENSIONS) {
891
+ if (fs4.existsSync(direct + ext)) return direct + ext;
892
+ }
876
893
  }
877
894
  return null;
878
895
  }
@@ -1038,13 +1055,32 @@ if (!window.__nasti_hot_map) window.__nasti_hot_map = new Map();
1038
1055
  window.__NASTI_HMR__ = { createHotContext };
1039
1056
  `;
1040
1057
  }
1041
- var esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
1058
+ var REACT_REFRESH_RUNTIME, REACT_REFRESH_PREAMBLE, REACT_REFRESH_FOOTER, esmBundleCache, VALID_IDENT, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
1042
1059
  var init_middleware = __esm({
1043
1060
  "src/server/middleware.ts"() {
1044
1061
  "use strict";
1045
1062
  init_transformer();
1046
1063
  init_html();
1047
1064
  init_env();
1065
+ REACT_REFRESH_RUNTIME = `
1066
+ export function createSignatureFunctionForTransform() {
1067
+ return function(type, key, forceReset, getCustomHooks) { return type; };
1068
+ }
1069
+ export function register(type, id) {}
1070
+ export default { createSignatureFunctionForTransform, register };
1071
+ `;
1072
+ REACT_REFRESH_PREAMBLE = `
1073
+ import RefreshRuntime from '/@react-refresh';
1074
+ if (!window.$RefreshReg$) {
1075
+ window.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, import.meta.url + ' ' + id);
1076
+ window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
1077
+ }
1078
+ `;
1079
+ REACT_REFRESH_FOOTER = `
1080
+ if (import.meta.hot) {
1081
+ import.meta.hot.accept();
1082
+ }
1083
+ `;
1048
1084
  esmBundleCache = /* @__PURE__ */ new Map();
1049
1085
  VALID_IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
1050
1086
  RESOLVE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".json", ".vue"];
@@ -1389,7 +1425,7 @@ async function createServer(inlineConfig = {}) {
1389
1425
  const localUrl = `http://localhost:${actualPort}`;
1390
1426
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1391
1427
  console.log();
1392
- console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.3.7"}`));
1428
+ console.log(pc.cyan(" nasti dev server") + pc.dim(` v${"1.3.9"}`));
1393
1429
  console.log();
1394
1430
  console.log(` ${pc.green(">")} Local: ${pc.cyan(localUrl)}`);
1395
1431
  if (networkUrl) {
@@ -1463,7 +1499,7 @@ import pc2 from "picocolors";
1463
1499
  async function build(inlineConfig = {}) {
1464
1500
  const config = await resolveConfig(inlineConfig, "build");
1465
1501
  const startTime = performance.now();
1466
- console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.3.7"}`));
1502
+ console.log(pc2.cyan("\n\u{1F528} nasti build") + pc2.dim(` v${"1.3.9"}`));
1467
1503
  console.log(pc2.dim(` root: ${config.root}`));
1468
1504
  console.log(pc2.dim(` mode: ${config.mode}`));
1469
1505
  const outDir = path10.resolve(config.root, config.build.outDir);
@@ -1683,6 +1719,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
1683
1719
  }
1684
1720
  });
1685
1721
  cli.help();
1686
- cli.version("1.3.7");
1722
+ cli.version("1.3.9");
1687
1723
  cli.parse();
1688
1724
  //# sourceMappingURL=cli.js.map