@modern-js/core 1.4.6 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +47 -0
  3. package/dist/js/modern/config/defaults.js +4 -1
  4. package/dist/js/modern/config/index.js +2 -1
  5. package/dist/js/modern/config/types/index.js +0 -0
  6. package/dist/js/modern/config/types/less.js +0 -0
  7. package/dist/js/modern/config/types/sass.js +0 -0
  8. package/dist/js/modern/config/types/ssg.js +0 -0
  9. package/dist/js/modern/config/types/test.js +0 -0
  10. package/dist/js/modern/config/types/unbundle.js +0 -0
  11. package/dist/js/modern/context.js +18 -0
  12. package/dist/js/modern/index.js +9 -28
  13. package/dist/js/modern/initWatcher.js +1 -0
  14. package/dist/js/modern/loadPlugins.js +43 -48
  15. package/dist/js/modern/manager.js +28 -0
  16. package/dist/js/modern/pluginAPI.js +11 -0
  17. package/dist/js/node/config/defaults.js +4 -1
  18. package/dist/js/node/config/index.js +22 -1
  19. package/dist/js/node/config/types/index.js +0 -0
  20. package/dist/js/node/config/types/less.js +0 -0
  21. package/dist/js/node/config/types/sass.js +0 -0
  22. package/dist/js/node/config/types/ssg.js +0 -0
  23. package/dist/js/node/config/types/test.js +0 -0
  24. package/dist/js/node/config/types/unbundle.js +0 -0
  25. package/dist/js/node/context.js +22 -1
  26. package/dist/js/node/index.js +78 -67
  27. package/dist/js/node/initWatcher.js +1 -0
  28. package/dist/js/node/loadPlugins.js +42 -47
  29. package/dist/js/node/manager.js +45 -0
  30. package/dist/js/node/pluginAPI.js +54 -0
  31. package/dist/types/config/defaults.d.ts +3 -0
  32. package/dist/types/config/index.d.ts +3 -129
  33. package/dist/types/config/types/index.d.ts +231 -0
  34. package/dist/types/config/types/less.d.ts +10 -0
  35. package/dist/types/config/types/sass.d.ts +8 -0
  36. package/dist/types/config/types/ssg.d.ts +13 -0
  37. package/dist/types/config/types/test.d.ts +15 -0
  38. package/dist/types/config/types/unbundle.d.ts +28 -0
  39. package/dist/types/context.d.ts +19 -1
  40. package/dist/types/index.d.ts +6 -95
  41. package/dist/types/initWatcher.d.ts +1 -1
  42. package/dist/types/loadPlugins.d.ts +24 -13
  43. package/dist/types/manager.d.ts +74 -0
  44. package/dist/types/pluginAPI.d.ts +13 -0
  45. package/jest.config.js +0 -1
  46. package/package.json +13 -8
  47. package/tests/config.test.ts +1 -1
  48. package/tests/initWatcher.test.ts +1 -1
  49. package/tests/loadPlugin.test.ts +32 -43
  50. package/tests/pluginAPI.test.ts +19 -0
@@ -0,0 +1,231 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage, ServerResponse } from 'http';
3
+ import type { NextFunction, BffProxyOptions } from '@modern-js/types';
4
+ import type { MetaOptions } from '@modern-js/utils';
5
+ import type { TransformOptions } from '@babel/core';
6
+ import type { PluginConfig } from '../../loadPlugins';
7
+ import type { TestConfig, JestConfig } from './test';
8
+ import type { SassConfig, SassLoaderOptions } from './sass';
9
+ import type { LessConfig, LessLoaderOptions } from './less';
10
+ import type { UnbundleConfig } from './unbundle';
11
+ import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
12
+ export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions };
13
+ export interface SourceConfig {
14
+ entries?: Record<string, string | {
15
+ entry: string;
16
+ enableFileSystemRoutes?: boolean;
17
+ disableMount?: boolean;
18
+ }>;
19
+ disableDefaultEntries?: boolean;
20
+ entriesDir?: string;
21
+ configDir?: string;
22
+ apiDir?: string;
23
+ envVars?: Array<string>;
24
+ globalVars?: Record<string, string>;
25
+ alias?: Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>);
26
+ moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
27
+ include?: Array<string | RegExp>;
28
+ /**
29
+ * The configuration of `source.designSystem` is provided by plugin `@modern-js/plugin-tailwindcss`.
30
+ * Please use `yarn new` to enable the corresponding capability.
31
+ * @requires `@modern-js/plugin-tailwindcss`
32
+ */
33
+
34
+ designSystem?: Record<string, any>;
35
+ }
36
+ export interface OutputConfig {
37
+ assetPrefix?: string;
38
+ htmlPath?: string;
39
+ jsPath?: string;
40
+ cssPath?: string;
41
+ mediaPath?: string;
42
+ path?: string;
43
+ title?: string;
44
+ titleByEntries?: Record<string, string>;
45
+ meta?: MetaOptions;
46
+ metaByEntries?: Record<string, MetaOptions>;
47
+ inject?: 'body' | 'head' | boolean;
48
+ injectByEntries?: Record<string, 'body' | 'head' | boolean>;
49
+ mountId?: string;
50
+ favicon?: string;
51
+ faviconByEntries?: Record<string, string | undefined>;
52
+ copy?: Array<Record<string, unknown> & {
53
+ from: string;
54
+ }>;
55
+ scriptExt?: Record<string, unknown>;
56
+ disableTsChecker?: boolean;
57
+ disableHtmlFolder?: boolean;
58
+ disableCssModuleExtension?: boolean;
59
+ disableCssExtract?: boolean;
60
+ enableCssModuleTSDeclaration?: boolean;
61
+ disableMinimize?: boolean;
62
+ enableInlineStyles?: boolean;
63
+ enableInlineScripts?: boolean;
64
+ disableSourceMap?: boolean;
65
+ disableInlineRuntimeChunk?: boolean;
66
+ disableAssetsCache?: boolean;
67
+ enableLatestDecorators?: boolean;
68
+ polyfill?: 'off' | 'usage' | 'entry' | 'ua';
69
+ dataUriLimit?: number;
70
+ templateParameters?: Record<string, unknown>;
71
+ templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
72
+ cssModuleLocalIdentName?: string;
73
+ enableModernMode?: boolean;
74
+ federation?: boolean;
75
+ disableNodePolyfill?: boolean;
76
+ enableTsLoader?: boolean;
77
+ /**
78
+ * Disables lazy import support for styles, currently supports antd and arco-design.
79
+ * The configuration of `output.disableAutoImportStyle` is provided by plugin `@modern-js/plugin-unbundle`.
80
+ * Please use `yarn new` to enable the corresponding capability.
81
+ * @requires `@modern-js/plugin-unbundle`
82
+ */
83
+
84
+ disableAutoImportStyle?: boolean;
85
+ /**
86
+ * The configuration of `output.ssg` is provided by plugin `@modern-js/plugin-ssg`.
87
+ * Please use `yarn new` to enable the corresponding capability.
88
+ * @requires `@modern-js/plugin-ssg`
89
+ */
90
+
91
+ ssg?: SSGConfig;
92
+ }
93
+ export interface ServerConfig {
94
+ routes?: Record<string, string | string[] | {
95
+ route: string | string[];
96
+ disableSpa?: boolean;
97
+ }>;
98
+ publicRoutes?: {
99
+ [filepath: string]: string;
100
+ };
101
+ ssr?: boolean | Record<string, unknown>;
102
+ ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
103
+ baseUrl?: string | Array<string>;
104
+ port?: number;
105
+ logger?: boolean | Record<string, any>;
106
+ metrics?: boolean | Record<string, any>;
107
+ enableMicroFrontendDebug?: boolean;
108
+ }
109
+ export declare type DevProxyOptions = string | Record<string, string>;
110
+ export interface DevConfig {
111
+ assetPrefix?: string | boolean;
112
+ https?: boolean;
113
+ /**
114
+ * The configuration of `dev.proxy` is provided by plugin `@modern-js/plugin-proxy`.
115
+ * Please use `yarn new` to enable the corresponding capability.
116
+ * @requires `@modern-js/plugin-proxy`
117
+ */
118
+
119
+ proxy?: DevProxyOptions;
120
+ /**
121
+ * The configuration of `dev.unbundle` is provided by plugin `@modern-js/plugin-unbundle`.
122
+ * Please use `yarn new` to enable the corresponding capability.
123
+ * @requires `@modern-js/plugin-unbundle`
124
+ */
125
+
126
+ unbundle?: UnbundleConfig;
127
+ }
128
+ export interface MicroFrontend {
129
+ enableHtmlEntry?: boolean;
130
+ externalBasicLibrary?: boolean;
131
+ moduleApp?: string;
132
+ }
133
+ export interface DeployConfig {
134
+ microFrontend?: false | MicroFrontend;
135
+ domain?: string | Array<string>;
136
+ domainByEntries?: Record<string, string | Array<string>>;
137
+ }
138
+ declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>) => Record<string, unknown> | void);
139
+ export declare type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
140
+ export declare type DevServerConfig = {
141
+ proxy?: BffProxyOptions;
142
+ headers?: Record<string, string>;
143
+ before?: RequestHandler[];
144
+ after?: RequestHandler[];
145
+ [propsName: string]: any;
146
+ };
147
+ export declare type BabelConfig = TransformOptions | ((config: TransformOptions) => TransformOptions | void);
148
+ export interface ToolsConfig {
149
+ webpack?: ConfigFunction;
150
+ babel?: BabelConfig;
151
+ autoprefixer?: ConfigFunction;
152
+ postcss?: ConfigFunction;
153
+ styledComponents?: ConfigFunction;
154
+ lodash?: ConfigFunction;
155
+ devServer?: DevServerConfig;
156
+ tsLoader?: ConfigFunction;
157
+ terser?: ConfigFunction;
158
+ minifyCss?: ConfigFunction;
159
+ esbuild?: Record<string, unknown>;
160
+ /**
161
+ * The configuration of `tools.tailwindcss` is provided by plugin `@modern-js/plugin-tailwindcss`.
162
+ * Please use `yarn new` to enable the corresponding capability.
163
+ * @requires `@modern-js/plugin-tailwindcss`
164
+ */
165
+
166
+ tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
167
+ /**
168
+ * The configuration of `tools.jest` is provided by plugin `@modern-js/plugin-testing`.
169
+ * Please use `yarn new` to enable the corresponding capability.
170
+ * @requires `@modern-js/plugin-testing`
171
+ */
172
+
173
+ jest?: TestConfig['jest'];
174
+ /**
175
+ * The configuration of `tools.sass` is provided by plugin `@modern-js/plugin-sass`.
176
+ * Please use `yarn new` to enable the corresponding capability.
177
+ * @requires `@modern-js/plugin-sass`
178
+ */
179
+
180
+ sass?: SassConfig;
181
+ /**
182
+ * The configuration of `tools.less` is provided by plugin `@modern-js/plugin-less`.
183
+ * Please use `yarn new` to enable the corresponding capability.
184
+ * @requires `@modern-js/plugin-less`
185
+ */
186
+
187
+ less?: LessConfig;
188
+ }
189
+ export declare type RuntimeConfig = Record<string, any>;
190
+ export interface RuntimeByEntriesConfig {
191
+ [name: string]: RuntimeConfig;
192
+ }
193
+ export declare type BffConfig = {
194
+ prefix?: string;
195
+ requestCreator?: string;
196
+ fetcher?: string;
197
+ proxy?: Record<string, any>;
198
+ };
199
+ export interface UserConfig {
200
+ source?: SourceConfig;
201
+ output?: OutputConfig;
202
+ server?: ServerConfig;
203
+ dev?: DevConfig;
204
+ deploy?: DeployConfig;
205
+ tools?: ToolsConfig;
206
+ plugins?: PluginConfig;
207
+ runtime?: RuntimeConfig;
208
+ runtimeByEntries?: RuntimeByEntriesConfig;
209
+ /**
210
+ * The configuration of `bff` is provided by plugin `@modern-js/plugin-bff`.
211
+ * Please use `yarn new` to enable the corresponding capability.
212
+ * @requires `@modern-js/plugin-bff`
213
+ */
214
+
215
+ bff?: BffConfig;
216
+ /**
217
+ * The configuration of `testing` is provided by plugin `@modern-js/plugin-testing`.
218
+ * Please use `yarn new` to enable the corresponding capability.
219
+ * @requires `@modern-js/plugin-testing`
220
+ */
221
+
222
+ testing?: TestConfig;
223
+ }
224
+ export declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
225
+ export interface LoadedConfig {
226
+ config: UserConfig;
227
+ filePath: string | false;
228
+ dependencies: string[];
229
+ pkgConfig: UserConfig;
230
+ jsConfig: UserConfig;
231
+ }
@@ -0,0 +1,10 @@
1
+ /// <reference types="less" />
2
+ import type { LoaderContext } from 'webpack';
3
+ export declare type LessLoaderOptions = {
4
+ lessOptions?: Less.Options;
5
+ additionalData?: string | ((content: string, loaderContext: LoaderContext<LessLoaderOptions>) => string);
6
+ sourceMap?: boolean;
7
+ webpackImporter?: boolean;
8
+ implementation?: boolean;
9
+ };
10
+ export declare type LessConfig = LessLoaderOptions | ((options: LessLoaderOptions) => LessLoaderOptions | void);
@@ -0,0 +1,8 @@
1
+ import type { LegacyFileOptions } from 'sass';
2
+ export interface SassLoaderOptions {
3
+ sassOptions?: LegacyFileOptions<'sync'>;
4
+ sourceMap?: boolean;
5
+ implementation?: string;
6
+ additionalData?: string | ((content: string, filename: string) => string);
7
+ }
8
+ export declare type SassConfig = SassLoaderOptions | ((options: SassLoaderOptions) => SassLoaderOptions | void);
@@ -0,0 +1,13 @@
1
+ export declare type SSGRouteOptions = string | {
2
+ url: string;
3
+ output?: string;
4
+ params?: Record<string, any>[];
5
+ headers?: Record<string, any>;
6
+ };
7
+ export declare type SSGSingleEntryOptions = boolean | {
8
+ preventDefault?: string[];
9
+ headers?: Record<string, any>;
10
+ routes?: SSGRouteOptions[];
11
+ };
12
+ export declare type SSGMultiEntryOptions = Record<string, SSGSingleEntryOptions>;
13
+ export declare type SSGConfig = boolean | SSGSingleEntryOptions | SSGMultiEntryOptions | ((entryName: string) => SSGSingleEntryOptions);
@@ -0,0 +1,15 @@
1
+ import type { Config as JestConfigTypes } from '@jest/types';
2
+ export declare type JestConfig = JestConfigTypes.InitialOptions;
3
+ export interface TestConfig {
4
+ /**
5
+ * Decide which transformer will be used to compile file
6
+ * Default: babel-jest
7
+ */
8
+ transformer?: 'babel-jest' | 'ts-jest';
9
+ /**
10
+ * Original jest config
11
+ * Doc: https://jestjs.io/docs/configuration
12
+ */
13
+
14
+ jest?: JestConfig | ((jestConfig: JestConfig) => JestConfig);
15
+ }
@@ -0,0 +1,28 @@
1
+ export declare type UnbundleConfig = {
2
+ /**
3
+ * Some package A may require another package B that is intended for Node.js
4
+ * use only. In such a case, if package B cannot be converted to ESM, it will
5
+ * cause package A to fail during unbundle development, even though package B
6
+ * is not really required. Package B can thus be safely ignored via this option
7
+ * to ensure transpilation of package A to ESM
8
+ */
9
+ ignore?: string | string[];
10
+ /**
11
+ * ignores cached esm modules and recompiles dependencies not available
12
+ * from PDN host on dev start.
13
+ * default: false
14
+ */
15
+
16
+ ignoreModuleCache?: boolean;
17
+ /**
18
+ * clears cache of downloaded esm modules (from PDN) on dev start.
19
+ * default: false
20
+ */
21
+
22
+ clearPdnCache?: boolean;
23
+ /**
24
+ * modifies host to attempt to download esm modules from
25
+ */
26
+
27
+ pdnHost?: string;
28
+ };
@@ -6,10 +6,28 @@ export type { IAppContext };
6
6
  export declare const AppContext: import("@modern-js/plugin").Context<IAppContext>;
7
7
  export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
8
8
  export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig>;
9
+ /**
10
+ * Set app context.
11
+ * @param value new app context. It will override previous app context.
12
+ */
13
+
14
+ export declare const setAppContext: (value: IAppContext) => void;
15
+ /**
16
+ * Get app context, including directories, plugins and some static infos.
17
+ */
18
+
9
19
  export declare const useAppContext: () => IAppContext;
20
+ /**
21
+ * Get original content of user config.
22
+ */
23
+
10
24
  export declare const useConfigContext: () => UserConfig;
25
+ /**
26
+ * Get normalized content of user config.
27
+ */
28
+
11
29
  export declare const useResolvedConfigContext: () => NormalizedConfig;
12
- export declare const initAppContext: (appDirectory: string, plugins: Array<LoadedPlugin>, configFile: string | false, options?: {
30
+ export declare const initAppContext: (appDirectory: string, plugins: LoadedPlugin[], configFile: string | false, options?: {
13
31
  metaName?: string | undefined;
14
32
  srcDir?: string | undefined;
15
33
  distDir?: string | undefined;
@@ -1,111 +1,22 @@
1
1
  import { INTERNAL_PLUGINS } from '@modern-js/utils';
2
- import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners, AsyncWaterfall } from '@modern-js/plugin';
3
2
  import type { Hooks } from '@modern-js/types';
4
3
  import { ErrorObject } from 'ajv';
5
- import { Command } from './utils/commander';
6
- import { TransformPlugin } from './loadPlugins';
7
- import { AppContext, ConfigContext, IAppContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from './context';
8
- import { NormalizedConfig } from './config/mergeConfig';
4
+ import { IAppContext, initAppContext } from './context';
5
+ import type { NormalizedConfig } from './config/mergeConfig';
9
6
  export type { Hooks };
10
7
  export * from './config';
11
8
  export * from '@modern-js/plugin';
12
9
  export * from '@modern-js/plugin/node';
13
- export declare type HooksRunner = Progresses2Runners<{
14
- config: ParallelWorkflow<void>;
15
- resolvedConfig: AsyncWaterfall<{
16
- resolved: NormalizedConfig;
17
- }>;
18
- validateSchema: ParallelWorkflow<void>;
19
- prepare: AsyncWorkflow<void, void>;
20
- commands: AsyncWorkflow<{
21
- program: Command;
22
- }, void>;
23
- watchFiles: ParallelWorkflow<void>;
24
- fileChange: AsyncWorkflow<{
25
- filename: string;
26
- eventType: 'add' | 'change' | 'unlink';
27
- }, void>;
28
- beforeExit: AsyncWorkflow<void, void>;
29
- }>;
30
- export declare const manager: import("@modern-js/plugin").AsyncManager<Hooks, {
31
- config: ParallelWorkflow<void, unknown>;
32
- resolvedConfig: AsyncWaterfall<{
33
- resolved: NormalizedConfig;
34
- }>;
35
- validateSchema: ParallelWorkflow<void, unknown>;
36
- prepare: AsyncWorkflow<void, void>;
37
- commands: AsyncWorkflow<{
38
- program: Command;
39
- }, void>;
40
- watchFiles: ParallelWorkflow<void, unknown>;
41
- fileChange: AsyncWorkflow<{
42
- filename: string;
43
- eventType: 'add' | 'change' | 'unlink';
44
- }, void>;
45
- beforeExit: AsyncWorkflow<void, void>;
46
- beforeRestart: AsyncWorkflow<void, void>;
47
- }>;
48
- export declare const createPlugin: (initializer: import("@modern-js/plugin").AsyncInitializer<Partial<import("@modern-js/plugin").Progresses2Threads<{
49
- config: ParallelWorkflow<void, unknown>;
50
- resolvedConfig: AsyncWaterfall<{
51
- resolved: NormalizedConfig;
52
- }>;
53
- validateSchema: ParallelWorkflow<void, unknown>;
54
- prepare: AsyncWorkflow<void, void>;
55
- commands: AsyncWorkflow<{
56
- program: Command;
57
- }, void>;
58
- watchFiles: ParallelWorkflow<void, unknown>;
59
- fileChange: AsyncWorkflow<{
60
- filename: string;
61
- eventType: 'add' | 'change' | 'unlink';
62
- }, void>;
63
- beforeExit: AsyncWorkflow<void, void>;
64
- beforeRestart: AsyncWorkflow<void, void>;
65
- } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, options?: import("@modern-js/plugin").PluginOptions | undefined) => import("@modern-js/plugin").AsyncPlugin<Partial<import("@modern-js/plugin").Progresses2Threads<{
66
- config: ParallelWorkflow<void, unknown>;
67
- resolvedConfig: AsyncWaterfall<{
68
- resolved: NormalizedConfig;
69
- }>;
70
- validateSchema: ParallelWorkflow<void, unknown>;
71
- prepare: AsyncWorkflow<void, void>;
72
- commands: AsyncWorkflow<{
73
- program: Command;
74
- }, void>;
75
- watchFiles: ParallelWorkflow<void, unknown>;
76
- fileChange: AsyncWorkflow<{
77
- filename: string;
78
- eventType: 'add' | 'change' | 'unlink';
79
- }, void>;
80
- beforeExit: AsyncWorkflow<void, void>;
81
- beforeRestart: AsyncWorkflow<void, void>;
82
- } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>>>, registerHook: (newShape: Partial<Hooks>) => void, mountHook: () => Progresses2Runners<{
83
- config: ParallelWorkflow<void, unknown>;
84
- resolvedConfig: AsyncWaterfall<{
85
- resolved: NormalizedConfig;
86
- }>;
87
- validateSchema: ParallelWorkflow<void, unknown>;
88
- prepare: AsyncWorkflow<void, void>;
89
- commands: AsyncWorkflow<{
90
- program: Command;
91
- }, void>;
92
- watchFiles: ParallelWorkflow<void, unknown>;
93
- fileChange: AsyncWorkflow<{
94
- filename: string;
95
- eventType: 'add' | 'change' | 'unlink';
96
- }, void>;
97
- beforeExit: AsyncWorkflow<void, void>;
98
- beforeRestart: AsyncWorkflow<void, void>;
99
- } & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
100
- export declare const usePlugins: (plugins: string[]) => void;
101
- export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
10
+ export { manager, mountHook, usePlugins, createPlugin, registerHook } from './manager';
11
+ export type { CliHooks, CliPlugin, CliHookCallbacks } from './manager';
12
+ export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from './pluginAPI';
13
+ export type { PluginAPI } from './pluginAPI';
102
14
  export type { NormalizedConfig, IAppContext };
103
15
  declare const initAppDir: (cwd?: string | undefined) => Promise<string>;
104
16
  export interface CoreOptions {
105
17
  configFile?: string;
106
18
  packageJsonConfig?: string;
107
19
  plugins?: typeof INTERNAL_PLUGINS;
108
- transformPlugin?: TransformPlugin;
109
20
  onSchemaError?: (error: ErrorObject) => void;
110
21
  options?: {
111
22
  metaName?: string;
@@ -1,4 +1,4 @@
1
1
  import chokidar from 'chokidar';
2
2
  import { LoadedConfig } from './config';
3
- import { HooksRunner } from '.';
3
+ import { HooksRunner } from './manager';
4
4
  export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<chokidar.FSWatcher | undefined>;
@@ -1,30 +1,41 @@
1
1
  import { INTERNAL_PLUGINS } from '@modern-js/utils';
2
2
  import type { UserConfig } from './config';
3
- declare type Plugin = string | [string, any];
3
+ import { CliPlugin } from './manager';
4
+ declare type PluginItem = string | [string, any];
4
5
  export declare type LoadedPlugin = {
5
- cli?: any;
6
- cliPkg?: string;
7
- server?: any;
6
+ cli?: CliPlugin;
7
+ server?: string;
8
8
  serverPkg?: string;
9
9
  };
10
- export declare type PluginConfigItem = {
11
- cli?: Plugin;
12
- server?: Plugin;
13
- } | Plugin;
14
- export declare type PluginConfig = Array<PluginConfigItem>;
15
- export declare type TransformPlugin = (plugin: PluginConfig, resolvedConfig: UserConfig, pluginOptions?: any) => PluginConfig;
16
- export declare function getAppPlugins(appDirectory: string, pluginConfig: PluginConfig, internalPlugins?: typeof INTERNAL_PLUGINS): PluginConfigItem[];
10
+ /**
11
+ * @deprecated
12
+ * Using NewPluginConfig insteand.
13
+ */
14
+
15
+ declare type OldPluginConfig = Array<PluginItem | {
16
+ cli?: PluginItem;
17
+ server?: PluginItem;
18
+ }>;
19
+ declare type NewPluginConfig = CliPlugin[] | {
20
+ cli?: CliPlugin[];
21
+ /** Custom server plugin is not supported yet. */
22
+
23
+ server?: never;
24
+ };
25
+ export declare type PluginConfig = OldPluginConfig | NewPluginConfig;
26
+ export declare function getAppPlugins(appDirectory: string, oldPluginConfig: OldPluginConfig, internalPlugins?: typeof INTERNAL_PLUGINS): (PluginItem | {
27
+ cli?: PluginItem | undefined;
28
+ server?: PluginItem | undefined;
29
+ })[];
17
30
  /**
18
31
  * Load internal plugins which in @modern-js scope and user's custom plugins.
19
32
  * @param appDirectory - Application root directory.
20
33
  * @param userConfig - Resolved user config.
21
34
  * @param options.internalPlugins - Internal plugins.
22
- * @param options.transformPlugin - transform plugin before using it.
23
35
  * @returns Plugin Objects has been required.
24
36
  */
25
37
 
26
38
  export declare const loadPlugins: (appDirectory: string, userConfig: UserConfig, options?: {
27
39
  internalPlugins?: typeof INTERNAL_PLUGINS;
28
- transformPlugin?: TransformPlugin;
29
40
  }) => LoadedPlugin[];
30
41
  export {};
@@ -0,0 +1,74 @@
1
+ import { ToThreads, ToRunners, AsyncSetup, PluginOptions, AsyncWorkflow, AsyncWaterfall, ParallelWorkflow } from '@modern-js/plugin';
2
+ import type { Hooks } from '@modern-js/types';
3
+ import type { Command } from './utils/commander';
4
+ import type { NormalizedConfig } from './config/mergeConfig';
5
+ import { pluginAPI } from './pluginAPI';
6
+ export declare type HooksRunner = ToRunners<{
7
+ config: ParallelWorkflow<void>;
8
+ resolvedConfig: AsyncWaterfall<{
9
+ resolved: NormalizedConfig;
10
+ }>;
11
+ validateSchema: ParallelWorkflow<void>;
12
+ prepare: AsyncWorkflow<void, void>;
13
+ commands: AsyncWorkflow<{
14
+ program: Command;
15
+ }, void>;
16
+ watchFiles: ParallelWorkflow<void>;
17
+ fileChange: AsyncWorkflow<{
18
+ filename: string;
19
+ eventType: 'add' | 'change' | 'unlink';
20
+ }, void>;
21
+ beforeExit: AsyncWorkflow<void, void>;
22
+ beforeRestart: AsyncWorkflow<void, void>;
23
+ }>;
24
+ declare const baseHooks: {
25
+ config: ParallelWorkflow<void, unknown>;
26
+ resolvedConfig: AsyncWaterfall<{
27
+ resolved: NormalizedConfig;
28
+ }>;
29
+ validateSchema: ParallelWorkflow<void, unknown>;
30
+ prepare: AsyncWorkflow<void, void>;
31
+ commands: AsyncWorkflow<{
32
+ program: Command;
33
+ }, void>;
34
+ watchFiles: ParallelWorkflow<void, unknown>;
35
+ fileChange: AsyncWorkflow<{
36
+ filename: string;
37
+ eventType: 'add' | 'change' | 'unlink';
38
+ }, void>;
39
+ beforeExit: AsyncWorkflow<void, void>;
40
+ beforeRestart: AsyncWorkflow<void, void>;
41
+ };
42
+ /** All hooks of cli plugin. */
43
+
44
+ export declare type CliHooks = typeof baseHooks & Hooks;
45
+ /** All hook callbacks of cli plugin. */
46
+
47
+ export declare type CliHookCallbacks = ToThreads<CliHooks>;
48
+ export declare const manager: import("@modern-js/plugin").AsyncManager<CliHooks, {
49
+ setAppContext: (value: import("@modern-js/types").IAppContext) => void;
50
+ useAppContext: () => import("@modern-js/types").IAppContext;
51
+ useConfigContext: () => import("./config").UserConfig;
52
+ useResolvedConfigContext: () => NormalizedConfig;
53
+ }>;
54
+ /** Plugin options of a cli plugin. */
55
+
56
+ export declare type CliPlugin = PluginOptions<CliHooks, AsyncSetup<CliHooks, typeof pluginAPI>>;
57
+ export declare const createPlugin: (setup?: AsyncSetup<CliHooks, {
58
+ setAppContext: (value: import("@modern-js/types").IAppContext) => void;
59
+ useAppContext: () => import("@modern-js/types").IAppContext;
60
+ useConfigContext: () => import("./config").UserConfig;
61
+ useResolvedConfigContext: () => NormalizedConfig;
62
+ }> | undefined, options?: PluginOptions<CliHooks, AsyncSetup<CliHooks, {
63
+ setAppContext: (value: import("@modern-js/types").IAppContext) => void;
64
+ useAppContext: () => import("@modern-js/types").IAppContext;
65
+ useConfigContext: () => import("./config").UserConfig;
66
+ useResolvedConfigContext: () => NormalizedConfig;
67
+ }>> | undefined) => import("@modern-js/plugin").AsyncPlugin<CliHooks, {
68
+ setAppContext: (value: import("@modern-js/types").IAppContext) => void;
69
+ useAppContext: () => import("@modern-js/types").IAppContext;
70
+ useConfigContext: () => import("./config").UserConfig;
71
+ useResolvedConfigContext: () => NormalizedConfig;
72
+ }>, registerHook: (newHooks: Partial<CliHooks>) => void, mountHook: () => ToRunners<CliHooks>;
73
+ export declare const usePlugins: (plugins: string[]) => void;
74
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { CommonAPI } from '@modern-js/plugin';
2
+ import type { CliHooks } from './manager';
3
+ import { AppContext, ConfigContext, useAppContext, useConfigContext, ResolvedConfigContext, useResolvedConfigContext } from './context';
4
+ export declare const pluginAPI: {
5
+ setAppContext: (value: import("@modern-js/types/cli").IAppContext) => void;
6
+ useAppContext: () => import("@modern-js/types/cli").IAppContext;
7
+ useConfigContext: () => import("./config").UserConfig;
8
+ useResolvedConfigContext: () => import(".").NormalizedConfig;
9
+ };
10
+ /** all apis for cli plugin */
11
+
12
+ export declare type PluginAPI = typeof pluginAPI & CommonAPI<CliHooks>;
13
+ export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext };
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.6",
14
+ "version": "1.6.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -43,8 +43,8 @@
43
43
  "@babel/code-frame": "^7.14.5",
44
44
  "@babel/runtime": "^7",
45
45
  "@modern-js/load-config": "^1.2.2",
46
- "@modern-js/plugin": "^1.2.1",
47
- "@modern-js/utils": "^1.3.4",
46
+ "@modern-js/plugin": "^1.3.2",
47
+ "@modern-js/utils": "^1.3.7",
48
48
  "address": "^1.1.2",
49
49
  "ajv": "^8.6.2",
50
50
  "ajv-keywords": "^5.0.0",
@@ -59,20 +59,25 @@
59
59
  "v8-compile-cache": "^2.3.0"
60
60
  },
61
61
  "devDependencies": {
62
- "btsm": "2.2.2",
62
+ "@jest/types": "^27.0.6",
63
+ "@modern-js/types": "^1.3.6",
64
+ "@scripts/build": "0.0.0",
65
+ "@scripts/jest-config": "0.0.0",
63
66
  "@types/babel__code-frame": "^7.0.3",
64
- "@modern-js/types": "^1.3.4",
67
+ "@types/babel__core": "^7.1.16",
65
68
  "@types/jest": "^26",
69
+ "@types/less": "^3.0.3",
66
70
  "@types/lodash.clonedeep": "^4.5.6",
67
71
  "@types/lodash.mergewith": "^4.6.6",
68
72
  "@types/node": "^14",
69
73
  "@types/react": "^17",
70
74
  "@types/react-dom": "^17",
71
75
  "@types/signale": "^1.4.2",
72
- "typescript": "^4",
76
+ "btsm": "2.2.2",
73
77
  "jest": "^27",
74
- "@scripts/build": "0.0.0",
75
- "@scripts/jest-config": "0.0.0"
78
+ "sass": "^1.45.0",
79
+ "typescript": "^4",
80
+ "webpack": "^5.71.0"
76
81
  },
77
82
  "sideEffects": false,
78
83
  "modernConfig": {