From fa6045e352df956a95ae56e683bcc4ddf2c00c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E2=9D=A4=EF=B8=8F=20=E2=98=AE=EF=B8=8F=20=E2=9C=8B?= <6723574+louisgv@users.noreply.github.com> Date: Mon, 4 Sep 2023 22:12:14 -0400 Subject: [PATCH] hotfix: bind hmrHost with the builder socket --- cli/create-plasmo/package.json | 2 +- cli/plasmo/package.json | 2 +- cli/plasmo/src/commands/dev.ts | 6 ++++-- packages/framework-shared/build-socket/index.ts | 11 +++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cli/create-plasmo/package.json b/cli/create-plasmo/package.json index 992941a0a..2de874431 100644 --- a/cli/create-plasmo/package.json +++ b/cli/create-plasmo/package.json @@ -1,6 +1,6 @@ { "name": "create-plasmo", - "version": "0.82.3", + "version": "0.82.4", "description": "Create Plasmo Framework Browser Extension", "main": "dist/index.js", "bin": "bin/index.mjs", diff --git a/cli/plasmo/package.json b/cli/plasmo/package.json index 75bd8466a..73041a974 100644 --- a/cli/plasmo/package.json +++ b/cli/plasmo/package.json @@ -1,6 +1,6 @@ { "name": "plasmo", - "version": "0.82.3", + "version": "0.82.4", "description": "The Plasmo Framework CLI", "publishConfig": { "types": "dist/type.d.ts" diff --git a/cli/plasmo/src/commands/dev.ts b/cli/plasmo/src/commands/dev.ts index 9f9d42f17..9ed147963 100644 --- a/cli/plasmo/src/commands/dev.ts +++ b/cli/plasmo/src/commands/dev.ts @@ -31,9 +31,11 @@ async function dev() { getPort({ port: parseInt(rawServePort) }), getPort({ port: parseInt(rawHmrPort) }) ]) - const buildWatcher = getBuildSocket(hmrPort) - vLog(`Starting dev server on ${serveHost}:${servePort}, HMR on ${hmrHost}:${hmrPort}...`) + const buildWatcher = getBuildSocket(hmrHost, hmrPort) + vLog( + `Starting dev server on ${serveHost}:${servePort}, HMR on ${hmrHost}:${hmrPort}...` + ) const bundleConfig = getBundleConfig() diff --git a/packages/framework-shared/build-socket/index.ts b/packages/framework-shared/build-socket/index.ts index a40168fae..4d84d959a 100644 --- a/packages/framework-shared/build-socket/index.ts +++ b/packages/framework-shared/build-socket/index.ts @@ -4,8 +4,11 @@ import { BuildSocketEvent } from "./event" export { BuildSocketEvent } -const createBuildSocket = (hmrPort: number) => { - const wss = new WebSocketServer({ port: hmrPort + 1 }) +const createBuildSocket = (hmrHost: string, hmrPort: number) => { + const wss = new WebSocketServer({ + host: hmrHost, + port: hmrPort + 1 + }) const broadcast = (type: BuildSocketEvent) => { for (const client of wss.clients) { @@ -22,7 +25,7 @@ const createBuildSocket = (hmrPort: number) => { let _buildSocket: Awaited> -export const getBuildSocket = (hmrPort?: number) => { +export const getBuildSocket = (hmrHost = "localhost", hmrPort?: number) => { if (process.env.NODE_ENV === "production") { return null } @@ -35,7 +38,7 @@ export const getBuildSocket = (hmrPort?: number) => { throw new Error("HMR port is not provided") } - _buildSocket = createBuildSocket(hmrPort) + _buildSocket = createBuildSocket(hmrHost, hmrPort) return _buildSocket }