1 | import { AggregatedResult } from '@jest/test-result';
|
2 | import { GlobalConfig } from '@jest/types/build/Config';
|
3 | import { Logger } from 'npmlog';
|
4 | import { IHash, Json, JsonValue, MaybeArray, MaybePromise, JsonArray } from '../types';
|
5 | import webpack = require('webpack');
|
6 | import WebpackChain = require('webpack-chain');
|
7 | import WebpackDevServer = require('webpack-dev-server');
|
8 | declare const PLUGIN_CONTEXT_KEY: ("command" | "commandArgs" | "rootDir" | "userConfig" | "pkg" | "webpack")[];
|
9 | declare const VALIDATION_MAP: {
|
10 | string: "isString";
|
11 | number: "isNumber";
|
12 | array: "isArray";
|
13 | object: "isObject";
|
14 | boolean: "isBoolean";
|
15 | };
|
16 | export declare type PluginContext = Pick<Context, typeof PLUGIN_CONTEXT_KEY[number]>;
|
17 | export declare type UserConfigContext = PluginContext & {
|
18 | taskName: string;
|
19 | };
|
20 | export declare type ValidationKey = keyof typeof VALIDATION_MAP;
|
21 | export interface IJestResult {
|
22 | results: AggregatedResult;
|
23 | globalConfig: GlobalConfig;
|
24 | }
|
25 | export interface IOnHookCallbackArg {
|
26 | err?: Error;
|
27 | args?: CommandArgs;
|
28 | stats?: webpack.compilation.MultiStats;
|
29 | url?: string;
|
30 | devServer?: WebpackDevServer;
|
31 | config?: any;
|
32 | result?: IJestResult;
|
33 | }
|
34 | export interface IOnHookCallback {
|
35 | (arg?: IOnHookCallbackArg): MaybePromise<void>;
|
36 | }
|
37 | export interface IOnHook {
|
38 | (eventName: string, callback: IOnHookCallback): void;
|
39 | }
|
40 | export interface IPluginConfigWebpack {
|
41 | (config: WebpackChain): void;
|
42 | }
|
43 | export interface IUserConfigWebpack {
|
44 | (config: WebpackChain, value: JsonValue, context: UserConfigContext): Promise<void>;
|
45 | }
|
46 | export interface IUserConfigArgs {
|
47 | name: string;
|
48 | configWebpack?: IUserConfigWebpack;
|
49 | defaultValue?: any;
|
50 | validation?: ValidationKey;
|
51 | }
|
52 | export interface ICliOptionArgs {
|
53 | name: string;
|
54 | configWebpack?: IUserConfigWebpack;
|
55 | commands?: string[];
|
56 | }
|
57 | export interface IOnGetWebpackConfig {
|
58 | (name: string, fn: IPluginConfigWebpack): void;
|
59 | (fn: IPluginConfigWebpack): void;
|
60 | }
|
61 | export interface IOnGetJestConfig {
|
62 | (fn: IJestConfigFunction): void;
|
63 | }
|
64 | export interface IRegisterTask {
|
65 | (name: string, chainConfig: WebpackChain): void;
|
66 | }
|
67 | export interface IMethodFunction {
|
68 | (args?: any): void;
|
69 | }
|
70 | export interface IRegsiterMethod {
|
71 | (name: string, fn: IMethodFunction): void;
|
72 | }
|
73 | export interface IApplyMethod {
|
74 | (name: string, ...args: any[]): any;
|
75 | }
|
76 | export interface IModifyConfig {
|
77 | (userConfig: IUserConfig): IHash<any>;
|
78 | }
|
79 | export interface IModifyUserConfig {
|
80 | (configKey: string | IModifyConfig, value?: any): void;
|
81 | }
|
82 | export interface IGetAllPlugin {
|
83 | (dataKeys?: string[]): Partial<IPluginInfo>[];
|
84 | }
|
85 | export interface IPluginAPI {
|
86 | log: Logger;
|
87 | context: PluginContext;
|
88 | registerTask: IRegisterTask;
|
89 | getAllTask: () => string[];
|
90 | getAllPlugin: IGetAllPlugin;
|
91 | onGetWebpackConfig: IOnGetWebpackConfig;
|
92 | onGetJestConfig: IOnGetJestConfig;
|
93 | onHook: IOnHook;
|
94 | setValue: (name: string, value: any) => void;
|
95 | getValue: (name: string) => any;
|
96 | registerUserConfig: (args: MaybeArray<IUserConfigArgs>) => void;
|
97 | registerCliOption: (args: MaybeArray<ICliOptionArgs>) => void;
|
98 | registerMethod: IRegsiterMethod;
|
99 | applyMethod: IApplyMethod;
|
100 | modifyUserConfig: IModifyUserConfig;
|
101 | }
|
102 | export interface IPluginInfo {
|
103 | fn: IPlugin;
|
104 | name?: string;
|
105 | pluginPath?: string;
|
106 | options: IPluginOptions;
|
107 | }
|
108 | export declare type IPluginOptions = Json | JsonArray;
|
109 | export interface IPlugin {
|
110 | (api: IPluginAPI, options?: IPluginOptions): MaybePromise<void>;
|
111 | }
|
112 | export declare type CommandName = 'start' | 'build' | 'test';
|
113 | export declare type CommandArgs = IHash<any>;
|
114 | export declare type IPluginList = (string | [string, Json])[];
|
115 | export declare type IGetBuiltInPlugins = (userConfig: IUserConfig) => IPluginList;
|
116 | export interface IContextOptions {
|
117 | command: CommandName;
|
118 | rootDir: string;
|
119 | args: CommandArgs;
|
120 | plugins?: IPluginList;
|
121 | getBuiltInPlugins?: IGetBuiltInPlugins;
|
122 | }
|
123 | export interface ITaskConfig {
|
124 | name: string;
|
125 | chainConfig: WebpackChain;
|
126 | modifyFunctions: IPluginConfigWebpack[];
|
127 | }
|
128 | export interface IUserConfig extends Json {
|
129 | plugins: IPluginList;
|
130 | }
|
131 | export interface IModeConfig {
|
132 | [name: string]: IUserConfig;
|
133 | }
|
134 | export interface IJestConfigFunction {
|
135 | (JestConfig: Json): Json;
|
136 | }
|
137 | export declare type IOnGetWebpackConfigArgs = [string, IPluginConfigWebpack] | [IPluginConfigWebpack];
|
138 | declare class Context {
|
139 | command: CommandName;
|
140 | commandArgs: CommandArgs;
|
141 | rootDir: string;
|
142 | webpack: (options: webpack.Configuration[]) => webpack.MultiCompiler;
|
143 | private configArr;
|
144 | private modifyConfigFns;
|
145 | private modifyJestConfig;
|
146 | private eventHooks;
|
147 | private internalValue;
|
148 | private userConfigRegistration;
|
149 | private cliOptionRegistration;
|
150 | private methodRegistration;
|
151 | pkg: Json;
|
152 | userConfig: IUserConfig;
|
153 | plugins: IPluginInfo[];
|
154 | constructor({ command, rootDir, args, plugins, getBuiltInPlugins, }: IContextOptions);
|
155 | private registerConfig;
|
156 | private runConfigWebpack;
|
157 | private getProjectFile;
|
158 | private getUserConfig;
|
159 | private mergeModeConfig;
|
160 | private resolvePlugins;
|
161 | getAllPlugin: IGetAllPlugin;
|
162 | registerTask: IRegisterTask;
|
163 | registerMethod: IRegsiterMethod;
|
164 | applyMethod: IApplyMethod;
|
165 | modifyUserConfig: IModifyUserConfig;
|
166 | getAllTask: () => string[];
|
167 | onGetWebpackConfig: IOnGetWebpackConfig;
|
168 | onGetJestConfig: IOnGetJestConfig;
|
169 | runJestConfig: (jestConfig: Json) => Json;
|
170 | onHook: IOnHook;
|
171 | applyHook: (key: string, opts?: {}) => Promise<void>;
|
172 | setValue: (key: string | number, value: any) => void;
|
173 | getValue: (key: string | number) => any;
|
174 | registerUserConfig: (args: MaybeArray<IUserConfigArgs>) => void;
|
175 | registerCliOption: (args: MaybeArray<ICliOptionArgs>) => void;
|
176 | private runPlugins;
|
177 | private checkPluginValue;
|
178 | private runUserConfig;
|
179 | private runCliOption;
|
180 | private runWebpackFunctions;
|
181 | setUp: () => Promise<ITaskConfig[]>;
|
182 | }
|
183 | export default Context;
|