[BUG] npm repo <pkg> assumes a master
branch
#4867
Labels
Bug
thing that needs fixing
Enhancement
new feature or improvement
Release 8.x
work is associated with a specific npm 8 release
Release 9.x
work is associated with a specific npm 9 release
semver:major
backwards-incompatible breaking changes
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Given the following package:
npm repo b
points tohttps://github.com/a/b/tree/master/c
. In other words, it assumes that amaster
branch exists, which increasingly isn't always the case with many repos moving to other default branch names likemain
.(Note: this only happens when the
repository
spec specifies adirectory
, because otherwise the command points to the repo base, e.g.,https://github.com/a/b
.)There are a few possible failure states. GitHub redirects to the default branch if
master
doesn't exist, but it can't always handle this gracefully (and I'm not sure how other hosts behave). One unfortunate example is when a repo switched frommaster
tomain
but kept the former as an archive, meaning thatnpm repo
opens to an outdated view of the repo, e.g.,npm repo @babel/[email protected]
.The underlying issue is here, or in one of the other places that this library hardcodes the string
'master'
.Expected Behavior
npm repo <pkg>
should open to the default branch of the repository. PerhapsHEAD
could be used instead ofmaster
?Steps To Reproduce
npm repo @babel/[email protected]
. (Including the version for posterity, but it's not currently necessary.)Environment
The text was updated successfully, but these errors were encountered: