Skip to content

Commit b882601

Browse files
committed
3.2.0 react-scripts/wptheme-scripts bin changes
1 parent 6ab18dc commit b882601

File tree

2 files changed

+66
-70
lines changed

2 files changed

+66
-70
lines changed

packages/react-scripts/bin/react-scripts.js

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,35 @@ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
2626

2727
script = script.replace(/cra/, ''); // wptheme -- added
2828

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

packages/react-scripts/bin/wptheme-scripts.js

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,55 @@
88

99
'use strict';
1010

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+
1118
const spawn = require('react-dev-utils/crossSpawn');
1219
const args = process.argv.slice(2);
1320

1421
const scriptIndex = args.findIndex(
1522
x => x === 'build' || x === 'start' || x === 'wpbuild' || x === 'wpstart'
1623
);
24+
let script = scriptIndex === -1 ? args[0] : args[scriptIndex]; // wptheme -- change to "let" to allow modification...
1725
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
1826

19-
let script = scriptIndex === -1 ? args[0] : args[scriptIndex];
2027
if (!script.startsWith('wp')) {
2128
script = `wp${script}`;
2229
}
2330

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+
);
4852
}
49-
50-
process.exit(result.status);
51-
break;
53+
process.exit(1);
5254
}
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+
);
5962
}

0 commit comments

Comments
 (0)