diff --git a/plugin/dal/lib/DataSource.ts b/plugin/dal/lib/DataSource.ts index 76fc7137..9ddbb7fa 100644 --- a/plugin/dal/lib/DataSource.ts +++ b/plugin/dal/lib/DataSource.ts @@ -21,6 +21,14 @@ import { EggObject, EggObjectLifeCycleContext } from '@eggjs/tegg-runtime'; import { TableModelManager } from './TableModelManager'; import { MysqlDataSourceManager } from './MysqlDataSourceManager'; import { SqlMapManager } from './SqlMapManager'; +import BuiltinModule from 'module'; + +// Guard against poorly mocked module constructors. +const Module = module.constructor.length > 1 + ? module.constructor + /* istanbul ignore next */ + : BuiltinModule; +const EXTENSION = Object.keys((Module as any)._extensions).find(t => t === '.ts') ? '.ts' : '.js'; @MultiInstanceProto({ accessLevel: AccessLevel.PUBLIC, @@ -36,8 +44,7 @@ import { SqlMapManager } from './SqlMapManager'; } catch { return []; } - - const daos = dirents.filter(t => t.endsWith('DAO.ts')); + const daos = dirents.filter(t => t.endsWith(`DAO${EXTENSION}`)); // eslint-disable-next-line @typescript-eslint/no-var-requires const daoClazzList = daos.map(t => { // eslint-disable-next-line @typescript-eslint/no-var-requires