Skip to content

Commit

Permalink
fix(reflection): fix source file detection after update to ts-morph v24
Browse files Browse the repository at this point in the history
More info in dsherret/ts-morph#1593

Closes #6297
  • Loading branch information
B4nan committed Dec 21, 2024
1 parent 4e5b18b commit d9716a6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/reflection/src/TsMorphMetadataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,23 @@ export class TsMorphMetadataProvider extends MetadataProvider {
this.initProject();
}

this.sources = [];

// All entity files are first required during the discovery, before we reach here, so it is safe to get the parts from the global
// metadata storage. We know the path thanks the decorators being executed. In case we are running via ts-node, the extension
// will be already `.ts`, so no change needed. `.js` files will get renamed to `.d.ts` files as they will be used as a source for
// metadata storage. We know the path thanks to the decorators being executed. In case we are running via ts-node, the extension
// will be already `.ts`, so no change is needed. `.js` files will get renamed to `.d.ts` files as they will be used as a source for
// the ts-morph reflection.
/* istanbul ignore next */
const paths = Object.values(MetadataStorage.getMetadata()).map(m => m.path.match(/\.[jt]s$/)
? m.path.replace(/\.js$/, '.d.ts')
: `${m.path}.d.ts`); // when entities are bundled, their paths are just their names
this.sources = this.project.addSourceFilesAtPaths(paths);
for (const meta of Utils.values(MetadataStorage.getMetadata())) {
/* istanbul ignore next */
const path = meta.path.match(/\.[jt]s$/)
? meta.path.replace(/\.js$/, '.d.ts')
: `${meta.path}.d.ts`; // when entities are bundled, their paths are just their names
const sourceFile = this.project.addSourceFileAtPathIfExists(path);

if (sourceFile) {
this.sources.push(sourceFile);
}
}
}

}

0 comments on commit d9716a6

Please sign in to comment.