From 339124723727c36a0e8520b20d147db8fd451f70 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Sun, 6 Oct 2024 16:33:32 +0900 Subject: [PATCH] Revert "refactor: BridgeServerDevEnvironment" This reverts commit 4de2cee008ee74c131bf782ee5779a5fee736b41. --- examples/child-process/vite.config.ts | 47 ++++++++++++--------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/examples/child-process/vite.config.ts b/examples/child-process/vite.config.ts index 5f1d2a1..19cfa9e 100644 --- a/examples/child-process/vite.config.ts +++ b/examples/child-process/vite.config.ts @@ -77,11 +77,24 @@ export default defineConfig((_env) => ({ }, })); -class BridgeServerDevEnvironment extends DevEnvironment { +// TODO +// can we abstract away child process? FetchBridgeDevEnvironment? +// multiple children per env (like Vitest)? need different API? +export class ChildProcessFetchDevEnvironment extends DevEnvironment { public bridge!: http.Server; public bridgeUrl!: string; + public child!: childProcess.ChildProcess; + public childUrl!: string; + public childUrlPromise!: PromiseWithResolvers; + + constructor( + public extraOptions: { command: string[] }, + ...args: ConstructorParameters + ) { + super(...args); + } - override async init(...args: Parameters) { + override init: DevEnvironment["init"] = async (...args) => { await super.init(...args); const listener = webToNodeHandler(async (request) => { @@ -117,29 +130,8 @@ class BridgeServerDevEnvironment extends DevEnvironment { reject(e); }); }); - } - - override async close(...args: Parameters) { - await super.close(...args); - this.bridge?.close(); - } -} - -export class ChildProcessFetchDevEnvironment extends BridgeServerDevEnvironment { - public child!: childProcess.ChildProcess; - public childUrl!: string; - public childUrlPromise!: PromiseWithResolvers; - - constructor( - public extraOptions: { command: string[] }, - ...args: ConstructorParameters - ) { - super(...args); - } - - override async init(...args: Parameters) { - await super.init(...args); + // TODO: separate child process concern? this.childUrlPromise = PromiseWithReoslvers(); const command = this.extraOptions.command; const child = childProcess.spawn( @@ -169,12 +161,13 @@ export class ChildProcessFetchDevEnvironment extends BridgeServerDevEnvironment bridgeUrl: this.bridgeUrl, childUrl: this.childUrl, }); - } + }; - override async close(...args: Parameters) { + override close: DevEnvironment["close"] = async (...args) => { await super.close(...args); this.child?.kill(); - } + this.bridge?.close(); + }; async dispatchFetch(entry: string, request: Request): Promise { const headers = new Headers(request.headers);