@bleedingdev/modern-js-plugin 3.2.0-ultramodern.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.
Files changed (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +26 -0
  3. package/dist/cjs/cli/api.js +119 -0
  4. package/dist/cjs/cli/context.js +85 -0
  5. package/dist/cjs/cli/hooks.js +65 -0
  6. package/dist/cjs/cli/index.js +71 -0
  7. package/dist/cjs/cli/run/config/createLoadedConfig.js +87 -0
  8. package/dist/cjs/cli/run/config/createResolvedConfig.js +48 -0
  9. package/dist/cjs/cli/run/config/loadConfig.js +113 -0
  10. package/dist/cjs/cli/run/create.js +198 -0
  11. package/dist/cjs/cli/run/index.js +56 -0
  12. package/dist/cjs/cli/run/run.js +57 -0
  13. package/dist/cjs/cli/run/types.js +18 -0
  14. package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
  15. package/dist/cjs/cli/run/utils/commander.js +56 -0
  16. package/dist/cjs/cli/run/utils/createFileWatcher.js +112 -0
  17. package/dist/cjs/cli/run/utils/debug.js +37 -0
  18. package/dist/cjs/cli/run/utils/initAppDir.js +55 -0
  19. package/dist/cjs/cli/run/utils/mergeConfig.js +66 -0
  20. package/dist/cjs/hooks.js +169 -0
  21. package/dist/cjs/index.js +55 -0
  22. package/dist/cjs/manager.js +135 -0
  23. package/dist/cjs/runtime/api.js +95 -0
  24. package/dist/cjs/runtime/context.js +60 -0
  25. package/dist/cjs/runtime/hooks.js +46 -0
  26. package/dist/cjs/runtime/index.js +51 -0
  27. package/dist/cjs/runtime/run/create.js +79 -0
  28. package/dist/cjs/runtime/run/index.js +37 -0
  29. package/dist/cjs/runtime/run/types.js +18 -0
  30. package/dist/cjs/server/api.js +96 -0
  31. package/dist/cjs/server/context.js +75 -0
  32. package/dist/cjs/server/hooks.js +43 -0
  33. package/dist/cjs/server/index.js +54 -0
  34. package/dist/cjs/server/run/create.js +79 -0
  35. package/dist/cjs/server/run/index.js +40 -0
  36. package/dist/cjs/server/run/types.js +18 -0
  37. package/dist/cjs/types/cli/api.js +18 -0
  38. package/dist/cjs/types/cli/context.js +18 -0
  39. package/dist/cjs/types/cli/hooks.js +18 -0
  40. package/dist/cjs/types/cli/index.js +18 -0
  41. package/dist/cjs/types/cli/plugin.js +18 -0
  42. package/dist/cjs/types/hooks.js +18 -0
  43. package/dist/cjs/types/index.js +18 -0
  44. package/dist/cjs/types/plugin.js +18 -0
  45. package/dist/cjs/types/runtime/api.js +18 -0
  46. package/dist/cjs/types/runtime/context.js +18 -0
  47. package/dist/cjs/types/runtime/hooks.js +18 -0
  48. package/dist/cjs/types/runtime/index.js +18 -0
  49. package/dist/cjs/types/runtime/plugin.js +18 -0
  50. package/dist/cjs/types/server/api.js +18 -0
  51. package/dist/cjs/types/server/context.js +18 -0
  52. package/dist/cjs/types/server/hooks.js +18 -0
  53. package/dist/cjs/types/server/index.js +18 -0
  54. package/dist/cjs/types/server/plugin.js +18 -0
  55. package/dist/cjs/types/utils.js +18 -0
  56. package/dist/esm/cli/api.mjs +85 -0
  57. package/dist/esm/cli/context.mjs +38 -0
  58. package/dist/esm/cli/hooks.mjs +31 -0
  59. package/dist/esm/cli/index.mjs +6 -0
  60. package/dist/esm/cli/run/config/createLoadedConfig.mjs +53 -0
  61. package/dist/esm/cli/run/config/createResolvedConfig.mjs +14 -0
  62. package/dist/esm/cli/run/config/loadConfig.mjs +60 -0
  63. package/dist/esm/cli/run/create.mjs +158 -0
  64. package/dist/esm/cli/run/index.mjs +7 -0
  65. package/dist/esm/cli/run/run.mjs +23 -0
  66. package/dist/esm/cli/run/types.mjs +0 -0
  67. package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
  68. package/dist/esm/cli/run/utils/commander.mjs +16 -0
  69. package/dist/esm/cli/run/utils/createFileWatcher.mjs +68 -0
  70. package/dist/esm/cli/run/utils/debug.mjs +3 -0
  71. package/dist/esm/cli/run/utils/initAppDir.mjs +11 -0
  72. package/dist/esm/cli/run/utils/mergeConfig.mjs +32 -0
  73. package/dist/esm/hooks.mjs +120 -0
  74. package/dist/esm/index.mjs +2 -0
  75. package/dist/esm/manager.mjs +101 -0
  76. package/dist/esm/runtime/api.mjs +61 -0
  77. package/dist/esm/runtime/context.mjs +23 -0
  78. package/dist/esm/runtime/hooks.mjs +12 -0
  79. package/dist/esm/runtime/index.mjs +4 -0
  80. package/dist/esm/runtime/run/create.mjs +45 -0
  81. package/dist/esm/runtime/run/index.mjs +3 -0
  82. package/dist/esm/runtime/run/types.mjs +0 -0
  83. package/dist/esm/server/api.mjs +59 -0
  84. package/dist/esm/server/context.mjs +38 -0
  85. package/dist/esm/server/hooks.mjs +9 -0
  86. package/dist/esm/server/index.mjs +4 -0
  87. package/dist/esm/server/run/create.mjs +45 -0
  88. package/dist/esm/server/run/index.mjs +3 -0
  89. package/dist/esm/server/run/types.mjs +0 -0
  90. package/dist/esm/types/cli/api.mjs +0 -0
  91. package/dist/esm/types/cli/context.mjs +0 -0
  92. package/dist/esm/types/cli/hooks.mjs +0 -0
  93. package/dist/esm/types/cli/index.mjs +0 -0
  94. package/dist/esm/types/cli/plugin.mjs +0 -0
  95. package/dist/esm/types/hooks.mjs +0 -0
  96. package/dist/esm/types/index.mjs +0 -0
  97. package/dist/esm/types/plugin.mjs +0 -0
  98. package/dist/esm/types/runtime/api.mjs +0 -0
  99. package/dist/esm/types/runtime/context.mjs +0 -0
  100. package/dist/esm/types/runtime/hooks.mjs +0 -0
  101. package/dist/esm/types/runtime/index.mjs +0 -0
  102. package/dist/esm/types/runtime/plugin.mjs +0 -0
  103. package/dist/esm/types/server/api.mjs +0 -0
  104. package/dist/esm/types/server/context.mjs +0 -0
  105. package/dist/esm/types/server/hooks.mjs +0 -0
  106. package/dist/esm/types/server/index.mjs +0 -0
  107. package/dist/esm/types/server/plugin.mjs +0 -0
  108. package/dist/esm/types/utils.mjs +0 -0
  109. package/dist/esm-node/cli/api.mjs +86 -0
  110. package/dist/esm-node/cli/context.mjs +39 -0
  111. package/dist/esm-node/cli/hooks.mjs +32 -0
  112. package/dist/esm-node/cli/index.mjs +7 -0
  113. package/dist/esm-node/cli/run/config/createLoadedConfig.mjs +54 -0
  114. package/dist/esm-node/cli/run/config/createResolvedConfig.mjs +15 -0
  115. package/dist/esm-node/cli/run/config/loadConfig.mjs +63 -0
  116. package/dist/esm-node/cli/run/create.mjs +159 -0
  117. package/dist/esm-node/cli/run/index.mjs +8 -0
  118. package/dist/esm-node/cli/run/run.mjs +24 -0
  119. package/dist/esm-node/cli/run/types.mjs +1 -0
  120. package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.mjs +12 -0
  121. package/dist/esm-node/cli/run/utils/commander.mjs +17 -0
  122. package/dist/esm-node/cli/run/utils/createFileWatcher.mjs +69 -0
  123. package/dist/esm-node/cli/run/utils/debug.mjs +4 -0
  124. package/dist/esm-node/cli/run/utils/initAppDir.mjs +12 -0
  125. package/dist/esm-node/cli/run/utils/mergeConfig.mjs +33 -0
  126. package/dist/esm-node/hooks.mjs +121 -0
  127. package/dist/esm-node/index.mjs +3 -0
  128. package/dist/esm-node/manager.mjs +102 -0
  129. package/dist/esm-node/runtime/api.mjs +62 -0
  130. package/dist/esm-node/runtime/context.mjs +24 -0
  131. package/dist/esm-node/runtime/hooks.mjs +13 -0
  132. package/dist/esm-node/runtime/index.mjs +5 -0
  133. package/dist/esm-node/runtime/run/create.mjs +46 -0
  134. package/dist/esm-node/runtime/run/index.mjs +4 -0
  135. package/dist/esm-node/runtime/run/types.mjs +1 -0
  136. package/dist/esm-node/server/api.mjs +60 -0
  137. package/dist/esm-node/server/context.mjs +39 -0
  138. package/dist/esm-node/server/hooks.mjs +10 -0
  139. package/dist/esm-node/server/index.mjs +5 -0
  140. package/dist/esm-node/server/run/create.mjs +46 -0
  141. package/dist/esm-node/server/run/index.mjs +4 -0
  142. package/dist/esm-node/server/run/types.mjs +1 -0
  143. package/dist/esm-node/types/cli/api.mjs +1 -0
  144. package/dist/esm-node/types/cli/context.mjs +1 -0
  145. package/dist/esm-node/types/cli/hooks.mjs +1 -0
  146. package/dist/esm-node/types/cli/index.mjs +1 -0
  147. package/dist/esm-node/types/cli/plugin.mjs +1 -0
  148. package/dist/esm-node/types/hooks.mjs +1 -0
  149. package/dist/esm-node/types/index.mjs +1 -0
  150. package/dist/esm-node/types/plugin.mjs +1 -0
  151. package/dist/esm-node/types/runtime/api.mjs +1 -0
  152. package/dist/esm-node/types/runtime/context.mjs +1 -0
  153. package/dist/esm-node/types/runtime/hooks.mjs +1 -0
  154. package/dist/esm-node/types/runtime/index.mjs +1 -0
  155. package/dist/esm-node/types/runtime/plugin.mjs +1 -0
  156. package/dist/esm-node/types/server/api.mjs +1 -0
  157. package/dist/esm-node/types/server/context.mjs +1 -0
  158. package/dist/esm-node/types/server/hooks.mjs +1 -0
  159. package/dist/esm-node/types/server/index.mjs +1 -0
  160. package/dist/esm-node/types/server/plugin.mjs +1 -0
  161. package/dist/esm-node/types/utils.mjs +1 -0
  162. package/dist/types/cli/api.d.ts +8 -0
  163. package/dist/types/cli/context.d.ts +19 -0
  164. package/dist/types/cli/hooks.d.ts +42 -0
  165. package/dist/types/cli/index.d.ts +6 -0
  166. package/dist/types/cli/run/config/createLoadedConfig.d.ts +2 -0
  167. package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
  168. package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
  169. package/dist/types/cli/run/create.d.ts +24 -0
  170. package/dist/types/cli/run/index.d.ts +13 -0
  171. package/dist/types/cli/run/run.d.ts +2 -0
  172. package/dist/types/cli/run/types.d.ts +32 -0
  173. package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
  174. package/dist/types/cli/run/utils/commander.d.ts +5 -0
  175. package/dist/types/cli/run/utils/createFileWatcher.d.ts +3 -0
  176. package/dist/types/cli/run/utils/debug.d.ts +1 -0
  177. package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
  178. package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
  179. package/dist/types/hooks.d.ts +7 -0
  180. package/dist/types/index.d.ts +7 -0
  181. package/dist/types/manager.d.ts +5 -0
  182. package/dist/types/runtime/api.d.ts +9 -0
  183. package/dist/types/runtime/context.d.ts +11 -0
  184. package/dist/types/runtime/hooks.d.ts +2 -0
  185. package/dist/types/runtime/index.d.ts +5 -0
  186. package/dist/types/runtime/run/create.d.ts +7 -0
  187. package/dist/types/runtime/run/index.d.ts +5 -0
  188. package/dist/types/runtime/run/types.d.ts +6 -0
  189. package/dist/types/server/api.d.ts +9 -0
  190. package/dist/types/server/context.d.ts +13 -0
  191. package/dist/types/server/hooks.d.ts +9 -0
  192. package/dist/types/server/index.d.ts +4 -0
  193. package/dist/types/server/run/create.d.ts +7 -0
  194. package/dist/types/server/run/index.d.ts +8 -0
  195. package/dist/types/server/run/types.d.ts +22 -0
  196. package/dist/types/types/cli/api.d.ts +49 -0
  197. package/dist/types/types/cli/context.d.ts +42 -0
  198. package/dist/types/types/cli/hooks.d.ts +72 -0
  199. package/dist/types/types/cli/index.d.ts +4 -0
  200. package/dist/types/types/cli/plugin.d.ts +17 -0
  201. package/dist/types/types/hooks.d.ts +27 -0
  202. package/dist/types/types/index.d.ts +4 -0
  203. package/dist/types/types/plugin.d.ts +45 -0
  204. package/dist/types/types/runtime/api.d.ts +21 -0
  205. package/dist/types/types/runtime/context.d.ts +13 -0
  206. package/dist/types/types/runtime/hooks.d.ts +39 -0
  207. package/dist/types/types/runtime/index.d.ts +4 -0
  208. package/dist/types/types/runtime/plugin.d.ts +14 -0
  209. package/dist/types/types/server/api.d.ts +19 -0
  210. package/dist/types/types/server/context.d.ts +28 -0
  211. package/dist/types/types/server/hooks.d.ts +24 -0
  212. package/dist/types/types/server/index.d.ts +4 -0
  213. package/dist/types/types/server/plugin.d.ts +14 -0
  214. package/dist/types/types/utils.d.ts +7 -0
  215. package/package.json +111 -0
  216. package/rslib.config.mts +4 -0
  217. package/rstest.config.mts +5 -0
@@ -0,0 +1,5 @@
1
+ import "node:module";
2
+ export { initPluginAPI } from "./api.mjs";
3
+ export { createRuntimeContext, initRuntimeContext } from "./context.mjs";
4
+ export { initHooks } from "./hooks.mjs";
5
+ export { runtime } from "./run/index.mjs";
@@ -0,0 +1,46 @@
1
+ import "node:module";
2
+ import { merge } from "@modern-js/runtime-utils/merge";
3
+ import { createPluginManager } from "../../manager.mjs";
4
+ import { initPluginAPI } from "../api.mjs";
5
+ import { createRuntimeContext, initRuntimeContext } from "../context.mjs";
6
+ const createRuntime = ()=>{
7
+ let initOptions;
8
+ const pluginManager = createPluginManager();
9
+ function init(options) {
10
+ pluginManager.clear();
11
+ initOptions = options;
12
+ const { plugins: allPlugins, handleSetupResult } = options;
13
+ pluginManager.addPlugins(allPlugins);
14
+ const plugins = pluginManager.getPlugins();
15
+ const context = createRuntimeContext({
16
+ runtimeContext: initRuntimeContext(),
17
+ config: initOptions.config,
18
+ plugins
19
+ });
20
+ const pluginAPI = initPluginAPI({
21
+ context,
22
+ pluginManager,
23
+ plugins
24
+ });
25
+ context.pluginAPI = pluginAPI;
26
+ for (const plugin of plugins){
27
+ const setupResult = plugin.setup?.(pluginAPI);
28
+ if (handleSetupResult) handleSetupResult(setupResult, pluginAPI);
29
+ }
30
+ return {
31
+ runtimeContext: context
32
+ };
33
+ }
34
+ function run(options) {
35
+ const { runtimeContext } = init(options);
36
+ const configs = runtimeContext.hooks.config.call().filter((config)=>Boolean(config));
37
+ runtimeContext.config = merge({}, ...configs, runtimeContext.config || {});
38
+ return {
39
+ runtimeContext
40
+ };
41
+ }
42
+ return {
43
+ run
44
+ };
45
+ };
46
+ export { createRuntime };
@@ -0,0 +1,4 @@
1
+ import "node:module";
2
+ import { createRuntime } from "./create.mjs";
3
+ const runtime = createRuntime();
4
+ export { runtime };
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1,60 @@
1
+ import "node:module";
2
+ import { createDebugger } from "@modern-js/utils";
3
+ import { assign as lodash_assign } from "@modern-js/utils/lodash";
4
+ const debug = createDebugger('plugin-server-v2');
5
+ function initPluginAPI({ context, pluginManager }) {
6
+ const { hooks, extendsHooks, plugins } = context;
7
+ function getServerContext() {
8
+ if (context) {
9
+ const { hooks, extendsHooks, config, pluginAPI, ...serverContext } = context;
10
+ serverContext._internalContext = context;
11
+ return serverContext;
12
+ }
13
+ throw new Error('Cannot access context');
14
+ }
15
+ function getConfig() {
16
+ if (context.config) return context.config;
17
+ throw new Error('Cannot access config');
18
+ }
19
+ function getHooks() {
20
+ return context.hooks;
21
+ }
22
+ const extendsPluginApi = {};
23
+ plugins.forEach((plugin)=>{
24
+ const { _registryApi } = plugin;
25
+ if (_registryApi) {
26
+ const apis = _registryApi(getServerContext, updateServerContext);
27
+ Object.keys(apis).forEach((apiName)=>{
28
+ extendsPluginApi[apiName] = apis[apiName];
29
+ });
30
+ }
31
+ });
32
+ if (extendsHooks) Object.keys(extendsHooks).forEach((hookName)=>{
33
+ extendsPluginApi[hookName] = extendsHooks[hookName].tap;
34
+ });
35
+ function updateServerContext(updateContext) {
36
+ context = lodash_assign(context, updateContext);
37
+ }
38
+ const pluginAPI = {
39
+ isPluginExists: pluginManager.isPluginExists,
40
+ getServerContext,
41
+ getServerConfig: getConfig,
42
+ getHooks,
43
+ updateServerContext,
44
+ modifyConfig: hooks.modifyConfig.tap,
45
+ onPrepare: hooks.onPrepare.tap,
46
+ onReset: hooks.onReset.tap,
47
+ ...extendsPluginApi
48
+ };
49
+ if ("u" < typeof Proxy) return pluginAPI;
50
+ return new Proxy(pluginAPI, {
51
+ get (target, prop) {
52
+ if ('then' === prop) return;
53
+ if (prop in target) return target[prop];
54
+ return ()=>{
55
+ debug(`api.${prop.toString()} not exist`);
56
+ };
57
+ }
58
+ });
59
+ }
60
+ export { debug, initPluginAPI };
@@ -0,0 +1,39 @@
1
+ import "node:module";
2
+ import { initHooks } from "./hooks.mjs";
3
+ function initServerContext(params) {
4
+ const { options, plugins } = params;
5
+ return {
6
+ routes: options.routes || [],
7
+ appDirectory: options.appContext.appDirectory || '',
8
+ apiDirectory: options.appContext.apiDirectory,
9
+ lambdaDirectory: options.appContext.lambdaDirectory,
10
+ internalDirectory: options.appContext.internalDirectory || '',
11
+ sharedDirectory: options.appContext.sharedDirectory || '',
12
+ distDirectory: options.pwd,
13
+ metaName: options.metaName || 'modern-js',
14
+ plugins: plugins,
15
+ middlewares: [],
16
+ bffRuntimeFramework: options.appContext.bffRuntimeFramework,
17
+ renderMiddlewares: []
18
+ };
19
+ }
20
+ function createServerContext({ serverContext, config }) {
21
+ const { plugins } = serverContext;
22
+ const extendsHooks = {};
23
+ plugins.forEach((plugin)=>{
24
+ const { registryHooks = {} } = plugin;
25
+ Object.keys(registryHooks).forEach((hookName)=>{
26
+ extendsHooks[hookName] = registryHooks[hookName];
27
+ });
28
+ });
29
+ return {
30
+ ...serverContext,
31
+ hooks: {
32
+ ...initHooks(),
33
+ ...extendsHooks
34
+ },
35
+ extendsHooks,
36
+ config
37
+ };
38
+ }
39
+ export { createServerContext, initServerContext };
@@ -0,0 +1,10 @@
1
+ import "node:module";
2
+ import { createAsyncHook } from "../hooks.mjs";
3
+ function initHooks() {
4
+ return {
5
+ modifyConfig: createAsyncHook(),
6
+ onPrepare: createAsyncHook(),
7
+ onReset: createAsyncHook()
8
+ };
9
+ }
10
+ export { initHooks };
@@ -0,0 +1,5 @@
1
+ import "node:module";
2
+ export { initPluginAPI } from "./api.mjs";
3
+ export { createServerContext, initServerContext } from "./context.mjs";
4
+ export { initHooks } from "./hooks.mjs";
5
+ export { createServer, server } from "./run/index.mjs";
@@ -0,0 +1,46 @@
1
+ import "node:module";
2
+ import { createPluginManager } from "../../manager.mjs";
3
+ import { initPluginAPI } from "../api.mjs";
4
+ import { createServerContext, initServerContext } from "../context.mjs";
5
+ const createServer = ()=>{
6
+ let initOptions;
7
+ const pluginManager = createPluginManager();
8
+ function init(options) {
9
+ pluginManager.clear();
10
+ initOptions = options;
11
+ const { plugins: allPlugins, options: runOptions, handleSetupResult } = initOptions;
12
+ pluginManager.addPlugins(allPlugins);
13
+ const plugins = pluginManager.getPlugins();
14
+ const context = createServerContext({
15
+ serverContext: initServerContext({
16
+ plugins,
17
+ options: runOptions
18
+ }),
19
+ config: initOptions.config
20
+ });
21
+ const pluginAPI = initPluginAPI({
22
+ context,
23
+ pluginManager
24
+ });
25
+ context.pluginAPI = pluginAPI;
26
+ for (const plugin of plugins){
27
+ const setupResult = plugin.setup?.(pluginAPI);
28
+ if (handleSetupResult) handleSetupResult(setupResult, pluginAPI);
29
+ }
30
+ return {
31
+ serverContext: context
32
+ };
33
+ }
34
+ async function run(options) {
35
+ const { serverContext } = init(options);
36
+ const config = await serverContext.hooks.modifyConfig.call(serverContext.config);
37
+ serverContext.config = config;
38
+ return {
39
+ serverContext
40
+ };
41
+ }
42
+ return {
43
+ run
44
+ };
45
+ };
46
+ export { createServer };
@@ -0,0 +1,4 @@
1
+ import "node:module";
2
+ import { createServer } from "./create.mjs";
3
+ const server = createServer();
4
+ export { createServer, server };
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -0,0 +1,8 @@
1
+ import type { CLIPluginAPI } from '../types/cli/api';
2
+ import type { InternalContext } from '../types/cli/context';
3
+ import type { CLIPluginExtends } from '../types/cli/plugin';
4
+ import type { PluginManager } from '../types/plugin';
5
+ export declare function initPluginAPI<Extends extends CLIPluginExtends>({ context, pluginManager, }: {
6
+ context: InternalContext<Extends>;
7
+ pluginManager: PluginManager;
8
+ }): CLIPluginAPI<Extends>;
@@ -0,0 +1,19 @@
1
+ import type { AppContext, InternalContext } from '../types/cli/context';
2
+ import type { CLIPlugin, CLIPluginExtends } from '../types/cli/plugin';
3
+ interface ContextParams<Extends extends CLIPluginExtends> {
4
+ appContext: AppContext<Extends>;
5
+ config: Extends['config'];
6
+ normalizedConfig: Extends['normalizedConfig'];
7
+ }
8
+ export declare function initAppContext<Extends extends CLIPluginExtends>(params: {
9
+ packageName: string;
10
+ configFile: string;
11
+ command: string;
12
+ appDirectory: string;
13
+ metaName: string;
14
+ plugins: CLIPlugin<Extends>[];
15
+ srcDir?: string;
16
+ distDir?: string;
17
+ }): AppContext<Extends>;
18
+ export declare function createContext<Extends extends CLIPluginExtends>({ appContext, config, normalizedConfig, }: ContextParams<Extends>): Promise<InternalContext<Extends>>;
19
+ export {};
@@ -0,0 +1,42 @@
1
+ import type { OnAfterBuildFn, OnAfterCreateCompilerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn } from '@rsbuild/core';
2
+ import type { AddCommandFn, AddWatchFilesFn, ConfigFn, InternalRuntimePluginsFn, InternalServerPluginsFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyServerRoutesFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnFileChangedFn, OnPrepareFn, RuntimePluginConfig, ServerPluginConfig } from '../types/cli/hooks';
3
+ import type { DeepPartial } from '../types/utils';
4
+ export type { AddCommandFn, AddWatchFilesFn, ConfigFn, InternalRuntimePluginsFn, InternalServerPluginsFn, ModifyBundlerChainFn, ModifyConfigFn, ModifyHtmlPartialsFn, ModifyResolvedConfigFn, ModifyRsbuildConfigFn, ModifyRspackConfigFn, ModifyServerRoutesFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterDeployFn, OnAfterDevFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeDeployFn, OnBeforeDevFn, OnBeforeExitFn, OnBeforeRestartFn, OnDevCompileDoneFn, OnFileChangedFn, OnPrepareFn, RuntimePluginConfig, ServerPluginConfig, };
5
+ export declare function initHooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils>(): {
6
+ /**
7
+ * add config for this cli plugin
8
+ */
9
+ config: import("..").CollectAsyncHook<ConfigFn<DeepPartial<Config>>>;
10
+ /**
11
+ * @private
12
+ * modify config for this cli plugin
13
+ */
14
+ modifyConfig: import("..").AsyncHook<ModifyConfigFn<Config, ExtendConfigUtils>>;
15
+ /**
16
+ * modify final config
17
+ */
18
+ modifyResolvedConfig: import("..").AsyncHook<ModifyResolvedConfigFn<NormalizedConfig, ExtendConfigUtils>>;
19
+ modifyRsbuildConfig: import("..").AsyncHook<ModifyRsbuildConfigFn<ExtendBuildUtils>>;
20
+ modifyBundlerChain: import("..").AsyncHook<ModifyBundlerChainFn<ExtendBuildUtils>>;
21
+ modifyRspackConfig: import("..").AsyncHook<ModifyRspackConfigFn<ExtendBuildUtils>>;
22
+ modifyHtmlPartials: import("..").AsyncHook<ModifyHtmlPartialsFn>;
23
+ addCommand: import("..").AsyncHook<AddCommandFn>;
24
+ addWatchFiles: import("..").CollectAsyncHook<AddWatchFilesFn>;
25
+ onPrepare: import("..").AsyncHook<OnPrepareFn>;
26
+ onFileChanged: import("..").AsyncHook<OnFileChangedFn>;
27
+ onBeforeRestart: import("..").AsyncHook<OnBeforeRestartFn>;
28
+ onBeforeCreateCompiler: import("..").AsyncHook<OnBeforeCreateCompilerFn>;
29
+ onAfterCreateCompiler: import("..").AsyncHook<OnAfterCreateCompilerFn>;
30
+ onDevCompileDone: import("..").AsyncHook<import("@rsbuild/core").OnAfterDevCompileFn>;
31
+ onBeforeBuild: import("..").AsyncHook<OnBeforeBuildFn>;
32
+ onAfterBuild: import("..").AsyncHook<OnAfterBuildFn>;
33
+ onBeforeDev: import("..").AsyncHook<OnBeforeDevFn>;
34
+ onAfterDev: import("..").AsyncHook<OnAfterDevFn>;
35
+ onBeforeDeploy: import("..").AsyncHook<OnBeforeDeployFn>;
36
+ onAfterDeploy: import("..").AsyncHook<OnAfterDeployFn>;
37
+ onBeforeExit: import("..").AsyncHook<OnBeforeExitFn>;
38
+ _internalRuntimePlugins: import("..").AsyncHook<InternalRuntimePluginsFn>;
39
+ _internalServerPlugins: import("..").AsyncHook<InternalServerPluginsFn>;
40
+ modifyServerRoutes: import("..").AsyncHook<ModifyServerRoutesFn>;
41
+ };
42
+ export type Hooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils> = ReturnType<typeof initHooks<Config, NormalizedConfig, ExtendBuildUtils, ExtendConfigUtils>>;
@@ -0,0 +1,6 @@
1
+ export { initPluginAPI } from './api';
2
+ export { createContext, initAppContext } from './context';
3
+ export { type AddCommandFn, type AddWatchFilesFn, type ConfigFn, type Hooks, type InternalRuntimePluginsFn, type InternalServerPluginsFn, initHooks, type ModifyBundlerChainFn, type ModifyConfigFn, type ModifyHtmlPartialsFn, type ModifyResolvedConfigFn, type ModifyRsbuildConfigFn, type ModifyRspackConfigFn, type ModifyServerRoutesFn, type OnAfterBuildFn, type OnAfterCreateCompilerFn, type OnAfterDeployFn, type OnAfterDevFn, type OnBeforeBuildFn, type OnBeforeCreateCompilerFn, type OnBeforeDeployFn, type OnBeforeDevFn, type OnBeforeExitFn, type OnBeforeRestartFn, type OnDevCompileDoneFn, type OnFileChangedFn, type OnPrepareFn, type RuntimePluginConfig, type ServerPluginConfig, } from './hooks';
4
+ export { cli, createCli, createLoadedConfig, initAppDir } from './run';
5
+ export { createConfigOptions, createStorybookOptions } from './run/create';
6
+ export { mergeConfig } from './run/utils/mergeConfig';
@@ -0,0 +1,2 @@
1
+ import type { LoadedConfig } from '../types';
2
+ export declare function createLoadedConfig<T>(appDirectory: string, configFilePath: string, otherConfig?: T): Promise<LoadedConfig<T>>;
@@ -0,0 +1,3 @@
1
+ import type { DeepPartial } from '../../../types/utils';
2
+ import type { LoadedConfig } from '../types';
3
+ export declare const createResolveConfig: <Config, NormalizedConfig>(loaded: LoadedConfig<Config>, configs: DeepPartial<Config>[]) => Promise<NormalizedConfig>;
@@ -0,0 +1,25 @@
1
+ export declare const getConfigFilePath: (appDirectory: string, configFilePath: string) => string;
2
+ /**
3
+ *
4
+ * @param targetDir target dir
5
+ * @param overtime Unit of second
6
+ */
7
+ export declare const clearFilesOverTime: (targetDir: string, overtime: number) => Promise<void>;
8
+ /**
9
+ * Parse and load user config file, support extensions like .ts, mjs, js, ejs.
10
+ * @param appDirectory - App root directory, from which start search user config file.
11
+ * @param configFile - Specific absolute config file path.
12
+ * @returns Object contain config file path, user config object and dependency files used by config file.
13
+ */
14
+ /**
15
+ * Load a TypeScript file dynamically using jiti
16
+ * @param {string} filePath - Path to the TypeScript file (absolute or relative)
17
+ * @returns {any} - The loaded module object
18
+ */
19
+ export declare const loadTypeScriptFile: (filePath: string) => any;
20
+ export declare const loadConfig: <T>(appDirectory: string, configFile: string) => Promise<{
21
+ packageName: string;
22
+ configFile: string;
23
+ config?: T;
24
+ pkgConfig?: T;
25
+ }>;
@@ -0,0 +1,24 @@
1
+ import type { InternalContext } from '../../types/cli/context';
2
+ import type { CLIPluginExtends } from '../../types/cli/plugin';
3
+ import type { CLIRunOptions } from './types';
4
+ export declare const createCli: <Extends extends CLIPluginExtends>() => {
5
+ init: (options: CLIRunOptions<Extends>) => Promise<{
6
+ appContext: InternalContext<Extends>;
7
+ }>;
8
+ run: (options: CLIRunOptions<Extends>) => Promise<void>;
9
+ getPrevInitOptions: () => CLIRunOptions<Extends>;
10
+ };
11
+ type UselessOptions = 'handleSetupResult' | 'command' | 'internalPlugins';
12
+ type CreateConfigOption<Extends extends CLIPluginExtends> = Omit<CLIRunOptions<Extends>, UselessOptions> & {
13
+ command: string;
14
+ modifyModernConfig?: (config: Extends['config']) => Extends['config'] | Promise<Extends['config']>;
15
+ };
16
+ export declare const createConfigOptions: <Extends extends CLIPluginExtends>(options: CreateConfigOption<Extends>) => Promise<{
17
+ config: Awaited<Extends["normalizedConfig"]> | NonNullable<Awaited<import("../../types/utils").UnwrapPromise<Extends["normalizedConfig"]>>>;
18
+ getAppContext: () => Readonly<import("../../types/cli/context").AppContext<Extends> & Extends["extendContext"]>;
19
+ }>;
20
+ export declare const createStorybookOptions: <Extends extends CLIPluginExtends>(options: Omit<CreateConfigOption<Extends>, "command">) => Promise<{
21
+ config: Awaited<Extends["normalizedConfig"]> | NonNullable<Awaited<import("../../types/utils").UnwrapPromise<Extends["normalizedConfig"]>>>;
22
+ getAppContext: () => Readonly<import("../../types/cli/context").AppContext<Extends> & Extends["extendContext"]>;
23
+ }>;
24
+ export {};
@@ -0,0 +1,13 @@
1
+ import { createCli } from './create';
2
+ export { createLoadedConfig } from './config/createLoadedConfig';
3
+ export { loadTypeScriptFile } from './config/loadConfig';
4
+ export { run } from './run';
5
+ export { initAppDir } from './utils/initAppDir';
6
+ export { createCli };
7
+ export declare const cli: {
8
+ init: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>) => Promise<{
9
+ appContext: import("../..").InternalContext<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>;
10
+ }>;
11
+ run: (options: import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>) => Promise<void>;
12
+ getPrevInitOptions: () => import("./types").CLIRunOptions<import("../..").CLIPluginExtends<{}, {}, {}, {}, {}, {}, {}>>;
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { CLIOptions } from './types';
2
+ export declare const run: (options: CLIOptions) => Promise<void>;
@@ -0,0 +1,32 @@
1
+ import type { CLIPluginExtends } from '../../types/cli';
2
+ import type { Plugin } from '../../types/plugin';
3
+ export interface CLIOptions<Extends extends CLIPluginExtends = {
4
+ config: {};
5
+ }> {
6
+ cwd?: string;
7
+ version?: string;
8
+ metaName?: string;
9
+ /**
10
+ * The initial log message when CLI started
11
+ */
12
+ initialLog?: string;
13
+ /**
14
+ * other config, overrides config file content
15
+ */
16
+ config?: Extends['config'];
17
+ configFile: string;
18
+ internalPlugins?: Plugin[];
19
+ handleSetupResult?: (params: any, api: Record<string, any>) => Promise<void> | void;
20
+ }
21
+ export type LoadedConfig<T> = {
22
+ packageName: string;
23
+ configFile: string;
24
+ config: T;
25
+ pkgConfig?: T;
26
+ jsConfig?: T;
27
+ };
28
+ export interface CLIRunOptions<Extends extends CLIPluginExtends = {
29
+ config: {};
30
+ }> extends CLIOptions<Extends> {
31
+ command: string;
32
+ }
@@ -0,0 +1 @@
1
+ export declare function checkIsDuplicationPlugin(plugins: (string | undefined)[]): void;
@@ -0,0 +1,5 @@
1
+ import { type Command, program } from '@modern-js/utils';
2
+ export declare const setProgramVersion: (version?: string) => void;
3
+ export declare function initCommandsMap(): void;
4
+ export type { Command };
5
+ export { program };
@@ -0,0 +1,3 @@
1
+ import type { InternalContext } from '../../../types';
2
+ import type { CLIPluginExtends } from '../../../types/cli/plugin';
3
+ export declare const createFileWatcher: <Extends extends CLIPluginExtends>(appContext: InternalContext<Extends>) => Promise<import("@modern-js/utils").FSWatcher | undefined>;
@@ -0,0 +1 @@
1
+ export declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
@@ -0,0 +1 @@
1
+ export declare const initAppDir: (currentDir?: string) => Promise<string>;
@@ -0,0 +1,2 @@
1
+ import type { DeepPartial } from '../../../types/utils';
2
+ export declare const mergeConfig: <Config, NormalizedConfig>(configs: Array<DeepPartial<Config>>) => NormalizedConfig;
@@ -0,0 +1,7 @@
1
+ import type { AsyncHook, AsyncInterruptHook, AsyncPipelineHook, 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>;
4
+ export declare function createAsyncHook<Callback extends (...args: any[]) => any>(): AsyncHook<Callback>;
5
+ export declare function createCollectAsyncHook<Callback extends (...params: any[]) => any>(): CollectAsyncHook<Callback>;
6
+ export declare function createCollectSyncHook<Callback extends (...params: any[]) => any>(): CollectSyncHook<Callback>;
7
+ export declare function createAsyncPipelineHook<Callback extends (...args: any[]) => any>(): AsyncPipelineHook<Callback>;
@@ -0,0 +1,7 @@
1
+ export { createAsyncHook, createAsyncInterruptHook, createAsyncPipelineHook, createCollectAsyncHook, createCollectSyncHook, createSyncHook, } from './hooks';
2
+ export { createPluginManager } from './manager';
3
+ export type { AppContext, CLIPlugin, CLIPluginAPI, CLIPluginExtends, Entrypoint, InternalContext, RuntimePluginConfig, ServerPluginConfig, } from './types/cli';
4
+ export type { AsyncHook, AsyncInterruptHook, AsyncPipelineHook, CollectAsyncHook, CollectSyncHook, PluginHook, PluginHookTap, SyncHook, } from './types/hooks';
5
+ export type { Plugin, PluginManager, TransformFunction, } from './types/plugin';
6
+ export type { InternalRuntimeContext, RuntimeContext, RuntimePlugin, RuntimePluginAPI, RuntimePluginExtends, } from './types/runtime';
7
+ export type { FileChangeEvent, InternalServerContext, ResetEvent, ServerContext, ServerPlugin, ServerPluginAPI, ServerPluginExtends, } from './types/server';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * NOTE: This file will be used in both Node.js and runtime environments. Please avoid importing Node.js-specific APIs.
3
+ */
4
+ import type { PluginManager } from './types/plugin';
5
+ export declare function createPluginManager(): PluginManager;
@@ -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,2 @@
1
+ import type { Hooks } from '../types/runtime/hooks';
2
+ export declare function initHooks<RuntimeConfig, RuntimeContext>(): Hooks<RuntimeConfig, RuntimeContext>;
@@ -0,0 +1,5 @@
1
+ export type { Hooks, InternalRuntimeContext, RuntimeContext, RuntimePlugin, RuntimePluginAPI, RuntimePluginExtends, } from '../types/runtime';
2
+ export { initPluginAPI } from './api';
3
+ export { createRuntimeContext, initRuntimeContext } from './context';
4
+ export { initHooks } from './hooks';
5
+ export { runtime } from './run';
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ export declare const runtime: {
2
+ run: (options: import("./types").RuntimeRunOptions) => {
3
+ runtimeContext: import("..").InternalRuntimeContext<import("..").RuntimePluginExtends<{}, {}, {}, {}>>;
4
+ };
5
+ };
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../types/plugin';
2
+ export type RuntimeRunOptions = {
3
+ config: Record<string, any>;
4
+ plugins: Plugin[];
5
+ handleSetupResult?: (params: any, api: Record<string, any>) => Promise<void> | void;
6
+ };
@@ -0,0 +1,9 @@
1
+ import type { PluginManager } from '../types/plugin';
2
+ import type { ServerPluginAPI } from '../types/server/api';
3
+ import type { InternalServerContext } from '../types/server/context';
4
+ import type { ServerPluginExtends } from '../types/server/plugin';
5
+ export declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
6
+ export declare function initPluginAPI<Extends extends ServerPluginExtends>({ context, pluginManager, }: {
7
+ context: InternalServerContext<Extends>;
8
+ pluginManager: PluginManager;
9
+ }): ServerPluginAPI<Extends>;