10

I have three packages:

  • A, depends on C
  • B, depends on C
  • C

When using lerna run build, C builds before A and B (good!)

But when I start a watch task lerna run watch, C never completes and therefor A and B dont get watched.

Using lerna run watch --parallel starts A, B and C at the same time but A and B both throw error because they cant find the dist folder from C (which C just deleted before rebuilding).

Is there any way to start watch tasks but still keep the order of dependencies like run normally does? Or at least delay some others?

Mick
  • 8,203
  • 10
  • 44
  • 66
  • I would assume that `parallel` doesn't guarantee the order of the build processes. – evolutionxbox Jan 26 '21 at 21:03
  • Does this answer your question? [Lerna specify run order](https://stackoverflow.com/questions/50769518/lerna-specify-run-order) – evolutionxbox Jan 26 '21 at 21:03
  • No how does it? Using parallel results in the problem described above. Not using parallel results in watching `C` but never watching `A` and `B` since the watch task of `C` never completes – Mick Jan 26 '21 at 21:12
  • Maybe there is no way to do this. I ended up watching `C` first and then all the rest. Another solution is to be sure dist does not gets removed when on build but event then initially there is no dist so build needs to be done before watch. – Mick Jan 30 '21 at 16:41
  • I think it answers it in this way: _"Similar to `--stream`, but completely disregards concurrency and topological sorting, running a given command or script immediately in all matching packages with prefixed streaming output."_ – evolutionxbox Jan 30 '21 at 16:46
  • @Mick I'm trying to setup a project but have the same problem, did you find out how to resolve it? – Alopwer Sep 08 '21 at 13:01

2 Answers2

0

Update: Based on the comment, I think I now understand whats happening. If you have build dependencies, they should sit in the same thread not concurrent threads, i.e. they should sequentially build.

However, you can still try it.. using the --noClean option in your build, it will not remove the dist folders! Then your parallel build will run.


Three settings: I would configure/double check (you didn't list your package.json) , so that lerna knows what order to follow

  1. First get your list in correct order for your peerDependencies
  2. Put those in the devDependencies
  3. of a given leaf package.json,

...The globs defined are relative to the directory that lerna.json lives in, which is usually the repository root. The only restriction is that you can't directly nest package locations, but this is a restriction shared by "normal" npm packages as well. And so... leaf packages under packages/* is considered a "best-practice"

enter image description here

Finally the topological order will then be user by lerna run in the build you can force it to include the dependencies --include-dependencies / or --include-dependents flag as needed, like so


Workaround option 2: for now to get past you can do...

lerna run build --concurrency 1
Transformer
  • 6,963
  • 2
  • 26
  • 52
  • Not sure if you understand the question but it has nothing to do with the order. The problem this if I start multiple WATCH tasks concurrently then each will remove its dist folder, then build their app and watch it. But while the dist folders are removed the apps cant find their dependencies. You cant do that in any order because lerna does not know when a watch task finished because they never finish. – Mick Feb 03 '21 at 16:05
  • @Mick did you try the `--noClean` option – Transformer Feb 07 '21 at 18:45
0

In my understanding, your watch jobs in a and b are not watching the node modules, especially the c dependency injected, and that result of this behavior.

Maybe if you add those directories to your watch job, you could find an efficient workaround.

  • No the problem is that each watch task deletes its dist folder when they start watching. Then all watch tasks start building at the same time but cant find their dependencies... – Mick Feb 05 '21 at 13:09