@modern-js/plugin-v2 2.65.5 → 2.65.6-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/cjs/hooks.js +29 -0
  2. package/dist/cjs/index.js +2 -0
  3. package/dist/cjs/server/api.js +94 -0
  4. package/dist/cjs/server/context.js +64 -0
  5. package/dist/cjs/server/hooks.js +35 -0
  6. package/dist/cjs/server/index.js +41 -0
  7. package/dist/cjs/server/run/create.js +74 -0
  8. package/dist/cjs/server/run/index.js +31 -0
  9. package/dist/cjs/server/run/types.js +16 -0
  10. package/dist/cjs/types/server/api.js +16 -0
  11. package/dist/cjs/types/server/context.js +16 -0
  12. package/dist/cjs/types/server/hooks.js +16 -0
  13. package/dist/cjs/types/server/index.js +16 -0
  14. package/dist/cjs/types/server/plugin.js +16 -0
  15. package/dist/esm/hooks.js +129 -0
  16. package/dist/esm/index.js +2 -1
  17. package/dist/esm/server/api.js +76 -0
  18. package/dist/esm/server/context.js +38 -0
  19. package/dist/esm/server/hooks.js +11 -0
  20. package/dist/esm/server/index.js +12 -0
  21. package/dist/esm/server/run/create.js +89 -0
  22. package/dist/esm/server/run/index.js +6 -0
  23. package/dist/esm/server/run/types.js +0 -0
  24. package/dist/esm/types/server/api.js +0 -0
  25. package/dist/esm/types/server/context.js +0 -0
  26. package/dist/esm/types/server/hooks.js +0 -0
  27. package/dist/esm/types/server/index.js +0 -0
  28. package/dist/esm/types/server/plugin.js +0 -0
  29. package/dist/esm-node/hooks.js +28 -0
  30. package/dist/esm-node/index.js +2 -1
  31. package/dist/esm-node/server/api.js +69 -0
  32. package/dist/esm-node/server/context.js +39 -0
  33. package/dist/esm-node/server/hooks.js +11 -0
  34. package/dist/esm-node/server/index.js +12 -0
  35. package/dist/esm-node/server/run/create.js +50 -0
  36. package/dist/esm-node/server/run/index.js +6 -0
  37. package/dist/esm-node/server/run/types.js +0 -0
  38. package/dist/esm-node/types/server/api.js +0 -0
  39. package/dist/esm-node/types/server/context.js +0 -0
  40. package/dist/esm-node/types/server/hooks.js +0 -0
  41. package/dist/esm-node/types/server/index.js +0 -0
  42. package/dist/esm-node/types/server/plugin.js +0 -0
  43. package/dist/types/hooks.d.ts +2 -1
  44. package/dist/types/index.d.ts +3 -2
  45. package/dist/types/server/api.d.ts +9 -0
  46. package/dist/types/server/context.d.ts +13 -0
  47. package/dist/types/server/hooks.d.ts +9 -0
  48. package/dist/types/server/index.d.ts +4 -0
  49. package/dist/types/server/run/create.d.ts +7 -0
  50. package/dist/types/server/run/index.d.ts +8 -0
  51. package/dist/types/server/run/types.d.ts +21 -0
  52. package/dist/types/types/hooks.d.ts +5 -1
  53. package/dist/types/types/server/api.d.ts +19 -0
  54. package/dist/types/types/server/context.d.ts +28 -0
  55. package/dist/types/types/server/hooks.d.ts +24 -0
  56. package/dist/types/types/server/index.d.ts +4 -0
  57. package/dist/types/types/server/plugin.d.ts +14 -0
  58. package/package.json +17 -5
@@ -0,0 +1,76 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
3
+ import { createDebugger } from "@modern-js/utils";
4
+ import { assign } from "@modern-js/utils/lodash";
5
+ var debug = createDebugger("plugin-server-v2");
6
+ function initPluginAPI(param) {
7
+ var context = param.context, pluginManager = param.pluginManager;
8
+ var hooks = context.hooks, extendsHooks = context.extendsHooks, plugins = context.plugins;
9
+ function getServerContext() {
10
+ if (context) {
11
+ var hooks2 = context.hooks, extendsHooks2 = context.extendsHooks, config = context.config, pluginAPI2 = context.pluginAPI, serverContext = _object_without_properties(context, [
12
+ "hooks",
13
+ "extendsHooks",
14
+ "config",
15
+ "pluginAPI"
16
+ ]);
17
+ serverContext._internalContext = context;
18
+ return serverContext;
19
+ }
20
+ throw new Error("Cannot access context");
21
+ }
22
+ function getConfig() {
23
+ if (context.config) {
24
+ return context.config;
25
+ }
26
+ throw new Error("Cannot access config");
27
+ }
28
+ function getHooks() {
29
+ return context.hooks;
30
+ }
31
+ var extendsPluginApi = {};
32
+ plugins.forEach(function(plugin) {
33
+ var _registryApi = plugin._registryApi;
34
+ if (_registryApi) {
35
+ var apis = _registryApi(getServerContext, updateServerContext);
36
+ Object.keys(apis).forEach(function(apiName) {
37
+ extendsPluginApi[apiName] = apis[apiName];
38
+ });
39
+ }
40
+ });
41
+ if (extendsHooks) {
42
+ Object.keys(extendsHooks).forEach(function(hookName) {
43
+ extendsPluginApi[hookName] = extendsHooks[hookName].tap;
44
+ });
45
+ }
46
+ function updateServerContext(updateContext) {
47
+ context = assign(context, updateContext);
48
+ }
49
+ var pluginAPI = _object_spread({
50
+ isPluginExists: pluginManager.isPluginExists,
51
+ getServerContext,
52
+ getConfig,
53
+ getHooks,
54
+ updateServerContext,
55
+ modifyConfig: hooks.modifyConfig.tap,
56
+ onPrepare: hooks.onPrepare.tap,
57
+ onReset: hooks.onReset.tap
58
+ }, extendsPluginApi);
59
+ return new Proxy(pluginAPI, {
60
+ get: function get(target, prop) {
61
+ if (prop === "then") {
62
+ return void 0;
63
+ }
64
+ if (prop in target) {
65
+ return target[prop];
66
+ }
67
+ return function() {
68
+ debug("api.".concat(prop.toString(), " not exist"));
69
+ };
70
+ }
71
+ });
72
+ }
73
+ export {
74
+ debug,
75
+ initPluginAPI
76
+ };
@@ -0,0 +1,38 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
3
+ import { initHooks } from "./hooks";
4
+ function initServerContext(params) {
5
+ var options = params.options, plugins = params.plugins;
6
+ return {
7
+ routes: options.routes || [],
8
+ appDirectory: options.appContext.appDirectory || "",
9
+ apiDirectory: options.appContext.apiDirectory,
10
+ lambdaDirectory: options.appContext.lambdaDirectory,
11
+ internalDirectory: options.appContext.internalDirectory || "",
12
+ sharedDirectory: options.appContext.sharedDirectory || "",
13
+ distDirectory: options.pwd,
14
+ metaName: options.metaName || "modern-js",
15
+ plugins,
16
+ middlewares: []
17
+ };
18
+ }
19
+ function createServerContext(param) {
20
+ var serverContext = param.serverContext, config = param.config;
21
+ var plugins = serverContext.plugins;
22
+ var extendsHooks = {};
23
+ plugins.forEach(function(plugin) {
24
+ var _plugin_registryHooks = plugin.registryHooks, registryHooks = _plugin_registryHooks === void 0 ? {} : _plugin_registryHooks;
25
+ Object.keys(registryHooks).forEach(function(hookName) {
26
+ extendsHooks[hookName] = registryHooks[hookName];
27
+ });
28
+ });
29
+ return _object_spread_props(_object_spread({}, serverContext), {
30
+ hooks: _object_spread({}, initHooks(), extendsHooks),
31
+ extendsHooks,
32
+ config
33
+ });
34
+ }
35
+ export {
36
+ createServerContext,
37
+ initServerContext
38
+ };
@@ -0,0 +1,11 @@
1
+ import { createAsyncHook } from "../hooks";
2
+ function initHooks() {
3
+ return {
4
+ modifyConfig: createAsyncHook(),
5
+ onPrepare: createAsyncHook(),
6
+ onReset: createAsyncHook()
7
+ };
8
+ }
9
+ export {
10
+ initHooks
11
+ };
@@ -0,0 +1,12 @@
1
+ import { initPluginAPI } from "./api";
2
+ import { initServerContext, createServerContext } from "./context";
3
+ import { initHooks } from "./hooks";
4
+ import { server, createServer } from "./run";
5
+ export {
6
+ createServer,
7
+ createServerContext,
8
+ initHooks,
9
+ initPluginAPI,
10
+ initServerContext,
11
+ server
12
+ };
@@ -0,0 +1,89 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { createPluginManager } from "../../manager";
4
+ import { initPluginAPI } from "../../server/api";
5
+ import { createServerContext, initServerContext } from "../../server/context";
6
+ var createServer = function() {
7
+ var init = function init2(options) {
8
+ pluginManager.clear();
9
+ initOptions = options;
10
+ var allPlugins = initOptions.plugins, runOptions = initOptions.options, handleSetupResult = initOptions.handleSetupResult;
11
+ pluginManager.addPlugins(allPlugins);
12
+ var plugins = pluginManager.getPlugins();
13
+ var context = createServerContext({
14
+ serverContext: initServerContext({
15
+ plugins,
16
+ options: runOptions
17
+ }),
18
+ config: initOptions.config
19
+ });
20
+ var pluginAPI = initPluginAPI({
21
+ context,
22
+ pluginManager
23
+ });
24
+ context.pluginAPI = pluginAPI;
25
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
26
+ try {
27
+ for (var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
28
+ var plugin = _step.value;
29
+ var _plugin_setup;
30
+ var setupResult = (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI);
31
+ if (handleSetupResult) {
32
+ handleSetupResult(setupResult, pluginAPI);
33
+ }
34
+ }
35
+ } catch (err) {
36
+ _didIteratorError = true;
37
+ _iteratorError = err;
38
+ } finally {
39
+ try {
40
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
41
+ _iterator.return();
42
+ }
43
+ } finally {
44
+ if (_didIteratorError) {
45
+ throw _iteratorError;
46
+ }
47
+ }
48
+ }
49
+ return {
50
+ serverContext: context
51
+ };
52
+ };
53
+ var run = function run2(options) {
54
+ return _run.apply(this, arguments);
55
+ };
56
+ var initOptions;
57
+ var pluginManager = createPluginManager();
58
+ function _run() {
59
+ _run = _async_to_generator(function(options) {
60
+ var serverContext, config;
61
+ return _ts_generator(this, function(_state) {
62
+ switch (_state.label) {
63
+ case 0:
64
+ serverContext = init(options).serverContext;
65
+ return [
66
+ 4,
67
+ serverContext.hooks.modifyConfig.call(serverContext.config)
68
+ ];
69
+ case 1:
70
+ config = _state.sent();
71
+ serverContext.config = config;
72
+ return [
73
+ 2,
74
+ {
75
+ serverContext
76
+ }
77
+ ];
78
+ }
79
+ });
80
+ });
81
+ return _run.apply(this, arguments);
82
+ }
83
+ return {
84
+ run
85
+ };
86
+ };
87
+ export {
88
+ createServer
89
+ };
@@ -0,0 +1,6 @@
1
+ import { createServer } from "./create";
2
+ var server = createServer();
3
+ export {
4
+ createServer,
5
+ server
6
+ };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -103,9 +103,37 @@ function createCollectSyncHook() {
103
103
  call
104
104
  };
105
105
  }
106
+ function createAsyncPipelineHook() {
107
+ const callbacks = [];
108
+ const tap = (cb) => {
109
+ callbacks.push(cb);
110
+ };
111
+ const call = async (...params) => {
112
+ for (const callback of callbacks) {
113
+ let runNext = false;
114
+ const next = (info) => {
115
+ runNext = true;
116
+ if (info) {
117
+ params[0] = info;
118
+ }
119
+ };
120
+ const result = await callback(...params, next);
121
+ if (!runNext) {
122
+ params[0] = result;
123
+ break;
124
+ }
125
+ }
126
+ return params[0] || [];
127
+ };
128
+ return {
129
+ tap,
130
+ call
131
+ };
132
+ }
106
133
  export {
107
134
  createAsyncHook,
108
135
  createAsyncInterruptHook,
136
+ createAsyncPipelineHook,
109
137
  createCollectAsyncHook,
110
138
  createCollectSyncHook,
111
139
  createSyncHook
@@ -1,8 +1,9 @@
1
1
  import { createPluginManager } from "./manager";
2
- import { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook } from "./hooks";
2
+ import { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook, createAsyncPipelineHook } from "./hooks";
3
3
  export {
4
4
  createAsyncHook,
5
5
  createAsyncInterruptHook,
6
+ createAsyncPipelineHook,
6
7
  createCollectAsyncHook,
7
8
  createCollectSyncHook,
8
9
  createPluginManager,
@@ -0,0 +1,69 @@
1
+ import { createDebugger } from "@modern-js/utils";
2
+ import { assign } from "@modern-js/utils/lodash";
3
+ const debug = createDebugger("plugin-server-v2");
4
+ function initPluginAPI({ context, pluginManager }) {
5
+ const { hooks, extendsHooks, plugins } = context;
6
+ function getServerContext() {
7
+ if (context) {
8
+ const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI: pluginAPI2, ...serverContext } = context;
9
+ serverContext._internalContext = context;
10
+ return serverContext;
11
+ }
12
+ throw new Error("Cannot access context");
13
+ }
14
+ function getConfig() {
15
+ if (context.config) {
16
+ return context.config;
17
+ }
18
+ throw new Error("Cannot access config");
19
+ }
20
+ function getHooks() {
21
+ return context.hooks;
22
+ }
23
+ const extendsPluginApi = {};
24
+ plugins.forEach((plugin) => {
25
+ const { _registryApi } = plugin;
26
+ if (_registryApi) {
27
+ const apis = _registryApi(getServerContext, updateServerContext);
28
+ Object.keys(apis).forEach((apiName) => {
29
+ extendsPluginApi[apiName] = apis[apiName];
30
+ });
31
+ }
32
+ });
33
+ if (extendsHooks) {
34
+ Object.keys(extendsHooks).forEach((hookName) => {
35
+ extendsPluginApi[hookName] = extendsHooks[hookName].tap;
36
+ });
37
+ }
38
+ function updateServerContext(updateContext) {
39
+ context = assign(context, updateContext);
40
+ }
41
+ const pluginAPI = {
42
+ isPluginExists: pluginManager.isPluginExists,
43
+ getServerContext,
44
+ getConfig,
45
+ getHooks,
46
+ updateServerContext,
47
+ modifyConfig: hooks.modifyConfig.tap,
48
+ onPrepare: hooks.onPrepare.tap,
49
+ onReset: hooks.onReset.tap,
50
+ ...extendsPluginApi
51
+ };
52
+ return new Proxy(pluginAPI, {
53
+ get(target, prop) {
54
+ if (prop === "then") {
55
+ return void 0;
56
+ }
57
+ if (prop in target) {
58
+ return target[prop];
59
+ }
60
+ return () => {
61
+ debug(`api.${prop.toString()} not exist`);
62
+ };
63
+ }
64
+ });
65
+ }
66
+ export {
67
+ debug,
68
+ initPluginAPI
69
+ };
@@ -0,0 +1,39 @@
1
+ import { initHooks } from "./hooks";
2
+ function initServerContext(params) {
3
+ const { options, plugins } = params;
4
+ return {
5
+ routes: options.routes || [],
6
+ appDirectory: options.appContext.appDirectory || "",
7
+ apiDirectory: options.appContext.apiDirectory,
8
+ lambdaDirectory: options.appContext.lambdaDirectory,
9
+ internalDirectory: options.appContext.internalDirectory || "",
10
+ sharedDirectory: options.appContext.sharedDirectory || "",
11
+ distDirectory: options.pwd,
12
+ metaName: options.metaName || "modern-js",
13
+ plugins,
14
+ middlewares: []
15
+ };
16
+ }
17
+ function createServerContext({ serverContext, config }) {
18
+ const { plugins } = serverContext;
19
+ const extendsHooks = {};
20
+ plugins.forEach((plugin) => {
21
+ const { registryHooks = {} } = plugin;
22
+ Object.keys(registryHooks).forEach((hookName) => {
23
+ extendsHooks[hookName] = registryHooks[hookName];
24
+ });
25
+ });
26
+ return {
27
+ ...serverContext,
28
+ hooks: {
29
+ ...initHooks(),
30
+ ...extendsHooks
31
+ },
32
+ extendsHooks,
33
+ config
34
+ };
35
+ }
36
+ export {
37
+ createServerContext,
38
+ initServerContext
39
+ };
@@ -0,0 +1,11 @@
1
+ import { createAsyncHook } from "../hooks";
2
+ function initHooks() {
3
+ return {
4
+ modifyConfig: createAsyncHook(),
5
+ onPrepare: createAsyncHook(),
6
+ onReset: createAsyncHook()
7
+ };
8
+ }
9
+ export {
10
+ initHooks
11
+ };
@@ -0,0 +1,12 @@
1
+ import { initPluginAPI } from "./api";
2
+ import { initServerContext, createServerContext } from "./context";
3
+ import { initHooks } from "./hooks";
4
+ import { server, createServer } from "./run";
5
+ export {
6
+ createServer,
7
+ createServerContext,
8
+ initHooks,
9
+ initPluginAPI,
10
+ initServerContext,
11
+ server
12
+ };
@@ -0,0 +1,50 @@
1
+ import { createPluginManager } from "../../manager";
2
+ import { initPluginAPI } from "../../server/api";
3
+ import { createServerContext, initServerContext } from "../../server/context";
4
+ const createServer = () => {
5
+ let initOptions;
6
+ const pluginManager = createPluginManager();
7
+ function init(options) {
8
+ pluginManager.clear();
9
+ initOptions = options;
10
+ const { plugins: allPlugins, options: runOptions, handleSetupResult } = initOptions;
11
+ pluginManager.addPlugins(allPlugins);
12
+ const plugins = pluginManager.getPlugins();
13
+ const context = createServerContext({
14
+ serverContext: initServerContext({
15
+ plugins,
16
+ options: runOptions
17
+ }),
18
+ config: initOptions.config
19
+ });
20
+ const pluginAPI = initPluginAPI({
21
+ context,
22
+ pluginManager
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
+ serverContext: context
34
+ };
35
+ }
36
+ async function run(options) {
37
+ const { serverContext } = init(options);
38
+ const config = await serverContext.hooks.modifyConfig.call(serverContext.config);
39
+ serverContext.config = config;
40
+ return {
41
+ serverContext
42
+ };
43
+ }
44
+ return {
45
+ run
46
+ };
47
+ };
48
+ export {
49
+ createServer
50
+ };
@@ -0,0 +1,6 @@
1
+ import { createServer } from "./create";
2
+ const server = createServer();
3
+ export {
4
+ createServer,
5
+ server
6
+ };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,6 +1,7 @@
1
- import type { AsyncHook, AsyncInterruptHook, CollectAsyncHook, CollectSyncHook, SyncHook } from './types/hooks';
1
+ import type { AsyncHook, AsyncInterruptHook, AsyncPipelineHook, CollectAsyncHook, CollectSyncHook, SyncHook } from './types/hooks';
2
2
  export declare function createAsyncInterruptHook<Callback extends (...args: any[]) => any>(): AsyncInterruptHook<Callback>;
3
3
  export declare function createSyncHook<Callback extends (...args: any[]) => any>(): SyncHook<Callback>;
4
4
  export declare function createAsyncHook<Callback extends (...args: any[]) => any>(): AsyncHook<Callback>;
5
5
  export declare function createCollectAsyncHook<Callback extends (...params: any[]) => any>(): CollectAsyncHook<Callback>;
6
6
  export declare function createCollectSyncHook<Callback extends (...params: any[]) => any>(): CollectSyncHook<Callback>;
7
+ export declare function createAsyncPipelineHook<Callback extends (...args: any[]) => any>(): AsyncPipelineHook<Callback>;
@@ -1,6 +1,7 @@
1
1
  export { createPluginManager } from './manager';
2
- export { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook, } from './hooks';
2
+ export { createSyncHook, createAsyncHook, createCollectSyncHook, createCollectAsyncHook, createAsyncInterruptHook, createAsyncPipelineHook, } from './hooks';
3
3
  export type { Plugin, PluginManager, TransformFunction, } from './types/plugin';
4
4
  export type { CLIPluginAPI, AppContext, InternalContext, Entrypoint, CLIPlugin, CLIPluginExtends, RuntimePluginConfig, ServerPluginConfig, } from './types/cli';
5
5
  export type { RuntimePluginAPI, RuntimeContext, InternalRuntimeContext, RuntimePlugin, RuntimePluginExtends, } from './types/runtime';
6
- export type { AsyncHook, CollectAsyncHook, PluginHook, PluginHookTap, } from './types/hooks';
6
+ export type { ServerPluginAPI, ServerContext, InternalServerContext, ServerPlugin, ServerPluginExtends, ResetEvent, FileChangeEvent, } from './types/server';
7
+ export type { SyncHook, AsyncHook, AsyncInterruptHook, CollectAsyncHook, CollectSyncHook, PluginHook, PluginHookTap, AsyncPipelineHook, } from './types/hooks';
@@ -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>;
@@ -0,0 +1,13 @@
1
+ import type { InternalServerContext, ServerContext } from '../types/server/context';
2
+ import type { ServerPlugin, ServerPluginExtends } from '../types/server/plugin';
3
+ import type { ServerCreateOptions } from './run/types';
4
+ interface ContextParams<Extends extends ServerPluginExtends> {
5
+ serverContext: ServerContext<Extends>;
6
+ config: Extends['config'];
7
+ }
8
+ export declare function initServerContext<Extends extends ServerPluginExtends>(params: {
9
+ options: ServerCreateOptions;
10
+ plugins: ServerPlugin<Extends>[];
11
+ }): ServerContext<Extends>;
12
+ export declare function createServerContext<Extends extends ServerPluginExtends>({ serverContext, config, }: ContextParams<Extends>): InternalServerContext<Extends>;
13
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { ModifyConfigFn, OnPrepareFn, OnResetFn } from '../types/server/hooks';
2
+ import type { DeepPartial } from '../types/utils';
3
+ export type { OnResetFn, OnPrepareFn, ModifyConfigFn };
4
+ export declare function initHooks<Config>(): {
5
+ modifyConfig: import("..").AsyncHook<ModifyConfigFn<DeepPartial<Config>>>;
6
+ onPrepare: import("..").AsyncHook<OnPrepareFn>;
7
+ onReset: import("..").AsyncHook<OnResetFn>;
8
+ };
9
+ export type Hooks<Config> = ReturnType<typeof initHooks<Config>>;
@@ -0,0 +1,4 @@
1
+ export { initPluginAPI } from './api';
2
+ export { initServerContext, createServerContext } from './context';
3
+ export { initHooks, type Hooks, type OnPrepareFn, type ModifyConfigFn, type OnResetFn, } from './hooks';
4
+ export { server, createServer, type ServerCreateOptions } from './run';
@@ -0,0 +1,7 @@
1
+ import type { ServerPluginExtends } from '../../types/server/plugin';
2
+ import type { ServerRunOptions } from './types';
3
+ export declare const createServer: <Extends extends ServerPluginExtends>() => {
4
+ run: (options: ServerRunOptions) => Promise<{
5
+ serverContext: import("../..").InternalServerContext<Extends>;
6
+ }>;
7
+ };
@@ -0,0 +1,8 @@
1
+ import { createServer } from './create';
2
+ export declare const server: {
3
+ run: (options: import("./types").ServerRunOptions) => Promise<{
4
+ serverContext: import("../..").InternalServerContext<import("../..").ServerPluginExtends<{}, {}, {}, {}>>;
5
+ }>;
6
+ };
7
+ export { createServer };
8
+ export type { ServerCreateOptions } from './types';
@@ -0,0 +1,21 @@
1
+ import type { ServerRoute } from '@modern-js/types';
2
+ import type { Plugin } from '../../types/plugin';
3
+ export type ServerCreateOptions = {
4
+ /** server working directory, and then also dist directory */
5
+ pwd: string;
6
+ metaName?: string;
7
+ routes?: ServerRoute[];
8
+ appContext: {
9
+ internalDirectory?: string;
10
+ appDirectory?: string;
11
+ sharedDirectory?: string;
12
+ apiDirectory?: string;
13
+ lambdaDirectory?: string;
14
+ };
15
+ };
16
+ export type ServerRunOptions = {
17
+ options: ServerCreateOptions;
18
+ config: Record<string, any>;
19
+ plugins: Plugin[];
20
+ handleSetupResult?: (params: any, api: Record<string, any>) => Promise<void> | void;
21
+ };
@@ -11,6 +11,10 @@ export type AsyncInterruptHook<Callback extends (...args: any[]) => any> = {
11
11
  tap: (cb: Callback) => void;
12
12
  call: (...args: Tail<Parameters<Callback>>) => Promise<UnwrapPromise<ReturnType<Callback>>>;
13
13
  };
14
+ export type AsyncPipelineHook<Callback extends (...args: any[]) => any> = {
15
+ tap: (cb: Callback) => void;
16
+ call: (...args: Parameters<Callback>) => Promise<UnwrapPromise<ReturnType<Callback>>>;
17
+ };
14
18
  export type CollectAsyncHook<Callback extends (...params: any[]) => any> = {
15
19
  tap: (cb: Callback) => void;
16
20
  call: (...params: Parameters<Callback>) => Promise<UnwrapPromise<ReturnType<Callback>>[]>;
@@ -19,5 +23,5 @@ export type CollectSyncHook<Callback extends (...params: any[]) => any> = {
19
23
  tap: (cb: Callback) => void;
20
24
  call: (...params: Parameters<Callback>) => ReturnType<Callback>[];
21
25
  };
22
- export type PluginHook<Callback extends (...args: any[]) => any> = SyncHook<Callback> | AsyncHook<Callback> | CollectSyncHook<Callback> | CollectAsyncHook<Callback> | AsyncInterruptHook<Callback>;
26
+ export type PluginHook<Callback extends (...args: any[]) => any> = SyncHook<Callback> | AsyncHook<Callback> | CollectSyncHook<Callback> | CollectAsyncHook<Callback> | AsyncInterruptHook<Callback> | AsyncPipelineHook<Callback>;
23
27
  export type PluginHookTap<T extends (...args: any[]) => any> = (options: T) => void;
@@ -0,0 +1,19 @@
1
+ import type { PluginHook, PluginHookTap } from '../hooks';
2
+ import type { DeepPartial } from '../utils';
3
+ import type { ServerContext } from './context';
4
+ import type { Hooks, ModifyConfigFn, OnPrepareFn, OnResetFn } from './hooks';
5
+ import type { ServerPluginExtends } from './plugin';
6
+ export type ServerPluginAPI<Extends extends ServerPluginExtends> = Readonly<{
7
+ getServerContext: () => Readonly<ServerContext<Extends>>;
8
+ updateServerContext: (updateContext: DeepPartial<ServerContext<Extends>>) => void;
9
+ getHooks: () => Readonly<Hooks<Extends['config']> & Extends['extendHooks']>;
10
+ getServerConfig: () => Readonly<Extends['config']>;
11
+ modifyConfig: PluginHookTap<ModifyConfigFn<Extends['config']>>;
12
+ onPrepare: PluginHookTap<OnPrepareFn>;
13
+ onReset: PluginHookTap<OnResetFn>;
14
+ } & ServerPluginExtendsAPI<Extends>>;
15
+ export type ServerPluginExtendsAPI<Extends extends ServerPluginExtends> = {
16
+ [K in keyof Extends['extendHooks']]: PluginHookTap<Extends['extendHooks'][K] extends PluginHook<infer Args> ? Args extends (...args: any[]) => any ? Args : (...args: any[]) => any : (...args: any[]) => any>;
17
+ } & Extends['extendApi'];
18
+ export type AllKeysForServerPluginExtendsAPI<Extends extends ServerPluginExtends> = keyof ServerPluginExtendsAPI<Extends>;
19
+ export type AllValueForServerPluginExtendsAPI<Extends extends ServerPluginExtends> = ServerPluginExtendsAPI<Extends>[AllKeysForServerPluginExtendsAPI<Extends>];