@modern-js/core 1.6.0 → 1.7.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.
- package/CHANGELOG.md +31 -0
- package/dist/js/modern/config/index.js +11 -7
- package/dist/js/modern/config/mergeConfig.js +1 -1
- package/dist/js/modern/config/schema/index.js +1 -1
- package/dist/js/modern/config/types/index.js +1 -0
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +8 -1
- package/dist/js/modern/index.js +26 -9
- package/dist/js/modern/initWatcher.js +2 -2
- package/dist/js/modern/utils/commander.js +15 -15
- package/dist/js/node/config/index.js +38 -11
- package/dist/js/node/config/mergeConfig.js +2 -4
- package/dist/js/node/config/schema/index.js +3 -5
- package/dist/js/node/config/types/index.js +5 -0
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +8 -1
- package/dist/js/node/index.js +31 -10
- package/dist/js/node/initWatcher.js +2 -3
- package/dist/js/node/utils/commander.js +16 -19
- package/dist/types/config/index.d.ts +4 -140
- package/dist/types/config/types/index.d.ts +239 -0
- package/dist/types/config/types/less.d.ts +10 -0
- package/dist/types/config/types/sass.d.ts +8 -0
- package/dist/types/config/types/ssg.d.ts +13 -0
- package/dist/types/config/types/test.d.ts +15 -0
- package/dist/types/config/types/unbundle.d.ts +28 -0
- package/dist/types/context.d.ts +18 -6
- package/dist/types/index.d.ts +25 -1
- package/dist/types/initWatcher.d.ts +1 -2
- package/dist/types/utils/commander.d.ts +4 -7
- package/jest.config.js +0 -1
- package/package.json +16 -16
- package/tests/config.test.ts +14 -5
- package/tests/context.test.ts +17 -2
- package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
- package/tests/index.test.ts +15 -1
- package/tests/initWatcher.test.ts +2 -2
- package/tests/utils.test.ts +1 -2
|
@@ -1,148 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import http from 'http';
|
|
3
1
|
import { ErrorObject } from 'ajv';
|
|
4
|
-
import { MetaOptions } from '@modern-js/utils';
|
|
5
|
-
import type { NextFunction, ProxyOptions } from '@modern-js/types';
|
|
6
|
-
import { PluginConfig } from '../loadPlugins';
|
|
7
2
|
import { defaults } from './defaults';
|
|
8
3
|
import { mergeConfig, NormalizedConfig } from './mergeConfig';
|
|
9
4
|
import { PluginValidateSchema } from './schema';
|
|
5
|
+
import type { UserConfig, ConfigParam, LoadedConfig } from './types';
|
|
10
6
|
export { defaults as defaultsConfig };
|
|
11
7
|
export { mergeConfig };
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
entry: string;
|
|
15
|
-
enableFileSystemRoutes?: boolean;
|
|
16
|
-
disableMount?: boolean;
|
|
17
|
-
}>;
|
|
18
|
-
disableDefaultEntries?: boolean;
|
|
19
|
-
entriesDir?: string;
|
|
20
|
-
configDir?: string;
|
|
21
|
-
apiDir?: string;
|
|
22
|
-
envVars?: Array<string>;
|
|
23
|
-
globalVars?: Record<string, string>;
|
|
24
|
-
alias?: Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>);
|
|
25
|
-
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
26
|
-
include?: Array<string | RegExp>;
|
|
27
|
-
}
|
|
28
|
-
interface OutputConfig {
|
|
29
|
-
assetPrefix?: string;
|
|
30
|
-
htmlPath?: string;
|
|
31
|
-
jsPath?: string;
|
|
32
|
-
cssPath?: string;
|
|
33
|
-
mediaPath?: string;
|
|
34
|
-
path?: string;
|
|
35
|
-
title?: string;
|
|
36
|
-
titleByEntries?: Record<string, string>;
|
|
37
|
-
meta?: MetaOptions;
|
|
38
|
-
metaByEntries?: Record<string, MetaOptions>;
|
|
39
|
-
inject?: 'body' | 'head' | boolean;
|
|
40
|
-
injectByEntries?: Record<string, 'body' | 'head' | boolean>;
|
|
41
|
-
mountId?: string;
|
|
42
|
-
favicon?: string;
|
|
43
|
-
faviconByEntries?: Record<string, string | undefined>;
|
|
44
|
-
copy?: Array<Record<string, unknown> & {
|
|
45
|
-
from: string;
|
|
46
|
-
}>;
|
|
47
|
-
scriptExt?: Record<string, unknown>;
|
|
48
|
-
disableTsChecker?: boolean;
|
|
49
|
-
disableHtmlFolder?: boolean;
|
|
50
|
-
disableCssModuleExtension?: boolean;
|
|
51
|
-
disableCssExtract?: boolean;
|
|
52
|
-
enableCssModuleTSDeclaration?: boolean;
|
|
53
|
-
disableMinimize?: boolean;
|
|
54
|
-
enableInlineStyles?: boolean;
|
|
55
|
-
enableInlineScripts?: boolean;
|
|
56
|
-
disableSourceMap?: boolean;
|
|
57
|
-
disableInlineRuntimeChunk?: boolean;
|
|
58
|
-
disableAssetsCache?: boolean;
|
|
59
|
-
enableLatestDecorators?: boolean;
|
|
60
|
-
polyfill?: 'off' | 'usage' | 'entry' | 'ua';
|
|
61
|
-
dataUriLimit?: number;
|
|
62
|
-
templateParameters?: Record<string, unknown>;
|
|
63
|
-
templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
|
|
64
|
-
cssModuleLocalIdentName?: string;
|
|
65
|
-
enableModernMode?: boolean;
|
|
66
|
-
federation?: boolean;
|
|
67
|
-
disableNodePolyfill?: boolean;
|
|
68
|
-
enableTsLoader?: boolean;
|
|
69
|
-
}
|
|
70
|
-
interface ServerConfig {
|
|
71
|
-
routes?: Record<string, string | string[] | {
|
|
72
|
-
route: string | string[];
|
|
73
|
-
disableSpa?: boolean;
|
|
74
|
-
}>;
|
|
75
|
-
publicRoutes?: {
|
|
76
|
-
[filepath: string]: string;
|
|
77
|
-
};
|
|
78
|
-
ssr?: boolean | Record<string, unknown>;
|
|
79
|
-
ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
|
|
80
|
-
baseUrl?: string | Array<string>;
|
|
81
|
-
port?: number;
|
|
82
|
-
logger?: boolean | Record<string, any>;
|
|
83
|
-
metrics?: boolean | Record<string, any>;
|
|
84
|
-
enableMicroFrontendDebug?: boolean;
|
|
85
|
-
}
|
|
86
|
-
interface DevConfig {
|
|
87
|
-
assetPrefix?: string | boolean;
|
|
88
|
-
https?: boolean;
|
|
89
|
-
}
|
|
90
|
-
interface MicroFrontend {
|
|
91
|
-
enableHtmlEntry?: boolean;
|
|
92
|
-
externalBasicLibrary?: boolean;
|
|
93
|
-
moduleApp?: string;
|
|
94
|
-
}
|
|
95
|
-
interface DeployConfig {
|
|
96
|
-
microFrontend?: false | MicroFrontend;
|
|
97
|
-
domain?: string | Array<string>;
|
|
98
|
-
domainByEntries?: Record<string, string | Array<string>>;
|
|
99
|
-
}
|
|
100
|
-
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>) => Record<string, unknown> | void);
|
|
101
|
-
declare type RequestHandler = (req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
|
|
102
|
-
declare type DevServerConfig = {
|
|
103
|
-
proxy?: ProxyOptions;
|
|
104
|
-
headers?: Record<string, string>;
|
|
105
|
-
before?: RequestHandler[];
|
|
106
|
-
after?: RequestHandler[];
|
|
107
|
-
[propsName: string]: any;
|
|
108
|
-
};
|
|
109
|
-
interface ToolsConfig {
|
|
110
|
-
webpack?: ConfigFunction;
|
|
111
|
-
babel?: ConfigFunction;
|
|
112
|
-
autoprefixer?: ConfigFunction;
|
|
113
|
-
postcss?: ConfigFunction;
|
|
114
|
-
styledComponents?: ConfigFunction;
|
|
115
|
-
lodash?: ConfigFunction;
|
|
116
|
-
devServer?: DevServerConfig;
|
|
117
|
-
tsLoader?: ConfigFunction;
|
|
118
|
-
terser?: ConfigFunction;
|
|
119
|
-
minifyCss?: ConfigFunction;
|
|
120
|
-
esbuild?: Record<string, unknown>;
|
|
121
|
-
}
|
|
122
|
-
declare type RuntimeConfig = Record<string, any>;
|
|
123
|
-
interface RuntimeByEntriesConfig {
|
|
124
|
-
[name: string]: RuntimeConfig;
|
|
125
|
-
}
|
|
126
|
-
interface UserConfig {
|
|
127
|
-
source?: SourceConfig;
|
|
128
|
-
output?: OutputConfig;
|
|
129
|
-
server?: ServerConfig;
|
|
130
|
-
dev?: DevConfig;
|
|
131
|
-
deploy?: DeployConfig;
|
|
132
|
-
tools?: ToolsConfig;
|
|
133
|
-
plugins?: PluginConfig;
|
|
134
|
-
runtime?: RuntimeConfig;
|
|
135
|
-
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
136
|
-
}
|
|
137
|
-
declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
138
|
-
interface LoadedConfig {
|
|
139
|
-
config: UserConfig;
|
|
140
|
-
filePath: string | false;
|
|
141
|
-
dependencies: string[];
|
|
142
|
-
pkgConfig: UserConfig;
|
|
143
|
-
jsConfig: UserConfig;
|
|
144
|
-
}
|
|
8
|
+
export * from './types';
|
|
9
|
+
export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
|
|
145
10
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
146
11
|
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
147
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|
|
148
|
-
export type { SourceConfig, OutputConfig, ServerConfig, DevConfig, DeployConfig, ToolsConfig, RuntimeConfig, RuntimeByEntriesConfig, UserConfig, ConfigParam, LoadedConfig };
|
|
12
|
+
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|
|
@@ -0,0 +1,239 @@
|
|
|
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 { Configuration as WebpackConfiguration } from 'webpack';
|
|
7
|
+
import autoprefixer from 'autoprefixer';
|
|
8
|
+
import type { BasePluginOptions, TerserOptions as RawTerserOptions } from 'terser-webpack-plugin';
|
|
9
|
+
import type { PluginConfig } from '../../loadPlugins';
|
|
10
|
+
import type { TestConfig, JestConfig } from './test';
|
|
11
|
+
import type { SassConfig, SassLoaderOptions } from './sass';
|
|
12
|
+
import type { LessConfig, LessLoaderOptions } from './less';
|
|
13
|
+
import type { UnbundleConfig } from './unbundle';
|
|
14
|
+
import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
|
|
15
|
+
declare type AutoprefixerOptions = autoprefixer.Options;
|
|
16
|
+
declare type TerserOptions = BasePluginOptions & RawTerserOptions;
|
|
17
|
+
export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions };
|
|
18
|
+
export interface SourceConfig {
|
|
19
|
+
entries?: Record<string, string | {
|
|
20
|
+
entry: string;
|
|
21
|
+
enableFileSystemRoutes?: boolean;
|
|
22
|
+
disableMount?: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
disableDefaultEntries?: boolean;
|
|
25
|
+
entriesDir?: string;
|
|
26
|
+
configDir?: string;
|
|
27
|
+
apiDir?: string;
|
|
28
|
+
envVars?: Array<string>;
|
|
29
|
+
globalVars?: Record<string, string>;
|
|
30
|
+
alias?: Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>);
|
|
31
|
+
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
32
|
+
include?: Array<string | RegExp>;
|
|
33
|
+
/**
|
|
34
|
+
* The configuration of `source.designSystem` is provided by plugin `@modern-js/plugin-tailwindcss`.
|
|
35
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
36
|
+
* @requires `@modern-js/plugin-tailwindcss`
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
designSystem?: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
export interface OutputConfig {
|
|
42
|
+
assetPrefix?: string;
|
|
43
|
+
htmlPath?: string;
|
|
44
|
+
jsPath?: string;
|
|
45
|
+
cssPath?: string;
|
|
46
|
+
mediaPath?: string;
|
|
47
|
+
path?: string;
|
|
48
|
+
title?: string;
|
|
49
|
+
titleByEntries?: Record<string, string>;
|
|
50
|
+
meta?: MetaOptions;
|
|
51
|
+
metaByEntries?: Record<string, MetaOptions>;
|
|
52
|
+
inject?: 'body' | 'head' | boolean;
|
|
53
|
+
injectByEntries?: Record<string, 'body' | 'head' | boolean>;
|
|
54
|
+
mountId?: string;
|
|
55
|
+
favicon?: string;
|
|
56
|
+
faviconByEntries?: Record<string, string | undefined>;
|
|
57
|
+
copy?: Array<Record<string, unknown> & {
|
|
58
|
+
from: string;
|
|
59
|
+
}>;
|
|
60
|
+
scriptExt?: Record<string, unknown>;
|
|
61
|
+
disableTsChecker?: boolean;
|
|
62
|
+
disableHtmlFolder?: boolean;
|
|
63
|
+
disableCssModuleExtension?: boolean;
|
|
64
|
+
disableCssExtract?: boolean;
|
|
65
|
+
enableCssModuleTSDeclaration?: boolean;
|
|
66
|
+
disableMinimize?: boolean;
|
|
67
|
+
enableInlineStyles?: boolean;
|
|
68
|
+
enableInlineScripts?: boolean;
|
|
69
|
+
disableSourceMap?: boolean;
|
|
70
|
+
disableInlineRuntimeChunk?: boolean;
|
|
71
|
+
disableAssetsCache?: boolean;
|
|
72
|
+
enableLatestDecorators?: boolean;
|
|
73
|
+
polyfill?: 'off' | 'usage' | 'entry' | 'ua';
|
|
74
|
+
dataUriLimit?: number;
|
|
75
|
+
templateParameters?: Record<string, unknown>;
|
|
76
|
+
templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
|
|
77
|
+
cssModuleLocalIdentName?: string;
|
|
78
|
+
enableModernMode?: boolean;
|
|
79
|
+
federation?: boolean;
|
|
80
|
+
disableNodePolyfill?: boolean;
|
|
81
|
+
enableTsLoader?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Disables lazy import support for styles, currently supports antd and arco-design.
|
|
84
|
+
* The configuration of `output.disableAutoImportStyle` is provided by plugin `@modern-js/plugin-unbundle`.
|
|
85
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
86
|
+
* @requires `@modern-js/plugin-unbundle`
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
disableAutoImportStyle?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The configuration of `output.ssg` is provided by plugin `@modern-js/plugin-ssg`.
|
|
92
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
93
|
+
* @requires `@modern-js/plugin-ssg`
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
ssg?: SSGConfig;
|
|
97
|
+
}
|
|
98
|
+
export interface ServerConfig {
|
|
99
|
+
routes?: Record<string, string | string[] | {
|
|
100
|
+
route: string | string[];
|
|
101
|
+
disableSpa?: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
publicRoutes?: {
|
|
104
|
+
[filepath: string]: string;
|
|
105
|
+
};
|
|
106
|
+
ssr?: boolean | Record<string, unknown>;
|
|
107
|
+
ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
|
|
108
|
+
baseUrl?: string | Array<string>;
|
|
109
|
+
port?: number;
|
|
110
|
+
logger?: boolean | Record<string, any>;
|
|
111
|
+
metrics?: boolean | Record<string, any>;
|
|
112
|
+
enableMicroFrontendDebug?: boolean;
|
|
113
|
+
}
|
|
114
|
+
export declare type DevProxyOptions = string | Record<string, string>;
|
|
115
|
+
export interface DevConfig {
|
|
116
|
+
assetPrefix?: string | boolean;
|
|
117
|
+
https?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* The configuration of `dev.proxy` is provided by plugin `@modern-js/plugin-proxy`.
|
|
120
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
121
|
+
* @requires `@modern-js/plugin-proxy`
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
proxy?: DevProxyOptions;
|
|
125
|
+
/**
|
|
126
|
+
* The configuration of `dev.unbundle` is provided by plugin `@modern-js/plugin-unbundle`.
|
|
127
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
128
|
+
* @requires `@modern-js/plugin-unbundle`
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
unbundle?: UnbundleConfig;
|
|
132
|
+
}
|
|
133
|
+
export interface MicroFrontend {
|
|
134
|
+
enableHtmlEntry?: boolean;
|
|
135
|
+
externalBasicLibrary?: boolean;
|
|
136
|
+
moduleApp?: string;
|
|
137
|
+
}
|
|
138
|
+
export interface DeployConfig {
|
|
139
|
+
microFrontend?: false | MicroFrontend;
|
|
140
|
+
domain?: string | Array<string>;
|
|
141
|
+
domainByEntries?: Record<string, string | Array<string>>;
|
|
142
|
+
}
|
|
143
|
+
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>, utils?: any) => Record<string, unknown> | void);
|
|
144
|
+
export declare type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
|
|
145
|
+
export declare type DevServerConfig = {
|
|
146
|
+
proxy?: BffProxyOptions;
|
|
147
|
+
headers?: Record<string, string>;
|
|
148
|
+
before?: RequestHandler[];
|
|
149
|
+
after?: RequestHandler[];
|
|
150
|
+
[propsName: string]: any;
|
|
151
|
+
};
|
|
152
|
+
export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils?: any) => WebpackConfiguration | void);
|
|
153
|
+
export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils?: any) => TransformOptions | void);
|
|
154
|
+
export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
|
|
155
|
+
export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
|
|
156
|
+
export interface ToolsConfig {
|
|
157
|
+
webpack?: WebpackConfig;
|
|
158
|
+
babel?: BabelConfig;
|
|
159
|
+
autoprefixer?: AutoprefixerConfig;
|
|
160
|
+
postcss?: ConfigFunction;
|
|
161
|
+
styledComponents?: ConfigFunction;
|
|
162
|
+
lodash?: ConfigFunction;
|
|
163
|
+
devServer?: DevServerConfig;
|
|
164
|
+
tsLoader?: ConfigFunction;
|
|
165
|
+
terser?: TerserConfig;
|
|
166
|
+
minifyCss?: ConfigFunction;
|
|
167
|
+
esbuild?: Record<string, unknown>;
|
|
168
|
+
/**
|
|
169
|
+
* The configuration of `tools.tailwindcss` is provided by plugin `@modern-js/plugin-tailwindcss`.
|
|
170
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
171
|
+
* @requires `@modern-js/plugin-tailwindcss`
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
|
|
175
|
+
/**
|
|
176
|
+
* The configuration of `tools.jest` is provided by plugin `@modern-js/plugin-testing`.
|
|
177
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
178
|
+
* @requires `@modern-js/plugin-testing`
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
jest?: TestConfig['jest'];
|
|
182
|
+
/**
|
|
183
|
+
* The configuration of `tools.sass` is provided by plugin `@modern-js/plugin-sass`.
|
|
184
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
185
|
+
* @requires `@modern-js/plugin-sass`
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
sass?: SassConfig;
|
|
189
|
+
/**
|
|
190
|
+
* The configuration of `tools.less` is provided by plugin `@modern-js/plugin-less`.
|
|
191
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
192
|
+
* @requires `@modern-js/plugin-less`
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
less?: LessConfig;
|
|
196
|
+
}
|
|
197
|
+
export declare type RuntimeConfig = Record<string, any>;
|
|
198
|
+
export interface RuntimeByEntriesConfig {
|
|
199
|
+
[name: string]: RuntimeConfig;
|
|
200
|
+
}
|
|
201
|
+
export declare type BffConfig = Partial<{
|
|
202
|
+
prefix: string;
|
|
203
|
+
requestCreator: string;
|
|
204
|
+
fetcher: string;
|
|
205
|
+
proxy: Record<string, any>;
|
|
206
|
+
}>;
|
|
207
|
+
export interface UserConfig {
|
|
208
|
+
source?: SourceConfig;
|
|
209
|
+
output?: OutputConfig;
|
|
210
|
+
server?: ServerConfig;
|
|
211
|
+
dev?: DevConfig;
|
|
212
|
+
deploy?: DeployConfig;
|
|
213
|
+
tools?: ToolsConfig;
|
|
214
|
+
plugins?: PluginConfig;
|
|
215
|
+
runtime?: RuntimeConfig;
|
|
216
|
+
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
217
|
+
/**
|
|
218
|
+
* The configuration of `bff` is provided by plugin `@modern-js/plugin-bff`.
|
|
219
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
220
|
+
* @requires `@modern-js/plugin-bff`
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
bff?: BffConfig;
|
|
224
|
+
/**
|
|
225
|
+
* The configuration of `testing` is provided by plugin `@modern-js/plugin-testing`.
|
|
226
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
227
|
+
* @requires `@modern-js/plugin-testing`
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
testing?: TestConfig;
|
|
231
|
+
}
|
|
232
|
+
export declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
233
|
+
export interface LoadedConfig {
|
|
234
|
+
config: UserConfig;
|
|
235
|
+
filePath: string | false;
|
|
236
|
+
dependencies: string[];
|
|
237
|
+
pkgConfig: UserConfig;
|
|
238
|
+
jsConfig: UserConfig;
|
|
239
|
+
}
|
|
@@ -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, utils?: any) => 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, utils?: any) => 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
|
+
};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -27,9 +27,21 @@ export declare const useConfigContext: () => UserConfig;
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
export declare const useResolvedConfigContext: () => NormalizedConfig;
|
|
30
|
-
export declare const initAppContext: (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
export declare const initAppContext: ({
|
|
31
|
+
appDirectory,
|
|
32
|
+
plugins,
|
|
33
|
+
configFile,
|
|
34
|
+
options,
|
|
35
|
+
serverConfigFile
|
|
36
|
+
}: {
|
|
37
|
+
appDirectory: string;
|
|
38
|
+
plugins: LoadedPlugin[];
|
|
39
|
+
configFile: string | false;
|
|
40
|
+
options?: {
|
|
41
|
+
metaName?: string | undefined;
|
|
42
|
+
srcDir?: string | undefined;
|
|
43
|
+
distDir?: string | undefined;
|
|
44
|
+
sharedDir?: string | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
serverConfigFile: string;
|
|
47
|
+
}) => IAppContext;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type { NormalizedConfig, IAppContext };
|
|
|
15
15
|
declare const initAppDir: (cwd?: string | undefined) => Promise<string>;
|
|
16
16
|
export interface CoreOptions {
|
|
17
17
|
configFile?: string;
|
|
18
|
+
serverConfigFile?: string;
|
|
18
19
|
packageJsonConfig?: string;
|
|
19
20
|
plugins?: typeof INTERNAL_PLUGINS;
|
|
20
21
|
onSchemaError?: (error: ErrorObject) => void;
|
|
@@ -25,6 +26,24 @@ export interface CoreOptions {
|
|
|
25
26
|
sharedDir?: string;
|
|
26
27
|
};
|
|
27
28
|
}
|
|
29
|
+
export declare const mergeOptions: (options?: CoreOptions | undefined) => {
|
|
30
|
+
configFile?: string | undefined;
|
|
31
|
+
serverConfigFile: string;
|
|
32
|
+
packageJsonConfig?: string | undefined;
|
|
33
|
+
plugins?: {
|
|
34
|
+
[name: string]: {
|
|
35
|
+
cli?: string | undefined;
|
|
36
|
+
server?: string | undefined;
|
|
37
|
+
};
|
|
38
|
+
} | undefined;
|
|
39
|
+
onSchemaError?: ((error: ErrorObject) => void) | undefined;
|
|
40
|
+
options?: {
|
|
41
|
+
metaName?: string | undefined;
|
|
42
|
+
srcDir?: string | undefined;
|
|
43
|
+
distDir?: string | undefined;
|
|
44
|
+
sharedDir?: string | undefined;
|
|
45
|
+
} | undefined;
|
|
46
|
+
};
|
|
28
47
|
export declare const cli: {
|
|
29
48
|
init: (argv?: string[], options?: CoreOptions | undefined) => Promise<{
|
|
30
49
|
loadedConfig: import("./config").LoadedConfig;
|
|
@@ -34,4 +53,9 @@ export declare const cli: {
|
|
|
34
53
|
run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
|
|
35
54
|
restart: () => Promise<void>;
|
|
36
55
|
};
|
|
37
|
-
export { initAppDir, initAppContext };
|
|
56
|
+
export { initAppDir, initAppContext };
|
|
57
|
+
declare module '@modern-js/utils/compiled/commander' {
|
|
58
|
+
interface Command {
|
|
59
|
+
commandsMap: Map<string, Command>;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
1
|
import { LoadedConfig } from './config';
|
|
3
2
|
import { HooksRunner } from './manager';
|
|
4
|
-
export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<
|
|
3
|
+
export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<import("@modern-js/utils").FSWatcher | undefined>;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { program, Command } from '
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export { program, Command };
|
|
1
|
+
import { program, Command } from '@modern-js/utils';
|
|
2
|
+
export declare function initCommandsMap(): void;
|
|
3
|
+
export type { Command };
|
|
4
|
+
export { program };
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.7.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -42,37 +42,37 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/code-frame": "^7.14.5",
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
|
-
"@modern-js/load-config": "^1.
|
|
45
|
+
"@modern-js/load-config": "^1.3.0",
|
|
46
46
|
"@modern-js/plugin": "^1.3.2",
|
|
47
|
-
"@modern-js/utils": "^1.
|
|
47
|
+
"@modern-js/utils": "^1.4.1",
|
|
48
48
|
"address": "^1.1.2",
|
|
49
49
|
"ajv": "^8.6.2",
|
|
50
50
|
"ajv-keywords": "^5.0.0",
|
|
51
51
|
"better-ajv-errors": "^0.7.0",
|
|
52
|
-
"chokidar": "^3.5.2",
|
|
53
|
-
"commander": "^8.1.0",
|
|
54
52
|
"dotenv": "^10.0.0",
|
|
55
53
|
"dotenv-expand": "^5.1.0",
|
|
56
|
-
"lodash.clonedeep": "^4.5.0",
|
|
57
|
-
"lodash.mergewith": "^4.6.2",
|
|
58
|
-
"signale": "^1.4.0",
|
|
59
54
|
"v8-compile-cache": "^2.3.0"
|
|
60
55
|
},
|
|
61
56
|
"devDependencies": {
|
|
62
|
-
"
|
|
57
|
+
"@jest/types": "^27.0.6",
|
|
58
|
+
"@modern-js/types": "^1.4.0",
|
|
59
|
+
"@scripts/build": "0.0.0",
|
|
60
|
+
"@scripts/jest-config": "0.0.0",
|
|
63
61
|
"@types/babel__code-frame": "^7.0.3",
|
|
64
|
-
"@
|
|
62
|
+
"@types/babel__core": "^7.1.16",
|
|
65
63
|
"@types/jest": "^26",
|
|
66
|
-
"@types/
|
|
67
|
-
"@types/lodash.mergewith": "^4.6.6",
|
|
64
|
+
"@types/less": "^3.0.3",
|
|
68
65
|
"@types/node": "^14",
|
|
69
66
|
"@types/react": "^17",
|
|
70
67
|
"@types/react-dom": "^17",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
68
|
+
"autoprefixer": "^10.3.1",
|
|
69
|
+
"btsm": "2.2.2",
|
|
73
70
|
"jest": "^27",
|
|
74
|
-
"
|
|
75
|
-
"
|
|
71
|
+
"sass": "^1.45.0",
|
|
72
|
+
"terser-webpack-plugin": "^5.1.4",
|
|
73
|
+
"typescript": "^4",
|
|
74
|
+
"webpack": "^5.71.0",
|
|
75
|
+
"webpack-chain": "^6.5.1"
|
|
76
76
|
},
|
|
77
77
|
"sideEffects": false,
|
|
78
78
|
"modernConfig": {
|
package/tests/config.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
// import os from 'os';
|
|
3
|
-
import { isDev, getPort } from '@modern-js/utils';
|
|
4
|
-
import { resolveConfig } from '../src/config';
|
|
3
|
+
import { isDev, getPort, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
|
|
4
|
+
import { resolveConfig, addServerConfigToDeps } from '../src/config';
|
|
5
5
|
import {
|
|
6
6
|
cli,
|
|
7
7
|
loadUserConfig,
|
|
@@ -26,7 +26,7 @@ jest.mock('@modern-js/utils', () => ({
|
|
|
26
26
|
|
|
27
27
|
describe('config', () => {
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* TypeScript Type annotations cannot be used for esbuild-jest
|
|
30
30
|
* test files that use jest.mock('@some/module')
|
|
31
31
|
* refer to this esbuild-jest issue:
|
|
32
32
|
* https://github.com/aelbore/esbuild-jest/issues/57
|
|
@@ -133,5 +133,14 @@ describe('config', () => {
|
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
describe('addServerConfigToDeps', () => {
|
|
137
|
+
it('should add server config to deps', async () => {
|
|
138
|
+
const appDirectory = path.join(__dirname, './fixtures/index-test');
|
|
139
|
+
const deps: string[] = [];
|
|
140
|
+
await addServerConfigToDeps(deps, appDirectory, DEFAULT_SERVER_CONFIG);
|
|
141
|
+
expect(deps.length).toBe(1);
|
|
142
|
+
expect(deps[0]).toBe(
|
|
143
|
+
path.join(appDirectory, `${DEFAULT_SERVER_CONFIG}.js`),
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
});
|