@midwayjs/web 3.0.14-beta.2 → 3.1.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/LICENSE +21 -0
- package/app/extend/context.js +1 -1
- package/app.js +7 -0
- package/dist/base.js +1 -2
- package/dist/configuration.js +3 -1
- package/dist/framework/lifecycle.js +6 -0
- package/dist/index.js +5 -1
- package/dist/logger.d.ts +2 -2
- package/dist/logger.js +28 -9
- package/dist/utils.js +8 -4
- package/package.json +6 -6
- package/CHANGELOG.md +0 -1376
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 - Now midwayjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/app/extend/context.js
CHANGED
package/app.js
CHANGED
|
@@ -65,6 +65,13 @@ 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
|
+
// 多进程时的路由加载必须放在这里,中间件加载之后
|
|
71
|
+
const framework = this.app.applicationContext.get('midwayWebFramework');
|
|
72
|
+
await framework.loadMidwayController();
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
this.app.emit('application-ready');
|
|
69
76
|
}
|
|
70
77
|
|
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
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -29,7 +29,9 @@ let EggConfiguration = class EggConfiguration {
|
|
|
29
29
|
}
|
|
30
30
|
async onServerReady() {
|
|
31
31
|
// trigger server didReady
|
|
32
|
-
this.app.messenger
|
|
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
|
|
@@ -65,6 +65,12 @@ let MidwayWebLifeCycleService = class MidwayWebLifeCycleService {
|
|
|
65
65
|
if (!this.configService.getConfiguration('debug.recordConfigMergeOrder')) {
|
|
66
66
|
this.configService.clearConfigMergeOrder();
|
|
67
67
|
}
|
|
68
|
+
// some preload module init
|
|
69
|
+
const modules = (0, decorator_1.listPreloadModule)();
|
|
70
|
+
for (const module of modules) {
|
|
71
|
+
// preload init context
|
|
72
|
+
await this.applicationContext.getAsync(module);
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
async stop() {
|
|
70
76
|
// 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.
|
|
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];
|
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 (
|
|
145
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
|
82
|
+
return configService.getConfiguration();
|
|
81
83
|
}
|
|
82
84
|
else {
|
|
83
|
-
return
|
|
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
|
|
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
|
|
102
|
+
return agent[key];
|
|
101
103
|
});
|
|
102
104
|
// init aspect module
|
|
103
105
|
await aspectService.loadAspect();
|
|
@@ -108,6 +110,8 @@ async function initializeAgentApplicationContext(agent) {
|
|
|
108
110
|
}
|
|
109
111
|
const applicationContext = (0, core_1.getCurrentApplicationContext)();
|
|
110
112
|
const agentFramework = new web_1.MidwayWebFramework(applicationContext);
|
|
113
|
+
agentFramework['logger'] = agent.logger;
|
|
114
|
+
agentFramework['appLogger'] = agent.coreLogger;
|
|
111
115
|
agentFramework.app = agent;
|
|
112
116
|
agentFramework.configService = applicationContext.get(core_1.MidwayConfigService);
|
|
113
117
|
agentFramework.overwriteApplication('agent');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/web",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.2",
|
|
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.
|
|
33
|
-
"axios": "0.26.
|
|
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.
|
|
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.
|
|
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": "
|
|
63
|
+
"gitHead": "4ff3aa892b76d016f0ea123c7f9520d054d5c96b"
|
|
64
64
|
}
|