@modern-js/core 2.0.0-beta.1 → 2.0.0-beta.3
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 +156 -0
- package/dist/bin.js +1 -4
- 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 +91 -0
- package/dist/config/index.d.ts +2 -17
- package/dist/config/index.js +2 -136
- package/dist/context.d.ts +5 -9
- package/dist/index.d.ts +8 -13
- package/dist/index.js +22 -59
- package/dist/loadPlugins.d.ts +2 -12
- package/dist/loadPlugins.js +12 -5
- package/dist/manager.d.ts +80 -64
- package/dist/manager.js +11 -5
- package/dist/runBin.d.ts +5 -0
- package/dist/runBin.js +50 -0
- package/dist/schema/patchSchema.d.ts +19 -0
- package/dist/{config/schema/index.js → schema/patchSchema.js} +8 -45
- 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 +41 -0
- package/dist/{config/types → types/config}/index.js +0 -0
- package/dist/types/config/testing.d.ts +15 -0
- package/dist/{config/types/electron.js → types/config/testing.js} +0 -0
- package/dist/types/context.d.ts +26 -0
- package/dist/{config/types/less.js → types/context.js} +0 -0
- package/dist/types/hooks.d.ts +26 -0
- package/dist/{config/types/postcss.js → types/hooks.js} +0 -0
- package/dist/types/index.d.ts +10 -1
- package/dist/types/index.js +5 -1
- package/dist/types/plugin.d.ts +26 -0
- package/dist/{config/types/sass.js → types/plugin.js} +0 -0
- package/dist/types/pluginAPI.d.ts +18 -0
- package/dist/{config/types/ssg.js → types/pluginAPI.js} +0 -0
- package/dist/utils/mergeConfig.d.ts +2 -0
- package/dist/{config → utils}/mergeConfig.js +1 -8
- package/dist/utils/repeatKeyWarning.d.ts +2 -2
- package/dist/utils/repeatKeyWarning.js +2 -2
- package/package.json +24 -10
- package/compiled/v8-compile-cache/index.d.ts +0 -1
- package/compiled/v8-compile-cache/index.js +0 -1
- package/compiled/v8-compile-cache/license +0 -21
- package/compiled/v8-compile-cache/package.json +0 -1
- package/dist/config/defaults.d.ts +0 -29
- package/dist/config/defaults.js +0 -110
- package/dist/config/mergeConfig.d.ts +0 -32
- package/dist/config/schema/deploy.d.ts +0 -16
- package/dist/config/schema/deploy.js +0 -16
- package/dist/config/schema/index.d.ts +0 -499
- package/dist/config/schema/output.d.ts +0 -146
- package/dist/config/schema/output.js +0 -68
- package/dist/config/schema/server.d.ts +0 -194
- package/dist/config/schema/server.js +0 -111
- package/dist/config/schema/source.d.ts +0 -64
- package/dist/config/schema/source.js +0 -38
- package/dist/config/schema/tools.d.ts +0 -51
- package/dist/config/schema/tools.js +0 -24
- package/dist/config/types/electron.d.ts +0 -13
- package/dist/config/types/index.d.ts +0 -260
- package/dist/config/types/less.d.ts +0 -12
- package/dist/config/types/postcss.d.ts +0 -28
- package/dist/config/types/sass.d.ts +0 -10
- package/dist/config/types/ssg.d.ts +0 -15
- package/dist/config/types/test.d.ts +0 -14
- package/dist/config/types/test.js +0 -2
- package/dist/config/types/ts-loader.d.ts +0 -23
- package/dist/config/types/ts-loader.js +0 -2
- package/dist/initWatcher.d.ts +0 -3
- package/dist/initWatcher.js +0 -66
- package/dist/pluginAPI.d.ts +0 -13
- package/dist/pluginAPI.js +0 -16
- package/dist/types/cli.d.ts +0 -59
- package/dist/types/cli.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,161 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- c9e800d39a: feat: support React18 streaming SSR
|
|
12
|
+
feat: 支持 React18 流式 SSR
|
|
13
|
+
- 92f0eade39: feat:
|
|
14
|
+
|
|
15
|
+
1. core: 增加 test 函数
|
|
16
|
+
2. module plugins: 增加 `babel`, `mainField`, `target` 插件
|
|
17
|
+
3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
|
|
18
|
+
4. 增加 designSystem 配置
|
|
19
|
+
|
|
20
|
+
feat:
|
|
21
|
+
|
|
22
|
+
1. core: add test method
|
|
23
|
+
2. module plugins: add `babel`, `mainField`, `target` plugin
|
|
24
|
+
3. storybook: change some logic and add tspath webpack plugin
|
|
25
|
+
4. add `designSystem` config
|
|
26
|
+
|
|
27
|
+
- edd1cfb1af: feat: modernjs Access builder compiler
|
|
28
|
+
feat: modernjs 接入 builder 构建
|
|
29
|
+
- d5a31df781: refactor: remove unbundle configs and types
|
|
30
|
+
|
|
31
|
+
refactor: 移除 unbundle 相关的配置项和类型定义
|
|
32
|
+
|
|
33
|
+
- e4558a0: feat:
|
|
34
|
+
|
|
35
|
+
1. add `runBin` function
|
|
36
|
+
2. config internal plugins constants in the app/module/doc tools
|
|
37
|
+
3. add app/module/doc tools internal plugins
|
|
38
|
+
|
|
39
|
+
feat:
|
|
40
|
+
|
|
41
|
+
1. 添加 `runBin` 函数
|
|
42
|
+
2. 在 app/module/doc tools 里配置内部插件
|
|
43
|
+
3. 增加 app/module/doc tools 使用的插件常量
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 85edee888c: feat(app-tools): support tools.htmlPlugin config
|
|
48
|
+
|
|
49
|
+
feat(app-tools): 支持 tools.htmlPlugin 配置项
|
|
50
|
+
|
|
51
|
+
- b8bbe036c7: feat: change type logic
|
|
52
|
+
feat: 修改类型相关的逻辑
|
|
53
|
+
- 8b8e1bb571: feat: support nested routes
|
|
54
|
+
feat: 支持嵌套路由
|
|
55
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
56
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
57
|
+
- b7a96c3: fix(app-tools): loose CLI init options after restart
|
|
58
|
+
|
|
59
|
+
fix(app-tools): 修复重启 CLI 后丢失 init options 的问题
|
|
60
|
+
|
|
61
|
+
- cce8ece: fix: handle some `TODO` & `FIXME`, change some tests
|
|
62
|
+
fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
|
|
63
|
+
- ea7cf06: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
|
|
64
|
+
|
|
65
|
+
chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
|
|
66
|
+
|
|
67
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
68
|
+
|
|
69
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
70
|
+
|
|
71
|
+
- Updated dependencies [6aca875]
|
|
72
|
+
- Updated dependencies [2e60319]
|
|
73
|
+
- Updated dependencies [a2509bfbdb]
|
|
74
|
+
- Updated dependencies [92f0eade39]
|
|
75
|
+
- Updated dependencies [edd1cfb1af]
|
|
76
|
+
- Updated dependencies [cc971eabfc]
|
|
77
|
+
- Updated dependencies [5b9049f2e9]
|
|
78
|
+
- Updated dependencies [92004d1906]
|
|
79
|
+
- Updated dependencies [b8bbe036c7]
|
|
80
|
+
- Updated dependencies [d5a31df781]
|
|
81
|
+
- Updated dependencies [dda38c9c3e]
|
|
82
|
+
- Updated dependencies [3bbea92b2a]
|
|
83
|
+
- Updated dependencies [b710adb]
|
|
84
|
+
- Updated dependencies [f179749375]
|
|
85
|
+
- Updated dependencies [ea7cf06]
|
|
86
|
+
- Updated dependencies [bbe4c4a]
|
|
87
|
+
- Updated dependencies [e4558a0]
|
|
88
|
+
- Updated dependencies [abf3421a75]
|
|
89
|
+
- Updated dependencies [543be9558e]
|
|
90
|
+
- Updated dependencies [14b712da84]
|
|
91
|
+
- @modern-js/utils@2.0.0-beta.3
|
|
92
|
+
- @modern-js/node-bundle-require@2.0.0-beta.3
|
|
93
|
+
- @modern-js/plugin@2.0.0-beta.3
|
|
94
|
+
|
|
95
|
+
## 2.0.0-beta.2
|
|
96
|
+
|
|
97
|
+
### Major Changes
|
|
98
|
+
|
|
99
|
+
- dda38c9c3e: chore: v2
|
|
100
|
+
|
|
101
|
+
### Minor Changes
|
|
102
|
+
|
|
103
|
+
- c9e800d39a: feat: support React18 streaming SSR
|
|
104
|
+
feat: 支持 React18 流式 SSR
|
|
105
|
+
- 92f0ead: feat:
|
|
106
|
+
|
|
107
|
+
1. core: 增加 test 函数
|
|
108
|
+
2. module plugins: 增加 `babel`, `mainField`, `target` 插件
|
|
109
|
+
3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
|
|
110
|
+
4. 增加 designSystem 配置
|
|
111
|
+
|
|
112
|
+
feat:
|
|
113
|
+
|
|
114
|
+
1. core: add test method
|
|
115
|
+
2. module plugins: add `babel`, `mainField`, `target` plugin
|
|
116
|
+
3. storybook: change some logic and add tspath webpack plugin
|
|
117
|
+
4. add `designSystem` config
|
|
118
|
+
|
|
119
|
+
- edd1cfb1af: feat: modernjs Access builder compiler
|
|
120
|
+
feat: modernjs 接入 builder 构建
|
|
121
|
+
- d5a31df781: refactor: remove unbundle configs and types
|
|
122
|
+
|
|
123
|
+
refactor: 移除 unbundle 相关的配置项和类型定义
|
|
124
|
+
|
|
125
|
+
### Patch Changes
|
|
126
|
+
|
|
127
|
+
- 85edee888c: feat(app-tools): support tools.htmlPlugin config
|
|
128
|
+
|
|
129
|
+
feat(app-tools): 支持 tools.htmlPlugin 配置项
|
|
130
|
+
|
|
131
|
+
- b8bbe036c7: feat: change type logic
|
|
132
|
+
feat: 修改类型相关的逻辑
|
|
133
|
+
- 8b8e1bb571: feat: support nested routes
|
|
134
|
+
feat: 支持嵌套路由
|
|
135
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
136
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
137
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
138
|
+
|
|
139
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
140
|
+
|
|
141
|
+
- Updated dependencies [a2509bfbdb]
|
|
142
|
+
- Updated dependencies [92f0ead]
|
|
143
|
+
- Updated dependencies [edd1cfb1af]
|
|
144
|
+
- Updated dependencies [cc971eabfc]
|
|
145
|
+
- Updated dependencies [5b9049f2e9]
|
|
146
|
+
- Updated dependencies [92004d1]
|
|
147
|
+
- Updated dependencies [b8bbe036c7]
|
|
148
|
+
- Updated dependencies [d5a31df781]
|
|
149
|
+
- Updated dependencies [dda38c9c3e]
|
|
150
|
+
- Updated dependencies [3bbea92b2a]
|
|
151
|
+
- Updated dependencies [f179749]
|
|
152
|
+
- Updated dependencies [abf3421a75]
|
|
153
|
+
- Updated dependencies [543be9558e]
|
|
154
|
+
- Updated dependencies [14b712da84]
|
|
155
|
+
- @modern-js/node-bundle-require@2.0.0-beta.2
|
|
156
|
+
- @modern-js/utils@2.0.0-beta.2
|
|
157
|
+
- @modern-js/plugin@2.0.0-beta.2
|
|
158
|
+
|
|
3
159
|
## 2.0.0-beta.1
|
|
4
160
|
|
|
5
161
|
### Major Changes
|
package/dist/bin.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
/* eslint-disable-next-line eslint-comments/disable-enable-pair */
|
|
4
|
-
/* eslint-disable import/first */
|
|
5
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
require('../compiled/v8-compile-cache');
|
|
7
4
|
const utils_1 = require("@modern-js/utils");
|
|
8
5
|
const _1 = require(".");
|
|
9
6
|
const command = process.argv[2];
|
|
@@ -38,4 +35,4 @@ const customConfigFile = cliParams.config || cliParams.c;
|
|
|
38
35
|
if (SUPPORT_CONFIG_PARAM_COMMANDS.includes(command) && customConfigFile) {
|
|
39
36
|
runOptions.configFile = customConfigFile;
|
|
40
37
|
}
|
|
41
|
-
_1.cli.run(
|
|
38
|
+
_1.cli.run(runOptions);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LoadedConfig, UserConfig, ConfigParams } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Assign the pkg config into the user config.
|
|
4
|
+
*/
|
|
5
|
+
export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParams) => UserConfig;
|
|
6
|
+
export declare function createLoadedConfig(appDirectory: string, filePath?: string, packageJsonConfig?: string): Promise<LoadedConfig<{}>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLoadedConfig = exports.assignPkgConfig = void 0;
|
|
4
|
+
const lodash_1 = require("@modern-js/utils/lodash");
|
|
5
|
+
const utils_1 = require("@modern-js/utils");
|
|
6
|
+
const load_configs_1 = require("../load-configs");
|
|
7
|
+
/**
|
|
8
|
+
* Assign the pkg config into the user config.
|
|
9
|
+
*/
|
|
10
|
+
const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
|
|
11
|
+
// mergeWith can not merge object with symbol, but plugins object contains symbol,
|
|
12
|
+
// so we need to handle it manually.
|
|
13
|
+
if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
|
|
14
|
+
return { ...srcValue };
|
|
15
|
+
}
|
|
16
|
+
// return undefined to use the default behavior of mergeWith
|
|
17
|
+
return undefined;
|
|
18
|
+
});
|
|
19
|
+
exports.assignPkgConfig = assignPkgConfig;
|
|
20
|
+
async function createLoadedConfig(appDirectory, filePath, packageJsonConfig) {
|
|
21
|
+
const loaded = await (0, load_configs_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
|
|
22
|
+
const config = !loaded
|
|
23
|
+
? {}
|
|
24
|
+
: await (typeof loaded.config === 'function'
|
|
25
|
+
? loaded.config(0)
|
|
26
|
+
: loaded.config);
|
|
27
|
+
return {
|
|
28
|
+
config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
|
|
29
|
+
filePath: loaded.path,
|
|
30
|
+
dependencies: loaded.dependencies || [],
|
|
31
|
+
pkgConfig: loaded.pkgConfig || {},
|
|
32
|
+
jsConfig: config || {},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.createLoadedConfig = createLoadedConfig;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ErrorObject } from '@modern-js/utils/ajv';
|
|
2
|
+
import type { UserConfig, NormalizedConfig, LoadedConfig, PluginValidateSchema } from '../types';
|
|
3
|
+
export declare const createResolveConfig: (loaded: LoadedConfig<{}>, configs: UserConfig[], schemas: PluginValidateSchema[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createResolveConfig = void 0;
|
|
27
|
+
const utils_1 = require("@modern-js/utils");
|
|
28
|
+
const constants_1 = require("@modern-js/utils/constants");
|
|
29
|
+
const patchSchema_1 = require("../schema/patchSchema");
|
|
30
|
+
const repeatKeyWarning_1 = require("../utils/repeatKeyWarning");
|
|
31
|
+
const mergeConfig_1 = require("../utils/mergeConfig");
|
|
32
|
+
const debug = (0, utils_1.createDebugger)('resolve-config');
|
|
33
|
+
const showAdditionalPropertiesError = async (error) => {
|
|
34
|
+
if (error.keyword === 'additionalProperties' &&
|
|
35
|
+
error.params.additionalProperty) {
|
|
36
|
+
const target = [
|
|
37
|
+
error.instancePath.slice(1),
|
|
38
|
+
error.params.additionalProperty,
|
|
39
|
+
]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join('.');
|
|
42
|
+
const name = Object.keys(constants_1.PLUGIN_SCHEMAS).find(key => constants_1.PLUGIN_SCHEMAS[key].some((schemaItem) => schemaItem.target === target));
|
|
43
|
+
if (name) {
|
|
44
|
+
const packageManager = await (0, utils_1.getPackageManager)();
|
|
45
|
+
utils_1.logger.warn(`The configuration of ${utils_1.chalk.bold(target)} is provided by plugin ${utils_1.chalk.bold(name)}. Please use ${utils_1.chalk.bold(`${packageManager} run new`)} to enable the corresponding capability.\n`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const createResolveConfig = async (
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
51
|
+
loaded, configs, schemas, onSchemaError = showAdditionalPropertiesError) => {
|
|
52
|
+
var _a;
|
|
53
|
+
const { default: Ajv } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv')));
|
|
54
|
+
const { default: ajvKeywords } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv-keywords')));
|
|
55
|
+
const { default: betterAjvErrors } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/better-ajv-errors')));
|
|
56
|
+
const { config: userConfig, jsConfig, pkgConfig } = loaded;
|
|
57
|
+
const ajv = new Ajv({ $data: true, strict: false });
|
|
58
|
+
ajvKeywords(ajv);
|
|
59
|
+
const validateSchema = (0, patchSchema_1.patchSchema)(schemas);
|
|
60
|
+
const validate = ajv.compile(validateSchema);
|
|
61
|
+
(0, repeatKeyWarning_1.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
|
|
62
|
+
// validate user config.
|
|
63
|
+
const valid = validate(userConfig);
|
|
64
|
+
const formatValidateError = (config) => {
|
|
65
|
+
var _a;
|
|
66
|
+
return betterAjvErrors(validateSchema, config, (_a = validate.errors) === null || _a === void 0 ? void 0 : _a.map(e => ({
|
|
67
|
+
...e,
|
|
68
|
+
dataPath: e.instancePath,
|
|
69
|
+
})), {
|
|
70
|
+
indent: 2,
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
if (!valid && ((_a = validate.errors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
74
|
+
await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
|
|
75
|
+
const errors = formatValidateError(userConfig);
|
|
76
|
+
utils_1.logger.log(errors);
|
|
77
|
+
throw new Error(`Validate configuration error`);
|
|
78
|
+
}
|
|
79
|
+
// validate config from plugins.
|
|
80
|
+
for (const config of configs) {
|
|
81
|
+
if (!validate(config)) {
|
|
82
|
+
const errors = formatValidateError(config);
|
|
83
|
+
utils_1.logger.error(errors);
|
|
84
|
+
throw new Error(`Validate configuration error.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const resolved = (0, mergeConfig_1.mergeConfig)([...configs, userConfig]);
|
|
88
|
+
debug('resolved %o', resolved);
|
|
89
|
+
return resolved;
|
|
90
|
+
};
|
|
91
|
+
exports.createResolveConfig = createResolveConfig;
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { NormalizedConfig } from './mergeConfig';
|
|
4
|
-
import { PluginValidateSchema } from './schema';
|
|
5
|
-
import type { UserConfig, ConfigParam, LoadedConfig } from './types';
|
|
6
|
-
export { getDefaultConfig };
|
|
7
|
-
export * from './mergeConfig';
|
|
8
|
-
export * from './types';
|
|
9
|
-
export * from './schema';
|
|
10
|
-
export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
|
|
11
|
-
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
12
|
-
/**
|
|
13
|
-
* Assign the pkg config into the user config.
|
|
14
|
-
*/
|
|
15
|
-
export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
|
|
16
|
-
export declare const loadUserConfig: (appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<LoadedConfig>;
|
|
17
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
|
|
1
|
+
export * from './createLoadedConfig';
|
|
2
|
+
export * from './createResolvedConfig';
|
package/dist/config/index.js
CHANGED
|
@@ -10,143 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const lodash_1 = require("@modern-js/utils/lodash");
|
|
32
|
-
const context_1 = require("../context");
|
|
33
|
-
const load_configs_1 = require("../load-configs");
|
|
34
|
-
const repeatKeyWarning_1 = require("../utils/repeatKeyWarning");
|
|
35
|
-
const defaults_1 = require("./defaults");
|
|
36
|
-
Object.defineProperty(exports, "getDefaultConfig", { enumerable: true, get: function () { return defaults_1.getDefaultConfig; } });
|
|
37
|
-
const mergeConfig_1 = require("./mergeConfig");
|
|
38
|
-
const schema_1 = require("./schema");
|
|
39
|
-
const debug = (0, utils_1.createDebugger)('resolve-config');
|
|
40
|
-
__exportStar(require("./mergeConfig"), exports);
|
|
41
|
-
__exportStar(require("./types"), exports);
|
|
42
|
-
__exportStar(require("./schema"), exports);
|
|
43
|
-
const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
44
|
-
const serverConfig = await (0, utils_1.getServerConfig)(appDirectory, serverConfigFile);
|
|
45
|
-
if (serverConfig) {
|
|
46
|
-
dependencies.push(serverConfig);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
exports.addServerConfigToDeps = addServerConfigToDeps;
|
|
50
|
-
const defineConfig = (config) => config;
|
|
51
|
-
exports.defineConfig = defineConfig;
|
|
52
|
-
/**
|
|
53
|
-
* Assign the pkg config into the user config.
|
|
54
|
-
*/
|
|
55
|
-
const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeWith)({}, userConfig, pkgConfig, (objValue, srcValue) => {
|
|
56
|
-
// mergeWith can not merge object with symbol, but plugins object contains symbol,
|
|
57
|
-
// so we need to handle it manually.
|
|
58
|
-
if (objValue === undefined && (0, utils_1.isPlainObject)(srcValue)) {
|
|
59
|
-
return { ...srcValue };
|
|
60
|
-
}
|
|
61
|
-
// return undefined to use the default behavior of mergeWith
|
|
62
|
-
return undefined;
|
|
63
|
-
});
|
|
64
|
-
exports.assignPkgConfig = assignPkgConfig;
|
|
65
|
-
const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
66
|
-
const loaded = await (0, load_configs_1.loadConfig)(appDirectory, filePath, packageJsonConfig);
|
|
67
|
-
const config = !loaded
|
|
68
|
-
? {}
|
|
69
|
-
: await (typeof loaded.config === 'function'
|
|
70
|
-
? loaded.config(0)
|
|
71
|
-
: loaded.config);
|
|
72
|
-
return {
|
|
73
|
-
config: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
|
|
74
|
-
jsConfig: config || {},
|
|
75
|
-
pkgConfig: ((loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
|
|
76
|
-
filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
|
|
77
|
-
dependencies: (loaded === null || loaded === void 0 ? void 0 : loaded.dependencies) || [],
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
exports.loadUserConfig = loadUserConfig;
|
|
81
|
-
const showAdditionalPropertiesError = async (error) => {
|
|
82
|
-
if (error.keyword === 'additionalProperties' &&
|
|
83
|
-
error.params.additionalProperty) {
|
|
84
|
-
const target = [
|
|
85
|
-
error.instancePath.slice(1),
|
|
86
|
-
error.params.additionalProperty,
|
|
87
|
-
]
|
|
88
|
-
.filter(Boolean)
|
|
89
|
-
.join('.');
|
|
90
|
-
const name = Object.keys(utils_1.PLUGIN_SCHEMAS).find(key => utils_1.PLUGIN_SCHEMAS[key].some((schemaItem) => schemaItem.target === target));
|
|
91
|
-
if (name) {
|
|
92
|
-
const packageManager = await (0, utils_1.getPackageManager)();
|
|
93
|
-
utils_1.logger.warn(`The configuration of ${utils_1.chalk.bold(target)} is provided by plugin ${utils_1.chalk.bold(name)}. Please use ${utils_1.chalk.bold(`${packageManager} run new`)} to enable the corresponding capability.\n`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
|
|
98
|
-
var _a;
|
|
99
|
-
const { default: Ajv } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv')));
|
|
100
|
-
const { default: ajvKeywords } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/ajv-keywords')));
|
|
101
|
-
const { default: betterAjvErrors } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils/better-ajv-errors')));
|
|
102
|
-
const { config: userConfig, jsConfig, pkgConfig } = loaded;
|
|
103
|
-
const ajv = new Ajv({ $data: true, strict: false });
|
|
104
|
-
ajvKeywords(ajv);
|
|
105
|
-
const validateSchema = (0, schema_1.patchSchema)(schemas);
|
|
106
|
-
const validate = ajv.compile(validateSchema);
|
|
107
|
-
(0, repeatKeyWarning_1.repeatKeyWarning)(validateSchema, jsConfig, pkgConfig);
|
|
108
|
-
// validate user config.
|
|
109
|
-
const valid = validate(userConfig);
|
|
110
|
-
const formatValidateError = (config) => {
|
|
111
|
-
var _a;
|
|
112
|
-
return betterAjvErrors(validateSchema, config, (_a = validate.errors) === null || _a === void 0 ? void 0 : _a.map(e => ({
|
|
113
|
-
...e,
|
|
114
|
-
dataPath: e.instancePath,
|
|
115
|
-
})), {
|
|
116
|
-
indent: 2,
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
if (!valid && ((_a = validate.errors) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
120
|
-
await onSchemaError(validate === null || validate === void 0 ? void 0 : validate.errors[0]);
|
|
121
|
-
const errors = formatValidateError(userConfig);
|
|
122
|
-
utils_1.logger.log(errors);
|
|
123
|
-
throw new Error(`Validate configuration error`);
|
|
124
|
-
}
|
|
125
|
-
// validate config from plugins.
|
|
126
|
-
for (const config of configs) {
|
|
127
|
-
if (!validate(config)) {
|
|
128
|
-
const errors = formatValidateError(config);
|
|
129
|
-
utils_1.logger.error(errors);
|
|
130
|
-
throw new Error(`Validate configuration error.`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const resolved = (0, mergeConfig_1.mergeConfig)([
|
|
134
|
-
(0, defaults_1.getDefaultConfig)(context_1.AppContext.use().value),
|
|
135
|
-
...configs,
|
|
136
|
-
userConfig,
|
|
137
|
-
]);
|
|
138
|
-
resolved._raw = loaded.config;
|
|
139
|
-
if ((0, utils_1.isDev)() && argv[0] === 'dev') {
|
|
140
|
-
if (restartWithExistingPort > 0) {
|
|
141
|
-
// dev server is restarted, should use existing port number
|
|
142
|
-
resolved.server.port = restartWithExistingPort;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
// get port for new dev server
|
|
146
|
-
resolved.server.port = await (0, utils_1.getPort)(resolved.server.port);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
debug('resolved %o', resolved);
|
|
150
|
-
return resolved;
|
|
151
|
-
};
|
|
152
|
-
exports.resolveConfig = resolveConfig;
|
|
17
|
+
__exportStar(require("./createLoadedConfig"), exports);
|
|
18
|
+
__exportStar(require("./createResolvedConfig"), exports);
|
package/dist/context.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { IAppContext, InternalPlugins } from '
|
|
2
|
-
import { UserConfig } from './config';
|
|
3
|
-
import { NormalizedConfig } from './config/mergeConfig';
|
|
4
|
-
import { CliPlugin } from './manager';
|
|
5
|
-
export type { IAppContext };
|
|
1
|
+
import type { CliPlugin, UserConfig, IAppContext, InternalPlugins, NormalizedConfig } from './types';
|
|
6
2
|
export declare const AppContext: import("@modern-js/plugin").Context<IAppContext>;
|
|
7
|
-
export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig
|
|
8
|
-
export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig
|
|
3
|
+
export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig<any, {}, {}, {}>>;
|
|
4
|
+
export declare const ResolvedConfigContext: import("@modern-js/plugin").Context<NormalizedConfig<any, {}, {}, {}>>;
|
|
9
5
|
/**
|
|
10
6
|
* Set app context.
|
|
11
7
|
* @param value new app context. It will override previous app context.
|
|
@@ -18,11 +14,11 @@ export declare const useAppContext: () => IAppContext;
|
|
|
18
14
|
/**
|
|
19
15
|
* Get original content of user config.
|
|
20
16
|
*/
|
|
21
|
-
export declare const useConfigContext: () => UserConfig
|
|
17
|
+
export declare const useConfigContext: <Extends extends Record<string, any>>() => UserConfig<Extends>;
|
|
22
18
|
/**
|
|
23
19
|
* Get normalized content of user config.
|
|
24
20
|
*/
|
|
25
|
-
export declare const useResolvedConfigContext: () => NormalizedConfig
|
|
21
|
+
export declare const useResolvedConfigContext: <Extends extends Record<string, any>>() => NormalizedConfig<Extends>;
|
|
26
22
|
export declare const initAppContext: ({ appDirectory, plugins, configFile, options, serverConfigFile, serverInternalPlugins, }: {
|
|
27
23
|
appDirectory: string;
|
|
28
24
|
plugins: CliPlugin[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { ErrorObject } from '@modern-js/utils/ajv';
|
|
2
2
|
import { InternalPlugins } from '@modern-js/types';
|
|
3
3
|
import { TransformPlugin } from './loadPlugins';
|
|
4
|
-
import {
|
|
5
|
-
export * from './
|
|
6
|
-
export type { Hooks, ImportSpecifier, ImportStatement, RuntimePlugin, } from './types';
|
|
4
|
+
import { initAppContext } from './context';
|
|
5
|
+
export * from './types';
|
|
7
6
|
export * from '@modern-js/plugin';
|
|
8
7
|
export { manager, mountHook, createPlugin, registerHook } from './manager';
|
|
9
|
-
export
|
|
10
|
-
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './pluginAPI';
|
|
11
|
-
export type { PluginAPI } from './pluginAPI';
|
|
12
|
-
export type { IAppContext };
|
|
8
|
+
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './context';
|
|
13
9
|
declare const initAppDir: (cwd?: string) => Promise<string>;
|
|
14
10
|
export interface CoreOptions {
|
|
15
11
|
cwd?: string;
|
|
@@ -50,17 +46,16 @@ export declare const mergeOptions: (options?: CoreOptions) => {
|
|
|
50
46
|
} | undefined;
|
|
51
47
|
};
|
|
52
48
|
export declare const cli: {
|
|
53
|
-
init: (
|
|
54
|
-
|
|
55
|
-
appContext: IAppContext;
|
|
56
|
-
resolved: import("./config").NormalizedConfig;
|
|
49
|
+
init: (options?: CoreOptions) => Promise<{
|
|
50
|
+
resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
|
|
51
|
+
appContext: import("./types").IAppContext;
|
|
57
52
|
}>;
|
|
58
|
-
run: (
|
|
59
|
-
restart: () => Promise<void>;
|
|
53
|
+
run: (options?: CoreOptions) => Promise<void>;
|
|
60
54
|
test: (argv: string[], options?: {
|
|
61
55
|
coreOptions?: CoreOptions;
|
|
62
56
|
disableWatcher?: boolean;
|
|
63
57
|
}) => Promise<void>;
|
|
58
|
+
getPrevInitOptions: () => CoreOptions | undefined;
|
|
64
59
|
};
|
|
65
60
|
export { initAppDir, initAppContext };
|
|
66
61
|
declare module '@modern-js/utils/compiled/commander' {
|