Skip to content

Commit

Permalink
refactor: keep plain require() for entities and config
Browse files Browse the repository at this point in the history
Using createRequire() for local files broke the ts-node, ending up with import issues

Related: #685
  • Loading branch information
B4nan committed Aug 9, 2020
1 parent 379b289 commit 668363f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/metadata/MetadataDiscovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ export class MetadataDiscovery {

private initEnumValues(prop: EntityProperty, path: string): void {
path = Utils.normalizePath(this.config.get('baseDir'), path);
const exports = Utils.requireFrom(path, process.cwd());
// eslint-disable-next-line @typescript-eslint/no-var-requires
const exports = require(path);
const target = exports[prop.type] || exports.default;

if (target) {
Expand Down Expand Up @@ -745,7 +746,8 @@ export class MetadataDiscovery {
}

private getEntityClassOrSchema(path: string, name: string) {
const exports = Utils.requireFrom(path, process.cwd());
// eslint-disable-next-line @typescript-eslint/no-var-requires
const exports = require(path);
const target = exports.default || exports[name];
const schema = Object.values(exports).find(item => item instanceof EntitySchema);

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utils/ConfigurationLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class ConfigurationLoader {
path = Utils.normalizePath(path);

if (await pathExists(path)) {
const config = Utils.requireFrom(path, process.cwd());
// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require(path);
return new Configuration({ ...(config.default || config), ...options }, validate);
}
}
Expand Down

0 comments on commit 668363f

Please sign in to comment.