@modern-js/core 2.10.0 → 2.11.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 +23 -0
- package/dist/config/createLoadedConfig.d.ts +1 -1
- package/dist/config/createLoadedConfig.js +2 -2
- package/dist/config/loadConfig.d.ts +1 -1
- package/dist/config/loadConfig.js +5 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.js +14 -2
- package/dist/manager.d.ts +6 -6
- package/dist/manager.js +1 -1
- package/dist/node-api.d.ts +4 -0
- package/dist/node-api.js +16 -0
- package/dist/types/hooks.d.ts +2 -2
- package/package.json +17 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 2.11.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0bd018b: feat: support use node api run dev & build & deploy command
|
|
8
|
+
feat: 支持通过 node api 运行 dev & build & deploy 命令
|
|
9
|
+
- 7178795: fix(core): beforeExit should be sync workflow
|
|
10
|
+
|
|
11
|
+
fix(core): beforeExit 需要使用同步的 workflow
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [cfb058f]
|
|
14
|
+
- Updated dependencies [0bd018b]
|
|
15
|
+
- Updated dependencies [5d624fd]
|
|
16
|
+
- Updated dependencies [e2466a1]
|
|
17
|
+
- Updated dependencies [02bb383]
|
|
18
|
+
- Updated dependencies [381a3b9]
|
|
19
|
+
- Updated dependencies [7a60f10]
|
|
20
|
+
- Updated dependencies [274b2e5]
|
|
21
|
+
- Updated dependencies [b9e1c54]
|
|
22
|
+
- @modern-js/utils@2.11.0
|
|
23
|
+
- @modern-js/node-bundle-require@2.11.0
|
|
24
|
+
- @modern-js/plugin@2.11.0
|
|
25
|
+
|
|
3
26
|
## 2.10.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
|
@@ -3,4 +3,4 @@ import { LoadedConfig, UserConfig } from '../types';
|
|
|
3
3
|
* Assign the pkg config into the user config.
|
|
4
4
|
*/
|
|
5
5
|
export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: UserConfig) => UserConfig;
|
|
6
|
-
export declare function createLoadedConfig(appDirectory: string, filePath?: string, packageJsonConfig?: string): Promise<LoadedConfig<{}>>;
|
|
6
|
+
export declare function createLoadedConfig(appDirectory: string, filePath?: string, packageJsonConfig?: string, loadedConfig?: UserConfig): Promise<LoadedConfig<{}>>;
|
|
@@ -53,9 +53,9 @@ async function loadLocalConfig(appDirectory, configFile) {
|
|
|
53
53
|
}
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
56
|
-
async function createLoadedConfig(appDirectory, filePath, packageJsonConfig) {
|
|
56
|
+
async function createLoadedConfig(appDirectory, filePath, packageJsonConfig, loadedConfig) {
|
|
57
57
|
const configFile = (0, loadConfig_1.getConfigFilePath)(appDirectory, filePath);
|
|
58
|
-
const loaded = await (0, loadConfig_1.loadConfig)(appDirectory, configFile, packageJsonConfig);
|
|
58
|
+
const loaded = await (0, loadConfig_1.loadConfig)(appDirectory, configFile, packageJsonConfig, loadedConfig);
|
|
59
59
|
if (!loaded.config && !loaded.pkgConfig) {
|
|
60
60
|
utils_1.logger.warn(`Can not find any config file in the current project, please check if you have a correct config file.`);
|
|
61
61
|
utils_1.logger.warn(`Current project path: ${utils_1.chalk.yellow(appDirectory)}`);
|
|
@@ -27,7 +27,7 @@ export declare const getConfigFilePath: (appDirectory: string, filePath?: string
|
|
|
27
27
|
* @param configFile - Specific absolute config file path.
|
|
28
28
|
* @returns Object contain config file path, user config object and dependency files used by config file.
|
|
29
29
|
*/
|
|
30
|
-
export declare const loadConfig: <T>(appDirectory: string, configFile: string | false, packageJsonConfig?: string) => Promise<{
|
|
30
|
+
export declare const loadConfig: <T>(appDirectory: string, configFile: string | false, packageJsonConfig?: string, loadedConfig?: T | undefined) => Promise<{
|
|
31
31
|
path: string | false;
|
|
32
32
|
config?: T | undefined;
|
|
33
33
|
dependencies?: string[] | undefined;
|
|
@@ -101,13 +101,16 @@ exports.getConfigFilePath = getConfigFilePath;
|
|
|
101
101
|
* @param configFile - Specific absolute config file path.
|
|
102
102
|
* @returns Object contain config file path, user config object and dependency files used by config file.
|
|
103
103
|
*/
|
|
104
|
-
const loadConfig = async (appDirectory, configFile, packageJsonConfig) => {
|
|
104
|
+
const loadConfig = async (appDirectory, configFile, packageJsonConfig, loadedConfig) => {
|
|
105
105
|
const pkgConfig = (0, exports.getPackageConfig)(appDirectory, packageJsonConfig);
|
|
106
106
|
let config;
|
|
107
107
|
const dependencies = pkgConfig
|
|
108
108
|
? [path_1.default.resolve(appDirectory, './package.json')]
|
|
109
109
|
: [];
|
|
110
|
-
if (
|
|
110
|
+
if (loadedConfig) {
|
|
111
|
+
config = loadedConfig;
|
|
112
|
+
}
|
|
113
|
+
else if (configFile) {
|
|
111
114
|
delete require.cache[configFile];
|
|
112
115
|
const mod = await bundleRequireWithCatch(configFile, { appDirectory });
|
|
113
116
|
config = mod.default || mod;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ErrorObject } from '@modern-js/utils/ajv';
|
|
2
2
|
import { InternalPlugins } from '@modern-js/types';
|
|
3
3
|
import { initAppContext } from './context';
|
|
4
|
-
import type { ToolsType } from './types';
|
|
4
|
+
import type { ToolsType, UserConfig } from './types';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from '@modern-js/plugin';
|
|
7
7
|
export { manager, createPlugin, registerHook } from './manager';
|
|
@@ -28,6 +28,8 @@ export interface CoreOptions {
|
|
|
28
28
|
toolsType?: ToolsType;
|
|
29
29
|
/** force the modern-js core auto register plugin exist in the package.json */
|
|
30
30
|
forceAutoLoadPlugins?: boolean;
|
|
31
|
+
/** config for Node API */
|
|
32
|
+
loadedConfig?: UserConfig;
|
|
31
33
|
}
|
|
32
34
|
export declare const mergeOptions: (options?: CoreOptions) => {
|
|
33
35
|
cwd?: string | undefined;
|
|
@@ -49,6 +51,7 @@ export declare const mergeOptions: (options?: CoreOptions) => {
|
|
|
49
51
|
} | undefined;
|
|
50
52
|
toolsType?: ToolsType | undefined;
|
|
51
53
|
forceAutoLoadPlugins?: boolean | undefined;
|
|
54
|
+
loadedConfig?: UserConfig<{}, {}, {}, {}> | undefined;
|
|
52
55
|
};
|
|
53
56
|
export declare const cli: {
|
|
54
57
|
init: (options?: CoreOptions) => Promise<{
|
|
@@ -60,6 +63,7 @@ export declare const cli: {
|
|
|
60
63
|
coreOptions?: CoreOptions;
|
|
61
64
|
disableWatcher?: boolean;
|
|
62
65
|
}) => Promise<void>;
|
|
66
|
+
runCommand: (command: string, commandOptions?: string[], options?: CoreOptions) => Promise<void>;
|
|
63
67
|
getPrevInitOptions: () => CoreOptions | undefined;
|
|
64
68
|
};
|
|
65
69
|
export { initAppDir, initAppContext };
|
package/dist/index.js
CHANGED
|
@@ -79,7 +79,7 @@ const createCli = () => {
|
|
|
79
79
|
setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
|
|
80
80
|
const metaName = (_b = (_a = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options) === null || _a === void 0 ? void 0 : _a.metaName) !== null && _b !== void 0 ? _b : 'MODERN';
|
|
81
81
|
(0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
82
|
-
const loaded = await (0, config_1.createLoadedConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
82
|
+
const loaded = await (0, config_1.createLoadedConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.loadedConfig);
|
|
83
83
|
const plugins = await (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
|
|
84
84
|
internalPlugins: (_c = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _c === void 0 ? void 0 : _c.cli,
|
|
85
85
|
autoLoad: (_d = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _d === void 0 ? void 0 : _d.autoLoad,
|
|
@@ -101,7 +101,7 @@ const createCli = () => {
|
|
|
101
101
|
hooksRunner = await manager_1.manager.init();
|
|
102
102
|
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
103
103
|
process.on(event, async (err) => {
|
|
104
|
-
|
|
104
|
+
hooksRunner.beforeExit();
|
|
105
105
|
if (err instanceof Error) {
|
|
106
106
|
utils_1.logger.error(err.stack);
|
|
107
107
|
}
|
|
@@ -137,6 +137,17 @@ const createCli = () => {
|
|
|
137
137
|
utils_1.logger.warn('No command found, please make sure you have registered plugins correctly.');
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
async function runCommand(command, commandOptions = [], options) {
|
|
141
|
+
const argv = process.argv
|
|
142
|
+
.slice(0, 2)
|
|
143
|
+
.concat(command)
|
|
144
|
+
.concat(commandOptions);
|
|
145
|
+
process.env.MODERN_ARGV = argv.join(' ');
|
|
146
|
+
const { appContext } = await init(options);
|
|
147
|
+
await hooksRunner.commands({ program: utils_1.program });
|
|
148
|
+
await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
|
|
149
|
+
utils_1.program.parse(argv);
|
|
150
|
+
}
|
|
140
151
|
async function test(argv, options) {
|
|
141
152
|
const newProgram = new utils_1.Command();
|
|
142
153
|
const { coreOptions } = options !== null && options !== void 0 ? options : {};
|
|
@@ -148,6 +159,7 @@ const createCli = () => {
|
|
|
148
159
|
init,
|
|
149
160
|
run,
|
|
150
161
|
test,
|
|
162
|
+
runCommand,
|
|
151
163
|
getPrevInitOptions: () => initOptions,
|
|
152
164
|
};
|
|
153
165
|
};
|
package/dist/manager.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const manager: import("@modern-js/plugin").AsyncManager<{
|
|
|
15
15
|
commands: import("@modern-js/plugin").AsyncWorkflow<{
|
|
16
16
|
program: import("@modern-js/utils").Command;
|
|
17
17
|
}, void>;
|
|
18
|
-
beforeExit: import("@modern-js/plugin").
|
|
18
|
+
beforeExit: import("@modern-js/plugin").Workflow<void, void>;
|
|
19
19
|
addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
20
20
|
}, BasePluginAPI<{}, {}, {}, {}>>;
|
|
21
21
|
export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSetup<{
|
|
@@ -34,7 +34,7 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
|
|
|
34
34
|
commands: import("@modern-js/plugin").AsyncWorkflow<{
|
|
35
35
|
program: import("@modern-js/utils").Command;
|
|
36
36
|
}, void>;
|
|
37
|
-
beforeExit: import("@modern-js/plugin").
|
|
37
|
+
beforeExit: import("@modern-js/plugin").Workflow<void, void>;
|
|
38
38
|
addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
39
39
|
}, BasePluginAPI<{}, {}, {}, {}>> | undefined, options?: import("@modern-js/plugin").PluginOptions<{
|
|
40
40
|
config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
|
|
@@ -52,7 +52,7 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
|
|
|
52
52
|
commands: import("@modern-js/plugin").AsyncWorkflow<{
|
|
53
53
|
program: import("@modern-js/utils").Command;
|
|
54
54
|
}, void>;
|
|
55
|
-
beforeExit: import("@modern-js/plugin").
|
|
55
|
+
beforeExit: import("@modern-js/plugin").Workflow<void, void>;
|
|
56
56
|
addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
57
57
|
}, import("@modern-js/plugin").AsyncSetup<{
|
|
58
58
|
config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
|
|
@@ -70,7 +70,7 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
|
|
|
70
70
|
commands: import("@modern-js/plugin").AsyncWorkflow<{
|
|
71
71
|
program: import("@modern-js/utils").Command;
|
|
72
72
|
}, void>;
|
|
73
|
-
beforeExit: import("@modern-js/plugin").
|
|
73
|
+
beforeExit: import("@modern-js/plugin").Workflow<void, void>;
|
|
74
74
|
addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
75
75
|
}, BasePluginAPI<{}, {}, {}, {}>>, Record<string, unknown>> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
|
|
76
76
|
config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
|
|
@@ -88,7 +88,7 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
|
|
|
88
88
|
commands: import("@modern-js/plugin").AsyncWorkflow<{
|
|
89
89
|
program: import("@modern-js/utils").Command;
|
|
90
90
|
}, void>;
|
|
91
|
-
beforeExit: import("@modern-js/plugin").
|
|
91
|
+
beforeExit: import("@modern-js/plugin").Workflow<void, void>;
|
|
92
92
|
addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
93
93
|
}, BasePluginAPI<{}, {}, {}, {}>>, registerHook: (newHooks: Partial<{
|
|
94
94
|
config: import("@modern-js/plugin").ParallelWorkflow<void, import("./types").UserConfig<{}, {}, {}, {}>>;
|
|
@@ -106,6 +106,6 @@ export declare const createPlugin: (setup?: import("@modern-js/plugin").AsyncSet
|
|
|
106
106
|
commands: import("@modern-js/plugin").AsyncWorkflow<{
|
|
107
107
|
program: import("@modern-js/utils").Command;
|
|
108
108
|
}, void>;
|
|
109
|
-
beforeExit: import("@modern-js/plugin").
|
|
109
|
+
beforeExit: import("@modern-js/plugin").Workflow<void, void>;
|
|
110
110
|
addRuntimeExports: import("@modern-js/plugin").AsyncWaterfall<void>;
|
|
111
111
|
}>) => void;
|
package/dist/manager.js
CHANGED
|
@@ -13,7 +13,7 @@ const baseHooks = {
|
|
|
13
13
|
commands: (0, plugin_1.createAsyncWorkflow)(),
|
|
14
14
|
watchFiles: (0, plugin_1.createParallelWorkflow)(),
|
|
15
15
|
fileChange: (0, plugin_1.createAsyncWorkflow)(),
|
|
16
|
-
beforeExit: (0, plugin_1.
|
|
16
|
+
beforeExit: (0, plugin_1.createWorkflow)(),
|
|
17
17
|
addRuntimeExports: (0, plugin_1.createAsyncWaterfall)(),
|
|
18
18
|
};
|
|
19
19
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CoreOptions } from '.';
|
|
2
|
+
export declare const dev: (options?: CoreOptions, commandOptions?: string[]) => void;
|
|
3
|
+
export declare const build: (options?: CoreOptions, commandOptions?: string[]) => void;
|
|
4
|
+
export declare const deploy: (options?: CoreOptions, commandOptions?: string[]) => void;
|
package/dist/node-api.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deploy = exports.build = exports.dev = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
const dev = (options, commandOptions = []) => {
|
|
6
|
+
_1.cli.runCommand('dev', commandOptions, options);
|
|
7
|
+
};
|
|
8
|
+
exports.dev = dev;
|
|
9
|
+
const build = (options, commandOptions = []) => {
|
|
10
|
+
_1.cli.runCommand('build', commandOptions, options);
|
|
11
|
+
};
|
|
12
|
+
exports.build = build;
|
|
13
|
+
const deploy = (options, commandOptions = []) => {
|
|
14
|
+
_1.cli.runCommand('deploy', commandOptions, options);
|
|
15
|
+
};
|
|
16
|
+
exports.deploy = deploy;
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParallelWorkflow, AsyncWaterfall, AsyncWorkflow, ToRunners, ToThreads } from '@modern-js/plugin';
|
|
1
|
+
import { Workflow, ParallelWorkflow, AsyncWaterfall, AsyncWorkflow, ToRunners, ToThreads } from '@modern-js/plugin';
|
|
2
2
|
import type { Command } from '@modern-js/utils';
|
|
3
3
|
import type { UserConfig, NormalizedConfig } from './config';
|
|
4
4
|
export type BaseHooks<Extends extends {
|
|
@@ -21,7 +21,7 @@ export type BaseHooks<Extends extends {
|
|
|
21
21
|
commands: AsyncWorkflow<{
|
|
22
22
|
program: Command;
|
|
23
23
|
}, void>;
|
|
24
|
-
beforeExit:
|
|
24
|
+
beforeExit: Workflow<void, void>;
|
|
25
25
|
addRuntimeExports: AsyncWaterfall<void>;
|
|
26
26
|
};
|
|
27
27
|
export type CliHooksRunner<Extends extends {
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"modern",
|
|
11
11
|
"modern.js"
|
|
12
12
|
],
|
|
13
|
-
"version": "2.
|
|
13
|
+
"version": "2.11.0",
|
|
14
14
|
"jsnext:source": "./src/index.ts",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"main": "./dist/index.js",
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"default": "./dist/index.js"
|
|
26
26
|
},
|
|
27
|
+
"./node": {
|
|
28
|
+
"jsnext:source": "./src/node-api.ts",
|
|
29
|
+
"types": "./dist/node-api.d.ts",
|
|
30
|
+
"default": "./dist/node-api.js"
|
|
31
|
+
},
|
|
27
32
|
"./bin": {
|
|
28
33
|
"jsnext:source": "./src/bin.ts",
|
|
29
34
|
"default": "./dist/bin.js"
|
|
@@ -51,15 +56,18 @@
|
|
|
51
56
|
"types": [
|
|
52
57
|
"./dist/types/index.d.ts"
|
|
53
58
|
],
|
|
59
|
+
"node": [
|
|
60
|
+
"./dist/node-api.d.ts"
|
|
61
|
+
],
|
|
54
62
|
"runBin": [
|
|
55
63
|
"./dist/runBin.d.ts"
|
|
56
64
|
]
|
|
57
65
|
}
|
|
58
66
|
},
|
|
59
67
|
"dependencies": {
|
|
60
|
-
"@modern-js/node-bundle-require": "2.
|
|
61
|
-
"@modern-js/plugin": "2.
|
|
62
|
-
"@modern-js/utils": "2.
|
|
68
|
+
"@modern-js/node-bundle-require": "2.11.0",
|
|
69
|
+
"@modern-js/plugin": "2.11.0",
|
|
70
|
+
"@modern-js/utils": "2.11.0"
|
|
63
71
|
},
|
|
64
72
|
"devDependencies": {
|
|
65
73
|
"@types/babel__code-frame": "^7.0.3",
|
|
@@ -76,11 +84,11 @@
|
|
|
76
84
|
"terser-webpack-plugin": "^5.1.4",
|
|
77
85
|
"typescript": "^4",
|
|
78
86
|
"webpack": "^5.76.2",
|
|
79
|
-
"@modern-js/builder-shared": "2.
|
|
80
|
-
"@modern-js/babel-preset-app": "2.
|
|
81
|
-
"@modern-js/types": "2.
|
|
82
|
-
"@scripts/
|
|
83
|
-
"@scripts/
|
|
87
|
+
"@modern-js/builder-shared": "2.11.0",
|
|
88
|
+
"@modern-js/babel-preset-app": "2.11.0",
|
|
89
|
+
"@modern-js/types": "2.11.0",
|
|
90
|
+
"@scripts/jest-config": "2.11.0",
|
|
91
|
+
"@scripts/build": "2.11.0"
|
|
84
92
|
},
|
|
85
93
|
"sideEffects": false,
|
|
86
94
|
"publishConfig": {
|