Skip to content

Commit

Permalink
fix: compile message not relayed by wrapper (wclr#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinWongM committed May 6, 2023
1 parent 32bdc92 commit 7d7bc44
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChildProcess } from 'child_process'
import type { CompileParams } from './compiler'

export type IPCMessage = {
cmd?: string
Expand All @@ -12,10 +13,17 @@ export type IPCMessage = {
/**
* Checks if the given message is an internal node-dev message.
*/
function isNodeDevMessage(m: IPCMessage) {
function isNodeDevMessage(m: any): m is IPCMessage {
return m.cmd === 'NODE_DEV'
}

/**
* Check if the given message is an compile request message.
*/
function isCompileRequestMessage(m: any): m is CompileParams {
return typeof m.compile === 'string' && typeof m.compiledPath === 'string'
}

/**
* Sends a message to the given process.
*/
Expand All @@ -29,7 +37,7 @@ export const on = function (
type: string,
cb: (m: IPCMessage) => void
) {
function handleMessage(m: IPCMessage) {
function handleMessage(m: any) {
if (isNodeDevMessage(m) && type in m) cb(m)
}
proc.on('internalMessage', handleMessage)
Expand All @@ -40,8 +48,8 @@ export const relay = function (
src: ChildProcess,
dest: NodeJS.Process = process
) {
function relayMessage(m: IPCMessage) {
if (isNodeDevMessage(m)) dest.send!(m)
function relayMessage(m: any) {
if (isNodeDevMessage(m) || isCompileRequestMessage(m)) dest.send!(m)
}
src.on('internalMessage', relayMessage)
src.on('message', relayMessage)
Expand Down

0 comments on commit 7d7bc44

Please sign in to comment.