CLI should not invoke process.exit()
Currently, the CLI invokes process.exit()
when the site generator completes. Not only is this unnecessary, it's also not recommended. Here's what the Node.js documentation has to say on the matter:
In most situations, it is not actually necessary to call process.exit() explicitly. The Node.js process will exit on its own if there is no additional work pending in the event loop. The process.exitCode property can be set to tell the process which exit code to use when the process exits gracefully.
Calling process.exit() forces the process to exit before pending writes to asynchronous streams can be performed.
If it is necessary to terminate the Node.js process due to an error condition, throwing an uncaught error and allowing the process to terminate accordingly is safer than calling process.exit().
Here's the main reason why calling process.exit()
directly is problematic for Antora specifically:
The 'beforeExit' event is not emitted for conditions causing explicit termination, such as calling process.exit() or uncaught exceptions.
By calling process.exit()
, Antora is preventing beforeExit
event listeners from being called. This could be useful both for Antora and extensions. For example, we may decide to use the beforeExit
event listener to finalize the logger gracefully if it hasn't already been finalized (See #792).
The CLI should set the the process.exitCode
then allow the Node.js process to exit normally.