@dudousxd/nestjs-codegen 0.27.0 → 0.27.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/index.cjs CHANGED
@@ -740,12 +740,18 @@ function findTypeInFile(name, file) {
740
740
  function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
741
741
  if (moduleSpecifier.startsWith(".")) {
742
742
  const dir = (0, import_node_path4.dirname)(sourceFile.getFilePath());
743
- const noExt = moduleSpecifier.replace(/\.(js|ts)$/, "");
744
- return [
745
- (0, import_node_path4.resolve)(dir, `${noExt}.ts`),
743
+ const ext = /\.(c|m)?(j|t)sx?$/.exec(moduleSpecifier)?.[0];
744
+ const base = ext ? moduleSpecifier.slice(0, -ext.length) : moduleSpecifier;
745
+ const flavour = ext?.startsWith(".c") ? "c" : ext?.startsWith(".m") ? "m" : "";
746
+ const candidates = [
747
+ (0, import_node_path4.resolve)(dir, `${base}.${flavour}ts`),
748
+ ...flavour === "" ? [(0, import_node_path4.resolve)(dir, `${base}.tsx`)] : [],
746
749
  (0, import_node_path4.resolve)(dir, `${moduleSpecifier}.ts`),
747
- (0, import_node_path4.resolve)(dir, moduleSpecifier, "index.ts")
750
+ (0, import_node_path4.resolve)(dir, moduleSpecifier, "index.ts"),
751
+ (0, import_node_path4.resolve)(dir, `${base}.d.${flavour}ts`),
752
+ ...ext === void 0 ? [(0, import_node_path4.resolve)(dir, moduleSpecifier, "index.d.ts")] : []
748
753
  ];
754
+ return [...new Set(candidates)];
749
755
  }
750
756
  const ctx = _ctxFor(project);
751
757
  const baseUrl = ctx.pathsBase ?? ctx.projectRoot;
@@ -775,10 +781,11 @@ function resolveModuleSpecifier(moduleSpecifier, sourceFile, project) {
775
781
  }
776
782
  return [];
777
783
  }
778
- function resolveImportedType(name, sourceFile, project) {
784
+ function resolveImportedType(name, sourceFile, project, seen = /* @__PURE__ */ new Set()) {
779
785
  for (const importDecl of sourceFile.getImportDeclarations()) {
780
- const namedImport = importDecl.getNamedImports().find((n) => n.getName() === name);
786
+ const namedImport = importDecl.getNamedImports().find((n) => (n.getAliasNode()?.getText() ?? n.getName()) === name);
781
787
  if (!namedImport) continue;
788
+ const sourceName = namedImport.getName();
782
789
  const moduleSpecifier = importDecl.getModuleSpecifierValue();
783
790
  const candidates = resolveModuleSpecifier(moduleSpecifier, sourceFile, project);
784
791
  for (const candidate of candidates) {
@@ -790,17 +797,17 @@ function resolveImportedType(name, sourceFile, project) {
790
797
  continue;
791
798
  }
792
799
  }
793
- const result = findTypeInFile(name, importedFile);
800
+ const result = findTypeInFile(sourceName, importedFile);
794
801
  if (result) return result;
795
- const viaReExport = resolveReExportedType(name, importedFile, project, /* @__PURE__ */ new Set());
802
+ const viaReExport = resolveReExportedType(sourceName, importedFile, project, /* @__PURE__ */ new Set());
796
803
  if (viaReExport) return viaReExport;
797
804
  }
798
805
  if (candidates.length === 0) {
799
- const viaCompiler = resolveBareSpecifierType(name, importDecl, project);
806
+ const viaCompiler = resolveBareSpecifierType(sourceName, importDecl, project);
800
807
  if (viaCompiler) return viaCompiler;
801
808
  }
802
809
  }
803
- return resolveReExportedType(name, sourceFile, project, /* @__PURE__ */ new Set());
810
+ return resolveReExportedType(name, sourceFile, project, seen);
804
811
  }
805
812
  function resolveBareSpecifierType(name, importDecl, project) {
806
813
  let target;
@@ -815,9 +822,9 @@ function resolveBareSpecifierType(name, importDecl, project) {
815
822
  return resolveReExportedType(name, target, project, /* @__PURE__ */ new Set());
816
823
  }
817
824
  function resolveReExportedType(name, file, project, seen) {
818
- const filePath = file.getFilePath();
819
- if (seen.has(filePath)) return null;
820
- seen.add(filePath);
825
+ const visit = `${file.getFilePath()}#${name}`;
826
+ if (seen.has(visit)) return null;
827
+ seen.add(visit);
821
828
  for (const exportDecl of file.getExportDeclarations()) {
822
829
  const moduleSpecifier = exportDecl.getModuleSpecifierValue();
823
830
  const namedExports = exportDecl.getNamedExports();
@@ -839,7 +846,7 @@ function resolveReExportedType(name, file, project, seen) {
839
846
  const sourceName = namedExports.find((n) => (n.getAliasNode()?.getText() ?? n.getName()) === name)?.getName() ?? name;
840
847
  const local = findTypeInFile(sourceName, file);
841
848
  if (local) return local;
842
- const imported = resolveImportedType(sourceName, file, project);
849
+ const imported = resolveImportedType(sourceName, file, project, seen);
843
850
  if (imported) return imported;
844
851
  }
845
852
  return null;
@@ -6138,7 +6145,7 @@ function createChainModuleRenderer(opts) {
6138
6145
  }
6139
6146
 
6140
6147
  // src/index.ts
6141
- var VERSION = "0.27.0";
6148
+ var VERSION = "0.27.2";
6142
6149
  // Annotate the CommonJS export names for ESM import in node:
6143
6150
  0 && (module.exports = {
6144
6151
  CodegenError,