diff --git a/index-old.d.ts b/index-old.d.ts index 7f7e014db9..0ac54fdc97 100644 --- a/index-old.d.ts +++ b/index-old.d.ts @@ -34,13 +34,11 @@ // import EggCookies = require('egg-cookies'); // import 'egg-onerror'; // import 'egg-session'; -// import 'egg-i18n'; // import 'egg-multipart'; // import 'egg-security'; // import 'egg-logrotator'; // import '@eggjs/schedule'; // import 'egg-static'; -// import 'egg-jsonp'; // import 'egg-view'; // declare module 'egg' { @@ -400,52 +398,11 @@ // hostHeaders: string; -// /** -// * I18n options -// */ -// i18n: { -// /** -// * default value EN_US -// */ -// defaultLocale: string; -// /** -// * i18n resource file dir, not recommend to change default value -// */ -// dirs: string[]; -// /** -// * custom the locale value field, default `query.locale`, you can modify this config, such as `query.lang` -// */ -// queryField: string; -// /** -// * The locale value key in the cookie, default is locale. -// */ -// cookieField: string; -// /** -// * Locale cookie expire time, default `1y`, If pass number value, the unit will be ms -// */ -// cookieMaxAge: string | number; -// }; - // /** // * Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true. // */ // ipHeaders: string; -// /** -// * jsonp options -// * @member Config#jsonp -// * @property {String} callback - jsonp callback method key, default to `_callback` -// * @property {Number} limit - callback method name's max length, default to `50` -// * @property {Boolean} csrf - enable csrf check or not. default to false -// * @property {String|RegExp|Array} whiteList - referrer white list -// */ -// jsonp: { -// limit: number; -// callback: string; -// csrf: boolean; -// whiteList: string | RegExp | Array; -// }; - // /** // * The key that signing cookies. It can contain multiple keys seperated by . // */ diff --git a/package.json b/package.json index e7122888f1..e2131832a4 100644 --- a/package.json +++ b/package.json @@ -23,14 +23,14 @@ "@eggjs/cookies": "^3.0.0", "@eggjs/core": "^6.2.13", "@eggjs/development": "^4.0.0", + "@eggjs/i18n": "^3.0.0", + "@eggjs/jsonp": "^3.0.0", "@eggjs/schedule": "^5.0.2", "@eggjs/utils": "^4.2.4", "@eggjs/watcher": "^4.0.3", "circular-json-for-egg": "^1.0.0", "cluster-client": "^3.7.0", "egg-errors": "^2.3.1", - "egg-i18n": "^2.1.1", - "egg-jsonp": "^2.0.0", "egg-logger": "^3.6.0", "egg-logrotator": "^3.1.0", "egg-multipart": "^3.1.0", diff --git a/site/docs/basics/plugin.md b/site/docs/basics/plugin.md index b2d7126157..c49f27bf92 100644 --- a/site/docs/basics/plugin.md +++ b/site/docs/basics/plugin.md @@ -162,7 +162,7 @@ Specific consolidation rules can be found in [Configuration](./config.md). - Framework has default built-in plugins for enterprise applications [Common plugins](https://eggjs.org/zh-cn/plugins/):   - [onerror](/~https://github.com/eggjs/egg-onerror) Uniform Exception Handling   - [Session](/~https://github.com/eggjs/egg-session) Session implementation -   - [i18n](/~https://github.com/eggjs/egg-i18n) Multilingual +   - [i18n](/~https://github.com/eggjs/i18n) Multilingual   - [watcher](/~https://github.com/eggjs/watcher) File and folder monitoring   - [multipart](/~https://github.com/eggjs/egg-multipart) File Streaming Upload   - [security](/~https://github.com/eggjs/egg-security) Security @@ -170,7 +170,7 @@ Specific consolidation rules can be found in [Configuration](./config.md).   - [logrotator](/~https://github.com/eggjs/egg-logrotator) Log segmentation   - [schedule](/~https://github.com/eggjs/egg-schedule) Timing tasks   - [static](/~https://github.com/eggjs/egg-static) Static server -   - [jsonp](/~https://github.com/eggjs/egg-jsonp) jsonp support +   - [jsonp](/~https://github.com/eggjs/jsonp) jsonp support   - [view](/~https://github.com/eggjs/egg-view) Template Engine - More community plugins can be found on GitHub [egg-plugin](/~https://github.com/topics/egg-plugin). diff --git a/site/docs/basics/plugin.zh-CN.md b/site/docs/basics/plugin.zh-CN.md index 1f697166fd..17d6dd15f3 100644 --- a/site/docs/basics/plugin.zh-CN.md +++ b/site/docs/basics/plugin.zh-CN.md @@ -162,7 +162,7 @@ exports.mysql = { - 框架默认内置了企业级应用[常用的插件](https://eggjs.org/zh-cn/plugins/): - [onerror](/~https://github.com/eggjs/egg-onerror) 统一异常处理 - [Session](/~https://github.com/eggjs/egg-session) Session 实现 - - [i18n](/~https://github.com/eggjs/egg-i18n) 多语言 + - [i18n](/~https://github.com/eggjs/i18n) 多语言 - [watcher](/~https://github.com/eggjs/watcher) 文件和文件夹监控 - [multipart](/~https://github.com/eggjs/egg-multipart) 文件流式上传 - [security](/~https://github.com/eggjs/egg-security) 安全 @@ -170,7 +170,7 @@ exports.mysql = { - [logrotator](/~https://github.com/eggjs/egg-logrotator) 日志切分 - [schedule](/~https://github.com/eggjs/egg-schedule) 定时任务 - [static](/~https://github.com/eggjs/egg-static) 静态服务器 - - [jsonp](/~https://github.com/eggjs/egg-jsonp) jsonp 支持 + - [jsonp](/~https://github.com/eggjs/jsonp) jsonp 支持 - [view](/~https://github.com/eggjs/egg-view) 模板引擎 - 更多社区的插件可以在 GitHub 上搜索 [egg-plugin](/~https://github.com/topics/egg-plugin)。 diff --git a/site/docs/core/i18n.md b/site/docs/core/i18n.md index ba3f952381..040d36ae17 100644 --- a/site/docs/core/i18n.md +++ b/site/docs/core/i18n.md @@ -3,7 +3,7 @@ title: I18n Internationalization order: 11 --- -For developing the multi-language application, build-in I18n support by [egg-i18n](/~https://github.com/eggjs/egg-i18n) plugin +For developing the multi-language application, build-in I18n support by [@eggjs/i18n](/~https://github.com/eggjs/i18n) plugin ## Default Language diff --git a/site/docs/core/i18n.zh-CN.md b/site/docs/core/i18n.zh-CN.md index e99cee3fc8..bf4cf7bac6 100644 --- a/site/docs/core/i18n.zh-CN.md +++ b/site/docs/core/i18n.zh-CN.md @@ -3,7 +3,7 @@ title: 国际化(I18n) order: 11 --- -为了方便开发多语言应用,框架内置了国际化(I18n)支持,由 [egg-i18n](/~https://github.com/eggjs/egg-i18n) 插件提供。 +为了方便开发多语言应用,框架内置了国际化(I18n)支持,由 [@eggjs/i18n](/~https://github.com/eggjs/i18n) 插件提供。 ## 默认语言 diff --git a/src/config/plugin.ts b/src/config/plugin.ts index ab62e547bf..8ab7bffcef 100644 --- a/src/config/plugin.ts +++ b/src/config/plugin.ts @@ -1,6 +1,4 @@ export default { - // enable plugins - /** * app global Error Handling * @member {Object} Plugin#onerror @@ -30,7 +28,7 @@ export default { */ i18n: { enable: true, - package: 'egg-i18n', + package: '@eggjs/i18n', }, /** @@ -118,7 +116,7 @@ export default { */ jsonp: { enable: true, - package: 'egg-jsonp', + package: '@eggjs/jsonp', }, /** diff --git a/src/lib/types.ts b/src/lib/types.ts index dbe4ed513f..0724d2601b 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -19,6 +19,8 @@ import type { SiteFileMiddlewareOptions } from '../app/middleware/site_file.js'; // import plugins types import '@eggjs/watcher'; import '@eggjs/development'; +import '@eggjs/jsonp'; +import '@eggjs/i18n'; export type { EggAppInfo, @@ -209,32 +211,6 @@ export interface EggAppConfig extends EggCoreAppConfig { hostHeaders: string; - /** - * I18n options - */ - i18n: { - /** - * default value EN_US - */ - defaultLocale: string; - /** - * i18n resource file dir, not recommend to change default value - */ - dirs: string[]; - /** - * custom the locale value field, default `query.locale`, you can modify this config, such as `query.lang` - */ - queryField: string; - /** - * The locale value key in the cookie, default is locale. - */ - cookieField: string; - /** - * Locale cookie expire time, default `1y`, If pass number value, the unit will be ms - */ - cookieMaxAge: string | number; - }; - /** * Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true. */ @@ -249,21 +225,6 @@ export interface EggAppConfig extends EggCoreAppConfig { httpOnly?: boolean; }; - /** - * jsonp options - * @member Config#jsonp - * @property {String} callback - jsonp callback method key, default to `_callback` - * @property {Number} limit - callback method name's max length, default to `50` - * @property {Boolean} csrf - enable csrf check or not. default to false - * @property {String|RegExp|Array} whiteList - referrer white list - */ - jsonp: { - limit: number; - callback: string; - csrf: boolean; - whiteList: string | RegExp | Array; - }; - /** * The key that signing cookies. It can contain multiple keys separated by . */ diff --git a/test/index.test-d.ts b/test/index.test-d.ts index ac0229b347..f5d642a381 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -5,6 +5,7 @@ import { EggPlugin, EggAppInfo, start, SingleModeApplication, SingleModeAgent, + MiddlewareFunc, } from '../src/index.js'; import { HttpClient } from '../src/urllib.js'; @@ -28,6 +29,26 @@ expectType(app.config.watcher.eventSources.default); expectType(app.config.development.fastReady); expectType(app.config.development.watchDirs); +// jsonp plugin types +expectType(app.config.jsonp.csrf); +expectType(app.config.jsonp.callback); +expectType(app.config.jsonp.limit); +expectType(app.config.jsonp.whiteList!); +expectType(ctx.acceptJSONP); +expectType(ctx.createJsonpBody({})); +expectType(app.jsonp()); +expectType(app.jsonp({ callback: 'callback' })); + +// i18n plugin types +expectType(app.config.i18n.writeCookie); +expectType(app.config.i18n.defaultLocale); +expectType(app.gettext('en-us', 'email')); +expectType(app.isSupportLocale('en-us')); +expectType(ctx.__('email')); +expectType(ctx.gettext('email %s', 'fengmk2')); +expectType(ctx.locale); +expectType(ctx.locale = 'en-us'); + class AppBoot implements ILifecycleBoot { private readonly app: Application; diff --git a/test/lib/core/loader/config_loader.test.ts b/test/lib/core/loader/config_loader.test.ts index 8437daab99..17aa2c7ab1 100644 --- a/test/lib/core/loader/config_loader.test.ts +++ b/test/lib/core/loader/config_loader.test.ts @@ -22,7 +22,6 @@ describe('test/lib/core/loader/config_loader.test.ts', () => { 'clusterAppMock', 'session', 'securities', - 'i18n', ]); });