Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 7, 2024
1 parent ec5bff1 commit c395631
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
1 change: 0 additions & 1 deletion examples/browser-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import repl from "node:repl";
import { createManualPromise, tinyassert } from "@hiogawa/utils";
import { chromium } from "@playwright/test";
import {
DevEnvironment,
type Plugin,
type PluginOption,
createServer,
Expand Down
6 changes: 3 additions & 3 deletions examples/web-worker/src/lib/fetch-module-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { ModuleRunnerTransport } from "vite/module-runner";
export function fetchClientFetchModule(
environmentName: string,
): ModuleRunnerTransport["invoke"] {
return async (...args) => {
const payload = JSON.stringify([environmentName, ...args]);
return async (payload) => {
const data = JSON.stringify([environmentName, payload]);
const response = await fetch(
"/@vite/invoke?" + new URLSearchParams({ payload }),
"/@vite/invoke?" + new URLSearchParams({ data }),
);
const result = response.json();
return result as any;
Expand Down
21 changes: 3 additions & 18 deletions examples/web-worker/src/lib/fetch-module-server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type HotChannel, type Plugin } from "vite";
import { type Plugin } from "vite";

export function vitePluginFetchModuleServer(): Plugin {
return {
Expand All @@ -7,9 +7,9 @@ export function vitePluginFetchModuleServer(): Plugin {
server.middlewares.use(async (req, res, next) => {
const url = new URL(req.url ?? "/", "https://any.local");
if (url.pathname === "/@vite/invoke") {
const [name, ...args] = JSON.parse(url.searchParams.get("payload")!);
const [name, payload] = JSON.parse(url.searchParams.get("data")!);
const devEnv = server.environments[name]!;
const result = await devEnv.hot.api.invoke(...args);
const result = await devEnv.hot.handleInvoke(payload);
res.end(JSON.stringify(result));
return;
}
Expand All @@ -18,18 +18,3 @@ export function vitePluginFetchModuleServer(): Plugin {
},
};
}

// expose `hot.api.invoke`
export function createTransportWithInvoke(): HotChannel {
let invokeHandler!: Function;
return {
setInvokeHandler(invokeHandler_) {
if (invokeHandler_) {
invokeHandler = invokeHandler_;
}
},
api: {
invoke: (...args: any[]) => invokeHandler(...args),
},
};
}

0 comments on commit c395631

Please sign in to comment.