Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle scoped forks in install & e2e tests #1537

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions tasks/e2e-installs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielfigueiredo this case should cover your issue

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
# ******************************************************************************
Expand Down