From 502a248e21b4c93a48190d154c18b0b2eb4fac75 Mon Sep 17 00:00:00 2001 From: liximomo Date: Wed, 6 Dec 2023 17:18:18 +0800 Subject: [PATCH] feat: pass request to appContext hook --- packages/platform-shared/src/shared/application.ts | 6 +++++- packages/platform-shared/src/shared/applicationTypes.ts | 2 ++ packages/platform-shared/src/shared/runtimPlugin.ts | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/platform-shared/src/shared/application.ts b/packages/platform-shared/src/shared/application.ts index 2ac58000e..935d4fd2f 100644 --- a/packages/platform-shared/src/shared/application.ts +++ b/packages/platform-shared/src/shared/application.ts @@ -1,3 +1,4 @@ +import type { ShuviRequest } from '@shuvi/service'; import { getManager, PluginManager } from './runtimPlugin'; import { initPlugins } from './runtimPlugin'; import { ModelPublicInstance, doura } from 'doura'; @@ -18,6 +19,7 @@ export class ApplicationImpl { private _router: IRouter; private _appComponent: any; private _pluginManager: PluginManager; + private _request?: ShuviRequest; private _context: IAppContext; private _config: Config; private _store: Doura; @@ -28,6 +30,7 @@ export class ApplicationImpl { constructor(options: ApplicationInternalOptions) { this._config = options.config; this._router = options.router; + this._request = options.request; this._context = {} as IAppContext; this._store = doura({ initialState: options.initialState }); this._error = this._store.getModel(errorModelName, errorModel); @@ -110,7 +113,8 @@ export class ApplicationImpl { private async _initAppContext() { await this._pluginManager.runner.appContext(this._context, { - router: this._router + router: this._router, + request: this._request }); } diff --git a/packages/platform-shared/src/shared/applicationTypes.ts b/packages/platform-shared/src/shared/applicationTypes.ts index edc32826d..f660bb7e5 100644 --- a/packages/platform-shared/src/shared/applicationTypes.ts +++ b/packages/platform-shared/src/shared/applicationTypes.ts @@ -1,5 +1,6 @@ import { Doura } from 'doura'; import { CustomAppContext } from '@shuvi/runtime'; +import type { ShuviRequest } from '@shuvi/service'; import { IRouter } from './routerTypes'; import { IPluginList } from './runtimPlugin'; import { Loader } from './loader'; @@ -57,6 +58,7 @@ export interface ApplicationInternalOptions { getLoaders: GetLoadersFn; initialState?: IAppState; plugins?: IPluginList; + request?: ShuviRequest; } export type ApplicationlOptions = Omit< diff --git a/packages/platform-shared/src/shared/runtimPlugin.ts b/packages/platform-shared/src/shared/runtimPlugin.ts index dba581ff5..450e4b506 100644 --- a/packages/platform-shared/src/shared/runtimPlugin.ts +++ b/packages/platform-shared/src/shared/runtimPlugin.ts @@ -8,6 +8,7 @@ import { IPluginHandlers, HookMap } from '@shuvi/hook'; +import type { ShuviRequest } from '@shuvi/service'; import { CustomRuntimePluginHooks } from '@shuvi/runtime'; import { createPluginCreator } from '@shuvi/shared/plugins'; import { IAppContext } from './applicationTypes'; @@ -16,6 +17,7 @@ import { IRouter } from './routerTypes'; export type AppComponent = unknown; export type AppContextCtx = { router: IRouter; + request?: ShuviRequest; }; const init = createAsyncParallelHook();