Skip to content

RFC for running workspace commands from root - #83

Merged
bestander merged 5 commits into
yarnpkg:masterfrom
DeltaCircuit:master
Jan 28, 2018
Merged

bestander merged 5 commits into
yarnpkg:masterfrom
DeltaCircuit:master

Conversation

@DeltaCircuit

Copy link
Copy Markdown

Redirected from here

It would be great if we have a single command to execute a package script for all the packages under a workspace.

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, thank you! Pinging @bestander for comments. and also @arcanis

Comment thread accepted/0000-workspace-run-commands.md Outdated
* `yarn workspaces list`
* `yarn workspaces run <command>`

By introducing `workpaces` command, it brings a modular approach from the CLI's perspective.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible additions:

yarn workspaces add : This would create the folder if it doesn't exist and make sure it is included in the top-level workspaces config.
yarn workspaces remove : Remove a specific workspace from the config and optionally delete the folder if -D flag is passed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the yarn workspaces add, shouldn't we pass the workspace name too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread accepted/0000-workspace-run-commands.md Outdated

## `yarn workspaces list`

This command lists out the package names inside that workspace. In the case of multiple workspace configuration, we'll need to pass the workspace name like `yarn workspaces <workspace_name> list`. By defaut, when no workspace name is not given, it'll pick the first workspace name from the root package.json.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what you mean by a multi-workspace config?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so sorry.. Got confused with this.
image I thought we had a multi-workspace setting. Will remove that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems more logical to either list all packages for all workspaces or fail with error.
Picking first workspace is strange and not really useful

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to listing all of the packages in all the workspaces. That would also allow for easy "filtering" of workspaces if you only want to list a specific few of them, like:

yarn workspaces --filter workspace-a list

...or similar. (I think something like --filter functionality would ideally be available on all the workspaces commands.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianstormtaylor thanks for that --filter tip.

@BYK BYK self-assigned this Sep 29, 2017
@BYK BYK removed their assignment Oct 6, 2017
@BYK
BYK requested a review from arcanis October 6, 2017 16:58
@jharris4

Copy link
Copy Markdown

This feature could be useful to help clean files from individual packages in workspace, such as node_modules.

Some related issues from non-workspace yarn are:

yarnpkg/yarn#1284
yarnpkg/yarn#1048

@James-E-Adams

Copy link
Copy Markdown

What are other peoples' thoughts on being able to execute a particular package's script in isolation?

I.e If workspace-a has a test script, being able to run yarn workspace-a:test, rather than run it for every workspace.

Comment thread accepted/0000-workspace-run-commands.md Outdated

## `yarn workspace remove <workspace_name> --opts`

Remove a specific workspace from the config. And by passing `-D` as an option, it'll delete the folder.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity I would focus only on list/run commands.

Add/delete are less utility and more like sugar on top of editing package.json and adding/removing folders.
Also I don't like inconsistency workspaces/workspace for those commands
And in Yarn we prefer using explicit flags and not shorts --delete-folder would be more consistent with other commands

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, yeah, you're right. This doesn't gives any extra convenience. Removed!

@bestander

Copy link
Copy Markdown
Member

@James-E-Adams, seems logical however it can be achieved with a cd workspace && yarn run test macro.
Because every new feature adds more support cost I would vote against it.

@bestander

Copy link
Copy Markdown
Member

@giridharangm, sorry for a delay in review.
If you are still around are you willing to go through a new review cycle?

@DeltaCircuit

Copy link
Copy Markdown
Author

No worries @bestander . Me too, was packed with tasks (I'm a full-time dev in a private firm). I'm in the middle of a production release, but I'll update the docs as per your review ASAP.

@bestander

Copy link
Copy Markdown
Member

No rush, just ping whenever you are ready

Comment thread accepted/0000-workspace-run-commands.md Outdated

This command will execute the specified command in all the packages under the workspace. Before we run the scripts, it should make sure that all packages has the script specified in the package.json. Otherwise, it should throw an error specifying which pacakge is missing that script.

Just like the `list` command, by default, it'll select the first workspace in case of no workspace name is provided.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should again run the command in all workspaces, not just the first one. And then later a "filtering" mechanism can be added to restrict further. But otherwise it seems to arbitrary.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, like @bestander said earlier, if we want to execute a command in a specific workspace, it's better to cd to that package and yarn run.

I've updated this command to execute all in all workspaces.

@DeltaCircuit

Copy link
Copy Markdown
Author

@bestander I've made some few change. Could you please have a look?

@ianstormtaylor

Copy link
Copy Markdown
Contributor

@bestander would you reconsider the ability to offer filtering to run commands in specific subsets of packages? I think there are three usage patterns for this:

  1. Executing a script in all packages.
  2. Executing a script in a specific subset of packages.
  3. Executing a script in a single package.

I agree that (3) can be easily solved by cd ... && yarn run ..., but only the option of some sort of filtering/scoping mechanism (like Lerna has) allows you to solve all three easily.

My use case for (3) is having workspaces split up into services and utils, like so:

workspaces: [
  'services/*',
  'utils/*',
]

Which allows me to keep things more organized, and then for example I could run build watchers across all workspaces, but only run server-starting commands in the services workspaces.

@bestander

Copy link
Copy Markdown
Member

To get the ball rolling let's merge this one.

@bestander
bestander merged commit 38dd9c8 into yarnpkg:master Jan 28, 2018
@bestander

Copy link
Copy Markdown
Member

@ianstormtaylor, sure, can you send a PR for the same file with the proposed change?
Let's discuss it pros and cons

@Siyfion

Siyfion commented Feb 13, 2018

Copy link
Copy Markdown

Just to add my 2¢...

I personally think this is a great idea, and will certainly help a lot when dealing with a monorepo. I also can't think of anything that this change would "break" in current functionality, which is always good! Lerna is fantastic and all, but not all monorepo projects need/should to be published to NPM.

We're currently investigating using monorepos to hold a number of SPAs that are all for a given "project". So for CI/CD integration this would be hugely useful as well as for local development.

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.

8 participants