From 7f289859d209f1c50831a86a3b33512e0203db08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lins?= Date: Tue, 24 Sep 2019 21:52:39 -0300 Subject: [PATCH 1/2] Remove switch case --- packages/react-scripts/bin/react-scripts.js | 66 ++++++++++----------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js index 84cc59b7253..2c3bfb9d05c 100755 --- a/packages/react-scripts/bin/react-scripts.js +++ b/packages/react-scripts/bin/react-scripts.js @@ -18,48 +18,42 @@ process.on('unhandledRejection', err => { const spawn = require('react-dev-utils/crossSpawn'); const args = process.argv.slice(2); +const scripts = ['build', 'eject', 'start', 'test']; const scriptIndex = args.findIndex( x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' ); const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; -switch (script) { - case 'build': - case 'eject': - case 'start': - case 'test': { - const result = spawn.sync( - 'node', - nodeArgs - .concat(require.resolve('../scripts/' + script)) - .concat(args.slice(scriptIndex + 1)), - { stdio: 'inherit' } - ); - if (result.signal) { - if (result.signal === 'SIGKILL') { - console.log( - 'The build failed because the process exited too early. ' + - 'This probably means the system ran out of memory or someone called ' + - '`kill -9` on the process.' - ); - } else if (result.signal === 'SIGTERM') { - console.log( - 'The build failed because the process exited too early. ' + - 'Someone might have called `kill` or `killall`, or the system could ' + - 'be shutting down.' - ); - } - process.exit(1); +if (scripts.includes(script)) { + const result = spawn.sync( + 'node', + nodeArgs + .concat(require.resolve('../scripts/' + script)) + .concat(args.slice(scriptIndex + 1)), + { stdio: 'inherit' } + ); + if (result.signal) { + if (result.signal === 'SIGKILL') { + console.log( + 'The build failed because the process exited too early. ' + + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.' + ); + } else if (result.signal === 'SIGTERM') { + console.log( + 'The build failed because the process exited too early. ' + + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.' + ); } - process.exit(result.status); - break; + process.exit(1); } - default: - console.log('Unknown script "' + script + '".'); - console.log('Perhaps you need to update react-scripts?'); - console.log( - 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases' - ); - break; + process.exit(result.status); +} else { + console.log('Unknown script "' + script + '".'); + console.log('Perhaps you need to update react-scripts?'); + console.log( + 'See: https://facebook.github.io/create-react-app/docs/updating-to-new-releases' + ); } From cc6ce04c901304f28b79edc57e019a235480d333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lins?= Date: Mon, 30 Sep 2019 15:45:36 -0300 Subject: [PATCH 2/2] Removing script variable --- packages/react-scripts/bin/react-scripts.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js index 2c3bfb9d05c..7e6e290251a 100755 --- a/packages/react-scripts/bin/react-scripts.js +++ b/packages/react-scripts/bin/react-scripts.js @@ -18,14 +18,13 @@ process.on('unhandledRejection', err => { const spawn = require('react-dev-utils/crossSpawn'); const args = process.argv.slice(2); -const scripts = ['build', 'eject', 'start', 'test']; const scriptIndex = args.findIndex( x => x === 'build' || x === 'eject' || x === 'start' || x === 'test' ); const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; -if (scripts.includes(script)) { +if (['build', 'eject', 'start', 'test'].includes(script)) { const result = spawn.sync( 'node', nodeArgs