Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
Given the following package:
{
"name": "b",
"repository": {
"type": "git",
"url": "https://github.com/a/b.git",
"directory": "c"
}
}
npm repo b
points to https://github.com/a/b/tree/master/c
. In other words, it assumes that a master
branch exists, which increasingly isn't always the case with many repos moving to other default branch names like main
.
(Note: this only happens when the repository
spec specifies a directory
, 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 from master
to main
but kept the former as an archive, meaning that npm 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. Perhaps HEAD
could be used instead of master
?
Steps To Reproduce
- Run
npm repo @babel/[email protected]
. (Including the version for posterity, but it's not currently necessary.) - Note that you've landed on https://github.com/babel/babel/tree/master/packages/babel-cli, which is not the default branch of the repo.
Environment
- npm: 8.9.0
- Node.js: 16.15.0
- OS Name: macOS
- System Model Name: MacBook Pro
- npm config: n/a