Skip to content

Commit 5860e72

Browse files
authoredOct 9, 2024
fix: reading data from spawned process (#5877)
1 parent c482ddb commit 5860e72

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed
 

‎packages/build/src/plugins/ipc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const getEventFromChild = async function (childProcess, callId) {
3939
throw getChildExitError('Could not receive event from child process because it already exited.')
4040
}
4141

42-
const messagePromise = pEvent(childProcess, 'message', { filter: ([actualCallId]) => actualCallId === callId })
43-
const errorPromise = pEvent(childProcess, 'message', { filter: ([actualCallId]) => actualCallId === 'error' })
42+
const messagePromise = pEvent(childProcess, 'message', { filter: (data) => data?.[0] === callId })
43+
const errorPromise = pEvent(childProcess, 'message', { filter: (data) => data?.[0] === 'error' })
4444
const exitPromise = pEvent(childProcess, 'exit', { multiArgs: true })
4545
try {
4646
return await Promise.race([getMessage(messagePromise), getError(errorPromise), getExit(exitPromise)])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: test
2+
inputs: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[[plugins]]
2+
package = "./plugin.js"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import process from 'process';
2+
3+
export const onPreBuild = function () {
4+
process.send({});
5+
}

‎packages/build/tests/plugins/tests.js

+5
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,8 @@ test('Plugins have a pre-populated Blobs context', async (t) => {
401401

402402
t.is(netlifyConfig.build.command, `echo ""Hello there""`)
403403
})
404+
405+
test('Plugins can respond anything to parent process', async (t) => {
406+
const build = await new Fixture('./fixtures/process_send_object').runBuildBinary()
407+
t.true(build.exitCode === 0)
408+
})

0 commit comments

Comments
 (0)