Skip to content

Commit

Permalink
fix: logger should not Partial (#5393)
Browse files Browse the repository at this point in the history
<!-- 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 -->
  • Loading branch information
fengmk2 authored Feb 4, 2025
1 parent 1bc746b commit 8e433d9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@arethetypeswrong/cli": "^0.17.3",
"@eggjs/bin": "^7.0.2",
"@eggjs/koa": "^2.20.6",
"@eggjs/mock": "^6.0.5",
"@eggjs/mock": "^6.0.6",
"@eggjs/supertest": "^8.2.0",
"@eggjs/tsconfig": "1",
"@types/koa-bodyparser": "^4.3.12",
Expand Down
6 changes: 3 additions & 3 deletions site/docs/advanced/plugin.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ $ npm test
});
};
```

### 设置定时任务

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

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

#### 应用层使用方案

##### 单实例
Expand Down Expand Up @@ -435,6 +437,7 @@ class PostController extends Controller {
1. 应用根目录下的 `node_modules`
2. 应用依赖框架路径下的 `node_modules`
3. 当前路径下的 `node_modules`(主要是兼容单元测试场景)

### 插件规范

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

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


[egg-boilerplate-plugin]: https://github.com/eggjs/egg-boilerplate-plugin
[egg-mysql]: https://github.com/eggjs/egg-mysql
[egg-oss]: https://github.com/eggjs/egg-oss
12 changes: 6 additions & 6 deletions src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import type { EggAppInfo } from '@eggjs/core';
import type { EggAppConfig } from '../lib/types.js';
import type { EggAppInfo, Context } from '@eggjs/core';
import type { EggAppConfig, PowerPartial } from '../lib/types.js';
import { getSourceFile } from '../lib/utils.js';

/**
Expand All @@ -10,7 +10,7 @@ import { getSourceFile } from '../lib/utils.js';
* @since 1.0.0
*/
export default (appInfo: EggAppInfo) => {
const config: Partial<EggAppConfig> = {
const config: PowerPartial<EggAppConfig> = {
/**
* The environment of egg
* @member {String} Config#env
Expand All @@ -28,7 +28,7 @@ export default (appInfo: EggAppInfo) => {
name: appInfo.name,

/**
* The key that signing cookies. It can contain multiple keys seperated by `,`.
* The key that signing cookies. It can contain multiple keys separated by `,`.
* @member {String} Config#keys
* @see http://eggjs.org/en/core/cookie-and-session.html#cookie-secret-key
* @default
Expand Down Expand Up @@ -237,7 +237,7 @@ export default (appInfo: EggAppInfo) => {
parameterLimit: 1000,
},
onProtoPoisoning: 'error',
onerror(err, ctx) {
onerror(err: any, ctx: Context) {
err.message = `${err.message}, check bodyParser config`;
if (ctx.status === 404) {
// set default status to 400, meaning client bad request
Expand Down Expand Up @@ -299,7 +299,7 @@ export default (appInfo: EggAppInfo) => {
* @property {Number} httpAgent.maxFreeSockets - http agent max free socket number of one host, default is 256.
*
* @property {Boolean} httpsAgent.keepAlive - Enable https agent keepalive or not, default is true
* @property {Number} httpsAgent.freeSocketTimeout - httpss agent socket keepalive max free time, default is 4000 ms.
* @property {Number} httpsAgent.freeSocketTimeout - https agent socket keepalive max free time, default is 4000 ms.
* @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
* @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
* @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
Expand Down
4 changes: 2 additions & 2 deletions src/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EggAppConfig } from '../lib/types.js';
import type { EggAppConfig, PowerPartial } from '../lib/types.js';

export default () => {
return {
Expand All @@ -7,5 +7,5 @@ export default () => {
consoleLevel: 'WARN',
},
},
} satisfies Partial<EggAppConfig>;
} satisfies PowerPartial<EggAppConfig>;
};
4 changes: 2 additions & 2 deletions src/config/config.unittest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { EggAppConfig } from '../lib/types.js';
import type { EggAppConfig, PowerPartial } from '../lib/types.js';

export default () => {
return {
logger: {
consoleLevel: 'WARN',
buffer: false,
},
} satisfies Partial<EggAppConfig>;
} satisfies PowerPartial<EggAppConfig>;
};
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export interface EggAppConfig extends EggCoreAppConfig {
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
* @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to false
*/
logger: Partial<EggLoggerConfig>;
logger: EggLoggerConfig;

/** custom logger of egg */
customLogger: {
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function rimraf(target: string) {

export { MockApplication, MockOptions, MockClusterOptions, mm };
export interface SingleModeApplication extends MockApplication {
agent: SingleModeAgent;
agent: SingleModeAgent & MockApplication['agent'];
}

export const restore = () => mm.restore();
Expand Down

0 comments on commit 8e433d9

Please sign in to comment.