Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Apr 8, 2024
1 parent 26ce0d0 commit 7053999
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
3 changes: 2 additions & 1 deletion core/dal-runtime/src/SqlMapLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { TableModel, SqlMap } from '@eggjs/dal-decorator';
import { Logger } from '@eggjs/tegg';
import { BaseSqlMapGenerator } from './BaseSqlMap';
import { TableSqlMap } from './TableSqlMap';
import { LoaderUtil } from '@eggjs/tegg/helper';

export class SqlMapLoader {
private readonly logger: Logger;
private readonly tableModel: TableModel;
private readonly sqlMapPath: string;

constructor(tableModel: TableModel, moduleDir: string, logger: Logger) {
this.sqlMapPath = path.join(moduleDir, 'dal/extension', `${tableModel.clazz.name}Extension.ts`);
this.sqlMapPath = path.join(moduleDir, 'dal/extension', `${tableModel.clazz.name}Extension${LoaderUtil.extension}`);
this.logger = logger;
this.tableModel = tableModel;
}
Expand Down
4 changes: 4 additions & 0 deletions core/loader/src/LoaderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const Module = module.constructor.length > 1
/* istanbul ignore next */
: BuiltinModule;

const EXTENSION = Object.keys((Module as any)._extensions).find(t => t === '.ts') ? '.ts' : '.js';

interface LoaderUtilConfig {
extraFilePattern?: string[];
}
Expand All @@ -18,6 +20,8 @@ export class LoaderUtil {
this.config = config;
}

static extension = EXTENSION;

static filePattern(): string[] {
const extensions = Object.keys((Module as any)._extensions);
const extensionPattern = extensions.map(t => t.substring(1))
Expand Down
11 changes: 2 additions & 9 deletions plugin/dal/lib/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ 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';
import { LoaderUtil } from '@eggjs/tegg/helper';

@MultiInstanceProto({
accessLevel: AccessLevel.PUBLIC,
Expand All @@ -44,7 +37,7 @@ const EXTENSION = Object.keys((Module as any)._extensions).find(t => t === '.ts'
} catch {
return [];
}
const daos = dirents.filter(t => t.endsWith(`DAO${EXTENSION}`));
const daos = dirents.filter(t => t.endsWith(`DAO${LoaderUtil.extension}`));
// eslint-disable-next-line @typescript-eslint/no-var-requires
const daoClazzList = daos.map(t => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down

0 comments on commit 7053999

Please sign in to comment.