Skip to content

Commit 4b9276a

Browse files
committed
add SingleModeApplication type
1 parent 193319d commit 4b9276a

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
*/
44

55
import { BaseContextClass } from './lib/core/base_context_class.js';
6-
import { startEgg } from './lib/start.js';
6+
import {
7+
startEgg,
8+
SingleModeApplication,
9+
SingleModeAgent,
10+
} from './lib/start.js';
711
import Helper from './app/extend/helper.js';
812

913
// export extends
@@ -45,6 +49,8 @@ export * from '@eggjs/cluster';
4549
*/
4650
export {
4751
startEgg as start,
52+
SingleModeApplication,
53+
SingleModeAgent,
4854
};
4955

5056
/**

src/lib/start.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { readJSON } from 'utility';
33
import { importModule } from '@eggjs/utils';
44
import { Agent } from './agent.js';
55
import { Application } from './application.js';
6+
import { EggPlugin } from './types.js';
67

78
export interface StartEggOptions {
89
/** specify framework that can be absolute path or npm package */
@@ -13,6 +14,15 @@ export interface StartEggOptions {
1314
ignoreWarning?: boolean;
1415
mode?: 'single';
1516
env?: string;
17+
plugins?: EggPlugin;
18+
}
19+
20+
export interface SingleModeApplication extends Application {
21+
agent: SingleModeAgent;
22+
}
23+
24+
export interface SingleModeAgent extends Agent {
25+
app: SingleModeApplication;
1626
}
1727

1828
/**
@@ -41,11 +51,11 @@ export async function startEgg(options: StartEggOptions = {}) {
4151

4252
const agent = new AgentClass({
4353
...options,
44-
});
54+
}) as SingleModeAgent;
4555
await agent.ready();
4656
const application = new ApplicationClass({
4757
...options,
48-
});
58+
}) as SingleModeApplication;
4959
application.agent = agent;
5060
agent.application = application;
5161
await application.ready();

test/index.test-d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
LoggerLevel,
55
EggPlugin,
66
EggAppInfo,
7+
start, SingleModeApplication, SingleModeAgent,
78
} from '../src/index.js';
89
import { HttpClient } from '../src/urllib.js';
910

@@ -113,3 +114,13 @@ expectType<EggAppInfo>({
113114
scope: 'scope',
114115
root: 'root',
115116
});
117+
118+
const singleApp = await start({
119+
baseDir: 'baseDir',
120+
framework: 'egg',
121+
plugins: plugin,
122+
});
123+
124+
expectType<SingleModeApplication>(singleApp);
125+
expectType<SingleModeAgent>(singleApp.agent);
126+
expectType<SingleModeApplication>(singleApp.agent.app);

0 commit comments

Comments
 (0)