Ability to specify yarn workspace run order

Do you want to request a feature or report a bug?

What is the current behavior?

It is impossible (as far as I know) to specify workspaces order when running a script on all workspaces. For example, I have the core-1 and core-2 which depends on core.

If the current behavior is a bug, please provide the steps to reproduce.

If I run yarn workspaces run build, then it does start with core-1, and as it depends on core, then the build fails because the other package hasn’t been built.

A temporary workaround is to use prebuild script and then build core-1 and core-2 at build:

"scripts": {
  "prebuild": "yarn workspace core run build",
  "build": "yarn workspace core-1 run build && yarn workspace core-2 run build"

What is the expected behavior?

To be able to somehow specify an order to run the packages.

Please mention your node.js, yarn and operating system version.
Node: 11.10.1
Yarn: 1.13.0

Author: Fantashit

8 thoughts on “Ability to specify yarn workspace run order

  1. I’m having this issue as well. You’d think it’d use the dependency graph between the packages to figure out order (like install does). Seems to be alphabetical right now.

  2. Running scripts in dependency order by default makes the most sense to me. I assumed yarn workspace run would do this automatically but was surprised to find a build command in a package which depended on another package in the workspace used a stale version of the build.

  3. from my testing, you can specify the order. they run in whatever order you give in the packages section of the root package.json. it looks like they only run alphabetically when evaluating wildcard patterns

  4. In my opinion this is a bug.

    • The wildcard configuration packages/* is default in the docs
    • The very purpose of yarn workspace run is to execute build scripts in all packages
    • for this to work, the order has to be depended on their dependencies

    How do others automate this? In our environment we use mrbt, which determines the build order before launching.

    Babel is using yarn in a monorepo, but not yarn workspaces…

  5. @andypillip I totally agree that this is a bug. Having written dependency tree logic recently, It’s really not that complex (we use it for incrementing package versions automatically), I’m surprised it’s not in yarn already. It sounds like there are a ton of solutions out there for building monorepos (lerna, rush, wsrun, mrbt, etc.) in the correct order, but I really don’t understand why yarn workspace run can’t do it.

  6. Is there any progress on this? Yarn workspaces aren’t very useful if there’s no way to build the packages in the correct order.

Comments are closed.