@modern-js/core 2.2.0 → 2.3.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # @modern-js/core
2
2
 
3
+ ## 2.3.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 65f1322: fix(core): merge array config correctly
8
+
9
+ fix(core): 修复合并配置中的数组时出现错误的问题
10
+
11
+ - fd5a3ed: fix: failed to exit new command
12
+
13
+ fix: 修复 new 命令执行完成后未退出进程的问题
14
+
15
+ - 7b2cdcb: feat(core): support read modern.config.local.ts
16
+
17
+ feat(core): 支持读取 modern.config.local.ts 文件
18
+
19
+ - 7736171: fix: remove disableRunBuild
20
+ fix: 移除 disableRunBuild
21
+ - Updated dependencies [fd5a3ed]
22
+ - Updated dependencies [6ca1c0b]
23
+ - Updated dependencies [89b6739]
24
+ - @modern-js/utils@2.3.0
25
+ - @modern-js/node-bundle-require@2.3.0
26
+ - @modern-js/plugin@2.3.0
27
+
3
28
  ## 2.2.0
4
29
 
5
30
  ### Minor Changes
@@ -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 load_configs_1 = require("../load-configs");
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(0)) || {};
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 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);
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: (0, exports.assignPkgConfig)(config, loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig),
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 filePath - Specific absolute config file path.
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, filePath?: string, packageJsonConfig?: string) => Promise<{
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 filePath - Specific absolute config file path.
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, filePath, packageJsonConfig) => {
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,
@@ -37,7 +37,6 @@ export interface DevToolData<DevOptions = any> {
37
37
  name: string;
38
38
  value: string;
39
39
  };
40
- disableRunBuild?: boolean;
41
40
  action: (options: DevOptions, context: {
42
41
  isTsProject?: boolean;
43
42
  }) => void | Promise<void>;
@@ -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.isDev)() || (0, utils_1.isTest)()) {
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 (Array.isArray(source)) {
15
- return [...target, ...source];
14
+ if (Array.isArray(target) || Array.isArray(source)) {
15
+ if (target === undefined) {
16
+ return source;
16
17
  }
17
- else {
18
- return source !== undefined ? [...target, source] : target;
18
+ if (source === undefined) {
19
+ return target;
19
20
  }
21
+ return [...(0, utils_1.ensureArray)(target), ...(0, utils_1.ensureArray)(source)];
20
22
  }
21
- else if ((0, lodash_1.isFunction)(target) || (0, lodash_1.isFunction)(source)) {
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
@@ -10,7 +10,7 @@
10
10
  "modern",
11
11
  "modern.js"
12
12
  ],
13
- "version": "2.2.0",
13
+ "version": "2.3.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.2.0",
55
- "@modern-js/plugin": "2.2.0",
56
- "@modern-js/utils": "2.2.0"
54
+ "@modern-js/node-bundle-require": "2.3.0",
55
+ "@modern-js/plugin": "2.3.0",
56
+ "@modern-js/utils": "2.3.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.2.0",
75
- "@modern-js/babel-preset-app": "2.2.0",
76
- "@modern-js/types": "2.2.0",
77
- "@scripts/jest-config": "2.2.0",
78
- "@scripts/build": "2.2.0"
74
+ "@modern-js/builder-shared": "2.3.0",
75
+ "@modern-js/babel-preset-app": "2.3.0",
76
+ "@modern-js/types": "2.3.0",
77
+ "@scripts/jest-config": "2.3.0",
78
+ "@scripts/build": "2.3.0"
79
79
  },
80
80
  "sideEffects": false,
81
81
  "publishConfig": {