From 72750e60580c30323114bc1ac0b99547b9c0a924 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Tue, 7 Feb 2017 17:26:48 +0200 Subject: [PATCH 1/7] Make build exit with error code when interrupted This addresses issue #1493. Current behavior is that `npm run build` exits code 0 without creating a bundle when interrupted. This change makes the build script catch catchable interruptions and exit with the appropriate error code. --- packages/react-scripts/scripts/build.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 42be50d43a8..d2fb10e6aeb 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -233,3 +233,15 @@ function copyPublicFolder() { filter: file => file !== paths.appHtml }); } + +var signals = { + 'SIGINT': 2, + 'SIGTERM': 15 +}; + +Object.keys(signals).forEach(function (signalName) { + process.on(signalName, function () { + console.log('Build stopped by ' + signalName); + process.exit(signals[signalName]); + }); +}); From af8559c0a8f1950d1c333438bad5ea3628eabd75 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Wed, 8 Feb 2017 00:08:07 +0200 Subject: [PATCH 2/7] Better error messages for kill signals --- packages/react-scripts/scripts/build.js | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index d2fb10e6aeb..951e6ae6653 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -234,14 +234,24 @@ function copyPublicFolder() { }); } -var signals = { - 'SIGINT': 2, - 'SIGTERM': 15 -}; - -Object.keys(signals).forEach(function (signalName) { - process.on(signalName, function () { - console.log('Build stopped by ' + signalName); - process.exit(signals[signalName]); +var signals = [ + { + name: 'SIGINT', + code: 2, + message: 'This usually means someone pressed Ctrl+C.' + }, + { + name: 'SIGTERM', + code: 15, + message: 'This could mean someone that killed the process (e.g. with ' + + '`kill -15` or `killall`), that the system is shutting down, or that ' + + 'it ran out of memory.' + } +]; + +signals.forEach(function (signal) { + process.on(signal.name, function () { + console.log('ERROR: Build stopped by ' + signal.name + '. ' + signal.message); + process.exit(signal.code); }); }); From 6520b8cb0eb86f2a5a62ad6ea1b9920eb98a2f80 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Thu, 9 Feb 2017 13:39:50 +0200 Subject: [PATCH 3/7] Don't catch SIGINT Ctrl+C should exit silently, and already produces a non-zero exit code when sent to the console while `npm run build` is running. Exit code 0 is produced if SIGINT is sent directly to the `node build.js` process, but this is unlikely to happen. A SIGINT handler in `build.js` will also be triggered by Ctrl+C in the console, potentially producing unnecessary noise. --- packages/react-scripts/scripts/build.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 951e6ae6653..738c4806337 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -234,24 +234,9 @@ function copyPublicFolder() { }); } -var signals = [ - { - name: 'SIGINT', - code: 2, - message: 'This usually means someone pressed Ctrl+C.' - }, - { - name: 'SIGTERM', - code: 15, - message: 'This could mean someone that killed the process (e.g. with ' + - '`kill -15` or `killall`), that the system is shutting down, or that ' + - 'it ran out of memory.' - } -]; - -signals.forEach(function (signal) { - process.on(signal.name, function () { - console.log('ERROR: Build stopped by ' + signal.name + '. ' + signal.message); - process.exit(signal.code); - }); +process.on('SIGTERM', function () { + console.log('Build stopped by SIGTERM. This could mean someone that ' + + 'killed the process (e.g. with `kill -15` or `killall`), that the ' + + 'system is shutting down, or that it ran out of memory.'); + process.exit(15); }); From 29440b756ea7106a5afe819b711b844e40425365 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Thu, 9 Feb 2017 20:28:35 +0200 Subject: [PATCH 4/7] Style fix --- packages/react-scripts/scripts/build.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 738c4806337..1d0b907cd0d 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -235,8 +235,10 @@ function copyPublicFolder() { } process.on('SIGTERM', function () { - console.log('Build stopped by SIGTERM. This could mean someone that ' + - 'killed the process (e.g. with `kill -15` or `killall`), that the ' + - 'system is shutting down, or that it ran out of memory.'); + console.log( + 'Build stopped by SIGTERM. This could mean that someone killed the ' + + 'process (e.g. with `kill -15` or `killall`), that the system is ' + + 'shutting down, or that it ran out of memory.' + ); process.exit(15); }); From db146ab2dd8e5b9bbe524fab48365b7051f7b26f Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Fri, 10 Feb 2017 18:22:31 +0200 Subject: [PATCH 5/7] No changes needed to build.js Problem is coming from the parent process, `react-scripts` --- packages/react-scripts/scripts/build.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 1d0b907cd0d..42be50d43a8 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -233,12 +233,3 @@ function copyPublicFolder() { filter: file => file !== paths.appHtml }); } - -process.on('SIGTERM', function () { - console.log( - 'Build stopped by SIGTERM. This could mean that someone killed the ' + - 'process (e.g. with `kill -15` or `killall`), that the system is ' + - 'shutting down, or that it ran out of memory.' - ); - process.exit(15); -}); From e7492584a89a9bdce61c783a2de0037eb56d39a2 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Fri, 10 Feb 2017 19:28:06 +0300 Subject: [PATCH 6/7] Make react-scripts script handle signals --- packages/react-scripts/bin/react-scripts.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js index 58381833957..ab1468d0351 100755 --- a/packages/react-scripts/bin/react-scripts.js +++ b/packages/react-scripts/bin/react-scripts.js @@ -13,6 +13,20 @@ case 'test': [require.resolve('../scripts/' + script)].concat(args), {stdio: 'inherit'} ); + if (result.signal) { + if (result.signal == 'SIGKILL') { + console.log( + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.' + ); + } else if (result.signal == 'SIGTERM') { + console.log( + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.' + ); + } + process.exit(1); + } process.exit(result.status); break; default: From 475038677cb9f1df07d79c3b0efd726693c69495 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Fri, 10 Feb 2017 16:50:17 -0500 Subject: [PATCH 7/7] Clarify context --- packages/react-scripts/bin/react-scripts.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js index ab1468d0351..a3ae830f45b 100755 --- a/packages/react-scripts/bin/react-scripts.js +++ b/packages/react-scripts/bin/react-scripts.js @@ -16,11 +16,13 @@ case 'test': if (result.signal) { if (result.signal == 'SIGKILL') { console.log( + 'The build failed because the process exited too early. ' + 'This probably means the system ran out of memory or someone called ' + '`kill -9` on the process.' ); } else if (result.signal == 'SIGTERM') { console.log( + 'The build failed because the process exited too early. ' + 'Someone might have called `kill` or `killall`, or the system could ' + 'be shutting down.' );