@modern-js/server-core 1.21.5 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,25 +1,67 @@
1
1
  # @modern-js/server-plugin
2
2
 
3
- ## 1.21.5
3
+ ## 2.0.0-beta.1
4
4
 
5
- ### Patch Changes
5
+ ### Major Changes
6
+
7
+ - dda38c9: chore: v2
6
8
 
7
- - @modern-js/plugin@1.21.5
8
- - @modern-js/utils@1.21.5
9
+ ### Minor Changes
9
10
 
10
- ## 1.21.4
11
+ - 543be9558e: feat: compile server loader and support handle loader request
12
+ feat: 编译 server loader 并支持处理 loader 的请求
11
13
 
12
14
  ### Patch Changes
13
15
 
14
- - @modern-js/plugin@1.21.4
15
- - @modern-js/utils@1.21.4
16
+ - 15bf09d9c8: feat: support completely custom server, export render() api for render single page
17
+ feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
18
+ - cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
19
+ refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
20
+ - Updated dependencies [92f0ead]
21
+ - Updated dependencies [edd1cfb1af]
22
+ - Updated dependencies [cc971eabfc]
23
+ - Updated dependencies [5b9049f]
24
+ - Updated dependencies [92004d1]
25
+ - Updated dependencies [b8bbe036c7]
26
+ - Updated dependencies [d5a31df781]
27
+ - Updated dependencies [dda38c9]
28
+ - Updated dependencies [3bbea92b2a]
29
+ - Updated dependencies [f179749]
30
+ - Updated dependencies [abf3421]
31
+ - Updated dependencies [543be9558e]
32
+ - Updated dependencies [14b712d]
33
+ - @modern-js/utils@2.0.0-beta.1
34
+ - @modern-js/plugin@2.0.0-beta.1
16
35
 
17
- ## 1.21.3
36
+ ## 2.0.0-beta.0
18
37
 
19
- ### Patch Changes
38
+ ### Major Changes
39
+
40
+ - dda38c9: chore: v2
41
+
42
+ ### Minor Changes
20
43
 
21
- - @modern-js/plugin@1.21.3
22
- - @modern-js/utils@1.21.3
44
+ - 543be95: feat: compile server loader and support handle loader request
45
+ feat: 编译 server loader 并支持处理 loader 的请求
46
+
47
+ ### Patch Changes
48
+
49
+ - 15bf09d9c: feat: support completely custom server, export render() api for render single page
50
+ feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
51
+ - cc971eabf: refactor: move server plugin load logic in `@modern-js/core`
52
+ refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
53
+ - Updated dependencies [edd1cfb1a]
54
+ - Updated dependencies [cc971eabf]
55
+ - Updated dependencies [5b9049f]
56
+ - Updated dependencies [b8bbe036c]
57
+ - Updated dependencies [d5a31df78]
58
+ - Updated dependencies [dda38c9]
59
+ - Updated dependencies [3bbea92b2]
60
+ - Updated dependencies [abf3421]
61
+ - Updated dependencies [543be95]
62
+ - Updated dependencies [14b712d]
63
+ - @modern-js/utils@2.0.0-beta.0
64
+ - @modern-js/plugin@2.0.0-beta.0
23
65
 
24
66
  ## 1.21.2
25
67
 
@@ -1,47 +1,25 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- import { compatRequire, tryResolve } from '@modern-js/utils';
1
+ import { compatRequire, getInternalPlugins, tryResolve } from '@modern-js/utils';
8
2
  import { createPlugin } from "./plugin";
9
- export const loadPlugins = (plugins, appDirectory) => {
10
- const resolvePlugin = p => {
11
- const isPluginInstance = typeof p !== 'string' && !Array.isArray(p);
12
-
13
- if (isPluginInstance) {
14
- return {
15
- module: createPlugin(p.setup, p)
16
- };
17
- }
18
-
19
- const [pkg, options] = typeof p === 'string' ? [p, undefined] : p;
20
- const pluginPath = tryResolve(pkg, appDirectory);
21
- let module = compatRequire(pluginPath);
22
- const useNewSyntax = typeof module === 'function';
23
-
24
- if (useNewSyntax) {
25
- const plugin = module(options);
26
- module = createPlugin(plugin.setup, plugin);
27
- }
28
-
3
+ const resolvePlugin = (p, appDirectory) => {
4
+ const isPluginInstance = typeof p !== 'string';
5
+ if (isPluginInstance) {
29
6
  return {
30
- pkg,
31
- path: pluginPath,
32
- module
7
+ module: createPlugin(p.setup, p)
33
8
  };
9
+ }
10
+ const pluginPath = tryResolve(p, appDirectory);
11
+ const module = compatRequire(pluginPath);
12
+ const pluginInstance = module();
13
+ return {
14
+ module: createPlugin(pluginInstance.setup, pluginInstance)
34
15
  };
35
-
36
- return plugins.map(plugin => {
16
+ };
17
+ export const loadPlugins = (appDirectory, configPlugins, options) => {
18
+ const loadedPlugins = getInternalPlugins(appDirectory, options.internalPlugins);
19
+ return [...loadedPlugins, ...configPlugins].map(plugin => {
37
20
  const {
38
- pkg,
39
- path,
40
21
  module
41
- } = resolvePlugin(plugin);
42
- return _objectSpread(_objectSpread({}, module), {}, {
43
- pluginPath: path,
44
- pkg
45
- });
22
+ } = resolvePlugin(plugin, appDirectory);
23
+ return module;
46
24
  });
47
25
  };
@@ -1,16 +1,19 @@
1
1
  import { createContext, createAsyncManager, createAsyncPipeline, createAsyncWaterfall, createParallelWorkflow, createWaterfall } from '@modern-js/plugin';
2
2
  // collect all middleware register in server plugins
3
3
  const gather = createParallelWorkflow();
4
+
4
5
  // config
5
6
  const config = createWaterfall();
6
7
  const prepare = createWaterfall();
7
- const create = createAsyncPipeline();
8
+ const preparebeforeRouteHandler = createAsyncPipeline();
8
9
  const prepareWebServer = createAsyncPipeline();
9
10
  const prepareApiServer = createAsyncPipeline();
10
11
  const onApiChange = createWaterfall();
11
12
  const beforeDevServer = createParallelWorkflow();
12
13
  const setupCompiler = createParallelWorkflow();
13
- const afterDevServer = createParallelWorkflow(); // TODO FIXME
14
+ const afterDevServer = createParallelWorkflow();
15
+
16
+ // TODO FIXME
14
17
 
15
18
  const beforeRouteSet = createAsyncPipeline();
16
19
  const afterRouteSet = createAsyncPipeline();
@@ -23,9 +26,13 @@ const extendSSRContext = createAsyncWaterfall();
23
26
  const extendContext = createAsyncPipeline();
24
27
  const handleError = createParallelWorkflow();
25
28
  const beforeMatch = createAsyncPipeline();
26
- const afterMatch = createAsyncPipeline(); // TODO FIXME
29
+ const afterMatch = createAsyncPipeline();
30
+
31
+ // TODO FIXME
27
32
 
28
- const prefetch = createParallelWorkflow(); // TODO FIXME
33
+ const prefetch = createParallelWorkflow();
34
+
35
+ // TODO FIXME
29
36
 
30
37
  const renderToString = createAsyncPipeline();
31
38
  const beforeRender = createAsyncPipeline();
@@ -36,15 +43,15 @@ const reset = createParallelWorkflow();
36
43
  export const AppContext = createContext({});
37
44
  export const setAppContext = value => AppContext.set(value);
38
45
  export const ConfigContext = createContext({});
46
+
39
47
  /**
40
48
  * Get original content of user config.
41
49
  */
42
-
43
50
  export const useConfigContext = () => ConfigContext.use().value;
51
+
44
52
  /**
45
53
  * Get app context, including directories, plugins and some static infos.
46
54
  */
47
-
48
55
  export const useAppContext = () => AppContext.use().value;
49
56
  const pluginAPI = {
50
57
  useAppContext,
@@ -56,7 +63,7 @@ const serverHooks = {
56
63
  gather,
57
64
  config,
58
65
  prepare,
59
- create,
66
+ preparebeforeRouteHandler,
60
67
  prepareWebServer,
61
68
  prepareApiServer,
62
69
  onApiChange,
@@ -84,10 +91,12 @@ const serverHooks = {
84
91
  afterSend,
85
92
  reset
86
93
  };
94
+
87
95
  /** All hooks of server plugin. */
88
96
 
89
97
  export const createServerManager = () => createAsyncManager(serverHooks, pluginAPI);
90
98
  export const serverManager = createServerManager();
99
+
91
100
  /** Plugin options of a server plugin. */
92
101
 
93
102
  export const {
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _plugin = require("./plugin");
8
-
9
7
  Object.keys(_plugin).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _plugin[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_plugin).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _plugin2 = require("@modern-js/plugin");
21
-
22
18
  Object.keys(_plugin2).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _plugin2[key]) return;
@@ -29,9 +25,7 @@ Object.keys(_plugin2).forEach(function (key) {
29
25
  }
30
26
  });
31
27
  });
32
-
33
28
  var _loadPlugins = require("./loadPlugins");
34
-
35
29
  Object.keys(_loadPlugins).forEach(function (key) {
36
30
  if (key === "default" || key === "__esModule") return;
37
31
  if (key in exports && exports[key] === _loadPlugins[key]) return;
@@ -4,55 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.loadPlugins = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  var _plugin = require("./plugin");
11
-
12
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
-
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
-
18
- const loadPlugins = (plugins, appDirectory) => {
19
- const resolvePlugin = p => {
20
- const isPluginInstance = typeof p !== 'string' && !Array.isArray(p);
21
-
22
- if (isPluginInstance) {
23
- return {
24
- module: (0, _plugin.createPlugin)(p.setup, p)
25
- };
26
- }
27
-
28
- const [pkg, options] = typeof p === 'string' ? [p, undefined] : p;
29
- const pluginPath = (0, _utils.tryResolve)(pkg, appDirectory);
30
- let module = (0, _utils.compatRequire)(pluginPath);
31
- const useNewSyntax = typeof module === 'function';
32
-
33
- if (useNewSyntax) {
34
- const plugin = module(options);
35
- module = (0, _plugin.createPlugin)(plugin.setup, plugin);
36
- }
37
-
9
+ const resolvePlugin = (p, appDirectory) => {
10
+ const isPluginInstance = typeof p !== 'string';
11
+ if (isPluginInstance) {
38
12
  return {
39
- pkg,
40
- path: pluginPath,
41
- module
13
+ module: (0, _plugin.createPlugin)(p.setup, p)
42
14
  };
15
+ }
16
+ const pluginPath = (0, _utils.tryResolve)(p, appDirectory);
17
+ const module = (0, _utils.compatRequire)(pluginPath);
18
+ const pluginInstance = module();
19
+ return {
20
+ module: (0, _plugin.createPlugin)(pluginInstance.setup, pluginInstance)
43
21
  };
44
-
45
- return plugins.map(plugin => {
22
+ };
23
+ const loadPlugins = (appDirectory, configPlugins, options) => {
24
+ const loadedPlugins = (0, _utils.getInternalPlugins)(appDirectory, options.internalPlugins);
25
+ return [...loadedPlugins, ...configPlugins].map(plugin => {
46
26
  const {
47
- pkg,
48
- path,
49
27
  module
50
- } = resolvePlugin(plugin);
51
- return _objectSpread(_objectSpread({}, module), {}, {
52
- pluginPath: path,
53
- pkg
54
- });
28
+ } = resolvePlugin(plugin, appDirectory);
29
+ return module;
55
30
  });
56
31
  };
57
-
58
32
  exports.loadPlugins = loadPlugins;
@@ -4,21 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.serverManager = exports.createServerManager = exports.createPlugin = exports.ConfigContext = exports.AppContext = void 0;
7
-
8
7
  var _plugin = require("@modern-js/plugin");
9
-
10
8
  // collect all middleware register in server plugins
11
9
  const gather = (0, _plugin.createParallelWorkflow)();
10
+
12
11
  // config
13
12
  const config = (0, _plugin.createWaterfall)();
14
13
  const prepare = (0, _plugin.createWaterfall)();
15
- const create = (0, _plugin.createAsyncPipeline)();
14
+ const preparebeforeRouteHandler = (0, _plugin.createAsyncPipeline)();
16
15
  const prepareWebServer = (0, _plugin.createAsyncPipeline)();
17
16
  const prepareApiServer = (0, _plugin.createAsyncPipeline)();
18
17
  const onApiChange = (0, _plugin.createWaterfall)();
19
18
  const beforeDevServer = (0, _plugin.createParallelWorkflow)();
20
19
  const setupCompiler = (0, _plugin.createParallelWorkflow)();
21
- const afterDevServer = (0, _plugin.createParallelWorkflow)(); // TODO FIXME
20
+ const afterDevServer = (0, _plugin.createParallelWorkflow)();
21
+
22
+ // TODO FIXME
22
23
 
23
24
  const beforeRouteSet = (0, _plugin.createAsyncPipeline)();
24
25
  const afterRouteSet = (0, _plugin.createAsyncPipeline)();
@@ -31,9 +32,13 @@ const extendSSRContext = (0, _plugin.createAsyncWaterfall)();
31
32
  const extendContext = (0, _plugin.createAsyncPipeline)();
32
33
  const handleError = (0, _plugin.createParallelWorkflow)();
33
34
  const beforeMatch = (0, _plugin.createAsyncPipeline)();
34
- const afterMatch = (0, _plugin.createAsyncPipeline)(); // TODO FIXME
35
+ const afterMatch = (0, _plugin.createAsyncPipeline)();
36
+
37
+ // TODO FIXME
35
38
 
36
- const prefetch = (0, _plugin.createParallelWorkflow)(); // TODO FIXME
39
+ const prefetch = (0, _plugin.createParallelWorkflow)();
40
+
41
+ // TODO FIXME
37
42
 
38
43
  const renderToString = (0, _plugin.createAsyncPipeline)();
39
44
  const beforeRender = (0, _plugin.createAsyncPipeline)();
@@ -43,27 +48,21 @@ const afterSend = (0, _plugin.createParallelWorkflow)();
43
48
  const reset = (0, _plugin.createParallelWorkflow)();
44
49
  const AppContext = (0, _plugin.createContext)({});
45
50
  exports.AppContext = AppContext;
46
-
47
51
  const setAppContext = value => AppContext.set(value);
48
-
49
52
  exports.setAppContext = setAppContext;
50
53
  const ConfigContext = (0, _plugin.createContext)({});
54
+
51
55
  /**
52
56
  * Get original content of user config.
53
57
  */
54
-
55
58
  exports.ConfigContext = ConfigContext;
56
-
57
59
  const useConfigContext = () => ConfigContext.use().value;
60
+
58
61
  /**
59
62
  * Get app context, including directories, plugins and some static infos.
60
63
  */
61
-
62
-
63
64
  exports.useConfigContext = useConfigContext;
64
-
65
65
  const useAppContext = () => AppContext.use().value;
66
-
67
66
  exports.useAppContext = useAppContext;
68
67
  const pluginAPI = {
69
68
  useAppContext,
@@ -75,7 +74,7 @@ const serverHooks = {
75
74
  gather,
76
75
  config,
77
76
  prepare,
78
- create,
77
+ preparebeforeRouteHandler,
79
78
  prepareWebServer,
80
79
  prepareApiServer,
81
80
  onApiChange,
@@ -103,14 +102,14 @@ const serverHooks = {
103
102
  afterSend,
104
103
  reset
105
104
  };
105
+
106
106
  /** All hooks of server plugin. */
107
107
 
108
108
  const createServerManager = () => (0, _plugin.createAsyncManager)(serverHooks, pluginAPI);
109
-
110
109
  exports.createServerManager = createServerManager;
111
110
  const serverManager = createServerManager();
112
- /** Plugin options of a server plugin. */
113
111
 
112
+ /** Plugin options of a server plugin. */
114
113
  exports.serverManager = serverManager;
115
114
  const {
116
115
  createPlugin
@@ -1,4 +1,64 @@
1
+ import { InternalPlugins } from '@modern-js/types';
1
2
  import { ServerPlugin } from './plugin';
2
- declare type Plugin = string | [string, any] | ServerPlugin;
3
- export declare const loadPlugins: (plugins: Plugin[], appDirectory: string) => any[];
4
- export {};
3
+ export declare const loadPlugins: (appDirectory: string, configPlugins: ServerPlugin[], options: {
4
+ internalPlugins?: InternalPlugins;
5
+ }) => import("@modern-js/plugin").AsyncPlugin<{
6
+ gather: import("@modern-js/plugin").ParallelWorkflow<{
7
+ addWebMiddleware: (_input: any) => void;
8
+ addAPIMiddleware: (_input: any) => void;
9
+ }, unknown>;
10
+ config: import("@modern-js/plugin").Waterfall<import("./plugin").ServerConfig>;
11
+ prepare: import("@modern-js/plugin").Waterfall<void>;
12
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
13
+ serverRoutes: import("@modern-js/types").ServerRoute[];
14
+ distDir: string;
15
+ }, import("./plugin").BeforeRouteHandler>;
16
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<import("./plugin").WebServerStartInput, import("./plugin").WebAdapter>;
17
+ prepareApiServer: import("@modern-js/plugin").AsyncPipeline<import("./plugin").APIServerStartInput, import("./plugin").Adapter>;
18
+ onApiChange: import("@modern-js/plugin").Waterfall<{
19
+ filename: string;
20
+ event: "add" | "unlink" | "change";
21
+ }[]>;
22
+ beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<import("./plugin").ServerOptions, any>;
23
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
24
+ afterDevServer: import("@modern-js/plugin").ParallelWorkflow<import("./plugin").ServerOptions, any>;
25
+ beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<import("./plugin").Route[], import("./plugin").Route[]>;
26
+ afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
27
+ beforeProdServer: import("@modern-js/plugin").ParallelWorkflow<import("./plugin").ServerOptions, any>;
28
+ afterProdServer: import("@modern-js/plugin").ParallelWorkflow<import("./plugin").ServerOptions, any>;
29
+ listen: import("@modern-js/plugin").ParallelWorkflow<{
30
+ ip: string;
31
+ port: number;
32
+ }, any[]>;
33
+ beforeServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
34
+ afterServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
35
+ extendSSRContext: import("@modern-js/plugin").AsyncWaterfall<import("@modern-js/types").BaseSSRServerContext>;
36
+ extendContext: import("@modern-js/plugin").AsyncPipeline<import("@modern-js/types").ModernServerContext, import("@modern-js/types").ModernServerContext>;
37
+ handleError: import("@modern-js/plugin").ParallelWorkflow<{
38
+ error: Error;
39
+ }, unknown>;
40
+ beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
41
+ context: import("@modern-js/types").ModernServerContext;
42
+ }, any>;
43
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<import("@modern-js/types").AfterMatchContext, any>;
44
+ prefetch: import("@modern-js/plugin").ParallelWorkflow<{
45
+ context: import("./plugin").SSRServerContext;
46
+ }, unknown>;
47
+ renderToString: import("@modern-js/plugin").AsyncPipeline<{
48
+ App: import("react").Component<{}, {}, any>;
49
+ context: import("./plugin").RenderContext;
50
+ }, string>;
51
+ beforeRender: import("@modern-js/plugin").AsyncPipeline<{
52
+ context: import("@modern-js/types").ModernServerContext;
53
+ }, any>;
54
+ afterRender: import("@modern-js/plugin").AsyncPipeline<import("@modern-js/types").AfterRenderContext, any>;
55
+ beforeSend: import("@modern-js/plugin").AsyncPipeline<import("@modern-js/types").ModernServerContext, import("./plugin").RequestResult>;
56
+ afterSend: import("@modern-js/plugin").ParallelWorkflow<{
57
+ context: import("@modern-js/types").ModernServerContext;
58
+ }, unknown>;
59
+ reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
60
+ }, {
61
+ useAppContext: () => import("@modern-js/types").ISAppContext;
62
+ useConfigContext: () => import("@modern-js/core").UserConfig;
63
+ setAppContext: (value: import("@modern-js/types").ISAppContext) => void;
64
+ }>[];
@@ -2,12 +2,10 @@
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
3
  import type { Component } from 'react';
4
4
  import { CommonAPI, ToThreads, AsyncSetup, PluginOptions } from '@modern-js/plugin';
5
- import type { ModernServerContext, BaseSSRServerContext, Metrics, Logger } from '@modern-js/types/server';
5
+ import type { ModernServerContext, BaseSSRServerContext, AfterMatchContext, AfterRenderContext, MiddlewareContext, ISAppContext, ServerRoute } from '@modern-js/types';
6
6
  import type { NormalizedConfig, UserConfig } from '@modern-js/core';
7
- import type { ISAppContext } from '@modern-js/types';
8
7
  import type { Options } from 'http-proxy-middleware';
9
8
  /** The subset of NormalizedConfig, which really need in server */
10
-
11
9
  export declare type ServerOptions = {
12
10
  output: Pick<NormalizedConfig['output'], 'path' | 'assetPrefix'>;
13
11
  source: Pick<NormalizedConfig['source'], 'alias' | 'envVars' | 'globalVars'>;
@@ -19,19 +17,13 @@ export declare type ServerOptions = {
19
17
  bff: NormalizedConfig['bff'];
20
18
  plugins: NormalizedConfig['plugins'];
21
19
  };
22
- declare type ServerInitInput = {
23
- loggerOptions: any;
24
- metricsOptions: any;
25
- };
26
- declare type InitExtension = {
27
- logger: Logger;
28
- metrics: Metrics;
29
- };
20
+ export declare type WebAdapter = (ctx: MiddlewareContext) => void | Promise<void>;
30
21
  export declare type Adapter = (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
31
22
  export declare type WebServerStartInput = {
32
23
  pwd: string;
33
24
  config: Record<string, any>;
34
25
  };
26
+ export declare type BeforeRouteHandler = (context: ModernServerContext) => Promise<void>;
35
27
  export declare type APIServerStartInput = {
36
28
  pwd: string;
37
29
  prefix?: string;
@@ -55,12 +47,10 @@ export declare const ConfigContext: import("@modern-js/plugin").Context<UserConf
55
47
  /**
56
48
  * Get original content of user config.
57
49
  */
58
-
59
50
  export declare const useConfigContext: () => UserConfig;
60
51
  /**
61
52
  * Get app context, including directories, plugins and some static infos.
62
53
  */
63
-
64
54
  export declare const useAppContext: () => ISAppContext;
65
55
  declare const pluginAPI: {
66
56
  useAppContext: () => ISAppContext;
@@ -74,8 +64,11 @@ declare const serverHooks: {
74
64
  }, unknown>;
75
65
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
76
66
  prepare: import("@modern-js/plugin").Waterfall<void>;
77
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
78
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
67
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
68
+ serverRoutes: ServerRoute[];
69
+ distDir: string;
70
+ }, BeforeRouteHandler>;
71
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
79
72
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
80
73
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
81
74
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -99,10 +92,7 @@ declare const serverHooks: {
99
92
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
100
93
  context: ModernServerContext;
101
94
  }, any>;
102
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
103
- context: ModernServerContext;
104
- routeAPI: any;
105
- }, any>;
95
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
106
96
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
107
97
  context: SSRServerContext;
108
98
  }, unknown>;
@@ -113,10 +103,7 @@ declare const serverHooks: {
113
103
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
114
104
  context: ModernServerContext;
115
105
  }, any>;
116
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
117
- context: ModernServerContext;
118
- templateAPI: any;
119
- }, any>;
106
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
120
107
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
121
108
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
122
109
  context: ModernServerContext;
@@ -124,13 +111,10 @@ declare const serverHooks: {
124
111
  reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
125
112
  };
126
113
  /** All hooks of server plugin. */
127
-
128
114
  export declare type ServerHooks = typeof serverHooks;
129
115
  /** All hook callbacks of server plugin. */
130
-
131
116
  export declare type ServerHookCallbacks = ToThreads<ServerHooks>;
132
117
  /** All apis for server plugin. */
133
-
134
118
  export declare type PluginAPI = typeof pluginAPI & CommonAPI<ServerHooks>;
135
119
  export declare const createServerManager: () => import("@modern-js/plugin").AsyncManager<{
136
120
  gather: import("@modern-js/plugin").ParallelWorkflow<{
@@ -139,8 +123,11 @@ export declare const createServerManager: () => import("@modern-js/plugin").Asyn
139
123
  }, unknown>;
140
124
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
141
125
  prepare: import("@modern-js/plugin").Waterfall<void>;
142
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
143
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
126
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
127
+ serverRoutes: ServerRoute[];
128
+ distDir: string;
129
+ }, BeforeRouteHandler>;
130
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
144
131
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
145
132
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
146
133
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -164,10 +151,7 @@ export declare const createServerManager: () => import("@modern-js/plugin").Asyn
164
151
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
165
152
  context: ModernServerContext;
166
153
  }, any>;
167
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
168
- context: ModernServerContext;
169
- routeAPI: any;
170
- }, any>;
154
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
171
155
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
172
156
  context: SSRServerContext;
173
157
  }, unknown>;
@@ -178,10 +162,7 @@ export declare const createServerManager: () => import("@modern-js/plugin").Asyn
178
162
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
179
163
  context: ModernServerContext;
180
164
  }, any>;
181
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
182
- context: ModernServerContext;
183
- templateAPI: any;
184
- }, any>;
165
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
185
166
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
186
167
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
187
168
  context: ModernServerContext;
@@ -199,8 +180,11 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
199
180
  }, unknown>;
200
181
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
201
182
  prepare: import("@modern-js/plugin").Waterfall<void>;
202
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
203
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
183
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
184
+ serverRoutes: ServerRoute[];
185
+ distDir: string;
186
+ }, BeforeRouteHandler>;
187
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
204
188
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
205
189
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
206
190
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -224,10 +208,7 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
224
208
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
225
209
  context: ModernServerContext;
226
210
  }, any>;
227
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
228
- context: ModernServerContext;
229
- routeAPI: any;
230
- }, any>;
211
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
231
212
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
232
213
  context: SSRServerContext;
233
214
  }, unknown>;
@@ -238,10 +219,7 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
238
219
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
239
220
  context: ModernServerContext;
240
221
  }, any>;
241
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
242
- context: ModernServerContext;
243
- templateAPI: any;
244
- }, any>;
222
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
245
223
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
246
224
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
247
225
  context: ModernServerContext;
@@ -253,7 +231,6 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
253
231
  setAppContext: (value: ISAppContext) => void;
254
232
  }>;
255
233
  /** Plugin options of a server plugin. */
256
-
257
234
  export declare type ServerPlugin = PluginOptions<ServerHooks, AsyncSetup<ServerHooks, PluginAPI>>;
258
235
  export declare type ServerConfig = {
259
236
  bff?: Partial<{
@@ -268,8 +245,11 @@ export declare const createPlugin: (setup?: AsyncSetup<{
268
245
  }, unknown>;
269
246
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
270
247
  prepare: import("@modern-js/plugin").Waterfall<void>;
271
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
272
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
248
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
249
+ serverRoutes: ServerRoute[];
250
+ distDir: string;
251
+ }, BeforeRouteHandler>;
252
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
273
253
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
274
254
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
275
255
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -293,10 +273,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
293
273
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
294
274
  context: ModernServerContext;
295
275
  }, any>;
296
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
297
- context: ModernServerContext;
298
- routeAPI: any;
299
- }, any>;
276
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
300
277
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
301
278
  context: SSRServerContext;
302
279
  }, unknown>;
@@ -307,10 +284,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
307
284
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
308
285
  context: ModernServerContext;
309
286
  }, any>;
310
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
311
- context: ModernServerContext;
312
- templateAPI: any;
313
- }, any>;
287
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
314
288
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
315
289
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
316
290
  context: ModernServerContext;
@@ -327,8 +301,11 @@ export declare const createPlugin: (setup?: AsyncSetup<{
327
301
  }, unknown>;
328
302
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
329
303
  prepare: import("@modern-js/plugin").Waterfall<void>;
330
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
331
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
304
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
305
+ serverRoutes: ServerRoute[];
306
+ distDir: string;
307
+ }, BeforeRouteHandler>;
308
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
332
309
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
333
310
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
334
311
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -352,10 +329,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
352
329
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
353
330
  context: ModernServerContext;
354
331
  }, any>;
355
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
356
- context: ModernServerContext;
357
- routeAPI: any;
358
- }, any>;
332
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
359
333
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
360
334
  context: SSRServerContext;
361
335
  }, unknown>;
@@ -366,10 +340,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
366
340
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
367
341
  context: ModernServerContext;
368
342
  }, any>;
369
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
370
- context: ModernServerContext;
371
- templateAPI: any;
372
- }, any>;
343
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
373
344
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
374
345
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
375
346
  context: ModernServerContext;
@@ -382,8 +353,11 @@ export declare const createPlugin: (setup?: AsyncSetup<{
382
353
  }, unknown>;
383
354
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
384
355
  prepare: import("@modern-js/plugin").Waterfall<void>;
385
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
386
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
356
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
357
+ serverRoutes: ServerRoute[];
358
+ distDir: string;
359
+ }, BeforeRouteHandler>;
360
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
387
361
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
388
362
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
389
363
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -407,10 +381,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
407
381
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
408
382
  context: ModernServerContext;
409
383
  }, any>;
410
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
411
- context: ModernServerContext;
412
- routeAPI: any;
413
- }, any>;
384
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
414
385
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
415
386
  context: SSRServerContext;
416
387
  }, unknown>;
@@ -421,10 +392,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
421
392
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
422
393
  context: ModernServerContext;
423
394
  }, any>;
424
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
425
- context: ModernServerContext;
426
- templateAPI: any;
427
- }, any>;
395
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
428
396
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
429
397
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
430
398
  context: ModernServerContext;
@@ -434,15 +402,18 @@ export declare const createPlugin: (setup?: AsyncSetup<{
434
402
  useAppContext: () => ISAppContext;
435
403
  useConfigContext: () => UserConfig;
436
404
  setAppContext: (value: ISAppContext) => void;
437
- }>> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
405
+ }>, Record<string, unknown>> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
438
406
  gather: import("@modern-js/plugin").ParallelWorkflow<{
439
407
  addWebMiddleware: (_input: any) => void;
440
408
  addAPIMiddleware: (_input: any) => void;
441
409
  }, unknown>;
442
410
  config: import("@modern-js/plugin").Waterfall<ServerConfig>;
443
411
  prepare: import("@modern-js/plugin").Waterfall<void>;
444
- create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
445
- prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
412
+ preparebeforeRouteHandler: import("@modern-js/plugin").AsyncPipeline<{
413
+ serverRoutes: ServerRoute[];
414
+ distDir: string;
415
+ }, BeforeRouteHandler>;
416
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, WebAdapter>;
446
417
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
447
418
  onApiChange: import("@modern-js/plugin").Waterfall<Change[]>;
448
419
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<ServerOptions, any>;
@@ -466,10 +437,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
466
437
  beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
467
438
  context: ModernServerContext;
468
439
  }, any>;
469
- afterMatch: import("@modern-js/plugin").AsyncPipeline<{
470
- context: ModernServerContext;
471
- routeAPI: any;
472
- }, any>;
440
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<AfterMatchContext, any>;
473
441
  prefetch: import("@modern-js/plugin").ParallelWorkflow<{
474
442
  context: SSRServerContext;
475
443
  }, unknown>;
@@ -480,10 +448,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
480
448
  beforeRender: import("@modern-js/plugin").AsyncPipeline<{
481
449
  context: ModernServerContext;
482
450
  }, any>;
483
- afterRender: import("@modern-js/plugin").AsyncPipeline<{
484
- context: ModernServerContext;
485
- templateAPI: any;
486
- }, any>;
451
+ afterRender: import("@modern-js/plugin").AsyncPipeline<AfterRenderContext, any>;
487
452
  beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
488
453
  afterSend: import("@modern-js/plugin").ParallelWorkflow<{
489
454
  context: ModernServerContext;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.21.5",
14
+ "version": "2.0.0-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -29,8 +29,8 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@modern-js/plugin": "1.21.5",
33
- "@modern-js/utils": "1.21.5"
32
+ "@modern-js/plugin": "2.0.0-beta.1",
33
+ "@modern-js/utils": "2.0.0-beta.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/jest": "^27",
@@ -39,10 +39,10 @@
39
39
  "jest": "^27",
40
40
  "ts-jest": "^27.0.4",
41
41
  "typescript": "^4",
42
- "@modern-js/core": "1.21.5",
43
- "@modern-js/types": "1.21.5",
44
- "@scripts/build": "1.21.5",
45
- "@scripts/jest-config": "1.21.5"
42
+ "@modern-js/core": "2.0.0-beta.1",
43
+ "@modern-js/types": "2.0.0-beta.1",
44
+ "@scripts/build": "2.0.0-beta.1",
45
+ "@scripts/jest-config": "2.0.0-beta.1"
46
46
  },
47
47
  "sideEffects": false,
48
48
  "modernConfig": {
@@ -54,32 +54,10 @@
54
54
  "registry": "https://registry.npmjs.org/",
55
55
  "access": "public"
56
56
  },
57
- "wireit": {
58
- "build": {
59
- "command": "modern build",
60
- "files": [
61
- "src/**/*",
62
- "tsconfig.json",
63
- "package.json"
64
- ],
65
- "output": [
66
- "dist/**/*"
67
- ]
68
- },
69
- "test": {
70
- "command": "jest --passWithNoTests",
71
- "files": [
72
- "src/**/*",
73
- "tsconfig.json",
74
- "package.json",
75
- "tests/**/*"
76
- ],
77
- "output": []
78
- }
79
- },
80
57
  "scripts": {
81
58
  "new": "modern new",
82
- "build": "wireit",
83
- "test": "wireit"
59
+ "dev": "modern build --watch",
60
+ "build": "modern build",
61
+ "test": "jest --passWithNoTests"
84
62
  }
85
63
  }