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

Make --scripts-version work with forked react-scripts #632

Merged
merged 1 commit into from
Sep 18, 2016
Merged
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
22 changes: 17 additions & 5 deletions global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ function createApp(name, verbose, version) {
}

function run(root, appName, version, verbose, originalDirectory) {
var installPackage = getInstallPackage(version);
var packageName = getPackageName(installPackage);
var args = [
'install',
verbose && '--verbose',
'--save-dev',
'--save-exact',
getInstallPackage(version),
installPackage,
].filter(function(e) { return e; });
var proc = spawn('npm', args, {stdio: 'inherit'});
proc.on('close', function (code) {
Expand All @@ -118,12 +120,12 @@ function run(root, appName, version, verbose, originalDirectory) {
return;
}

checkNodeVersion();
checkNodeVersion(packageName);

var scriptsPath = path.resolve(
process.cwd(),
'node_modules',
'react-scripts',
packageName,
'scripts',
'init.js'
);
Expand All @@ -144,11 +146,21 @@ function getInstallPackage(version) {
return packageToInstall;
}

function checkNodeVersion() {
// Extract package name from tarball url or path.
function getPackageName(installPackage) {
if (~installPackage.indexOf('.tgz')) {
return installPackage.match(/^.+\/(.+)-.+\.tgz$/)[1];
} else if (~installPackage.indexOf('@')) {
return installPackage.split('@')[0];
}
return installPackage;
}

function checkNodeVersion(packageName) {
var packageJsonPath = path.resolve(
process.cwd(),
'node_modules',
'react-scripts',
packageName,
'package.json'
);
var packageJson = require(packageJsonPath);
Expand Down