Skip to content

Commit

Permalink
feat(core): improve support for ts-node
Browse files Browse the repository at this point in the history
Previously one could setup ORM either for vanilla node, or for ts-node.
Now it will automatically check whether you used node or ts-node and
choose correct entities directory.

When running via ts-node, entitiesDirs option will be ignored, and
entitiesDirsTs will be used instead.
  • Loading branch information
B4nan committed Mar 20, 2019
1 parent edb6eec commit 220bcaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/metadata/MetadataDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class MetadataDiscovery {

if (this.config.get('entities').length > 0) {
await Promise.all(this.config.get('entities').map(entity => this.discoverEntity(entity)));
} else if (process.argv[0].endsWith('ts-node')) {
await Promise.all(this.config.get('entitiesDirsTs').map(dir => this.discoverDirectory(dir)));
} else {
await Promise.all(this.config.get('entitiesDirs').map(dir => this.discoverDirectory(dir)));
}
Expand Down
6 changes: 5 additions & 1 deletion tests/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export async function initORM() {
hash = '-' + Math.random().toString(36).substring(6);
}

// simulate ts-node to raise coverage
process.argv[0] = process.argv[0].replace(/node$/, 'ts-node');

return MikroORM.init({
entitiesDirs: ['entities'],
entitiesDirs: ['dist/entities'], // will be ignored as we simulate ts-node
entitiesDirsTs: ['entities'],
dbName: `mikro-orm-test${hash}`,
baseDir: BASE_DIR,
debug: true,
Expand Down

0 comments on commit 220bcaa

Please sign in to comment.