-
I have a project with a few workspace, "frontend", "backend", "common". Each has its own "package.json" and dependencies. With Yarn 1, I put the "typescript", "eslint", and "jest" dependencies in the top-level "package.json". Seemed like an easy way to ensure the same version of those tools was used across all three workspaces. With Yarn 2, this doesn't seem to work the same way. For one, the "tsc" command (from TypeScript) is not available in the "backend" folder anymore. One solution is to put the "typescript", "eslint", and "jest" dependencies into each of the workspace "package.json" files. Is there another way to share dependencies between workspaces? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 17 replies
-
@arcanis how does this work with dependencies needed to run tests within packages? ie: my root many thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
I use the same setup and have this working using this: https://yarnpkg.com/getting-started/qa#how-to-share-scripts-between-workspaces In each package.json where you have a dependency, typescript for example, that needs to be used in child worktrees/workspaces, just add a Also, I use |
Beta Was this translation helpful? Give feedback.
-
I am fine with listing dependencies in each package that uses them, but how can I share the same version? I'd like to be able to bump a version for all packages that use it simultaneously. |
Beta Was this translation helpful? Give feedback.
-
I'm struggling with this "shared dependencies" problem as well - imagine having 7 sub-projects and updating "typescript", "webpack", ... in all 7 simultaneously - very painful |
Beta Was this translation helpful? Give feedback.
-
Have exact same issues migrating from yarn v1 to berry. Referring @davidluckystar comment, locking common dependencies for multiple packages / workspaces in one place without need of redeclare them per package was a great feature. Why there is no official docs refers it in berry? |
Beta Was this translation helpful? Give feedback.
-
What's stopping y'all from just running these commands in the root? Or defining the package scripts there? |
Beta Was this translation helpful? Give feedback.
-
When in doubt, write a plugin. That has been my principle recently for For this particular topic, i did end up writing a plugin that will run the binary from the root in the context of the package the command was executed. The nice thing is that i don't need custom names, the same I don't use PnP, so the plugin just reads the node_modules package.json but that should be easy to adjust. As an added bonus, the dependencies don't even have to be installed in root, they can be launched from some other folder as well. We use this to dynamically change which version of
|
Beta Was this translation helpful? Give feedback.
How to share scripts between workspaces?