@modern-js/core 2.2.0 → 2.4.0
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 +39 -0
- package/README.md +14 -18
- package/dist/config/createLoadedConfig.d.ts +2 -2
- package/dist/config/createLoadedConfig.js +53 -8
- package/dist/{load-configs/index.d.ts → config/loadConfig.d.ts} +3 -2
- package/dist/{load-configs/index.js → config/loadConfig.js} +4 -6
- package/dist/types/config/index.d.ts +5 -1
- package/dist/types/hooks.d.ts +0 -1
- package/dist/utils/createFileWatcher.js +1 -1
- package/dist/utils/mergeConfig.js +8 -6
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 2.4.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8c2db5f: feat(core): improve support for exporting a function in config file
|
|
8
|
+
|
|
9
|
+
feat(core): 完善对配置文件中导出函数的支持
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [98a2733]
|
|
12
|
+
- Updated dependencies [8c2db5f]
|
|
13
|
+
- @modern-js/node-bundle-require@2.4.0
|
|
14
|
+
- @modern-js/utils@2.4.0
|
|
15
|
+
- @modern-js/plugin@2.4.0
|
|
16
|
+
|
|
17
|
+
## 2.3.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 65f1322: fix(core): merge array config correctly
|
|
22
|
+
|
|
23
|
+
fix(core): 修复合并配置中的数组时出现错误的问题
|
|
24
|
+
|
|
25
|
+
- fd5a3ed: fix: failed to exit new command
|
|
26
|
+
|
|
27
|
+
fix: 修复 new 命令执行完成后未退出进程的问题
|
|
28
|
+
|
|
29
|
+
- 7b2cdcb: feat(core): support read modern.config.local.ts
|
|
30
|
+
|
|
31
|
+
feat(core): 支持读取 modern.config.local.ts 文件
|
|
32
|
+
|
|
33
|
+
- 7736171: fix: remove disableRunBuild
|
|
34
|
+
fix: 移除 disableRunBuild
|
|
35
|
+
- Updated dependencies [fd5a3ed]
|
|
36
|
+
- Updated dependencies [6ca1c0b]
|
|
37
|
+
- Updated dependencies [89b6739]
|
|
38
|
+
- @modern-js/utils@2.3.0
|
|
39
|
+
- @modern-js/node-bundle-require@2.3.0
|
|
40
|
+
- @modern-js/plugin@2.3.0
|
|
41
|
+
|
|
3
42
|
## 2.2.0
|
|
4
43
|
|
|
5
44
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
1
|
<p align="center">
|
|
3
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
3
|
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
5
7
|
<p align="center">
|
|
6
|
-
|
|
7
|
-
<br/>
|
|
8
|
-
<a href="https://modernjs.dev" target="blank">
|
|
9
|
-
modernjs.dev
|
|
10
|
-
</a>
|
|
11
|
-
</p>
|
|
12
|
-
<p align="center">
|
|
13
|
-
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
14
9
|
</p>
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
11
|
+
## Getting Started
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
21
14
|
|
|
22
|
-
##
|
|
15
|
+
## Documentation
|
|
23
16
|
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [API References](https://modernjs.dev/docs/apis)
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
27
19
|
|
|
28
20
|
## Contributing
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LoadedConfig, UserConfig
|
|
1
|
+
import { LoadedConfig, UserConfig } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Assign the pkg config into the user config.
|
|
4
4
|
*/
|
|
5
|
-
export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?:
|
|
5
|
+
export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: UserConfig) => UserConfig;
|
|
6
6
|
export declare function createLoadedConfig(appDirectory: string, filePath?: string, packageJsonConfig?: string): Promise<LoadedConfig<{}>>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.createLoadedConfig = exports.assignPkgConfig = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
4
8
|
const lodash_1 = require("@modern-js/utils/lodash");
|
|
5
9
|
const utils_1 = require("@modern-js/utils");
|
|
6
|
-
const
|
|
10
|
+
const utils_2 = require("../utils");
|
|
11
|
+
const loadConfig_1 = require("./loadConfig");
|
|
7
12
|
/**
|
|
8
13
|
* Assign the pkg config into the user config.
|
|
9
14
|
*/
|
|
@@ -17,15 +22,55 @@ const assignPkgConfig = (userConfig = {}, pkgConfig = {}) => (0, lodash_1.mergeW
|
|
|
17
22
|
return undefined;
|
|
18
23
|
});
|
|
19
24
|
exports.assignPkgConfig = assignPkgConfig;
|
|
25
|
+
/**
|
|
26
|
+
* A modern config can export a function or an object
|
|
27
|
+
* If it's a function, it will be called and return a config object
|
|
28
|
+
*/
|
|
29
|
+
async function getConfigObject(config) {
|
|
30
|
+
if (typeof config === 'function') {
|
|
31
|
+
return (await config({ env: (0, utils_1.getNodeEnv)(), command: (0, utils_1.getCommand)() })) || {};
|
|
32
|
+
}
|
|
33
|
+
return config || {};
|
|
34
|
+
}
|
|
35
|
+
async function loadLocalConfig(appDirectory, configFile) {
|
|
36
|
+
let localConfigFile = false;
|
|
37
|
+
if (typeof configFile === 'string') {
|
|
38
|
+
for (const ext of utils_1.CONFIG_FILE_EXTENSIONS) {
|
|
39
|
+
if (configFile.endsWith(ext)) {
|
|
40
|
+
const replacedPath = configFile.replace(ext, `.local${ext}`);
|
|
41
|
+
if (utils_1.fs.existsSync(replacedPath)) {
|
|
42
|
+
localConfigFile = replacedPath;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
localConfigFile = (0, utils_1.findExists)(utils_1.CONFIG_FILE_EXTENSIONS.map(extension => path_1.default.resolve(appDirectory, `${loadConfig_1.LOCAL_CONFIG_FILE_NAME}${extension}`)));
|
|
49
|
+
}
|
|
50
|
+
if (localConfigFile) {
|
|
51
|
+
const loaded = await (0, loadConfig_1.loadConfig)(appDirectory, localConfigFile);
|
|
52
|
+
return getConfigObject(loaded.config);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
20
56
|
async function createLoadedConfig(appDirectory, filePath, packageJsonConfig) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
57
|
+
const configFile = (0, loadConfig_1.getConfigFilePath)(appDirectory, filePath);
|
|
58
|
+
const loaded = await (0, loadConfig_1.loadConfig)(appDirectory, configFile, packageJsonConfig);
|
|
59
|
+
const config = await getConfigObject(loaded.config);
|
|
60
|
+
let mergedConfig = config;
|
|
61
|
+
if (loaded.pkgConfig) {
|
|
62
|
+
mergedConfig = (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig);
|
|
63
|
+
}
|
|
64
|
+
// Only load local config when running dev command
|
|
65
|
+
if ((0, utils_1.isDevCommand)()) {
|
|
66
|
+
const localConfig = await loadLocalConfig(appDirectory, configFile);
|
|
67
|
+
// The priority of local config is higher than the user config and pkg config
|
|
68
|
+
if (localConfig) {
|
|
69
|
+
mergedConfig = (0, utils_2.mergeConfig)([mergedConfig, localConfig]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
27
72
|
return {
|
|
28
|
-
config:
|
|
73
|
+
config: mergedConfig,
|
|
29
74
|
filePath: loaded.path,
|
|
30
75
|
dependencies: loaded.dependencies || [],
|
|
31
76
|
pkgConfig: loaded.pkgConfig || {},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
export declare const CONFIG_FILE_NAME = "modern.config";
|
|
3
|
+
export declare const LOCAL_CONFIG_FILE_NAME = "modern.config.local";
|
|
3
4
|
export declare const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
4
5
|
/**
|
|
5
6
|
* Get user config from package.json.
|
|
@@ -23,10 +24,10 @@ export declare const getConfigFilePath: (appDirectory: string, filePath?: string
|
|
|
23
24
|
/**
|
|
24
25
|
* Parse and load user config file, support extensions like .ts, mjs, js, ejs.
|
|
25
26
|
* @param appDirectory - App root directory, from which start search user config file.
|
|
26
|
-
* @param
|
|
27
|
+
* @param configFile - Specific absolute config file path.
|
|
27
28
|
* @returns Object contain config file path, user config object and dependency files used by config file.
|
|
28
29
|
*/
|
|
29
|
-
export declare const loadConfig: <T>(appDirectory: string,
|
|
30
|
+
export declare const loadConfig: <T>(appDirectory: string, configFile: string | false, packageJsonConfig?: string) => Promise<{
|
|
30
31
|
path: string | false;
|
|
31
32
|
config?: T | undefined;
|
|
32
33
|
dependencies?: string[] | undefined;
|
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.loadConfig = exports.getConfigFilePath = exports.clearFilesOverTime = exports.getDependencies = exports.getPackageConfig = exports.PACKAGE_JSON_CONFIG_NAME = exports.CONFIG_FILE_NAME = void 0;
|
|
6
|
+
exports.loadConfig = exports.getConfigFilePath = exports.clearFilesOverTime = exports.getDependencies = exports.getPackageConfig = exports.PACKAGE_JSON_CONFIG_NAME = exports.LOCAL_CONFIG_FILE_NAME = exports.CONFIG_FILE_NAME = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_1 = require("@modern-js/utils");
|
|
9
9
|
const node_bundle_require_1 = require("@modern-js/node-bundle-require");
|
|
10
10
|
const debug = (0, utils_1.createDebugger)('load-config');
|
|
11
11
|
exports.CONFIG_FILE_NAME = 'modern.config';
|
|
12
|
+
exports.LOCAL_CONFIG_FILE_NAME = 'modern.config.local';
|
|
12
13
|
exports.PACKAGE_JSON_CONFIG_NAME = 'modernConfig';
|
|
13
14
|
/**
|
|
14
15
|
* Get user config from package.json.
|
|
@@ -97,11 +98,10 @@ exports.getConfigFilePath = getConfigFilePath;
|
|
|
97
98
|
/**
|
|
98
99
|
* Parse and load user config file, support extensions like .ts, mjs, js, ejs.
|
|
99
100
|
* @param appDirectory - App root directory, from which start search user config file.
|
|
100
|
-
* @param
|
|
101
|
+
* @param configFile - Specific absolute config file path.
|
|
101
102
|
* @returns Object contain config file path, user config object and dependency files used by config file.
|
|
102
103
|
*/
|
|
103
|
-
const loadConfig = async (appDirectory,
|
|
104
|
-
const configFile = (0, exports.getConfigFilePath)(appDirectory, filePath);
|
|
104
|
+
const loadConfig = async (appDirectory, configFile, packageJsonConfig) => {
|
|
105
105
|
const pkgConfig = (0, exports.getPackageConfig)(appDirectory, packageJsonConfig);
|
|
106
106
|
let config;
|
|
107
107
|
const dependencies = pkgConfig
|
|
@@ -111,8 +111,6 @@ const loadConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
|
111
111
|
delete require.cache[configFile];
|
|
112
112
|
const mod = await bundleRequireWithCatch(configFile, { appDirectory });
|
|
113
113
|
config = mod.default || mod;
|
|
114
|
-
// TODO: get deps.
|
|
115
|
-
// dependencies = dependencies.concat(getDependencies(configFile));
|
|
116
114
|
}
|
|
117
115
|
return {
|
|
118
116
|
path: configFile,
|
|
@@ -46,4 +46,8 @@ export type LoadedConfig<Extends extends {
|
|
|
46
46
|
pkgConfig: UserConfig<Extends>;
|
|
47
47
|
jsConfig: UserConfig<Extends>;
|
|
48
48
|
};
|
|
49
|
-
export type ConfigParams =
|
|
49
|
+
export type ConfigParams = {
|
|
50
|
+
env: string;
|
|
51
|
+
command: string;
|
|
52
|
+
};
|
|
53
|
+
export type UserConfigExport<Config = UserConfig> = Config | ((env: ConfigParams) => Config | Promise<Config>);
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ const hashMap = new Map();
|
|
|
36
36
|
const md5 = (data) => crypto_1.default.createHash('md5').update(data).digest('hex');
|
|
37
37
|
const createFileWatcher = async (appContext, hooksRunner) => {
|
|
38
38
|
// only add fs watcher on dev mode.
|
|
39
|
-
if ((0, utils_1.
|
|
39
|
+
if ((0, utils_1.isDevCommand)()) {
|
|
40
40
|
const { appDirectory } = appContext;
|
|
41
41
|
const extraFiles = await hooksRunner.watchFiles();
|
|
42
42
|
const watched = extraFiles.filter(Boolean);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeConfig = void 0;
|
|
4
|
+
const utils_1 = require("@modern-js/utils");
|
|
4
5
|
const lodash_1 = require("@modern-js/utils/lodash");
|
|
5
6
|
const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target, source, key) => {
|
|
6
7
|
// Do not use the following merge logic for source.designSystem and tools.tailwind(css)
|
|
@@ -10,15 +11,16 @@ const mergeConfig = (configs) => (0, lodash_1.mergeWith)({}, ...configs, (target
|
|
|
10
11
|
key === 'devServer') {
|
|
11
12
|
return (0, lodash_1.mergeWith)({}, target !== null && target !== void 0 ? target : {}, source !== null && source !== void 0 ? source : {});
|
|
12
13
|
}
|
|
13
|
-
if (Array.isArray(target)) {
|
|
14
|
-
if (
|
|
15
|
-
return
|
|
14
|
+
if (Array.isArray(target) || Array.isArray(source)) {
|
|
15
|
+
if (target === undefined) {
|
|
16
|
+
return source;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
return
|
|
18
|
+
if (source === undefined) {
|
|
19
|
+
return target;
|
|
19
20
|
}
|
|
21
|
+
return [...(0, utils_1.ensureArray)(target), ...(0, utils_1.ensureArray)(source)];
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
if ((0, lodash_1.isFunction)(target) || (0, lodash_1.isFunction)(source)) {
|
|
22
24
|
if (source === undefined) {
|
|
23
25
|
return target;
|
|
24
26
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/core",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/modern-js-dev/modern.js/issues",
|
|
6
6
|
"repository": "modern-js-dev/modern.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"modern",
|
|
11
11
|
"modern.js"
|
|
12
12
|
],
|
|
13
|
-
"version": "2.
|
|
13
|
+
"version": "2.4.0",
|
|
14
14
|
"jsnext:source": "./src/index.ts",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"main": "./dist/index.js",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@modern-js/node-bundle-require": "2.
|
|
55
|
-
"@modern-js/plugin": "2.
|
|
56
|
-
"@modern-js/utils": "2.
|
|
54
|
+
"@modern-js/node-bundle-require": "2.4.0",
|
|
55
|
+
"@modern-js/plugin": "2.4.0",
|
|
56
|
+
"@modern-js/utils": "2.4.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@jest/types": "^27.0.6",
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
"terser-webpack-plugin": "^5.1.4",
|
|
72
72
|
"typescript": "^4",
|
|
73
73
|
"webpack": "^5.75.0",
|
|
74
|
-
"@modern-js/builder-shared": "2.
|
|
75
|
-
"@modern-js/babel-preset-app": "2.
|
|
76
|
-
"@modern-js/types": "2.
|
|
77
|
-
"@scripts/jest-config": "2.
|
|
78
|
-
"@scripts/build": "2.
|
|
74
|
+
"@modern-js/builder-shared": "2.4.0",
|
|
75
|
+
"@modern-js/babel-preset-app": "2.4.0",
|
|
76
|
+
"@modern-js/types": "2.4.0",
|
|
77
|
+
"@scripts/jest-config": "2.4.0",
|
|
78
|
+
"@scripts/build": "2.4.0"
|
|
79
79
|
},
|
|
80
80
|
"sideEffects": false,
|
|
81
81
|
"publishConfig": {
|