@midwayjs/web 3.1.0 → 3.1.3

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/app.js CHANGED
@@ -65,6 +65,16 @@ class AppBootHook {
65
65
  const eggRouterMiddleware = this.app.router.middleware();
66
66
  eggRouterMiddleware._name = 'eggRouterMiddleware';
67
67
  this.app.useMiddleware(eggRouterMiddleware);
68
+
69
+ if (process.env['EGG_CLUSTER_MODE'] === 'true') {
70
+ const lifeCycleService = this.app.applicationContext.get('midwayWebLifeCycleService');
71
+ // exec onReady()
72
+ await lifeCycleService.runReady();
73
+ // 多进程时的路由加载必须放在这里,中间件加载之后
74
+ const framework = this.app.applicationContext.get('midwayWebFramework');
75
+ await framework.loadMidwayController();
76
+ }
77
+
68
78
  this.app.emit('application-ready');
69
79
  }
70
80
 
package/dist/base.js CHANGED
@@ -132,9 +132,8 @@ const createAppWorkerLoader = () => {
132
132
  });
133
133
  // 这里生命周期走到 onReady
134
134
  this.lifecycleService = await applicationContext.getAsync(lifecycle_1.MidwayWebLifeCycleService, [applicationContext]);
135
- // 执行加载路由
135
+ // 执行加载框架初始化
136
136
  this.framework = await applicationContext.getAsync(web_1.MidwayWebFramework);
137
- await this.framework.loadMidwayController();
138
137
  });
139
138
  }
140
139
  }
@@ -29,7 +29,9 @@ let EggConfiguration = class EggConfiguration {
29
29
  }
30
30
  async onServerReady() {
31
31
  // trigger server didReady
32
- this.app.messenger.emit('egg-ready');
32
+ if (this.app.messenger) {
33
+ this.app.messenger.emit('egg-ready');
34
+ }
33
35
  }
34
36
  async onStop() {
35
37
  // TODO flush egg logger and close it
@@ -6,6 +6,7 @@ export declare class MidwayWebLifeCycleService {
6
6
  private lifecycleInstanceList;
7
7
  constructor(applicationContext: IMidwayContainer);
8
8
  protected init(): Promise<void>;
9
+ runReady(): Promise<void>;
9
10
  afterInit(): Promise<void>;
10
11
  stop(): Promise<void>;
11
12
  private runContainerLifeCycle;
@@ -53,6 +53,9 @@ let MidwayWebLifeCycleService = class MidwayWebLifeCycleService {
53
53
  this.configService.addObject(configData);
54
54
  }
55
55
  });
56
+ // cluster 下,onReady 放到 egg willReady 中执行
57
+ }
58
+ async runReady() {
56
59
  // exec onReady()
57
60
  await this.runContainerLifeCycle(this.lifecycleInstanceList, 'onReady');
58
61
  }
@@ -65,6 +68,12 @@ let MidwayWebLifeCycleService = class MidwayWebLifeCycleService {
65
68
  if (!this.configService.getConfiguration('debug.recordConfigMergeOrder')) {
66
69
  this.configService.clearConfigMergeOrder();
67
70
  }
71
+ // some preload module init
72
+ const modules = (0, decorator_1.listPreloadModule)();
73
+ for (const module of modules) {
74
+ // preload init context
75
+ await this.applicationContext.getAsync(module);
76
+ }
68
77
  }
69
78
  async stop() {
70
79
  // stop lifecycle
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -86,7 +86,7 @@ export interface IWebMiddleware {
86
86
  resolve(): MidwayWebMiddleware;
87
87
  }
88
88
  declare module '@midwayjs/core/dist/interface' {
89
- interface MidwayConfig extends Partial<EggAppConfig> {
89
+ interface MidwayConfig extends PowerPartial<EggAppConfig> {
90
90
  egg?: IMidwayWebConfigurationOptions;
91
91
  }
92
92
  }
package/dist/logger.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILogger } from '@midwayjs/logger';
1
+ import { ILogger, LoggerOptions } from '@midwayjs/logger';
2
2
  import { Application } from 'egg';
3
3
  import { MidwayLoggerService } from '@midwayjs/core';
4
4
  declare class MidwayLoggers extends Map<string, ILogger> {
@@ -28,7 +28,7 @@ declare class MidwayLoggers extends Map<string, ILogger> {
28
28
  createLogger(options: any, loggerKey: string): ILogger;
29
29
  disableConsole(): void;
30
30
  reload(): void;
31
- transformEggLogger(eggCustomLogger: any): {
31
+ transformEggLogger(eggCustomLogger: any, midwayLoggerConfig: LoggerOptions): {
32
32
  midwayLogger: {
33
33
  clients: {};
34
34
  };
package/dist/logger.js CHANGED
@@ -101,7 +101,7 @@ class MidwayLoggers extends Map {
101
101
  const configService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayConfigService);
102
102
  // 先把 egg 的日志配置转为 midway logger 配置
103
103
  if (configService.getConfiguration('customLogger')) {
104
- const eggLoggerConfig = this.transformEggLogger(configService.getConfiguration('customLogger'));
104
+ const eggLoggerConfig = this.transformEggLogger(configService.getConfiguration('customLogger'), configService.getConfiguration('midwayLogger.default'));
105
105
  if (eggLoggerConfig) {
106
106
  configService.addObject(eggLoggerConfig);
107
107
  }
@@ -139,10 +139,9 @@ class MidwayLoggers extends Map {
139
139
  return logger;
140
140
  }
141
141
  disableConsole() {
142
- var _a, _b;
143
142
  for (const value of this.values()) {
144
- if ((_a = value) === null || _a === void 0 ? void 0 : _a.disableConsole) {
145
- (_b = value) === null || _b === void 0 ? void 0 : _b.disableConsole();
143
+ if (value === null || value === void 0 ? void 0 : value.disableConsole) {
144
+ value === null || value === void 0 ? void 0 : value.disableConsole();
146
145
  }
147
146
  else if (value.disable) {
148
147
  value.disable('console');
@@ -157,18 +156,38 @@ class MidwayLoggers extends Map {
157
156
  }
158
157
  }
159
158
  }
160
- transformEggLogger(eggCustomLogger) {
161
- var _a, _b, _c;
159
+ transformEggLogger(eggCustomLogger, midwayLoggerConfig) {
160
+ var _a, _b, _c, _d;
162
161
  const transformLoggerConfig = {
163
162
  midwayLogger: {
164
163
  clients: {},
165
164
  },
166
165
  };
167
166
  for (const name in eggCustomLogger) {
167
+ const file = (_a = eggCustomLogger[name]) === null || _a === void 0 ? void 0 : _a.file;
168
+ if (!file) {
169
+ continue;
170
+ }
171
+ const options = {};
172
+ if ((0, path_1.isAbsolute)(file)) {
173
+ // 绝对路径,单独处理
174
+ options.dir = (0, path_1.dirname)(file);
175
+ options.fileLogName = (0, path_1.basename)(file);
176
+ options.auditFileDir =
177
+ midwayLoggerConfig.auditFileDir === '.audit'
178
+ ? (0, path_1.join)(midwayLoggerConfig.dir, '.audit')
179
+ : midwayLoggerConfig.auditFileDir;
180
+ options.errorDir =
181
+ (_b = midwayLoggerConfig.errorDir) !== null && _b !== void 0 ? _b : midwayLoggerConfig.dir;
182
+ }
183
+ else {
184
+ // 相对路径,使用默认的 dir 即可
185
+ options.fileLogName = file;
186
+ }
168
187
  transformLoggerConfig.midwayLogger.clients[name] = {
169
- fileLogName: (_a = eggCustomLogger[name]) === null || _a === void 0 ? void 0 : _a.file,
170
- level: levelTransform((_b = eggCustomLogger[name]) === null || _b === void 0 ? void 0 : _b.level),
171
- consoleLevel: levelTransform((_c = eggCustomLogger[name]) === null || _c === void 0 ? void 0 : _c.consoleLevel),
188
+ level: levelTransform((_c = eggCustomLogger[name]) === null || _c === void 0 ? void 0 : _c.level),
189
+ consoleLevel: levelTransform((_d = eggCustomLogger[name]) === null || _d === void 0 ? void 0 : _d.consoleLevel),
190
+ ...options,
172
191
  };
173
192
  cleanUndefinedProperty(transformLoggerConfig.midwayLogger.clients[name]);
174
193
  }
package/dist/utils.js CHANGED
@@ -72,21 +72,23 @@ async function initializeAgentApplicationContext(agent) {
72
72
  const aspectService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayAspectService);
73
73
  // init decorator service
74
74
  const decoratorService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayDecoratorService);
75
+ const configService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayConfigService);
76
+ const loggerService = (0, core_1.getCurrentApplicationContext)().get(core_1.MidwayLoggerService);
75
77
  // framework/config/plugin/logger/app decorator support
76
78
  // register base config hook
77
79
  decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
78
80
  var _a;
79
81
  if (meta.identifier === decorator_1.ALL) {
80
- return this.configService.getConfiguration();
82
+ return configService.getConfiguration();
81
83
  }
82
84
  else {
83
- return this.configService.getConfiguration((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
85
+ return configService.getConfiguration((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
84
86
  }
85
87
  });
86
88
  // register @Logger decorator handler
87
89
  decoratorService.registerPropertyHandler(decorator_1.LOGGER_KEY, (propertyName, meta) => {
88
90
  var _a;
89
- return this.loggerService.getLogger((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
91
+ return loggerService.getLogger((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
90
92
  });
91
93
  decoratorService.registerPropertyHandler(decorator_1.PIPELINE_IDENTIFIER, (key, meta, instance) => {
92
94
  var _a, _b;
@@ -97,7 +99,7 @@ async function initializeAgentApplicationContext(agent) {
97
99
  return agent;
98
100
  });
99
101
  decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
100
- return this.agent[key];
102
+ return agent[key];
101
103
  });
102
104
  // init aspect module
103
105
  await aspectService.loadAspect();
@@ -112,6 +114,9 @@ async function initializeAgentApplicationContext(agent) {
112
114
  agentFramework['appLogger'] = agent.coreLogger;
113
115
  agentFramework.app = agent;
114
116
  agentFramework.configService = applicationContext.get(core_1.MidwayConfigService);
117
+ agentFramework.environmentService = applicationContext.get(core_1.MidwayEnvironmentService);
118
+ agentFramework.loggerService = applicationContext.get(core_1.MidwayLoggerService);
119
+ agentFramework.informationService = applicationContext.get(core_1.MidwayInformationService);
115
120
  agentFramework.overwriteApplication('agent');
116
121
  return applicationContext;
117
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.1.0",
3
+ "version": "3.1.3",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -29,12 +29,12 @@
29
29
  "devDependencies": {
30
30
  "@midwayjs/decorator": "^3.0.10",
31
31
  "@midwayjs/logger": "^2.15.0",
32
- "@midwayjs/mock": "^3.1.0",
33
- "axios": "0.26.0",
32
+ "@midwayjs/mock": "^3.1.2",
33
+ "axios": "0.26.1",
34
34
  "dayjs": "1.10.8",
35
35
  "egg-logger": "2.7.1",
36
36
  "egg-mock": "4.2.0",
37
- "egg-scripts": "2.15.2",
37
+ "egg-scripts": "2.15.3",
38
38
  "egg-socket.io": "4.1.6",
39
39
  "egg-view-nunjucks": "2.3.0",
40
40
  "fake-egg": "1.0.0",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@eggjs/router": "^2.0.0",
49
- "@midwayjs/core": "^3.1.0",
49
+ "@midwayjs/core": "^3.1.2",
50
50
  "egg": "^2.28.0",
51
51
  "egg-cluster": "^1.27.1",
52
52
  "find-up": "5.0.0",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=12"
62
62
  },
63
- "gitHead": "2074c838e454a9673a044dbe065631dd9f944005"
63
+ "gitHead": "98d41a7a8b40d65f43df9655b1f5b4aebcdc091a"
64
64
  }