-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[BUG] npm repo <pkg> assumes a master branch #4867
Copy link
Copy link
Closed
Labels
Bugthing that needs fixingthing that needs fixingEnhancementnew feature or improvementnew feature or improvementRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 releaseRelease 9.xwork is associated with a specific npm 9 releasework is associated with a specific npm 9 releasesemver:majorbackwards-incompatible breaking changesbackwards-incompatible breaking changes
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingEnhancementnew feature or improvementnew feature or improvementRelease 8.xwork is associated with a specific npm 8 releasework is associated with a specific npm 8 releaseRelease 9.xwork is associated with a specific npm 9 releasework is associated with a specific npm 9 releasesemver:majorbackwards-incompatible breaking changesbackwards-incompatible breaking changes
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Given the following package:
{ "name": "b", "repository": { "type": "git", "url": "https://github.com/a/b.git", "directory": "c" } }npm repo bpoints tohttps://github.com/a/b/tree/master/c. In other words, it assumes that amasterbranch exists, which increasingly isn't always the case with many repos moving to other default branch names likemain.(Note: this only happens when the
repositoryspec 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
masterdoesn'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 frommastertomainbut kept the former as an archive, meaning thatnpm repoopens 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. PerhapsHEADcould be used instead ofmaster?Steps To Reproduce
npm repo @babel/[email protected]. (Including the version for posterity, but it's not currently necessary.)Environment