@midwayjs/bootstrap 3.0.0-alpha.6 → 3.0.0-beta.11
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/CHANGELOG.md +97 -0
- package/README.md +1 -1
- package/dist/bootstrap.d.ts +6 -22
- package/dist/bootstrap.js +15 -116
- package/package.json +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,103 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
42
|
+
|
|
43
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
|
|
58
|
+
|
|
59
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
### Bug Fixes
|
|
69
|
+
|
|
70
|
+
* logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
77
|
+
|
|
78
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
85
|
+
|
|
86
|
+
**Note:** Version bump only for package @midwayjs/bootstrap
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Bug Fixes
|
|
96
|
+
|
|
97
|
+
* serverless app support applicationContext ([#1281](https://github.com/midwayjs/midway/issues/1281)) ([b692001](https://github.com/midwayjs/midway/commit/b692001c451b17a10d26cb6778a8566d5fa569c5))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
6
103
|
## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
|
|
7
104
|
|
|
8
105
|
**Note:** Version bump only for package @midwayjs/bootstrap
|
package/README.md
CHANGED
package/dist/bootstrap.d.ts
CHANGED
|
@@ -1,46 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { IMidwayBootstrapOptions, IMidwayContainer } from '@midwayjs/core';
|
|
2
|
+
import { IMidwayLogger } from '@midwayjs/logger';
|
|
3
3
|
export declare function isTypeScriptEnvironment(): boolean;
|
|
4
4
|
export declare class BootstrapStarter {
|
|
5
5
|
protected appDir: string;
|
|
6
6
|
protected baseDir: string;
|
|
7
|
-
protected bootstrapItems: IMidwayFramework<any, any>[];
|
|
8
7
|
protected globalOptions: Partial<IMidwayBootstrapOptions>;
|
|
9
|
-
protected globalAppMap: Map<MidwayFrameworkType, import("@midwayjs/core").IMidwayBaseApplication<any>>;
|
|
10
8
|
protected globalConfig: any;
|
|
11
9
|
private applicationContext;
|
|
12
10
|
configure(options: IMidwayBootstrapOptions): this;
|
|
13
|
-
|
|
14
|
-
load(unit: IMidwayFramework<any, any>): any;
|
|
15
|
-
init(): Promise<void>;
|
|
11
|
+
init(): Promise<IMidwayContainer>;
|
|
16
12
|
run(): Promise<void>;
|
|
17
13
|
stop(): Promise<void>;
|
|
18
|
-
getActions(action: string, args?: any): any[];
|
|
19
|
-
getFirstActions(action: string, args?: any): Promise<any>;
|
|
20
|
-
getTailActions(action: string, args?: any): any[];
|
|
21
|
-
protected getMainFramework(): IMidwayFramework<any, any>;
|
|
22
|
-
protected refreshBootstrapItems(): void;
|
|
23
14
|
protected getBaseDir(): string;
|
|
24
|
-
getBootstrapAppMap(): Map<MidwayFrameworkType, import("@midwayjs/core").IMidwayBaseApplication<any>>;
|
|
25
15
|
}
|
|
26
16
|
export declare class Bootstrap {
|
|
27
17
|
static starter: BootstrapStarter;
|
|
28
|
-
static logger:
|
|
18
|
+
static logger: IMidwayLogger;
|
|
29
19
|
static configured: boolean;
|
|
30
|
-
static
|
|
20
|
+
static applicationContext: IMidwayContainer;
|
|
31
21
|
/**
|
|
32
22
|
* set global configuration for midway
|
|
33
23
|
* @param configuration
|
|
34
24
|
*/
|
|
35
25
|
static configure(configuration?: IMidwayBootstrapOptions): typeof Bootstrap;
|
|
36
|
-
/**
|
|
37
|
-
* load midway framework unit
|
|
38
|
-
* @param unit
|
|
39
|
-
*/
|
|
40
|
-
static load(unit: (globalConfig: unknown) => IMidwayFramework<any, any>): any;
|
|
41
|
-
static load(unit: IMidwayFramework<any, any>): any;
|
|
42
26
|
private static getStarter;
|
|
43
|
-
static before(beforeHandler: (container: IMidwayContainer) => void): typeof Bootstrap;
|
|
44
27
|
static run(): Promise<void>;
|
|
45
28
|
static stop(): Promise<void>;
|
|
46
29
|
static reset(): void;
|
|
@@ -56,5 +39,6 @@ export declare class Bootstrap {
|
|
|
56
39
|
static onExit(code: any): void;
|
|
57
40
|
static uncaughtExceptionHandler(err: any): void;
|
|
58
41
|
static unhandledRejectionHandler(err: any): void;
|
|
42
|
+
static getApplicationContext(): IMidwayContainer;
|
|
59
43
|
}
|
|
60
44
|
//# sourceMappingURL=bootstrap.d.ts.map
|
package/dist/bootstrap.js
CHANGED
|
@@ -15,136 +15,37 @@ function isTypeScriptEnvironment() {
|
|
|
15
15
|
exports.isTypeScriptEnvironment = isTypeScriptEnvironment;
|
|
16
16
|
class BootstrapStarter {
|
|
17
17
|
constructor() {
|
|
18
|
-
this.bootstrapItems = [];
|
|
19
18
|
this.globalOptions = {};
|
|
20
|
-
this.globalAppMap = new Map();
|
|
21
19
|
}
|
|
22
20
|
configure(options) {
|
|
23
21
|
this.globalOptions = options;
|
|
24
22
|
return this;
|
|
25
23
|
}
|
|
26
|
-
load(unit) {
|
|
27
|
-
this.bootstrapItems.push(unit);
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
24
|
async init() {
|
|
31
25
|
this.appDir = this.globalOptions.appDir || process.cwd();
|
|
32
26
|
this.baseDir = this.getBaseDir();
|
|
33
|
-
|
|
34
|
-
if (this.globalOptions.applicationContext) {
|
|
35
|
-
this.applicationContext = this.globalOptions.applicationContext;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
this.applicationContext = new core_1.MidwayContainer();
|
|
39
|
-
this.applicationContext.setFileDetector(new core_1.DirectoryFileDetector({
|
|
40
|
-
baseDir: this.baseDir,
|
|
41
|
-
}));
|
|
42
|
-
this.applicationContext.load(require(path_1.join(this.baseDir, 'configuration')));
|
|
43
|
-
await this.applicationContext.ready();
|
|
44
|
-
}
|
|
45
|
-
// 调用 bootstrap 的 before 逻辑
|
|
46
|
-
if (this.globalOptions['beforeHandler']) {
|
|
47
|
-
await this.globalOptions['beforeHandler'](this.applicationContext);
|
|
48
|
-
}
|
|
49
|
-
// 获取全局配置
|
|
50
|
-
this.globalConfig =
|
|
51
|
-
this.applicationContext.getConfigService().getConfiguration() || {};
|
|
52
|
-
this.refreshBootstrapItems();
|
|
53
|
-
// 初始化主框架
|
|
54
|
-
await this.getFirstActions('initialize', {
|
|
27
|
+
this.applicationContext = await (0, core_1.initializeGlobalApplicationContext)({
|
|
55
28
|
...this.globalOptions,
|
|
56
|
-
baseDir: this.baseDir,
|
|
57
29
|
appDir: this.appDir,
|
|
58
|
-
isMainFramework: true,
|
|
59
|
-
applicationContext: this.applicationContext,
|
|
60
|
-
globalApplicationHandler: (type) => {
|
|
61
|
-
if (type) {
|
|
62
|
-
return this.globalAppMap.get(type);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
return mainApp;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
global['MIDWAY_MAIN_FRAMEWORK'] = this.getMainFramework();
|
|
70
|
-
mainApp = await this.getFirstActions('getApplication');
|
|
71
|
-
// 初始化其余的副框架
|
|
72
|
-
await Promise.all(this.getTailActions('initialize', {
|
|
73
|
-
...this.globalOptions,
|
|
74
30
|
baseDir: this.baseDir,
|
|
75
|
-
appDir: this.appDir,
|
|
76
|
-
applicationContext: this.applicationContext,
|
|
77
|
-
isMainFramework: false,
|
|
78
|
-
}));
|
|
79
|
-
this.bootstrapItems.forEach(item => {
|
|
80
|
-
this.globalAppMap.set(item.getFrameworkType(), item.getApplication());
|
|
81
|
-
if (global['MIDWAY_BOOTSTRAP_APP_SET']) {
|
|
82
|
-
// for test/dev
|
|
83
|
-
global['MIDWAY_BOOTSTRAP_APP_SET'].add({
|
|
84
|
-
framework: item,
|
|
85
|
-
starter: this,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
31
|
});
|
|
89
|
-
|
|
90
|
-
await this.getFirstActions('loadExtension');
|
|
91
|
-
await this.getActions('afterContainerReady');
|
|
92
|
-
}
|
|
93
|
-
async run() {
|
|
94
|
-
await Promise.all(this.getActions('run', {}));
|
|
95
|
-
global['MIDWAY_BOOTSTRAP_APP_READY'] = true;
|
|
32
|
+
return this.applicationContext;
|
|
96
33
|
}
|
|
34
|
+
async run() { }
|
|
97
35
|
async stop() {
|
|
98
|
-
await
|
|
99
|
-
global['MIDWAY_BOOTSTRAP_APP_READY'] = false;
|
|
100
|
-
}
|
|
101
|
-
getActions(action, args) {
|
|
102
|
-
return this.bootstrapItems.map(item => {
|
|
103
|
-
if (item[action]) {
|
|
104
|
-
return item[action](args);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async getFirstActions(action, args) {
|
|
109
|
-
if (this.bootstrapItems.length && this.bootstrapItems[0][action]) {
|
|
110
|
-
return this.bootstrapItems[0][action](args);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
getTailActions(action, args) {
|
|
114
|
-
if (this.bootstrapItems.length > 1) {
|
|
115
|
-
return this.bootstrapItems.slice(1).map(item => {
|
|
116
|
-
if (item[action]) {
|
|
117
|
-
return item[action](args);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
getMainFramework() {
|
|
124
|
-
return this.bootstrapItems[0];
|
|
125
|
-
}
|
|
126
|
-
refreshBootstrapItems() {
|
|
127
|
-
this.bootstrapItems = this.bootstrapItems.map(bootstrapItem => {
|
|
128
|
-
if (typeof bootstrapItem === 'function') {
|
|
129
|
-
return bootstrapItem(this.globalConfig);
|
|
130
|
-
}
|
|
131
|
-
return bootstrapItem;
|
|
132
|
-
});
|
|
36
|
+
await (0, core_1.destroyGlobalApplicationContext)(this.applicationContext);
|
|
133
37
|
}
|
|
134
38
|
getBaseDir() {
|
|
135
39
|
if (this.globalOptions.baseDir) {
|
|
136
40
|
return this.globalOptions.baseDir;
|
|
137
41
|
}
|
|
138
42
|
if (isTypeScriptEnvironment()) {
|
|
139
|
-
return path_1.join(this.appDir, 'src');
|
|
43
|
+
return (0, path_1.join)(this.appDir, 'src');
|
|
140
44
|
}
|
|
141
45
|
else {
|
|
142
|
-
return path_1.join(this.appDir, 'dist');
|
|
46
|
+
return (0, path_1.join)(this.appDir, 'dist');
|
|
143
47
|
}
|
|
144
48
|
}
|
|
145
|
-
getBootstrapAppMap() {
|
|
146
|
-
return this.globalAppMap;
|
|
147
|
-
}
|
|
148
49
|
}
|
|
149
50
|
exports.BootstrapStarter = BootstrapStarter;
|
|
150
51
|
class Bootstrap {
|
|
@@ -156,7 +57,10 @@ class Bootstrap {
|
|
|
156
57
|
var _a;
|
|
157
58
|
this.configured = true;
|
|
158
59
|
if (!this.logger && !configuration.logger) {
|
|
159
|
-
this.logger = logger_1.
|
|
60
|
+
this.logger = new logger_1.MidwayBaseLogger({
|
|
61
|
+
disableError: true,
|
|
62
|
+
disableFile: true,
|
|
63
|
+
});
|
|
160
64
|
if (configuration.logger === false) {
|
|
161
65
|
(_a = this.logger) === null || _a === void 0 ? void 0 : _a['disableConsole']();
|
|
162
66
|
}
|
|
@@ -169,24 +73,15 @@ class Bootstrap {
|
|
|
169
73
|
if (configuration.appDir && configuration.appDir !== process.cwd()) {
|
|
170
74
|
process.chdir(configuration.appDir);
|
|
171
75
|
}
|
|
172
|
-
configuration['beforeHandler'] = this.beforeHandler;
|
|
173
76
|
this.getStarter().configure(configuration);
|
|
174
77
|
return this;
|
|
175
78
|
}
|
|
176
|
-
static load(unit) {
|
|
177
|
-
this.getStarter().load(unit);
|
|
178
|
-
return this;
|
|
179
|
-
}
|
|
180
79
|
static getStarter() {
|
|
181
80
|
if (!this.starter) {
|
|
182
81
|
this.starter = new BootstrapStarter();
|
|
183
82
|
}
|
|
184
83
|
return this.starter;
|
|
185
84
|
}
|
|
186
|
-
static before(beforeHandler) {
|
|
187
|
-
this.beforeHandler = beforeHandler;
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
85
|
static async run() {
|
|
191
86
|
if (!this.configured) {
|
|
192
87
|
this.configure();
|
|
@@ -204,7 +99,7 @@ class Bootstrap {
|
|
|
204
99
|
process.on('uncaughtException', this.uncaughtExceptionHandler);
|
|
205
100
|
this.unhandledRejectionHandler = this.unhandledRejectionHandler.bind(this);
|
|
206
101
|
process.on('unhandledRejection', this.unhandledRejectionHandler);
|
|
207
|
-
await this.getStarter().init();
|
|
102
|
+
this.applicationContext = await this.getStarter().init();
|
|
208
103
|
return this.getStarter()
|
|
209
104
|
.run()
|
|
210
105
|
.then(() => {
|
|
@@ -224,6 +119,7 @@ class Bootstrap {
|
|
|
224
119
|
static reset() {
|
|
225
120
|
this.configured = false;
|
|
226
121
|
this.starter = null;
|
|
122
|
+
this.logger.close();
|
|
227
123
|
}
|
|
228
124
|
/**
|
|
229
125
|
* on bootstrap receive a exit signal
|
|
@@ -276,6 +172,9 @@ class Bootstrap {
|
|
|
276
172
|
}
|
|
277
173
|
this.logger.error(err);
|
|
278
174
|
}
|
|
175
|
+
static getApplicationContext() {
|
|
176
|
+
return this.applicationContext;
|
|
177
|
+
}
|
|
279
178
|
}
|
|
280
179
|
exports.Bootstrap = Bootstrap;
|
|
281
180
|
Bootstrap.configured = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/bootstrap",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"description": "midwayjs bootstrap",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,9 +21,11 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@midwayjs/core": "^3.0.0-
|
|
25
|
-
"@midwayjs/decorator": "^3.0.0-
|
|
26
|
-
"@midwayjs/logger": "^3.0.0-
|
|
24
|
+
"@midwayjs/core": "^3.0.0-beta.11",
|
|
25
|
+
"@midwayjs/decorator": "^3.0.0-beta.11",
|
|
26
|
+
"@midwayjs/logger": "^3.0.0-beta.11",
|
|
27
|
+
"@midwayjs/socketio": "^3.0.0-beta.11",
|
|
28
|
+
"@midwayjs/web": "^3.0.0-beta.11",
|
|
27
29
|
"@types/socket.io-client": "^1.4.36",
|
|
28
30
|
"request": "^2.88.2",
|
|
29
31
|
"socket.io-client": "^4.0.0"
|
|
@@ -33,5 +35,8 @@
|
|
|
33
35
|
"type": "git",
|
|
34
36
|
"url": "http://github.com/midwayjs/midway.git"
|
|
35
37
|
},
|
|
36
|
-
"
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=12"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "a2b066fd500e815e799e7f421cd216f12e0e9f8e"
|
|
37
42
|
}
|