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