From 25c65288936a06324325005fa6a7fe94ffa377eb Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 3 Jan 2025 17:55:36 +0800 Subject: [PATCH] export EggAppInfo --- index-old.d.ts | 24 ------------------------ src/app/extend/request.ts | 2 ++ src/app/extend/response.ts | 2 ++ src/lib/types.ts | 5 +++++ test/index.test-d.ts | 11 +++++++++++ 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/index-old.d.ts b/index-old.d.ts index 7793188a62..b09956ad21 100644 --- a/index-old.d.ts +++ b/index-old.d.ts @@ -218,30 +218,6 @@ // export type LoggerLevel = EggLoggerLevel; - -// /** -// * egg app info -// * @example -// * ```js -// * // config/config.default.ts -// * import { EggAppInfo } from 'egg'; -// * -// * export default (appInfo: EggAppInfo) => { -// * return { -// * keys: appInfo.name + '123456', -// * }; -// * } -// * ``` -// */ -// export interface EggAppInfo { -// pkg: any; // package.json -// name: string; // the application name from package.json -// baseDir: string; // current directory of application -// env: EggEnvType; // equals to serverEnv -// HOME: string; // home directory of the OS -// root: string; // baseDir when local and unittest, HOME when other environment -// } - // type IgnoreItem = string | RegExp | ((ctx: Context) => boolean); // type IgnoreOrMatch = IgnoreItem | IgnoreItem[]; diff --git a/src/app/extend/request.ts b/src/app/extend/request.ts index cd2ae0074c..623d248e54 100644 --- a/src/app/extend/request.ts +++ b/src/app/extend/request.ts @@ -11,6 +11,8 @@ const HOST = Symbol('request host'); const IPS = Symbol('request ips'); const RE_ARRAY_KEY = /[^\[\]]+\[\]$/; +import './request.types.js'; + export default class Request extends EggCoreRequest { declare app: Application; declare ctx: Context; diff --git a/src/app/extend/response.ts b/src/app/extend/response.ts index 3611a129b6..5c0e029047 100644 --- a/src/app/extend/response.ts +++ b/src/app/extend/response.ts @@ -2,6 +2,8 @@ import { Response as KoaResponse } from '@eggjs/core'; const REAL_STATUS = Symbol('response realStatus'); +import './response.types.js'; + export default class Response extends KoaResponse { /** * Get or set a real status code. diff --git a/src/lib/types.ts b/src/lib/types.ts index 890db19cf3..d16b55cf19 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -18,6 +18,11 @@ import type { SiteFileMiddlewareOptions } from '../app/middleware/site_file.js'; // import @eggjs/watcher types // import '@eggjs/watcher'; +export type { + EggAppInfo, +} from '@eggjs/core'; + + type IgnoreItem = string | RegExp | ((ctx: Context) => boolean); type IgnoreOrMatch = IgnoreItem | IgnoreItem[]; diff --git a/test/index.test-d.ts b/test/index.test-d.ts index 1b20fa1e66..d5f6e0fb83 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -3,6 +3,7 @@ import { Context, Application, IBoot, ILifecycleBoot, LoggerLevel, EggPlugin, + EggAppInfo, } from '../src/index.js'; import { HttpClient } from '../src/urllib.js'; @@ -98,3 +99,13 @@ const plugin: EggPlugin = { logrotator: true, }; expectType(plugin); + +expectType({ + name: 'egg', + baseDir: 'baseDir', + env: 'env', + HOME: 'HOME', + pkg: {}, + scope: 'scope', + root: 'root', +});