Skip to content

Commit

Permalink
fix: framework find and sort (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Mar 27, 2021
1 parent 0b56648 commit 2aac414
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/mock/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,19 @@ const bootstrapAppSet = (global['MIDWAY_BOOTSTRAP_APP_SET'] = new Set<{
}>());

function getIncludeFramework(dependencies): string {
const values: string[] = Object.values(MidwayFrameworkType);
for (const name of Object.keys(dependencies)) {
if (values.includes(name)) {
return name;
const currentFramework = [
'@midwayjs/web',
'@midwayjs/koa',
'@midwayjs/express',
'@midwayjs/serverless-app',
'@midwayjs/grpc',
'@midwayjs/rabbitmq',
'@midwayjs/socketio',
'@midwayjs/faas',
];
for (const frameworkName of currentFramework) {
if (dependencies[frameworkName]) {
return frameworkName;
}
}
}
Expand Down Expand Up @@ -139,8 +148,10 @@ export async function create<
} else {
// find default framework from pkg
const pkg = require(join(appDir, 'package.json'));
if (pkg.dependencies) {
customFrameworkName = getIncludeFramework(pkg.dependencies);
if (pkg.dependencies || pkg.devDependencies) {
customFrameworkName = getIncludeFramework(
Object.assign({}, pkg.dependencies || {}, pkg.devDependencies || {})
);
}
DefaultFramework = require(customFrameworkName as string).Framework;
}
Expand Down

0 comments on commit 2aac414

Please sign in to comment.