From 2cd71ce50e3b57b792a67324822a6fd4ef9fbd0d Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 4 Feb 2025 23:30:44 +0800 Subject: [PATCH] fix: logger should not Partial --- package.json | 2 +- site/docs/advanced/plugin.zh-CN.md | 6 +++--- src/config/config.default.ts | 12 ++++++------ src/config/config.local.ts | 4 ++-- src/config/config.unittest.ts | 4 ++-- src/lib/types.ts | 2 +- test/utils.ts | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 77cb8a5064..98e818d59c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/site/docs/advanced/plugin.zh-CN.md b/site/docs/advanced/plugin.zh-CN.md index 3372cf9775..bdf5c78c3e 100644 --- a/site/docs/advanced/plugin.zh-CN.md +++ b/site/docs/advanced/plugin.zh-CN.md @@ -239,6 +239,7 @@ $ npm test }); }; ``` + ### 设置定时任务 1. 在 `package.json` 里设置依赖 schedule 插件 @@ -326,6 +327,7 @@ async function createMysql(config, app) { ``` 可以看到,插件中我们只需要提供要挂载的字段和服务的初始化方法,所有配置管理、实例获取方式由框架封装并统一提供。 + #### 应用层使用方案 ##### 单实例 @@ -435,6 +437,7 @@ class PostController extends Controller { 1. 应用根目录下的 `node_modules` 2. 应用依赖框架路径下的 `node_modules` 3. 当前路径下的 `node_modules`(主要是兼容单元测试场景) + ### 插件规范 我们非常欢迎你贡献新的插件,同时也希望你遵守下面一些规范: @@ -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 diff --git a/src/config/config.default.ts b/src/config/config.default.ts index 31fc19637d..68e8993680 100644 --- a/src/config/config.default.ts +++ b/src/config/config.default.ts @@ -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'; /** @@ -10,7 +10,7 @@ import { getSourceFile } from '../lib/utils.js'; * @since 1.0.0 */ export default (appInfo: EggAppInfo) => { - const config: Partial = { + const config: PowerPartial = { /** * The environment of egg * @member {String} Config#env @@ -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 @@ -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 @@ -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 diff --git a/src/config/config.local.ts b/src/config/config.local.ts index 479adc202f..d7139db96c 100644 --- a/src/config/config.local.ts +++ b/src/config/config.local.ts @@ -1,4 +1,4 @@ -import type { EggAppConfig } from '../lib/types.js'; +import type { EggAppConfig, PowerPartial } from '../lib/types.js'; export default () => { return { @@ -7,5 +7,5 @@ export default () => { consoleLevel: 'WARN', }, }, - } satisfies Partial; + } satisfies PowerPartial; }; diff --git a/src/config/config.unittest.ts b/src/config/config.unittest.ts index a9f64353b9..0694958b40 100644 --- a/src/config/config.unittest.ts +++ b/src/config/config.unittest.ts @@ -1,4 +1,4 @@ -import type { EggAppConfig } from '../lib/types.js'; +import type { EggAppConfig, PowerPartial } from '../lib/types.js'; export default () => { return { @@ -6,5 +6,5 @@ export default () => { consoleLevel: 'WARN', buffer: false, }, - } satisfies Partial; + } satisfies PowerPartial; }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 5f97e6ee55..2943aed880 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -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; + logger: EggLoggerConfig; /** custom logger of egg */ customLogger: { diff --git a/test/utils.ts b/test/utils.ts index d7d254d23f..4eb102e552 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -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();