fix: remove url.parse (#9502)

close #9492
This commit is contained in:
btea
2025-05-11 20:15:38 +08:00
committed by GitHub
parent 28402b9c89
commit 6b6ccf97e7
2 changed files with 21 additions and 10 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/git-resolver": patch
"pnpm": patch
---
Remove `url.parse` usage to fix warning on Node.js 24 [#9492](https://github.com/pnpm/pnpm/issues/9492).

View File

@@ -169,16 +169,21 @@ function parseGitParams (committish: string | null): GitParsedParams {
// handle SCP-like URLs
// see https://github.com/yarnpkg/yarn/blob/5682d55/src/util/git.js#L103
function correctUrl (gitUrl: string): string {
const parsed = urlLib.parse(gitUrl.replace(/^git\+/, '')) // eslint-disable-line n/no-deprecated-api
if (parsed.protocol === 'ssh:' &&
parsed.hostname &&
parsed.pathname &&
parsed.pathname.startsWith('/:') &&
parsed.port === null) {
parsed.pathname = parsed.pathname.replace(/^\/:/, '')
return urlLib.format(parsed)
let _gitUrl = gitUrl.replace(/^git\+/, '')
if (_gitUrl.startsWith('ssh://')) {
const hashIndex = _gitUrl.indexOf('#')
let hash = ''
if (hashIndex !== -1) {
hash = _gitUrl.slice(hashIndex)
_gitUrl = _gitUrl.slice(0, hashIndex)
}
const [auth, pathname] = _gitUrl.slice(6).split('/')
const [, host] = auth.split('@')
if (host.includes(':') && !/:\d+$/.test(host)) {
const authArr = auth.split(':')
const protocol = gitUrl.split('://')[0]
gitUrl = `${protocol}://${authArr.slice(0, -1).join(':') + '/' + authArr[authArr.length - 1]}${pathname ? '/' + pathname : ''}${hash}`
}
}
return gitUrl
}