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

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,25 @@
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.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
7
+
8
+ **Note:** Version bump only for package @midwayjs/bootstrap
9
+
10
+
11
+
12
+
13
+
14
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * serverless app support applicationContext ([#1281](https://github.com/midwayjs/midway/issues/1281)) ([b692001](https://github.com/midwayjs/midway/commit/b692001c451b17a10d26cb6778a8566d5fa569c5))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [2.12.3](https://github.com/midwayjs/midway/compare/v2.12.2...v2.12.3) (2021-08-09)
7
26
 
8
27
  **Note:** Version bump only for package @midwayjs/bootstrap
@@ -1,42 +1,28 @@
1
- import { IMidwayFramework, IMidwayBootstrapOptions, MidwayFrameworkType } from '@midwayjs/core';
1
+ import { IMidwayBootstrapOptions, IMidwayContainer } from '@midwayjs/core';
2
2
  import { ILogger } 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
18
  static logger: ILogger;
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 {
@@ -169,10 +73,6 @@ class Bootstrap {
169
73
  this.getStarter().configure(configuration);
170
74
  return this;
171
75
  }
172
- static load(unit) {
173
- this.getStarter().load(unit);
174
- return this;
175
- }
176
76
  static getStarter() {
177
77
  if (!this.starter) {
178
78
  this.starter = new BootstrapStarter();
@@ -196,7 +96,7 @@ class Bootstrap {
196
96
  process.on('uncaughtException', this.uncaughtExceptionHandler);
197
97
  this.unhandledRejectionHandler = this.unhandledRejectionHandler.bind(this);
198
98
  process.on('unhandledRejection', this.unhandledRejectionHandler);
199
- await this.getStarter().init();
99
+ this.applicationContext = await this.getStarter().init();
200
100
  return this.getStarter()
201
101
  .run()
202
102
  .then(() => {
@@ -268,6 +168,9 @@ class Bootstrap {
268
168
  }
269
169
  this.logger.error(err);
270
170
  }
171
+ static getApplicationContext() {
172
+ return this.applicationContext;
173
+ }
271
174
  }
272
175
  exports.Bootstrap = Bootstrap;
273
176
  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.2",
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.2",
25
+ "@midwayjs/decorator": "^3.0.0-beta.2",
26
+ "@midwayjs/logger": "^3.0.0-beta.2",
27
+ "@midwayjs/socketio": "^3.0.0-beta.2",
28
+ "@midwayjs/web": "^3.0.0-beta.2",
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": "7f07de960da1155a9f7df554e1789c7a97bdd3fe"
37
42
  }