@modern-js/core 1.2.0 → 1.3.2
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 +38 -0
- package/dist/js/modern/cli.js +29 -0
- package/dist/js/modern/config/index.js +11 -5
- package/dist/js/modern/context.js +24 -16
- package/dist/js/modern/index.js +19 -10
- package/dist/js/modern/loadPlugins.js +16 -2
- package/dist/js/node/cli.js +35 -0
- package/dist/js/node/config/index.js +11 -5
- package/dist/js/node/context.js +24 -16
- package/dist/js/node/index.js +28 -37
- package/dist/js/node/loadPlugins.js +17 -1
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config/index.d.ts +14 -13
- package/dist/types/context.d.ts +6 -1
- package/dist/types/index.d.ts +13 -7
- package/dist/types/loadPlugins.d.ts +5 -0
- package/jest.config.js +8 -0
- package/modern.config.js +0 -7
- package/package.json +17 -10
- package/tests/btsm.test.ts +20 -0
- package/tests/config.test.ts +137 -0
- package/tests/context.test.ts +63 -0
- package/tests/fixtures/index-test/package.json +3 -0
- package/tests/index.test.ts +74 -0
- package/tests/loadEnv.test.ts +1 -1
- package/tests/loadPlugin.test.ts +36 -1
- package/tests/mergeConfig.test.ts +1 -1
- package/tests/repeatKeyWarning.test.ts +2 -2
- package/tests/schema.test.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tests/utils.test.ts +8 -0
- package/tsconfig.json +1 -3
- package/src/config/defaults.ts +0 -101
- package/src/config/index.ts +0 -297
- package/src/config/mergeConfig.ts +0 -69
- package/src/config/schema/deploy.ts +0 -17
- package/src/config/schema/index.ts +0 -116
- package/src/config/schema/output.ts +0 -65
- package/src/config/schema/server.ts +0 -106
- package/src/config/schema/source.ts +0 -34
- package/src/config/schema/tools.ts +0 -15
- package/src/context.ts +0 -46
- package/src/index.ts +0 -277
- package/src/initWatcher.ts +0 -77
- package/src/loadEnv.ts +0 -23
- package/src/loadPlugins.ts +0 -91
- package/src/types.d.ts +0 -0
- package/src/utils/commander.ts +0 -22
- package/src/utils/repeatKeyWarning.ts +0 -29
package/src/config/defaults.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { OutputConfig, ServerConfig, SourceConfig } from '.';
|
|
2
|
-
|
|
3
|
-
const sourceDefaults: SourceConfig = {
|
|
4
|
-
entries: undefined,
|
|
5
|
-
disableDefaultEntries: false,
|
|
6
|
-
entriesDir: './src',
|
|
7
|
-
configDir: './config',
|
|
8
|
-
apiDir: './api',
|
|
9
|
-
envVars: [],
|
|
10
|
-
globalVars: undefined,
|
|
11
|
-
alias: undefined,
|
|
12
|
-
moduleScopes: undefined,
|
|
13
|
-
include: [],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const outputDefaults: OutputConfig = {
|
|
17
|
-
assetPrefix: '/',
|
|
18
|
-
htmlPath: 'html',
|
|
19
|
-
jsPath: 'static/js',
|
|
20
|
-
cssPath: 'static/css',
|
|
21
|
-
mediaPath: 'static/media',
|
|
22
|
-
path: 'dist',
|
|
23
|
-
title: '',
|
|
24
|
-
titleByEntries: undefined,
|
|
25
|
-
meta: {
|
|
26
|
-
charset: { charset: 'utf-8' },
|
|
27
|
-
viewport:
|
|
28
|
-
'width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
|
|
29
|
-
'http-equiv': { 'http-equiv': 'x-ua-compatible', content: 'ie=edge' },
|
|
30
|
-
renderer: 'webkit',
|
|
31
|
-
layoutmode: 'standard',
|
|
32
|
-
imagemode: 'force',
|
|
33
|
-
'wap-font-scale': 'no',
|
|
34
|
-
'format-detection': 'telephone=no',
|
|
35
|
-
},
|
|
36
|
-
metaByEntries: undefined,
|
|
37
|
-
inject: 'head',
|
|
38
|
-
injectByEntries: undefined,
|
|
39
|
-
mountId: 'root',
|
|
40
|
-
favicon: '',
|
|
41
|
-
faviconByEntries: undefined,
|
|
42
|
-
copy: undefined,
|
|
43
|
-
scriptExt: undefined,
|
|
44
|
-
disableHtmlFolder: false,
|
|
45
|
-
disableCssModuleExtension: false,
|
|
46
|
-
disableCssExtract: false,
|
|
47
|
-
enableCssModuleTSDeclaration: false,
|
|
48
|
-
disableMinimize: false,
|
|
49
|
-
enableInlineStyles: false,
|
|
50
|
-
enableInlineScripts: false,
|
|
51
|
-
disableSourceMap: false,
|
|
52
|
-
disableInlineRuntimeChunk: false,
|
|
53
|
-
disableAssetsCache: false,
|
|
54
|
-
enableLatestDecorators: false,
|
|
55
|
-
polyfill: 'entry',
|
|
56
|
-
dataUriLimit: 10000,
|
|
57
|
-
templateParameters: {},
|
|
58
|
-
templateParametersByEntries: undefined,
|
|
59
|
-
cssModuleLocalIdentName: '[name]__[local]--[hash:base64:5]',
|
|
60
|
-
enableModernMode: false,
|
|
61
|
-
federation: undefined,
|
|
62
|
-
disableNodePolyfill: false,
|
|
63
|
-
enableTsLoader: false,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const serverDefaults: ServerConfig = {
|
|
67
|
-
routes: undefined,
|
|
68
|
-
publicRoutes: undefined,
|
|
69
|
-
ssr: undefined,
|
|
70
|
-
ssrByEntries: undefined,
|
|
71
|
-
baseUrl: '/',
|
|
72
|
-
port: 8080,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const devDefaults = { assetPrefix: false, https: false };
|
|
76
|
-
|
|
77
|
-
const deployDefaults = {
|
|
78
|
-
domain: '',
|
|
79
|
-
domainByEntries: undefined,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const toolsDefaults = {
|
|
83
|
-
webpack: undefined,
|
|
84
|
-
babel: undefined,
|
|
85
|
-
postcss: undefined,
|
|
86
|
-
autoprefixer: undefined,
|
|
87
|
-
lodash: undefined,
|
|
88
|
-
devServer: undefined,
|
|
89
|
-
tsLoader: undefined,
|
|
90
|
-
terser: undefined,
|
|
91
|
-
minifyCss: undefined,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export const defaults = {
|
|
95
|
-
source: sourceDefaults,
|
|
96
|
-
output: outputDefaults,
|
|
97
|
-
server: serverDefaults,
|
|
98
|
-
dev: devDefaults,
|
|
99
|
-
deploy: deployDefaults,
|
|
100
|
-
tools: toolsDefaults,
|
|
101
|
-
};
|
package/src/config/index.ts
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from '@modern-js/load-config';
|
|
2
|
-
import Ajv, { ErrorObject } from 'ajv';
|
|
3
|
-
import ajvKeywords from 'ajv-keywords';
|
|
4
|
-
import logger from 'signale';
|
|
5
|
-
import {
|
|
6
|
-
createDebugger,
|
|
7
|
-
getPort,
|
|
8
|
-
isDev,
|
|
9
|
-
MetaOptions,
|
|
10
|
-
PLUGIN_SCHEMAS,
|
|
11
|
-
chalk,
|
|
12
|
-
} from '@modern-js/utils';
|
|
13
|
-
import mergeWith from 'lodash.mergewith';
|
|
14
|
-
import betterAjvErrors from 'better-ajv-errors';
|
|
15
|
-
import { codeFrameColumns } from '@babel/code-frame';
|
|
16
|
-
import { PluginConfig } from '../loadPlugins';
|
|
17
|
-
import { repeatKeyWarning } from '../utils/repeatKeyWarning';
|
|
18
|
-
import { defaults } from './defaults';
|
|
19
|
-
import { mergeConfig, NormalizedConfig } from './mergeConfig';
|
|
20
|
-
import { patchSchema, PluginValidateSchema } from './schema';
|
|
21
|
-
|
|
22
|
-
const debug = createDebugger('resolve-config');
|
|
23
|
-
|
|
24
|
-
export { defaults as defaultsConfig };
|
|
25
|
-
export { mergeConfig };
|
|
26
|
-
|
|
27
|
-
export interface SourceConfig {
|
|
28
|
-
entries?: Record<
|
|
29
|
-
string,
|
|
30
|
-
| string
|
|
31
|
-
| {
|
|
32
|
-
entry: string;
|
|
33
|
-
enableFileSystemRoutes?: boolean;
|
|
34
|
-
disableMount?: boolean;
|
|
35
|
-
}
|
|
36
|
-
>;
|
|
37
|
-
disableDefaultEntries?: boolean;
|
|
38
|
-
entriesDir?: string;
|
|
39
|
-
configDir?: string;
|
|
40
|
-
apiDir?: string;
|
|
41
|
-
envVars?: Array<string>;
|
|
42
|
-
globalVars?: Record<string, string>;
|
|
43
|
-
alias?:
|
|
44
|
-
| Record<string, string>
|
|
45
|
-
| ((aliases: Record<string, string>) => Record<string, unknown>);
|
|
46
|
-
moduleScopes?:
|
|
47
|
-
| Array<string | RegExp>
|
|
48
|
-
| ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
49
|
-
include?: Array<string | RegExp>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface OutputConfig {
|
|
53
|
-
assetPrefix?: string;
|
|
54
|
-
htmlPath?: string;
|
|
55
|
-
jsPath?: string;
|
|
56
|
-
cssPath?: string;
|
|
57
|
-
mediaPath?: string;
|
|
58
|
-
path?: string;
|
|
59
|
-
title?: string;
|
|
60
|
-
titleByEntries?: Record<string, string>;
|
|
61
|
-
meta?: MetaOptions;
|
|
62
|
-
metaByEntries?: Record<string, MetaOptions>;
|
|
63
|
-
inject?: 'body' | 'head' | boolean;
|
|
64
|
-
injectByEntries?: Record<string, 'body' | 'head' | boolean>;
|
|
65
|
-
mountId?: string;
|
|
66
|
-
favicon?: string;
|
|
67
|
-
faviconByEntries?: Record<string, string | undefined>;
|
|
68
|
-
copy?: Record<string, unknown>;
|
|
69
|
-
scriptExt?: Record<string, unknown>;
|
|
70
|
-
disableHtmlFolder?: boolean;
|
|
71
|
-
disableCssModuleExtension?: boolean;
|
|
72
|
-
disableCssExtract?: boolean;
|
|
73
|
-
enableCssModuleTSDeclaration?: boolean;
|
|
74
|
-
disableMinimize?: boolean;
|
|
75
|
-
enableInlineStyles?: boolean;
|
|
76
|
-
enableInlineScripts?: boolean;
|
|
77
|
-
disableSourceMap?: boolean;
|
|
78
|
-
disableInlineRuntimeChunk?: boolean;
|
|
79
|
-
disableAssetsCache?: boolean;
|
|
80
|
-
enableLatestDecorators?: boolean;
|
|
81
|
-
polyfill?: 'off' | 'usage' | 'entry' | 'ua';
|
|
82
|
-
dataUriLimit?: number;
|
|
83
|
-
templateParameters?: Record<string, unknown>;
|
|
84
|
-
templateParametersByEntries?: Record<
|
|
85
|
-
string,
|
|
86
|
-
Record<string, unknown> | undefined
|
|
87
|
-
>;
|
|
88
|
-
cssModuleLocalIdentName?: string;
|
|
89
|
-
enableModernMode?: boolean;
|
|
90
|
-
federation?: boolean;
|
|
91
|
-
disableNodePolyfill?: boolean;
|
|
92
|
-
enableTsLoader?: boolean;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export interface ServerConfig {
|
|
96
|
-
routes?: Record<
|
|
97
|
-
string,
|
|
98
|
-
| string
|
|
99
|
-
| {
|
|
100
|
-
route: string | string[];
|
|
101
|
-
disableSpa?: boolean;
|
|
102
|
-
}
|
|
103
|
-
>;
|
|
104
|
-
publicRoutes?: { [filepath: string]: string };
|
|
105
|
-
ssr?: boolean | Record<string, unknown>;
|
|
106
|
-
ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
|
|
107
|
-
baseUrl?: string | Array<string>;
|
|
108
|
-
port?: number;
|
|
109
|
-
logger?: Record<string, any>;
|
|
110
|
-
metrics?: Record<string, any>;
|
|
111
|
-
enableMicroFrontendDebug?: boolean;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface DevConfig {
|
|
115
|
-
assetPrefix?: string | boolean;
|
|
116
|
-
https?: boolean;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface DeployConfig {
|
|
120
|
-
microFrontend?: boolean & Record<string, unknown>;
|
|
121
|
-
domain?: string | Array<string>;
|
|
122
|
-
domainByEntries?: Record<string, string | Array<string>>;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
type ConfigFunction =
|
|
126
|
-
| Record<string, unknown>
|
|
127
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
128
|
-
| ((config: Record<string, unknown>) => Record<string, unknown> | void);
|
|
129
|
-
export interface ToolsConfig {
|
|
130
|
-
webpack?: ConfigFunction;
|
|
131
|
-
babel?: ConfigFunction;
|
|
132
|
-
autoprefixer?: ConfigFunction;
|
|
133
|
-
postcss?: ConfigFunction;
|
|
134
|
-
lodash?: ConfigFunction;
|
|
135
|
-
devServer?: Record<string, unknown>;
|
|
136
|
-
tsLoader?: ConfigFunction;
|
|
137
|
-
terser?: ConfigFunction;
|
|
138
|
-
minifyCss?: ConfigFunction;
|
|
139
|
-
esbuild?: Record<string, unknown>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export type RuntimeConfig = Record<string, any>;
|
|
143
|
-
|
|
144
|
-
export interface RuntimeByEntriesConfig {
|
|
145
|
-
[name: string]: RuntimeConfig;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface UserConfig {
|
|
149
|
-
source?: SourceConfig;
|
|
150
|
-
output?: OutputConfig;
|
|
151
|
-
server?: ServerConfig;
|
|
152
|
-
dev?: DevConfig;
|
|
153
|
-
deploy?: DeployConfig;
|
|
154
|
-
tools?: ToolsConfig;
|
|
155
|
-
plugins?: PluginConfig;
|
|
156
|
-
runtime?: RuntimeConfig;
|
|
157
|
-
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export type ConfigParam =
|
|
161
|
-
| UserConfig
|
|
162
|
-
| Promise<UserConfig>
|
|
163
|
-
| ((env: any) => UserConfig | Promise<UserConfig>);
|
|
164
|
-
|
|
165
|
-
export interface LoadedConfig {
|
|
166
|
-
config: UserConfig;
|
|
167
|
-
filePath: string | false;
|
|
168
|
-
dependencies: string[];
|
|
169
|
-
pkgConfig: UserConfig;
|
|
170
|
-
jsConfig: UserConfig;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export const defineConfig = (config: ConfigParam): ConfigParam => config;
|
|
174
|
-
|
|
175
|
-
export const loadUserConfig = async (
|
|
176
|
-
appDirectory: string,
|
|
177
|
-
filePath?: string,
|
|
178
|
-
): Promise<LoadedConfig> => {
|
|
179
|
-
const loaded = await loadConfig<ConfigParam>(appDirectory, filePath);
|
|
180
|
-
|
|
181
|
-
const config = !loaded
|
|
182
|
-
? {}
|
|
183
|
-
: await (typeof loaded.config === 'function'
|
|
184
|
-
? loaded.config(0)
|
|
185
|
-
: loaded.config);
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
config: mergeWith({}, config || {}, loaded?.pkgConfig || {}),
|
|
189
|
-
jsConfig: config || {},
|
|
190
|
-
pkgConfig: (loaded?.pkgConfig || {}) as UserConfig,
|
|
191
|
-
filePath: loaded?.path,
|
|
192
|
-
dependencies: loaded?.dependencies || [],
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const showAdditionalPropertiesError = (error: ErrorObject) => {
|
|
197
|
-
if (
|
|
198
|
-
error.keyword === 'additionalProperties' &&
|
|
199
|
-
error.instancePath &&
|
|
200
|
-
error.params.additionalProperty
|
|
201
|
-
) {
|
|
202
|
-
const target = `${error.instancePath.substr(1)}.${
|
|
203
|
-
error.params.additionalProperty
|
|
204
|
-
}`;
|
|
205
|
-
|
|
206
|
-
const name = Object.keys(PLUGIN_SCHEMAS).find(key =>
|
|
207
|
-
(PLUGIN_SCHEMAS as Record<string, any>)[key].some(
|
|
208
|
-
(schemaItem: any) => schemaItem.target === target,
|
|
209
|
-
),
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
if (name) {
|
|
213
|
-
logger.warn(
|
|
214
|
-
`The configuration of ${chalk.bold(
|
|
215
|
-
target,
|
|
216
|
-
)} is provided by plugin ${chalk.bold(name)}. Please use ${chalk.bold(
|
|
217
|
-
'yarn new',
|
|
218
|
-
)} to enable the corresponding capability.\n`,
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
/* eslint-disable max-statements, max-params */
|
|
225
|
-
export const resolveConfig = async (
|
|
226
|
-
loaded: LoadedConfig,
|
|
227
|
-
configs: UserConfig[],
|
|
228
|
-
schemas: PluginValidateSchema[],
|
|
229
|
-
isRestart: boolean,
|
|
230
|
-
argv: string[],
|
|
231
|
-
): Promise<NormalizedConfig> => {
|
|
232
|
-
const { config: userConfig, jsConfig, pkgConfig } = loaded;
|
|
233
|
-
|
|
234
|
-
const ajv = new Ajv({ $data: true, strict: false });
|
|
235
|
-
|
|
236
|
-
ajvKeywords(ajv);
|
|
237
|
-
|
|
238
|
-
const validateSchema = patchSchema(schemas);
|
|
239
|
-
|
|
240
|
-
const validate = ajv.compile(validateSchema);
|
|
241
|
-
|
|
242
|
-
repeatKeyWarning(validateSchema, jsConfig, pkgConfig);
|
|
243
|
-
|
|
244
|
-
// validate user config.
|
|
245
|
-
const valid = validate(userConfig);
|
|
246
|
-
|
|
247
|
-
if (!valid && validate.errors?.length) {
|
|
248
|
-
showAdditionalPropertiesError(validate?.errors[0]);
|
|
249
|
-
const errors = betterAjvErrors(
|
|
250
|
-
validateSchema,
|
|
251
|
-
userConfig,
|
|
252
|
-
validate.errors?.map(e => ({
|
|
253
|
-
...e,
|
|
254
|
-
dataPath: e.instancePath,
|
|
255
|
-
})),
|
|
256
|
-
{
|
|
257
|
-
format: 'js',
|
|
258
|
-
indent: 2,
|
|
259
|
-
},
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
logger.log(
|
|
263
|
-
codeFrameColumns(
|
|
264
|
-
JSON.stringify(userConfig, null, 2),
|
|
265
|
-
{
|
|
266
|
-
start: errors?.[0].start as any,
|
|
267
|
-
end: errors?.[0].end as any,
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
highlightCode: true,
|
|
271
|
-
message: errors?.[0].error,
|
|
272
|
-
},
|
|
273
|
-
),
|
|
274
|
-
);
|
|
275
|
-
throw new Error(`Validate configuration error`);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// validate config from plugins.
|
|
279
|
-
for (const config of configs) {
|
|
280
|
-
if (!validate(config)) {
|
|
281
|
-
logger.error(validate.errors);
|
|
282
|
-
throw new Error(`Validate configuration error.`);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
const resolved = mergeConfig([defaults, ...configs, userConfig]);
|
|
286
|
-
|
|
287
|
-
resolved._raw = loaded.config;
|
|
288
|
-
|
|
289
|
-
if (isDev() && argv[0] === 'dev' && !isRestart) {
|
|
290
|
-
resolved.server.port = await getPort(resolved.server.port!);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
debug('resolved %o', resolved);
|
|
294
|
-
|
|
295
|
-
return resolved;
|
|
296
|
-
};
|
|
297
|
-
/* eslint-enable max-statements, max-params */
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import mergeWith from 'lodash.mergewith';
|
|
2
|
-
import { isFunction } from '@modern-js/utils';
|
|
3
|
-
import { UserConfig, SourceConfig, ToolsConfig } from '.';
|
|
4
|
-
|
|
5
|
-
export interface NormalizedSourceConfig
|
|
6
|
-
extends Omit<SourceConfig, 'alias' | 'moduleScopes'> {
|
|
7
|
-
alias: SourceConfig['alias'] | Array<SourceConfig['alias']>;
|
|
8
|
-
moduleScopes:
|
|
9
|
-
| SourceConfig['moduleScopes']
|
|
10
|
-
| Array<SourceConfig['moduleScopes']>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface NormalizedToolsConfig
|
|
14
|
-
extends Omit<
|
|
15
|
-
ToolsConfig,
|
|
16
|
-
| 'webpack'
|
|
17
|
-
| 'babel'
|
|
18
|
-
| 'postcss'
|
|
19
|
-
| 'autoprefixer'
|
|
20
|
-
| 'lodash'
|
|
21
|
-
| 'tsLoader'
|
|
22
|
-
| 'terser'
|
|
23
|
-
| 'minifyCss'
|
|
24
|
-
| 'esbuild'
|
|
25
|
-
> {
|
|
26
|
-
webpack: ToolsConfig['webpack'] | Array<NonNullable<ToolsConfig['webpack']>>;
|
|
27
|
-
babel: ToolsConfig['babel'] | Array<NonNullable<ToolsConfig['babel']>>;
|
|
28
|
-
postcss: ToolsConfig['postcss'] | Array<NonNullable<ToolsConfig['postcss']>>;
|
|
29
|
-
autoprefixer:
|
|
30
|
-
| ToolsConfig['autoprefixer']
|
|
31
|
-
| Array<NonNullable<ToolsConfig['autoprefixer']>>;
|
|
32
|
-
lodash: ToolsConfig['lodash'] | Array<ToolsConfig['lodash']>;
|
|
33
|
-
tsLoader:
|
|
34
|
-
| ToolsConfig['tsLoader']
|
|
35
|
-
| Array<NonNullable<ToolsConfig['tsLoader']>>;
|
|
36
|
-
terser: ToolsConfig['terser'] | Array<NonNullable<ToolsConfig['terser']>>;
|
|
37
|
-
minifyCss:
|
|
38
|
-
| ToolsConfig['minifyCss']
|
|
39
|
-
| Array<NonNullable<ToolsConfig['minifyCss']>>;
|
|
40
|
-
esbuild: ToolsConfig['esbuild'] | Array<NonNullable<ToolsConfig['esbuild']>>;
|
|
41
|
-
}
|
|
42
|
-
export interface NormalizedConfig
|
|
43
|
-
extends Omit<Required<UserConfig>, 'source' | 'tools'> {
|
|
44
|
-
source: NormalizedSourceConfig;
|
|
45
|
-
tools: NormalizedToolsConfig;
|
|
46
|
-
cliOptions?: Record<string, any>;
|
|
47
|
-
_raw: UserConfig;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* merge configuration from modern.config.js and plugins.
|
|
52
|
-
*
|
|
53
|
-
* @param configs - Configuration from modern.config.ts or plugin's config hook.
|
|
54
|
-
* @returns - normalized user config.
|
|
55
|
-
*/
|
|
56
|
-
export const mergeConfig = (
|
|
57
|
-
configs: Array<UserConfig | NormalizedConfig>,
|
|
58
|
-
): NormalizedConfig =>
|
|
59
|
-
mergeWith({}, ...configs, (target: any, source: any) => {
|
|
60
|
-
if (Array.isArray(target) && Array.isArray(source)) {
|
|
61
|
-
return [...target, ...source];
|
|
62
|
-
}
|
|
63
|
-
if (isFunction(source)) {
|
|
64
|
-
return Array.isArray(target)
|
|
65
|
-
? [...target, source]
|
|
66
|
-
: [target, source].filter(Boolean);
|
|
67
|
-
}
|
|
68
|
-
return undefined;
|
|
69
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
|
|
2
|
-
|
|
3
|
-
export const deploy = {
|
|
4
|
-
type: 'object',
|
|
5
|
-
properties: {
|
|
6
|
-
microFrontend: {
|
|
7
|
-
type: ['boolean', 'object'],
|
|
8
|
-
},
|
|
9
|
-
domain: { type: ['array', 'string'] },
|
|
10
|
-
domainByEntries: {
|
|
11
|
-
type: 'object',
|
|
12
|
-
patternProperties: {
|
|
13
|
-
[ENTRY_NAME_PATTERN]: { type: ['array', 'string'] },
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
};
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { JSONSchemaType } from 'ajv';
|
|
2
|
-
import { isObject, createDebugger } from '@modern-js/utils';
|
|
3
|
-
import cloneDeep from 'lodash.clonedeep';
|
|
4
|
-
import { source } from './source';
|
|
5
|
-
import { output } from './output';
|
|
6
|
-
import { server } from './server';
|
|
7
|
-
import { deploy } from './deploy';
|
|
8
|
-
import { tools } from './tools';
|
|
9
|
-
|
|
10
|
-
const debug = createDebugger('validate-schema');
|
|
11
|
-
|
|
12
|
-
const plugins = {
|
|
13
|
-
type: 'array',
|
|
14
|
-
additionalProperties: false,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const dev = {
|
|
18
|
-
type: 'object',
|
|
19
|
-
properties: {
|
|
20
|
-
assetPrefix: { type: ['boolean', 'string'] },
|
|
21
|
-
https: {
|
|
22
|
-
type: 'boolean',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
additionalProperties: false,
|
|
26
|
-
};
|
|
27
|
-
export interface PluginValidateSchema {
|
|
28
|
-
target: string;
|
|
29
|
-
schema: JSONSchemaType<any>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const patchSchema = (
|
|
33
|
-
pluginSchemas: Array<PluginValidateSchema | PluginValidateSchema[]>,
|
|
34
|
-
) => {
|
|
35
|
-
const finalSchema = cloneDeep({
|
|
36
|
-
type: 'object',
|
|
37
|
-
additionalProperties: false,
|
|
38
|
-
properties: {
|
|
39
|
-
source,
|
|
40
|
-
output,
|
|
41
|
-
server,
|
|
42
|
-
deploy,
|
|
43
|
-
plugins,
|
|
44
|
-
dev,
|
|
45
|
-
tools,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const findTargetNode = (props: string[]) => {
|
|
50
|
-
let node = finalSchema.properties;
|
|
51
|
-
|
|
52
|
-
for (const prop of props) {
|
|
53
|
-
node = node[prop as keyof typeof node] as any;
|
|
54
|
-
if (!node || !isObject(node)) {
|
|
55
|
-
throw new Error(`add schema ${props.join('.')} error`);
|
|
56
|
-
}
|
|
57
|
-
(node as any).properties = (node as any).hasOwnProperty('properties')
|
|
58
|
-
? (node as any).properties
|
|
59
|
-
: {};
|
|
60
|
-
|
|
61
|
-
node = (node as any).properties;
|
|
62
|
-
}
|
|
63
|
-
return node;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const finalPluginSchemas: PluginValidateSchema[] = [];
|
|
67
|
-
pluginSchemas.forEach(item => {
|
|
68
|
-
if (Array.isArray(item)) {
|
|
69
|
-
finalPluginSchemas.push(...item);
|
|
70
|
-
} else {
|
|
71
|
-
finalPluginSchemas.push(item);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
for (const { target, schema } of finalPluginSchemas) {
|
|
75
|
-
if (!target) {
|
|
76
|
-
throw new Error(`should return target property in plugin schema.`);
|
|
77
|
-
}
|
|
78
|
-
const props = target.split('.');
|
|
79
|
-
|
|
80
|
-
const mountProperty = props.pop();
|
|
81
|
-
|
|
82
|
-
const targetNode = findTargetNode(props);
|
|
83
|
-
|
|
84
|
-
if (targetNode.hasOwnProperty(mountProperty!)) {
|
|
85
|
-
throw new Error(`${target} already exists in current validate schema`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
(targetNode as any)[mountProperty as string] = cloneDeep(schema);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
debug(`final validate schema: %o`, finalSchema);
|
|
92
|
-
|
|
93
|
-
return finalSchema;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const traverseSchema = (schema: ReturnType<typeof patchSchema>) => {
|
|
97
|
-
const keys: string[] = [];
|
|
98
|
-
|
|
99
|
-
const traverse = (
|
|
100
|
-
{ properties }: { properties: any },
|
|
101
|
-
old: string[] = [],
|
|
102
|
-
) => {
|
|
103
|
-
for (const key of Object.keys(properties)) {
|
|
104
|
-
const current = [...old, key];
|
|
105
|
-
if (properties[key].type === 'object' && properties[key].properties) {
|
|
106
|
-
traverse(properties[key], current);
|
|
107
|
-
} else {
|
|
108
|
-
keys.push(current.join('.'));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
traverse(schema);
|
|
114
|
-
|
|
115
|
-
return keys;
|
|
116
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ENTRY_NAME_PATTERN } from '@modern-js/utils';
|
|
2
|
-
|
|
3
|
-
export const output = {
|
|
4
|
-
type: 'object',
|
|
5
|
-
additionalProperties: false,
|
|
6
|
-
properties: {
|
|
7
|
-
assetPrefix: { type: 'string' },
|
|
8
|
-
path: { type: 'string' },
|
|
9
|
-
jsPath: { type: 'string' },
|
|
10
|
-
cssPath: { type: 'string' },
|
|
11
|
-
htmlPath: { type: 'string' },
|
|
12
|
-
mediaPath: { type: 'string' },
|
|
13
|
-
mountId: { type: 'string' },
|
|
14
|
-
favicon: { type: 'string' },
|
|
15
|
-
faviconByEntries: {
|
|
16
|
-
type: 'object',
|
|
17
|
-
patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'string' } },
|
|
18
|
-
},
|
|
19
|
-
title: { type: 'string' },
|
|
20
|
-
titleByEntries: {
|
|
21
|
-
type: 'object',
|
|
22
|
-
patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'string' } },
|
|
23
|
-
},
|
|
24
|
-
meta: { type: 'object' },
|
|
25
|
-
metaByEntries: {
|
|
26
|
-
type: 'object',
|
|
27
|
-
patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'object' } },
|
|
28
|
-
},
|
|
29
|
-
inject: { enum: [true, 'head', 'body', false] },
|
|
30
|
-
injectByEntries: {
|
|
31
|
-
type: 'object',
|
|
32
|
-
patternProperties: {
|
|
33
|
-
[ENTRY_NAME_PATTERN]: { enum: [true, 'head', 'body', false] },
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
copy: { type: 'array' },
|
|
37
|
-
scriptExt: { type: 'object' },
|
|
38
|
-
disableHtmlFolder: { type: 'boolean' },
|
|
39
|
-
disableCssModuleExtension: { type: 'boolean' },
|
|
40
|
-
disableCssExtract: { type: 'boolean' },
|
|
41
|
-
enableCssModuleTSDeclaration: { type: 'boolean' },
|
|
42
|
-
disableMinimize: { type: 'boolean' },
|
|
43
|
-
enableInlineStyles: { type: 'boolean' },
|
|
44
|
-
enableInlineScripts: { type: 'boolean' },
|
|
45
|
-
disableSourceMap: { type: 'boolean' },
|
|
46
|
-
disableInlineRuntimeChunk: { type: 'boolean' },
|
|
47
|
-
disableAssetsCache: { type: 'boolean' },
|
|
48
|
-
enableLatestDecorators: { type: 'boolean' },
|
|
49
|
-
enableTsLoader: { type: 'boolean' },
|
|
50
|
-
dataUriLimit: { type: 'number' },
|
|
51
|
-
templateParameters: { type: 'object' },
|
|
52
|
-
templateParametersByEntries: {
|
|
53
|
-
type: 'object',
|
|
54
|
-
patternProperties: { [ENTRY_NAME_PATTERN]: { type: 'object' } },
|
|
55
|
-
},
|
|
56
|
-
polyfill: {
|
|
57
|
-
type: 'string',
|
|
58
|
-
enum: ['usage', 'entry', 'off', 'ua'],
|
|
59
|
-
},
|
|
60
|
-
cssModuleLocalIdentName: { type: 'string' },
|
|
61
|
-
federation: { type: 'object' },
|
|
62
|
-
disableNodePolyfill: { type: 'boolean' },
|
|
63
|
-
enableModernMode: { type: 'boolean' },
|
|
64
|
-
},
|
|
65
|
-
};
|