Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(typings): add class EggLoader #2321

Merged
merged 15 commits into from
Aug 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,48 @@ declare module 'egg' {
*/
sendToApp(action: string, data: any): void;
}

export interface EggLoaderOptions {
baseDir: string;
typescript?: boolean;
app: Application;
logger: Logger;
plugins?: any;
}

// egg-core
export class EggLoader {
options: EggLoaderOptions;

constructor(options: EggLoaderOptions);

getHomedir(): EggAppInfo['HOME']

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EggLoader 里其实有很多暴露出来的方法可能是需要在上层框架中用到的,也需要补一下吧,比如 getLoadUnitsloadToApploadToContext 这些?

Copy link
Contributor Author

@waitingsong waitingsong Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方法比较多,如果在 EggCore 里面添加 index.d.ts 可能更清晰些。 不过我对 typings 合并(到egg)机制不大清楚

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用,你直接加 d.ts 到 egg-core 中,然后在 egg 中 import 进来就行了,typings 合并到 egg 那个只是适用于上层框架、插件的

Copy link
Contributor Author

@waitingsong waitingsong Apr 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whxaxes 你的意思是在 egg-core 项目中添加 egg-core/index.d.ts 文件么?

declare module 'egg' {   <--- 'egg' OR 'egg-core' ?
  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
  }

  export interface EggLoaderOptions {
    baseDir: string;
    typescript?: boolean;
    app: Application;
    logger: Logger;
    plugins?: any;
  }

  export class EggLoader {
    options: EggLoaderOptions;
    constructor(options: EggLoaderOptions);
    getHomedir(): EggAppInfo['HOME']
    getAppInfo(): EggAppInfo;
  }
}  

不过 EggAppInfo 这个类型是在 egg/index.d.ts 中定义的啊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以有两种方式

  1. egg-core 里面 import { EggLoaderOptions } from 'egg',这样会循环依赖,但问题不大,运行是没有问题的
  2. EggLoaderOptions 直接放 egg-core 里面,在 egg 里面 export { EggLoaderOptions } from 'egg-core'

getAppInfo(): EggAppInfo;
}

/**
* App worker process Loader, will load plugins
* @see https://github.com/eggjs/egg-core
*/
export class AppWorkerLoader extends EggLoader {
constructor(options: EggLoaderOptions);

loadConfig(): void;

load(): void;
}

/**
* Agent worker process loader
* @see https://github.com/eggjs/egg-loader
*/
export class AgentWorkerLoader extends EggLoader {
constructor(options: EggLoaderOptions);

loadConfig(): void;

load(): void;
}

}