Lerna specify run order
Asked Answered
R

3

21

In my monorepo, I have 3 packages package1, package2, package3, each package contains a npm script named build.

However, these packages are not linked together. I.e. there are no require() in any of those packages linking to a sibling package.

From the root folder, I run lerna run build. It seems to run build of the packages in the alphabetically order.

Is there a way to specify the order to run the build commands of these packages?

--sort won't work because they are not linked.

Rother answered 8/6, 2018 at 23:21 Comment(1)
Any luck on finding a way to specify build order?Borlase
G
34

You don't specify the order, you specify the topology by including a package as a dependency of another.

If package1 needs to be built before package2 you add package1 to the dependencies of package2 in the latter's package.json file. If you do not want package2 to directly depend on package1 (e.g. on production) you can still add it into devDependencies and Lerna will understand the dependency.

From lerna -h:

--sort Sort packages topologically (dependencies before dependents). Pass --no-sort to disable. [boolean] [default: true]

Note Some commands can be ran ignoring this topology, for example from lerna exec's --parallel option documentation:

completely disregards concurrency and topological sorting

Gorki answered 13/1, 2019 at 8:38 Comment(2)
You saved my life.Bardwell
This way really messes when you try to remove or update other dependencies in a project that contains the Lerna package.Stressful
C
4

lerna run build --include-dependencies --stream

--include-dependencies this flag can help

Caddell answered 16/11, 2020 at 8:46 Comment(0)
F
1

You can first build your shared package and after that trigger another build.

Ex :

yarn workspace @shared run build && yarn lerna run build

Foliolate answered 2/9, 2021 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.