From 542eaf9de26edc2a1a5a796ce007f66f312dcc9e Mon Sep 17 00:00:00 2001 From: Ben Schmeckpeper Date: Thu, 6 Feb 2020 12:04:34 -0600 Subject: [PATCH] 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. --- bin/webpack.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/webpack.js b/bin/webpack.js index f08edf477..e97b624f2 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -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();