@modern-js/core 1.12.1 → 1.12.2-alpha.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/config/index.d.ts +4 -3
- package/dist/config/index.js +8 -3
- package/dist/index.d.ts +4 -5
- package/dist/index.js +15 -18
- package/dist/loadPlugins.js +1 -21
- package/dist/pluginAPI.d.ts +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.12.2-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9cd364e06: The buildPreset will be split out of a buildConfig, preset only supports built-in strings, config this piece to remove speedyOptions, watch, add platform, splitting, minify, external, and add tools.speedy
|
|
8
|
+
- f29e9bacf: feat: simplify context usage, no longer depend on containers
|
|
9
|
+
- a90bc96bd: perf(babel): skip babel-plugin-import if package not installed
|
|
10
|
+
- Updated dependencies [9cd364e06]
|
|
11
|
+
- Updated dependencies [3050accbe]
|
|
12
|
+
- Updated dependencies [f29e9bacf]
|
|
13
|
+
- Updated dependencies [a90bc96bd]
|
|
14
|
+
- @modern-js/utils@1.7.9-alpha.0
|
|
15
|
+
- @modern-js/load-config@1.3.6-alpha.0
|
|
16
|
+
- @modern-js/plugin@1.4.0-alpha.0
|
|
17
|
+
|
|
3
18
|
## 1.12.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { ErrorObject } from '../../compiled/ajv';
|
|
2
2
|
import { defaults } from './defaults';
|
|
3
|
-
import {
|
|
3
|
+
import { NormalizedConfig } from './mergeConfig';
|
|
4
4
|
import { PluginValidateSchema } from './schema';
|
|
5
5
|
import type { UserConfig, ConfigParam, LoadedConfig } from './types';
|
|
6
6
|
export { defaults as defaultsConfig };
|
|
7
|
-
export
|
|
7
|
+
export * from './mergeConfig';
|
|
8
8
|
export * from './types';
|
|
9
|
+
export * from './schema';
|
|
9
10
|
export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
|
|
10
11
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
11
12
|
/**
|
|
12
13
|
* Assign the pkg config into the user config.
|
|
13
14
|
*/
|
|
14
15
|
export declare const assignPkgConfig: (userConfig?: UserConfig, pkgConfig?: ConfigParam) => UserConfig & ConfigParam;
|
|
15
|
-
export declare const loadUserConfig: (appDirectory: string, filePath?: string
|
|
16
|
+
export declare const loadUserConfig: (appDirectory: string, filePath?: string, packageJsonConfig?: string) => Promise<LoadedConfig>;
|
|
16
17
|
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void | Promise<void>) => Promise<NormalizedConfig>;
|
package/dist/config/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
18
|
};
|
|
15
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.resolveConfig = exports.loadUserConfig = exports.assignPkgConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.
|
|
20
|
+
exports.resolveConfig = exports.loadUserConfig = exports.assignPkgConfig = exports.defineConfig = exports.addServerConfigToDeps = exports.defaultsConfig = void 0;
|
|
17
21
|
const load_config_1 = require("@modern-js/load-config");
|
|
18
22
|
const utils_1 = require("@modern-js/utils");
|
|
19
23
|
const lodash_1 = require("@modern-js/utils/lodash");
|
|
@@ -24,10 +28,11 @@ const repeatKeyWarning_1 = require("../utils/repeatKeyWarning");
|
|
|
24
28
|
const defaults_1 = require("./defaults");
|
|
25
29
|
Object.defineProperty(exports, "defaultsConfig", { enumerable: true, get: function () { return defaults_1.defaults; } });
|
|
26
30
|
const mergeConfig_1 = require("./mergeConfig");
|
|
27
|
-
Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function () { return mergeConfig_1.mergeConfig; } });
|
|
28
31
|
const schema_1 = require("./schema");
|
|
29
32
|
const debug = (0, utils_1.createDebugger)('resolve-config');
|
|
33
|
+
__exportStar(require("./mergeConfig"), exports);
|
|
30
34
|
__exportStar(require("./types"), exports);
|
|
35
|
+
__exportStar(require("./schema"), exports);
|
|
31
36
|
const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
32
37
|
const serverConfig = await (0, utils_1.getServerConfig)(appDirectory, serverConfigFile);
|
|
33
38
|
if (serverConfig) {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,13 +7,12 @@ import type { NormalizedConfig } from './config/mergeConfig';
|
|
|
7
7
|
export type { Hooks };
|
|
8
8
|
export * from './config';
|
|
9
9
|
export * from '@modern-js/plugin';
|
|
10
|
-
export * from '@modern-js/plugin/node';
|
|
11
10
|
export { manager, mountHook, usePlugins, createPlugin, registerHook, } from './manager';
|
|
12
11
|
export type { CliHooks, CliPlugin, CliHookCallbacks } from './manager';
|
|
13
12
|
export { AppContext, ConfigContext, ResolvedConfigContext, useAppContext, useConfigContext, useResolvedConfigContext, } from './pluginAPI';
|
|
14
13
|
export type { PluginAPI } from './pluginAPI';
|
|
15
14
|
export type { NormalizedConfig, IAppContext };
|
|
16
|
-
declare const initAppDir: (cwd?: string
|
|
15
|
+
declare const initAppDir: (cwd?: string) => Promise<string>;
|
|
17
16
|
export interface CoreOptions {
|
|
18
17
|
version?: string;
|
|
19
18
|
configFile?: string;
|
|
@@ -29,7 +28,7 @@ export interface CoreOptions {
|
|
|
29
28
|
sharedDir?: string;
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
|
-
export declare const mergeOptions: (options?: CoreOptions
|
|
31
|
+
export declare const mergeOptions: (options?: CoreOptions) => {
|
|
33
32
|
version?: string | undefined;
|
|
34
33
|
configFile?: string | undefined;
|
|
35
34
|
serverConfigFile: string;
|
|
@@ -50,12 +49,12 @@ export declare const mergeOptions: (options?: CoreOptions | undefined) => {
|
|
|
50
49
|
} | undefined;
|
|
51
50
|
};
|
|
52
51
|
export declare const cli: {
|
|
53
|
-
init: (argv?: string[], options?: CoreOptions
|
|
52
|
+
init: (argv?: string[], options?: CoreOptions) => Promise<{
|
|
54
53
|
loadedConfig: import("./config").LoadedConfig;
|
|
55
54
|
appContext: IAppContext;
|
|
56
55
|
resolved: NormalizedConfig;
|
|
57
56
|
}>;
|
|
58
|
-
run: (argv: string[], options?: CoreOptions
|
|
57
|
+
run: (argv: string[], options?: CoreOptions) => Promise<void>;
|
|
59
58
|
restart: () => Promise<void>;
|
|
60
59
|
};
|
|
61
60
|
export { initAppDir, initAppContext };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -16,7 +20,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
20
|
exports.initAppContext = exports.initAppDir = exports.cli = exports.mergeOptions = exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = exports.registerHook = exports.createPlugin = exports.usePlugins = exports.mountHook = exports.manager = void 0;
|
|
17
21
|
const path_1 = __importDefault(require("path"));
|
|
18
22
|
const utils_1 = require("@modern-js/utils");
|
|
19
|
-
const node_1 = require("@modern-js/plugin/node");
|
|
20
23
|
const commander_1 = require("./utils/commander");
|
|
21
24
|
const config_1 = require("./config");
|
|
22
25
|
const loadPlugins_1 = require("./loadPlugins");
|
|
@@ -27,7 +30,6 @@ const loadEnv_1 = require("./loadEnv");
|
|
|
27
30
|
const manager_1 = require("./manager");
|
|
28
31
|
__exportStar(require("./config"), exports);
|
|
29
32
|
__exportStar(require("@modern-js/plugin"), exports);
|
|
30
|
-
__exportStar(require("@modern-js/plugin/node"), exports);
|
|
31
33
|
// TODO: remove export after refactor all plugins
|
|
32
34
|
var manager_2 = require("./manager");
|
|
33
35
|
Object.defineProperty(exports, "manager", { enumerable: true, get: function () { return manager_2.manager; } });
|
|
@@ -75,7 +77,6 @@ const createCli = () => {
|
|
|
75
77
|
let restartOptions;
|
|
76
78
|
const init = async (argv = [], options) => {
|
|
77
79
|
var _a, _b;
|
|
78
|
-
(0, node_1.enable)();
|
|
79
80
|
manager_1.manager.clear();
|
|
80
81
|
const mergedOptions = (0, exports.mergeOptions)(options);
|
|
81
82
|
restartOptions = mergedOptions;
|
|
@@ -99,10 +100,8 @@ const createCli = () => {
|
|
|
99
100
|
});
|
|
100
101
|
// 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
101
102
|
(0, config_1.addServerConfigToDeps)(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
context_1.AppContext.set(appContext);
|
|
105
|
-
});
|
|
103
|
+
context_1.ConfigContext.set(loaded.config);
|
|
104
|
+
context_1.AppContext.set(appContext);
|
|
106
105
|
hooksRunner = await manager_1.manager.init();
|
|
107
106
|
['SIGINT', 'SIGTERM', 'unhandledRejection', 'uncaughtException'].forEach(event => {
|
|
108
107
|
process.on(event, async (err) => {
|
|
@@ -123,14 +122,12 @@ const createCli = () => {
|
|
|
123
122
|
resolved: config,
|
|
124
123
|
});
|
|
125
124
|
// update context value
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path),
|
|
133
|
-
});
|
|
125
|
+
context_1.ConfigContext.set(loaded.config);
|
|
126
|
+
context_1.ResolvedConfigContext.set(resolved);
|
|
127
|
+
context_1.AppContext.set({
|
|
128
|
+
...appContext,
|
|
129
|
+
port: resolved.server.port,
|
|
130
|
+
distDirectory: (0, utils_1.ensureAbsolutePath)(appDirectory, resolved.output.path),
|
|
134
131
|
});
|
|
135
132
|
await hooksRunner.prepare();
|
|
136
133
|
return {
|
|
@@ -144,7 +141,7 @@ const createCli = () => {
|
|
|
144
141
|
const { loadedConfig, appContext, resolved } = await init(argv, options);
|
|
145
142
|
await hooksRunner.commands({ program: utils_1.program });
|
|
146
143
|
(0, initWatcher_1.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
147
|
-
|
|
144
|
+
utils_1.program.parse(process.argv);
|
|
148
145
|
}
|
|
149
146
|
async function restart() {
|
|
150
147
|
var _a, _b;
|
|
@@ -163,7 +160,7 @@ const createCli = () => {
|
|
|
163
160
|
}
|
|
164
161
|
finally {
|
|
165
162
|
if (!hasGetError) {
|
|
166
|
-
|
|
163
|
+
utils_1.program.parse(process.argv);
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
166
|
}
|
package/dist/loadPlugins.js
CHANGED
|
@@ -4,26 +4,6 @@ exports.loadPlugins = exports.getAppPlugins = void 0;
|
|
|
4
4
|
const utils_1 = require("@modern-js/utils");
|
|
5
5
|
const manager_1 = require("./manager");
|
|
6
6
|
const debug = (0, utils_1.createDebugger)('load-plugins');
|
|
7
|
-
/**
|
|
8
|
-
* Try to resolve plugin entry file path.
|
|
9
|
-
* @param name - Plugin name.
|
|
10
|
-
* @param appDirectory - Application root directory.
|
|
11
|
-
* @returns Resolved file path.
|
|
12
|
-
*/
|
|
13
|
-
const tryResolve = (name, appDirectory) => {
|
|
14
|
-
let filePath = '';
|
|
15
|
-
try {
|
|
16
|
-
filePath = require.resolve(name, { paths: [appDirectory] });
|
|
17
|
-
delete require.cache[filePath];
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
20
|
-
if (err.code === 'MODULE_NOT_FOUND') {
|
|
21
|
-
throw new Error(`Can not find plugin ${name}.`);
|
|
22
|
-
}
|
|
23
|
-
throw err;
|
|
24
|
-
}
|
|
25
|
-
return filePath;
|
|
26
|
-
};
|
|
27
7
|
function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
|
|
28
8
|
const allPlugins = internalPlugins || utils_1.INTERNAL_PLUGINS;
|
|
29
9
|
const appPlugins = [
|
|
@@ -44,7 +24,7 @@ exports.getAppPlugins = getAppPlugins;
|
|
|
44
24
|
const resolveCliPlugin = (p, userConfig, appDirectory, transformPlugin) => {
|
|
45
25
|
const pkg = typeof p === 'string' ? p : p[0];
|
|
46
26
|
const pluginOptions = typeof p === 'string' ? undefined : p[1];
|
|
47
|
-
const path = tryResolve(pkg, appDirectory);
|
|
27
|
+
const path = (0, utils_1.tryResolve)(pkg, appDirectory);
|
|
48
28
|
let module = (0, utils_1.compatRequire)(path);
|
|
49
29
|
if (transformPlugin) {
|
|
50
30
|
module = transformPlugin(module, userConfig, pluginOptions);
|
package/dist/pluginAPI.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const pluginAPI: {
|
|
|
5
5
|
setAppContext: (value: import("@modern-js/types").IAppContext) => void;
|
|
6
6
|
useAppContext: () => import("@modern-js/types").IAppContext;
|
|
7
7
|
useConfigContext: () => import("./config").UserConfig;
|
|
8
|
-
useResolvedConfigContext: () => import("
|
|
8
|
+
useResolvedConfigContext: () => import("./config").NormalizedConfig;
|
|
9
9
|
};
|
|
10
10
|
export type { IAppContext } from '@modern-js/types';
|
|
11
11
|
/** all apis for cli plugin */
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.12.
|
|
14
|
+
"version": "1.12.2-alpha.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"main": "./dist/index.js",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@modern-js/load-config": "^1.3.
|
|
43
|
-
"@modern-js/plugin": "^1.
|
|
44
|
-
"@modern-js/utils": "^1.7.
|
|
42
|
+
"@modern-js/load-config": "^1.3.6-alpha.0",
|
|
43
|
+
"@modern-js/plugin": "^1.4.0-alpha.0",
|
|
44
|
+
"@modern-js/utils": "^1.7.9-alpha.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@jest/types": "^27.0.6",
|
|
48
|
-
"@modern-js/types": "1.5.
|
|
48
|
+
"@modern-js/types": "1.5.5-alpha.0",
|
|
49
49
|
"@scripts/build": "0.0.0",
|
|
50
50
|
"@scripts/jest-config": "0.0.0",
|
|
51
51
|
"@types/babel__code-frame": "^7.0.3",
|