@nasti-toolchain/nasti 1.6.1 → 1.6.2

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
@@ -966,6 +966,8 @@ async function bundlePackageAsEsm(entryFile) {
966
966
  return esmBundleCache.get(entryFile);
967
967
  }
968
968
  async function doBundlePackage(entryFile) {
969
+ const shim = await tryGenerateSubpathShim(entryFile);
970
+ if (shim != null) return shim;
969
971
  const { rolldown: rolldown4 } = await import("rolldown");
970
972
  const bundle = await rolldown4({
971
973
  input: entryFile,
@@ -995,6 +997,103 @@ async function doBundlePackage(entryFile) {
995
997
  }
996
998
  return code;
997
999
  }
1000
+ async function tryGenerateSubpathShim(entryFile) {
1001
+ const NM = `${import_node_path4.default.sep}node_modules${import_node_path4.default.sep}`;
1002
+ if (!entryFile.includes(NM)) return null;
1003
+ let pkgDir = null;
1004
+ let pkgName = null;
1005
+ let dir = import_node_path4.default.dirname(entryFile);
1006
+ while (true) {
1007
+ const pkgJsonPath = import_node_path4.default.join(dir, "package.json");
1008
+ if (import_node_fs4.default.existsSync(pkgJsonPath)) {
1009
+ try {
1010
+ const pkg = JSON.parse(import_node_fs4.default.readFileSync(pkgJsonPath, "utf-8"));
1011
+ if (typeof pkg?.name === "string" && pkg.name) {
1012
+ pkgDir = dir;
1013
+ pkgName = pkg.name;
1014
+ break;
1015
+ }
1016
+ } catch {
1017
+ }
1018
+ }
1019
+ const parent = import_node_path4.default.dirname(dir);
1020
+ if (parent === dir) return null;
1021
+ dir = parent;
1022
+ if (!dir.includes(NM)) return null;
1023
+ }
1024
+ if (!pkgDir || !pkgName) return null;
1025
+ const entryExt = import_node_path4.default.extname(entryFile);
1026
+ const mainEntry = pickMainEntryByExtension(pkgDir, entryExt);
1027
+ if (!mainEntry) return null;
1028
+ if (import_node_path4.default.resolve(mainEntry) === import_node_path4.default.resolve(entryFile)) return null;
1029
+ let mainNs;
1030
+ let subNs;
1031
+ try {
1032
+ mainNs = await import((0, import_node_url2.pathToFileURL)(mainEntry).href);
1033
+ subNs = await import((0, import_node_url2.pathToFileURL)(entryFile).href);
1034
+ } catch {
1035
+ return null;
1036
+ }
1037
+ if (!mainNs || typeof mainNs !== "object") return null;
1038
+ if (!subNs || typeof subNs !== "object") return null;
1039
+ const subKeys = Object.keys(subNs).filter(
1040
+ (k) => k !== "__esModule" && k !== "default" && VALID_IDENT.test(k)
1041
+ );
1042
+ if (subKeys.length === 0) return null;
1043
+ for (const k of subKeys) {
1044
+ if (!(k in mainNs)) return null;
1045
+ if (mainNs[k] !== subNs[k]) return null;
1046
+ }
1047
+ if ("default" in subNs) {
1048
+ if (!("default" in mainNs)) return null;
1049
+ if (mainNs["default"] !== subNs["default"]) return null;
1050
+ }
1051
+ const lines = [
1052
+ `// Nasti subpath shim \u2192 ${pkgName} (avoid duplicate bundling)`,
1053
+ `import * as __pkg from "/@modules/${pkgName}";`
1054
+ ];
1055
+ for (const k of subKeys) {
1056
+ lines.push(`export const ${k} = __pkg[${JSON.stringify(k)}];`);
1057
+ }
1058
+ if ("default" in subNs) {
1059
+ lines.push(`export default ("default" in __pkg ? __pkg["default"] : __pkg);`);
1060
+ }
1061
+ return lines.join("\n") + "\n";
1062
+ }
1063
+ function pickMainEntryByExtension(pkgDir, preferredExt) {
1064
+ const pkgJsonPath = import_node_path4.default.join(pkgDir, "package.json");
1065
+ let pkg;
1066
+ try {
1067
+ pkg = JSON.parse(import_node_fs4.default.readFileSync(pkgJsonPath, "utf-8"));
1068
+ } catch {
1069
+ return null;
1070
+ }
1071
+ const candidates = [];
1072
+ const collectFromExportObject = (obj) => {
1073
+ if (!obj || typeof obj !== "object") return;
1074
+ for (const cond of ["import", "module", "default", "require", "node"]) {
1075
+ const v = obj[cond];
1076
+ if (typeof v === "string") candidates.push(v);
1077
+ else if (v && typeof v === "object") collectFromExportObject(v);
1078
+ }
1079
+ };
1080
+ const dot = pkg?.exports?.["."];
1081
+ if (typeof dot === "string") candidates.push(dot);
1082
+ else if (dot && typeof dot === "object") collectFromExportObject(dot);
1083
+ if (typeof pkg.module === "string") candidates.push(pkg.module);
1084
+ if (typeof pkg.main === "string") candidates.push(pkg.main);
1085
+ for (const cand of candidates) {
1086
+ if (import_node_path4.default.extname(cand) === preferredExt) {
1087
+ const full = import_node_path4.default.resolve(pkgDir, cand);
1088
+ if (import_node_fs4.default.existsSync(full)) return full;
1089
+ }
1090
+ }
1091
+ for (const cand of candidates) {
1092
+ const full = import_node_path4.default.resolve(pkgDir, cand);
1093
+ if (import_node_fs4.default.existsSync(full)) return full;
1094
+ }
1095
+ return null;
1096
+ }
998
1097
  function rewriteExternalRequires(code) {
999
1098
  const pkgs = /* @__PURE__ */ new Set();
1000
1099
  const re = /__require\(["']([^"']+)["']\)/g;
@@ -1711,7 +1810,7 @@ async function createServer(inlineConfig = {}) {
1711
1810
  const localUrl = `http://localhost:${actualPort}`;
1712
1811
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1713
1812
  console.log();
1714
- console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.1"}`));
1813
+ console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.6.2"}`));
1715
1814
  console.log();
1716
1815
  console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
1717
1816
  if (networkUrl) {
@@ -1838,7 +1937,7 @@ __export(build_exports, {
1838
1937
  async function build(inlineConfig = {}) {
1839
1938
  const config = await resolveConfig(inlineConfig, "build");
1840
1939
  const startTime = performance.now();
1841
- console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.1"}`));
1940
+ console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.6.2"}`));
1842
1941
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
1843
1942
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
1844
1943
  const outDir = import_node_path10.default.resolve(config.root, config.build.outDir);
@@ -1999,7 +2098,7 @@ async function buildElectron(inlineConfig = {}) {
1999
2098
  const config = await resolveConfig({ ...inlineConfig, target: "electron" }, "build");
2000
2099
  const startTime = performance.now();
2001
2100
  assertElectronVersion(config);
2002
- console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.1"}`));
2101
+ console.log(import_picocolors3.default.cyan("\n\u26A1 nasti build (electron)") + import_picocolors3.default.dim(` v${"1.6.2"}`));
2003
2102
  console.log(import_picocolors3.default.dim(` root: ${config.root}`));
2004
2103
  console.log(import_picocolors3.default.dim(` mode: ${config.mode}`));
2005
2104
  console.log(import_picocolors3.default.dim(` target: electron (\u2265 ${config.electron.minVersion})`));
@@ -2151,7 +2250,7 @@ async function startElectronDev(inlineConfig = {}) {
2151
2250
  const { noSpawn, ...rest } = inlineConfig;
2152
2251
  const config = await resolveConfig({ ...rest, target: "electron" }, "serve");
2153
2252
  warnElectronVersion(config);
2154
- console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.1"}`));
2253
+ console.log(import_picocolors4.default.cyan("\n\u26A1 nasti electron dev") + import_picocolors4.default.dim(` v${"1.6.2"}`));
2155
2254
  const { createServer: createServer2 } = await Promise.resolve().then(() => (init_server(), server_exports));
2156
2255
  const server = await createServer2({ ...rest, target: "electron" });
2157
2256
  await server.listen();
@@ -2486,6 +2585,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
2486
2585
  }
2487
2586
  });
2488
2587
  cli.help();
2489
- cli.version("1.6.1");
2588
+ cli.version("1.6.2");
2490
2589
  cli.parse();
2491
2590
  //# sourceMappingURL=cli.cjs.map