UNPKG

1.99 kBJavaScriptView Raw
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
9'use strict';
10
11// Makes the script crash on unhandled rejections instead of silently
12// ignoring them. In the future, promise rejections that are not handled will
13// terminate the Node.js process with a non-zero exit code.
14process.on('unhandledRejection', err => {
15 throw err;
16});
17
18const spawn = require('react-dev-utils/crossSpawn');
19const args = process.argv.slice(2);
20
21const scriptIndex = args.findIndex(
22 x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
23);
24const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
25const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
26
27switch (script) {
28 case 'build':
29 case 'eject':
30 case 'start':
31 case 'test': {
32 const result = spawn.sync(
33 'node',
34 nodeArgs
35 .concat(require.resolve('../scripts/' + script))
36 .concat(args.slice(scriptIndex + 1)),
37 { stdio: 'inherit' }
38 );
39 if (result.signal) {
40 if (result.signal === 'SIGKILL') {
41 console.log(
42 'The build failed because the process exited too early. ' +
43 'This probably means the system ran out of memory or someone called ' +
44 '`kill -9` on the process.'
45 );
46 } else if (result.signal === 'SIGTERM') {
47 console.log(
48 'The build failed because the process exited too early. ' +
49 'Someone might have called `kill` or `killall`, or the system could ' +
50 'be shutting down.'
51 );
52 }
53 process.exit(1);
54 }
55 process.exit(result.status);
56 break;
57 }
58 default:
59 console.log('Unknown script "' + script + '".');
60 console.log('Perhaps you need to update react-scripts?');
61 console.log(
62 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases'
63 );
64 break;
65}