@nasti-toolchain/nasti 1.3.5 → 1.3.7

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/README.md CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  ```bash
32
32
  # 安装
33
- npm install -D nasti-build
33
+ npm install -D @nasti-toolchain/nasti
34
34
 
35
35
  # 启动开发服务器
36
36
  npx nasti dev
package/dist/cli.cjs CHANGED
@@ -786,11 +786,30 @@ async function doBundlePackage(entryFile) {
786
786
  /^(import\s+)(['"])([^'"./][^'"]*)(\2)/gm,
787
787
  (_, prefix, q, spec) => `${prefix}${q}/@modules/${spec}${q}`
788
788
  );
789
+ code = rewriteExternalRequires(code);
789
790
  if (code.includes("__commonJSMin")) {
790
791
  code = await injectCjsNamedExports(code, entryFile);
791
792
  }
792
793
  return code;
793
794
  }
795
+ function rewriteExternalRequires(code) {
796
+ const pkgs = /* @__PURE__ */ new Set();
797
+ const re = /__require\(["']([^"']+)["']\)/g;
798
+ let m;
799
+ while ((m = re.exec(code)) !== null) {
800
+ pkgs.add(m[1]);
801
+ }
802
+ if (pkgs.size === 0) return code;
803
+ let result = code;
804
+ const imports = [];
805
+ for (const pkg of pkgs) {
806
+ const safe = pkg.replace(/[^a-zA-Z0-9_$]/g, "_");
807
+ imports.push(`import __req_${safe} from "/@modules/${pkg}";`);
808
+ result = result.replaceAll(`__require("${pkg}")`, `__req_${safe}`);
809
+ result = result.replaceAll(`__require('${pkg}')`, `__req_${safe}`);
810
+ }
811
+ return imports.join("\n") + "\n" + result;
812
+ }
794
813
  async function injectCjsNamedExports(code, entryFile) {
795
814
  try {
796
815
  const { createRequire: createRequire2 } = await import("module");
@@ -885,6 +904,8 @@ function resolveNodeModule(root, moduleName) {
885
904
  if (import_node_fs4.default.existsSync(entry)) return entry;
886
905
  }
887
906
  }
907
+ const indexFallback = import_node_path4.default.join(pkgDir, "index.js");
908
+ if (import_node_fs4.default.existsSync(indexFallback)) return indexFallback;
888
909
  return null;
889
910
  }
890
911
  function resolvePackageExports(exports2, key, pkgDir) {
@@ -1388,7 +1409,7 @@ async function createServer(inlineConfig = {}) {
1388
1409
  const localUrl = `http://localhost:${actualPort}`;
1389
1410
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1390
1411
  console.log();
1391
- console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.3.5"}`));
1412
+ console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.3.7"}`));
1392
1413
  console.log();
1393
1414
  console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
1394
1415
  if (networkUrl) {
@@ -1466,7 +1487,7 @@ __export(build_exports, {
1466
1487
  async function build(inlineConfig = {}) {
1467
1488
  const config = await resolveConfig(inlineConfig, "build");
1468
1489
  const startTime = performance.now();
1469
- console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.3.5"}`));
1490
+ console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.3.7"}`));
1470
1491
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
1471
1492
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
1472
1493
  const outDir = import_node_path10.default.resolve(config.root, config.build.outDir);
@@ -1691,6 +1712,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
1691
1712
  }
1692
1713
  });
1693
1714
  cli.help();
1694
- cli.version("1.3.5");
1715
+ cli.version("1.3.7");
1695
1716
  cli.parse();
1696
1717
  //# sourceMappingURL=cli.cjs.map