Skip to content

Commit

Permalink
fix: use @eggjs/jsonp and @eggjs/i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 11, 2025
1 parent 9849f8b commit 6325ab5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 97 deletions.
43 changes: 0 additions & 43 deletions index-old.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down Expand Up @@ -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<string | RegExp>;
// };

// /**
// * The key that signing cookies. It can contain multiple keys seperated by .
// */
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions site/docs/basics/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ 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
  - [development](https://github.com/eggjs/development) Development Environment Configuration
  - [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).

Expand Down
4 changes: 2 additions & 2 deletions site/docs/basics/plugin.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ 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) 安全
- [development](https://github.com/eggjs/development) 开发环境配置
- [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)

Expand Down
2 changes: 1 addition & 1 deletion site/docs/core/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion site/docs/core/i18n.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) 插件提供。

## 默认语言

Expand Down
6 changes: 2 additions & 4 deletions src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default {
// enable plugins

/**
* app global Error Handling
* @member {Object} Plugin#onerror
Expand Down Expand Up @@ -30,7 +28,7 @@ export default {
*/
i18n: {
enable: true,
package: 'egg-i18n',
package: '@eggjs/i18n',
},

/**
Expand Down Expand Up @@ -118,7 +116,7 @@ export default {
*/
jsonp: {
enable: true,
package: 'egg-jsonp',
package: '@eggjs/jsonp',
},

/**
Expand Down
43 changes: 2 additions & 41 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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<string | RegExp>;
};

/**
* The key that signing cookies. It can contain multiple keys separated by .
*/
Expand Down
21 changes: 21 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EggPlugin,
EggAppInfo,
start, SingleModeApplication, SingleModeAgent,
MiddlewareFunc,
} from '../src/index.js';
import { HttpClient } from '../src/urllib.js';

Expand All @@ -28,6 +29,26 @@ expectType<string>(app.config.watcher.eventSources.default);
expectType<boolean>(app.config.development.fastReady);
expectType<string[]>(app.config.development.watchDirs);

// jsonp plugin types
expectType<boolean>(app.config.jsonp.csrf);
expectType<string[] | string>(app.config.jsonp.callback);
expectType<number>(app.config.jsonp.limit);
expectType<string | RegExp |(string | RegExp)[]>(app.config.jsonp.whiteList!);
expectType<boolean>(ctx.acceptJSONP);
expectType<void>(ctx.createJsonpBody({}));
expectType<MiddlewareFunc>(app.jsonp());
expectType<MiddlewareFunc>(app.jsonp({ callback: 'callback' }));

// i18n plugin types
expectType<boolean>(app.config.i18n.writeCookie);
expectType<string>(app.config.i18n.defaultLocale);
expectType<string>(app.gettext('en-us', 'email'));
expectType<boolean>(app.isSupportLocale('en-us'));
expectType<string>(ctx.__('email'));
expectType<string>(ctx.gettext('email %s', 'fengmk2'));
expectType<string>(ctx.locale);
expectType<string>(ctx.locale = 'en-us');

class AppBoot implements ILifecycleBoot {
private readonly app: Application;

Expand Down
1 change: 0 additions & 1 deletion test/lib/core/loader/config_loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('test/lib/core/loader/config_loader.test.ts', () => {
'clusterAppMock',
'session',
'securities',
'i18n',
]);
});

Expand Down

0 comments on commit 6325ab5

Please sign in to comment.