-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(workspaces): Allow patterns with non-semver ranges to match workspace packages #6012
base: master
Are you sure you want to change the base?
Conversation
…pace packages Previously for a requested dependency pattern to match a package in a workspace, it's name had to match and so did the semver range. If a request specified a non-semver range (like a github url) then it would not match, causing the resolver to attempt to resolve the package on the registry instead of use the workspace package. This change will match a workspace package just on it's name if no valid semver range was found on the requested pattern. fixes yarnpkg#4878 fixes yarnpkg#3973 affects yarnpkg#5726
I don't know how I feel about this change. I have a few remarks:
|
in #5726 (comment) @no-more mentions that he is using github refs because it is a set of private packages. That's the only case I've seen. I didn't think much about it at the time, but if they are private repos then they will probably never be published to the registry, so it might be fine to use a version or
IMO it was confusing (and took me days of debugging through the code to even realize) that workspace packages aren't just matched on their name and even took version into account. It might be worth adding something about that limitation in the docs.
If we ditch this PR then we could solve this a different way. |
Hi. I just found this and it bit me really hard. Eventually packages are pushed to a private NPM registry, but during development I use a Yarn workspace to wire them up. My typical convention is to use versions with Yarn throwing a rod at this is a really big bummer. I'd hope that the PR under consideration gets some love. |
I think this is exactly what my team needs. We publish to some private github repos (never to any NPM registry) but want to have everything together during dev. |
I'm in exactly the same situation as @kjs3 and the absence of this is currently blocking me from using workspaces, as I haven't found a workaround... |
@rally25rs I'm not quite sure how this would work...say I have a workspace with
Am I missing something? I'm happy to specify |
@bendemboski: Not exactly a completely open-ended |
@bestander IIRC this issue is what I tried to PM you on Discord about. |
I still don't think it's the right solution, fwiw. Imo, a better fix might be to use a |
I agree that git dependencies are a common thing and we should address this. I think resolution field would work but it is too hacky and not obvious, matching for semver validity makes more sense to me |
Yep, but you have no way to know the version of the remote dependency until you bring it to the disk (at least not without querying the network, which is not ideal since - on top of the obvious problems with |
Well this PR does not specifically enable network access, it just relaxes semver validity if users did not specify a correct semver limit. |
@arcanis @rally25rs Any updates on this one? |
Not fully versed in all the subtleties of the issue and the proposed solution but it feels to me like there is an inconsistency in how yarn is handling non-standard semver ranges like github urls/references when it comes to workspace packages. e.g. outside of workspaces, we can add versions that resolve to github urls like this to two different packages and yarn will resolve/dedupe this to most recent package.
So it was extremely confusing when we tried to use |
Would really like to see this or a similar solution get merged. My company would like to move to |
I just ran smack into this issue on a new project. I thought it might be a decent idea to have a monorepo that consists of git submodules for each package. Each package is maintained by a separate dev team, so in order to let them have their own Github PR and issues tracking, the workspace projects are separate github repos. The problem becomes these teams obviously want to have their own CI and test process, but to do that the dependencies would need to be resolved from github URLs when it's run outside the monorepo (which doesn't work because of this issue with semver resolution). Otherwise the CI server would have to checkout the entire monorepo and all subprojects, then flip one of them to the PR branch in order to be built/tested. |
I believe I ran into this by trying to have an alpha version as one of the workspace values and then in a different workspace linking it as However, when i switched |
Just wanted to bump this. #3973 has been an issue literally for years, and this PR has been open for (less) years. However this is solved, it needs to be solved at some point. We aren't using workspaces to publish packages, we are just using them to break up main app into modules, so we don't have to do a 20 minute rebuild every time. Because of this issue, we have to manually add packages and versions to a workspace package.json, and it's super tedious, and lowers my teams confidence in yarn workspaces. I'm currently considering publishing empty packages to work around this. Which is just silly. |
Why hasn't this been reviewed yet?
Edit: I have discovered a solution for my case. I am including a private "common" package from another private package in the same monorepo. Specify "*" version in the dependent's dependency list, and add any version to the dependency itself. |
Summary
Previously for a requested dependency pattern to match a package in a workspace, it's name had to
match and so did the semver range. If a request specified a non-semver range (like a github url)
then it would not match, causing the resolver to attempt to resolve the package on the registry
instead of use the workspace package. This change will match a workspace package just on it's name
if no valid semver range was found on the requested pattern.
This also fixes the command
yarn workspace @scope/foo add @scope/bar
where@scope/bar
is a workspace package. The semver range of the request is empty (no version was specified in the command), so it used to not match the package and instead try to find it on the registry. Now it will properly match the workspace package name.fixes #4878
fixes #3973
affects #5726
Test plan
Added new test file for
workspace-layout
.