-
Notifications
You must be signed in to change notification settings - Fork 146
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
Isolated workspaces #90
Conversation
accepted/0000-isolated-workspaces.md
Outdated
Running a workspace in isolation should be as easy as running all workspaces together. Running a yarn command in | ||
a workspace should behave the same whether it is part of a larger project or whether it is its own separate repo. There | ||
should be a new set of commands, `yarn workspaces <command>` to distinguish between running commands that affect | ||
the whole workspace from commands that affect a single workspace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whole workspace => all workspaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops yea
accepted/0000-isolated-workspaces.md
Outdated
|
||
# Summary | ||
|
||
Running a workspace in isolation should be as easy as running all workspaces together. Running a yarn command in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Running a workspace" is a bit misleading, word missed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it could say
Working on a workspace in isolation should be as easy as working on all workspaces together.
accepted/0000-isolated-workspaces.md
Outdated
Terminology used for this doc: | ||
- rootDir: the root directory of a workspaces project. the one with the package.json with workspaces in it | ||
- workspaceDir: Directory for an individual workspace/package | ||
- regular (isolated) mode: `yarn foo` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think isolated is a better term than regular
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
@bdwain thanks for your RFC! I was thinking of something way simpler. Can we have a flag like |
@bestander yea a flag on the existing commands also works. I kind of mentioned that in the unresolved questions section. I'm not too attached to having it be a separate command versus a flag. I think the general idea is the same though. I was pretty detailed when I wrote it (to cover all edge cases) but I don't think it's a super complicated proposal overall. If possible though, I would like to retain the ability to run install in a specific workspace without a flag. The reason I think this would be useful is that for a team who is migrating away from a multi-repo setup, people would be used to working on projects in isolation, which means having yarn install behave in an isolated way. For a lot of these projects, it can be the case that the average person working on the project works on a single workspace at a time, and it would be annoying for them to always have to remember to type I think the simplest way to achieve that would be what I described, where the commands are aware if they are run in a single workspace or at the root of the project. As a slightly more complicated alternative though, there could be 2 flags, |
updated with the wording changes. |
BTW, did you know that you can set a flag via .yarnrc for any command? The team that migrates to monorepo can just set
In their project's .yarnrc and it will do the trick. |
accepted/0000-isolated-workspaces.md
Outdated
- rootDir: the root directory of a workspaces project. the one with the package.json with workspaces in it | ||
- workspaceDir: Directory for an individual workspace/package | ||
- isolated mode: `yarn foo` | ||
- workspaces mode `yarn workspaces foo` (could also be `yarn foo --workspaces` or `yarn foo -W` like yarn add) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the default mode right now and you propose isolated mode to become default?
I would rather avoid a breaking change and reverse it.
Via .yarnrc you can set up a subfolder to work in isolated mode and if a user cd to that folder Yarn would work in isolated mode.
But if user cd to any other folder Yarn would work the way it works right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works. I did not know about settings flags via yarnrc. I do think it's worth reconsidering the default mode at the next major version, but that can be a separate issue.
So if i used that, i could still go into the workspace and say yarn install --isolate=false
to run explicitly in workspaces mode? That is a bit awkward. Kinda why i was thinking of having a --workspaces flag that is basically the opposite of --isolate (in addition to --isolate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose doing a non breaking progressive change first and shipping it.
Then before Yarn v2.0 we can ask people to weigh in if introducing the reverse would be better for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough! I'll make those changes to the doc
@bestander i changed the proposal to have an --isolated flag |
Thanks, @bdwain, I think we achieved a nice balance here. |
Sweet! I can try to work on a PR to implement this. Thanks for the feedback! |
@bestander I've gotten yarnpkg/yarn@master...bdwain:isolated basically i just added a rootFolder value to the config object (which takes into account the isolated flag) and use that everywhere instead of using the lockfile folder and assuming it's the installation location. Do you think you could check out that branch (it's small) and let me know if my general approach looks alright? Or if you're busy if you could point me to someone else who might be able to look? Thanks! |
I am looking forward for this to be supported by yarn natively. Until then I wrote a little package that provides a way to isolate a single yarn workspace: https://github.com/choffmeister/yarn-workspace-isolator So far it worked pretty well for me (I used it to build individual docker images from my monorepo), but there are for sure some edgecases around the corner. Maybe this can help others, too, until this RFC is implemented. |
@bdwain, looks good, can't wait to see the PR! |
Hmm...maybe you already cover that, but I do not see it working for the following case. Say I am having a monorepo:
Imagine this monorepo is to be open-sourced, but at the same time you start working on a Thus, imagine you clone the Now I want to be able to run
So in other words I would like that yarn install behaves as usually with respect to symlinking, but does not hoist any other modules that are listed as dependencies of I would imagine that in the root
Does it make sense, or maybe you think this should be approached in some other, better way? |
my thought is that monorepos aren't really designed to have arbitrary consumer packages added temporarily. if the packages are closely related enough that someone would develop them locally against eachother, it probably makes sense for them to be in the same monorepo. If it's just something like a client-app developer is making a PR to the monorepo and wants to test their changes locally (but does not normally work on it), they can always use yarn link to try it out. |
@bdwain ok, I should not mention "temporarily" - the key point in my initial comment is that the |
I'm a bit confused. Is the monorepo aware of client-app? Or does it only exist inside the monorepo when working locally? Is this needed to simplify development? Git submodules/subtrees/subrepos may be a useful tool for something like that either way. I've heard mixed things about them, but they might be useful for adding arbitrary other repos into the monorepo without committing the actual code. |
Yes, it may be a bit confusing, but this is actually very common scenario in our environment (mixed Open Source and not open source). So monorepo is both aware and not aware of the You mentioned before |
I may be mistaken but it sounds like you kind of want the opposite of an isolated workspace. You want to run client-app inside the monorepo but use its yarn.lock, not the main lockfile, to resolve dependencies, right? And then just to use local copies of package1 and package2 instead of copies installed from npm? |
I would not say that it is a total opposite of an isolated workspace (in some way it is), but the rest you got right :). |
Yarn is introducing the |
@marcinczenko the proposal ended up changing a bit. Check out the focused workspace folder in the accepted folder. It’s a bit simpler now. I think nohoist should work well with it. |
@bestander this is based on discussion in yarnpkg/yarn#4099 and would likely address yarnpkg/yarn#4207 and possible yarnpkg/yarn#4219 as well.
rendered view