@modern-js/core 1.6.0 → 1.7.1
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 +31 -0
- package/dist/js/modern/config/index.js +11 -7
- package/dist/js/modern/config/mergeConfig.js +1 -1
- package/dist/js/modern/config/schema/index.js +1 -1
- package/dist/js/modern/config/types/index.js +1 -0
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +8 -1
- package/dist/js/modern/index.js +26 -9
- package/dist/js/modern/initWatcher.js +2 -2
- package/dist/js/modern/utils/commander.js +15 -15
- package/dist/js/node/config/index.js +38 -11
- package/dist/js/node/config/mergeConfig.js +2 -4
- package/dist/js/node/config/schema/index.js +3 -5
- package/dist/js/node/config/types/index.js +5 -0
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +8 -1
- package/dist/js/node/index.js +31 -10
- package/dist/js/node/initWatcher.js +2 -3
- package/dist/js/node/utils/commander.js +16 -19
- package/dist/types/config/index.d.ts +4 -140
- package/dist/types/config/types/index.d.ts +239 -0
- package/dist/types/config/types/less.d.ts +10 -0
- package/dist/types/config/types/sass.d.ts +8 -0
- package/dist/types/config/types/ssg.d.ts +13 -0
- package/dist/types/config/types/test.d.ts +15 -0
- package/dist/types/config/types/unbundle.d.ts +28 -0
- package/dist/types/context.d.ts +18 -6
- package/dist/types/index.d.ts +25 -1
- package/dist/types/initWatcher.d.ts +1 -2
- package/dist/types/utils/commander.d.ts +4 -7
- package/jest.config.js +0 -1
- package/package.json +16 -16
- package/tests/config.test.ts +14 -5
- package/tests/context.test.ts +17 -2
- package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
- package/tests/index.test.ts +15 -1
- package/tests/initWatcher.test.ts +2 -2
- package/tests/utils.test.ts +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d2d1d6b2: feat: support server config
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 60855eb2: fix: ignore initial watching add event
|
|
12
|
+
- ec1b7367: fix: tools config types
|
|
13
|
+
- 07a4887e: feat: prebundle commander and signale to @modern-js/utils
|
|
14
|
+
- 17d0cc46: feat: prebundle lodash to @modern-js/utils/lodash
|
|
15
|
+
- Updated dependencies [77ff9754]
|
|
16
|
+
- Updated dependencies [d2d1d6b2]
|
|
17
|
+
- Updated dependencies [07a4887e]
|
|
18
|
+
- Updated dependencies [ea2ae711]
|
|
19
|
+
- Updated dependencies [17d0cc46]
|
|
20
|
+
- Updated dependencies [d2d1d6b2]
|
|
21
|
+
- @modern-js/utils@1.4.0
|
|
22
|
+
- @modern-js/load-config@1.3.0
|
|
23
|
+
|
|
24
|
+
## 1.6.1
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- ef28a4e6: fix: module-tools build error
|
|
29
|
+
- 132f7b53: feat: move config declarations to @modern-js/core
|
|
30
|
+
- 9d4a005b: fix: config babel via tools.babel
|
|
31
|
+
- Updated dependencies [132f7b53]
|
|
32
|
+
- @modern-js/utils@1.3.7
|
|
33
|
+
|
|
3
34
|
## 1.6.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
|
@@ -7,9 +7,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
7
7
|
import { loadConfig } from '@modern-js/load-config';
|
|
8
8
|
import Ajv from 'ajv';
|
|
9
9
|
import ajvKeywords from 'ajv-keywords';
|
|
10
|
-
import logger from '
|
|
11
|
-
import {
|
|
12
|
-
import mergeWith from 'lodash.mergewith';
|
|
10
|
+
import { signale as logger, createDebugger, getPort, isDev, PLUGIN_SCHEMAS, chalk, getServerConfig } from '@modern-js/utils';
|
|
11
|
+
import { mergeWith } from '@modern-js/utils/lodash';
|
|
13
12
|
import betterAjvErrors from 'better-ajv-errors';
|
|
14
13
|
import { codeFrameColumns } from '@babel/code-frame';
|
|
15
14
|
import { repeatKeyWarning } from "../utils/repeatKeyWarning";
|
|
@@ -19,6 +18,14 @@ import { patchSchema } from "./schema";
|
|
|
19
18
|
const debug = createDebugger('resolve-config');
|
|
20
19
|
export { defaults as defaultsConfig };
|
|
21
20
|
export { mergeConfig };
|
|
21
|
+
export * from "./types";
|
|
22
|
+
export const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
23
|
+
const serverConfig = await getServerConfig(appDirectory, serverConfigFile);
|
|
24
|
+
|
|
25
|
+
if (serverConfig) {
|
|
26
|
+
dependencies.push(serverConfig);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
22
29
|
export const defineConfig = config => config;
|
|
23
30
|
export const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
24
31
|
const loaded = await loadConfig(appDirectory, filePath, packageJsonConfig);
|
|
@@ -42,8 +49,6 @@ const showAdditionalPropertiesError = error => {
|
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
};
|
|
45
|
-
/* eslint-disable max-statements, max-params */
|
|
46
|
-
|
|
47
52
|
|
|
48
53
|
export const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
|
|
49
54
|
var _validate$errors;
|
|
@@ -107,5 +112,4 @@ export const resolveConfig = async (loaded, configs, schemas, restartWithExistin
|
|
|
107
112
|
|
|
108
113
|
debug('resolved %o', resolved);
|
|
109
114
|
return resolved;
|
|
110
|
-
};
|
|
111
|
-
/* eslint-enable max-statements, max-params */
|
|
115
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isObject, createDebugger } from '@modern-js/utils';
|
|
2
|
-
import cloneDeep from 'lodash
|
|
2
|
+
import { cloneDeep } from '@modern-js/utils/lodash';
|
|
3
3
|
import { source } from "./source";
|
|
4
4
|
import { output } from "./output";
|
|
5
5
|
import { server } from "./server";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -25,7 +25,13 @@ export const useConfigContext = () => ConfigContext.use().value;
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
28
|
-
export const initAppContext = (
|
|
28
|
+
export const initAppContext = ({
|
|
29
|
+
appDirectory,
|
|
30
|
+
plugins,
|
|
31
|
+
configFile,
|
|
32
|
+
options,
|
|
33
|
+
serverConfigFile
|
|
34
|
+
}) => {
|
|
29
35
|
const {
|
|
30
36
|
metaName = 'modern-js',
|
|
31
37
|
srcDir = 'src',
|
|
@@ -36,6 +42,7 @@ export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
|
36
42
|
metaName,
|
|
37
43
|
appDirectory,
|
|
38
44
|
configFile,
|
|
45
|
+
serverConfigFile,
|
|
39
46
|
ip: address.ip(),
|
|
40
47
|
port: 0,
|
|
41
48
|
packageName: require(path.resolve(appDirectory, './package.json')).name,
|
package/dist/js/modern/index.js
CHANGED
|
@@ -5,10 +5,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
7
|
import path from 'path';
|
|
8
|
-
import { pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
|
|
8
|
+
import { pkgUp, program, ensureAbsolutePath, logger, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
|
|
9
9
|
import { enable } from '@modern-js/plugin/node';
|
|
10
|
-
import {
|
|
11
|
-
import { resolveConfig, loadUserConfig } from "./config";
|
|
10
|
+
import { initCommandsMap } from "./utils/commander";
|
|
11
|
+
import { resolveConfig, loadUserConfig, addServerConfigToDeps } from "./config";
|
|
12
12
|
import { loadPlugins } from "./loadPlugins";
|
|
13
13
|
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext } from "./context";
|
|
14
14
|
import { initWatcher } from "./initWatcher";
|
|
@@ -40,6 +40,13 @@ const initAppDir = async cwd => {
|
|
|
40
40
|
return path.dirname(pkg);
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
export const mergeOptions = options => {
|
|
44
|
+
const defaultOptions = {
|
|
45
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
|
46
|
+
};
|
|
47
|
+
return _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
48
|
+
};
|
|
49
|
+
|
|
43
50
|
const createCli = () => {
|
|
44
51
|
let hooksRunner;
|
|
45
52
|
let isRestart = false;
|
|
@@ -47,20 +54,30 @@ const createCli = () => {
|
|
|
47
54
|
let restartOptions;
|
|
48
55
|
|
|
49
56
|
const init = async (argv = [], options) => {
|
|
50
|
-
var
|
|
57
|
+
var _mergedOptions$option, _mergedOptions$option2;
|
|
51
58
|
|
|
52
59
|
enable();
|
|
53
60
|
manager.clear();
|
|
54
|
-
|
|
61
|
+
const mergedOptions = mergeOptions(options);
|
|
62
|
+
restartOptions = mergedOptions;
|
|
55
63
|
const appDirectory = await initAppDir();
|
|
56
|
-
|
|
64
|
+
initCommandsMap();
|
|
65
|
+
const metaName = (_mergedOptions$option = mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions$option2 = mergedOptions.options) === null || _mergedOptions$option2 === void 0 ? void 0 : _mergedOptions$option2.metaName) !== null && _mergedOptions$option !== void 0 ? _mergedOptions$option : 'MODERN';
|
|
57
66
|
loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
58
|
-
const loaded = await loadUserConfig(appDirectory,
|
|
67
|
+
const loaded = await loadUserConfig(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
59
68
|
const plugins = loadPlugins(appDirectory, loaded.config, {
|
|
60
|
-
internalPlugins:
|
|
69
|
+
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins
|
|
61
70
|
});
|
|
62
71
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
63
|
-
const appContext = initAppContext(
|
|
72
|
+
const appContext = initAppContext({
|
|
73
|
+
appDirectory,
|
|
74
|
+
plugins,
|
|
75
|
+
configFile: loaded.filePath,
|
|
76
|
+
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
77
|
+
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
|
|
78
|
+
}); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
79
|
+
|
|
80
|
+
addServerConfigToDeps(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
|
|
64
81
|
manager.run(() => {
|
|
65
82
|
ConfigContext.set(loaded.config);
|
|
66
83
|
AppContext.set(appContext);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { isDev, createDebugger, isTest } from '@modern-js/utils';
|
|
5
|
-
import chokidar from 'chokidar';
|
|
4
|
+
import { isDev, chokidar, createDebugger, isTest } from '@modern-js/utils';
|
|
6
5
|
const debug = createDebugger('watch-files');
|
|
7
6
|
|
|
8
7
|
const md5 = data => crypto.createHash('md5').update(data).digest('hex');
|
|
@@ -17,6 +16,7 @@ export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner,
|
|
|
17
16
|
debug(`watched: %o`, watched);
|
|
18
17
|
const watcher = chokidar.watch(watched, {
|
|
19
18
|
cwd: appDirectory,
|
|
19
|
+
ignoreInitial: true,
|
|
20
20
|
ignorePermissionErrors: true,
|
|
21
21
|
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
22
22
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { program
|
|
1
|
+
import { program } from '@modern-js/utils';
|
|
2
|
+
export function initCommandsMap() {
|
|
3
|
+
if (!program.hasOwnProperty('commandsMap')) {
|
|
4
|
+
Object.defineProperty(program, 'commandsMap', {
|
|
5
|
+
get() {
|
|
6
|
+
const map = new Map();
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const map = new Map();
|
|
8
|
+
for (const command of program.commands) {
|
|
9
|
+
map.set(command._name, command);
|
|
10
|
+
}
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
12
|
+
return map;
|
|
13
|
+
},
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
configurable: false
|
|
16
|
-
});
|
|
15
|
+
configurable: false
|
|
16
|
+
});
|
|
17
|
+
}
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
export { program, Command };
|
|
19
|
+
export { program };
|
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
addServerConfigToDeps: true,
|
|
8
|
+
defineConfig: true,
|
|
9
|
+
loadUserConfig: true,
|
|
10
|
+
resolveConfig: true,
|
|
11
|
+
defaultsConfig: true,
|
|
12
|
+
mergeConfig: true
|
|
13
|
+
};
|
|
14
|
+
exports.addServerConfigToDeps = void 0;
|
|
6
15
|
Object.defineProperty(exports, "defaultsConfig", {
|
|
7
16
|
enumerable: true,
|
|
8
17
|
get: function () {
|
|
@@ -24,11 +33,9 @@ var _ajv = _interopRequireDefault(require("ajv"));
|
|
|
24
33
|
|
|
25
34
|
var _ajvKeywords = _interopRequireDefault(require("ajv-keywords"));
|
|
26
35
|
|
|
27
|
-
var _signale = _interopRequireDefault(require("signale"));
|
|
28
|
-
|
|
29
36
|
var _utils = require("@modern-js/utils");
|
|
30
37
|
|
|
31
|
-
var _lodash =
|
|
38
|
+
var _lodash = require("@modern-js/utils/lodash");
|
|
32
39
|
|
|
33
40
|
var _betterAjvErrors = _interopRequireDefault(require("better-ajv-errors"));
|
|
34
41
|
|
|
@@ -42,6 +49,20 @@ var _mergeConfig = require("./mergeConfig");
|
|
|
42
49
|
|
|
43
50
|
var _schema = require("./schema");
|
|
44
51
|
|
|
52
|
+
var _types = require("./types");
|
|
53
|
+
|
|
54
|
+
Object.keys(_types).forEach(function (key) {
|
|
55
|
+
if (key === "default" || key === "__esModule") return;
|
|
56
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
57
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
58
|
+
Object.defineProperty(exports, key, {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _types[key];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
45
66
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
46
67
|
|
|
47
68
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -52,6 +73,16 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
52
73
|
|
|
53
74
|
const debug = (0, _utils.createDebugger)('resolve-config');
|
|
54
75
|
|
|
76
|
+
const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
77
|
+
const serverConfig = await (0, _utils.getServerConfig)(appDirectory, serverConfigFile);
|
|
78
|
+
|
|
79
|
+
if (serverConfig) {
|
|
80
|
+
dependencies.push(serverConfig);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.addServerConfigToDeps = addServerConfigToDeps;
|
|
85
|
+
|
|
55
86
|
const defineConfig = config => config;
|
|
56
87
|
|
|
57
88
|
exports.defineConfig = defineConfig;
|
|
@@ -60,7 +91,7 @@ const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
|
60
91
|
const loaded = await (0, _loadConfig.loadConfig)(appDirectory, filePath, packageJsonConfig);
|
|
61
92
|
const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
|
|
62
93
|
return {
|
|
63
|
-
config: (0, _lodash.
|
|
94
|
+
config: (0, _lodash.mergeWith)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
|
|
64
95
|
jsConfig: config || {},
|
|
65
96
|
pkgConfig: (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {},
|
|
66
97
|
filePath: loaded === null || loaded === void 0 ? void 0 : loaded.path,
|
|
@@ -76,12 +107,10 @@ const showAdditionalPropertiesError = error => {
|
|
|
76
107
|
const name = Object.keys(_utils.PLUGIN_SCHEMAS).find(key => _utils.PLUGIN_SCHEMAS[key].some(schemaItem => schemaItem.target === target));
|
|
77
108
|
|
|
78
109
|
if (name) {
|
|
79
|
-
|
|
110
|
+
_utils.signale.warn(`The configuration of ${_utils.chalk.bold(target)} is provided by plugin ${_utils.chalk.bold(name)}. Please use ${_utils.chalk.bold('yarn new')} to enable the corresponding capability.\n`);
|
|
80
111
|
}
|
|
81
112
|
}
|
|
82
113
|
};
|
|
83
|
-
/* eslint-disable max-statements, max-params */
|
|
84
|
-
|
|
85
114
|
|
|
86
115
|
const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv, onSchemaError = showAdditionalPropertiesError) => {
|
|
87
116
|
var _validate$errors;
|
|
@@ -113,7 +142,7 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
|
|
|
113
142
|
indent: 2
|
|
114
143
|
});
|
|
115
144
|
|
|
116
|
-
|
|
145
|
+
_utils.signale.log((0, _codeFrame.codeFrameColumns)(JSON.stringify(userConfig, null, 2), {
|
|
117
146
|
start: errors === null || errors === void 0 ? void 0 : errors[0].start,
|
|
118
147
|
end: errors === null || errors === void 0 ? void 0 : errors[0].end
|
|
119
148
|
}, {
|
|
@@ -127,7 +156,7 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
|
|
|
127
156
|
|
|
128
157
|
for (const config of configs) {
|
|
129
158
|
if (!validate(config)) {
|
|
130
|
-
|
|
159
|
+
_utils.signale.error(validate.errors);
|
|
131
160
|
|
|
132
161
|
throw new Error(`Validate configuration error.`);
|
|
133
162
|
}
|
|
@@ -149,7 +178,5 @@ const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort,
|
|
|
149
178
|
debug('resolved %o', resolved);
|
|
150
179
|
return resolved;
|
|
151
180
|
};
|
|
152
|
-
/* eslint-enable max-statements, max-params */
|
|
153
|
-
|
|
154
181
|
|
|
155
182
|
exports.resolveConfig = resolveConfig;
|
|
@@ -5,19 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.mergeConfig = void 0;
|
|
7
7
|
|
|
8
|
-
var _lodash =
|
|
8
|
+
var _lodash = require("@modern-js/utils/lodash");
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
12
|
/**
|
|
15
13
|
* merge configuration from modern.config.js and plugins.
|
|
16
14
|
*
|
|
17
15
|
* @param configs - Configuration from modern.config.ts or plugin's config hook.
|
|
18
16
|
* @returns - normalized user config.
|
|
19
17
|
*/
|
|
20
|
-
const mergeConfig = configs => (0, _lodash.
|
|
18
|
+
const mergeConfig = configs => (0, _lodash.mergeWith)({}, ...configs, (target, source) => {
|
|
21
19
|
if (Array.isArray(target)) {
|
|
22
20
|
if (Array.isArray(source)) {
|
|
23
21
|
return [...target, ...source];
|
|
@@ -7,7 +7,7 @@ exports.traverseSchema = exports.patchSchema = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
|
-
var _lodash =
|
|
10
|
+
var _lodash = require("@modern-js/utils/lodash");
|
|
11
11
|
|
|
12
12
|
var _source = require("./source");
|
|
13
13
|
|
|
@@ -19,8 +19,6 @@ var _deploy = require("./deploy");
|
|
|
19
19
|
|
|
20
20
|
var _tools = require("./tools");
|
|
21
21
|
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
22
|
const debug = (0, _utils.createDebugger)('validate-schema');
|
|
25
23
|
const plugins = {
|
|
26
24
|
type: 'array',
|
|
@@ -40,7 +38,7 @@ const dev = {
|
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
const patchSchema = pluginSchemas => {
|
|
43
|
-
const finalSchema = (0, _lodash.
|
|
41
|
+
const finalSchema = (0, _lodash.cloneDeep)({
|
|
44
42
|
type: 'object',
|
|
45
43
|
additionalProperties: false,
|
|
46
44
|
properties: {
|
|
@@ -96,7 +94,7 @@ const patchSchema = pluginSchemas => {
|
|
|
96
94
|
throw new Error(`${target} already exists in current validate schema`);
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
targetNode[mountProperty] = (0, _lodash.
|
|
97
|
+
targetNode[mountProperty] = (0, _lodash.cloneDeep)(schema);
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
debug(`final validate schema: %o`, finalSchema);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/js/node/context.js
CHANGED
|
@@ -53,7 +53,13 @@ const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
|
53
53
|
|
|
54
54
|
exports.useResolvedConfigContext = useResolvedConfigContext;
|
|
55
55
|
|
|
56
|
-
const initAppContext = (
|
|
56
|
+
const initAppContext = ({
|
|
57
|
+
appDirectory,
|
|
58
|
+
plugins,
|
|
59
|
+
configFile,
|
|
60
|
+
options,
|
|
61
|
+
serverConfigFile
|
|
62
|
+
}) => {
|
|
57
63
|
const {
|
|
58
64
|
metaName = 'modern-js',
|
|
59
65
|
srcDir = 'src',
|
|
@@ -64,6 +70,7 @@ const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
|
64
70
|
metaName,
|
|
65
71
|
appDirectory,
|
|
66
72
|
configFile,
|
|
73
|
+
serverConfigFile,
|
|
67
74
|
ip: _address.default.ip(),
|
|
68
75
|
port: 0,
|
|
69
76
|
packageName: require(_path.default.resolve(appDirectory, './package.json')).name,
|
package/dist/js/node/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
mergeOptions: true,
|
|
7
8
|
cli: true,
|
|
8
9
|
initAppDir: true,
|
|
9
10
|
initAppContext: true,
|
|
@@ -57,6 +58,7 @@ Object.defineProperty(exports, "manager", {
|
|
|
57
58
|
return _manager.manager;
|
|
58
59
|
}
|
|
59
60
|
});
|
|
61
|
+
exports.mergeOptions = void 0;
|
|
60
62
|
Object.defineProperty(exports, "mountHook", {
|
|
61
63
|
enumerable: true,
|
|
62
64
|
get: function () {
|
|
@@ -162,7 +164,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
162
164
|
|
|
163
165
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
_utils.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
166
168
|
|
|
167
169
|
const initAppDir = async cwd => {
|
|
168
170
|
if (!cwd) {
|
|
@@ -183,6 +185,15 @@ const initAppDir = async cwd => {
|
|
|
183
185
|
|
|
184
186
|
exports.initAppDir = initAppDir;
|
|
185
187
|
|
|
188
|
+
const mergeOptions = options => {
|
|
189
|
+
const defaultOptions = {
|
|
190
|
+
serverConfigFile: _utils.DEFAULT_SERVER_CONFIG
|
|
191
|
+
};
|
|
192
|
+
return _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
exports.mergeOptions = mergeOptions;
|
|
196
|
+
|
|
186
197
|
const createCli = () => {
|
|
187
198
|
let hooksRunner;
|
|
188
199
|
let isRestart = false;
|
|
@@ -190,22 +201,32 @@ const createCli = () => {
|
|
|
190
201
|
let restartOptions;
|
|
191
202
|
|
|
192
203
|
const init = async (argv = [], options) => {
|
|
193
|
-
var
|
|
204
|
+
var _mergedOptions$option, _mergedOptions$option2;
|
|
194
205
|
|
|
195
206
|
(0, _node.enable)();
|
|
196
207
|
|
|
197
208
|
_manager.manager.clear();
|
|
198
209
|
|
|
199
|
-
|
|
210
|
+
const mergedOptions = mergeOptions(options);
|
|
211
|
+
restartOptions = mergedOptions;
|
|
200
212
|
const appDirectory = await initAppDir();
|
|
201
|
-
|
|
213
|
+
(0, _commander.initCommandsMap)();
|
|
214
|
+
const metaName = (_mergedOptions$option = mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions$option2 = mergedOptions.options) === null || _mergedOptions$option2 === void 0 ? void 0 : _mergedOptions$option2.metaName) !== null && _mergedOptions$option !== void 0 ? _mergedOptions$option : 'MODERN';
|
|
202
215
|
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
203
|
-
const loaded = await (0, _config.loadUserConfig)(appDirectory,
|
|
216
|
+
const loaded = await (0, _config.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
204
217
|
const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
|
|
205
|
-
internalPlugins:
|
|
218
|
+
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins
|
|
206
219
|
});
|
|
207
220
|
plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
|
|
208
|
-
const appContext = (0, _context.initAppContext)(
|
|
221
|
+
const appContext = (0, _context.initAppContext)({
|
|
222
|
+
appDirectory,
|
|
223
|
+
plugins,
|
|
224
|
+
configFile: loaded.filePath,
|
|
225
|
+
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
226
|
+
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
|
|
227
|
+
}); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
228
|
+
|
|
229
|
+
(0, _config.addServerConfigToDeps)(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
|
|
209
230
|
|
|
210
231
|
_manager.manager.run(() => {
|
|
211
232
|
_context.ConfigContext.set(loaded.config);
|
|
@@ -263,11 +284,11 @@ const createCli = () => {
|
|
|
263
284
|
resolved
|
|
264
285
|
} = await init(argv, options);
|
|
265
286
|
await hooksRunner.commands({
|
|
266
|
-
program:
|
|
287
|
+
program: _utils.program
|
|
267
288
|
});
|
|
268
289
|
(0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
269
290
|
|
|
270
|
-
_manager.manager.run(() =>
|
|
291
|
+
_manager.manager.run(() => _utils.program.parse(process.argv));
|
|
271
292
|
}
|
|
272
293
|
|
|
273
294
|
async function restart() {
|
|
@@ -291,7 +312,7 @@ const createCli = () => {
|
|
|
291
312
|
hasGetError = true;
|
|
292
313
|
} finally {
|
|
293
314
|
if (!hasGetError) {
|
|
294
|
-
_manager.manager.run(() =>
|
|
315
|
+
_manager.manager.run(() => _utils.program.parse(process.argv));
|
|
295
316
|
}
|
|
296
317
|
}
|
|
297
318
|
}
|
|
@@ -13,8 +13,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
17
|
-
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
17
|
|
|
20
18
|
const debug = (0, _utils.createDebugger)('watch-files');
|
|
@@ -33,8 +31,9 @@ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) =
|
|
|
33
31
|
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
34
32
|
debug(`watched: %o`, watched);
|
|
35
33
|
|
|
36
|
-
const watcher =
|
|
34
|
+
const watcher = _utils.chokidar.watch(watched, {
|
|
37
35
|
cwd: appDirectory,
|
|
36
|
+
ignoreInitial: true,
|
|
38
37
|
ignorePermissionErrors: true,
|
|
39
38
|
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
40
39
|
});
|
|
@@ -3,33 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _commander.Command;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
6
|
+
exports.initCommandsMap = initCommandsMap;
|
|
12
7
|
Object.defineProperty(exports, "program", {
|
|
13
8
|
enumerable: true,
|
|
14
9
|
get: function () {
|
|
15
|
-
return
|
|
10
|
+
return _utils.program;
|
|
16
11
|
}
|
|
17
12
|
});
|
|
18
13
|
|
|
19
|
-
var
|
|
14
|
+
var _utils = require("@modern-js/utils");
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
function initCommandsMap() {
|
|
17
|
+
if (!_utils.program.hasOwnProperty('commandsMap')) {
|
|
18
|
+
Object.defineProperty(_utils.program, 'commandsMap', {
|
|
19
|
+
get() {
|
|
20
|
+
const map = new Map();
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
for (const command of _utils.program.commands) {
|
|
23
|
+
map.set(command._name, command);
|
|
24
|
+
}
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
return map;
|
|
27
|
+
},
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
configurable: false
|
|
30
|
+
});
|
|
31
|
+
}
|
|
35
32
|
}
|