From da6c193100d900c7a43e65b4308a3f31399968b9 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 23 Jun 2024 21:41:39 +0800 Subject: [PATCH 1/4] fix: should export everything --- src/index.ts | 10 +- src/types.ts | 447 -------------------------------------------- src/utils/timing.ts | 2 +- 3 files changed, 9 insertions(+), 450 deletions(-) delete mode 100644 src/types.ts diff --git a/src/index.ts b/src/index.ts index 8d4338d..acc0491 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,12 @@ import utils from './utils/index.js'; +export { utils }; + export * from './egg.js'; -export * from './loader/egg_loader.js'; export * from './base_context_class.js'; -export { utils }; +export * from './lifecycle.js'; +export * from './loader/egg_loader.js'; +export * from './loader/file_loader.js'; +export * from './loader/context_loader.js'; +export * from './utils/sequencify.js'; +export * from './utils/timing.js'; diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index 9894733..0000000 --- a/src/types.ts +++ /dev/null @@ -1,447 +0,0 @@ -// import type KoaApplication from '@eggjs/koa'; -// // import type depd = require('depd'); -// import type { Logger } from 'egg-logger'; - -// export type EggType = 'application' | 'agent'; - -// interface PlainObject { -// [key: string]: T; -// } - -// export interface EggCoreOptions { -// /** egg type, application or agent */ -// type?: EggType; -// /** the directory of application */ -// baseDir?: EggAppInfo['baseDir']; -// /** server scope */ -// serverScope?: string; -// /** custom plugins */ -// plugins?: Plugins; -// } - -// export interface EggLoaderOptions { -// /** Application instance */ -// app: EggCore; -// /** the directory of application */ -// baseDir: EggAppInfo['baseDir']; -// /** egg logger */ -// logger: Logger; -// /** server scope */ -// serverScope?: string; -// /** custom plugins */ -// plugins?: Plugins; -// } - -// export interface PluginInfo { -// /** the plugin name, it can be used in `dep` */ -// name: string; -// /** the package name of plugin */ -// package: string; -// /** whether enabled */ -// enable: boolean; -// /** the directory of the plugin package */ -// path: string; -// /** the dependent plugins, you can use the plugin name */ -// dependencies: string[]; -// /** the optional dependent plugins. */ -// optionalDependencies: string[]; -// /** specify the serverEnv that only enable the plugin in it */ -// env: string[]; -// /** the file plugin config in. */ -// from: string; -// } - -// export interface Plugins extends PlainObject { } - -// export interface EggCoreBase extends KoaApplication { -// /** -// * Whether `application` or `agent` -// * @member {String} -// * @since 1.0.0 -// */ -// type: EggType; - -// /** -// * The current directory of application -// * @member {String} -// * @see {@link EggAppInfo#baseDir} -// * @since 1.0.0 -// */ -// baseDir: EggAppInfo['baseDir']; - -// /** -// * The name of application -// * @member {String} -// * @see {@link EggAppInfo#name} -// * @since 1.0.0 -// */ -// name: EggAppInfo['name']; - -// /** -// * Convert a generator function to a promisable one. -// * -// * Notice: for other kinds of functions, it directly returns you what it is. -// * -// * @param {Function} fn The inputted function. -// * @return {AsyncFunction} An async promise-based function. -// * @example -// * ```javascript -// * const fn = function* (arg) { -// return arg; -// }; -// const wrapped = app.toAsyncFunction(fn); -// wrapped(true).then((value) => console.log(value)); -// * ``` -// */ -// toAsyncFunction(fn: (...args: any[]) => IterableIterator): (...args: any[]) => Promise; - -// /** -// * Convert an object with generator functions to a Promisable one. -// * @param {Mixed} obj The inputted object. -// * @return {Promise} A Promisable result. -// * @example -// * ```javascript -// * const fn = function* (arg) { -// return arg; -// }; -// const arr = [ fn(1), fn(2) ]; -// const promise = app.toPromise(arr); -// promise.then(res => console.log(res)); -// * ``` -// */ -// toPromise(obj: any): Promise; - -// /** -// * register an callback function that will be invoked when application is ready. -// * @see https://github.com/node-modules/ready -// * @since 1.0.0 -// * @param {boolean|Error|Function} flagOrFunction - -// * @return {Promise|null} return promise when argument is undefined -// * @example -// * const app = new Application(...); -// * app.ready(err => { -// * if (err) throw err; -// * console.log('done'); -// * }); -// */ -// ready(fn?: (err?: Error) => void): any; - -// /** -// * Close all, it wil close -// * - callbacks registered by beforeClose -// * - emit `close` event -// * - remove add listeners -// * -// * If error is thrown when it's closing, the promise will reject. -// * It will also reject after following call. -// * @return {Promise} promise -// * @since 1.0.0 -// */ -// close(): Promise; - -// /** -// * If a client starts asynchronously, you can register `readyCallback`, -// * then the application will wait for the callback to ready -// * -// * It will log when the callback is not invoked after 10s -// * -// * Recommend to use {@link EggCore#beforeStart} -// * @since 1.0.0 -// * -// * @param {String} name - readyCallback task name -// * @param {object} opts - -// * - {Number} [timeout=10000] - emit `ready_timeout` when it doesn't finish but reach the timeout -// * - {Boolean} [isWeakDep=false] - whether it's a weak dependency -// * @return {Function} - a callback -// * @example -// * const done = app.readyCallback('mysql'); -// * mysql.ready(done); -// */ -// readyCallback(name: string, opts?: { timeout?: number; isWeakDep?: boolean }): () => void; - -// /** -// * The loader instance, the default class is {@link EggLoader}. -// * If you want define -// * @member {EggLoader} EggCore#loader -// * @since 1.0.0 -// */ -// loader: EggLoader; - -// /** -// * The configuration of application -// * @member {Config} -// * @since 1.0.0 -// */ -// config: Config; - -// /** -// * Retrieve enabled plugins -// * @member {Object} -// * @since 1.0.0 -// */ -// plugins: Plugins; - -// /** -// * Register a function that will be called when app close -// */ -// beforeClose(fn: () => void): void; - -// /** -// * Execute scope after loaded and before app start -// */ -// beforeStart(scope: () => void): void; - -// /** -// * Alias to {@link https://npmjs.com/package/depd} -// * @member {Function} -// * @since 1.0.0 -// */ -// deprecate: depd.Deprecate; -// } - -// export interface EggCore extends EggCoreBase { -// Controller: typeof BaseContextClass; -// Service: typeof BaseContextClass; -// } - -// export class EggCore { -// /** -// * @class -// * @param {Object} options - options -// * @param {String} [options.baseDir=process.cwd()] - the directory of application -// * @param {String} [options.type=application|agent] - whether it's running in app worker or agent worker -// * @param {Object} [options.plugins] - custom plugins -// * @since 1.0.0 -// */ -// constructor(options?: EggCoreOptions); -// } - -// /** -// * 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 { -// /** package.json */ -// pkg: PlainObject; -// /** the application name from package.json */ -// name: string; -// /** current directory of application */ -// baseDir: string; -// /** equals to serverEnv */ -// env: string; -// /** home directory of the OS */ -// HOME: string; -// /** baseDir when local and unittest, HOME when other environment */ -// root: string; -// } - -// /** -// * BaseContextClass is a base class that can be extended, -// * it's instantiated in context level, -// * {@link Helper}, {@link Service} is extending it. -// */ -// export class BaseContextClass< -// Context = any, -// Application = any, -// EggAppConfig = any, -// Service = any -// > { -// constructor(ctx: Context); - -// /** request context */ -// protected ctx: Context; - -// /** Application */ -// protected app: Application; - -// /** Application config object */ -// protected config: EggAppConfig; - -// /** service */ -// protected service: Service; -// } - -// declare interface FileLoaderBase { -// /** -// * attach items to target object. Mapping the directory to properties. -// * `app/controller/group/repository.js` => `target.group.repository` -// * @return {Object} target -// * @since 1.0.0 -// */ -// load(): object; - -// /** -// * Parse files from given directories, then return an items list, each item contains properties and exports. -// * -// * For example, parse `app/controller/group/repository.js` -// * -// * ```js -// * module.exports = app => { -// * return class RepositoryController extends app.Controller {}; -// * } -// * ``` -// * -// * It returns a item -// * -// * ```js -// * { -// * properties: [ 'group', 'repository' ], -// * exports: app => { ... }, -// * } -// * ``` -// * -// * `Properties` is an array that contains the directory of a filepath. -// * -// * `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing. -// * @return {Array} items -// * @since 1.0.0 -// */ -// parse(): Array<{ fullpath: string; properties: string[]; exports: any; }>; -// } - -// declare interface ContextLoaderBase extends FileLoaderBase {} - -// export interface FileLoader { -// /** -// * Load files from directory to target object. -// * @since 1.0.0 -// */ -// new (options: FileLoaderOption): FileLoaderBase; -// } - -// export interface ContextLoader { -// /** -// * Same as {@link FileLoader}, but it will attach file to `inject[fieldClass]`. The exports will be lazy loaded, such as `ctx.group.repository`. -// * @augments FileLoader -// * @since 1.0.0 -// */ -// new (options: ContextLoaderOption): ContextLoaderBase; -// } - -// export class EggLoader< -// T = EggCore, -// Config = any, -// Options extends EggLoaderOptions = EggLoaderOptions -// > { -// app: T; -// eggPaths: string[]; -// pkg: PlainObject; -// appInfo: EggAppInfo; -// serverScope: string; -// plugins: Plugins; -// config: Config; -// options: Options; - -// /** -// * @class -// * @param {Object} options - options -// * @param {String} options.baseDir - the directory of application -// * @param {EggCore} options.app - Application instance -// * @param {Logger} options.logger - logger -// * @param {Object} [options.plugins] - custom plugins -// * @since 1.0.0 -// */ -// constructor(options: EggLoaderOptions); - -// /** -// * Get home directory -// * @return {String} home directory -// * @since 3.4.0 -// */ -// getHomedir(): EggAppInfo['HOME']; - -// /** -// * Get app info -// * @return {EggAppInfo} appInfo -// * @since 1.0.0 -// */ -// getAppInfo(): EggAppInfo; - -// // Low Level API - -// /** -// * Load single file, will invoke when export is function -// * -// * @param {String} filepath - fullpath -// * @param {Array} arguments - pass rest arguments into the function when invoke -// * @return {Object} exports -// * @example -// * ```js -// * app.loader.loadFile(path.join(app.options.baseDir, 'config/router.js')); -// * ``` -// * @since 1.0.0 -// */ -// loadFile(filepath: string, ...inject: any[]): T; - -// /** -// * Get all loadUnit -// * -// * loadUnit is a directory that can be loaded by EggLoader, it has the same structure. -// * loadUnit has a path and a type(app, framework, plugin). -// * -// * The order of the loadUnits: -// * -// * 1. plugin -// * 2. framework -// * 3. app -// * -// * @return {Array} loadUnits -// * @since 1.0.0 -// */ -// getLoadUnits(): Array<{ path: string; type: string; }>; - -// getEggPaths(): string[]; - -// getServerEnv(): string; - -// /** -// * Load files using {@link FileLoader}, inject to {@link Application} -// * @param {String|Array} directory - see {@link FileLoader} -// * @param {String} property - see {@link FileLoader} -// * @param {Object} opt - see {@link FileLoader} -// * @since 1.0.0 -// */ -// loadToApp(directory: string | string[], property: string, opt?: Partial): void; - -// /** -// * Load files using {@link ContextLoader} -// * @param {String|Array} directory - see {@link ContextLoader} -// * @param {String} property - see {@link ContextLoader} -// * @param {Object} opt - see {@link ContextLoader} -// * @since 1.0.0 -// */ -// loadToContext(directory: string | string[], property: string, opt?: Partial): void; - -// getTypeFiles(filename: string): string[]; -// resolveModule(filepath: string): string | undefined; - -// FileLoader: FileLoader; -// ContextLoader: ContextLoader; - -// // load methods -// protected loadConfig(): void; -// protected loadController(opt?: Partial): void; -// protected loadCustomLoader(): void; -// protected loadCustomApp(): void; -// protected loadCustomAgent(): void; -// protected loadAgentExtend(): void; -// protected loadApplicationExtend(): void; -// protected loadRequestExtend(): void; -// protected loadResponseExtend(): void; -// protected loadContextExtend(): void; -// protected loadHelperExtend(): void; -// protected loadMiddleware(opt?: Partial): void; -// protected loadPlugin(): void; -// protected loadRouter(): void; -// protected loadService(opt?: Partial): void; -// } diff --git a/src/utils/timing.ts b/src/utils/timing.ts index 50f5b24..5f5be62 100644 --- a/src/utils/timing.ts +++ b/src/utils/timing.ts @@ -4,7 +4,7 @@ import assert from 'node:assert'; const debug = debuglog('@eggjs/core:utils:timing'); -interface TimingItem { +export interface TimingItem { name: string; start: number; end?: number; From fc38412e26bd41cbf7d898764d4647477949cffa Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 23 Jun 2024 21:44:42 +0800 Subject: [PATCH 2/4] f --- src/loader/context_loader.ts | 4 ++-- src/utils/index.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/loader/context_loader.ts b/src/loader/context_loader.ts index 854c6c2..9222425 100644 --- a/src/loader/context_loader.ts +++ b/src/loader/context_loader.ts @@ -5,12 +5,12 @@ import { FileLoader, EXPORTS, type FileLoaderOptions } from './file_loader.js'; const CLASS_LOADER = Symbol('classLoader'); -interface ClassLoaderOptions { +export interface ClassLoaderOptions { ctx: ContextDelegation; properties: any; } -class ClassLoader { +export class ClassLoader { readonly _cache = new Map(); _ctx: ContextDelegation; diff --git a/src/utils/index.ts b/src/utils/index.ts index 3de29e8..9ff70e5 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -24,6 +24,7 @@ export default { }, extensions, + extensionNames, async loadFile(filepath: string) { try { From f8b4a29405e68ae00de8bbdcc8140e0f35349684 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 23 Jun 2024 21:47:04 +0800 Subject: [PATCH 3/4] f --- README.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 453471c..cad214e 100644 --- a/README.md +++ b/README.md @@ -282,20 +282,10 @@ Please open an issue [here](https://github.com/eggjs/egg/issues). [MIT](LICENSE) -[egg]: https://github.com/eggjs/egg - - - ## Contributors -|[
popomore](https://github.com/popomore)
|[
dead-horse](https://github.com/dead-horse)
|[
fengmk2](https://github.com/fengmk2)
|[
atian25](https://github.com/atian25)
|[
whxaxes](https://github.com/whxaxes)
|[
killagu](https://github.com/killagu)
| -| :---: | :---: | :---: | :---: | :---: | :---: | -|[
semantic-release-bot](https://github.com/semantic-release-bot)
|[
gxcsoccer](https://github.com/gxcsoccer)
|[
iyuq](https://github.com/iyuq)
|[
ngot](https://github.com/ngot)
|[
waitingsong](https://github.com/waitingsong)
|[
initial-wu](https://github.com/initial-wu)
| -|[
hyj1991](https://github.com/hyj1991)
|[
mosaic101](https://github.com/mosaic101)
|[
answord](https://github.com/answord)
|[
ZhangDianPeng](https://github.com/ZhangDianPeng)
|[
supperchong](https://github.com/supperchong)
|[
superiums](https://github.com/superiums)
| -|[
maxming2333](https://github.com/maxming2333)
|[
chenbin92](https://github.com/chenbin92)
|[
dsonet](https://github.com/dsonet)
|[
zhang740](https://github.com/zhang740)
|[
shaoshuai0102](https://github.com/shaoshuai0102)
|[
mattma](https://github.com/mattma)
| -|[
monkindey](https://github.com/monkindey)
|[
XadillaX](https://github.com/XadillaX)
|[
JimmyDaddy](https://github.com/JimmyDaddy)
|[
JacksonTian](https://github.com/JacksonTian)
|[
njugray](https://github.com/njugray)
|[
army8735](https://github.com/army8735)
| -[
AnzerWall](https://github.com/AnzerWall)
+[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-core)](https://github.com/eggjs/egg-core/graphs/contributors) -This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Jun 18 2024 01:12:54 GMT+0800`. +Made with [contributors-img](https://contrib.rocks). - +[egg]: https://github.com/eggjs/egg From fe08ca6f353900e76fc5d0edeca376b3a22ba2b8 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 23 Jun 2024 21:50:47 +0800 Subject: [PATCH 4/4] f --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 4a3e9d5..5587f25 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "test-local": "egg-bin test", "preci": "npm run prepublishOnly", "ci": "npm run lint && egg-bin cov && npm run prepublishOnly", - "contributor": "git-contributor", "prepublishOnly": "tshy && tshy-after" }, "repository": { @@ -63,7 +62,6 @@ "eslint": "8", "eslint-config-egg": "13", "gals": "1", - "git-contributor": "2", "js-yaml": "3", "mm": "3", "supertest": "7",