Remove explicit process.exit(0)
from cli.ts (take 2)
#8135
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I accidentally deleted my fork, so I'm re-opening #7552. This is a copy/paste of that PR's body.
Calling
process.exit(0)
in the successful case is redundant, but also causes problems when wanting to use the CLI commands in any kind of automated capacity, if the output is larger than 8192 bytes. This is because the Promise resolves before the stdout buffers have been flushed, and whenprocess.exit(0)
is called, the entire process terminates leaving buffered output unsent to the calling process.This is usually not a problem when running the CLI directly, but can be problematic when invoked via a child process. For instance, @brophdawg11 supplied this sample code in Discord:
However, attempting to run this on a project with a large number of routes, resulting in a JSON object larger than 8192 bytes, results in a deserialization error:
The default case for a node script that exits gracefully is an exit code of
0
. So, removing the explicitprocess.exit(0)
leaves the process running until all I/O is completed and STDOUT buffers are flushed.Testing Strategy:
I tested this using the following patch on an installed version of
@remix-run/dev
, which resulted in letting the above JS code run successfully and parse the full JSON output (which is larger than 8192 bytes):