@nasti-toolchain/nasti 1.3.0 → 1.3.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
@@ -769,22 +769,113 @@ function rewriteImports(code, _config) {
769
769
  }
770
770
  );
771
771
  }
772
+ function resolveNodeModule(root, moduleName) {
773
+ let pkgName;
774
+ let subpath;
775
+ if (moduleName.startsWith("@")) {
776
+ const parts = moduleName.split("/");
777
+ pkgName = parts.slice(0, 2).join("/");
778
+ subpath = parts.slice(2).join("/");
779
+ } else {
780
+ const slash = moduleName.indexOf("/");
781
+ pkgName = slash === -1 ? moduleName : moduleName.slice(0, slash);
782
+ subpath = slash === -1 ? "" : moduleName.slice(slash + 1);
783
+ }
784
+ let pkgDir = null;
785
+ let dir = root;
786
+ for (; ; ) {
787
+ const candidate = import_node_path4.default.join(dir, "node_modules", pkgName);
788
+ if (import_node_fs4.default.existsSync(candidate)) {
789
+ pkgDir = candidate;
790
+ break;
791
+ }
792
+ const parent = import_node_path4.default.dirname(dir);
793
+ if (parent === dir) break;
794
+ dir = parent;
795
+ }
796
+ if (!pkgDir) return null;
797
+ const pkgJsonPath = import_node_path4.default.join(pkgDir, "package.json");
798
+ if (!import_node_fs4.default.existsSync(pkgJsonPath)) return null;
799
+ let pkg;
800
+ try {
801
+ pkg = JSON.parse(import_node_fs4.default.readFileSync(pkgJsonPath, "utf-8"));
802
+ } catch {
803
+ return null;
804
+ }
805
+ if (pkg.exports) {
806
+ const exportKey = subpath ? `./${subpath}` : ".";
807
+ const resolved = resolvePackageExports(pkg.exports, exportKey, pkgDir);
808
+ if (resolved) return resolved;
809
+ }
810
+ if (subpath) {
811
+ const direct = import_node_path4.default.join(pkgDir, subpath);
812
+ if (import_node_fs4.default.existsSync(direct) && import_node_fs4.default.statSync(direct).isFile()) return direct;
813
+ for (const ext of RESOLVE_EXTENSIONS) {
814
+ if (import_node_fs4.default.existsSync(direct + ext)) return direct + ext;
815
+ }
816
+ return null;
817
+ }
818
+ for (const field of ["module", "jsnext:main", "jsnext", "main"]) {
819
+ if (typeof pkg[field] === "string") {
820
+ const entry = import_node_path4.default.join(pkgDir, pkg[field]);
821
+ if (import_node_fs4.default.existsSync(entry)) return entry;
822
+ }
823
+ }
824
+ return null;
825
+ }
826
+ function resolvePackageExports(exports2, key, pkgDir) {
827
+ if (typeof exports2 === "string") {
828
+ return key === "." ? import_node_path4.default.join(pkgDir, exports2) : null;
829
+ }
830
+ const entry = exports2[key];
831
+ if (entry === void 0) return null;
832
+ return resolveExportValue(entry, pkgDir);
833
+ }
834
+ function resolveExportValue(value, pkgDir) {
835
+ if (typeof value === "string") return import_node_path4.default.join(pkgDir, value);
836
+ if (Array.isArray(value)) {
837
+ for (const item of value) {
838
+ const r = resolveExportValue(item, pkgDir);
839
+ if (r) return r;
840
+ }
841
+ return null;
842
+ }
843
+ if (value && typeof value === "object") {
844
+ for (const cond of ESM_CONDITIONS) {
845
+ if (cond in value) {
846
+ const r = resolveExportValue(value[cond], pkgDir);
847
+ if (r) return r;
848
+ }
849
+ }
850
+ }
851
+ return null;
852
+ }
772
853
  function resolveUrlToFile(url, root) {
773
854
  const cleanUrl = url.split("?")[0];
774
855
  if (cleanUrl.startsWith("/@modules/")) {
775
856
  const moduleName = cleanUrl.slice("/@modules/".length);
776
- try {
777
- const req = (0, import_node_module.createRequire)(import_node_path4.default.resolve(root, "package.json"));
778
- return req.resolve(moduleName);
779
- } catch {
780
- return null;
781
- }
857
+ return resolveNodeModule(root, moduleName);
858
+ }
859
+ const filePath = import_node_path4.default.resolve(root, cleanUrl.replace(/^\//, ""));
860
+ if (import_node_fs4.default.existsSync(filePath) && import_node_fs4.default.statSync(filePath).isFile()) {
861
+ return filePath;
862
+ }
863
+ for (const ext of RESOLVE_EXTENSIONS) {
864
+ const withExt = filePath + ext;
865
+ if (import_node_fs4.default.existsSync(withExt)) return withExt;
782
866
  }
783
- return import_node_path4.default.resolve(root, cleanUrl.replace(/^\//, ""));
867
+ for (const ext of RESOLVE_EXTENSIONS) {
868
+ const indexFile = import_node_path4.default.join(filePath, "index" + ext);
869
+ if (import_node_fs4.default.existsSync(indexFile)) return indexFile;
870
+ }
871
+ return null;
784
872
  }
785
873
  function isModuleRequest(url) {
786
874
  const cleanUrl = url.split("?")[0];
787
- return /\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl) || cleanUrl.startsWith("/@modules/");
875
+ if (/\.(ts|tsx|jsx|js|mjs|vue|css|json)$/.test(cleanUrl)) return true;
876
+ if (cleanUrl.startsWith("/@modules/")) return true;
877
+ if (!import_node_path4.default.extname(cleanUrl)) return true;
878
+ return false;
788
879
  }
789
880
  function getHmrClientCode() {
790
881
  return `
@@ -884,16 +975,17 @@ if (!window.__nasti_hot_map) window.__nasti_hot_map = new Map();
884
975
  window.__NASTI_HMR__ = { createHotContext };
885
976
  `;
886
977
  }
887
- var import_node_path4, import_node_fs4, import_node_module;
978
+ var import_node_path4, import_node_fs4, RESOLVE_EXTENSIONS, ESM_CONDITIONS;
888
979
  var init_middleware = __esm({
889
980
  "src/server/middleware.ts"() {
890
981
  "use strict";
891
982
  import_node_path4 = __toESM(require("path"), 1);
892
983
  import_node_fs4 = __toESM(require("fs"), 1);
893
- import_node_module = require("module");
894
984
  init_transformer();
895
985
  init_html();
896
986
  init_env();
987
+ RESOLVE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".json", ".vue"];
988
+ ESM_CONDITIONS = ["import", "browser", "module", "default"];
897
989
  }
898
990
  });
899
991
 
@@ -957,7 +1049,7 @@ var init_hmr = __esm({
957
1049
  // src/plugins/resolve.ts
958
1050
  function resolvePlugin(config) {
959
1051
  const { alias, extensions } = config.resolve;
960
- const require2 = (0, import_node_module2.createRequire)(import_node_path6.default.resolve(config.root, "package.json"));
1052
+ const require2 = (0, import_node_module.createRequire)(import_node_path6.default.resolve(config.root, "package.json"));
961
1053
  return {
962
1054
  name: "nasti:resolve",
963
1055
  enforce: "pre",
@@ -1023,13 +1115,13 @@ function tryResolveFile(file, extensions) {
1023
1115
  }
1024
1116
  return null;
1025
1117
  }
1026
- var import_node_path6, import_node_fs6, import_node_module2;
1118
+ var import_node_path6, import_node_fs6, import_node_module;
1027
1119
  var init_resolve = __esm({
1028
1120
  "src/plugins/resolve.ts"() {
1029
1121
  "use strict";
1030
1122
  import_node_path6 = __toESM(require("path"), 1);
1031
1123
  import_node_fs6 = __toESM(require("fs"), 1);
1032
- import_node_module2 = require("module");
1124
+ import_node_module = require("module");
1033
1125
  }
1034
1126
  });
1035
1127
 
@@ -1230,7 +1322,7 @@ async function createServer(inlineConfig = {}) {
1230
1322
  const localUrl = `http://localhost:${actualPort}`;
1231
1323
  const networkUrl = host === "0.0.0.0" ? `http://${getNetworkAddress()}:${actualPort}` : null;
1232
1324
  console.log();
1233
- console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.3.0"}`));
1325
+ console.log(import_picocolors.default.cyan(" nasti dev server") + import_picocolors.default.dim(` v${"1.3.2"}`));
1234
1326
  console.log();
1235
1327
  console.log(` ${import_picocolors.default.green(">")} Local: ${import_picocolors.default.cyan(localUrl)}`);
1236
1328
  if (networkUrl) {
@@ -1308,7 +1400,7 @@ __export(build_exports, {
1308
1400
  async function build(inlineConfig = {}) {
1309
1401
  const config = await resolveConfig(inlineConfig, "build");
1310
1402
  const startTime = performance.now();
1311
- console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.3.0"}`));
1403
+ console.log(import_picocolors2.default.cyan("\n\u{1F528} nasti build") + import_picocolors2.default.dim(` v${"1.3.2"}`));
1312
1404
  console.log(import_picocolors2.default.dim(` root: ${config.root}`));
1313
1405
  console.log(import_picocolors2.default.dim(` mode: ${config.mode}`));
1314
1406
  const outDir = import_node_path10.default.resolve(config.root, config.build.outDir);
@@ -1533,6 +1625,6 @@ cli.command("preview [root]", "Preview production build").option("--port <port>"
1533
1625
  }
1534
1626
  });
1535
1627
  cli.help();
1536
- cli.version("1.3.0");
1628
+ cli.version("1.3.2");
1537
1629
  cli.parse();
1538
1630
  //# sourceMappingURL=cli.cjs.map