react-scripts.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env node
  2. /**
  3. * Copyright (c) 2015-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. 'use strict';
  9. // Makes the script crash on unhandled rejections instead of silently
  10. // ignoring them. In the future, promise rejections that are not handled will
  11. // terminate the Node.js process with a non-zero exit code.
  12. process.on('unhandledRejection', err => {
  13. throw err;
  14. });
  15. const spawn = require('react-dev-utils/crossSpawn');
  16. const args = process.argv.slice(2);
  17. const scriptIndex = args.findIndex(
  18. x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
  19. );
  20. const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
  21. const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
  22. if (['build', 'eject', 'start', 'test'].includes(script)) {
  23. const result = spawn.sync(
  24. process.execPath,
  25. nodeArgs
  26. .concat(require.resolve('../scripts/' + script))
  27. .concat(args.slice(scriptIndex + 1)),
  28. { stdio: 'inherit' }
  29. );
  30. if (result.signal) {
  31. if (result.signal === 'SIGKILL') {
  32. console.log(
  33. 'The build failed because the process exited too early. ' +
  34. 'This probably means the system ran out of memory or someone called ' +
  35. '`kill -9` on the process.'
  36. );
  37. } else if (result.signal === 'SIGTERM') {
  38. console.log(
  39. 'The build failed because the process exited too early. ' +
  40. 'Someone might have called `kill` or `killall`, or the system could ' +
  41. 'be shutting down.'
  42. );
  43. }
  44. process.exit(1);
  45. }
  46. process.exit(result.status);
  47. } else {
  48. console.log('Unknown script "' + script + '".');
  49. console.log('Perhaps you need to update react-scripts?');
  50. console.log(
  51. 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases'
  52. );
  53. }