@modern-js/core 2.12.0 → 2.13.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 +15 -0
- package/dist/createCli.d.ts +17 -0
- package/dist/createCli.js +122 -0
- package/dist/index.d.ts +9 -60
- package/dist/index.js +18 -148
- package/dist/types/config/index.d.ts +1 -1
- package/dist/types/context.d.ts +1 -0
- package/dist/types/coreOptions.d.ts +28 -0
- package/dist/types/coreOptions.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/initAppDir.d.ts +1 -0
- package/dist/utils/initAppDir.js +20 -0
- package/package.json +9 -9
- /package/dist/{node-api.d.ts → nodeApi.d.ts} +0 -0
- /package/dist/{node-api.js → nodeApi.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 2.13.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e9b1656: fix: plugin config hook can not get bundlerType, so we can't set babelConfig correctly in ssr plugin
|
|
8
|
+
fix: 插件的 config 钩子不能获得 bundlerType,所以我们在 ssr 插件不能正确的设置 babelConfig
|
|
9
|
+
- e91ec97: feat(app-tools): export mergeConfig function
|
|
10
|
+
|
|
11
|
+
feat(app-tools): 导出 mergeConfig 函数
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [78431f4]
|
|
14
|
+
- @modern-js/plugin@2.13.0
|
|
15
|
+
- @modern-js/node-bundle-require@2.13.0
|
|
16
|
+
- @modern-js/utils@2.13.0
|
|
17
|
+
|
|
3
18
|
## 2.12.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CoreOptions } from './types';
|
|
2
|
+
export declare const mergeOptions: (options?: CoreOptions) => CoreOptions & {
|
|
3
|
+
serverConfigFile: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const createCli: () => {
|
|
6
|
+
init: (options?: CoreOptions) => Promise<{
|
|
7
|
+
resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
|
|
8
|
+
appContext: import("./types").IAppContext;
|
|
9
|
+
}>;
|
|
10
|
+
run: (options?: CoreOptions) => Promise<void>;
|
|
11
|
+
test: (argv: string[], options?: {
|
|
12
|
+
coreOptions?: CoreOptions;
|
|
13
|
+
disableWatcher?: boolean;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
runCommand: (command: string, commandOptions?: string[], options?: CoreOptions) => Promise<void>;
|
|
16
|
+
getPrevInitOptions: () => CoreOptions | undefined;
|
|
17
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCli = exports.mergeOptions = void 0;
|
|
4
|
+
const utils_1 = require("@modern-js/utils");
|
|
5
|
+
const utils_2 = require("./utils");
|
|
6
|
+
const loadPlugins_1 = require("./loadPlugins");
|
|
7
|
+
const context_1 = require("./context");
|
|
8
|
+
const loadEnv_1 = require("./loadEnv");
|
|
9
|
+
const manager_1 = require("./manager");
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const checkIsDuplicationPlugin_1 = require("./utils/checkIsDuplicationPlugin");
|
|
12
|
+
const setProgramVersion = (version = 'unknown') => {
|
|
13
|
+
utils_1.program.name('modern').usage('<command> [options]').version(version);
|
|
14
|
+
};
|
|
15
|
+
const mergeOptions = (options) => {
|
|
16
|
+
const defaultOptions = {
|
|
17
|
+
serverConfigFile: utils_1.DEFAULT_SERVER_CONFIG,
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
...defaultOptions,
|
|
21
|
+
...options,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.mergeOptions = mergeOptions;
|
|
25
|
+
const createCli = () => {
|
|
26
|
+
let hooksRunner;
|
|
27
|
+
let initOptions;
|
|
28
|
+
const init = async (options) => {
|
|
29
|
+
var _a, _b, _c, _d, _e;
|
|
30
|
+
manager_1.manager.clear();
|
|
31
|
+
const mergedOptions = (0, exports.mergeOptions)(options);
|
|
32
|
+
initOptions = mergedOptions;
|
|
33
|
+
const appDirectory = await (0, utils_2.initAppDir)(options === null || options === void 0 ? void 0 : options.cwd);
|
|
34
|
+
(0, utils_2.initCommandsMap)();
|
|
35
|
+
setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
|
|
36
|
+
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';
|
|
37
|
+
(0, loadEnv_1.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
38
|
+
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);
|
|
39
|
+
const plugins = await (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
|
|
40
|
+
internalPlugins: (_c = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _c === void 0 ? void 0 : _c.cli,
|
|
41
|
+
autoLoad: (_d = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _d === void 0 ? void 0 : _d.autoLoad,
|
|
42
|
+
forceAutoLoadPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.forceAutoLoadPlugins,
|
|
43
|
+
});
|
|
44
|
+
(0, checkIsDuplicationPlugin_1.checkIsDuplicationPlugin)(plugins.map(plugin => plugin.name), loaded.config.autoLoadPlugins);
|
|
45
|
+
plugins.forEach(plugin => plugin && manager_1.manager.usePlugin(plugin));
|
|
46
|
+
const appContext = (0, context_1.initAppContext)({
|
|
47
|
+
toolsType: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.toolsType,
|
|
48
|
+
appDirectory,
|
|
49
|
+
plugins,
|
|
50
|
+
configFile: loaded.filePath,
|
|
51
|
+
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
52
|
+
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile,
|
|
53
|
+
serverInternalPlugins: ((_e = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _e === void 0 ? void 0 : _e.server) || utils_1.INTERNAL_SERVER_PLUGINS,
|
|
54
|
+
});
|
|
55
|
+
context_1.ConfigContext.set(loaded.config);
|
|
56
|
+
context_1.AppContext.set(appContext);
|
|
57
|
+
hooksRunner = await manager_1.manager.init();
|
|
58
|
+
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
59
|
+
process.on(event, async (err) => {
|
|
60
|
+
hooksRunner.beforeExit();
|
|
61
|
+
if (err instanceof Error) {
|
|
62
|
+
utils_1.logger.error(err.stack);
|
|
63
|
+
}
|
|
64
|
+
process.nextTick(() => {
|
|
65
|
+
// eslint-disable-next-line no-process-exit
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
const extraConfigs = await hooksRunner.config();
|
|
71
|
+
const extraSchemas = await hooksRunner.validateSchema();
|
|
72
|
+
const normalizedConfig = await (0, config_1.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
73
|
+
const { resolved } = await hooksRunner.resolvedConfig({
|
|
74
|
+
resolved: normalizedConfig,
|
|
75
|
+
});
|
|
76
|
+
// update context value
|
|
77
|
+
context_1.ConfigContext.set(loaded.config);
|
|
78
|
+
context_1.ResolvedConfigContext.set(resolved);
|
|
79
|
+
await hooksRunner.addRuntimeExports();
|
|
80
|
+
await hooksRunner.prepare();
|
|
81
|
+
await hooksRunner.afterPrepare();
|
|
82
|
+
return {
|
|
83
|
+
resolved,
|
|
84
|
+
appContext: (0, context_1.useAppContext)(),
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
async function run(options) {
|
|
88
|
+
const { appContext } = await init(options);
|
|
89
|
+
await hooksRunner.commands({ program: utils_1.program });
|
|
90
|
+
await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
|
|
91
|
+
utils_1.program.parse(process.argv);
|
|
92
|
+
if (!utils_1.program.commands || !utils_1.program.commands.length) {
|
|
93
|
+
utils_1.logger.warn('No command found, please make sure you have registered plugins correctly.');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function runCommand(command, commandOptions = [], options) {
|
|
97
|
+
const argv = process.argv
|
|
98
|
+
.slice(0, 2)
|
|
99
|
+
.concat(command)
|
|
100
|
+
.concat(commandOptions);
|
|
101
|
+
process.env.MODERN_ARGV = argv.join(' ');
|
|
102
|
+
const { appContext } = await init(options);
|
|
103
|
+
await hooksRunner.commands({ program: utils_1.program });
|
|
104
|
+
await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
|
|
105
|
+
utils_1.program.parse(argv);
|
|
106
|
+
}
|
|
107
|
+
async function test(argv, options) {
|
|
108
|
+
const newProgram = new utils_1.Command();
|
|
109
|
+
const { coreOptions } = options !== null && options !== void 0 ? options : {};
|
|
110
|
+
await init(coreOptions);
|
|
111
|
+
await hooksRunner.commands({ program: newProgram });
|
|
112
|
+
await newProgram.parseAsync(argv);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
init,
|
|
116
|
+
run,
|
|
117
|
+
test,
|
|
118
|
+
runCommand,
|
|
119
|
+
getPrevInitOptions: () => initOptions,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
exports.createCli = createCli;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,21 @@
|
|
|
1
|
-
import type { ErrorObject } from '@modern-js/utils/ajv';
|
|
2
|
-
import { InternalPlugins } from '@modern-js/types';
|
|
3
|
-
import { initAppContext } from './context';
|
|
4
|
-
import type { ToolsType, UserConfig } from './types';
|
|
5
1
|
export * from './types';
|
|
6
2
|
export * from '@modern-js/plugin';
|
|
3
|
+
export { mergeConfig, initAppDir } from './utils';
|
|
7
4
|
export { manager, createPlugin, registerHook } from './manager';
|
|
8
|
-
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './context';
|
|
9
|
-
declare const initAppDir: (cwd?: string) => Promise<string>;
|
|
10
|
-
export interface CoreOptions {
|
|
11
|
-
cwd?: string;
|
|
12
|
-
version?: string;
|
|
13
|
-
configFile?: string;
|
|
14
|
-
serverConfigFile?: string;
|
|
15
|
-
packageJsonConfig?: string;
|
|
16
|
-
internalPlugins?: {
|
|
17
|
-
cli?: InternalPlugins;
|
|
18
|
-
server?: InternalPlugins;
|
|
19
|
-
autoLoad?: InternalPlugins;
|
|
20
|
-
};
|
|
21
|
-
onSchemaError?: (error: ErrorObject) => void;
|
|
22
|
-
options?: {
|
|
23
|
-
metaName?: string;
|
|
24
|
-
srcDir?: string;
|
|
25
|
-
distDir?: string;
|
|
26
|
-
sharedDir?: string;
|
|
27
|
-
};
|
|
28
|
-
toolsType?: ToolsType;
|
|
29
|
-
/** force the modern-js core auto register plugin exist in the package.json */
|
|
30
|
-
forceAutoLoadPlugins?: boolean;
|
|
31
|
-
/** config for Node API */
|
|
32
|
-
loadedConfig?: UserConfig;
|
|
33
|
-
}
|
|
34
|
-
export declare const mergeOptions: (options?: CoreOptions) => {
|
|
35
|
-
cwd?: string | undefined;
|
|
36
|
-
version?: string | undefined;
|
|
37
|
-
configFile?: string | undefined;
|
|
38
|
-
serverConfigFile: string;
|
|
39
|
-
packageJsonConfig?: string | undefined;
|
|
40
|
-
internalPlugins?: {
|
|
41
|
-
cli?: InternalPlugins | undefined;
|
|
42
|
-
server?: InternalPlugins | undefined;
|
|
43
|
-
autoLoad?: InternalPlugins | undefined;
|
|
44
|
-
} | undefined;
|
|
45
|
-
onSchemaError?: ((error: ErrorObject) => void) | undefined;
|
|
46
|
-
options?: {
|
|
47
|
-
metaName?: string | undefined;
|
|
48
|
-
srcDir?: string | undefined;
|
|
49
|
-
distDir?: string | undefined;
|
|
50
|
-
sharedDir?: string | undefined;
|
|
51
|
-
} | undefined;
|
|
52
|
-
toolsType?: ToolsType | undefined;
|
|
53
|
-
forceAutoLoadPlugins?: boolean | undefined;
|
|
54
|
-
loadedConfig?: UserConfig<{}, {}, {}, {}> | undefined;
|
|
55
|
-
};
|
|
5
|
+
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, initAppContext, } from './context';
|
|
56
6
|
export declare const cli: {
|
|
57
|
-
init: (options?: CoreOptions) => Promise<{
|
|
7
|
+
init: (options?: import("./types").CoreOptions | undefined) => Promise<{
|
|
58
8
|
resolved: import("./types").NormalizedConfig<{}, {}, {}, {}>;
|
|
59
9
|
appContext: import("./types").IAppContext;
|
|
60
10
|
}>;
|
|
61
|
-
run: (options?: CoreOptions) => Promise<void>;
|
|
11
|
+
run: (options?: import("./types").CoreOptions | undefined) => Promise<void>;
|
|
62
12
|
test: (argv: string[], options?: {
|
|
63
|
-
coreOptions?: CoreOptions;
|
|
64
|
-
disableWatcher?: boolean;
|
|
65
|
-
}) => Promise<void>;
|
|
66
|
-
runCommand: (command: string, commandOptions?: string[], options?: CoreOptions) => Promise<void>;
|
|
67
|
-
getPrevInitOptions: () => CoreOptions | undefined;
|
|
13
|
+
coreOptions?: import("./types").CoreOptions | undefined;
|
|
14
|
+
disableWatcher?: boolean | undefined;
|
|
15
|
+
} | undefined) => Promise<void>;
|
|
16
|
+
runCommand: (command: string, commandOptions?: string[], options?: import("./types").CoreOptions | undefined) => Promise<void>;
|
|
17
|
+
getPrevInitOptions: () => import("./types").CoreOptions | undefined;
|
|
68
18
|
};
|
|
69
|
-
export { initAppDir, initAppContext };
|
|
70
19
|
declare module '@modern-js/utils/compiled/commander' {
|
|
71
20
|
interface Command {
|
|
72
21
|
commandsMap: Map<string, Command>;
|
package/dist/index.js
CHANGED
|
@@ -13,154 +13,24 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
const
|
|
22
|
-
const utils_1 = require("@modern-js/utils");
|
|
23
|
-
const utils_2 = require("./utils");
|
|
24
|
-
const loadPlugins_1 = require("./loadPlugins");
|
|
25
|
-
const context_1 = require("./context");
|
|
26
|
-
Object.defineProperty(exports, "initAppContext", { enumerable: true, get: function () { return context_1.initAppContext; } });
|
|
27
|
-
const loadEnv_1 = require("./loadEnv");
|
|
28
|
-
const manager_1 = require("./manager");
|
|
29
|
-
const config_1 = require("./config");
|
|
30
|
-
const checkIsDuplicationPlugin_1 = require("./utils/checkIsDuplicationPlugin");
|
|
17
|
+
exports.cli = exports.initAppContext = exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = exports.registerHook = exports.createPlugin = exports.manager = exports.initAppDir = exports.mergeConfig = void 0;
|
|
18
|
+
const createCli_1 = require("./createCli");
|
|
31
19
|
__exportStar(require("./types"), exports);
|
|
32
20
|
__exportStar(require("@modern-js/plugin"), exports);
|
|
33
|
-
var
|
|
34
|
-
Object.defineProperty(exports, "
|
|
35
|
-
Object.defineProperty(exports, "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Object.defineProperty(exports, "
|
|
39
|
-
Object.defineProperty(exports, "
|
|
40
|
-
|
|
41
|
-
Object.defineProperty(exports, "
|
|
42
|
-
Object.defineProperty(exports, "
|
|
43
|
-
Object.defineProperty(exports, "
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const pkg = await (0, utils_1.pkgUp)({ cwd });
|
|
50
|
-
if (!pkg) {
|
|
51
|
-
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
52
|
-
}
|
|
53
|
-
return path_1.default.dirname(pkg);
|
|
54
|
-
};
|
|
55
|
-
exports.initAppDir = initAppDir;
|
|
56
|
-
const mergeOptions = (options) => {
|
|
57
|
-
const defaultOptions = {
|
|
58
|
-
serverConfigFile: utils_1.DEFAULT_SERVER_CONFIG,
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
...defaultOptions,
|
|
62
|
-
...options,
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
exports.mergeOptions = mergeOptions;
|
|
66
|
-
const setProgramVersion = (version = 'unknown') => {
|
|
67
|
-
utils_1.program.name('modern').usage('<command> [options]').version(version);
|
|
68
|
-
};
|
|
69
|
-
const createCli = () => {
|
|
70
|
-
let hooksRunner;
|
|
71
|
-
let initOptions;
|
|
72
|
-
const init = async (options) => {
|
|
73
|
-
var _a, _b, _c, _d, _e;
|
|
74
|
-
manager_1.manager.clear();
|
|
75
|
-
const mergedOptions = (0, exports.mergeOptions)(options);
|
|
76
|
-
initOptions = mergedOptions;
|
|
77
|
-
const appDirectory = await initAppDir(options === null || options === void 0 ? void 0 : options.cwd);
|
|
78
|
-
(0, utils_2.initCommandsMap)();
|
|
79
|
-
setProgramVersion(options === null || options === void 0 ? void 0 : options.version);
|
|
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
|
-
(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, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.loadedConfig);
|
|
83
|
-
const plugins = await (0, loadPlugins_1.loadPlugins)(appDirectory, loaded.config, {
|
|
84
|
-
internalPlugins: (_c = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _c === void 0 ? void 0 : _c.cli,
|
|
85
|
-
autoLoad: (_d = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _d === void 0 ? void 0 : _d.autoLoad,
|
|
86
|
-
forceAutoLoadPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.forceAutoLoadPlugins,
|
|
87
|
-
});
|
|
88
|
-
(0, checkIsDuplicationPlugin_1.checkIsDuplicationPlugin)(plugins.map(plugin => plugin.name), loaded.config.autoLoadPlugins);
|
|
89
|
-
plugins.forEach(plugin => plugin && manager_1.manager.usePlugin(plugin));
|
|
90
|
-
const appContext = (0, context_1.initAppContext)({
|
|
91
|
-
toolsType: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.toolsType,
|
|
92
|
-
appDirectory,
|
|
93
|
-
plugins,
|
|
94
|
-
configFile: loaded.filePath,
|
|
95
|
-
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
96
|
-
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile,
|
|
97
|
-
serverInternalPlugins: ((_e = mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.internalPlugins) === null || _e === void 0 ? void 0 : _e.server) || utils_1.INTERNAL_SERVER_PLUGINS,
|
|
98
|
-
});
|
|
99
|
-
context_1.ConfigContext.set(loaded.config);
|
|
100
|
-
context_1.AppContext.set(appContext);
|
|
101
|
-
hooksRunner = await manager_1.manager.init();
|
|
102
|
-
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
103
|
-
process.on(event, async (err) => {
|
|
104
|
-
hooksRunner.beforeExit();
|
|
105
|
-
if (err instanceof Error) {
|
|
106
|
-
utils_1.logger.error(err.stack);
|
|
107
|
-
}
|
|
108
|
-
process.nextTick(() => {
|
|
109
|
-
// eslint-disable-next-line no-process-exit
|
|
110
|
-
process.exit(1);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
const extraConfigs = await hooksRunner.config();
|
|
115
|
-
const extraSchemas = await hooksRunner.validateSchema();
|
|
116
|
-
const normalizedConfig = await (0, config_1.createResolveConfig)(loaded, extraConfigs, extraSchemas, options === null || options === void 0 ? void 0 : options.onSchemaError);
|
|
117
|
-
const { resolved } = await hooksRunner.resolvedConfig({
|
|
118
|
-
resolved: normalizedConfig,
|
|
119
|
-
});
|
|
120
|
-
// update context value
|
|
121
|
-
context_1.ConfigContext.set(loaded.config);
|
|
122
|
-
context_1.ResolvedConfigContext.set(resolved);
|
|
123
|
-
await hooksRunner.addRuntimeExports();
|
|
124
|
-
await hooksRunner.prepare();
|
|
125
|
-
await hooksRunner.afterPrepare();
|
|
126
|
-
return {
|
|
127
|
-
resolved,
|
|
128
|
-
appContext: (0, context_1.useAppContext)(),
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
async function run(options) {
|
|
132
|
-
const { appContext } = await init(options);
|
|
133
|
-
await hooksRunner.commands({ program: utils_1.program });
|
|
134
|
-
await (0, utils_2.createFileWatcher)(appContext, hooksRunner);
|
|
135
|
-
utils_1.program.parse(process.argv);
|
|
136
|
-
if (!utils_1.program.commands || !utils_1.program.commands.length) {
|
|
137
|
-
utils_1.logger.warn('No command found, please make sure you have registered plugins correctly.');
|
|
138
|
-
}
|
|
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
|
-
}
|
|
151
|
-
async function test(argv, options) {
|
|
152
|
-
const newProgram = new utils_1.Command();
|
|
153
|
-
const { coreOptions } = options !== null && options !== void 0 ? options : {};
|
|
154
|
-
await init(coreOptions);
|
|
155
|
-
await hooksRunner.commands({ program: newProgram });
|
|
156
|
-
await newProgram.parseAsync(argv);
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
init,
|
|
160
|
-
run,
|
|
161
|
-
test,
|
|
162
|
-
runCommand,
|
|
163
|
-
getPrevInitOptions: () => initOptions,
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
exports.cli = createCli();
|
|
21
|
+
var utils_1 = require("./utils");
|
|
22
|
+
Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function () { return utils_1.mergeConfig; } });
|
|
23
|
+
Object.defineProperty(exports, "initAppDir", { enumerable: true, get: function () { return utils_1.initAppDir; } });
|
|
24
|
+
var manager_1 = require("./manager");
|
|
25
|
+
Object.defineProperty(exports, "manager", { enumerable: true, get: function () { return manager_1.manager; } });
|
|
26
|
+
Object.defineProperty(exports, "createPlugin", { enumerable: true, get: function () { return manager_1.createPlugin; } });
|
|
27
|
+
Object.defineProperty(exports, "registerHook", { enumerable: true, get: function () { return manager_1.registerHook; } });
|
|
28
|
+
var context_1 = require("./context");
|
|
29
|
+
Object.defineProperty(exports, "AppContext", { enumerable: true, get: function () { return context_1.AppContext; } });
|
|
30
|
+
Object.defineProperty(exports, "ConfigContext", { enumerable: true, get: function () { return context_1.ConfigContext; } });
|
|
31
|
+
Object.defineProperty(exports, "ResolvedConfigContext", { enumerable: true, get: function () { return context_1.ResolvedConfigContext; } });
|
|
32
|
+
Object.defineProperty(exports, "useAppContext", { enumerable: true, get: function () { return context_1.useAppContext; } });
|
|
33
|
+
Object.defineProperty(exports, "useConfigContext", { enumerable: true, get: function () { return context_1.useConfigContext; } });
|
|
34
|
+
Object.defineProperty(exports, "useResolvedConfigContext", { enumerable: true, get: function () { return context_1.useResolvedConfigContext; } });
|
|
35
|
+
Object.defineProperty(exports, "initAppContext", { enumerable: true, get: function () { return context_1.initAppContext; } });
|
|
36
|
+
exports.cli = (0, createCli_1.createCli)();
|
|
@@ -30,7 +30,7 @@ export type NormalizedConfig<Extends extends {
|
|
|
30
30
|
plugins: PluginConfig<any>;
|
|
31
31
|
testing: BaseTestingNormalizedConfig<DropUndefined<Extends['normalizedConfig']>['testing']>;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Auto load plugin that exist in the package.json
|
|
34
34
|
*
|
|
35
35
|
* **default: `false`**
|
|
36
36
|
*/
|
package/dist/types/context.d.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ErrorObject } from '@modern-js/utils/compiled/ajv';
|
|
2
|
+
import type { InternalPlugins } from './plugin';
|
|
3
|
+
import type { ToolsType } from './context';
|
|
4
|
+
import type { UserConfig } from './config';
|
|
5
|
+
export interface CoreOptions {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
configFile?: string;
|
|
9
|
+
serverConfigFile?: string;
|
|
10
|
+
packageJsonConfig?: string;
|
|
11
|
+
internalPlugins?: {
|
|
12
|
+
cli?: InternalPlugins;
|
|
13
|
+
server?: InternalPlugins;
|
|
14
|
+
autoLoad?: InternalPlugins;
|
|
15
|
+
};
|
|
16
|
+
onSchemaError?: (error: ErrorObject) => void;
|
|
17
|
+
options?: {
|
|
18
|
+
metaName?: string;
|
|
19
|
+
srcDir?: string;
|
|
20
|
+
distDir?: string;
|
|
21
|
+
sharedDir?: string;
|
|
22
|
+
};
|
|
23
|
+
toolsType?: ToolsType;
|
|
24
|
+
/** force the modern-js core auto register plugin exist in the package.json */
|
|
25
|
+
forceAutoLoadPlugins?: boolean;
|
|
26
|
+
/** config for Node API */
|
|
27
|
+
loadedConfig?: UserConfig;
|
|
28
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./commander"), exports);
|
|
18
18
|
__exportStar(require("./createFileWatcher"), exports);
|
|
19
|
+
__exportStar(require("./initAppDir"), exports);
|
|
19
20
|
__exportStar(require("./mergeConfig"), exports);
|
|
20
21
|
__exportStar(require("./repeatKeyWarning"), exports);
|
|
21
22
|
__exportStar(require("./checkIsDuplicationPlugin"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initAppDir: (cwd?: string) => Promise<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initAppDir = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_1 = require("@modern-js/utils");
|
|
9
|
+
const initAppDir = async (cwd) => {
|
|
10
|
+
if (!cwd) {
|
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
|
12
|
+
cwd = process.cwd();
|
|
13
|
+
}
|
|
14
|
+
const pkg = await (0, utils_1.pkgUp)({ cwd });
|
|
15
|
+
if (!pkg) {
|
|
16
|
+
throw new Error(`no package.json found in current work dir: ${cwd}`);
|
|
17
|
+
}
|
|
18
|
+
return path_1.default.dirname(pkg);
|
|
19
|
+
};
|
|
20
|
+
exports.initAppDir = initAppDir;
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"modern",
|
|
11
11
|
"modern.js"
|
|
12
12
|
],
|
|
13
|
-
"version": "2.
|
|
13
|
+
"version": "2.13.0",
|
|
14
14
|
"jsnext:source": "./src/index.ts",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"main": "./dist/index.js",
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@modern-js/node-bundle-require": "2.
|
|
69
|
-
"@modern-js/plugin": "2.
|
|
70
|
-
"@modern-js/utils": "2.
|
|
68
|
+
"@modern-js/node-bundle-require": "2.13.0",
|
|
69
|
+
"@modern-js/plugin": "2.13.0",
|
|
70
|
+
"@modern-js/utils": "2.13.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/babel__code-frame": "^7.0.3",
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"terser-webpack-plugin": "^5.1.4",
|
|
85
85
|
"typescript": "^4",
|
|
86
86
|
"webpack": "^5.76.2",
|
|
87
|
-
"@modern-js/builder-shared": "2.
|
|
88
|
-
"@modern-js/babel-preset-app": "2.
|
|
89
|
-
"@modern-js/types": "2.
|
|
90
|
-
"@scripts/
|
|
91
|
-
"@scripts/
|
|
87
|
+
"@modern-js/builder-shared": "2.13.0",
|
|
88
|
+
"@modern-js/babel-preset-app": "2.13.0",
|
|
89
|
+
"@modern-js/types": "2.13.0",
|
|
90
|
+
"@scripts/jest-config": "2.13.0",
|
|
91
|
+
"@scripts/build": "2.13.0"
|
|
92
92
|
},
|
|
93
93
|
"sideEffects": false,
|
|
94
94
|
"publishConfig": {
|
|
File without changes
|
|
File without changes
|