From a75fc3193d5e8d8756dfb3a046873e9c222bb6c8 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Mon, 2 Dec 2024 13:28:15 +0000 Subject: [PATCH] fix: make result interfaces for `ModuleRunnerTransport#invoke` more explicit (#18851) --- docs/guide/api-environment-runtimes.md | 4 +--- packages/vite/src/shared/moduleRunnerTransport.ts | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/guide/api-environment-runtimes.md b/docs/guide/api-environment-runtimes.md index c54f892f52bde4..adf37d31ebbea1 100644 --- a/docs/guide/api-environment-runtimes.md +++ b/docs/guide/api-environment-runtimes.md @@ -265,9 +265,7 @@ interface ModuleRunnerTransport { connect?(handlers: ModuleRunnerTransportHandlers): Promise | void disconnect?(): Promise | void send?(data: HotPayload): Promise | void - invoke?( - data: HotPayload, - ): Promise<{ /** result */ r: any } | { /** error */ e: any }> + invoke?(data: HotPayload): Promise<{ result: any } | { error: any }> timeout?: number } ``` diff --git a/packages/vite/src/shared/moduleRunnerTransport.ts b/packages/vite/src/shared/moduleRunnerTransport.ts index 8fad9b0d2f5fe0..23b91c7a5bf50d 100644 --- a/packages/vite/src/shared/moduleRunnerTransport.ts +++ b/packages/vite/src/shared/moduleRunnerTransport.ts @@ -19,9 +19,7 @@ export interface ModuleRunnerTransport { connect?(handlers: ModuleRunnerTransportHandlers): Promise | void disconnect?(): Promise | void send?(data: HotPayload): Promise | void - invoke?( - data: HotPayload, - ): Promise<{ /** result */ r: any } | { /** error */ e: any }> + invoke?(data: HotPayload): Promise<{ result: any } | { error: any }> timeout?: number } @@ -58,10 +56,10 @@ const createInvokeableTransport = ( data, } satisfies InvokeSendData, } satisfies CustomPayload) - if ('e' in result) { - throw reviveInvokeError(result.e) + if ('error' in result) { + throw reviveInvokeError(result.error) } - return result.r + return result.result }, } }