UNPKG

1.89 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
27if (['build', 'eject', 'start', 'test'].includes(script)) {
28 const result = spawn.sync(
29 'node',
30 nodeArgs
31 .concat(require.resolve('../scripts/' + script))
32 .concat(args.slice(scriptIndex + 1)),
33 { stdio: 'inherit' }
34 );
35 if (result.signal) {
36 if (result.signal === 'SIGKILL') {
37 console.log(
38 'The build failed because the process exited too early. ' +
39 'This probably means the system ran out of memory or someone called ' +
40 '`kill -9` on the process.'
41 );
42 } else if (result.signal === 'SIGTERM') {
43 console.log(
44 'The build failed because the process exited too early. ' +
45 'Someone might have called `kill` or `killall`, or the system could ' +
46 'be shutting down.'
47 );
48 }
49 process.exit(1);
50 }
51 process.exit(result.status);
52} else {
53 console.log('Unknown script "' + script + '".');
54 console.log('Perhaps you need to update react-scripts?');
55 console.log(
56 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases'
57 );
58}