@eggjs/core 7.0.0-beta.35 → 7.0.0-beta.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base_context_class.d.ts +19 -14
- package/dist/base_context_class.js +39 -36
- package/dist/egg.d.ts +279 -277
- package/dist/egg.js +394 -426
- package/dist/index.d.ts +12 -12
- package/dist/index.js +12 -12
- package/dist/lifecycle.d.ts +79 -75
- package/dist/lifecycle.js +280 -306
- package/dist/loader/context_loader.d.ts +34 -30
- package/dist/loader/context_loader.js +76 -99
- package/dist/loader/egg_loader.d.ts +370 -366
- package/dist/loader/egg_loader.js +1169 -1567
- package/dist/loader/file_loader.d.ts +99 -95
- package/dist/loader/file_loader.js +190 -241
- package/dist/singleton.d.ts +31 -27
- package/dist/singleton.js +107 -117
- package/dist/types.d.ts +54 -51
- package/dist/utils/index.d.ts +16 -14
- package/dist/utils/index.js +96 -105
- package/dist/utils/sequencify.d.ts +13 -10
- package/dist/utils/sequencify.js +44 -58
- package/dist/utils/timing.d.ts +22 -19
- package/dist/utils/timing.js +85 -92
- package/package.json +35 -40
- package/dist/types.js +0 -2
|
@@ -1,369 +1,373 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { Timing } from "../utils/timing.js";
|
|
2
|
+
import { Lifecycle } from "../lifecycle.js";
|
|
3
|
+
import { EggAppConfig, EggAppInfo, EggPluginInfo } from "../types.js";
|
|
4
|
+
import { FileLoader, FileLoaderOptions } from "./file_loader.js";
|
|
5
|
+
import { ContextLoader, ContextLoaderOptions } from "./context_loader.js";
|
|
6
|
+
import { EggCore } from "../egg.js";
|
|
7
|
+
import { Logger } from "egg-logger";
|
|
8
|
+
|
|
9
|
+
//#region src/loader/egg_loader.d.ts
|
|
10
|
+
interface EggLoaderOptions {
|
|
11
|
+
/** server env */
|
|
12
|
+
env: string;
|
|
13
|
+
/** Application instance */
|
|
14
|
+
app: EggCore;
|
|
15
|
+
EggCoreClass?: typeof EggCore;
|
|
16
|
+
/** the directory of application */
|
|
17
|
+
baseDir: string;
|
|
18
|
+
/** egg logger */
|
|
19
|
+
logger: Logger;
|
|
20
|
+
/** server scope */
|
|
21
|
+
serverScope?: string;
|
|
22
|
+
/** custom plugins */
|
|
23
|
+
plugins?: Record<string, EggPluginInfo>;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
type EggDirInfoType = "app" | "plugin" | "framework";
|
|
26
|
+
interface EggDirInfo {
|
|
27
|
+
path: string;
|
|
28
|
+
type: EggDirInfoType;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
30
|
+
declare class EggLoader {
|
|
31
|
+
#private;
|
|
32
|
+
readonly options: EggLoaderOptions;
|
|
33
|
+
readonly timing: Timing;
|
|
34
|
+
readonly pkg: Record<string, any>;
|
|
35
|
+
readonly eggPaths: string[];
|
|
36
|
+
readonly serverEnv: string;
|
|
37
|
+
readonly serverScope: string;
|
|
38
|
+
readonly appInfo: EggAppInfo;
|
|
39
|
+
dirs?: EggDirInfo[];
|
|
40
|
+
/**
|
|
41
|
+
* @class
|
|
42
|
+
* @param {Object} options - options
|
|
43
|
+
* @param {String} options.baseDir - the directory of application
|
|
44
|
+
* @param {EggCore} options.app - Application instance
|
|
45
|
+
* @param {Logger} options.logger - logger
|
|
46
|
+
* @param {Object} [options.plugins] - custom plugins
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
*/
|
|
49
|
+
constructor(options: EggLoaderOptions);
|
|
50
|
+
get app(): EggCore;
|
|
51
|
+
get lifecycle(): Lifecycle;
|
|
52
|
+
get logger(): Logger;
|
|
53
|
+
/**
|
|
54
|
+
* Get {@link AppInfo#env}
|
|
55
|
+
* @returns {String} env
|
|
56
|
+
* @see AppInfo#env
|
|
57
|
+
* @private
|
|
58
|
+
* @since 1.0.0
|
|
59
|
+
*/
|
|
60
|
+
protected getServerEnv(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get {@link AppInfo#scope}
|
|
63
|
+
* @returns {String} serverScope
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
protected getServerScope(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Get {@link AppInfo#name}
|
|
69
|
+
* @returns {String} appname
|
|
70
|
+
* @private
|
|
71
|
+
* @since 1.0.0
|
|
72
|
+
*/
|
|
73
|
+
getAppname(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Get home directory
|
|
76
|
+
* @returns {String} home directory
|
|
77
|
+
* @since 3.4.0
|
|
78
|
+
*/
|
|
79
|
+
getHomedir(): string;
|
|
80
|
+
/**
|
|
81
|
+
* Get app info
|
|
82
|
+
* @returns {AppInfo} appInfo
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
*/
|
|
85
|
+
protected getAppInfo(): EggAppInfo;
|
|
86
|
+
/**
|
|
87
|
+
* Get {@link EggLoader#eggPaths}
|
|
88
|
+
* @returns {Array} framework directories
|
|
89
|
+
* @see {@link EggLoader#eggPaths}
|
|
90
|
+
* @private
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
*/
|
|
93
|
+
protected getEggPaths(): string[];
|
|
94
|
+
/** start Plugin loader */
|
|
95
|
+
lookupDirs: Set<string>;
|
|
96
|
+
eggPlugins: Record<string, EggPluginInfo>;
|
|
97
|
+
appPlugins: Record<string, EggPluginInfo>;
|
|
98
|
+
customPlugins: Record<string, EggPluginInfo>;
|
|
99
|
+
allPlugins: Record<string, EggPluginInfo>;
|
|
100
|
+
orderPlugins: EggPluginInfo[];
|
|
101
|
+
/** enable plugins */
|
|
102
|
+
plugins: Record<string, EggPluginInfo>;
|
|
103
|
+
/**
|
|
104
|
+
* Load config/plugin.js from {EggLoader#loadUnits}
|
|
105
|
+
*
|
|
106
|
+
* plugin.js is written below
|
|
107
|
+
*
|
|
108
|
+
* ```js
|
|
109
|
+
* {
|
|
110
|
+
* 'xxx-client': {
|
|
111
|
+
* enable: true,
|
|
112
|
+
* package: 'xxx-client',
|
|
113
|
+
* dep: [],
|
|
114
|
+
* env: [],
|
|
115
|
+
* },
|
|
116
|
+
* // short hand
|
|
117
|
+
* 'rds': false,
|
|
118
|
+
* 'depd': {
|
|
119
|
+
* enable: true,
|
|
120
|
+
* path: 'path/to/depd'
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* If the plugin has path, Loader will find the module from it.
|
|
126
|
+
*
|
|
127
|
+
* Otherwise Loader will lookup follow the order by packageName
|
|
128
|
+
*
|
|
129
|
+
* 1. $APP_BASE/node_modules/${package}
|
|
130
|
+
* 2. $EGG_BASE/node_modules/${package}
|
|
131
|
+
*
|
|
132
|
+
* You can call `loader.plugins` that retrieve enabled plugins.
|
|
133
|
+
*
|
|
134
|
+
* ```js
|
|
135
|
+
* loader.plugins['xxx-client'] = {
|
|
136
|
+
* name: 'xxx-client', // the plugin name, it can be used in `dep`
|
|
137
|
+
* package: 'xxx-client', // the package name of plugin
|
|
138
|
+
* enable: true, // whether enabled
|
|
139
|
+
* path: 'path/to/xxx-client', // the directory of the plugin package
|
|
140
|
+
* dep: [], // the dependent plugins, you can use the plugin name
|
|
141
|
+
* env: [ 'local', 'unittest' ], // specify the serverEnv that only enable the plugin in it
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* `loader.allPlugins` can be used when retrieve all plugins.
|
|
146
|
+
* @function EggLoader#loadPlugin
|
|
147
|
+
* @since 1.0.0
|
|
148
|
+
*/
|
|
149
|
+
loadPlugin(): Promise<void>;
|
|
150
|
+
protected loadAppPlugins(): Promise<Record<string, EggPluginInfo>>;
|
|
151
|
+
protected loadEggPlugins(): Promise<Record<string, EggPluginInfo>>;
|
|
152
|
+
protected loadCustomPlugins(): Record<string, EggPluginInfo>;
|
|
153
|
+
protected readPluginConfigs(configPaths: string[] | string): Promise<Record<string, EggPluginInfo>>;
|
|
154
|
+
protected getOrderPlugins(allPlugins: Record<string, EggPluginInfo>, enabledPluginNames: string[], appPlugins: Record<string, EggPluginInfo>): EggPluginInfo[];
|
|
155
|
+
protected getLookupDirs(): Set<string>;
|
|
156
|
+
protected getPluginPath(plugin: EggPluginInfo): string;
|
|
157
|
+
/** end Plugin loader */
|
|
158
|
+
/** start Config loader */
|
|
159
|
+
configMeta: Record<string, any>;
|
|
160
|
+
config: EggAppConfig;
|
|
161
|
+
/**
|
|
162
|
+
* Load config/config.js
|
|
163
|
+
*
|
|
164
|
+
* Will merge config.default.js 和 config.${env}.js
|
|
165
|
+
*
|
|
166
|
+
* @function EggLoader#loadConfig
|
|
167
|
+
* @since 1.0.0
|
|
168
|
+
*/
|
|
169
|
+
loadConfig(): Promise<void>;
|
|
170
|
+
/** end Config loader */
|
|
171
|
+
/** start Extend loader */
|
|
172
|
+
/**
|
|
173
|
+
* mixin Agent.prototype
|
|
174
|
+
* @function EggLoader#loadAgentExtend
|
|
175
|
+
* @since 1.0.0
|
|
176
|
+
*/
|
|
177
|
+
loadAgentExtend(): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* mixin Application.prototype
|
|
180
|
+
* @function EggLoader#loadApplicationExtend
|
|
181
|
+
* @since 1.0.0
|
|
182
|
+
*/
|
|
183
|
+
loadApplicationExtend(): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* mixin Request.prototype
|
|
186
|
+
* @function EggLoader#loadRequestExtend
|
|
187
|
+
* @since 1.0.0
|
|
188
|
+
*/
|
|
189
|
+
loadRequestExtend(): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* mixin Response.prototype
|
|
192
|
+
* @function EggLoader#loadResponseExtend
|
|
193
|
+
* @since 1.0.0
|
|
194
|
+
*/
|
|
195
|
+
loadResponseExtend(): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* mixin Context.prototype
|
|
198
|
+
* @function EggLoader#loadContextExtend
|
|
199
|
+
* @since 1.0.0
|
|
200
|
+
*/
|
|
201
|
+
loadContextExtend(): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* mixin app.Helper.prototype
|
|
204
|
+
* @function EggLoader#loadHelperExtend
|
|
205
|
+
* @since 1.0.0
|
|
206
|
+
*/
|
|
207
|
+
loadHelperExtend(): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Find all extend file paths by name
|
|
210
|
+
* can be override in top level framework to support load `app/extends/{name}.js`
|
|
211
|
+
*
|
|
212
|
+
* @param {String} name - filename which may be `app/extend/{name}.js`
|
|
213
|
+
* @returns {Array} filepaths extend file paths
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
protected getExtendFilePaths(name: string): string[];
|
|
217
|
+
/**
|
|
218
|
+
* Loader app/extend/xx.js to `prototype`,
|
|
219
|
+
* @function loadExtend
|
|
220
|
+
* @param {String} name - filename which may be `app/extend/{name}.js`
|
|
221
|
+
* @param {Object} proto - prototype that mixed
|
|
222
|
+
* @since 1.0.0
|
|
223
|
+
*/
|
|
224
|
+
loadExtend(name: string, proto: object): Promise<void>;
|
|
225
|
+
/** end Extend loader */
|
|
226
|
+
/** start Custom loader */
|
|
227
|
+
/**
|
|
228
|
+
* load app.js
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* - old:
|
|
232
|
+
*
|
|
233
|
+
* ```js
|
|
234
|
+
* module.exports = function(app) {
|
|
235
|
+
* doSomething();
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* - new:
|
|
240
|
+
*
|
|
241
|
+
* ```js
|
|
242
|
+
* module.exports = class Boot {
|
|
243
|
+
* constructor(app) {
|
|
244
|
+
* this.app = app;
|
|
245
|
+
* }
|
|
246
|
+
* configDidLoad() {
|
|
247
|
+
* doSomething();
|
|
248
|
+
* }
|
|
249
|
+
* }
|
|
250
|
+
* @since 1.0.0
|
|
251
|
+
*/
|
|
252
|
+
loadCustomApp(): Promise<void>;
|
|
253
|
+
/**
|
|
254
|
+
* Load agent.js, same as {@link EggLoader#loadCustomApp}
|
|
255
|
+
*/
|
|
256
|
+
loadCustomAgent(): Promise<void>;
|
|
257
|
+
loadBootHook(): void;
|
|
258
|
+
/** end Custom loader */
|
|
259
|
+
/** start Service loader */
|
|
260
|
+
/**
|
|
261
|
+
* Load app/service
|
|
262
|
+
* @function EggLoader#loadService
|
|
263
|
+
* @param {Object} options - LoaderOptions
|
|
264
|
+
* @since 1.0.0
|
|
265
|
+
*/
|
|
266
|
+
loadService(options?: Partial<ContextLoaderOptions>): Promise<void>;
|
|
267
|
+
/** end Service loader */
|
|
268
|
+
/** start Middleware loader */
|
|
269
|
+
/**
|
|
270
|
+
* Load app/middleware
|
|
271
|
+
*
|
|
272
|
+
* app.config.xx is the options of the middleware xx that has same name as config
|
|
273
|
+
*
|
|
274
|
+
* @function EggLoader#loadMiddleware
|
|
275
|
+
* @param {Object} opt - LoaderOptions
|
|
276
|
+
* @example
|
|
277
|
+
* ```js
|
|
278
|
+
* // app/middleware/status.js
|
|
279
|
+
* module.exports = function(options, app) {
|
|
280
|
+
* // options == app.config.status
|
|
281
|
+
* return async next => {
|
|
282
|
+
* await next();
|
|
283
|
+
* }
|
|
284
|
+
* }
|
|
285
|
+
* ```
|
|
286
|
+
* @since 1.0.0
|
|
287
|
+
*/
|
|
288
|
+
loadMiddleware(opt?: Partial<FileLoaderOptions>): Promise<void>;
|
|
289
|
+
/** end Middleware loader */
|
|
290
|
+
/** start Controller loader */
|
|
291
|
+
/**
|
|
292
|
+
* Load app/controller
|
|
293
|
+
* @param {Object} opt - LoaderOptions
|
|
294
|
+
* @since 1.0.0
|
|
295
|
+
*/
|
|
296
|
+
loadController(opt?: Partial<FileLoaderOptions>): Promise<void>;
|
|
297
|
+
/** end Controller loader */
|
|
298
|
+
/** start Router loader */
|
|
299
|
+
/**
|
|
300
|
+
* Load app/router.js
|
|
301
|
+
* @function EggLoader#loadRouter
|
|
302
|
+
* @since 1.0.0
|
|
303
|
+
*/
|
|
304
|
+
loadRouter(): Promise<void>;
|
|
305
|
+
/** end Router loader */
|
|
306
|
+
/** start CustomLoader loader */
|
|
307
|
+
loadCustomLoader(): Promise<void>;
|
|
308
|
+
/** end CustomLoader loader */
|
|
309
|
+
/**
|
|
310
|
+
* Load single file, will invoke when export is function
|
|
311
|
+
*
|
|
312
|
+
* @param {String} filepath - fullpath
|
|
313
|
+
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
314
|
+
* @returns {Object} exports
|
|
315
|
+
* @example
|
|
316
|
+
* ```js
|
|
317
|
+
* app.loader.loadFile(path.join(app.options.baseDir, 'config/router.js'));
|
|
318
|
+
* ```
|
|
319
|
+
* @since 1.0.0
|
|
320
|
+
*/
|
|
321
|
+
loadFile(filepath: string, ...inject: unknown[]): Promise<any>;
|
|
322
|
+
/**
|
|
323
|
+
* @param {String} filepath - fullpath
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
requireFile(filepath: string): Promise<any>;
|
|
327
|
+
/**
|
|
328
|
+
* Get all loadUnit
|
|
329
|
+
*
|
|
330
|
+
* loadUnit is a directory that can be loaded by EggLoader, it has the same structure.
|
|
331
|
+
* loadUnit has a path and a type(app, framework, plugin).
|
|
332
|
+
*
|
|
333
|
+
* The order of the loadUnits:
|
|
334
|
+
*
|
|
335
|
+
* 1. plugin
|
|
336
|
+
* 2. framework
|
|
337
|
+
* 3. app
|
|
338
|
+
*
|
|
339
|
+
* @returns {Array} loadUnits
|
|
340
|
+
* @since 1.0.0
|
|
341
|
+
*/
|
|
342
|
+
getLoadUnits(): EggDirInfo[];
|
|
343
|
+
/**
|
|
344
|
+
* Load files using {@link FileLoader}, inject to {@link Application}
|
|
345
|
+
* @param {String|Array} directory - see {@link FileLoader}
|
|
346
|
+
* @param {String} property - see {@link FileLoader}, e.g.: 'controller', 'middlewares'
|
|
347
|
+
* @param {Object} options - see {@link FileLoader}
|
|
348
|
+
* @since 1.0.0
|
|
349
|
+
*/
|
|
350
|
+
loadToApp(directory: string | string[], property: string | symbol, options?: Omit<FileLoaderOptions, "inject" | "target">): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* Load files using {@link ContextLoader}
|
|
353
|
+
* @param {String|Array} directory - see {@link ContextLoader}
|
|
354
|
+
* @param {String} property - see {@link ContextLoader}
|
|
355
|
+
* @param {Object} options - see {@link ContextLoader}
|
|
356
|
+
* @since 1.0.0
|
|
357
|
+
*/
|
|
358
|
+
loadToContext(directory: string | string[], property: string | symbol, options?: Omit<ContextLoaderOptions, "inject" | "property">): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* @member {FileLoader} EggLoader#FileLoader
|
|
361
|
+
* @since 1.0.0
|
|
362
|
+
*/
|
|
363
|
+
get FileLoader(): typeof FileLoader;
|
|
364
|
+
/**
|
|
365
|
+
* @member {ContextLoader} EggLoader#ContextLoader
|
|
366
|
+
* @since 1.0.0
|
|
367
|
+
*/
|
|
368
|
+
get ContextLoader(): typeof ContextLoader;
|
|
369
|
+
getTypeFiles(filename: string): string[];
|
|
370
|
+
resolveModule(filepath: string): string | undefined;
|
|
369
371
|
}
|
|
372
|
+
//#endregion
|
|
373
|
+
export { EggDirInfo, EggDirInfoType, EggLoader, EggLoaderOptions };
|