@modern-js/core 1.3.1 → 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 +12 -0
- package/dist/js/modern/context.js +24 -16
- package/dist/js/modern/index.js +1 -1
- package/dist/js/node/context.js +24 -16
- package/dist/js/node/index.js +1 -1
- package/dist/types/context.d.ts +6 -1
- package/dist/types/index.d.ts +6 -0
- package/package.json +5 -5
- package/tests/context.test.ts +35 -0
- package/src/cli.ts +0 -36
- package/src/config/defaults.ts +0 -101
- package/src/config/index.ts +0 -322
- 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 -278
- package/src/initWatcher.ts +0 -77
- package/src/loadEnv.ts +0 -23
- package/src/loadPlugins.ts +0 -108
- package/src/types.d.ts +0 -0
- package/src/utils/commander.ts +0 -22
- package/src/utils/repeatKeyWarning.ts +0 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 83166714: change .npmignore
|
|
8
|
+
- c3de9882: fix: internalDirectory path
|
|
9
|
+
- 33ff48af: feat: extend CoreOptions
|
|
10
|
+
- Updated dependencies [83166714]
|
|
11
|
+
- @modern-js/load-config@1.2.1
|
|
12
|
+
- @modern-js/plugin@1.2.1
|
|
13
|
+
- @modern-js/utils@1.2.2
|
|
14
|
+
|
|
3
15
|
## 1.3.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -7,19 +7,27 @@ export const ResolvedConfigContext = createContext({});
|
|
|
7
7
|
export const useAppContext = () => AppContext.use().value;
|
|
8
8
|
export const useConfigContext = () => ConfigContext.use().value;
|
|
9
9
|
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
10
|
-
export const initAppContext = (appDirectory, plugins, configFile) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
11
|
+
const {
|
|
12
|
+
srcDir = 'src',
|
|
13
|
+
distDir = '',
|
|
14
|
+
sharedDir = 'shared',
|
|
15
|
+
internalDir = '.modern-js'
|
|
16
|
+
} = options || {};
|
|
17
|
+
return {
|
|
18
|
+
appDirectory,
|
|
19
|
+
configFile,
|
|
20
|
+
ip: address.ip(),
|
|
21
|
+
port: 0,
|
|
22
|
+
packageName: require(path.resolve(appDirectory, './package.json')).name,
|
|
23
|
+
srcDirectory: path.resolve(appDirectory, srcDir),
|
|
24
|
+
distDirectory: distDir,
|
|
25
|
+
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
|
26
|
+
nodeModulesDirectory: path.resolve(appDirectory, './node_modules'),
|
|
27
|
+
internalDirectory: path.resolve(appDirectory, `./node_modules/${internalDir}`),
|
|
28
|
+
plugins,
|
|
29
|
+
htmlTemplates: {},
|
|
30
|
+
serverRoutes: [],
|
|
31
|
+
entrypoints: []
|
|
32
|
+
};
|
|
33
|
+
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -74,7 +74,7 @@ const createCli = () => {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
77
|
-
const appContext = initAppContext(appDirectory, plugins, loaded.filePath);
|
|
77
|
+
const appContext = initAppContext(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
78
78
|
manager.run(() => {
|
|
79
79
|
ConfigContext.set(loaded.config);
|
|
80
80
|
AppContext.set(appContext);
|
package/dist/js/node/context.js
CHANGED
|
@@ -32,21 +32,29 @@ const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
|
32
32
|
|
|
33
33
|
exports.useResolvedConfigContext = useResolvedConfigContext;
|
|
34
34
|
|
|
35
|
-
const initAppContext = (appDirectory, plugins, configFile) =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
36
|
+
const {
|
|
37
|
+
srcDir = 'src',
|
|
38
|
+
distDir = '',
|
|
39
|
+
sharedDir = 'shared',
|
|
40
|
+
internalDir = '.modern-js'
|
|
41
|
+
} = options || {};
|
|
42
|
+
return {
|
|
43
|
+
appDirectory,
|
|
44
|
+
configFile,
|
|
45
|
+
ip: _address.default.ip(),
|
|
46
|
+
port: 0,
|
|
47
|
+
packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
|
|
48
|
+
srcDirectory: _path.default.resolve(appDirectory, srcDir),
|
|
49
|
+
distDirectory: distDir,
|
|
50
|
+
sharedDirectory: _path.default.resolve(appDirectory, sharedDir),
|
|
51
|
+
nodeModulesDirectory: _path.default.resolve(appDirectory, './node_modules'),
|
|
52
|
+
internalDirectory: _path.default.resolve(appDirectory, `./node_modules/${internalDir}`),
|
|
53
|
+
plugins,
|
|
54
|
+
htmlTemplates: {},
|
|
55
|
+
serverRoutes: [],
|
|
56
|
+
entrypoints: []
|
|
57
|
+
};
|
|
58
|
+
};
|
|
51
59
|
|
|
52
60
|
exports.initAppContext = initAppContext;
|
package/dist/js/node/index.js
CHANGED
|
@@ -195,7 +195,7 @@ const createCli = () => {
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
198
|
-
const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath);
|
|
198
|
+
const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
199
199
|
manager.run(() => {
|
|
200
200
|
_context.ConfigContext.set(loaded.config);
|
|
201
201
|
|
package/dist/types/context.d.ts
CHANGED
|
@@ -11,4 +11,9 @@ export declare const useResolvedConfigContext: () => NormalizedConfig;
|
|
|
11
11
|
export declare const initAppContext: (appDirectory: string, plugins: Array<{
|
|
12
12
|
cli: any;
|
|
13
13
|
server: any;
|
|
14
|
-
}>, configFile: string | false
|
|
14
|
+
}>, configFile: string | false, options?: {
|
|
15
|
+
srcDir?: string | undefined;
|
|
16
|
+
distDir?: string | undefined;
|
|
17
|
+
sharedDir?: string | undefined;
|
|
18
|
+
internalDir?: string | undefined;
|
|
19
|
+
} | undefined) => IAppContext;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -100,6 +100,12 @@ export interface CoreOptions {
|
|
|
100
100
|
server: any;
|
|
101
101
|
serverPath: any;
|
|
102
102
|
}[];
|
|
103
|
+
options?: {
|
|
104
|
+
srcDir?: string;
|
|
105
|
+
distDir?: string;
|
|
106
|
+
sharedDir?: string;
|
|
107
|
+
internalDir?: string;
|
|
108
|
+
};
|
|
103
109
|
}
|
|
104
110
|
export declare const cli: {
|
|
105
111
|
init: (argv?: string[], options?: CoreOptions | undefined) => Promise<{
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.3.
|
|
14
|
+
"version": "1.3.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/code-frame": "^7.14.5",
|
|
44
44
|
"@babel/runtime": "^7",
|
|
45
|
-
"@modern-js/load-config": "^1.2.
|
|
46
|
-
"@modern-js/plugin": "^1.2.
|
|
47
|
-
"@modern-js/utils": "^1.2.
|
|
45
|
+
"@modern-js/load-config": "^1.2.1",
|
|
46
|
+
"@modern-js/plugin": "^1.2.1",
|
|
47
|
+
"@modern-js/utils": "^1.2.2",
|
|
48
48
|
"address": "^1.1.2",
|
|
49
49
|
"ajv": "^8.6.2",
|
|
50
50
|
"ajv-keywords": "^5.0.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"btsm": "2.2.2",
|
|
64
64
|
"@types/babel__code-frame": "^7.0.3",
|
|
65
|
-
"@modern-js/types": "^1.2.
|
|
65
|
+
"@modern-js/types": "^1.2.1",
|
|
66
66
|
"@types/jest": "^26",
|
|
67
67
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
68
68
|
"@types/lodash.mergewith": "^4.6.6",
|
package/tests/context.test.ts
CHANGED
|
@@ -25,4 +25,39 @@ describe('context', () => {
|
|
|
25
25
|
entrypoints: [],
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
|
|
29
|
+
it('custom AppContext', () => {
|
|
30
|
+
const appDirectory = path.resolve(
|
|
31
|
+
__dirname,
|
|
32
|
+
'./fixtures/load-plugin/user-plugins',
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const customOptions = {
|
|
36
|
+
srcDir: 'source',
|
|
37
|
+
distDir: 'dist',
|
|
38
|
+
sharedDir: 'myShared',
|
|
39
|
+
internalDir: 'myInternal',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const appContext = initAppContext(appDirectory, [], false, customOptions);
|
|
43
|
+
expect(appContext).toEqual({
|
|
44
|
+
appDirectory,
|
|
45
|
+
configFile: false,
|
|
46
|
+
ip: expect.any(String),
|
|
47
|
+
port: 0,
|
|
48
|
+
packageName: 'user-plugins',
|
|
49
|
+
srcDirectory: path.resolve(appDirectory, './source'),
|
|
50
|
+
distDirectory: 'dist',
|
|
51
|
+
sharedDirectory: path.resolve(appDirectory, './myShared'),
|
|
52
|
+
nodeModulesDirectory: expect.any(String),
|
|
53
|
+
internalDirectory: path.resolve(
|
|
54
|
+
appDirectory,
|
|
55
|
+
'./node_modules/myInternal',
|
|
56
|
+
),
|
|
57
|
+
plugins: [],
|
|
58
|
+
htmlTemplates: {},
|
|
59
|
+
serverRoutes: [],
|
|
60
|
+
entrypoints: [],
|
|
61
|
+
});
|
|
62
|
+
});
|
|
28
63
|
});
|
package/src/cli.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// 这个文件跟 bin/modern-js.js 基本一样
|
|
2
|
-
// 在开发阶段,因为 package.json 的 exports['./bin']['jsnext:source'] 配置
|
|
3
|
-
// 了这个文件,所以需要保留, 后续如果找到更好的方式之后会移除这个文件
|
|
4
|
-
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { cli } from '.';
|
|
7
|
-
|
|
8
|
-
const { version } = require('../package.json');
|
|
9
|
-
|
|
10
|
-
// XXX: 通过这个方式去掉了 package.json 里面对于 @modern-js/module-tools 的 devDependencies 依赖
|
|
11
|
-
// 然后可以正常的执行 modern build
|
|
12
|
-
const kModuleToolsCliPath = path.resolve(
|
|
13
|
-
__dirname,
|
|
14
|
-
'../../../solutions/module-tools/src/index.ts',
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
process.env.MODERN_JS_VERSION = version;
|
|
18
|
-
if (!process.env.NODE_ENV) {
|
|
19
|
-
process.env.NODE_ENV =
|
|
20
|
-
// eslint-disable-next-line no-nested-ternary
|
|
21
|
-
['build', 'start', 'deploy'].includes(process.argv[2])
|
|
22
|
-
? 'production'
|
|
23
|
-
: process.argv[2] === 'test'
|
|
24
|
-
? 'test'
|
|
25
|
-
: 'development';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
cli.run(process.argv.slice(2), {
|
|
29
|
-
plugins: {
|
|
30
|
-
'@modern-js/module-tools': {
|
|
31
|
-
cli: kModuleToolsCliPath,
|
|
32
|
-
// 是否需要强制加载这个组件,跳过 loadPlugins 里面 filter 的检测逻辑
|
|
33
|
-
forced: true,
|
|
34
|
-
} as any,
|
|
35
|
-
},
|
|
36
|
-
});
|
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,322 +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
|
-
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
|
-
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
|
-
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
|
-
interface DevConfig {
|
|
115
|
-
assetPrefix?: string | boolean;
|
|
116
|
-
https?: boolean;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
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
|
-
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
|
-
type RuntimeConfig = Record<string, any>;
|
|
143
|
-
|
|
144
|
-
interface RuntimeByEntriesConfig {
|
|
145
|
-
[name: string]: RuntimeConfig;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
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
|
-
type ConfigParam =
|
|
161
|
-
| UserConfig
|
|
162
|
-
| Promise<UserConfig>
|
|
163
|
-
| ((env: any) => UserConfig | Promise<UserConfig>);
|
|
164
|
-
|
|
165
|
-
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
|
-
packageJsonConfig?: string,
|
|
179
|
-
): Promise<LoadedConfig> => {
|
|
180
|
-
const loaded = await loadConfig<ConfigParam>(
|
|
181
|
-
appDirectory,
|
|
182
|
-
filePath,
|
|
183
|
-
packageJsonConfig,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
const config = !loaded
|
|
187
|
-
? {}
|
|
188
|
-
: await (typeof loaded.config === 'function'
|
|
189
|
-
? loaded.config(0)
|
|
190
|
-
: loaded.config);
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
config: mergeWith({}, config || {}, loaded?.pkgConfig || {}),
|
|
194
|
-
jsConfig: (config || {}) as any,
|
|
195
|
-
pkgConfig: (loaded?.pkgConfig || {}) as UserConfig,
|
|
196
|
-
filePath: loaded?.path,
|
|
197
|
-
dependencies: loaded?.dependencies || [],
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const showAdditionalPropertiesError = (error: ErrorObject) => {
|
|
202
|
-
if (
|
|
203
|
-
error.keyword === 'additionalProperties' &&
|
|
204
|
-
error.instancePath &&
|
|
205
|
-
error.params.additionalProperty
|
|
206
|
-
) {
|
|
207
|
-
const target = `${error.instancePath.substr(1)}.${
|
|
208
|
-
error.params.additionalProperty
|
|
209
|
-
}`;
|
|
210
|
-
|
|
211
|
-
const name = Object.keys(PLUGIN_SCHEMAS).find(key =>
|
|
212
|
-
(PLUGIN_SCHEMAS as Record<string, any>)[key].some(
|
|
213
|
-
(schemaItem: any) => schemaItem.target === target,
|
|
214
|
-
),
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
if (name) {
|
|
218
|
-
logger.warn(
|
|
219
|
-
`The configuration of ${chalk.bold(
|
|
220
|
-
target,
|
|
221
|
-
)} is provided by plugin ${chalk.bold(name)}. Please use ${chalk.bold(
|
|
222
|
-
'yarn new',
|
|
223
|
-
)} to enable the corresponding capability.\n`,
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
/* eslint-disable max-statements, max-params */
|
|
230
|
-
export const resolveConfig = async (
|
|
231
|
-
loaded: LoadedConfig,
|
|
232
|
-
configs: UserConfig[],
|
|
233
|
-
schemas: PluginValidateSchema[],
|
|
234
|
-
restartWithExistingPort: number,
|
|
235
|
-
argv: string[],
|
|
236
|
-
): Promise<NormalizedConfig> => {
|
|
237
|
-
const { config: userConfig, jsConfig, pkgConfig } = loaded;
|
|
238
|
-
|
|
239
|
-
const ajv = new Ajv({ $data: true, strict: false });
|
|
240
|
-
|
|
241
|
-
ajvKeywords(ajv);
|
|
242
|
-
|
|
243
|
-
const validateSchema = patchSchema(schemas);
|
|
244
|
-
|
|
245
|
-
const validate = ajv.compile(validateSchema);
|
|
246
|
-
|
|
247
|
-
repeatKeyWarning(validateSchema, jsConfig, pkgConfig);
|
|
248
|
-
|
|
249
|
-
// validate user config.
|
|
250
|
-
const valid = validate(userConfig);
|
|
251
|
-
|
|
252
|
-
if (!valid && validate.errors?.length) {
|
|
253
|
-
showAdditionalPropertiesError(validate?.errors[0]);
|
|
254
|
-
const errors = betterAjvErrors(
|
|
255
|
-
validateSchema,
|
|
256
|
-
userConfig,
|
|
257
|
-
validate.errors?.map(e => ({
|
|
258
|
-
...e,
|
|
259
|
-
dataPath: e.instancePath,
|
|
260
|
-
})),
|
|
261
|
-
{
|
|
262
|
-
format: 'js',
|
|
263
|
-
indent: 2,
|
|
264
|
-
},
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
logger.log(
|
|
268
|
-
codeFrameColumns(
|
|
269
|
-
JSON.stringify(userConfig, null, 2),
|
|
270
|
-
{
|
|
271
|
-
start: errors?.[0].start as any,
|
|
272
|
-
end: errors?.[0].end as any,
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
highlightCode: true,
|
|
276
|
-
message: errors?.[0].error,
|
|
277
|
-
},
|
|
278
|
-
),
|
|
279
|
-
);
|
|
280
|
-
throw new Error(`Validate configuration error`);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// validate config from plugins.
|
|
284
|
-
for (const config of configs) {
|
|
285
|
-
if (!validate(config)) {
|
|
286
|
-
logger.error(validate.errors);
|
|
287
|
-
throw new Error(`Validate configuration error.`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
const resolved = mergeConfig([defaults as any, ...configs, userConfig]);
|
|
291
|
-
|
|
292
|
-
resolved._raw = loaded.config;
|
|
293
|
-
|
|
294
|
-
if (isDev() && argv[0] === 'dev') {
|
|
295
|
-
if (restartWithExistingPort > 0) {
|
|
296
|
-
// dev server is restarted, should use existing port number
|
|
297
|
-
resolved.server.port = restartWithExistingPort;
|
|
298
|
-
} else {
|
|
299
|
-
// get port for new dev server
|
|
300
|
-
resolved.server.port = await getPort(resolved.server.port!);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
debug('resolved %o', resolved);
|
|
305
|
-
|
|
306
|
-
return resolved;
|
|
307
|
-
};
|
|
308
|
-
/* eslint-enable max-statements, max-params */
|
|
309
|
-
|
|
310
|
-
export type {
|
|
311
|
-
SourceConfig,
|
|
312
|
-
OutputConfig,
|
|
313
|
-
ServerConfig,
|
|
314
|
-
DevConfig,
|
|
315
|
-
DeployConfig,
|
|
316
|
-
ToolsConfig,
|
|
317
|
-
RuntimeConfig,
|
|
318
|
-
RuntimeByEntriesConfig,
|
|
319
|
-
UserConfig,
|
|
320
|
-
ConfigParam,
|
|
321
|
-
LoadedConfig,
|
|
322
|
-
};
|