FredrikNoren / ungit

The easiest way to use git. On any platform. Anywhere.
MIT License
10.44k stars 639 forks source link

Use fork to spawn a new node process #1537

Closed Hirse closed 1 year ago

Hirse commented 1 year ago

Changes child_process.spawn to child_process.fork to create new node process to run server.js.

Currently bin/ungit creates a new child process using spawn with the first argument of process, which is expected to be "node" or in some OS (apparently) "nodejs". When running this script from other programs, for example as part of a VSCode extension, this expectation does not hold and the first argument is actually "Code.exe". Trying to spawn the ungit server there fails for obvious reasons.

Since the goal is to create a new node process (with the same one that is already running), we can shorthand it by using fork:

The child_process.fork() method is a special case of child_process.spawn() used specifically to spawn new Node.js processes.

Adding the silent option is necessary to keep the event handlers the same.

campersau commented 1 year ago

Did a successful run after rebasing this on top of #1540.