@modern-js/core 1.1.5-beta.1 → 1.3.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 +43 -0
- package/dist/js/modern/cli.js +29 -0
- package/dist/js/modern/config/index.js +11 -5
- package/dist/js/modern/index.js +18 -9
- package/dist/js/modern/loadPlugins.js +16 -2
- package/dist/js/node/cli.js +35 -0
- package/dist/js/node/config/index.js +11 -5
- package/dist/js/node/index.js +27 -36
- package/dist/js/node/loadPlugins.js +17 -1
- package/dist/types/cli.d.ts +1 -0
- package/dist/types/config/index.d.ts +14 -13
- package/dist/types/index.d.ts +7 -7
- package/dist/types/loadPlugins.d.ts +5 -0
- package/jest.config.js +8 -0
- package/modern.config.js +0 -7
- package/package.json +25 -19
- package/src/cli.ts +36 -0
- package/src/config/index.ts +42 -17
- package/src/index.ts +21 -20
- package/src/loadPlugins.ts +23 -6
- package/tests/btsm.test.ts +20 -0
- package/tests/config.test.ts +137 -0
- package/tests/context.test.ts +28 -0
- package/tests/fixtures/index-test/package.json +3 -0
- package/tests/index.test.ts +74 -0
- package/tests/loadEnv.test.ts +1 -1
- package/tests/loadPlugin.test.ts +36 -1
- package/tests/mergeConfig.test.ts +1 -1
- package/tests/repeatKeyWarning.test.ts +2 -2
- package/tests/schema.test.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tests/utils.test.ts +8 -0
- package/tsconfig.json +1 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4584cc04: export DeployConfig interface
|
|
8
|
+
- 7c19fd94: use existing port number for AppContext when dev server is restarted
|
|
9
|
+
- Updated dependencies [823809c6]
|
|
10
|
+
- @modern-js/utils@1.2.1
|
|
11
|
+
|
|
12
|
+
## 1.3.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- fc71e36f: support custom property name for the config in package.json
|
|
17
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [2da09c69]
|
|
22
|
+
- Updated dependencies [fc71e36f]
|
|
23
|
+
- Updated dependencies [c3d46ee4]
|
|
24
|
+
- Updated dependencies [cfe11628]
|
|
25
|
+
- @modern-js/utils@1.2.0
|
|
26
|
+
- @modern-js/load-config@1.2.0
|
|
27
|
+
- @modern-js/plugin@1.2.0
|
|
28
|
+
|
|
29
|
+
## 1.2.0
|
|
30
|
+
|
|
31
|
+
### Minor Changes
|
|
32
|
+
|
|
33
|
+
- 90eeb72c: add modern config schema and types of testing, tools.jest.
|
|
34
|
+
add typesVersions for re-exporting types of @modern-js/plugin-testing.
|
|
35
|
+
fix type lost when redeclareing modules.
|
|
36
|
+
- 5a4c557e: feat: support bff test
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- e04914ce: add route types, fix metrics types
|
|
41
|
+
- e04914ce: add route types, fix metrics types
|
|
42
|
+
- ecb344dc: fix micro-frontend type error
|
|
43
|
+
- Updated dependencies [ca7dcb32]
|
|
44
|
+
- @modern-js/utils@1.1.5
|
|
45
|
+
|
|
3
46
|
## 1.1.4
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// 这个文件跟 bin/modern-js.js 基本一样
|
|
2
|
+
// 在开发阶段,因为 package.json 的 exports['./bin']['jsnext:source'] 配置
|
|
3
|
+
// 了这个文件,所以需要保留, 后续如果找到更好的方式之后会移除这个文件
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { cli } from ".";
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
version
|
|
9
|
+
} = require("../../package.json"); // XXX: 通过这个方式去掉了 package.json 里面对于 @modern-js/module-tools 的 devDependencies 依赖
|
|
10
|
+
// 然后可以正常的执行 modern build
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const kModuleToolsCliPath = path.resolve(__dirname, '../../../solutions/module-tools/src/index.ts');
|
|
14
|
+
process.env.MODERN_JS_VERSION = version;
|
|
15
|
+
|
|
16
|
+
if (!process.env.NODE_ENV) {
|
|
17
|
+
process.env.NODE_ENV = // eslint-disable-next-line no-nested-ternary
|
|
18
|
+
['build', 'start', 'deploy'].includes(process.argv[2]) ? 'production' : process.argv[2] === 'test' ? 'test' : 'development';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
cli.run(process.argv.slice(2), {
|
|
22
|
+
plugins: {
|
|
23
|
+
'@modern-js/module-tools': {
|
|
24
|
+
cli: kModuleToolsCliPath,
|
|
25
|
+
// 是否需要强制加载这个组件,跳过 loadPlugins 里面 filter 的检测逻辑
|
|
26
|
+
forced: true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -20,8 +20,8 @@ const debug = createDebugger('resolve-config');
|
|
|
20
20
|
export { defaults as defaultsConfig };
|
|
21
21
|
export { mergeConfig };
|
|
22
22
|
export const defineConfig = config => config;
|
|
23
|
-
export const loadUserConfig = async (appDirectory, filePath) => {
|
|
24
|
-
const loaded = await loadConfig(appDirectory, filePath);
|
|
23
|
+
export const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
24
|
+
const loaded = await loadConfig(appDirectory, filePath, packageJsonConfig);
|
|
25
25
|
const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
|
|
26
26
|
return {
|
|
27
27
|
config: mergeWith({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
|
|
@@ -45,7 +45,7 @@ const showAdditionalPropertiesError = error => {
|
|
|
45
45
|
/* eslint-disable max-statements, max-params */
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
export const resolveConfig = async (loaded, configs, schemas,
|
|
48
|
+
export const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv) => {
|
|
49
49
|
var _validate$errors;
|
|
50
50
|
|
|
51
51
|
const {
|
|
@@ -95,8 +95,14 @@ export const resolveConfig = async (loaded, configs, schemas, isRestart, argv) =
|
|
|
95
95
|
const resolved = mergeConfig([defaults, ...configs, userConfig]);
|
|
96
96
|
resolved._raw = loaded.config;
|
|
97
97
|
|
|
98
|
-
if (isDev() && argv[0] === 'dev'
|
|
99
|
-
|
|
98
|
+
if (isDev() && argv[0] === 'dev') {
|
|
99
|
+
if (restartWithExistingPort > 0) {
|
|
100
|
+
// dev server is restarted, should use existing port number
|
|
101
|
+
resolved.server.port = restartWithExistingPort;
|
|
102
|
+
} else {
|
|
103
|
+
// get port for new dev server
|
|
104
|
+
resolved.server.port = await getPort(resolved.server.port);
|
|
105
|
+
}
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
debug('resolved %o', resolved);
|
package/dist/js/modern/index.js
CHANGED
|
@@ -9,12 +9,12 @@ import { compatRequire, pkgUp, ensureAbsolutePath, logger } from '@modern-js/uti
|
|
|
9
9
|
import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow, createAsyncWaterfall } from '@modern-js/plugin';
|
|
10
10
|
import { enable } from '@modern-js/plugin/node';
|
|
11
11
|
import { program } from "./utils/commander";
|
|
12
|
-
import { resolveConfig,
|
|
12
|
+
import { resolveConfig, loadUserConfig } from "./config";
|
|
13
13
|
import { loadPlugins } from "./loadPlugins";
|
|
14
14
|
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from "./context";
|
|
15
15
|
import { initWatcher } from "./initWatcher";
|
|
16
16
|
import { loadEnv } from "./loadEnv";
|
|
17
|
-
export
|
|
17
|
+
export * from "./config";
|
|
18
18
|
export * from '@modern-js/plugin';
|
|
19
19
|
export * from '@modern-js/plugin/node';
|
|
20
20
|
program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
@@ -37,15 +37,20 @@ export const {
|
|
|
37
37
|
useRunner: mountHook
|
|
38
38
|
} = manager;
|
|
39
39
|
export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(require.resolve(plugin))));
|
|
40
|
-
export {
|
|
40
|
+
export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
|
|
41
|
+
|
|
42
|
+
const initAppDir = async cwd => {
|
|
43
|
+
if (!cwd) {
|
|
44
|
+
// eslint-disable-next-line no-param-reassign
|
|
45
|
+
cwd = process.cwd();
|
|
46
|
+
}
|
|
41
47
|
|
|
42
|
-
const initAppDir = async () => {
|
|
43
48
|
const pkg = await pkgUp({
|
|
44
|
-
cwd
|
|
49
|
+
cwd
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
if (!pkg) {
|
|
48
|
-
throw new Error(`no package.json found in current work dir: ${
|
|
53
|
+
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
return path.dirname(pkg);
|
|
@@ -54,13 +59,14 @@ const initAppDir = async () => {
|
|
|
54
59
|
const createCli = () => {
|
|
55
60
|
let hooksRunner;
|
|
56
61
|
let isRestart = false;
|
|
62
|
+
let restartWithExistingPort = 0;
|
|
57
63
|
|
|
58
64
|
const init = async (argv = [], options) => {
|
|
59
65
|
enable();
|
|
60
66
|
manager.clear();
|
|
61
67
|
const appDirectory = await initAppDir();
|
|
62
68
|
loadEnv(appDirectory);
|
|
63
|
-
const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile);
|
|
69
|
+
const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
64
70
|
let plugins = loadPlugins(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
|
|
65
71
|
|
|
66
72
|
if (options !== null && options !== void 0 && options.beforeUsePlugins) {
|
|
@@ -90,7 +96,7 @@ const createCli = () => {
|
|
|
90
96
|
});
|
|
91
97
|
const extraConfigs = await hooksRunner.config();
|
|
92
98
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
93
|
-
const config = await resolveConfig(loaded, extraConfigs, extraSchemas,
|
|
99
|
+
const config = await resolveConfig(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
94
100
|
const {
|
|
95
101
|
resolved
|
|
96
102
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -127,7 +133,10 @@ const createCli = () => {
|
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
async function restart() {
|
|
136
|
+
var _AppContext$use$value, _AppContext$use$value2;
|
|
137
|
+
|
|
130
138
|
isRestart = true;
|
|
139
|
+
restartWithExistingPort = isRestart ? (_AppContext$use$value = (_AppContext$use$value2 = AppContext.use().value) === null || _AppContext$use$value2 === void 0 ? void 0 : _AppContext$use$value2.port) !== null && _AppContext$use$value !== void 0 ? _AppContext$use$value : 0 : 0;
|
|
131
140
|
logger.info('Restart...\n');
|
|
132
141
|
let hasGetError = false;
|
|
133
142
|
|
|
@@ -151,4 +160,4 @@ const createCli = () => {
|
|
|
151
160
|
};
|
|
152
161
|
|
|
153
162
|
export const cli = createCli();
|
|
154
|
-
export {
|
|
163
|
+
export { initAppDir, initAppContext };
|
|
@@ -45,6 +45,21 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
45
45
|
|
|
46
46
|
return resolved;
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
export function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
50
|
+
const allPlugins = internalPlugins || INTERNAL_PLUGINS;
|
|
51
|
+
const appPlugins = [...Object.keys(allPlugins).filter(name => {
|
|
52
|
+
const config = allPlugins[name];
|
|
53
|
+
|
|
54
|
+
if (config.forced === true) {
|
|
55
|
+
// 参考 packages/cli/core/src/cli.ts 文件
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return isDepExists(appDirectory, name);
|
|
60
|
+
}).map(name => allPlugins[name]), ...pluginConfig];
|
|
61
|
+
return appPlugins;
|
|
62
|
+
}
|
|
48
63
|
/**
|
|
49
64
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
50
65
|
* @param appDirectory - Application root directory.
|
|
@@ -52,9 +67,8 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
52
67
|
* @returns Plugin Objects has been required.
|
|
53
68
|
*/
|
|
54
69
|
|
|
55
|
-
|
|
56
70
|
export const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
|
|
57
|
-
const plugins =
|
|
71
|
+
const plugins = getAppPlugins(appDirectory, pluginConfig, internalPlugins);
|
|
58
72
|
return plugins.map(plugin => {
|
|
59
73
|
const {
|
|
60
74
|
cli,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
|
4
|
+
|
|
5
|
+
var _ = require(".");
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
// 这个文件跟 bin/modern-js.js 基本一样
|
|
10
|
+
// 在开发阶段,因为 package.json 的 exports['./bin']['jsnext:source'] 配置
|
|
11
|
+
// 了这个文件,所以需要保留, 后续如果找到更好的方式之后会移除这个文件
|
|
12
|
+
const {
|
|
13
|
+
version
|
|
14
|
+
} = require("../../package.json"); // XXX: 通过这个方式去掉了 package.json 里面对于 @modern-js/module-tools 的 devDependencies 依赖
|
|
15
|
+
// 然后可以正常的执行 modern build
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const kModuleToolsCliPath = _path.default.resolve(__dirname, '../../../solutions/module-tools/src/index.ts');
|
|
19
|
+
|
|
20
|
+
process.env.MODERN_JS_VERSION = version;
|
|
21
|
+
|
|
22
|
+
if (!process.env.NODE_ENV) {
|
|
23
|
+
process.env.NODE_ENV = // eslint-disable-next-line no-nested-ternary
|
|
24
|
+
['build', 'start', 'deploy'].includes(process.argv[2]) ? 'production' : process.argv[2] === 'test' ? 'test' : 'development';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_.cli.run(process.argv.slice(2), {
|
|
28
|
+
plugins: {
|
|
29
|
+
'@modern-js/module-tools': {
|
|
30
|
+
cli: kModuleToolsCliPath,
|
|
31
|
+
// 是否需要强制加载这个组件,跳过 loadPlugins 里面 filter 的检测逻辑
|
|
32
|
+
forced: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -56,8 +56,8 @@ const defineConfig = config => config;
|
|
|
56
56
|
|
|
57
57
|
exports.defineConfig = defineConfig;
|
|
58
58
|
|
|
59
|
-
const loadUserConfig = async (appDirectory, filePath) => {
|
|
60
|
-
const loaded = await (0, _loadConfig.loadConfig)(appDirectory, filePath);
|
|
59
|
+
const loadUserConfig = async (appDirectory, filePath, packageJsonConfig) => {
|
|
60
|
+
const loaded = await (0, _loadConfig.loadConfig)(appDirectory, filePath, packageJsonConfig);
|
|
61
61
|
const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
|
|
62
62
|
return {
|
|
63
63
|
config: (0, _lodash.default)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
|
|
@@ -83,7 +83,7 @@ const showAdditionalPropertiesError = error => {
|
|
|
83
83
|
/* eslint-disable max-statements, max-params */
|
|
84
84
|
|
|
85
85
|
|
|
86
|
-
const resolveConfig = async (loaded, configs, schemas,
|
|
86
|
+
const resolveConfig = async (loaded, configs, schemas, restartWithExistingPort, argv) => {
|
|
87
87
|
var _validate$errors;
|
|
88
88
|
|
|
89
89
|
const {
|
|
@@ -136,8 +136,14 @@ const resolveConfig = async (loaded, configs, schemas, isRestart, argv) => {
|
|
|
136
136
|
const resolved = (0, _mergeConfig.mergeConfig)([_defaults.defaults, ...configs, userConfig]);
|
|
137
137
|
resolved._raw = loaded.config;
|
|
138
138
|
|
|
139
|
-
if ((0, _utils.isDev)() && argv[0] === 'dev'
|
|
140
|
-
|
|
139
|
+
if ((0, _utils.isDev)() && argv[0] === 'dev') {
|
|
140
|
+
if (restartWithExistingPort > 0) {
|
|
141
|
+
// dev server is restarted, should use existing port number
|
|
142
|
+
resolved.server.port = restartWithExistingPort;
|
|
143
|
+
} else {
|
|
144
|
+
// get port for new dev server
|
|
145
|
+
resolved.server.port = await (0, _utils.getPort)(resolved.server.port);
|
|
146
|
+
}
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
debug('resolved %o', resolved);
|
package/dist/js/node/index.js
CHANGED
|
@@ -11,10 +11,6 @@ var _exportNames = {
|
|
|
11
11
|
usePlugins: true,
|
|
12
12
|
cli: true,
|
|
13
13
|
initAppDir: true,
|
|
14
|
-
defineConfig: true,
|
|
15
|
-
loadUserConfig: true,
|
|
16
|
-
defaultsConfig: true,
|
|
17
|
-
mergeConfig: true,
|
|
18
14
|
AppContext: true,
|
|
19
15
|
ConfigContext: true,
|
|
20
16
|
initAppContext: true,
|
|
@@ -42,39 +38,13 @@ Object.defineProperty(exports, "ResolvedConfigContext", {
|
|
|
42
38
|
}
|
|
43
39
|
});
|
|
44
40
|
exports.createPlugin = exports.cli = void 0;
|
|
45
|
-
Object.defineProperty(exports, "defaultsConfig", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
get: function () {
|
|
48
|
-
return _config.defaultsConfig;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports, "defineConfig", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return _config.defineConfig;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
41
|
Object.defineProperty(exports, "initAppContext", {
|
|
58
42
|
enumerable: true,
|
|
59
43
|
get: function () {
|
|
60
44
|
return _context.initAppContext;
|
|
61
45
|
}
|
|
62
46
|
});
|
|
63
|
-
exports.initAppDir = void 0;
|
|
64
|
-
Object.defineProperty(exports, "loadUserConfig", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function () {
|
|
67
|
-
return _config.loadUserConfig;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
exports.manager = void 0;
|
|
71
|
-
Object.defineProperty(exports, "mergeConfig", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () {
|
|
74
|
-
return _config.mergeConfig;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
exports.registerHook = exports.mountHook = void 0;
|
|
47
|
+
exports.registerHook = exports.mountHook = exports.manager = exports.initAppDir = void 0;
|
|
78
48
|
Object.defineProperty(exports, "useAppContext", {
|
|
79
49
|
enumerable: true,
|
|
80
50
|
get: function () {
|
|
@@ -131,6 +101,18 @@ var _commander = require("./utils/commander");
|
|
|
131
101
|
|
|
132
102
|
var _config = require("./config");
|
|
133
103
|
|
|
104
|
+
Object.keys(_config).forEach(function (key) {
|
|
105
|
+
if (key === "default" || key === "__esModule") return;
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
107
|
+
if (key in exports && exports[key] === _config[key]) return;
|
|
108
|
+
Object.defineProperty(exports, key, {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _config[key];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
134
116
|
var _loadPlugins = require("./loadPlugins");
|
|
135
117
|
|
|
136
118
|
var _context = require("./context");
|
|
@@ -176,13 +158,18 @@ const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _u
|
|
|
176
158
|
|
|
177
159
|
exports.usePlugins = usePlugins;
|
|
178
160
|
|
|
179
|
-
const initAppDir = async
|
|
161
|
+
const initAppDir = async cwd => {
|
|
162
|
+
if (!cwd) {
|
|
163
|
+
// eslint-disable-next-line no-param-reassign
|
|
164
|
+
cwd = process.cwd();
|
|
165
|
+
}
|
|
166
|
+
|
|
180
167
|
const pkg = await (0, _utils.pkgUp)({
|
|
181
|
-
cwd
|
|
168
|
+
cwd
|
|
182
169
|
});
|
|
183
170
|
|
|
184
171
|
if (!pkg) {
|
|
185
|
-
throw new Error(`no package.json found in current work dir: ${
|
|
172
|
+
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
186
173
|
}
|
|
187
174
|
|
|
188
175
|
return _path.default.dirname(pkg);
|
|
@@ -193,13 +180,14 @@ exports.initAppDir = initAppDir;
|
|
|
193
180
|
const createCli = () => {
|
|
194
181
|
let hooksRunner;
|
|
195
182
|
let isRestart = false;
|
|
183
|
+
let restartWithExistingPort = 0;
|
|
196
184
|
|
|
197
185
|
const init = async (argv = [], options) => {
|
|
198
186
|
(0, _node.enable)();
|
|
199
187
|
manager.clear();
|
|
200
188
|
const appDirectory = await initAppDir();
|
|
201
189
|
(0, _loadEnv.loadEnv)(appDirectory);
|
|
202
|
-
const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile);
|
|
190
|
+
const loaded = await (0, _config.loadUserConfig)(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
203
191
|
let plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config.plugins || [], options === null || options === void 0 ? void 0 : options.plugins);
|
|
204
192
|
|
|
205
193
|
if (options !== null && options !== void 0 && options.beforeUsePlugins) {
|
|
@@ -230,7 +218,7 @@ const createCli = () => {
|
|
|
230
218
|
});
|
|
231
219
|
const extraConfigs = await hooksRunner.config();
|
|
232
220
|
const extraSchemas = await hooksRunner.validateSchema();
|
|
233
|
-
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas,
|
|
221
|
+
const config = await (0, _config.resolveConfig)(loaded, extraConfigs, extraSchemas, restartWithExistingPort, argv);
|
|
234
222
|
const {
|
|
235
223
|
resolved
|
|
236
224
|
} = await hooksRunner.resolvedConfig({
|
|
@@ -269,7 +257,10 @@ const createCli = () => {
|
|
|
269
257
|
}
|
|
270
258
|
|
|
271
259
|
async function restart() {
|
|
260
|
+
var _AppContext$use$value, _AppContext$use$value2;
|
|
261
|
+
|
|
272
262
|
isRestart = true;
|
|
263
|
+
restartWithExistingPort = isRestart ? (_AppContext$use$value = (_AppContext$use$value2 = _context.AppContext.use().value) === null || _AppContext$use$value2 === void 0 ? void 0 : _AppContext$use$value2.port) !== null && _AppContext$use$value !== void 0 ? _AppContext$use$value : 0 : 0;
|
|
273
264
|
|
|
274
265
|
_utils.logger.info('Restart...\n');
|
|
275
266
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getAppPlugins = getAppPlugins;
|
|
6
7
|
exports.loadPlugins = void 0;
|
|
7
8
|
|
|
8
9
|
var _utils = require("@modern-js/utils");
|
|
@@ -53,6 +54,21 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
53
54
|
|
|
54
55
|
return resolved;
|
|
55
56
|
};
|
|
57
|
+
|
|
58
|
+
function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
59
|
+
const allPlugins = internalPlugins || _utils.INTERNAL_PLUGINS;
|
|
60
|
+
const appPlugins = [...Object.keys(allPlugins).filter(name => {
|
|
61
|
+
const config = allPlugins[name];
|
|
62
|
+
|
|
63
|
+
if (config.forced === true) {
|
|
64
|
+
// 参考 packages/cli/core/src/cli.ts 文件
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (0, _utils.isDepExists)(appDirectory, name);
|
|
69
|
+
}).map(name => allPlugins[name]), ...pluginConfig];
|
|
70
|
+
return appPlugins;
|
|
71
|
+
}
|
|
56
72
|
/**
|
|
57
73
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
58
74
|
* @param appDirectory - Application root directory.
|
|
@@ -62,7 +78,7 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
62
78
|
|
|
63
79
|
|
|
64
80
|
const loadPlugins = (appDirectory, pluginConfig, internalPlugins) => {
|
|
65
|
-
const plugins =
|
|
81
|
+
const plugins = getAppPlugins(appDirectory, pluginConfig, internalPlugins);
|
|
66
82
|
return plugins.map(plugin => {
|
|
67
83
|
const {
|
|
68
84
|
cli,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,7 +5,7 @@ import { mergeConfig, NormalizedConfig } from './mergeConfig';
|
|
|
5
5
|
import { PluginValidateSchema } from './schema';
|
|
6
6
|
export { defaults as defaultsConfig };
|
|
7
7
|
export { mergeConfig };
|
|
8
|
-
|
|
8
|
+
interface SourceConfig {
|
|
9
9
|
entries?: Record<string, string | {
|
|
10
10
|
entry: string;
|
|
11
11
|
enableFileSystemRoutes?: boolean;
|
|
@@ -21,7 +21,7 @@ export interface SourceConfig {
|
|
|
21
21
|
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
22
22
|
include?: Array<string | RegExp>;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
interface OutputConfig {
|
|
25
25
|
assetPrefix?: string;
|
|
26
26
|
htmlPath?: string;
|
|
27
27
|
jsPath?: string;
|
|
@@ -60,7 +60,7 @@ export interface OutputConfig {
|
|
|
60
60
|
disableNodePolyfill?: boolean;
|
|
61
61
|
enableTsLoader?: boolean;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
interface ServerConfig {
|
|
64
64
|
routes?: Record<string, string | {
|
|
65
65
|
route: string | string[];
|
|
66
66
|
disableSpa?: boolean;
|
|
@@ -76,17 +76,17 @@ export interface ServerConfig {
|
|
|
76
76
|
metrics?: Record<string, any>;
|
|
77
77
|
enableMicroFrontendDebug?: boolean;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
interface DevConfig {
|
|
80
80
|
assetPrefix?: string | boolean;
|
|
81
81
|
https?: boolean;
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
interface DeployConfig {
|
|
84
84
|
microFrontend?: boolean & Record<string, unknown>;
|
|
85
85
|
domain?: string | Array<string>;
|
|
86
86
|
domainByEntries?: Record<string, string | Array<string>>;
|
|
87
87
|
}
|
|
88
88
|
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>) => Record<string, unknown> | void);
|
|
89
|
-
|
|
89
|
+
interface ToolsConfig {
|
|
90
90
|
webpack?: ConfigFunction;
|
|
91
91
|
babel?: ConfigFunction;
|
|
92
92
|
autoprefixer?: ConfigFunction;
|
|
@@ -98,11 +98,11 @@ export interface ToolsConfig {
|
|
|
98
98
|
minifyCss?: ConfigFunction;
|
|
99
99
|
esbuild?: Record<string, unknown>;
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
declare type RuntimeConfig = Record<string, any>;
|
|
102
|
+
interface RuntimeByEntriesConfig {
|
|
103
103
|
[name: string]: RuntimeConfig;
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
interface UserConfig {
|
|
106
106
|
source?: SourceConfig;
|
|
107
107
|
output?: OutputConfig;
|
|
108
108
|
server?: ServerConfig;
|
|
@@ -113,8 +113,8 @@ export interface UserConfig {
|
|
|
113
113
|
runtime?: RuntimeConfig;
|
|
114
114
|
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
115
115
|
}
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
117
|
+
interface LoadedConfig {
|
|
118
118
|
config: UserConfig;
|
|
119
119
|
filePath: string | false;
|
|
120
120
|
dependencies: string[];
|
|
@@ -122,5 +122,6 @@ export interface LoadedConfig {
|
|
|
122
122
|
jsConfig: UserConfig;
|
|
123
123
|
}
|
|
124
124
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
125
|
-
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined) => Promise<LoadedConfig>;
|
|
126
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[],
|
|
125
|
+
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
126
|
+
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[]) => Promise<NormalizedConfig>;
|
|
127
|
+
export type { SourceConfig, OutputConfig, ServerConfig, DevConfig, DeployConfig, ToolsConfig, RuntimeConfig, RuntimeByEntriesConfig, UserConfig, ConfigParam, LoadedConfig };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
|
2
2
|
import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners, AsyncWaterfall } from '@modern-js/plugin';
|
|
3
3
|
import type { Hooks } from '@modern-js/types';
|
|
4
4
|
import { Command } from './utils/commander';
|
|
5
|
-
import { defineConfig, loadUserConfig, UserConfig, ToolsConfig } from './config';
|
|
6
5
|
import { AppContext, ConfigContext, IAppContext, initAppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from './context';
|
|
7
6
|
import { NormalizedConfig } from './config/mergeConfig';
|
|
8
7
|
export type { Hooks };
|
|
9
|
-
export
|
|
8
|
+
export * from './config';
|
|
10
9
|
export * from '@modern-js/plugin';
|
|
11
10
|
export * from '@modern-js/plugin/node';
|
|
12
11
|
export declare type HooksRunner = Progresses2Runners<{
|
|
@@ -88,13 +87,14 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
88
87
|
beforeExit: AsyncWorkflow<void, void>;
|
|
89
88
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
|
|
90
89
|
export declare const usePlugins: (plugins: string[]) => void;
|
|
91
|
-
export {
|
|
92
|
-
export type { NormalizedConfig, IAppContext
|
|
93
|
-
declare const initAppDir: () => Promise<string>;
|
|
90
|
+
export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
|
|
91
|
+
export type { NormalizedConfig, IAppContext };
|
|
92
|
+
declare const initAppDir: (cwd?: string | undefined) => Promise<string>;
|
|
94
93
|
export interface CoreOptions {
|
|
95
94
|
configFile?: string;
|
|
95
|
+
packageJsonConfig?: string;
|
|
96
96
|
plugins?: typeof INTERNAL_PLUGINS;
|
|
97
|
-
beforeUsePlugins
|
|
97
|
+
beforeUsePlugins?: (plugins: any, config: any) => {
|
|
98
98
|
cli: any;
|
|
99
99
|
cliPath: any;
|
|
100
100
|
server: any;
|
|
@@ -110,4 +110,4 @@ export declare const cli: {
|
|
|
110
110
|
run: (argv: string[], options?: CoreOptions | undefined) => Promise<void>;
|
|
111
111
|
restart: () => Promise<void>;
|
|
112
112
|
};
|
|
113
|
-
export {
|
|
113
|
+
export { initAppDir, initAppContext };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
1
2
|
export interface PluginConfigItem {
|
|
2
3
|
cli?: string;
|
|
3
4
|
server?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare type PluginConfig = Array<PluginConfigItem>;
|
|
7
|
+
export declare function getAppPlugins(appDirectory: string, pluginConfig: PluginConfig, internalPlugins?: typeof INTERNAL_PLUGINS): {
|
|
8
|
+
cli?: string | undefined;
|
|
9
|
+
server?: string | undefined;
|
|
10
|
+
}[];
|
|
6
11
|
/**
|
|
7
12
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
8
13
|
* @param appDirectory - Application root directory.
|
package/jest.config.js
ADDED