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

Fix using pre-release tags with a tarball url in --scripts-version #876

Merged
merged 4 commits into from
Oct 12, 2016
Merged
Changes from 3 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
4 changes: 3 additions & 1 deletion packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "This" -> "this".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

return installPackage.match(/^.+\/(.+)-\d+.+\.tgz$/)[1];
Copy link
Contributor

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.

Copy link
Contributor Author

@jihchi jihchi Oct 12, 2016

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 with dash & number
      • .+ cut everything after
    • )? it's optional
  • \.tgz$ finally, the tarball file extension

} else if (installPackage.indexOf('@') > 0) {
// Do not match @scope/ when stripping off @version or @tag
return installPackage.charAt(0) + installPackage.substr(1).split('@')[0];
Expand Down