Skip to content

Commit

Permalink
Allowing for local "file:" prefixed scripts packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Felchlin committed Dec 19, 2017
1 parent ed5c48c commit 707e5b8
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.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 707e5b8

Please sign in to comment.