@modern-js/plugin-v2 2.63.7 → 2.63.8-alpha.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/dist/cjs/cli/run/create.js +25 -14
- package/dist/cjs/hooks.js +74 -2
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/manager.js +3 -5
- package/dist/cjs/runtime/api.js +79 -0
- package/dist/cjs/runtime/context.js +51 -0
- package/dist/cjs/runtime/hooks.js +36 -0
- package/dist/cjs/runtime/index.js +39 -0
- package/dist/cjs/runtime/run/create.js +74 -0
- package/dist/cjs/runtime/run/index.js +29 -0
- package/dist/cjs/runtime/run/types.js +16 -0
- package/dist/cjs/types/runtime/api.js +16 -0
- package/dist/cjs/types/runtime/context.js +16 -0
- package/dist/cjs/types/runtime/hooks.js +16 -0
- package/dist/cjs/types/runtime/index.js +16 -0
- package/dist/cjs/types/runtime/plugin.js +16 -0
- package/dist/esm/cli/api.js +103 -0
- package/dist/esm/cli/context.js +53 -0
- package/dist/esm/cli/hooks.js +42 -0
- package/dist/esm/cli/index.js +14 -0
- package/dist/esm/cli/run/config/createLoadedConfig.js +190 -0
- package/dist/esm/cli/run/config/createResolvedConfig.js +30 -0
- package/dist/esm/cli/run/config/loadConfig.js +210 -0
- package/dist/esm/cli/run/create.js +300 -0
- package/dist/esm/cli/run/index.js +10 -0
- package/dist/esm/cli/run/run.js +60 -0
- package/dist/esm/cli/run/types.js +0 -0
- package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.js +24 -0
- package/dist/esm/cli/run/utils/commander.js +42 -0
- package/dist/esm/cli/run/utils/createFileWatcher.js +110 -0
- package/dist/esm/cli/run/utils/debug.js +5 -0
- package/dist/esm/cli/run/utils/initAppDir.js +36 -0
- package/dist/esm/cli/run/utils/loadEnv.js +24 -0
- package/dist/esm/cli/run/utils/mergeConfig.js +43 -0
- package/dist/esm/hooks.js +378 -0
- package/dist/esm/index.js +6 -357
- package/dist/esm/manager.js +161 -0
- package/dist/esm/runtime/api.js +59 -0
- package/dist/esm/runtime/context.js +25 -0
- package/dist/esm/runtime/hooks.js +12 -0
- package/dist/esm/runtime/index.js +11 -0
- package/dist/esm/runtime/run/create.js +72 -0
- package/dist/esm/runtime/run/index.js +5 -0
- package/dist/esm/runtime/run/types.js +0 -0
- package/dist/esm/types/cli/api.js +0 -0
- package/dist/esm/types/cli/context.js +0 -0
- package/dist/esm/types/cli/hooks.js +0 -0
- package/dist/esm/types/cli/index.js +0 -0
- package/dist/esm/types/cli/plugin.js +0 -0
- package/dist/esm/types/hooks.js +0 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm/types/plugin.js +0 -0
- package/dist/esm/types/runtime/api.js +0 -0
- package/dist/esm/types/runtime/context.js +0 -0
- package/dist/esm/types/runtime/hooks.js +0 -0
- package/dist/esm/types/runtime/index.js +0 -0
- package/dist/esm/types/runtime/plugin.js +0 -0
- package/dist/esm/types/utils.js +0 -0
- package/dist/esm-node/cli/run/create.js +26 -15
- package/dist/esm-node/hooks.js +70 -1
- package/dist/esm-node/index.js +5 -2
- package/dist/esm-node/manager.js +2 -4
- package/dist/esm-node/runtime/api.js +55 -0
- package/dist/esm-node/runtime/context.js +26 -0
- package/dist/esm-node/runtime/hooks.js +12 -0
- package/dist/esm-node/runtime/index.js +11 -0
- package/dist/esm-node/runtime/run/create.js +50 -0
- package/dist/esm-node/runtime/run/index.js +5 -0
- package/dist/esm-node/runtime/run/types.js +0 -0
- package/dist/esm-node/types/runtime/api.js +0 -0
- package/dist/esm-node/types/runtime/context.js +0 -0
- package/dist/esm-node/types/runtime/hooks.js +0 -0
- package/dist/esm-node/types/runtime/index.js +0 -0
- package/dist/esm-node/types/runtime/plugin.js +0 -0
- package/dist/types/cli/hooks.d.ts +3 -3
- package/dist/types/cli/run/create.d.ts +2 -1
- package/dist/types/cli/run/index.d.ts +4 -4
- package/dist/types/hooks.d.ts +4 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/manager.d.ts +3 -0
- package/dist/types/runtime/api.d.ts +9 -0
- package/dist/types/runtime/context.d.ts +11 -0
- package/dist/types/runtime/hooks.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/run/create.d.ts +7 -0
- package/dist/types/runtime/run/index.d.ts +5 -0
- package/dist/types/runtime/run/types.d.ts +6 -0
- package/dist/types/types/cli/api.d.ts +2 -2
- package/dist/types/types/cli/context.d.ts +1 -1
- package/dist/types/types/cli/hooks.d.ts +3 -3
- package/dist/types/types/cli/plugin.d.ts +2 -1
- package/dist/types/types/hooks.d.ts +14 -2
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/plugin.d.ts +1 -1
- package/dist/types/types/runtime/api.d.ts +15 -0
- package/dist/types/types/runtime/context.d.ts +13 -0
- package/dist/types/types/runtime/hooks.d.ts +12 -0
- package/dist/types/types/runtime/index.d.ts +4 -0
- package/dist/types/types/runtime/plugin.d.ts +14 -0
- package/dist/types/types/utils.d.ts +1 -0
- package/package.json +13 -9
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
|
+
import { createPluginManager } from "../../manager";
|
|
4
|
+
import { initPluginAPI } from "../../runtime/api";
|
|
5
|
+
import { createRuntimeContext, initRuntimeContext } from "../../runtime/context";
|
|
6
|
+
var createRuntime = function() {
|
|
7
|
+
var init = function init2(options) {
|
|
8
|
+
pluginManager.clear();
|
|
9
|
+
initOptions = options;
|
|
10
|
+
var allPlugins = options.plugins, handleSetupResult = options.handleSetupResult;
|
|
11
|
+
pluginManager.addPlugins(allPlugins);
|
|
12
|
+
var plugins = pluginManager.getPlugins();
|
|
13
|
+
var context = createRuntimeContext({
|
|
14
|
+
runtimeContext: initRuntimeContext(),
|
|
15
|
+
config: initOptions.config,
|
|
16
|
+
plugins
|
|
17
|
+
});
|
|
18
|
+
var pluginAPI = initPluginAPI({
|
|
19
|
+
context,
|
|
20
|
+
pluginManager,
|
|
21
|
+
plugins
|
|
22
|
+
});
|
|
23
|
+
context.pluginAPI = pluginAPI;
|
|
24
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
25
|
+
try {
|
|
26
|
+
for (var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
27
|
+
var plugin = _step.value;
|
|
28
|
+
var _plugin_setup;
|
|
29
|
+
var setupResult = (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI);
|
|
30
|
+
if (handleSetupResult) {
|
|
31
|
+
handleSetupResult(setupResult, pluginAPI);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
_didIteratorError = true;
|
|
36
|
+
_iteratorError = err;
|
|
37
|
+
} finally {
|
|
38
|
+
try {
|
|
39
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
40
|
+
_iterator.return();
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
if (_didIteratorError) {
|
|
44
|
+
throw _iteratorError;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
runtimeContext: context
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
var run = function run2(options) {
|
|
53
|
+
var runtimeContext = init(options).runtimeContext;
|
|
54
|
+
var configs = runtimeContext.hooks.modifyRuntimeConfig.call(runtimeContext.config).filter(function(config) {
|
|
55
|
+
return Boolean(config);
|
|
56
|
+
});
|
|
57
|
+
runtimeContext.config = merge.apply(void 0, [
|
|
58
|
+
{}
|
|
59
|
+
].concat(_to_consumable_array(configs)));
|
|
60
|
+
return {
|
|
61
|
+
runtimeContext
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
var initOptions;
|
|
65
|
+
var pluginManager = createPluginManager();
|
|
66
|
+
return {
|
|
67
|
+
run
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export {
|
|
71
|
+
createRuntime
|
|
72
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger } from "@modern-js/utils";
|
|
1
|
+
import { createDebugger, logger } from "@modern-js/utils";
|
|
2
2
|
import { program } from "@modern-js/utils/commander";
|
|
3
3
|
import { createPluginManager } from "../../manager";
|
|
4
4
|
import { initPluginAPI } from "../api";
|
|
@@ -10,9 +10,27 @@ import { initCommandsMap, setProgramVersion } from "./utils/commander";
|
|
|
10
10
|
import { createFileWatcher } from "./utils/createFileWatcher";
|
|
11
11
|
import { initAppDir } from "./utils/initAppDir";
|
|
12
12
|
import { loadEnv } from "./utils/loadEnv";
|
|
13
|
+
const debug = createDebugger("plugin-v2");
|
|
13
14
|
const createCli = () => {
|
|
14
15
|
let initOptions;
|
|
15
16
|
const pluginManager = createPluginManager();
|
|
17
|
+
const existListenerMap = /* @__PURE__ */ new Map();
|
|
18
|
+
function createExistListener(event, context) {
|
|
19
|
+
return async function(err) {
|
|
20
|
+
await context.hooks.onBeforeExit.call();
|
|
21
|
+
let hasError = false;
|
|
22
|
+
if (err instanceof Error) {
|
|
23
|
+
logger.error(err.stack);
|
|
24
|
+
hasError = true;
|
|
25
|
+
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
26
|
+
console.trace("Unknown Error", err);
|
|
27
|
+
hasError = true;
|
|
28
|
+
}
|
|
29
|
+
process.nextTick(() => {
|
|
30
|
+
process.exit(hasError ? 1 : 0);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
16
34
|
async function init(options) {
|
|
17
35
|
var _context_hooks_onAfterPrepare, _context_hooks;
|
|
18
36
|
pluginManager.clear();
|
|
@@ -30,6 +48,7 @@ const createCli = () => {
|
|
|
30
48
|
checkIsDuplicationPlugin(allPlugins.map((plugin) => plugin.name), loaded.config.autoLoadPlugins);
|
|
31
49
|
pluginManager.addPlugins(allPlugins);
|
|
32
50
|
const plugins = await pluginManager.getPlugins();
|
|
51
|
+
debug("CLI Plugins:", plugins.map((p) => p.name));
|
|
33
52
|
const context = await createContext({
|
|
34
53
|
appContext: initAppContext({
|
|
35
54
|
packageName: loaded.packageName,
|
|
@@ -59,20 +78,12 @@ const createCli = () => {
|
|
|
59
78
|
"unhandledRejection",
|
|
60
79
|
"uncaughtException"
|
|
61
80
|
].forEach((event) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} else if (err && (event === "unhandledRejection" || event === "uncaughtException")) {
|
|
69
|
-
console.trace("Unknown Error", err);
|
|
70
|
-
hasError = true;
|
|
71
|
-
}
|
|
72
|
-
process.nextTick(() => {
|
|
73
|
-
process.exit(hasError ? 1 : 0);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
81
|
+
if (existListenerMap.get(event)) {
|
|
82
|
+
process.off(event, existListenerMap.get(event));
|
|
83
|
+
}
|
|
84
|
+
const existListener = createExistListener(event, context);
|
|
85
|
+
existListenerMap.set(event, existListener);
|
|
86
|
+
process.on(event, existListener);
|
|
76
87
|
});
|
|
77
88
|
const extraConfigs = await context.hooks.config.call();
|
|
78
89
|
const normalizedConfig = await createResolveConfig(loaded, extraConfigs);
|
package/dist/esm-node/hooks.js
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
function createAsyncInterruptHook() {
|
|
2
|
+
const callbacks = [];
|
|
3
|
+
const tap = (cb) => {
|
|
4
|
+
callbacks.push(cb);
|
|
5
|
+
};
|
|
6
|
+
const call = async (...params) => {
|
|
7
|
+
let interrupted = false;
|
|
8
|
+
let interruptResult;
|
|
9
|
+
const interrupt = (info) => {
|
|
10
|
+
interrupted = true;
|
|
11
|
+
interruptResult = info;
|
|
12
|
+
};
|
|
13
|
+
for (const callback of callbacks) {
|
|
14
|
+
if (interrupted)
|
|
15
|
+
break;
|
|
16
|
+
const result = await callback(...params, interrupt);
|
|
17
|
+
if (result !== void 0) {
|
|
18
|
+
params[0] = result;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return interrupted ? interruptResult : params[0] || [];
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
tap,
|
|
25
|
+
call
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createSyncHook() {
|
|
29
|
+
const callbacks = [];
|
|
30
|
+
const tap = (cb) => {
|
|
31
|
+
callbacks.push(cb);
|
|
32
|
+
};
|
|
33
|
+
const call = (...params) => {
|
|
34
|
+
for (const callback of callbacks) {
|
|
35
|
+
const result = callback(...params);
|
|
36
|
+
if (result !== void 0) {
|
|
37
|
+
params[0] = result;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return params[0];
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
tap,
|
|
44
|
+
call
|
|
45
|
+
};
|
|
46
|
+
}
|
|
1
47
|
function createAsyncHook() {
|
|
2
48
|
const callbacks = [];
|
|
3
49
|
const tap = (cb) => {
|
|
@@ -37,7 +83,30 @@ function createCollectAsyncHook() {
|
|
|
37
83
|
call
|
|
38
84
|
};
|
|
39
85
|
}
|
|
86
|
+
function createCollectSyncHook() {
|
|
87
|
+
const callbacks = [];
|
|
88
|
+
const tap = (cb) => {
|
|
89
|
+
callbacks.push(cb);
|
|
90
|
+
};
|
|
91
|
+
const call = (...params) => {
|
|
92
|
+
const results = [];
|
|
93
|
+
for (const callback of callbacks) {
|
|
94
|
+
const result = callback(params);
|
|
95
|
+
if (result !== void 0) {
|
|
96
|
+
results.push(result);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return results;
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
tap,
|
|
103
|
+
call
|
|
104
|
+
};
|
|
105
|
+
}
|
|
40
106
|
export {
|
|
41
107
|
createAsyncHook,
|
|
42
|
-
|
|
108
|
+
createAsyncInterruptHook,
|
|
109
|
+
createCollectAsyncHook,
|
|
110
|
+
createCollectSyncHook,
|
|
111
|
+
createSyncHook
|
|
43
112
|
};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createPluginManager } from "./manager";
|
|
2
|
-
import { createAsyncHook, createCollectAsyncHook } from "./hooks";
|
|
2
|
+
import { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook } from "./hooks";
|
|
3
3
|
export {
|
|
4
4
|
createAsyncHook,
|
|
5
|
+
createAsyncInterruptHook,
|
|
5
6
|
createCollectAsyncHook,
|
|
6
|
-
|
|
7
|
+
createCollectSyncHook,
|
|
8
|
+
createPluginManager,
|
|
9
|
+
createSyncHook
|
|
7
10
|
};
|
package/dist/esm-node/manager.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { debug } from "./cli/run/utils/debug";
|
|
1
|
+
const isFunction = (obj) => typeof obj === "function";
|
|
3
2
|
function validatePlugin(plugin) {
|
|
4
3
|
const type = typeof plugin;
|
|
5
4
|
if (type !== "object" || plugin === null) {
|
|
@@ -47,7 +46,7 @@ function createPluginManager() {
|
|
|
47
46
|
validatePlugin(newPlugin);
|
|
48
47
|
const { name, usePlugins = [], pre = [], post = [] } = newPlugin;
|
|
49
48
|
if (plugins.has(name)) {
|
|
50
|
-
|
|
49
|
+
console.warn(`Plugin ${name} already exists.`);
|
|
51
50
|
return;
|
|
52
51
|
}
|
|
53
52
|
plugins.set(name, newPlugin);
|
|
@@ -112,7 +111,6 @@ function createPluginManager() {
|
|
|
112
111
|
visit(name);
|
|
113
112
|
});
|
|
114
113
|
result = result.filter((result2) => result2);
|
|
115
|
-
debug("CLI Plugins:", result.map((p) => p.name));
|
|
116
114
|
return result;
|
|
117
115
|
};
|
|
118
116
|
const clear = () => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
2
|
+
function initPluginAPI({ context, plugins }) {
|
|
3
|
+
const { hooks, extendsHooks } = context;
|
|
4
|
+
function getRuntimeContext() {
|
|
5
|
+
if (context) {
|
|
6
|
+
const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI, ...runtimeContext } = context;
|
|
7
|
+
runtimeContext._internalContext = context;
|
|
8
|
+
return runtimeContext;
|
|
9
|
+
}
|
|
10
|
+
throw new Error("Cannot access context");
|
|
11
|
+
}
|
|
12
|
+
function updateRuntimeContext(updateContext) {
|
|
13
|
+
context = merge(context, updateContext);
|
|
14
|
+
}
|
|
15
|
+
function getHooks() {
|
|
16
|
+
return {
|
|
17
|
+
...hooks,
|
|
18
|
+
...extendsHooks
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function getRuntimeConfig() {
|
|
22
|
+
if (context.config) {
|
|
23
|
+
return context.config;
|
|
24
|
+
}
|
|
25
|
+
throw new Error("Cannot access config");
|
|
26
|
+
}
|
|
27
|
+
const extendsPluginApi = {};
|
|
28
|
+
plugins.forEach((plugin) => {
|
|
29
|
+
const { _registryApi } = plugin;
|
|
30
|
+
if (_registryApi) {
|
|
31
|
+
const apis = _registryApi(getRuntimeContext, updateRuntimeContext);
|
|
32
|
+
Object.keys(apis).forEach((apiName) => {
|
|
33
|
+
extendsPluginApi[apiName] = apis[apiName];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (extendsHooks) {
|
|
38
|
+
Object.keys(extendsHooks).forEach((hookName) => {
|
|
39
|
+
extendsPluginApi[hookName] = extendsHooks[hookName].tap;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
updateRuntimeContext,
|
|
44
|
+
getHooks,
|
|
45
|
+
getRuntimeConfig,
|
|
46
|
+
modifyRuntimeConfig: hooks.modifyRuntimeConfig.tap,
|
|
47
|
+
onBeforeRender: hooks.onBeforeRender.tap,
|
|
48
|
+
wrapRoot: hooks.wrapRoot.tap,
|
|
49
|
+
pickContext: hooks.pickContext.tap,
|
|
50
|
+
...extendsPluginApi
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
initPluginAPI
|
|
55
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { initHooks } from "./hooks";
|
|
2
|
+
function initRuntimeContext() {
|
|
3
|
+
return {};
|
|
4
|
+
}
|
|
5
|
+
function createRuntimeContext({ runtimeContext, config, plugins }) {
|
|
6
|
+
const extendsHooks = {};
|
|
7
|
+
plugins.forEach((plugin) => {
|
|
8
|
+
const { registryHooks = {} } = plugin;
|
|
9
|
+
Object.keys(registryHooks).forEach((hookName) => {
|
|
10
|
+
extendsHooks[hookName] = registryHooks[hookName];
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
...runtimeContext,
|
|
15
|
+
hooks: {
|
|
16
|
+
...initHooks(),
|
|
17
|
+
...extendsHooks
|
|
18
|
+
},
|
|
19
|
+
extendsHooks,
|
|
20
|
+
config
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
createRuntimeContext,
|
|
25
|
+
initRuntimeContext
|
|
26
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createAsyncInterruptHook, createCollectSyncHook, createSyncHook } from "../hooks";
|
|
2
|
+
function initHooks() {
|
|
3
|
+
return {
|
|
4
|
+
onBeforeRender: createAsyncInterruptHook(),
|
|
5
|
+
wrapRoot: createSyncHook(),
|
|
6
|
+
pickContext: createSyncHook(),
|
|
7
|
+
modifyRuntimeConfig: createCollectSyncHook()
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
initHooks
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { initPluginAPI } from "./api";
|
|
2
|
+
import { initRuntimeContext, createRuntimeContext } from "./context";
|
|
3
|
+
import { initHooks } from "./hooks";
|
|
4
|
+
import { runtime } from "./run";
|
|
5
|
+
export {
|
|
6
|
+
createRuntimeContext,
|
|
7
|
+
initHooks,
|
|
8
|
+
initPluginAPI,
|
|
9
|
+
initRuntimeContext,
|
|
10
|
+
runtime
|
|
11
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
2
|
+
import { createPluginManager } from "../../manager";
|
|
3
|
+
import { initPluginAPI } from "../../runtime/api";
|
|
4
|
+
import { createRuntimeContext, initRuntimeContext } from "../../runtime/context";
|
|
5
|
+
const createRuntime = () => {
|
|
6
|
+
let initOptions;
|
|
7
|
+
const pluginManager = createPluginManager();
|
|
8
|
+
function init(options) {
|
|
9
|
+
pluginManager.clear();
|
|
10
|
+
initOptions = options;
|
|
11
|
+
const { plugins: allPlugins, handleSetupResult } = options;
|
|
12
|
+
pluginManager.addPlugins(allPlugins);
|
|
13
|
+
const plugins = pluginManager.getPlugins();
|
|
14
|
+
const context = createRuntimeContext({
|
|
15
|
+
runtimeContext: initRuntimeContext(),
|
|
16
|
+
config: initOptions.config,
|
|
17
|
+
plugins
|
|
18
|
+
});
|
|
19
|
+
const pluginAPI = initPluginAPI({
|
|
20
|
+
context,
|
|
21
|
+
pluginManager,
|
|
22
|
+
plugins
|
|
23
|
+
});
|
|
24
|
+
context.pluginAPI = pluginAPI;
|
|
25
|
+
for (const plugin of plugins) {
|
|
26
|
+
var _plugin_setup;
|
|
27
|
+
const setupResult = (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI);
|
|
28
|
+
if (handleSetupResult) {
|
|
29
|
+
handleSetupResult(setupResult, pluginAPI);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
runtimeContext: context
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function run(options) {
|
|
37
|
+
const { runtimeContext } = init(options);
|
|
38
|
+
const configs = runtimeContext.hooks.modifyRuntimeConfig.call(runtimeContext.config).filter((config) => Boolean(config));
|
|
39
|
+
runtimeContext.config = merge({}, ...configs);
|
|
40
|
+
return {
|
|
41
|
+
runtimeContext
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
run
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
createRuntime
|
|
50
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,7 +2,7 @@ import type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBefore
|
|
|
2
2
|
import type { AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn } from '../types/cli/hooks';
|
|
3
3
|
import type { DeepPartial } from '../types/utils';
|
|
4
4
|
export type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, AddCommandFn, AddWatchFilesFn, ConfigFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyWebpackChainFn, ModifyWebpackConfigFn, OnAfterDeployFn, OnBeforeDeployFn, OnBeforeDevFn, OnAfterDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn, };
|
|
5
|
-
export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>(): {
|
|
5
|
+
export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils>(): {
|
|
6
6
|
/**
|
|
7
7
|
* add config for this cli plugin
|
|
8
8
|
*/
|
|
@@ -11,7 +11,7 @@ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>():
|
|
|
11
11
|
* @private
|
|
12
12
|
* modify config for this cli plugin
|
|
13
13
|
*/
|
|
14
|
-
modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config>>;
|
|
14
|
+
modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config, ExtendConfigUtils>>;
|
|
15
15
|
/**
|
|
16
16
|
* modify final config
|
|
17
17
|
*/
|
|
@@ -38,4 +38,4 @@ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils>():
|
|
|
38
38
|
onAfterDeploy: import("..").AsyncHook<OnAfterDeployFn>;
|
|
39
39
|
onBeforeExit: import("..").AsyncHook<OnBeforeExitFn>;
|
|
40
40
|
};
|
|
41
|
-
export type Hooks<Config, NormalizedConfig, ExtendBuildUtils> = ReturnType<typeof initHooks<Config, NormalizedConfig, ExtendBuildUtils>>;
|
|
41
|
+
export type Hooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils> = ReturnType<typeof initHooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils>>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { InternalContext } from '../../types/cli/context';
|
|
1
2
|
import type { CLIPluginExtends } from '../../types/cli/plugin';
|
|
2
3
|
import type { CLIRunOptions } from './types';
|
|
3
4
|
export declare const createCli: <Extends extends CLIPluginExtends>() => {
|
|
4
5
|
init: (options: CLIRunOptions<Extends>) => Promise<{
|
|
5
|
-
appContext:
|
|
6
|
+
appContext: InternalContext<Extends>;
|
|
6
7
|
}>;
|
|
7
8
|
run: (options: CLIRunOptions<Extends>) => Promise<void>;
|
|
8
9
|
getPrevInitOptions: () => CLIRunOptions<Extends>;
|
|
@@ -3,9 +3,9 @@ export { createLoadedConfig } from './config/createLoadedConfig';
|
|
|
3
3
|
export { initAppDir } from './utils/initAppDir';
|
|
4
4
|
export { createCli };
|
|
5
5
|
export declare const cli: {
|
|
6
|
-
init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<{
|
|
7
|
-
appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
|
|
6
|
+
init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>) => Promise<{
|
|
7
|
+
appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>;
|
|
8
8
|
}>;
|
|
9
|
-
run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>) => Promise<void>;
|
|
10
|
-
getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}>>;
|
|
9
|
+
run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>) => Promise<void>;
|
|
10
|
+
getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>;
|
|
11
11
|
};
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type { AsyncHook, CollectAsyncHook } from './types/hooks';
|
|
1
|
+
import type { AsyncHook, AsyncInterruptHook, CollectAsyncHook, CollectSyncHook, SyncHook } from './types/hooks';
|
|
2
|
+
export declare function createAsyncInterruptHook<Callback extends (...args: any[]) => any>(): AsyncInterruptHook<Callback>;
|
|
3
|
+
export declare function createSyncHook<Callback extends (...args: any[]) => any>(): SyncHook<Callback>;
|
|
2
4
|
export declare function createAsyncHook<Callback extends (...args: any[]) => any>(): AsyncHook<Callback>;
|
|
3
5
|
export declare function createCollectAsyncHook<Callback extends (...params: any[]) => any>(): CollectAsyncHook<Callback>;
|
|
6
|
+
export declare function createCollectSyncHook<Callback extends (...params: any[]) => any>(): CollectSyncHook<Callback>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createPluginManager } from './manager';
|
|
2
|
-
export { createAsyncHook, createCollectAsyncHook } from './hooks';
|
|
2
|
+
export { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook, } from './hooks';
|
|
3
3
|
export type { Plugin, PluginManager, TransformFunction, } from './types/plugin';
|
|
4
4
|
export type { CLIPluginAPI, AppContext, InternalContext, Entrypoint, CLIPlugin, CLIPluginExtends, } from './types/cli';
|
|
5
|
+
export type { RuntimePluginAPI, RuntimeContext, InternalRuntimeContext, RuntimePlugin, RuntimePluginExtends, } from './types/runtime';
|
|
5
6
|
export type { AsyncHook, CollectAsyncHook, PluginHook, PluginHookTap, } from './types/hooks';
|
package/dist/types/manager.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PluginManager } from '../types/plugin';
|
|
2
|
+
import type { RuntimePluginAPI } from '../types/runtime/api';
|
|
3
|
+
import type { InternalRuntimeContext } from '../types/runtime/context';
|
|
4
|
+
import type { RuntimePlugin, RuntimePluginExtends } from '../types/runtime/plugin';
|
|
5
|
+
export declare function initPluginAPI<Extends extends RuntimePluginExtends>({ context, plugins, }: {
|
|
6
|
+
context: InternalRuntimeContext<Extends>;
|
|
7
|
+
pluginManager: PluginManager;
|
|
8
|
+
plugins: RuntimePlugin<Extends>[];
|
|
9
|
+
}): RuntimePluginAPI<Extends>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InternalRuntimeContext, RuntimeContext } from '../types/runtime/context';
|
|
2
|
+
import type { RuntimePlugin, RuntimePluginExtends } from '../types/runtime/plugin';
|
|
3
|
+
export interface RuntimeConfig<Extends extends RuntimePluginExtends> {
|
|
4
|
+
plugins?: RuntimePlugin<Extends>[];
|
|
5
|
+
}
|
|
6
|
+
export declare function initRuntimeContext(): RuntimeContext;
|
|
7
|
+
export declare function createRuntimeContext<Extends extends RuntimePluginExtends>({ runtimeContext, config, plugins, }: {
|
|
8
|
+
runtimeContext: RuntimeContext & Extends['extendContext'];
|
|
9
|
+
config: Extends['config'];
|
|
10
|
+
plugins: RuntimePlugin<Extends>[];
|
|
11
|
+
}): InternalRuntimeContext<Extends>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { initPluginAPI } from './api';
|
|
2
|
+
export { initRuntimeContext, createRuntimeContext } from './context';
|
|
3
|
+
export { initHooks } from './hooks';
|
|
4
|
+
export { runtime } from './run';
|
|
5
|
+
export type { RuntimePluginAPI, RuntimeContext, InternalRuntimeContext, RuntimePlugin, RuntimePluginExtends, Hooks, } from '../types/runtime';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RuntimePluginExtends } from '../../types/runtime/plugin';
|
|
2
|
+
import type { RuntimeRunOptions } from './types';
|
|
3
|
+
export declare const createRuntime: <Extends extends RuntimePluginExtends>() => {
|
|
4
|
+
run: (options: RuntimeRunOptions) => {
|
|
5
|
+
runtimeContext: import("..").InternalRuntimeContext<Extends>;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -13,10 +13,10 @@ export type CLIPluginAPI<Extends extends CLIPluginExtends> = Readonly<{
|
|
|
13
13
|
getAppContext: () => Readonly<AppContext<Extends> & Extends['extendContext']>;
|
|
14
14
|
getConfig: () => Readonly<Extends['config']>;
|
|
15
15
|
getNormalizedConfig: () => Readonly<Extends['normalizedConfig']>;
|
|
16
|
-
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']> & Extends['extendHooks']>;
|
|
16
|
+
getHooks: () => Readonly<Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils'], Extends['extendConfigUtils']> & Extends['extendHooks']>;
|
|
17
17
|
updateAppContext: (appContext: DeepPartial<AppContext<Extends> & Extends['extendContext']>) => void;
|
|
18
18
|
config: PluginHookTap<ConfigFn<DeepPartial<Extends['config']>>>;
|
|
19
|
-
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config']>>;
|
|
19
|
+
modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config'], Extends['extendConfigUtils']>>;
|
|
20
20
|
modifyResolvedConfig: PluginHookTap<ModifyResolvedConfigFn<Extends['normalizedConfig']>>;
|
|
21
21
|
modifyRsbuildConfig: PluginHookTap<ModifyRsbuildConfigFn<Extends['extendBuildUtils']>>;
|
|
22
22
|
modifyBundlerChain: PluginHookTap<ModifyBundlerChainFn<Extends['extendBuildUtils']>>;
|
|
@@ -28,7 +28,7 @@ export type AppContext<Extends extends CLIPluginExtends> = {
|
|
|
28
28
|
/** The inner context. */
|
|
29
29
|
export type InternalContext<Extends extends CLIPluginExtends> = AppContext<Extends> & {
|
|
30
30
|
/** All hooks. */
|
|
31
|
-
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils']> & Extends['extendHooks'];
|
|
31
|
+
hooks: Hooks<Extends['config'], Extends['normalizedConfig'], Extends['extendBuildUtils'], Extends['extendConfigUtils']> & Extends['extendHooks'];
|
|
32
32
|
/** All plugin registry hooks */
|
|
33
33
|
extendsHooks: Extends['extendHooks'];
|
|
34
34
|
/** Current App config. */
|