diff --git a/src/run/runners/cli/start.js b/src/run/runners/cli/start.js index 0850547a8..9b20b9459 100644 --- a/src/run/runners/cli/start.js +++ b/src/run/runners/cli/start.js @@ -1,8 +1,9 @@ import { exit } from 'process' +import { getInput, sendOutput, sendError } from '../common/ipc.js' + import { benchmark } from './benchmark/main.js' import { loadBenchmarkFile } from './load/main.js' -import { getInput, sendOutput, sendError } from './ipc.js' import { measure } from './benchmark/measure.js' // Child process entry point diff --git a/src/run/runners/cli/ipc.js b/src/run/runners/common/ipc.js similarity index 100% rename from src/run/runners/cli/ipc.js rename to src/run/runners/common/ipc.js diff --git a/src/run/runners/node/ipc.js b/src/run/runners/node/ipc.js deleted file mode 100644 index 489e3c44d..000000000 --- a/src/run/runners/node/ipc.js +++ /dev/null @@ -1,31 +0,0 @@ -import { argv } from 'process' -import { write } from 'fs' -import { promisify } from 'util' - -const pWrite = promisify(write) - -// Get input from parent to child process -export const getInput = function() { - const [, , input] = argv - return JSON.parse(input) -} - -// Send output from child to parent process -export const sendOutput = async function(message) { - if (message === undefined) { - return - } - - const messageStr = JSON.stringify(message) - await pWrite(OUTPUT_FD, messageStr) -} - -// Send error messages from child to parent process -export const sendError = async function(error) { - const message = error instanceof Error ? error.stack : String(error) - await pWrite(ERROR_FD, `${message}\n`) -} - -// Communicate to parent using those file descriptors -const OUTPUT_FD = 4 -const ERROR_FD = 5 diff --git a/src/run/runners/node/start.js b/src/run/runners/node/start.js index 7dbdc6a02..f2cec99b5 100644 --- a/src/run/runners/node/start.js +++ b/src/run/runners/node/start.js @@ -1,8 +1,9 @@ import { exit } from 'process' +import { getInput, sendOutput, sendError } from '../common/ipc.js' + import { benchmark } from './benchmark/main.js' import { loadBenchmarkFile } from './load/main.js' -import { getInput, sendOutput, sendError } from './ipc.js' import { debugRun } from './debug.js' // Child process entry point