Description
Hi, I've noticed yet another problem with a spawn
of child process.
For now ts-node has the following option while creating a child node: stdio: 'inherit'
.
And according node.js docs it means "no IPC" (Inter-process communication)
In reality this breaks a communication with yet another parent:
parent.js:
const cp = require('child_process');
cp.fork('child.ts', [], {
env: process.env,
execPath: 'node_modules/.bin/ts-node'
});
child.ts:
if (!process.send)
console.log('IPC is not enabled');
else
console.log('IPC is enabled')
will produce IPC is not enabled
See more details in the sample repository with proper environment.
So I propose to replace the stdio
option value with ['inherit', 'inherit', 'inherit', 'ipc']
in order to enable IPC. I think it's quite safe change because according the stdio doc
the child is launched with the IPC channel unreferenced until the child registers an event handler for the process
After such modification the sample will produce IPC is enabled
If someone is wondering about real-life use case sample:
- npm start
- webpack build client source
- run server api + webpack dev server
- wait until the server will start
- open browser
In this chain wait until the server will start is usually implemented in IPC way like process.send('online')
and ts-node breaks this for now
PR #502