From 87389558663385216363168422cb305bf05a3cb4 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Tue, 4 Feb 2025 00:44:11 +0800 Subject: [PATCH] f --- index-old.d.ts | 15 --------------- package.json | 2 +- site/docs/advanced/view-plugin.zh-CN.md | 1 + site/docs/core/view.md | 2 +- site/docs/tutorials/index.md | 2 +- site/docs/tutorials/index.zh-CN.md | 2 +- site/docs/tutorials/typescript.zh-CN.md | 3 ++- src/config/plugin.ts | 2 +- src/lib/types.ts | 1 + test/index.test-d.ts | 9 +++++++++ 10 files changed, 18 insertions(+), 21 deletions(-) diff --git a/index-old.d.ts b/index-old.d.ts index 4e48b26f4f..4ca765a383 100644 --- a/index-old.d.ts +++ b/index-old.d.ts @@ -32,7 +32,6 @@ // BaseContextClass as CoreBaseContextClass, // } from 'egg-core'; // import EggCookies = require('egg-cookies'); -// import 'egg-view'; // declare module 'egg' { // export type EggLogger = Logger; @@ -1042,20 +1041,6 @@ // export function start(options?: StartOptions): Promise; -// /** -// * Powerful Partial, Support adding ? modifier to a mapped property in deep level -// * @example -// * import { PowerPartial, EggAppConfig } from 'egg'; -// * -// * // { view: { defaultEngines: string } } => { view?: { defaultEngines?: string } } -// * type EggConfig = PowerPartial -// */ -// export type PowerPartial = { -// [U in keyof T]?: T[U] extends object -// ? PowerPartial -// : T[U] -// }; - // // send data can be number|string|boolean|object but not Set|Map // export interface Messenger extends EventEmitter { // /** diff --git a/package.json b/package.json index 526993ed05..1855962733 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,12 @@ "@eggjs/session": "^4.0.1", "@eggjs/static": "^3.0.0", "@eggjs/utils": "^4.2.5", + "@eggjs/view": "^3.0.1", "@eggjs/watcher": "^4.0.4", "circular-json-for-egg": "^1.0.0", "cluster-client": "^3.7.0", "egg-errors": "^2.3.2", "egg-logger": "^3.6.1", - "egg-view": "^2.1.4", "extend2": "^4.0.0", "graceful": "^2.0.0", "humanize-ms": "^2.0.0", diff --git a/site/docs/advanced/view-plugin.zh-CN.md b/site/docs/advanced/view-plugin.zh-CN.md index 75ec524668..b29bfad552 100644 --- a/site/docs/advanced/view-plugin.zh-CN.md +++ b/site/docs/advanced/view-plugin.zh-CN.md @@ -8,6 +8,7 @@ order: 5 本文将阐述框架对 View 插件的规范约束。我们可以依此来封装对应的模板引擎插件。以下以 [egg-view-ejs](https://github.com/eggjs/egg-view-ejs) 为例。 ## 插件目录结构 + ```bash egg-view-ejs ├── config diff --git a/site/docs/core/view.md b/site/docs/core/view.md index 174ca42a36..5051286d54 100644 --- a/site/docs/core/view.md +++ b/site/docs/core/view.md @@ -222,4 +222,4 @@ The built-in plugin [@eggjs/security] provides common security helper functions, [@eggjs/security]: https://github.com/eggjs/security [egg-view-nunjucks]: https://github.com/eggjs/egg-view-nunjucks -[egg-view]: https://github.com/eggjs/egg-view +[egg-view]: https://github.com/eggjs/view diff --git a/site/docs/tutorials/index.md b/site/docs/tutorials/index.md index a10794d048..18b980b58e 100644 --- a/site/docs/tutorials/index.md +++ b/site/docs/tutorials/index.md @@ -51,7 +51,7 @@ Official maintained ORM model is [egg-orm] base on [Leoric], and the following d [egg-sequelize]: https://github.com/eggjs/egg-sequelize [egg-mongoose]: https://github.com/eggjs/egg-mongoose [egg-mysql]: https://github.com/eggjs/egg-mysql -[egg-view]: https://github.com/eggjs/egg-view +[egg-view]: https://github.com/eggjs/view [egg-view-nunjucks]: https://github.com/eggjs/egg-view-nunjucks [egg-view-ejs]: https://github.com/eggjs/egg-view-ejs [egg-view-handlebars]: https://github.com/eggjs/egg-view-handlebars diff --git a/site/docs/tutorials/index.zh-CN.md b/site/docs/tutorials/index.zh-CN.md index b2bad980fe..9023c8fffa 100644 --- a/site/docs/tutorials/index.zh-CN.md +++ b/site/docs/tutorials/index.zh-CN.md @@ -53,7 +53,7 @@ $ npm init egg --type=simple [egg-sequelize]: https://github.com/eggjs/egg-sequelize [egg-mongoose]: https://github.com/eggjs/egg-mongoose [egg-mysql]: https://github.com/eggjs/egg-mysql -[egg-view]: https://github.com/eggjs/egg-view +[egg-view]: https://github.com/eggjs/view [egg-view-nunjucks]: https://github.com/eggjs/egg-view-nunjucks [egg-view-ejs]: https://github.com/eggjs/egg-view-ejs [egg-view-handlebars]: https://github.com/eggjs/egg-view-handlebars diff --git a/site/docs/tutorials/typescript.zh-CN.md b/site/docs/tutorials/typescript.zh-CN.md index 27d39dae1f..bf80dd2179 100644 --- a/site/docs/tutorials/typescript.zh-CN.md +++ b/site/docs/tutorials/typescript.zh-CN.md @@ -706,8 +706,9 @@ describe('typescript', () => { 以下几个项目可作为单元测试参考: - [https://github.com/eggjs/egg](https://github.com/eggjs/egg) -- [https://github.com/eggjs/egg-view](https://github.com/eggjs/egg-view) +- [https://github.com/eggjs/view](https://github.com/eggjs/view) - [https://github.com/eggjs/egg-logger](https://github.com/eggjs/egg-logger) + ### 编译速度慢? 根据我们的实践,`ts-node` 是目前相对较优的解决方案,既不用另起终端执行 `tsc`,也能获得还能接受的启动速度(仅限于 `ts-node@7`,新的版本由于把文件缓存去掉了,导致特别慢([#754](https://github.com/TypeStrong/ts-node/issues/754)),因此未升级)。 diff --git a/src/config/plugin.ts b/src/config/plugin.ts index 0d583245e0..305575dec4 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -127,6 +127,6 @@ export default { */ view: { enable: true, - package: 'egg-view', + package: '@eggjs/view', }, }; diff --git a/src/lib/types.ts b/src/lib/types.ts index 6c03ab88b3..82c925c04b 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -28,6 +28,7 @@ import '@eggjs/session'; import '@eggjs/onerror'; import '@eggjs/logrotator'; import '@eggjs/multipart'; +import '@eggjs/view'; export type { EggAppInfo, diff --git a/test/index.test-d.ts b/test/index.test-d.ts index 9b0f4004c9..9f5ffee717 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -91,6 +91,15 @@ expectType(app.config.multipart.cleanSchedule.cron); expectType(app.config.multipart.defaultCharset); expectType<'file' | 'stream'>(app.config.multipart.mode); +// view plugin types +expectType(app.config.view.defaultViewEngine); +expectType(app.config.view.root); +expectType(app.config.view.mapping.html); +expectType(app.config.view.defaultExtension); +expectType(await ctx.renderString('hello')); +expectType(await ctx.view.renderString('hello')); +const ViewEngine = app.view.get('html')!; +expectType(await new ViewEngine(ctx).render('hello')); class AppBoot implements ILifecycleBoot { private readonly app: Application;