Skip to content

Commit

Permalink
hotfix: bind hmrHost with the builder socket
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgv committed Sep 5, 2023
1 parent d975d46 commit fa6045e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/create-plasmo/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cli/plasmo/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions cli/plasmo/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
11 changes: 7 additions & 4 deletions packages/framework-shared/build-socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -22,7 +25,7 @@ const createBuildSocket = (hmrPort: number) => {

let _buildSocket: Awaited<ReturnType<typeof createBuildSocket>>

export const getBuildSocket = (hmrPort?: number) => {
export const getBuildSocket = (hmrHost = "localhost", hmrPort?: number) => {
if (process.env.NODE_ENV === "production") {
return null
}
Expand All @@ -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
}

Expand Down

0 comments on commit fa6045e

Please sign in to comment.