Skip to content

Commit

Permalink
export EggPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 2, 2025
1 parent 5bd9567 commit 8e1a12e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 40 deletions.
34 changes: 0 additions & 34 deletions index-old.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
// */
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "egg",
"version": "4.0.0-beta.12",
"version": "4.0.0-beta.13",
"engines": {
"node": ">= 18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.local.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EggAppConfig } from '../lib/type.js';
import type { EggAppConfig } from '../lib/types.js';

export default () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.unittest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EggAppConfig } from '../lib/type.js';
import type { EggAppConfig } from '../lib/types.js';

export default () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/egg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions src/lib/type.ts → src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,35 @@ export interface EggAppConfig {
}

export type RequestObjectBody = Record<string, any>;

/**
* 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;
}

31 changes: 31 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -67,3 +68,33 @@ expectType<ILifecycleBoot>(appBoot);
expectType<string[]>(appBoot.stages);

expectType<LoggerLevel>('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<EggPlugin>(plugin);

0 comments on commit 8e1a12e

Please sign in to comment.