添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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

This way really messes when you try to remove or update other dependencies in a project that contains the Lerna package. Long Nguyen Jan 13, 2021 at 2:04

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .