Skip to content

Commit 8e433d9

Browse files
authored
fix: logger should not Partial (#5393)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Documentation** - Expanded plugin development guides now include sections on scheduled tasks, best practices for global instance plugins, application usage scenarios, addressing rules, and plugin standards. - **Chores** - Upgraded the development mock dependency to improve reliability. - Made internal enhancements to configuration and testing setups that bolster overall system robustness. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1bc746b commit 8e433d9

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@arethetypeswrong/cli": "^0.17.3",
5656
"@eggjs/bin": "^7.0.2",
5757
"@eggjs/koa": "^2.20.6",
58-
"@eggjs/mock": "^6.0.5",
58+
"@eggjs/mock": "^6.0.6",
5959
"@eggjs/supertest": "^8.2.0",
6060
"@eggjs/tsconfig": "1",
6161
"@types/koa-bodyparser": "^4.3.12",

site/docs/advanced/plugin.zh-CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ $ npm test
239239
});
240240
};
241241
```
242+
242243
### 设置定时任务
243244

244245
1.`package.json` 里设置依赖 schedule 插件
@@ -326,6 +327,7 @@ async function createMysql(config, app) {
326327
```
327328

328329
可以看到,插件中我们只需要提供要挂载的字段和服务的初始化方法,所有配置管理、实例获取方式由框架封装并统一提供。
330+
329331
#### 应用层使用方案
330332

331333
##### 单实例
@@ -435,6 +437,7 @@ class PostController extends Controller {
435437
1. 应用根目录下的 `node_modules`
436438
2. 应用依赖框架路径下的 `node_modules`
437439
3. 当前路径下的 `node_modules`(主要是兼容单元测试场景)
440+
438441
### 插件规范
439442

440443
我们非常欢迎你贡献新的插件,同时也希望你遵守下面一些规范:
@@ -479,7 +482,4 @@ Egg 通过 `eggPlugin.name` 来定义插件名,只需应用或框架具备唯
479482

480483
**将相同功能的插件赋予相同的插件名,以及提供相同的 API,可以快速进行切换**。这种做法在模板、数据库等领域非常适用。
481484

482-
483485
[egg-boilerplate-plugin]: https://github.com/eggjs/egg-boilerplate-plugin
484-
[egg-mysql]: https://github.com/eggjs/egg-mysql
485-
[egg-oss]: https://github.com/eggjs/egg-oss

src/config/config.default.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path';
22
import { pathToFileURL } from 'node:url';
3-
import type { EggAppInfo } from '@eggjs/core';
4-
import type { EggAppConfig } from '../lib/types.js';
3+
import type { EggAppInfo, Context } from '@eggjs/core';
4+
import type { EggAppConfig, PowerPartial } from '../lib/types.js';
55
import { getSourceFile } from '../lib/utils.js';
66

77
/**
@@ -10,7 +10,7 @@ import { getSourceFile } from '../lib/utils.js';
1010
* @since 1.0.0
1111
*/
1212
export default (appInfo: EggAppInfo) => {
13-
const config: Partial<EggAppConfig> = {
13+
const config: PowerPartial<EggAppConfig> = {
1414
/**
1515
* The environment of egg
1616
* @member {String} Config#env
@@ -28,7 +28,7 @@ export default (appInfo: EggAppInfo) => {
2828
name: appInfo.name,
2929

3030
/**
31-
* The key that signing cookies. It can contain multiple keys seperated by `,`.
31+
* The key that signing cookies. It can contain multiple keys separated by `,`.
3232
* @member {String} Config#keys
3333
* @see http://eggjs.org/en/core/cookie-and-session.html#cookie-secret-key
3434
* @default
@@ -237,7 +237,7 @@ export default (appInfo: EggAppInfo) => {
237237
parameterLimit: 1000,
238238
},
239239
onProtoPoisoning: 'error',
240-
onerror(err, ctx) {
240+
onerror(err: any, ctx: Context) {
241241
err.message = `${err.message}, check bodyParser config`;
242242
if (ctx.status === 404) {
243243
// set default status to 400, meaning client bad request
@@ -299,7 +299,7 @@ export default (appInfo: EggAppInfo) => {
299299
* @property {Number} httpAgent.maxFreeSockets - http agent max free socket number of one host, default is 256.
300300
*
301301
* @property {Boolean} httpsAgent.keepAlive - Enable https agent keepalive or not, default is true
302-
* @property {Number} httpsAgent.freeSocketTimeout - httpss agent socket keepalive max free time, default is 4000 ms.
302+
* @property {Number} httpsAgent.freeSocketTimeout - https agent socket keepalive max free time, default is 4000 ms.
303303
* @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
304304
* @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
305305
* @property {Boolean} useHttpClientNext - use urllib@3 HttpClient

src/config/config.local.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EggAppConfig } from '../lib/types.js';
1+
import type { EggAppConfig, PowerPartial } from '../lib/types.js';
22

33
export default () => {
44
return {
@@ -7,5 +7,5 @@ export default () => {
77
consoleLevel: 'WARN',
88
},
99
},
10-
} satisfies Partial<EggAppConfig>;
10+
} satisfies PowerPartial<EggAppConfig>;
1111
};

src/config/config.unittest.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { EggAppConfig } from '../lib/types.js';
1+
import type { EggAppConfig, PowerPartial } from '../lib/types.js';
22

33
export default () => {
44
return {
55
logger: {
66
consoleLevel: 'WARN',
77
buffer: false,
88
},
9-
} satisfies Partial<EggAppConfig>;
9+
} satisfies PowerPartial<EggAppConfig>;
1010
};

src/lib/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export interface EggAppConfig extends EggCoreAppConfig {
168168
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
169169
* @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to false
170170
*/
171-
logger: Partial<EggLoggerConfig>;
171+
logger: EggLoggerConfig;
172172

173173
/** custom logger of egg */
174174
customLogger: {

test/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function rimraf(target: string) {
2626

2727
export { MockApplication, MockOptions, MockClusterOptions, mm };
2828
export interface SingleModeApplication extends MockApplication {
29-
agent: SingleModeAgent;
29+
agent: SingleModeAgent & MockApplication['agent'];
3030
}
3131

3232
export const restore = () => mm.restore();

0 commit comments

Comments
 (0)