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

[Feature] Support custom protocol via plugins #6672

Closed
2 tasks done
TrevorBurnham opened this issue Feb 1, 2025 · 2 comments
Closed
2 tasks done

[Feature] Support custom protocol via plugins #6672

TrevorBurnham opened this issue Feb 1, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@TrevorBurnham
Copy link

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

I have an internal use case where I want certain packages to be resolved by an in-house plugin.

Describe the solution you'd like

I've found that I can't use a plugin to resolve packages that use the normal dependency syntax, e.g. "@my-org/my-package": "^1.0.0". See discussion: #6658

As a second-best solution, I was thinking of using a custom protocol to indicate that the package should be resolved by the plugin, e.g.

"custom:@my-org/my-package": "^1.0.0"

However, that doesn't work either:

➤ YN0000: · Yarn 4.6.0
➤ YN0000: ┌ Project validation
➤ YN0057: │ @my-org/my-app: Parsing failed for the dependency name 'custom:@my-org/my-package'

The request here is to allow plugins to register a custom protocol.

Describe the drawbacks of your solution

Having dependencies use a custom protocol would mean that downstream packages would be "locked in" to using Yarn with a plugin capable of resolving that protocol.

Describe alternatives you've considered

As mentioned above, I'd prefer to do without the custom protocol and instead have my plugin logic determine which packages it should resolve. However, to do that I'd need a way to make my plugin take precedence over the built-in resolvers.

@TrevorBurnham TrevorBurnham added the enhancement New feature or request label Feb 1, 2025
@clemyan
Copy link
Member

clemyan commented Feb 8, 2025

A custom protocol goes to the range of a descriptor

"@my-org/my-package": "custom:^1.0.0"

You can then define a resolver for the custom: protocol via a plugin.

You can also use the defaultProtocol config to default all direct dependency ranges without an explicit protocol to your custom protocol, allowing you to intercept resolution of direct dependencies.

To intercept all dependency resolution, you can use the reduceDependency hook to change the descriptors of transitive dependencies.

@TrevorBurnham
Copy link
Author

Thank you, @clemyan! That's very clarifying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants