@modern-js/server-core 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.
- 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/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/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/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 +4 -3
- 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
|
@@ -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",
|
|
@@ -54,8 +54,9 @@
|
|
|
54
54
|
"hono": "^3.12.2",
|
|
55
55
|
"ts-deepmerge": "7.0.2",
|
|
56
56
|
"@modern-js/plugin": "2.65.5",
|
|
57
|
-
"@modern-js/utils": "2.65.5",
|
|
58
|
-
"@modern-js/
|
|
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",
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var pluginManager_exports = {};
|
|
20
|
-
__export(pluginManager_exports, {
|
|
21
|
-
PluginManager: () => PluginManager
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(pluginManager_exports);
|
|
24
|
-
var import_class_private_field_get = require("@swc/helpers/_/_class_private_field_get");
|
|
25
|
-
var import_class_private_field_init = require("@swc/helpers/_/_class_private_field_init");
|
|
26
|
-
var import_class_private_field_set = require("@swc/helpers/_/_class_private_field_set");
|
|
27
|
-
var import_class_private_method_get = require("@swc/helpers/_/_class_private_method_get");
|
|
28
|
-
var import_class_private_method_init = require("@swc/helpers/_/_class_private_method_init");
|
|
29
|
-
var import_plugin = require("@modern-js/plugin");
|
|
30
|
-
var import_utils = require("./utils");
|
|
31
|
-
var _appContext = /* @__PURE__ */ new WeakMap(), _plugins = /* @__PURE__ */ new WeakMap(), _options = /* @__PURE__ */ new WeakMap(), _configContext = /* @__PURE__ */ new WeakMap(), _createCoreManager = /* @__PURE__ */ new WeakSet(), _initConfigContext = /* @__PURE__ */ new WeakSet();
|
|
32
|
-
class PluginManager {
|
|
33
|
-
async init() {
|
|
34
|
-
const coreManager = (0, import_class_private_method_get._)(this, _createCoreManager, createCoreManager).call(this);
|
|
35
|
-
const runner = await coreManager.init();
|
|
36
|
-
await (0, import_class_private_method_get._)(this, _initConfigContext, initConfigContext).call(this, runner);
|
|
37
|
-
return runner;
|
|
38
|
-
}
|
|
39
|
-
addPlugins(plugins) {
|
|
40
|
-
(0, import_class_private_field_get._)(this, _plugins).push(...plugins);
|
|
41
|
-
}
|
|
42
|
-
constructor(options) {
|
|
43
|
-
(0, import_class_private_method_init._)(this, _createCoreManager);
|
|
44
|
-
(0, import_class_private_method_init._)(this, _initConfigContext);
|
|
45
|
-
(0, import_class_private_field_init._)(this, _appContext, {
|
|
46
|
-
writable: true,
|
|
47
|
-
value: void 0
|
|
48
|
-
});
|
|
49
|
-
(0, import_class_private_field_init._)(this, _plugins, {
|
|
50
|
-
writable: true,
|
|
51
|
-
value: void 0
|
|
52
|
-
});
|
|
53
|
-
(0, import_class_private_field_init._)(this, _options, {
|
|
54
|
-
writable: true,
|
|
55
|
-
value: void 0
|
|
56
|
-
});
|
|
57
|
-
(0, import_class_private_field_init._)(this, _configContext, {
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
|
-
(0, import_class_private_field_set._)(this, _plugins, []);
|
|
62
|
-
(0, import_class_private_field_set._)(this, _configContext, (0, import_plugin.createContext)({}));
|
|
63
|
-
(0, import_class_private_field_set._)(this, _appContext, options.appContext);
|
|
64
|
-
(0, import_class_private_field_set._)(this, _configContext, (0, import_plugin.createContext)(options.serverConfig || {}));
|
|
65
|
-
(0, import_class_private_field_set._)(this, _options, options);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function createCoreManager() {
|
|
69
|
-
var _class_private_field_get_serverConfig;
|
|
70
|
-
const hooks = {
|
|
71
|
-
config: (0, import_plugin.createAsyncWaterfall)(),
|
|
72
|
-
prepare: (0, import_plugin.createAsyncWaterfall)(),
|
|
73
|
-
reset: (0, import_plugin.createAsyncWorkflow)(),
|
|
74
|
-
prepareWebServer: (0, import_plugin.createAsyncPipeline)(),
|
|
75
|
-
fallback: (0, import_plugin.createParallelWorkflow)(),
|
|
76
|
-
prepareApiServer: (0, import_plugin.createAsyncPipeline)(),
|
|
77
|
-
afterMatch: (0, import_plugin.createAsyncPipeline)(),
|
|
78
|
-
afterRender: (0, import_plugin.createAsyncPipeline)(),
|
|
79
|
-
afterStreamingRender: (0, import_plugin.createAsyncPipeline)()
|
|
80
|
-
};
|
|
81
|
-
const pluginApi = {
|
|
82
|
-
useConfigContext: () => (0, import_class_private_field_get._)(this, _configContext).use().value,
|
|
83
|
-
useAppContext: () => (0, import_class_private_field_get._)(this, _appContext).use().value,
|
|
84
|
-
setAppContext: (c) => (0, import_class_private_field_get._)(this, _appContext).set(c)
|
|
85
|
-
};
|
|
86
|
-
const coreManager = (0, import_plugin.createAsyncManager)(hooks, pluginApi);
|
|
87
|
-
this.addPlugins(((_class_private_field_get_serverConfig = (0, import_class_private_field_get._)(this, _options).serverConfig) === null || _class_private_field_get_serverConfig === void 0 ? void 0 : _class_private_field_get_serverConfig.plugins) || []);
|
|
88
|
-
(0, import_class_private_field_get._)(this, _plugins).forEach((p) => {
|
|
89
|
-
const plugin = coreManager.createPlugin(p.setup, p);
|
|
90
|
-
coreManager.usePlugin(plugin);
|
|
91
|
-
});
|
|
92
|
-
return coreManager;
|
|
93
|
-
}
|
|
94
|
-
async function initConfigContext(runner) {
|
|
95
|
-
const { serverConfig, cliConfig } = (0, import_class_private_field_get._)(this, _options);
|
|
96
|
-
const mergedConfig = (0, import_utils.loadConfig)({
|
|
97
|
-
cliConfig,
|
|
98
|
-
serverConfig: serverConfig || {}
|
|
99
|
-
});
|
|
100
|
-
const finalServerConfig = await runner.config(mergedConfig);
|
|
101
|
-
(0, import_class_private_field_get._)(this, _configContext).set(finalServerConfig);
|
|
102
|
-
}
|
|
103
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
-
0 && (module.exports = {
|
|
105
|
-
PluginManager
|
|
106
|
-
});
|