Repository: yarnpkg/berry

Issue #2240: [Bug] Git URL Resolve Regression
Created: 2020-12-14T16:35:38Z
I'd be willing to implement a fix

Describe the bug
As discussed on Discord, it seems a regression has occurred sometime prior to 2.4.0 when a git-style reference isn't handled correctly
To Reproduce
// package.json

dependencies: {
  ...
  "typeorm": "git@github.com:elmpp/typeorm.git#commit=610da48cd6d82c7adadf19dbca1a62ba2fdebf00"
}


version 2.3.0: No Error
version 2.4.0: Error

○ → yarn
➤ YN0000: ┌ Resolution step
➤ YN0001: │ TypeError [ERR_INVALID_URL]: Invalid URL: git@github.com:elmpp/typeorm.git
    at onParseError (internal/url.js:258:9)
    at new URL (internal/url.js:334:5)
    at Module.d (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:412670)
    at b (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:136459)
    at v (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:136973)
    at F.resolvers.getCandidates (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:140649)
    at n.getCandidates (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:336286)
    at n.getCandidates (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:336286)
    at /Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:357942
    at Module.w (/Users/matt/dev/org-repo/.yarn/releases/yarn-2.4.0.cjs:2:417413)
➤ YN0000: └ Completed in 0s 289ms
➤ YN0000: Failed with errors in 0s 299ms

Environment if relevant (please complete the following information):

OS: OSX
Node version 14.15.0
Yarn version: 2.4.0

Duplicate issue #2978: [Bug] Git URLs parsed incorrectly
Created: 2021-06-03T11:33:39Z
I'd be willing to implement a fix

Yarn install fails when using Git protocol with workspace and tag parameters.
Per Protocol page in docs https://yarnpkg.com/features/protocols#git
Using git protocol in package.json
yarn-berry-issues [master●] % yarn -v
2.4.2

"dependencies": {
    "@yarnpkg/shell": "git@github.com:yarnpkg/berry.git#workspace=@yarnpkg/shell&tag=@yarnpkg/shell/2.1.0"
  }
Running yarn fails:
yarn-berry-issues [master●] % yarn
➤ YN0000: ┌ Resolution step
➤ YN0001: │ TypeError [ERR_INVALID_URL]: Invalid URL: git@github.com:yarnpkg/berry.git
    at onParseError (internal/url.js:258:9)
    at new URL (internal/url.js:334:5)
    at Module.d (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:419330)
    at b (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:143119)
    at v (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:143633)
    at F.resolvers.getCandidates (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:147309)
    at n.getCandidates (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:342946)
    at n.getCandidates (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:342946)
    at /Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:364602
    at Module.w (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:424073)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 10ms

Both @yarnpkg/shell/2.1.0 git tag and packages/yarnpkg-shell workspace exist:
berry [master] % git tag -l '*shell*2.1.0' | cat 
@yarnpkg/shell/2.1.0
berry [master] % yarn workspaces list -v | grep shell
➤ YN0000: packages/yarnpkg-shell

Still fails If change workspace param from @yarnpkg/shell to packages/yarnpkg-shell.
"dependencies": {
    "@yarnpkg/shell": "git@github.com:yarnpkg/berry.git#workspace=packages/yarnpkg-shell&tag=@yarnpkg/shell/2.1.0"
  }

yarn
➤ YN0000: ┌ Resolution step
➤ YN0001: │ TypeError [ERR_INVALID_URL]: Invalid URL: git@github.com:yarnpkg/berry.git
    at onParseError (internal/url.js:258:9)
    at new URL (internal/url.js:334:5)
    at Module.d (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:419330)
    at b (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:143119)
    at v (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:143633)
    at F.resolvers.getCandidates (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:147309)
    at n.getCandidates (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:342946)
    at n.getCandidates (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:342946)
    at /Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:364602
    at Module.w (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:424073)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 10ms

Using git protocol in yarn add
yarn-berry-issues [master●] % yarn add git@github.com:yarnpkg/berry.git#workspace=packages/yarnpkg-shell&tag=@yarnpkg/shell/2.1.0
[1] 32819
yarn-berry-issues [master●] % ➤ YN0000: ┌ Resolution step
➤ YN0001: │ Error: git@github.com:yarnpkg/berry.git#workspace=packages/yarnpkg-shell isn't supported by any available resolver
    at n.getResolverByDescriptor (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:343343)
    at n.bindDescriptor (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:342708)
    at d (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:364069)
    at async Promise.all (index 0)
    at async ie.resolveEverything (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:365274)
    at async /Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:383931
    at async f.startTimerPromise (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:396400)
    at async ie.install (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:383870)
    at async /Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:39877
    at async Function.start (/Users/alexander/Documents/code/yarn-berry-issues/.yarn/releases/yarn-berry.cjs:2:395097)
➤ YN0000: └ Completed
➤ YN0000: Failed with errors in 0s 8ms

[1]  + 32819 exit 1     yarn add git@github.com:yarnpkg/berry.git#workspace=packages/yarnpkg-shell

Closing comment (2021-06-03T11:50:06Z): Duplicate of #2240
Fixed in #2295 but it hasn't been released yet, you can run yarn set version from sources to use it before the next release

Using git protocol in yarn add

You need to quote it so your shell doesn't mess with it