Skip to content

Commit

Permalink
Allowing "file:<path>" --scripts-version values (facebook#3629)
Browse files Browse the repository at this point in the history
* Allowing for local "file:" prefixed scripts packages

* Fixing test failure
  • Loading branch information
GreenGremlin authored and Pavel Zhytko committed Jul 10, 2018
1 parent c905165 commit 9d3b101
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function run(
template,
useYarn
) {
const packageToInstall = getInstallPackage(version);
const packageToInstall = getInstallPackage(version, originalDirectory);
const allDependencies = ['react', 'react-dom', packageToInstall];

console.log('Installing packages. This might take a couple of minutes.');
Expand Down Expand Up @@ -365,11 +365,16 @@ function run(
});
}

function getInstallPackage(version) {
function getInstallPackage(version, originalDirectory) {
let packageToInstall = 'react-scripts';
const validSemver = semver.valid(version);
if (validSemver) {
packageToInstall += `@${validSemver}`;
} else if (version && version.match(/^file:/)) {
packageToInstall = `file:${path.resolve(
originalDirectory,
version.match(/^file:(.*)?$/)[1]
)}`;
} else if (version) {
// for tar.gz or alternative paths
packageToInstall = version;
Expand Down Expand Up @@ -459,6 +464,10 @@ function getPackageName(installPackage) {
return Promise.resolve(
installPackage.charAt(0) + installPackage.substr(1).split('@')[0]
);
} else if (installPackage.match(/^file:/)) {
const installPackagePath = installPackage.match(/^file:(.*)?$/)[1];
const installPackageJson = require(path.join(installPackagePath, 'package.json'));
return Promise.resolve(installPackageJson.name);
}
return Promise.resolve(installPackage);
}
Expand Down

0 comments on commit 9d3b101

Please sign in to comment.