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

Hard to transition to workspaces working with other repos because of peerDependencies #6888

Closed
mbeaudru opened this issue Jan 8, 2019 · 2 comments
Assignees
Labels

Comments

@mbeaudru
Copy link

mbeaudru commented Jan 8, 2019

I've done a repo that explains the problem, the solutions we've been thinking about and steps to reproduce with the files.

Yarn workspaces peerDependencies resolution repo

The issue summary

We want to be able to dev on a package "package-a" belonging to a yarn workspace while it is linked in a project "project-a" not related to this workspace.

We want to always have the same results than in prod, like when packages are taken from the registry for instance.

  • package-a belongs to the workspace and has a peerDependency on log-version ^1.0.0
  • package-b and package-c belongs to the workspace and both have a dependency on log-version@1.0.0

This makes log-version@1.0.0 be hoisted by the workspace

  • project-a has a dependency on log-version@1.1.0 and on package-a (version doesn't matter)
workspaces
  |-- node_modules
    |-- log-version@1.0.0
  |-- packages
    |-- package-a (peerDependency: log-version ^1.0.0)
    |-- package-b (dependency: log-version@1.0.0)
    |-- package-c (dependency: log-version@1.0.0)

project-a
  |-- node_modules
    |-- log-version@1.1.0
    |-- package-a
  package.json
    * dependency:
      - log-version@1.1.0
      - package-a

In dev

We link package-a in project-a and run project-a:

  • project-a has log-version@1.1.0 in dependency so uses version 1.1.0 when running

Expected behavior

  • package-a has log-version ^1.0.0 in peerDependency so running in project-a, should use log-version@1.1.0

Current behavior

BUT, package-a in fact uses log-version@1.0.0 because it is found in the workspaces root node_modules before!

Follow the steps, having in mind that package-a is linked into project-a:

workspaces
  |-- node_modules // STEP 3
    |-- log-version@1.0.0 // STEP 4
  |-- packages
    |-- package-a (peerDependency: log-version ^1.0.0) // STEP 2
    |-- package-b (dependency: log-version@1.0.0)
    |-- package-c (dependency: log-version@1.0.0)

project-a
  |-- node_modules
    |-- log-version@1.1.0
    |-- package-a // STEP 1
  package.json
    * dependency:
      - log-version@1.1.0
      - package-a

In production

  • project-a has log-version@1.1.0 in dependency so uses version 1.1.0 when running
  • package-a has log-version ^1.0.0 in peerDependency so running in project-a, uses log-version@1.1.0

When not linked, we do have:

project-a
  |-- node_modules
    |-- log-version@1.1.0 // STEP 2
    |-- package-a // STEP 1
  package.json
    * dependency:
      - log-version@1.1.0
      - package-a

Note : The readme in the repo is much more detailed, I didn't know if I should have gone to this level of detail in the issue description. I can edit this post and add everything if you prefer 👍

Environment

  • nodejs@8.12.0
  • yarn@1.12.3
  • OS: Tried on MacOS and Ubuntu 18.04

@arcanis

@ghost ghost assigned imsnif Jan 8, 2019
@ghost ghost added the triaged label Jan 8, 2019
@mbeaudru
Copy link
Author

Anyone ? 😄

@mbeaudru
Copy link
Author

I'm closing since @arcanis said this had to be done with Yarn PnP 👍

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

No branches or pull requests

2 participants