|
8 | 8 |
|
9 | 9 | 'use strict'; |
10 | 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. |
| 14 | +process.on('unhandledRejection', err => { |
| 15 | + throw err; |
| 16 | +}); |
| 17 | + |
11 | 18 | const spawn = require('react-dev-utils/crossSpawn'); |
12 | 19 | const args = process.argv.slice(2); |
13 | 20 |
|
14 | 21 | const scriptIndex = args.findIndex( |
15 | 22 | x => x === 'build' || x === 'start' || x === 'wpbuild' || x === 'wpstart' |
16 | 23 | ); |
| 24 | +let script = scriptIndex === -1 ? args[0] : args[scriptIndex]; // wptheme -- change to "let" to allow modification... |
17 | 25 | const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; |
18 | 26 |
|
19 | | -let script = scriptIndex === -1 ? args[0] : args[scriptIndex]; |
20 | 27 | if (!script.startsWith('wp')) { |
21 | 28 | script = `wp${script}`; |
22 | 29 | } |
23 | 30 |
|
24 | | -switch (script) { |
25 | | - case 'wpbuild': |
26 | | - case 'wpstart': { |
27 | | - const result = spawn.sync( |
28 | | - 'node', |
29 | | - nodeArgs |
30 | | - .concat(require.resolve('../scripts/' + script)) |
31 | | - .concat(args.slice(scriptIndex + 1)), |
32 | | - { stdio: 'inherit' } |
33 | | - ); |
34 | | - if (result.signal) { |
35 | | - if (result.signal === 'SIGKILL') { |
36 | | - console.log('The build failed because the process exited too early.'); |
37 | | - console.log( |
38 | | - 'This probably means the system ran out of memory or someone called `kill -9` on the process.' |
39 | | - ); |
40 | | - } else if (result.signal === 'SIGTERM') { |
41 | | - console.log('The build failed because the process exited too early.'); |
42 | | - console.log( |
43 | | - 'Someone might have called `kill` or `killall`, or the system could be shutting down.' |
44 | | - ); |
45 | | - } |
46 | | - |
47 | | - process.exit(1); |
| 31 | +if (['wpbuild', 'wpstart'].includes(script)) { |
| 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 | + ); |
48 | 52 | } |
49 | | - |
50 | | - process.exit(result.status); |
51 | | - break; |
| 53 | + process.exit(1); |
52 | 54 | } |
53 | | - default: |
54 | | - console.log('Unknown script "' + script + '".'); |
55 | | - console.log( |
56 | | - "The original create-react-scripts commands are still available but must be prefixed with 'cra' (e.g. crastart, craeject, etc.)." |
57 | | - ); |
58 | | - break; |
| 55 | + process.exit(result.status); |
| 56 | +} else { |
| 57 | + console.log('Unknown script "' + script + '".'); |
| 58 | + // console.log('Perhaps you need to update react-scripts?'); |
| 59 | + console.log( |
| 60 | + "The original create-react-scripts commands are still available but must be prefixed with 'cra' (e.g. crastart, craeject, etc.)." |
| 61 | + ); |
59 | 62 | } |
0 commit comments