From 66e05f42e4697abb882d6846fd3ce3664becb337 Mon Sep 17 00:00:00 2001 From: William Monk Date: Mon, 22 May 2017 13:31:27 +0100 Subject: [PATCH] Fix @type Installing --- packages/react-scripts/scripts/init.js | 42 ++++++++++++++++---------- tasks/e2e-simple.sh | 14 ++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index afc083ff..e271d2ea 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -107,14 +107,6 @@ module.exports = function( command = 'npm'; args = ['install', '--save', verbose && '--verbose'].filter(e => e); } - args.push( - 'react', - 'react-dom', - '@types/node', - '@types/react', - '@types/react-dom', - '@types/jest' - ); // Install additional template dependencies, if present const templateDependenciesPath = path.join( @@ -131,19 +123,37 @@ module.exports = function( fs.unlinkSync(templateDependenciesPath); } + const types = [ + '@types/node', + '@types/react', + '@types/react-dom', + '@types/jest', + ]; + + console.log(`Installing ${types.join(', ')} ${command}...`); + console.log(); + + const proc = spawn.sync(command, args.concat(types), { stdio: 'inherit' }); + if (proc.status !== 0) { + console.error(`\`${command} ${args.concat(types).join(' ')}\` failed`); + return; + } + // Install react and react-dom for backward compatibility with old CRA cli // which doesn't install react and react-dom along with react-scripts // or template is presetend (via --internal-testing-template) - // if (!isReactInstalled(appPackage) || template) { - console.log(`Installing react and react-dom using ${command}...`); - console.log(); + if (!isReactInstalled(appPackage) || template) { + console.log(`Installing react and react-dom using ${command}...`); + console.log(); - const proc = spawn.sync(command, args, { stdio: 'inherit' }); - if (proc.status !== 0) { - console.error(`\`${command} ${args.join(' ')}\` failed`); - return; + const proc = spawn.sync(command, args.concat(['react', 'react-dom']), { + stdio: 'inherit', + }); + if (proc.status !== 0) { + console.error(`\`${command} ${args.join(' ')}\` failed`); + return; + } } - // } // Display the most elegant way to cd. // This needs to handle an undefined originalDirectory for diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index d7b04cf8..22970578 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -233,18 +233,18 @@ function verify_module_scope { echo "{}" >> sample.json # Save App.js, we're going to modify it - cp src/App.js src/App.js.bak + cp src/App.tsx src/App.tsx.bak # Add an out of scope import - echo "import sampleJson from '../sample'" | cat - src/App.js > src/App.js.temp && mv src/App.js.temp src/App.js + echo "import sampleJson from '../sample.json'" | cat - src/App.tsx > src/App.tsx.temp && mv src/App.tsx.temp src/App.tsx # Make sure the build fails npm run build; test $? -eq 1 || exit 1 # TODO: check for error message - # Restore App.js - rm src/App.js - mv src/App.js.bak src/App.js + # Restore App.tsx + rm src/App.tsx + mv src/App.tsx.bak src/App.tsx } # Enter the app directory @@ -263,7 +263,7 @@ exists build/favicon.ico # Run tests with CI flag CI=true npm test # Uncomment when snapshot testing is enabled by default: -# exists src/__snapshots__/App.test.js.snap +# exists src/__snapshots__/App.test.tsx.snap # Test the server npm start -- --smoke-test @@ -285,7 +285,7 @@ echo yes | npm run eject npm link "$root_path"/packages/babel-preset-react-app npm link "$root_path"/packages/eslint-config-react-app npm link "$root_path"/packages/react-dev-utils -npm link "$root_path"/packages/react-scripts +npm link "$root_path"/packages/react-scripts-ts # Test the build npm run build