Skip to content

Commit 38dd9c8

Browse files
Giridharan GMbestander
authored andcommitted
RFC for running workspace commands from root (#83)
* RFC for running workspace commands from root * workspace add and remove commands * workspace list command lists out all packages for all workspaces * Remove add/remove options * update run command to execute in all workspaces
1 parent a9fdad7 commit 38dd9c8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
* Start Date: 2017-09-21
2+
* RFC PR:
3+
* Yarn Issue:
4+
5+
# Summary
6+
7+
Allow Yarn CLI to execute a package script on each packages from the workspace root.
8+
9+
# Motivation
10+
11+
"Lerna". Lerna does a great job for handling monorepos. Since Yarn has a built-in
12+
workspaces feature, we could use some of the functionalities that being used in
13+
lerna (not entirely though!) for handling the monorepo more efficiently.
14+
15+
Just like installing all dependencies from one place (workspace root), it'd be great
16+
to execute all the sub-package scripts from the workspace root using a single command.
17+
Not only this would make a less back-and-forth traveling between the packages to
18+
execute scripts, but also it'll help a lot for CI/CD configuration.
19+
20+
# Detailed design
21+
22+
As @BYK mentioned [here](https://github.com/yarnpkg/yarn/issues/4467#issuecomment-330873337),
23+
we could create two commands for this feature.
24+
25+
* `yarn workspaces list`
26+
* `yarn workspaces run <command>`
27+
28+
By introducing `workpaces` command, it brings a modular approach from the CLI's perspective.
29+
30+
## `yarn workspaces list --args`
31+
32+
This command will list out all the packages for all the workspaces (alphabetically). If no workspace is found, this will fail with error.
33+
34+
Additionally, we can pass a `--filter` argument followed by a workspace name. In that case, it'll list out all the package inside that specified workspace.
35+
36+
## `yarn workspaces run <command>`
37+
38+
This will execute the specified `<command>` in all workspaces. For a _fail fast_ operation, we could traverse all the workspaces to check whether the specified command exists within that workspace, before we actually start executing. If not found, display an error with which workspace is missing that command.
39+
40+
The ordering of execution is also important. It must be executed _topologically_. So that it won't break the inter-dependant workspaces.
41+
42+
# How We Teach This
43+
44+
Since this is a new feature and doesn't affect existing functionalities, it shouldn't affect existing/new users. However, a slight documentation should be written under the workspace CLI.
45+
46+
# Drawbacks
47+
48+
Complexity. Especially while executing the package scripts. We need to keep track of the package dependencies. And also, there's already a library (lerna) does the same thing and is compatible with yarn without any extra configuration.
49+
50+
# Alternatives
51+
52+
Don't have an alternative way (I can think of) inside yarn.
53+
54+
# Unresolved questions
55+
56+
How to handle multiple workspaces?

0 commit comments

Comments
 (0)