@midwayjs/bootstrap 3.0.0-alpha.43 → 3.0.0-beta.10

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 CHANGED
@@ -3,6 +3,95 @@
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.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
7
+
8
+ **Note:** Version bump only for package @midwayjs/bootstrap
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
15
+
16
+ **Note:** Version bump only for package @midwayjs/bootstrap
17
+
18
+
19
+
20
+
21
+
22
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * 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))
28
+
29
+
30
+
31
+
32
+
33
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
34
+
35
+ **Note:** Version bump only for package @midwayjs/bootstrap
36
+
37
+
38
+
39
+
40
+
41
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
42
+
43
+ **Note:** Version bump only for package @midwayjs/bootstrap
44
+
45
+
46
+
47
+
48
+
49
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
50
+
51
+ **Note:** Version bump only for package @midwayjs/bootstrap
52
+
53
+
54
+
55
+
56
+
57
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
58
+
59
+
60
+ ### Bug Fixes
61
+
62
+ * logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
63
+
64
+
65
+
66
+
67
+
68
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
69
+
70
+ **Note:** Version bump only for package @midwayjs/bootstrap
71
+
72
+
73
+
74
+
75
+
76
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
77
+
78
+ **Note:** Version bump only for package @midwayjs/bootstrap
79
+
80
+
81
+
82
+
83
+
84
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
85
+
86
+
87
+ ### Bug Fixes
88
+
89
+ * serverless app support applicationContext ([#1281](https://github.com/midwayjs/midway/issues/1281)) ([b692001](https://github.com/midwayjs/midway/commit/b692001c451b17a10d26cb6778a8566d5fa569c5))
90
+
91
+
92
+
93
+
94
+
6
95
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
96
 
8
97
  **Note:** Version bump only for package @midwayjs/bootstrap
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  this is a sub package for midway.
7
7
 
8
- Document: [https://midwayjs.org/midway](https://midwayjs.org/midway)
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
9
 
10
10
  ## License
11
11
 
@@ -1,42 +1,28 @@
1
- import { IMidwayFramework, IMidwayBootstrapOptions, MidwayFrameworkType } from '@midwayjs/core';
2
- import { ILogger } from '@midwayjs/logger';
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
- load(unit: (globalConfig: unknown) => IMidwayFramework<any, any>): any;
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: ILogger;
18
+ static logger: IMidwayLogger;
29
19
  static configured: boolean;
20
+ static applicationContext: IMidwayContainer;
30
21
  /**
31
22
  * set global configuration for midway
32
23
  * @param configuration
33
24
  */
34
25
  static configure(configuration?: IMidwayBootstrapOptions): typeof Bootstrap;
35
- /**
36
- * load midway framework unit
37
- * @param unit
38
- */
39
- static load(unit: IMidwayFramework<any, any>): any;
40
26
  private static getStarter;
41
27
  static run(): Promise<void>;
42
28
  static stop(): Promise<void>;
@@ -53,5 +39,6 @@ export declare class Bootstrap {
53
39
  static onExit(code: any): void;
54
40
  static uncaughtExceptionHandler(err: any): void;
55
41
  static unhandledRejectionHandler(err: any): void;
42
+ static getApplicationContext(): IMidwayContainer;
56
43
  }
57
44
  //# sourceMappingURL=bootstrap.d.ts.map
package/dist/bootstrap.js CHANGED
@@ -15,118 +15,25 @@ 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
- var _a;
32
25
  this.appDir = this.globalOptions.appDir || process.cwd();
33
26
  this.baseDir = this.getBaseDir();
34
- let mainApp; // eslint-disable-line prefer-const
35
- if (this.globalOptions.applicationContext) {
36
- this.applicationContext = this.globalOptions.applicationContext;
37
- }
38
- else {
39
- this.applicationContext = new core_1.MidwayContainer();
40
- this.applicationContext.setFileDetector(new core_1.DirectoryFileDetector({
41
- loadDir: this.baseDir,
42
- }));
43
- this.applicationContext.load((_a = this.globalOptions.configurationModule) !== null && _a !== void 0 ? _a : require((0, path_1.join)(this.baseDir, 'configuration')));
44
- await this.applicationContext.ready();
45
- }
46
- // 获取全局配置
47
- this.globalConfig =
48
- this.applicationContext.getConfigService().getConfiguration() || {};
49
- this.refreshBootstrapItems();
50
- // 初始化主框架
51
- await this.getFirstActions('initialize', {
27
+ this.applicationContext = await (0, core_1.initializeGlobalApplicationContext)({
52
28
  ...this.globalOptions,
53
- baseDir: this.baseDir,
54
29
  appDir: this.appDir,
55
- isMainFramework: true,
56
- applicationContext: this.applicationContext,
57
- globalApplicationHandler: (type) => {
58
- if (type) {
59
- return this.globalAppMap.get(type);
60
- }
61
- else {
62
- return mainApp;
63
- }
64
- },
65
- });
66
- global['MIDWAY_MAIN_FRAMEWORK'] = this.getMainFramework();
67
- mainApp = await this.getFirstActions('getApplication');
68
- // 初始化其余的副框架
69
- await Promise.all(this.getTailActions('initialize', {
70
- ...this.globalOptions,
71
30
  baseDir: this.baseDir,
72
- appDir: this.appDir,
73
- applicationContext: this.applicationContext,
74
- isMainFramework: false,
75
- }));
76
- this.bootstrapItems.forEach(item => {
77
- this.globalAppMap.set(item.getFrameworkType(), item.getApplication());
78
- if (global['MIDWAY_BOOTSTRAP_APP_SET']) {
79
- // for test/dev
80
- global['MIDWAY_BOOTSTRAP_APP_SET'].add({
81
- framework: item,
82
- starter: this,
83
- });
84
- }
85
31
  });
86
- // 等所有框架初始化完之后,开始执行生命周期
87
- await this.getFirstActions('loadExtension');
88
- await this.getActions('afterContainerReady');
89
- }
90
- async run() {
91
- await Promise.all(this.getActions('run', {}));
92
- global['MIDWAY_BOOTSTRAP_APP_READY'] = true;
32
+ return this.applicationContext;
93
33
  }
34
+ async run() { }
94
35
  async stop() {
95
- await Promise.all(this.getActions('stop', {}));
96
- global['MIDWAY_BOOTSTRAP_APP_READY'] = false;
97
- }
98
- getActions(action, args) {
99
- return this.bootstrapItems.map(item => {
100
- if (item[action]) {
101
- return item[action](args);
102
- }
103
- });
104
- }
105
- async getFirstActions(action, args) {
106
- if (this.bootstrapItems.length && this.bootstrapItems[0][action]) {
107
- return this.bootstrapItems[0][action](args);
108
- }
109
- }
110
- getTailActions(action, args) {
111
- if (this.bootstrapItems.length > 1) {
112
- return this.bootstrapItems.slice(1).map(item => {
113
- if (item[action]) {
114
- return item[action](args);
115
- }
116
- });
117
- }
118
- return [];
119
- }
120
- getMainFramework() {
121
- return this.bootstrapItems[0];
122
- }
123
- refreshBootstrapItems() {
124
- this.bootstrapItems = this.bootstrapItems.map(bootstrapItem => {
125
- if (typeof bootstrapItem === 'function') {
126
- return bootstrapItem(this.globalConfig);
127
- }
128
- return bootstrapItem;
129
- });
36
+ await (0, core_1.destroyGlobalApplicationContext)(this.applicationContext);
130
37
  }
131
38
  getBaseDir() {
132
39
  if (this.globalOptions.baseDir) {
@@ -139,9 +46,6 @@ class BootstrapStarter {
139
46
  return (0, path_1.join)(this.appDir, 'dist');
140
47
  }
141
48
  }
142
- getBootstrapAppMap() {
143
- return this.globalAppMap;
144
- }
145
49
  }
146
50
  exports.BootstrapStarter = BootstrapStarter;
147
51
  class Bootstrap {
@@ -153,7 +57,10 @@ class Bootstrap {
153
57
  var _a;
154
58
  this.configured = true;
155
59
  if (!this.logger && !configuration.logger) {
156
- this.logger = (0, logger_1.createConsoleLogger)('bootstrapConsole');
60
+ this.logger = new logger_1.MidwayBaseLogger({
61
+ disableError: true,
62
+ disableFile: true,
63
+ });
157
64
  if (configuration.logger === false) {
158
65
  (_a = this.logger) === null || _a === void 0 ? void 0 : _a['disableConsole']();
159
66
  }
@@ -169,10 +76,6 @@ class Bootstrap {
169
76
  this.getStarter().configure(configuration);
170
77
  return this;
171
78
  }
172
- static load(unit) {
173
- this.getStarter().load(unit);
174
- return this;
175
- }
176
79
  static getStarter() {
177
80
  if (!this.starter) {
178
81
  this.starter = new BootstrapStarter();
@@ -196,7 +99,7 @@ class Bootstrap {
196
99
  process.on('uncaughtException', this.uncaughtExceptionHandler);
197
100
  this.unhandledRejectionHandler = this.unhandledRejectionHandler.bind(this);
198
101
  process.on('unhandledRejection', this.unhandledRejectionHandler);
199
- await this.getStarter().init();
102
+ this.applicationContext = await this.getStarter().init();
200
103
  return this.getStarter()
201
104
  .run()
202
105
  .then(() => {
@@ -216,6 +119,7 @@ class Bootstrap {
216
119
  static reset() {
217
120
  this.configured = false;
218
121
  this.starter = null;
122
+ this.logger.close();
219
123
  }
220
124
  /**
221
125
  * on bootstrap receive a exit signal
@@ -268,6 +172,9 @@ class Bootstrap {
268
172
  }
269
173
  this.logger.error(err);
270
174
  }
175
+ static getApplicationContext() {
176
+ return this.applicationContext;
177
+ }
271
178
  }
272
179
  exports.Bootstrap = Bootstrap;
273
180
  Bootstrap.configured = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/bootstrap",
3
- "version": "3.0.0-alpha.43+8b8075f0",
3
+ "version": "3.0.0-beta.10",
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-alpha.43+8b8075f0",
25
- "@midwayjs/decorator": "^3.0.0-alpha.43+8b8075f0",
26
- "@midwayjs/logger": "^3.0.0-alpha.43+8b8075f0",
24
+ "@midwayjs/core": "^3.0.0-beta.10",
25
+ "@midwayjs/decorator": "^3.0.0-beta.10",
26
+ "@midwayjs/logger": "^3.0.0-beta.10",
27
+ "@midwayjs/socketio": "^3.0.0-beta.10",
28
+ "@midwayjs/web": "^3.0.0-beta.10",
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
- "gitHead": "8b8075f0d40c5de19bb9026f0950e738ca512c7e"
38
+ "engines": {
39
+ "node": ">=12"
40
+ },
41
+ "gitHead": "153870f2e2dd6b17673ec7591e49224a6bd51b36"
37
42
  }