@modern-js/server-core 2.65.4 → 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.
- package/dist/cjs/adapters/node/hono.js +24 -0
- package/dist/cjs/adapters/node/index.js +2 -0
- package/dist/cjs/index.js +2 -5
- package/dist/cjs/plugins/compat/hooks.js +92 -0
- package/dist/cjs/plugins/compat/index.js +65 -0
- package/dist/cjs/plugins/customServer/index.js +11 -17
- package/dist/cjs/plugins/default.js +2 -0
- package/dist/cjs/plugins/index.js +5 -0
- package/dist/cjs/plugins/render/index.js +2 -2
- package/dist/cjs/serverBase.js +31 -40
- package/dist/cjs/types/index.js +2 -2
- package/dist/cjs/types/{plugin.js → plugins/base.js} +2 -2
- package/dist/cjs/types/plugins/index.js +24 -0
- package/dist/cjs/types/plugins/new.js +16 -0
- package/dist/cjs/types/plugins/old.js +16 -0
- package/dist/esm/adapters/node/hono.js +33 -0
- package/dist/esm/adapters/node/index.js +2 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/plugins/compat/hooks.js +70 -0
- package/dist/esm/plugins/compat/index.js +45 -0
- package/dist/esm/plugins/customServer/index.js +30 -22
- package/dist/esm/plugins/default.js +2 -0
- package/dist/esm/plugins/index.js +3 -0
- package/dist/esm/plugins/render/index.js +3 -3
- package/dist/esm/serverBase.js +34 -38
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/types/plugins/base.js +0 -0
- package/dist/esm/types/plugins/index.js +2 -0
- package/dist/esm/types/plugins/new.js +0 -0
- package/dist/esm/types/plugins/old.js +0 -0
- package/dist/esm-node/adapters/node/hono.js +23 -0
- package/dist/esm-node/adapters/node/index.js +2 -1
- package/dist/esm-node/index.js +1 -3
- package/dist/esm-node/plugins/compat/hooks.js +66 -0
- package/dist/esm-node/plugins/compat/index.js +40 -0
- package/dist/esm-node/plugins/customServer/index.js +10 -16
- package/dist/esm-node/plugins/default.js +2 -0
- package/dist/esm-node/plugins/index.js +3 -0
- package/dist/esm-node/plugins/render/index.js +2 -2
- package/dist/esm-node/serverBase.js +31 -40
- package/dist/esm-node/types/index.js +1 -1
- package/dist/esm-node/types/plugins/index.js +2 -0
- package/dist/esm-node/types/plugins/old.js +0 -0
- package/dist/types/adapters/node/hono.d.ts +6 -0
- package/dist/types/adapters/node/index.d.ts +1 -1
- package/dist/types/adapters/node/plugins/nodeServer.d.ts +4 -2
- package/dist/types/adapters/node/plugins/resource.d.ts +3 -3
- package/dist/types/adapters/node/plugins/static.d.ts +2 -2
- package/dist/types/index.d.ts +1 -2
- package/dist/types/plugins/compat/hooks.d.ts +8 -0
- package/dist/types/plugins/compat/index.d.ts +3 -0
- package/dist/types/plugins/customServer/index.d.ts +3 -3
- package/dist/types/plugins/default.d.ts +2 -2
- package/dist/types/plugins/favicon.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +1 -0
- package/dist/types/plugins/log.d.ts +2 -2
- package/dist/types/plugins/monitors.d.ts +4 -4
- package/dist/types/plugins/processedBy.d.ts +2 -2
- package/dist/types/plugins/render/index.d.ts +2 -2
- package/dist/types/plugins/render/inject.d.ts +2 -2
- package/dist/types/plugins/route.d.ts +2 -2
- package/dist/types/serverBase.d.ts +11 -22
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/plugins/base.d.ts +80 -0
- package/dist/types/types/plugins/index.d.ts +3 -0
- package/dist/types/types/plugins/new.d.ts +34 -0
- package/dist/types/types/plugins/old.d.ts +56 -0
- package/package.json +9 -9
- package/dist/cjs/pluginManager.js +0 -106
- package/dist/esm/pluginManager.js +0 -140
- package/dist/esm-node/pluginManager.js +0 -82
- package/dist/types/pluginManager.d.ts +0 -31
- package/dist/types/types/plugin.d.ts +0 -150
- /package/dist/esm-node/types/{plugin.js → plugins/base.js} +0 -0
- /package/dist/{esm/types/plugin.js → esm-node/types/plugins/new.js} +0 -0
|
@@ -4,10 +4,13 @@ import { injectServerTiming, injectloggerPlugin } from "./monitors";
|
|
|
4
4
|
import { processedByPlugin } from "./processedBy";
|
|
5
5
|
import { logPlugin } from "./log";
|
|
6
6
|
import { createDefaultPlugins } from "./default";
|
|
7
|
+
import { compatPlugin, handleSetupResult } from "./compat";
|
|
7
8
|
export {
|
|
9
|
+
compatPlugin,
|
|
8
10
|
createDefaultPlugins,
|
|
9
11
|
faviconPlugin,
|
|
10
12
|
getRenderHandler,
|
|
13
|
+
handleSetupResult,
|
|
11
14
|
injectRenderHandlerPlugin,
|
|
12
15
|
injectServerTiming,
|
|
13
16
|
injectloggerPlugin,
|
|
@@ -11,12 +11,12 @@ const renderPlugin = () => ({
|
|
|
11
11
|
async prepare() {
|
|
12
12
|
var _config_render;
|
|
13
13
|
const { middlewares, routes, render, distDirectory: pwd, serverBase } = api.useAppContext();
|
|
14
|
-
const
|
|
14
|
+
const hooks = api.getHooks();
|
|
15
15
|
const config = api.useConfigContext();
|
|
16
16
|
if (!routes) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
const customServer = new CustomServer(
|
|
19
|
+
const customServer = new CustomServer(hooks, serverBase, pwd);
|
|
20
20
|
const serverMiddleware = ((_config_render = config.render) === null || _config_render === void 0 ? void 0 : _config_render.middleware) && getServerMidFromUnstableMid(config.render.middleware);
|
|
21
21
|
const pageRoutes = getPageRoutes(routes);
|
|
22
22
|
middlewares.push({
|
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
import { _ as _class_private_method_get } from "@swc/helpers/_/_class_private_method_get";
|
|
2
2
|
import { _ as _class_private_method_init } from "@swc/helpers/_/_class_private_method_init";
|
|
3
|
-
import {
|
|
3
|
+
import { server } from "@modern-js/plugin-v2/server";
|
|
4
4
|
import { Hono } from "hono";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { handleSetupResult } from "./plugins/compat/hooks";
|
|
6
|
+
import { loadConfig } from "./utils";
|
|
7
|
+
var _applyMiddlewares = /* @__PURE__ */ new WeakSet();
|
|
7
8
|
class ServerBase {
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* - 应用 middlewares
|
|
10
|
+
* Order
|
|
11
|
+
* - server runner
|
|
12
|
+
* - apply middlewares
|
|
13
13
|
*/
|
|
14
14
|
async init() {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const { serverConfig, config: cliConfig } = this.options;
|
|
16
|
+
const mergedConfig = loadConfig({
|
|
17
|
+
cliConfig,
|
|
18
|
+
serverConfig: serverConfig || {}
|
|
19
|
+
});
|
|
20
|
+
this.addPlugins(mergedConfig.plugins || []);
|
|
21
|
+
const { serverContext } = await server.run({
|
|
22
|
+
plugins: this.plugins,
|
|
23
|
+
options: this.options,
|
|
24
|
+
config: mergedConfig,
|
|
25
|
+
handleSetupResult
|
|
26
|
+
});
|
|
27
|
+
serverContext.serverBase = this;
|
|
28
|
+
await serverContext.hooks.onPrepare.call();
|
|
29
|
+
this.serverContext = serverContext;
|
|
18
30
|
_class_private_method_get(this, _applyMiddlewares, applyMiddlewares).call(this);
|
|
19
31
|
return this;
|
|
20
32
|
}
|
|
21
33
|
addPlugins(plugins) {
|
|
22
|
-
this.
|
|
34
|
+
this.plugins.push(...plugins);
|
|
35
|
+
}
|
|
36
|
+
get hooks() {
|
|
37
|
+
return this.serverContext.hooks;
|
|
23
38
|
}
|
|
24
39
|
get all() {
|
|
25
40
|
return this.app.all.bind(this.app);
|
|
@@ -55,39 +70,15 @@ class ServerBase {
|
|
|
55
70
|
return this.app.onError.bind(this.app);
|
|
56
71
|
}
|
|
57
72
|
constructor(options) {
|
|
58
|
-
_class_private_method_init(this, _getAppContext);
|
|
59
73
|
_class_private_method_init(this, _applyMiddlewares);
|
|
74
|
+
this.plugins = [];
|
|
75
|
+
this.serverContext = null;
|
|
60
76
|
this.options = options;
|
|
61
|
-
const { config, serverConfig } = options;
|
|
62
|
-
const appContext = _class_private_method_get(this, _getAppContext, getAppContext).call(this);
|
|
63
|
-
this.appContext = appContext;
|
|
64
|
-
this.pluginManager = new PluginManager({
|
|
65
|
-
cliConfig: config,
|
|
66
|
-
appContext,
|
|
67
|
-
serverConfig
|
|
68
|
-
});
|
|
69
77
|
this.app = new Hono();
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
|
-
function getAppContext() {
|
|
73
|
-
const { appContext: context, pwd, routes, metaName } = this.options;
|
|
74
|
-
const appContext = {
|
|
75
|
-
routes,
|
|
76
|
-
middlewares: [],
|
|
77
|
-
appDirectory: (context === null || context === void 0 ? void 0 : context.appDirectory) || "",
|
|
78
|
-
apiDirectory: context === null || context === void 0 ? void 0 : context.apiDirectory,
|
|
79
|
-
internalDirectory: (context === null || context === void 0 ? void 0 : context.internalDirectory) || "",
|
|
80
|
-
lambdaDirectory: context === null || context === void 0 ? void 0 : context.lambdaDirectory,
|
|
81
|
-
sharedDirectory: (context === null || context === void 0 ? void 0 : context.sharedDirectory) || "",
|
|
82
|
-
distDirectory: pwd,
|
|
83
|
-
plugins: [],
|
|
84
|
-
metaName: metaName || "modern-js",
|
|
85
|
-
serverBase: this
|
|
86
|
-
};
|
|
87
|
-
return createContext(appContext);
|
|
88
|
-
}
|
|
89
80
|
function applyMiddlewares() {
|
|
90
|
-
const { middlewares } = this.
|
|
81
|
+
const { middlewares } = this.serverContext;
|
|
91
82
|
const preMiddlewares = [];
|
|
92
83
|
const defaultMiddlewares = [];
|
|
93
84
|
const postMiddlewares = [];
|
|
@@ -145,8 +136,8 @@ function createServerBase(options) {
|
|
|
145
136
|
if (options == null) {
|
|
146
137
|
throw new Error("can not start server without options");
|
|
147
138
|
}
|
|
148
|
-
const
|
|
149
|
-
return
|
|
139
|
+
const server2 = new ServerBase(options);
|
|
140
|
+
return server2;
|
|
150
141
|
}
|
|
151
142
|
export {
|
|
152
143
|
ServerBase,
|
|
File without changes
|
|
@@ -9,4 +9,10 @@ type Handler = (req: NodeRequest, res: NodeResponse) => void | Promise<void>;
|
|
|
9
9
|
export declare const httpCallBack2HonoMid: (handler: Handler) => (context: Context<ServerNodeEnv & ServerEnv>, next: Next) => Promise<void>;
|
|
10
10
|
type ConnectMiddleware = ((req: NodeRequest, res: NodeResponse, callback: (...args: unknown[]) => void) => void) | ((req: NodeRequest, res: NodeResponse) => void);
|
|
11
11
|
export declare const connectMid2HonoMid: (handler: ConnectMiddleware) => Middleware;
|
|
12
|
+
/**
|
|
13
|
+
* Because we are not sure how use devServer.before and devServer.after, we add a new function to handle the mock middleware
|
|
14
|
+
* And we supose mock handler always process the res directly
|
|
15
|
+
* So we need to set the context.finalized = true and resolve the promise
|
|
16
|
+
*/
|
|
17
|
+
export declare const connectMockMid2HonoMid: (handler: ConnectMiddleware) => Middleware;
|
|
12
18
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { httpCallBack2HonoMid, connectMid2HonoMid } from './hono';
|
|
1
|
+
export { httpCallBack2HonoMid, connectMid2HonoMid, connectMockMid2HonoMid, } from './hono';
|
|
2
2
|
export type { ServerNodeContext, ServerNodeMiddleware } from './hono';
|
|
3
3
|
export { createNodeServer, sendResponse, createWebRequest, writeReadableStreamToWritable, } from './node';
|
|
4
4
|
export { serverStaticPlugin, injectResourcePlugin, getHtmlTemplates, getServerManifest, injectNodeSeverPlugin, injectRscManifestPlugin, } from './plugins';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Server as NodeServer } from 'node:http';
|
|
3
|
+
import type { ServerPluginLegacy } from '../../../types';
|
|
2
4
|
export declare const injectNodeSeverPlugin: ({ nodeServer, }: {
|
|
3
5
|
nodeServer: NodeServer;
|
|
4
|
-
}) =>
|
|
6
|
+
}) => ServerPluginLegacy;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger, ServerRoute } from '@modern-js/types';
|
|
2
|
-
import type { Middleware, ServerEnv, ServerManifest,
|
|
2
|
+
import type { Middleware, ServerEnv, ServerManifest, ServerPluginLegacy } from '../../../types';
|
|
3
3
|
export declare function getHtmlTemplates(pwd: string, routes: ServerRoute[]): Promise<Record<string, string>>;
|
|
4
4
|
export declare function injectTemplates(pwd: string, routes?: ServerRoute[], htmlTemplatePromise?: ReturnType<typeof getHtmlTemplates>): Middleware<ServerEnv>;
|
|
5
5
|
export declare function getServerManifest(pwd: string, routes: ServerRoute[], logger: Logger): Promise<ServerManifest>;
|
|
@@ -7,5 +7,5 @@ export declare function injectServerManifest(pwd: string, routes?: ServerRoute[]
|
|
|
7
7
|
export declare function getRscServerManifest(pwd: string): Promise<any>;
|
|
8
8
|
export declare function getClientManifest(pwd: string): Promise<any>;
|
|
9
9
|
export declare function getRscSSRManifest(pwd: string): Promise<any>;
|
|
10
|
-
export declare const injectRscManifestPlugin: () =>
|
|
11
|
-
export declare const injectResourcePlugin: () =>
|
|
10
|
+
export declare const injectRscManifestPlugin: () => ServerPluginLegacy;
|
|
11
|
+
export declare const injectResourcePlugin: () => ServerPluginLegacy;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ServerRoute } from '@modern-js/types';
|
|
2
|
-
import type { HtmlNormalizedConfig, Middleware, OutputNormalizedConfig,
|
|
3
|
-
export declare const serverStaticPlugin: () =>
|
|
2
|
+
import type { HtmlNormalizedConfig, Middleware, OutputNormalizedConfig, ServerPluginLegacy } from '../../../types';
|
|
3
|
+
export declare const serverStaticPlugin: () => ServerPluginLegacy;
|
|
4
4
|
export type PublicMiddlwareOptions = {
|
|
5
5
|
pwd: string;
|
|
6
6
|
routes: ServerRoute[];
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ export { createErrorHtml, onError, ErrorDigest } from './utils';
|
|
|
2
2
|
export { AGGRED_DIR } from './constants';
|
|
3
3
|
export type { ServerBase, ServerBaseOptions } from './serverBase';
|
|
4
4
|
export { createServerBase } from './serverBase';
|
|
5
|
-
export { PluginManager, type PluginManagerOptions } from './pluginManager';
|
|
6
5
|
export type { Middleware, Context, Next, HonoRequest as InternalRequest, ServerEnv, ServerManifest, ServerLoaderBundle, } from './types';
|
|
7
6
|
export { getLoaderCtx } from './helper';
|
|
8
7
|
export * from './plugins';
|
|
9
|
-
export * from './types/
|
|
8
|
+
export * from './types/plugins';
|
|
10
9
|
export * from './types/render';
|
|
11
10
|
export * from '@modern-js/plugin';
|
|
12
11
|
export * from './types/config';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { InternalServerContext } from '@modern-js/plugin-v2';
|
|
2
|
+
import type { ServerPluginExtends } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* old plugin useHookRunners function result
|
|
5
|
+
*/
|
|
6
|
+
export declare function getHookRunners(context: InternalServerContext<ServerPluginExtends>): Record<string, any>;
|
|
7
|
+
export declare function transformHookRunner(hookRunnerName: string): string;
|
|
8
|
+
export declare function handleSetupResult(setupResult: Record<string, (...args: any) => any>, api: Record<string, any>): void;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ServerRoute, UnstableMiddleware } from '@modern-js/types';
|
|
2
2
|
import type { ServerNodeEnv } from '../../adapters/node/hono';
|
|
3
3
|
import type { ServerBase } from '../../serverBase';
|
|
4
|
-
import type { Middleware, ServerEnv,
|
|
4
|
+
import type { Middleware, ServerEnv, ServerPluginHooks } from '../../types';
|
|
5
5
|
export declare class CustomServer {
|
|
6
|
-
private
|
|
6
|
+
private hooks;
|
|
7
7
|
private serverMiddlewarePromise;
|
|
8
8
|
private serverBase;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(hooks: ServerPluginHooks, serverBase: ServerBase, pwd: string);
|
|
10
10
|
getHookMiddleware(entryName: string, routes: ServerRoute[]): Middleware<ServerEnv>;
|
|
11
11
|
getServerMiddleware(renderMiddlewares?: Middleware<ServerNodeEnv & ServerEnv>[]): Promise<Middleware<ServerNodeEnv & ServerEnv> | Array<Middleware<ServerNodeEnv & ServerEnv>> | undefined>;
|
|
12
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Logger } from '@modern-js/types';
|
|
2
|
-
import type { ServerPlugin } from '../types';
|
|
2
|
+
import type { ServerPlugin, ServerPluginLegacy } from '../types';
|
|
3
3
|
import { type InjectRenderHandlerOptions } from './render';
|
|
4
4
|
export type CreateDefaultPluginsOptions = InjectRenderHandlerOptions & {
|
|
5
5
|
logger?: Logger | false;
|
|
6
6
|
};
|
|
7
|
-
export declare function createDefaultPlugins(options?: CreateDefaultPluginsOptions): ServerPlugin[];
|
|
7
|
+
export declare function createDefaultPlugins(options?: CreateDefaultPluginsOptions): (ServerPluginLegacy | ServerPlugin)[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const faviconPlugin: () =>
|
|
1
|
+
import type { ServerPluginLegacy } from '../types';
|
|
2
|
+
export declare const faviconPlugin: () => ServerPluginLegacy;
|
|
@@ -4,3 +4,4 @@ export { injectServerTiming, injectloggerPlugin } from './monitors';
|
|
|
4
4
|
export { processedByPlugin } from './processedBy';
|
|
5
5
|
export { logPlugin } from './log';
|
|
6
6
|
export { createDefaultPlugins, type CreateDefaultPluginsOptions, } from './default';
|
|
7
|
+
export { compatPlugin, handleSetupResult } from './compat';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const logPlugin: () =>
|
|
1
|
+
import type { ServerPluginLegacy } from '../types';
|
|
2
|
+
export declare const logPlugin: () => ServerPluginLegacy;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@modern-js/types';
|
|
2
|
-
import type { Context, Next, ServerEnv,
|
|
3
|
-
export declare const initMonitorsPlugin: () =>
|
|
4
|
-
export declare const injectloggerPlugin: (inputLogger?: Logger) =>
|
|
5
|
-
export declare const injectServerTiming: () =>
|
|
2
|
+
import type { Context, Next, ServerEnv, ServerPluginLegacy } from '../types';
|
|
3
|
+
export declare const initMonitorsPlugin: () => ServerPluginLegacy;
|
|
4
|
+
export declare const injectloggerPlugin: (inputLogger?: Logger) => ServerPluginLegacy;
|
|
5
|
+
export declare const injectServerTiming: () => ServerPluginLegacy;
|
|
6
6
|
export declare function requestLatencyMiddleware(): (c: Context<ServerEnv>, next: Next) => Promise<void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const processedByPlugin: () =>
|
|
1
|
+
import type { ServerPluginLegacy } from '../types';
|
|
2
|
+
export declare const processedByPlugin: () => ServerPluginLegacy;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ServerPluginLegacy } from '../../types';
|
|
2
2
|
export * from './inject';
|
|
3
|
-
export declare const renderPlugin: () =>
|
|
3
|
+
export declare const renderPlugin: () => ServerPluginLegacy;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CacheConfig, GetRenderHandlerOptions, Render,
|
|
1
|
+
import type { CacheConfig, GetRenderHandlerOptions, Render, ServerPluginLegacy } from '../../types';
|
|
2
2
|
export interface InjectRenderHandlerOptions {
|
|
3
3
|
staticGenerate?: boolean;
|
|
4
4
|
cacheConfig?: CacheConfig;
|
|
5
5
|
}
|
|
6
|
-
export declare const injectRenderHandlerPlugin: ({ staticGenerate, cacheConfig, }: InjectRenderHandlerOptions) =>
|
|
6
|
+
export declare const injectRenderHandlerPlugin: ({ staticGenerate, cacheConfig, }: InjectRenderHandlerOptions) => ServerPluginLegacy;
|
|
7
7
|
export declare function getRenderHandler({ pwd, routes, config, cacheConfig, metaName, staticGenerate, onFallback, }: GetRenderHandlerOptions): Promise<Render>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const injectRoutePlugin: () =>
|
|
1
|
+
import type { ServerPluginLegacy } from '../types';
|
|
2
|
+
export declare const injectRoutePlugin: () => ServerPluginLegacy;
|
|
@@ -1,44 +1,33 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ServerCreateOptions } from '@modern-js/plugin-v2/server';
|
|
2
2
|
import { Hono } from 'hono';
|
|
3
|
-
import type { Env, ServerConfig,
|
|
3
|
+
import type { Env, ServerConfig, ServerPlugin, ServerPluginHooks, ServerPluginLegacy } from './types';
|
|
4
4
|
import type { CliConfig } from './types/config';
|
|
5
5
|
declare module '@modern-js/types' {
|
|
6
6
|
interface ISAppContext {
|
|
7
7
|
serverBase?: ServerBase;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export interface ServerBaseOptions extends ServerCreateOptions {
|
|
11
11
|
/** server working directory, and then also dist directory */
|
|
12
|
-
pwd: string;
|
|
13
12
|
config: CliConfig;
|
|
14
13
|
serverConfig?: ServerConfig;
|
|
15
|
-
metaName?: string;
|
|
16
|
-
routes?: ServerRoute[];
|
|
17
|
-
appContext: {
|
|
18
|
-
internalDirectory?: string;
|
|
19
|
-
appDirectory?: string;
|
|
20
|
-
sharedDirectory?: string;
|
|
21
|
-
apiDirectory?: string;
|
|
22
|
-
lambdaDirectory?: string;
|
|
23
|
-
};
|
|
24
14
|
runMode?: 'apiOnly' | 'ssrOnly' | 'webOnly';
|
|
25
|
-
}
|
|
15
|
+
}
|
|
26
16
|
export declare class ServerBase<E extends Env = any> {
|
|
27
17
|
#private;
|
|
28
18
|
options: ServerBaseOptions;
|
|
29
|
-
runner: ServerHookRunner;
|
|
30
19
|
private app;
|
|
31
|
-
private
|
|
32
|
-
private
|
|
20
|
+
private plugins;
|
|
21
|
+
private serverContext;
|
|
33
22
|
constructor(options: ServerBaseOptions);
|
|
34
23
|
/**
|
|
35
|
-
*
|
|
36
|
-
* -
|
|
37
|
-
* -
|
|
38
|
-
* - 应用 middlewares
|
|
24
|
+
* Order
|
|
25
|
+
* - server runner
|
|
26
|
+
* - apply middlewares
|
|
39
27
|
*/
|
|
40
28
|
init(): Promise<this>;
|
|
41
|
-
addPlugins(plugins: ServerPlugin[]): void;
|
|
29
|
+
addPlugins(plugins: (ServerPlugin | ServerPluginLegacy)[]): void;
|
|
30
|
+
get hooks(): ServerPluginHooks;
|
|
42
31
|
get all(): import("hono/types").HandlerInterface<E, "all", {}, "/">;
|
|
43
32
|
get use(): import("hono/types").MiddlewareHandlerInterface<E, {}, "/">;
|
|
44
33
|
get get(): import("hono/types").HandlerInterface<E, "get", {}, "/">;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage, Server as NodeServer, ServerResponse } from 'http';
|
|
3
|
+
import type { CacheOption, Container, HttpMethodDecider, Logger, Metrics, MiddlewareContext, Reporter, ServerRoute, UnstableMiddleware } from '@modern-js/types';
|
|
4
|
+
import type { MiddlewareHandler } from 'hono';
|
|
5
|
+
import type { UserConfig } from '../config';
|
|
6
|
+
import type { Render } from '../render';
|
|
7
|
+
import type { ServerPlugin } from './new';
|
|
8
|
+
import type { ServerPluginLegacy } from './old';
|
|
9
|
+
export type { FileChangeEvent, ResetEvent } from '@modern-js/plugin-v2';
|
|
10
|
+
export type FallbackReason = 'error' | 'header' | 'query';
|
|
11
|
+
export type FallbackInput = {
|
|
12
|
+
reason: FallbackReason;
|
|
13
|
+
error: unknown;
|
|
14
|
+
logger: Logger;
|
|
15
|
+
metrics?: Metrics;
|
|
16
|
+
reporter?: Reporter;
|
|
17
|
+
};
|
|
18
|
+
export type OnFallback = (reason: FallbackReason, utils: {
|
|
19
|
+
logger: Logger;
|
|
20
|
+
metrics?: Metrics;
|
|
21
|
+
reporter?: Reporter;
|
|
22
|
+
}, error?: unknown) => Promise<void>;
|
|
23
|
+
export type APIServerStartInput = {
|
|
24
|
+
pwd: string;
|
|
25
|
+
prefix?: string;
|
|
26
|
+
httpMethodDecider?: HttpMethodDecider;
|
|
27
|
+
config?: {
|
|
28
|
+
middleware?: Array<any>;
|
|
29
|
+
};
|
|
30
|
+
render?: Render | null;
|
|
31
|
+
};
|
|
32
|
+
export type WebServerStartInput = {
|
|
33
|
+
pwd: string;
|
|
34
|
+
config: Record<string, any>;
|
|
35
|
+
};
|
|
36
|
+
export type WebAdapter = (ctx: MiddlewareContext) => void | Promise<void>;
|
|
37
|
+
/** Plugin Api */
|
|
38
|
+
type MiddlewareOrder = 'pre' | 'post' | 'default';
|
|
39
|
+
export type Middleware = {
|
|
40
|
+
name: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
method?: 'options' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all';
|
|
43
|
+
handler: MiddlewareHandler | MiddlewareHandler[];
|
|
44
|
+
before?: Array<Middleware['name']>;
|
|
45
|
+
order?: MiddlewareOrder;
|
|
46
|
+
};
|
|
47
|
+
export interface GetRenderHandlerOptions {
|
|
48
|
+
pwd: string;
|
|
49
|
+
routes: ServerRoute[];
|
|
50
|
+
config: UserConfig;
|
|
51
|
+
onFallback?: OnFallback;
|
|
52
|
+
cacheConfig?: CacheConfig;
|
|
53
|
+
staticGenerate?: boolean;
|
|
54
|
+
metaName?: string;
|
|
55
|
+
}
|
|
56
|
+
declare module '@modern-js/types' {
|
|
57
|
+
interface ISAppContext {
|
|
58
|
+
middlewares: Middleware[];
|
|
59
|
+
metaName: string;
|
|
60
|
+
getRenderOptions?: GetRenderHandlerOptions;
|
|
61
|
+
render?: Render;
|
|
62
|
+
routes?: ServerRoute[];
|
|
63
|
+
nodeServer?: NodeServer;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export type NodeRequest = IncomingMessage;
|
|
67
|
+
export type NodeResponse = ServerResponse;
|
|
68
|
+
export type CacheConfig = {
|
|
69
|
+
strategy: CacheOption;
|
|
70
|
+
container?: Container;
|
|
71
|
+
};
|
|
72
|
+
type RenderMiddleware = UnstableMiddleware;
|
|
73
|
+
export interface RenderConfig {
|
|
74
|
+
cache?: CacheConfig;
|
|
75
|
+
middleware?: RenderMiddleware[];
|
|
76
|
+
}
|
|
77
|
+
export type ServerConfig = {
|
|
78
|
+
render?: RenderConfig;
|
|
79
|
+
plugins?: (ServerPlugin | ServerPluginLegacy)[];
|
|
80
|
+
} & UserConfig;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AsyncHook, AsyncPipelineHook, ServerContext as BaseServerContext, ServerPlugin as BaseServerPlugin, ServerPluginExtends as BaseServerPluginExtends } from '@modern-js/plugin-v2';
|
|
2
|
+
import type { Hooks } from '@modern-js/plugin-v2/server';
|
|
3
|
+
import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, ISAppContext, UnstableMiddleware } from '@modern-js/types';
|
|
4
|
+
import type { MiddlewareHandler } from 'hono';
|
|
5
|
+
import type { Middleware } from './base';
|
|
6
|
+
import type { APIServerStartInput, FallbackInput, ServerConfig, WebAdapter, WebServerStartInput } from './base';
|
|
7
|
+
export type FallbackFn = (input: FallbackInput) => Promise<FallbackInput>;
|
|
8
|
+
export type PrepareWebServerFn = (input: WebServerStartInput) => Promise<WebAdapter | Array<UnstableMiddleware> | null>;
|
|
9
|
+
export type PrepareApiServerFn = (input: APIServerStartInput) => Promise<MiddlewareHandler>;
|
|
10
|
+
export type AfterMatchFn = (ctx: AfterMatchContext) => Promise<any>;
|
|
11
|
+
export type AfterRenderFn = (ctx: AfterRenderContext) => Promise<any>;
|
|
12
|
+
export type AfterStreamingRenderContextFn = (ctx: AfterStreamingRenderContext) => Promise<AfterStreamingRenderContext>;
|
|
13
|
+
export interface ServerPluginExtends extends BaseServerPluginExtends {
|
|
14
|
+
config: ServerConfig;
|
|
15
|
+
extendContext: {
|
|
16
|
+
middlewares: Middleware[];
|
|
17
|
+
};
|
|
18
|
+
extendApi: {
|
|
19
|
+
setAppContext: (c: ISAppContext) => void;
|
|
20
|
+
useAppContext: () => ISAppContext;
|
|
21
|
+
useConfigContext: () => ServerConfig;
|
|
22
|
+
};
|
|
23
|
+
extendHooks: {
|
|
24
|
+
prepareWebServer: AsyncPipelineHook<PrepareWebServerFn>;
|
|
25
|
+
fallback: AsyncHook<FallbackFn>;
|
|
26
|
+
prepareApiServer: AsyncPipelineHook<PrepareApiServerFn>;
|
|
27
|
+
afterMatch: AsyncPipelineHook<AfterMatchFn>;
|
|
28
|
+
afterRender: AsyncPipelineHook<AfterRenderFn>;
|
|
29
|
+
afterStreamingRender: AsyncPipelineHook<AfterStreamingRenderContextFn>;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type ServerPlugin = BaseServerPlugin<ServerPluginExtends>;
|
|
33
|
+
export type ServerContext = BaseServerContext<ServerPluginExtends> & ServerPluginExtends['extendContext'];
|
|
34
|
+
export type ServerPluginHooks = Hooks<ServerPluginExtends> & ServerPluginExtends['extendHooks'];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AsyncPipeline, AsyncSetup, AsyncWaterfall, AsyncWorkflow, CommonAPI, ParallelWorkflow, PluginOptions } from '@modern-js/plugin';
|
|
2
|
+
import type { AfterMatchContext, AfterRenderContext, AfterStreamingRenderContext, ISAppContext, UnstableMiddleware } from '@modern-js/types';
|
|
3
|
+
import type { MiddlewareHandler } from 'hono';
|
|
4
|
+
import type { APIServerStartInput, FallbackInput, ResetEvent, ServerConfig, WebAdapter, WebServerStartInput } from './base';
|
|
5
|
+
export interface ServerHooks {
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated
|
|
8
|
+
*
|
|
9
|
+
* deprecate it next major version
|
|
10
|
+
*/
|
|
11
|
+
config: AsyncWaterfall<ServerConfig>;
|
|
12
|
+
prepare: AsyncWaterfall<void>;
|
|
13
|
+
reset: AsyncWorkflow<{
|
|
14
|
+
event: ResetEvent;
|
|
15
|
+
}, void>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated
|
|
18
|
+
*
|
|
19
|
+
* deprecate it next major version
|
|
20
|
+
* */
|
|
21
|
+
prepareWebServer: AsyncPipeline<WebServerStartInput, WebAdapter | Array<UnstableMiddleware> | null>;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated
|
|
24
|
+
*
|
|
25
|
+
* deprecate it when server runtime entry refactor
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
fallback: ParallelWorkflow<FallbackInput>;
|
|
29
|
+
prepareApiServer: AsyncPipeline<APIServerStartInput, MiddlewareHandler>;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated
|
|
32
|
+
*
|
|
33
|
+
* deprecate it next major version
|
|
34
|
+
*/
|
|
35
|
+
afterMatch: AsyncPipeline<AfterMatchContext, any>;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated
|
|
38
|
+
*
|
|
39
|
+
* deprecate it next major version
|
|
40
|
+
*/
|
|
41
|
+
afterRender: AsyncPipeline<AfterRenderContext, any>;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated
|
|
44
|
+
*
|
|
45
|
+
* deprecate it next major version
|
|
46
|
+
* */
|
|
47
|
+
afterStreamingRender: AsyncPipeline<AfterStreamingRenderContext, string>;
|
|
48
|
+
}
|
|
49
|
+
export type ServerPluginAPI = {
|
|
50
|
+
setAppContext: (c: ISAppContext) => void;
|
|
51
|
+
useAppContext: () => ISAppContext;
|
|
52
|
+
useConfigContext: () => ServerConfig;
|
|
53
|
+
};
|
|
54
|
+
export type PluginAPI = ServerPluginAPI & CommonAPI<ServerHooks>;
|
|
55
|
+
/**old server plugin. */
|
|
56
|
+
export type ServerPluginLegacy = PluginOptions<ServerHooks, AsyncSetup<ServerHooks, PluginAPI>>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.65.
|
|
18
|
+
"version": "2.65.6-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -53,9 +53,10 @@
|
|
|
53
53
|
"flatted": "^3.2.9",
|
|
54
54
|
"hono": "^3.12.2",
|
|
55
55
|
"ts-deepmerge": "7.0.2",
|
|
56
|
-
"@modern-js/plugin": "2.65.
|
|
57
|
-
"@modern-js/runtime-utils": "2.65.
|
|
58
|
-
"@modern-js/
|
|
56
|
+
"@modern-js/plugin": "2.65.5",
|
|
57
|
+
"@modern-js/runtime-utils": "2.65.5",
|
|
58
|
+
"@modern-js/plugin-v2": "2.65.6-alpha.0",
|
|
59
|
+
"@modern-js/utils": "2.65.5"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@types/jest": "^29",
|
|
@@ -65,15 +66,14 @@
|
|
|
65
66
|
"jest": "^29",
|
|
66
67
|
"ts-jest": "^29.1.0",
|
|
67
68
|
"typescript": "^5",
|
|
68
|
-
"@modern-js/types": "2.65.
|
|
69
|
-
"@scripts/build": "2.65.
|
|
70
|
-
"@scripts/jest-config": "2.65.
|
|
69
|
+
"@modern-js/types": "2.65.5",
|
|
70
|
+
"@scripts/build": "2.65.5",
|
|
71
|
+
"@scripts/jest-config": "2.65.5"
|
|
71
72
|
},
|
|
72
73
|
"sideEffects": false,
|
|
73
74
|
"publishConfig": {
|
|
74
75
|
"registry": "https://registry.npmjs.org/",
|
|
75
|
-
"access": "public"
|
|
76
|
-
"provenance": true
|
|
76
|
+
"access": "public"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"new": "modern-lib new",
|