Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix dao extension in prod #206

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions plugin/dal/lib/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { EggObject, EggObjectLifeCycleContext } from '@eggjs/tegg-runtime';
import { TableModelManager } from './TableModelManager';
import { MysqlDataSourceManager } from './MysqlDataSourceManager';
import { SqlMapManager } from './SqlMapManager';
import { LoaderUtil } from '@eggjs/tegg/helper';

@MultiInstanceProto({
accessLevel: AccessLevel.PUBLIC,
Expand All @@ -36,8 +37,7 @@ import { SqlMapManager } from './SqlMapManager';
} catch {
return [];
}

const daos = dirents.filter(t => t.endsWith('DAO.ts'));
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
Loading