Commit 0d716713 authored by Jonathan's avatar Jonathan Committed by Dan Abramov
Browse files

Allowing "file:<path>" --scripts-version values (#3629)

* Allowing for local "file:" prefixed scripts packages

* Fixing test failure
parent 10b05c76
3 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file
Showing with 11 additions and 2 deletions
+11 -2
......@@ -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.');
......@@ -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;
......@@ -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);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment