From 8e1a12efdbe8ecf504abdeaa742020ea449d1b65 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 3 Jan 2025 00:36:59 +0800 Subject: [PATCH] export EggPlugin --- index-old.d.ts | 34 ---------------------------------- package.json | 2 +- src/config/config.default.ts | 2 +- src/config/config.local.ts | 2 +- src/config/config.unittest.ts | 2 +- src/index.ts | 2 +- src/lib/egg.ts | 2 +- src/lib/{type.ts => types.ts} | 32 ++++++++++++++++++++++++++++++++ test/index.test-d.ts | 31 +++++++++++++++++++++++++++++++ 9 files changed, 69 insertions(+), 40 deletions(-) rename src/lib/{type.ts => types.ts} (94%) diff --git a/index-old.d.ts b/index-old.d.ts index b187499352..7793188a62 100644 --- a/index-old.d.ts +++ b/index-old.d.ts @@ -1082,40 +1082,6 @@ // urlFor(name: string, params?: PlainObject): string; // } -// // egg env type -// export type EggEnvType = 'local' | 'unittest' | 'prod' | string; - -// /** -// * plugin config item interface -// */ -// export interface IEggPluginItem { -// env?: EggEnvType[]; -// path?: string; -// package?: string; -// enable?: boolean; -// } - -// export type EggPluginItem = IEggPluginItem | boolean; - -// /** -// * build-in plugin list -// */ -// export interface EggPlugin { -// [key: string]: EggPluginItem | undefined; -// onerror?: EggPluginItem; -// session?: EggPluginItem; -// i18n?: EggPluginItem; -// watcher?: EggPluginItem; -// multipart?: EggPluginItem; -// security?: EggPluginItem; -// development?: EggPluginItem; -// logrotator?: EggPluginItem; -// schedule?: EggPluginItem; -// static?: EggPluginItem; -// jsonp?: EggPluginItem; -// view?: EggPluginItem; -// } - // /** // * Singleton instance in Agent Worker, extend {@link EggApplication} // */ diff --git a/package.json b/package.json index 1278f7f069..77925a68c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "egg", - "version": "4.0.0-beta.12", + "version": "4.0.0-beta.13", "engines": { "node": ">= 18.19.0" }, diff --git a/src/config/config.default.ts b/src/config/config.default.ts index e9525b4f26..31fc19637d 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/type.js'; +import type { EggAppConfig } from '../lib/types.js'; import { getSourceFile } from '../lib/utils.js'; /** diff --git a/src/config/config.local.ts b/src/config/config.local.ts index 6ba0294b1a..479adc202f 100644 --- a/src/config/config.local.ts +++ b/src/config/config.local.ts @@ -1,4 +1,4 @@ -import type { EggAppConfig } from '../lib/type.js'; +import type { EggAppConfig } from '../lib/types.js'; export default () => { return { diff --git a/src/config/config.unittest.ts b/src/config/config.unittest.ts index 3c16597396..a9f64353b9 100644 --- a/src/config/config.unittest.ts +++ b/src/config/config.unittest.ts @@ -1,4 +1,4 @@ -import type { EggAppConfig } from '../lib/type.js'; +import type { EggAppConfig } from '../lib/types.js'; export default () => { return { diff --git a/src/index.ts b/src/index.ts index e7b12424f5..c4b71b0e6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,7 +17,7 @@ export type { // export types export * from './lib/egg.js'; -export * from './lib/type.js'; +export * from './lib/types.js'; export * from './lib/start.js'; // export errors diff --git a/src/lib/egg.ts b/src/lib/egg.ts index 66498fc6af..d78c7d297f 100644 --- a/src/lib/egg.ts +++ b/src/lib/egg.ts @@ -27,7 +27,7 @@ import CircularJSON from 'circular-json-for-egg'; import type { Agent } from './agent.js'; import type { Application } from './application.js'; import Context from '../app/extend/context.js'; -import type { EggAppConfig } from './type.js'; +import type { EggAppConfig } from './types.js'; import { create as createMessenger, IMessenger } from './core/messenger/index.js'; import { ContextHttpClient } from './core/context_httpclient.js'; import { diff --git a/src/lib/type.ts b/src/lib/types.ts similarity index 94% rename from src/lib/type.ts rename to src/lib/types.ts index 32c6f47ac5..890db19cf3 100644 --- a/src/lib/type.ts +++ b/src/lib/types.ts @@ -333,3 +333,35 @@ export interface EggAppConfig { } export type RequestObjectBody = Record; + +/** + * plugin config item interface + */ +export interface IEggPluginItem { + env?: EggEnvType[]; + path?: string; + package?: string; + enable?: boolean; +} + +export type EggPluginItem = IEggPluginItem | boolean; + +/** + * build-in plugin list + */ +export interface EggPlugin { + [key: string]: EggPluginItem | undefined; + onerror?: EggPluginItem; + session?: EggPluginItem; + i18n?: EggPluginItem; + watcher?: EggPluginItem; + multipart?: EggPluginItem; + security?: EggPluginItem; + development?: EggPluginItem; + logrotator?: EggPluginItem; + schedule?: EggPluginItem; + static?: EggPluginItem; + jsonp?: EggPluginItem; + view?: EggPluginItem; +} + diff --git a/test/index.test-d.ts b/test/index.test-d.ts index b87291a995..1b20fa1e66 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -2,6 +2,7 @@ import { expectType } from 'tsd'; import { Context, Application, IBoot, ILifecycleBoot, LoggerLevel, + EggPlugin, } from '../src/index.js'; import { HttpClient } from '../src/urllib.js'; @@ -67,3 +68,33 @@ expectType(appBoot); expectType(appBoot.stages); expectType('DEBUG'); + +const plugin: EggPlugin = { + tegg: { + enable: true, + package: '@eggjs/tegg-plugin', + }, + teggConfig: { + enable: true, + package: '@eggjs/tegg-config', + }, + teggController: { + enable: true, + package: '@eggjs/tegg-controller-plugin', + }, + teggSchedule: { + enable: true, + package: '@eggjs/tegg-schedule-plugin', + }, + eventbusModule: { + enable: true, + package: '@eggjs/tegg-eventbus-plugin', + }, + aopModule: { + enable: true, + package: '@eggjs/tegg-aop-plugin', + }, + onerror: true, + logrotator: true, +}; +expectType(plugin);