Exit with an error if we can't prompt for webpack-cli installation.

If STDIN is not in terminal mode when the webpack script is executed, the
readline module will never execute the callback passed to question and the
script will exit successfully, without ever building the pack.  An example of
this is Rails' webpacker gem, which executes the webpack script in a subshell.

If STDIN is not in terminal mode, we should exit with an error immediately,
instead of attempting to ask a question to which we'll never receive an answer.
This commit is contained in:
Ben Schmeckpeper 2020-02-06 12:04:34 -06:00
parent f40d05fdea
commit 542eaf9de2
1 changed files with 10 additions and 0 deletions

View File

@ -86,6 +86,16 @@ if (!cli.installed) {
input: process.stdin,
output: process.stderr
});
// If we're not in terminal mode, readline won't execute the callback function below. Return here
// so that we can set the exit code properly.
if (!questionInterface.terminal) {
console.error(
"You need to install 'webpack-cli' to use webpack via CLI.\n" +
"You can also install the CLI manually."
);
process.exit(1);
}
questionInterface.question(question, answer => {
questionInterface.close();