diff --git a/.changeset/pretty-humans-work.md b/.changeset/pretty-humans-work.md new file mode 100644 index 0000000000..8801f717f0 --- /dev/null +++ b/.changeset/pretty-humans-work.md @@ -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). diff --git a/resolving/git-resolver/src/parseBareSpecifier.ts b/resolving/git-resolver/src/parseBareSpecifier.ts index e40b0b3efe..a574da1443 100644 --- a/resolving/git-resolver/src/parseBareSpecifier.ts +++ b/resolving/git-resolver/src/parseBareSpecifier.ts @@ -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 }