@modern-js/plugin-v2 0.0.0-nightly-20250119160327 → 0.0.0-nightly-20250120160316
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 +2 -0
- 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 +291 -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 +3 -1
- 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/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/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 +17 -12
|
@@ -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,6 +10,7 @@ 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();
|
|
@@ -30,6 +31,7 @@ const createCli = () => {
|
|
|
30
31
|
checkIsDuplicationPlugin(allPlugins.map((plugin) => plugin.name), loaded.config.autoLoadPlugins);
|
|
31
32
|
pluginManager.addPlugins(allPlugins);
|
|
32
33
|
const plugins = await pluginManager.getPlugins();
|
|
34
|
+
debug("CLI Plugins:", plugins.map((p) => p.name));
|
|
33
35
|
const context = await createContext({
|
|
34
36
|
appContext: initAppContext({
|
|
35
37
|
packageName: loaded.packageName,
|
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
|
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
|
+
};
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import type { UnwrapPromise } from './utils';
|
|
1
|
+
import type { Tail, UnwrapPromise } from './utils';
|
|
2
|
+
export type SyncHook<Callback extends (...args: any[]) => any> = {
|
|
3
|
+
tap: (cb: Callback) => void;
|
|
4
|
+
call: (...args: Parameters<Callback>) => ReturnType<Callback>;
|
|
5
|
+
};
|
|
2
6
|
export type AsyncHook<Callback extends (...args: any[]) => any> = {
|
|
3
7
|
tap: (cb: Callback) => void;
|
|
4
8
|
call: (...args: Parameters<Callback>) => Promise<ReturnType<Callback>>;
|
|
5
9
|
};
|
|
10
|
+
export type AsyncInterruptHook<Callback extends (...args: any[]) => any> = {
|
|
11
|
+
tap: (cb: Callback) => void;
|
|
12
|
+
call: (...args: Tail<Parameters<Callback>>) => Promise<ReturnType<Callback>>;
|
|
13
|
+
};
|
|
6
14
|
export type CollectAsyncHook<Callback extends (...params: any[]) => any> = {
|
|
7
15
|
tap: (cb: Callback) => void;
|
|
8
16
|
call: (...params: Parameters<Callback>) => Promise<UnwrapPromise<ReturnType<Callback>>[]>;
|
|
9
17
|
};
|
|
10
|
-
export type
|
|
18
|
+
export type CollectSyncHook<Callback extends (...params: any[]) => any> = {
|
|
19
|
+
tap: (cb: Callback) => void;
|
|
20
|
+
call: (...params: Parameters<Callback>) => ReturnType<Callback>[];
|
|
21
|
+
};
|
|
22
|
+
export type PluginHook<Callback extends (...args: any[]) => any> = SyncHook<Callback> | AsyncHook<Callback> | CollectSyncHook<Callback> | CollectAsyncHook<Callback> | AsyncInterruptHook<Callback>;
|
|
11
23
|
export type PluginHookTap<T extends (...args: any[]) => any> = (options: T) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { Plugin, PluginManager, TransformFunction, } from './plugin';
|
|
2
2
|
export type { CLIPluginAPI, AppContext, InternalContext, Entrypoint, CLIPlugin, } from './cli';
|
|
3
|
+
export type { RuntimePluginAPI, RuntimeContext, InternalRuntimeContext, RuntimePlugin, } from './runtime';
|
|
3
4
|
export type { AsyncHook, CollectAsyncHook, PluginHook, PluginHookTap, } from './hooks';
|
|
@@ -18,7 +18,7 @@ export type Plugin<PluginAPI = {}, Context = {}> = {
|
|
|
18
18
|
/**
|
|
19
19
|
* The plugins add new apis to the plugin manager.
|
|
20
20
|
*/
|
|
21
|
-
_registryApi?: (
|
|
21
|
+
_registryApi?: (...params: any[]) => Record<string, (...args: any[]) => any>;
|
|
22
22
|
/**
|
|
23
23
|
* The setup function of the plugin, which can be an async function.
|
|
24
24
|
* This function is called once when the plugin is initialized.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginHookTap } from '../hooks';
|
|
2
|
+
import type { DeepPartial } from '../utils';
|
|
3
|
+
import type { RuntimeContext } from './context';
|
|
4
|
+
import type { Hooks } from './hooks';
|
|
5
|
+
import type { ModifyRuntimeConfigFn, OnBeforeRenderFn, PickContextFn, WrapRootFn } from './hooks';
|
|
6
|
+
import type { RuntimePluginExtends } from './plugin';
|
|
7
|
+
export type RuntimePluginAPI<Extends extends RuntimePluginExtends> = Readonly<{
|
|
8
|
+
updateRuntimeContext: (updateContext: DeepPartial<RuntimeContext>) => void;
|
|
9
|
+
getHooks: () => Readonly<Hooks<Extends['config'], RuntimeContext & Extends['extendContext']> & Extends['extendHooks']>;
|
|
10
|
+
getRuntimeConfig: () => Readonly<Extends['config']>;
|
|
11
|
+
onBeforeRender: PluginHookTap<OnBeforeRenderFn<Extends['extendContext']>>;
|
|
12
|
+
wrapRoot: PluginHookTap<WrapRootFn>;
|
|
13
|
+
pickContext: PluginHookTap<PickContextFn<RuntimeContext>>;
|
|
14
|
+
modifyRuntimeConfig: PluginHookTap<ModifyRuntimeConfigFn<Extends['config']>>;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RuntimePluginAPI } from './api';
|
|
2
|
+
import type { Hooks } from './hooks';
|
|
3
|
+
import type { RuntimePluginExtends } from './plugin';
|
|
4
|
+
export type RuntimeContext = {};
|
|
5
|
+
export type InternalRuntimeContext<Extends extends RuntimePluginExtends> = RuntimeContext & {
|
|
6
|
+
/** All hooks. */
|
|
7
|
+
hooks: Hooks<Extends['config'], RuntimeContext & Extends['extendContext']> & Extends['extendHooks'];
|
|
8
|
+
/** All plugin registry hooks */
|
|
9
|
+
extendsHooks: Extends['extendHooks'];
|
|
10
|
+
config: Extends['config'];
|
|
11
|
+
pluginAPI?: RuntimePluginAPI<Extends>;
|
|
12
|
+
_internalContext?: InternalRuntimeContext<Extends>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { AsyncInterruptHook, CollectSyncHook, SyncHook } from '../hooks';
|
|
3
|
+
export type OnBeforeRenderFn<RuntimeContext> = (context: RuntimeContext, interrupt: (info: any) => any) => Promise<any> | any;
|
|
4
|
+
export type WrapRootFn = (root: React.ComponentType<any>) => React.ComponentType<any>;
|
|
5
|
+
export type PickContextFn<RuntimeContext> = (context: RuntimeContext) => RuntimeContext;
|
|
6
|
+
export type ModifyRuntimeConfigFn<RuntimeConfig> = (config: RuntimeConfig) => RuntimeConfig;
|
|
7
|
+
export type Hooks<RuntimeConfig, RuntimeContext> = {
|
|
8
|
+
onBeforeRender: AsyncInterruptHook<OnBeforeRenderFn<RuntimeContext>>;
|
|
9
|
+
wrapRoot: SyncHook<WrapRootFn>;
|
|
10
|
+
pickContext: SyncHook<PickContextFn<RuntimeContext>>;
|
|
11
|
+
modifyRuntimeConfig: CollectSyncHook<ModifyRuntimeConfigFn<RuntimeConfig>>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PluginHook } from '../hooks';
|
|
2
|
+
import type { Plugin } from '../plugin';
|
|
3
|
+
import type { RuntimePluginAPI } from './api';
|
|
4
|
+
import type { RuntimeContext } from './context';
|
|
5
|
+
export interface RuntimePluginExtends<Config extends Record<string, any> = {}, ExtendContext extends Record<string, any> = {}, ExtendAPI extends Record<string, any> = {}, ExtendHook extends Record<string, PluginHook<(...args: any[]) => any>> = {}> {
|
|
6
|
+
config?: Config;
|
|
7
|
+
extendContext?: ExtendContext;
|
|
8
|
+
extendApi?: ExtendAPI;
|
|
9
|
+
extendHooks?: ExtendHook;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The type of the Runtime plugin object.
|
|
13
|
+
*/
|
|
14
|
+
export type RuntimePlugin<Extends extends RuntimePluginExtends> = Plugin<RuntimePluginAPI<Extends> & Extends['extendApi'], RuntimeContext & Extends['extendContext']>;
|