fix(git-resolver): avoid retries on bitbucket/gitlab private repos (#2731)

Retry feature exposed this bug. The hosted.git() only works with GitHub repos, bitbucket/gitlab has no gitTemplate defined in hosted-git-info.
This commit is contained in:
Chunpeng Huo
2021-12-07 08:35:59 +11:00
committed by GitHub
parent 77ff0898b8
commit c941044727
2 changed files with 10 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/git-resolver": patch
"pnpm": patch
---
Don't make unnecessary retries when fetching Git-hosted packages [#2731](https://github.com/pnpm/pnpm/pull/2731).

View File

@@ -78,7 +78,9 @@ async function fromHostedGit (hosted: any): Promise<HostedPackageSpec> { // esli
let fetchSpec: string | null = null
// try git/https url before fallback to ssh url
const gitUrl = hosted.git({ noCommittish: true })
// Note only GitHub has gitTemplate (git://...) in hosted-git-info, has to use
// sshTemplate (git@...) for bitbucket and gitlab.
const gitUrl = hosted.git({ noCommittish: true }) ?? hosted.ssh({ noCommittish: true })
if (gitUrl && await accessRepository(gitUrl)) {
fetchSpec = gitUrl
}
@@ -105,7 +107,7 @@ async function fromHostedGit (hosted: any): Promise<HostedPackageSpec> { // esli
// npm instead tries git ls-remote directly which prompts user for login credentials.
// HTTP HEAD on https://domain/user/repo, strip out ".git"
const response = await fetch(httpsUrl.substr(0, httpsUrl.length - 4), { method: 'HEAD', follow: 0 })
const response = await fetch(httpsUrl.substr(0, httpsUrl.length - 4), { method: 'HEAD', follow: 0, retry: { retries: 0 } })
if (response.ok) {
fetchSpec = httpsUrl
}