• Brandon Istenes's avatar
    Make build exit with error code when interrupted (#1496) · e19b0f63
    Brandon Istenes authored
    * 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.
    
    * Better error messages for kill signals
    
    * 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.
    
    * Style fix
    
    * No changes needed to build.js
    
    Problem is coming from the parent process, `react-scripts`
    
    * Make react-scripts script handle signals
    
    * Clarify context
    e19b0f63
react-scripts.js 1.02 KiB
#!/usr/bin/env node
var spawn = require('cross-spawn');
var script = process.argv[2];
var args = process.argv.slice(3);
switch (script) {
case 'build':
case 'eject':
case 'start':
case 'test':
  var result = spawn.sync(
    'node',
    [require.resolve('../scripts/' + script)].concat(args),
    {stdio: 'inherit'}
  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.'
    process.exit(1);
  process.exit(result.status);
  break;
default:
  console.log('Unknown script "' + script + '".');
  console.log('Perhaps you need to update react-scripts?');
  break;