From 4ee352b4de4419943f4327bcc39aafcc809e38b5 Mon Sep 17 00:00:00 2001 From: William Monk Date: Tue, 21 Mar 2017 21:28:14 +0000 Subject: [PATCH] Install @types deps on init fixes #30 --- packages/react-scripts/scripts/init.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index db6c3f8c..82b2845f 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -79,8 +79,15 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template '--save', verbose && '--verbose' ].filter(function(e) { return e; }); + } + + var reactDeps = ['react', 'react-dom']; + if (!isReactInstalled(appPackage)) { + args = args.concat(reactDeps); } - args.push('react', 'react-dom', '@types/node', '@types/react', '@types/react-dom', '@types/jest'); + + var dependencies = [ '@types/node', '@types/react', '@types/react-dom', '@types/jest']; + args = args.concat(dependencies); // Install additional template dependencies, if present var templateDependenciesPath = path.join(appPath, '.template.dependencies.json'); @@ -95,15 +102,14 @@ module.exports = function(appPath, appName, verbose, originalDirectory, template // 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(); + console.log('Installing dependencies using ' + command + '...'); + console.log(chalk.cyan(args.join(', '))); + console.log(); - var proc = spawn.sync(command, args, {stdio: 'inherit'}); - if (proc.status !== 0) { - console.error('`' + command + ' ' + args.join(' ') + '` failed'); - return; - } + var proc = spawn.sync(command, args, {stdio: 'inherit'}); + if (proc.status !== 0) { + console.error('`' + command + ' ' + args.join(' ') + '` failed'); + return; } // Display the most elegant way to cd.