@modern-js/core 1.4.4 → 1.5.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/.eslintrc.js +10 -0
- package/CHANGELOG.md +31 -0
- package/dist/js/modern/config/mergeConfig.js +8 -6
- package/dist/js/modern/config/schema/deploy.js +0 -3
- package/dist/js/modern/config/schema/server.js +2 -2
- package/dist/js/modern/context.js +18 -0
- package/dist/js/modern/index.js +9 -28
- package/dist/js/modern/loadPlugins.js +7 -12
- package/dist/js/modern/manager.js +28 -0
- package/dist/js/modern/pluginAPI.js +11 -0
- package/dist/js/node/config/mergeConfig.js +8 -6
- package/dist/js/node/config/schema/deploy.js +0 -3
- package/dist/js/node/config/schema/server.js +2 -2
- package/dist/js/node/context.js +22 -1
- package/dist/js/node/index.js +78 -67
- package/dist/js/node/loadPlugins.js +8 -12
- package/dist/js/node/manager.js +45 -0
- package/dist/js/node/pluginAPI.js +54 -0
- package/dist/types/config/index.d.ts +3 -3
- package/dist/types/config/schema/deploy.d.ts +0 -3
- package/dist/types/config/schema/index.d.ts +2 -5
- package/dist/types/config/schema/server.d.ts +2 -2
- package/dist/types/context.d.ts +18 -0
- package/dist/types/index.d.ts +6 -95
- package/dist/types/initWatcher.d.ts +1 -1
- package/dist/types/loadPlugins.d.ts +1 -4
- package/dist/types/manager.d.ts +74 -0
- package/dist/types/pluginAPI.d.ts +13 -0
- package/package.json +4 -4
- package/tests/loadPlugin.test.ts +4 -33
- package/tests/mergeConfig.test.ts +22 -3
- package/tests/pluginAPI.test.ts +19 -0
- package/tests/schema.test.ts +2 -4
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
extends: ['@modern-js'],
|
|
4
|
+
parserOptions: {
|
|
5
|
+
// the base path used to search for `tsconfig.json`
|
|
6
|
+
tsconfigRootDir: __dirname,
|
|
7
|
+
// the relative path to sub-package's `tsconfig.json`
|
|
8
|
+
project: ['./tsconfig.json'],
|
|
9
|
+
},
|
|
10
|
+
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 80d8ddfe: feat: add `CliPlugin` type to define new plugin
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 80d3cfb7: fix: server.metrics type
|
|
12
|
+
- 42c6b136: feat: support api.setAppContext
|
|
13
|
+
- 4e7dcbd5: fix: server.logger type
|
|
14
|
+
- 9e8bc4ab: fix: server.routes type
|
|
15
|
+
- 0c556e59: fix: tools.less type
|
|
16
|
+
- 2008fdbd: convert two packages server part, support server load plugin itself
|
|
17
|
+
- Updated dependencies [5bf5868d]
|
|
18
|
+
- Updated dependencies [80d8ddfe]
|
|
19
|
+
- Updated dependencies [491145e3]
|
|
20
|
+
- @modern-js/utils@1.3.5
|
|
21
|
+
- @modern-js/plugin@1.3.0
|
|
22
|
+
|
|
23
|
+
## 1.4.6
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- cc5e8001: fix: load plugins
|
|
28
|
+
- 2520ea86: fix: garfish schema
|
|
29
|
+
- e81fd9b7: fix: update "server.metrics" type
|
|
30
|
+
- 1c411e71: fix: mergeConfig util function
|
|
31
|
+
- Updated dependencies [db43dce6]
|
|
32
|
+
- @modern-js/utils@1.3.4
|
|
33
|
+
|
|
3
34
|
## 1.4.4
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
|
@@ -8,12 +8,14 @@ import { isFunction } from '@modern-js/utils';
|
|
|
8
8
|
* @returns - normalized user config.
|
|
9
9
|
*/
|
|
10
10
|
export const mergeConfig = configs => mergeWith({}, ...configs, (target, source) => {
|
|
11
|
-
if (Array.isArray(target)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
if (Array.isArray(target)) {
|
|
12
|
+
if (Array.isArray(source)) {
|
|
13
|
+
return [...target, ...source];
|
|
14
|
+
} else {
|
|
15
|
+
return typeof source !== 'undefined' ? [...target, source] : target;
|
|
16
|
+
}
|
|
17
|
+
} else if (isFunction(source)) {
|
|
18
|
+
return typeof target !== 'undefined' ? [target, source] : [source];
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
return undefined;
|
|
@@ -4,8 +4,26 @@ import address from 'address';
|
|
|
4
4
|
export const AppContext = createContext({});
|
|
5
5
|
export const ConfigContext = createContext({});
|
|
6
6
|
export const ResolvedConfigContext = createContext({});
|
|
7
|
+
/**
|
|
8
|
+
* Set app context.
|
|
9
|
+
* @param value new app context. It will override previous app context.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const setAppContext = value => AppContext.set(value);
|
|
13
|
+
/**
|
|
14
|
+
* Get app context, including directories, plugins and some static infos.
|
|
15
|
+
*/
|
|
16
|
+
|
|
7
17
|
export const useAppContext = () => AppContext.use().value;
|
|
18
|
+
/**
|
|
19
|
+
* Get original content of user config.
|
|
20
|
+
*/
|
|
21
|
+
|
|
8
22
|
export const useConfigContext = () => ConfigContext.use().value;
|
|
23
|
+
/**
|
|
24
|
+
* Get normalized content of user config.
|
|
25
|
+
*/
|
|
26
|
+
|
|
9
27
|
export const useResolvedConfigContext = () => ResolvedConfigContext.use().value;
|
|
10
28
|
export const initAppContext = (appDirectory, plugins, configFile, options) => {
|
|
11
29
|
const {
|
package/dist/js/modern/index.js
CHANGED
|
@@ -5,41 +5,23 @@ 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 {
|
|
9
|
-
import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow, createAsyncWaterfall } from '@modern-js/plugin';
|
|
8
|
+
import { pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
|
|
10
9
|
import { enable } from '@modern-js/plugin/node';
|
|
11
10
|
import { program } from "./utils/commander";
|
|
12
11
|
import { resolveConfig, loadUserConfig } from "./config";
|
|
13
12
|
import { loadPlugins } from "./loadPlugins";
|
|
14
|
-
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext
|
|
13
|
+
import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext } from "./context";
|
|
15
14
|
import { initWatcher } from "./initWatcher";
|
|
16
15
|
import { loadEnv } from "./loadEnv";
|
|
16
|
+
import { manager } from "./manager";
|
|
17
17
|
export * from "./config";
|
|
18
18
|
export * from '@modern-js/plugin';
|
|
19
|
-
export * from '@modern-js/plugin/node';
|
|
19
|
+
export * from '@modern-js/plugin/node'; // TODO: remove export after refactor all plugins
|
|
20
|
+
|
|
21
|
+
export { manager, mountHook, usePlugins, createPlugin, registerHook } from "./manager";
|
|
22
|
+
// TODO: remove export after refactor all plugins
|
|
23
|
+
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext } from "./pluginAPI";
|
|
20
24
|
program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
21
|
-
const hooksMap = {
|
|
22
|
-
config: createParallelWorkflow(),
|
|
23
|
-
resolvedConfig: createAsyncWaterfall(),
|
|
24
|
-
validateSchema: createParallelWorkflow(),
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
26
|
-
prepare: createAsyncWorkflow(),
|
|
27
|
-
commands: createAsyncWorkflow(),
|
|
28
|
-
watchFiles: createParallelWorkflow(),
|
|
29
|
-
fileChange: createAsyncWorkflow(),
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
31
|
-
beforeExit: createAsyncWorkflow(),
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
33
|
-
beforeRestart: createAsyncWorkflow()
|
|
34
|
-
};
|
|
35
|
-
export const manager = createAsyncManager(hooksMap);
|
|
36
|
-
export const {
|
|
37
|
-
createPlugin,
|
|
38
|
-
registe: registerHook,
|
|
39
|
-
useRunner: mountHook
|
|
40
|
-
} = manager;
|
|
41
|
-
export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(require.resolve(plugin))));
|
|
42
|
-
export { AppContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, ConfigContext };
|
|
43
25
|
|
|
44
26
|
const initAppDir = async cwd => {
|
|
45
27
|
if (!cwd) {
|
|
@@ -75,8 +57,7 @@ const createCli = () => {
|
|
|
75
57
|
loadEnv(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
76
58
|
const loaded = await loadUserConfig(appDirectory, options === null || options === void 0 ? void 0 : options.configFile, options === null || options === void 0 ? void 0 : options.packageJsonConfig);
|
|
77
59
|
const plugins = loadPlugins(appDirectory, loaded.config, {
|
|
78
|
-
internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
|
|
79
|
-
transformPlugin: options === null || options === void 0 ? void 0 : options.transformPlugin
|
|
60
|
+
internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
|
|
80
61
|
});
|
|
81
62
|
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
82
63
|
const appContext = initAppContext(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
@@ -5,6 +5,7 @@ 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 { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
8
|
+
import { createPlugin } from "./manager";
|
|
8
9
|
const debug = createDebugger('load-plugins');
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -51,14 +52,12 @@ export function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
|
51
52
|
* @param appDirectory - Application root directory.
|
|
52
53
|
* @param userConfig - Resolved user config.
|
|
53
54
|
* @param options.internalPlugins - Internal plugins.
|
|
54
|
-
* @param options.transformPlugin - transform plugin before using it.
|
|
55
55
|
* @returns Plugin Objects has been required.
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
58
|
export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
59
59
|
const {
|
|
60
|
-
internalPlugins
|
|
61
|
-
transformPlugin
|
|
60
|
+
internalPlugins
|
|
62
61
|
} = options;
|
|
63
62
|
|
|
64
63
|
const resolvePlugin = p => {
|
|
@@ -67,10 +66,9 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
67
66
|
let module = compatRequire(path);
|
|
68
67
|
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
69
68
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
module = typeof module === 'function' ? module(pluginOptions) : module;
|
|
69
|
+
if (typeof module === 'function') {
|
|
70
|
+
const plugin = module(pluginOptions);
|
|
71
|
+
module = createPlugin(plugin.setup, plugin);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
return {
|
|
@@ -82,7 +80,7 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
82
80
|
|
|
83
81
|
const plugins = getAppPlugins(appDirectory, userConfig.plugins || [], internalPlugins);
|
|
84
82
|
return plugins.map(plugin => {
|
|
85
|
-
const _plugin = typeof plugin === 'string' ? {
|
|
83
|
+
const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
|
|
86
84
|
cli: plugin
|
|
87
85
|
} : plugin;
|
|
88
86
|
|
|
@@ -106,10 +104,7 @@ export const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
106
104
|
|
|
107
105
|
|
|
108
106
|
if (server && typeof server === 'string') {
|
|
109
|
-
|
|
110
|
-
loadedPlugin.server = {
|
|
111
|
-
pluginPath: path
|
|
112
|
-
};
|
|
107
|
+
loadedPlugin.server = server;
|
|
113
108
|
loadedPlugin.serverPkg = server;
|
|
114
109
|
}
|
|
115
110
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createAsyncManager, createAsyncWorkflow, createAsyncWaterfall, createParallelWorkflow } from '@modern-js/plugin';
|
|
2
|
+
import { compatRequire } from '@modern-js/utils';
|
|
3
|
+
import { pluginAPI } from "./pluginAPI";
|
|
4
|
+
const baseHooks = {
|
|
5
|
+
config: createParallelWorkflow(),
|
|
6
|
+
resolvedConfig: createAsyncWaterfall(),
|
|
7
|
+
validateSchema: createParallelWorkflow(),
|
|
8
|
+
prepare: createAsyncWorkflow(),
|
|
9
|
+
commands: createAsyncWorkflow(),
|
|
10
|
+
watchFiles: createParallelWorkflow(),
|
|
11
|
+
fileChange: createAsyncWorkflow(),
|
|
12
|
+
beforeExit: createAsyncWorkflow(),
|
|
13
|
+
beforeRestart: createAsyncWorkflow()
|
|
14
|
+
};
|
|
15
|
+
/** All hooks of cli plugin. */
|
|
16
|
+
|
|
17
|
+
export const manager = createAsyncManager(baseHooks, pluginAPI);
|
|
18
|
+
/** Plugin options of a cli plugin. */
|
|
19
|
+
|
|
20
|
+
export const {
|
|
21
|
+
createPlugin,
|
|
22
|
+
registerHook,
|
|
23
|
+
useRunner: mountHook
|
|
24
|
+
} = manager;
|
|
25
|
+
export const usePlugins = plugins => plugins.forEach(pluginPath => {
|
|
26
|
+
const module = compatRequire(require.resolve(pluginPath));
|
|
27
|
+
manager.usePlugin(module);
|
|
28
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AppContext, ConfigContext, setAppContext, useAppContext, useConfigContext, ResolvedConfigContext, useResolvedConfigContext } from "./context";
|
|
2
|
+
export const pluginAPI = {
|
|
3
|
+
setAppContext,
|
|
4
|
+
useAppContext,
|
|
5
|
+
useConfigContext,
|
|
6
|
+
useResolvedConfigContext
|
|
7
|
+
};
|
|
8
|
+
/** all apis for cli plugin */
|
|
9
|
+
|
|
10
|
+
// TODO: only export types after refactor all plugins
|
|
11
|
+
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext };
|
|
@@ -18,12 +18,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
* @returns - normalized user config.
|
|
19
19
|
*/
|
|
20
20
|
const mergeConfig = configs => (0, _lodash.default)({}, ...configs, (target, source) => {
|
|
21
|
-
if (Array.isArray(target)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
if (Array.isArray(target)) {
|
|
22
|
+
if (Array.isArray(source)) {
|
|
23
|
+
return [...target, ...source];
|
|
24
|
+
} else {
|
|
25
|
+
return typeof source !== 'undefined' ? [...target, source] : target;
|
|
26
|
+
}
|
|
27
|
+
} else if ((0, _utils.isFunction)(source)) {
|
|
28
|
+
return typeof target !== 'undefined' ? [target, source] : [source];
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
return undefined;
|
package/dist/js/node/context.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.initAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
|
|
6
|
+
exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.initAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
|
|
7
7
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
|
@@ -18,13 +18,34 @@ exports.AppContext = AppContext;
|
|
|
18
18
|
const ConfigContext = (0, _plugin.createContext)({});
|
|
19
19
|
exports.ConfigContext = ConfigContext;
|
|
20
20
|
const ResolvedConfigContext = (0, _plugin.createContext)({});
|
|
21
|
+
/**
|
|
22
|
+
* Set app context.
|
|
23
|
+
* @param value new app context. It will override previous app context.
|
|
24
|
+
*/
|
|
25
|
+
|
|
21
26
|
exports.ResolvedConfigContext = ResolvedConfigContext;
|
|
22
27
|
|
|
28
|
+
const setAppContext = value => AppContext.set(value);
|
|
29
|
+
/**
|
|
30
|
+
* Get app context, including directories, plugins and some static infos.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
exports.setAppContext = setAppContext;
|
|
35
|
+
|
|
23
36
|
const useAppContext = () => AppContext.use().value;
|
|
37
|
+
/**
|
|
38
|
+
* Get original content of user config.
|
|
39
|
+
*/
|
|
40
|
+
|
|
24
41
|
|
|
25
42
|
exports.useAppContext = useAppContext;
|
|
26
43
|
|
|
27
44
|
const useConfigContext = () => ConfigContext.use().value;
|
|
45
|
+
/**
|
|
46
|
+
* Get normalized content of user config.
|
|
47
|
+
*/
|
|
48
|
+
|
|
28
49
|
|
|
29
50
|
exports.useConfigContext = useConfigContext;
|
|
30
51
|
|
package/dist/js/node/index.js
CHANGED
|
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
cli: true,
|
|
8
|
+
initAppDir: true,
|
|
9
|
+
initAppContext: true,
|
|
7
10
|
manager: true,
|
|
8
|
-
createPlugin: true,
|
|
9
|
-
registerHook: true,
|
|
10
11
|
mountHook: true,
|
|
11
12
|
usePlugins: true,
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
createPlugin: true,
|
|
14
|
+
registerHook: true,
|
|
14
15
|
AppContext: true,
|
|
15
16
|
ConfigContext: true,
|
|
16
|
-
initAppContext: true,
|
|
17
17
|
ResolvedConfigContext: true,
|
|
18
18
|
useAppContext: true,
|
|
19
19
|
useConfigContext: true,
|
|
@@ -22,46 +22,75 @@ var _exportNames = {
|
|
|
22
22
|
Object.defineProperty(exports, "AppContext", {
|
|
23
23
|
enumerable: true,
|
|
24
24
|
get: function () {
|
|
25
|
-
return
|
|
25
|
+
return _pluginAPI.AppContext;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "ConfigContext", {
|
|
29
29
|
enumerable: true,
|
|
30
30
|
get: function () {
|
|
31
|
-
return
|
|
31
|
+
return _pluginAPI.ConfigContext;
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
Object.defineProperty(exports, "ResolvedConfigContext", {
|
|
35
35
|
enumerable: true,
|
|
36
36
|
get: function () {
|
|
37
|
-
return
|
|
37
|
+
return _pluginAPI.ResolvedConfigContext;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.cli = void 0;
|
|
41
|
+
Object.defineProperty(exports, "createPlugin", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return _manager.createPlugin;
|
|
38
45
|
}
|
|
39
46
|
});
|
|
40
|
-
exports.createPlugin = exports.cli = void 0;
|
|
41
47
|
Object.defineProperty(exports, "initAppContext", {
|
|
42
48
|
enumerable: true,
|
|
43
49
|
get: function () {
|
|
44
50
|
return _context.initAppContext;
|
|
45
51
|
}
|
|
46
52
|
});
|
|
47
|
-
exports.
|
|
53
|
+
exports.initAppDir = void 0;
|
|
54
|
+
Object.defineProperty(exports, "manager", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _manager.manager;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "mountHook", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _manager.mountHook;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "registerHook", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _manager.registerHook;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
48
72
|
Object.defineProperty(exports, "useAppContext", {
|
|
49
73
|
enumerable: true,
|
|
50
74
|
get: function () {
|
|
51
|
-
return
|
|
75
|
+
return _pluginAPI.useAppContext;
|
|
52
76
|
}
|
|
53
77
|
});
|
|
54
78
|
Object.defineProperty(exports, "useConfigContext", {
|
|
55
79
|
enumerable: true,
|
|
56
80
|
get: function () {
|
|
57
|
-
return
|
|
81
|
+
return _pluginAPI.useConfigContext;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "usePlugins", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _manager.usePlugins;
|
|
58
88
|
}
|
|
59
89
|
});
|
|
60
|
-
exports.usePlugins = void 0;
|
|
61
90
|
Object.defineProperty(exports, "useResolvedConfigContext", {
|
|
62
91
|
enumerable: true,
|
|
63
92
|
get: function () {
|
|
64
|
-
return
|
|
93
|
+
return _pluginAPI.useResolvedConfigContext;
|
|
65
94
|
}
|
|
66
95
|
});
|
|
67
96
|
|
|
@@ -69,20 +98,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
69
98
|
|
|
70
99
|
var _utils = require("@modern-js/utils");
|
|
71
100
|
|
|
72
|
-
var _plugin = require("@modern-js/plugin");
|
|
73
|
-
|
|
74
|
-
Object.keys(_plugin).forEach(function (key) {
|
|
75
|
-
if (key === "default" || key === "__esModule") return;
|
|
76
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
77
|
-
if (key in exports && exports[key] === _plugin[key]) return;
|
|
78
|
-
Object.defineProperty(exports, key, {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return _plugin[key];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
101
|
var _node = require("@modern-js/plugin/node");
|
|
87
102
|
|
|
88
103
|
Object.keys(_node).forEach(function (key) {
|
|
@@ -121,6 +136,24 @@ var _initWatcher = require("./initWatcher");
|
|
|
121
136
|
|
|
122
137
|
var _loadEnv = require("./loadEnv");
|
|
123
138
|
|
|
139
|
+
var _manager = require("./manager");
|
|
140
|
+
|
|
141
|
+
var _plugin = require("@modern-js/plugin");
|
|
142
|
+
|
|
143
|
+
Object.keys(_plugin).forEach(function (key) {
|
|
144
|
+
if (key === "default" || key === "__esModule") return;
|
|
145
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
146
|
+
if (key in exports && exports[key] === _plugin[key]) return;
|
|
147
|
+
Object.defineProperty(exports, key, {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () {
|
|
150
|
+
return _plugin[key];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
var _pluginAPI = require("./pluginAPI");
|
|
156
|
+
|
|
124
157
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
125
158
|
|
|
126
159
|
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; }
|
|
@@ -131,35 +164,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
131
164
|
|
|
132
165
|
_commander.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
133
166
|
|
|
134
|
-
const hooksMap = {
|
|
135
|
-
config: (0, _plugin.createParallelWorkflow)(),
|
|
136
|
-
resolvedConfig: (0, _plugin.createAsyncWaterfall)(),
|
|
137
|
-
validateSchema: (0, _plugin.createParallelWorkflow)(),
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
139
|
-
prepare: (0, _plugin.createAsyncWorkflow)(),
|
|
140
|
-
commands: (0, _plugin.createAsyncWorkflow)(),
|
|
141
|
-
watchFiles: (0, _plugin.createParallelWorkflow)(),
|
|
142
|
-
fileChange: (0, _plugin.createAsyncWorkflow)(),
|
|
143
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
144
|
-
beforeExit: (0, _plugin.createAsyncWorkflow)(),
|
|
145
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
146
|
-
beforeRestart: (0, _plugin.createAsyncWorkflow)()
|
|
147
|
-
};
|
|
148
|
-
const manager = (0, _plugin.createAsyncManager)(hooksMap);
|
|
149
|
-
exports.manager = manager;
|
|
150
|
-
const {
|
|
151
|
-
createPlugin,
|
|
152
|
-
registe: registerHook,
|
|
153
|
-
useRunner: mountHook
|
|
154
|
-
} = manager;
|
|
155
|
-
exports.mountHook = mountHook;
|
|
156
|
-
exports.registerHook = registerHook;
|
|
157
|
-
exports.createPlugin = createPlugin;
|
|
158
|
-
|
|
159
|
-
const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(require.resolve(plugin))));
|
|
160
|
-
|
|
161
|
-
exports.usePlugins = usePlugins;
|
|
162
|
-
|
|
163
167
|
const initAppDir = async cwd => {
|
|
164
168
|
if (!cwd) {
|
|
165
169
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -189,24 +193,27 @@ const createCli = () => {
|
|
|
189
193
|
var _options$options$meta, _options$options;
|
|
190
194
|
|
|
191
195
|
(0, _node.enable)();
|
|
192
|
-
|
|
196
|
+
|
|
197
|
+
_manager.manager.clear();
|
|
198
|
+
|
|
193
199
|
restartOptions = options;
|
|
194
200
|
const appDirectory = await initAppDir();
|
|
195
201
|
const metaName = (_options$options$meta = options === null || options === void 0 ? void 0 : (_options$options = options.options) === null || _options$options === void 0 ? void 0 : _options$options.metaName) !== null && _options$options$meta !== void 0 ? _options$options$meta : 'MODERN';
|
|
196
202
|
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
197
203
|
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);
|
|
198
204
|
const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
|
|
199
|
-
internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
|
|
200
|
-
transformPlugin: options === null || options === void 0 ? void 0 : options.transformPlugin
|
|
205
|
+
internalPlugins: options === null || options === void 0 ? void 0 : options.plugins
|
|
201
206
|
});
|
|
202
|
-
plugins.forEach(plugin => plugin.cli && manager.usePlugin(plugin.cli));
|
|
207
|
+
plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
|
|
203
208
|
const appContext = (0, _context.initAppContext)(appDirectory, plugins, loaded.filePath, options === null || options === void 0 ? void 0 : options.options);
|
|
204
|
-
|
|
209
|
+
|
|
210
|
+
_manager.manager.run(() => {
|
|
205
211
|
_context.ConfigContext.set(loaded.config);
|
|
206
212
|
|
|
207
213
|
_context.AppContext.set(appContext);
|
|
208
214
|
});
|
|
209
|
-
|
|
215
|
+
|
|
216
|
+
hooksRunner = await _manager.manager.init();
|
|
210
217
|
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
211
218
|
process.on(event, async err => {
|
|
212
219
|
await hooksRunner.beforeExit();
|
|
@@ -230,7 +237,7 @@ const createCli = () => {
|
|
|
230
237
|
resolved: config
|
|
231
238
|
}); // update context value
|
|
232
239
|
|
|
233
|
-
manager.run(() => {
|
|
240
|
+
_manager.manager.run(() => {
|
|
234
241
|
_context.ConfigContext.set(loaded.config);
|
|
235
242
|
|
|
236
243
|
_context.ResolvedConfigContext.set(resolved);
|
|
@@ -240,6 +247,7 @@ const createCli = () => {
|
|
|
240
247
|
distDirectory: (0, _utils.ensureAbsolutePath)(appDirectory, resolved.output.path)
|
|
241
248
|
}));
|
|
242
249
|
});
|
|
250
|
+
|
|
243
251
|
await hooksRunner.prepare();
|
|
244
252
|
return {
|
|
245
253
|
loadedConfig: loaded,
|
|
@@ -258,7 +266,8 @@ const createCli = () => {
|
|
|
258
266
|
program: _commander.program
|
|
259
267
|
});
|
|
260
268
|
(0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
261
|
-
|
|
269
|
+
|
|
270
|
+
_manager.manager.run(() => _commander.program.parse(process.argv));
|
|
262
271
|
}
|
|
263
272
|
|
|
264
273
|
async function restart() {
|
|
@@ -270,7 +279,9 @@ const createCli = () => {
|
|
|
270
279
|
_utils.logger.info('Restart...\n');
|
|
271
280
|
|
|
272
281
|
let hasGetError = false;
|
|
273
|
-
|
|
282
|
+
|
|
283
|
+
const runner = _manager.manager.useRunner();
|
|
284
|
+
|
|
274
285
|
await runner.beforeRestart();
|
|
275
286
|
|
|
276
287
|
try {
|
|
@@ -280,7 +291,7 @@ const createCli = () => {
|
|
|
280
291
|
hasGetError = true;
|
|
281
292
|
} finally {
|
|
282
293
|
if (!hasGetError) {
|
|
283
|
-
manager.run(() => _commander.program.parse(process.argv));
|
|
294
|
+
_manager.manager.run(() => _commander.program.parse(process.argv));
|
|
284
295
|
}
|
|
285
296
|
}
|
|
286
297
|
}
|