Skip to content

Commit

Permalink
feat: support file returning async functions when loading it
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiMoron committed Dec 11, 2024
1 parent 9ff7f76 commit 8bf0ba5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/loader/egg_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert';
import { debuglog, inspect } from 'node:util';
import { isAsyncFunction, isClass, isGeneratorFunction, isObject } from 'is-type-of';
import is, { isAsyncFunction, isClass, isGeneratorFunction, isObject } from 'is-type-of';
import homedir from 'node-homedir';
import type { Logger } from 'egg-logger';
import { getParamNames, readJSONSync } from 'utility';
Expand Down Expand Up @@ -1421,6 +1421,9 @@ export class EggLoader {
let mod = await this.requireFile(fullpath);
if (typeof mod === 'function' && !isClass(mod)) {
mod = mod(...inject);
if (is.promise(mod)) {
mod = await mod;
}
}
return mod;
}
Expand Down

0 comments on commit 8bf0ba5

Please sign in to comment.