From d48bbbd5d81944dc1d8d94f8a2f088d6f25f933f Mon Sep 17 00:00:00 2001 From: Enoah Netzach Date: Sun, 12 Feb 2017 19:12:22 +0100 Subject: [PATCH] Handle @scoped forks in install & e2e tests --- packages/create-react-app/index.js | 31 +++++++++++++++++++++++------- tasks/e2e-installs.sh | 23 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 4dbb37f4969..542cea82908 100644 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -179,13 +179,12 @@ function run(root, appName, version, verbose, originalDirectory, template) { console.error(chalk.cyan(command + ' ' + args.join(' ')) + ' failed'); process.exit(1); } + var packagePath = getPackagePath(packageName); - checkNodeVersion(packageName); + checkNodeVersion(packagePath); var scriptsPath = path.resolve( - process.cwd(), - 'node_modules', - packageName, + packagePath, 'scripts', 'init.js' ); @@ -219,11 +218,29 @@ function getPackageName(installPackage) { return installPackage; } -function checkNodeVersion(packageName) { - var packageJsonPath = path.resolve( +function getPackagePath(packageName) { + let packagePath = path.resolve( process.cwd(), 'node_modules', - packageName, + packageName + ); + + if (!packageName.startsWith('@') && packageName.indexOf('react-scripts') > -1 && !fs.existsSync(packagePath)) { + // The package could be @scoped + packagePath = path.resolve( + process.cwd(), + 'node_modules', + '@' + packageName.replace(/-react-scripts.*/, ''), + 'react-scripts' + ); + } + + return packagePath +} + +function checkNodeVersion(packagePath) { + var packageJsonPath = path.resolve( + packagePath, 'package.json' ); var packageJson = require(packageJsonPath); diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index d117c24015b..dd27f12c083 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -119,6 +119,29 @@ cd test-app-fork # Check corresponding scripts version is installed. exists node_modules/react-scripts-fork +# ****************************************************************************** +# Test --scripts-version with a scoped fork of react-scripts +# ****************************************************************************** + +cd $temp_app_path +create_react_app --scripts-version=@enoah_netzach/react-scripts test-app-scoped-fork +cd test-app-scoped-fork + +# Check corresponding scripts version is installed. +exists node_modules/@enoah_netzach/react-scripts + +# ****************************************************************************** +# Test --scripts-version with a scoped fork tgz of react-scripts +# ****************************************************************************** + +cd $temp_app_path +curl "https://registry.npmjs.org/@enoah_netzach/react-scripts/-/react-scripts-0.9.0.tgz" -o enoah_netzach-react-scripts-0.9.0.tgz +create_react_app --scripts-version=$temp_app_path/enoah_netzach-react-scripts-0.9.0.tgz test-app-scoped-fork-tgz +cd test-app-scoped-fork + +# Check corresponding scripts version is installed. +exists node_modules/@enoah_netzach/react-scripts + # ****************************************************************************** # Test nested folder path as the project name # ******************************************************************************