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

feat(workspaces): nested workspaces #6151

Closed
wants to merge 1 commit into from
Closed

Conversation

Anber
Copy link

@Anber Anber commented Jul 25, 2018

motivation
yarn finds the closest manifest with workspaces. It's ok in almost all cases, but it fails if a package in workspace already has his own workspaces. In this case will be better to use global workspaces settings.

Test plan

Package
|-- package.json # has workspaces
|-- packages
|   |-- a
|   |   |-- package.json # also has workspaces
|   |   |-- more_packages
|   |   |   |-- aa # `yarn workspaces info` here should return workspaces from the root package.json
|   |   |   |-- ab
|   |-- b
…

@arcanis
Copy link
Member

arcanis commented Jul 25, 2018

Thanks for your contribution! Nested workspaces are currently missing by design. If you want to add them, we'll need a more formal process where we expect you to detail the benefits and possible issues, and your PR will have to be thoroughly tested 🙂

@Anber
Copy link
Author

Anber commented Jul 26, 2018

Hi @arcanis!
I thought it's just a bug :)
Shall I open an issue for discussion or we can continue here?

@Anber Anber changed the title fix(workspaces): find real workspaceRoot instead of first found feat(workspaces): nested workspaces Jul 26, 2018
@Gudahtt
Copy link
Contributor

Gudahtt commented Aug 5, 2018

Substantial feature requests should be proposed as an RFC, which you can do here: https://github.com/yarnpkg/rfcs

Workspaces were the subject of many RFCs already. First it was proposed here, then it was split into three RFCs [1, 2, 3].

I can't find any detailed discussions about nested workspaces though. It would be great to see an RFC for that.

@milesj
Copy link

milesj commented Aug 8, 2018

I'm curious what use case you have for such an architecture?

@Gudahtt
Copy link
Contributor

Gudahtt commented Aug 9, 2018

The "extension repo" example from this issue comes to mind. Nested workspaces would make extending a monorepo easier to accomplish.

@milesj
Copy link

milesj commented Aug 9, 2018

@Gudahtt Multiple workspaces at the same folder level is quite different than nested workspaces.

@Gudahtt
Copy link
Contributor

Gudahtt commented Aug 9, 2018

Where are you seeing multiple workspaces at the same level?

The case I linked to was two monorepos, where one depends upon (i.e. is an extension of) the other. Each of these monorepos would have multiple workspaces.

e.g.

Extension Monorepo (root workspace)
  - packages/
  - Base Monorepo (root workspace)
    - packages/

Or...

Example Project (root workspace)
  - Base Monorepo (root workspace)
    - packages/
  - Extension monorepo
    - packages/

The main point here being that if you wanted this "Base Monorepo" to be usable with Yarn workspaces independently, nested workspaces would be a reasonable solution.

@Anber
Copy link
Author

Anber commented Aug 9, 2018

@milesj We have some projects with workspaces and one project with e2e tests which depends from all other.

@vitorcamachoo
Copy link

Any new ? I'm waiting for this feature. It will be very useful

@Anber
Copy link
Author

Anber commented May 22, 2019

@vitorcamachoo nested workspaces will be implemented in yarn v2 (#6953)

@vitorcamachoo
Copy link

vitorcamachoo commented Jul 5, 2019

What would be the behaviour of this feature ?
Im asking this because if I have the following structure:

Main Project (root workspace)
    - package.json (workspace: [web-modules, shared-modules])
  - web-modules (root workspace)
    - package.json (workspace: [*])
    - packages/*
  - shared-modules (root workspace)
    - package.json (workspace: [*])
    - packages/*

Every workspace is composed by linters, jest and so on.
So my question is, having this "nested workspaces" feature ready, running yarn on the Main project, will it install all dependencies of Main Project as well as sub workspaces (jest and linter dependencies) ?

Note:
-Every sub workspace is a git repository added by git submodule feature, because it will be used in other projects.

@arcanis
Copy link
Member

arcanis commented Jul 5, 2019

The workspace implementation for the v2 is described here:
https://yarnpkg.github.io/berry/features/workspaces

@vitorcamachoo
Copy link

vitorcamachoo commented Jul 5, 2019

The workspace implementation for the v2 is described here:
https://yarnpkg.github.io/berry/features/workspaces

It doesn't explain in detail what it does. I have some suggestions to make:

  1. Why you define on root workspace workspaces: [sub-workspace/*] if we can define without * ( workspaces: [sub-workspace]) and let the engine read the workspace attribute on sub-workspace package.json and use it to install their dependencies ?
  2. Dependencies and Dev-dependencies on sub-workspace package.json, should be installed on sub-workspace level, because most of them will be tool dependencies.

@Oba-One
Copy link

Oba-One commented Oct 26, 2020

Any update?

@forgetso
Copy link

Are nested workspaces supported yet? I have wasted many hours on this and I can't find any clear documentation surrounding it.

@cimchd
Copy link

cimchd commented Feb 21, 2022

Are nested workspaces supported yet? I have wasted many hours on this and I can't find any clear documentation surrounding it.

Almost. We have a project structure like above:

Main Project (root workspace)
    - .yarn/
    - package.json (workspace: [web-modules, shared-modules])
    - .yarnrc.yml
    - yarn.lock
  - web-modules (root workspace)
    - package.json (workspace: [*])
    - packages/*
  - shared-modules (root workspace)
    - package.json (workspace: [*])
    - packages/*

and it is working. :-)
The only problem we have, is that it's only working without nested .yarn 3 folders. So if we install yarn 3 separately inside the workspaces we encounter several problems.
Not working:

    - .yarn/
    - package.json (workspace: [web-modules, shared-modules])
    - .yarnrc.yml
    - yarn.lock
  - web-modules (root workspace)
    - .yarn/
    - package.json (workspace: [*])
    - packages/*
    - .yarnrc.yml
  - shared-modules (root workspace)
    - .yarn/
    - package.json (workspace: [*])
    - packages/*
    - .yarnrc.yml
    - yarn.lock

It's only working if there is only one .yarn folder inside the root folder.

@forgetso
Copy link

It's only working if there is only one .yarn folder inside the root folder.

Thanks, @cimchd. This helped me so much.

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

Successfully merging this pull request may close these issues.

None yet

8 participants