-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Fix using pre-release tags with a tarball url in --scripts-version
#876
Conversation
Thanks for the PR! Can you please explain why this works and the other one didn't? |
getPackageName('https://registry.npmjs.org/react-scripts/-/react-scripts-0.2.0-alpha.1.tgz');
// expected: react-scripts
// actual: react-scripts-0.2.0 Current regex didn't handle pre-release tags. This modification adds support for this case as well as original case. Just like original regex, first it searches first backslash |
@@ -153,7 +153,7 @@ function getInstallPackage(version) { | |||
// Extract package name from tarball url or path. | |||
function getPackageName(installPackage) { | |||
if (installPackage.indexOf('.tgz') > -1) { | |||
return installPackage.match(/^.+\/(.+)-.+\.tgz$/)[1]; | |||
return installPackage.match(/^.+\/(.+)-[0-9]+\.[0-9]+\.[0-9]+(?:[-+].+)?\.tgz$/)[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment showing intended inputs and what should match them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added.
@@ -153,6 +153,8 @@ function getInstallPackage(version) { | |||
// Extract package name from tarball url or path. | |||
function getPackageName(installPackage) { | |||
if (installPackage.indexOf('.tgz') > -1) { | |||
// The package name could be with or without semver version, e.g. react-scripts-0.2.0-alpha.1.tgz | |||
// However, This function returns package name only wihout semver version. | |||
return installPackage.match(/^.+\/(.+)-[0-9]+\.[0-9]+\.[0-9]+(?:[-+].+)?\.tgz$/)[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make regex cut everything after the first -\d
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changed.
return installPackage.match(/^.+\/(.+)-.+\.tgz$/)[1]; | ||
// The package name could be with or without semver version, e.g. react-scripts-0.2.0-alpha.1.tgz | ||
// However, This function returns package name only wihout semver version. | ||
return installPackage.match(/^.+\/(.+)-\d+.+\.tgz$/)[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make that group optional? So that just react-scripts.tgz
will also get parsed correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changed.
Regex breakdown:
^.+\/
starts with any characters until last slash(
group 1.+?
searches for package name (non-greedy for searching optional semver version)
)
(?:
non-capturing group-\d+
searches for version starts withdash & number
.+
cut everything after
)?
it's optional
\.tgz$
finally, the tarball file extension
@@ -153,7 +153,9 @@ function getInstallPackage(version) { | |||
// Extract package name from tarball url or path. | |||
function getPackageName(installPackage) { | |||
if (installPackage.indexOf('.tgz') > -1) { | |||
return installPackage.match(/^.+\/(.+)-.+\.tgz$/)[1]; | |||
// The package name could be with or without semver version, e.g. react-scripts-0.2.0-alpha.1.tgz | |||
// However, This function returns package name only wihout semver version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "This" -> "this".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Looks good to me. Thanks! |
…acebook#876) * Add supports for prelease tags version * Add comment to regex * Cut everything after the first -\d * Make semver version optional, so just package name get parsed correctly
…acebook#876) * Add supports for prelease tags version * Add comment to regex * Cut everything after the first -\d * Make semver version optional, so just package name get parsed correctly
For example, react-scripts version
0.2.0-alpha.1
with tarball url didn't works:create-react-app version: 0.5.0