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

[BUG] npm repo <pkg> assumes a master branch #4867

Closed
2 tasks done
billyjanitsch opened this issue May 6, 2022 · 2 comments · Fixed by #5692
Closed
2 tasks done

[BUG] npm repo <pkg> assumes a master branch #4867

billyjanitsch opened this issue May 6, 2022 · 2 comments · Fixed by #5692
Assignees
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

Comments

@billyjanitsch
Copy link

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

  1. Run npm repo @babel/[email protected]. (Including the version for posterity, but it's not currently necessary.)
  2. 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
@billyjanitsch billyjanitsch added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels May 6, 2022
@ljharb
Copy link
Contributor

ljharb commented May 6, 2022

oof, this should definitely use HEAD and not master.

@darcyclarke
Copy link
Contributor

@billyjanitsch thanks for bringing this to our attention. The change required to make this possible is actually in an upstream dep (hosted-git-info). It is a breaking change as this will more holistically change the default across the board for npm (but that's a good thing). We've got it queued up to land for v9 which we'll hopefully have prereleases/RCs for in a month or so.

@darcyclarke darcyclarke added Enhancement new feature or improvement Bug thing that needs fixing Release 9.x work is associated with a specific npm 9 release semver:major backwards-incompatible breaking changes Release 8.x work is associated with a specific npm 8 release and removed Needs Triage needs review for next steps Bug thing that needs fixing Release 8.x work is associated with a specific npm 8 release labels May 7, 2022
@lukekarrys lukekarrys assigned lukekarrys and unassigned lukekarrys Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants