Steve B
Steve B

Reputation: 37660

How to control pnpm workspace build order

I'm working in a large pnpm monorepo (pnpm v7).

The repository contains :

Every package (app or shared library) may reference any shared library (no circular ref though)

The compilation setup package is gulp helper that setup the compilation tasks for each app and some shared components.

It means that the build order should be :

Although dependencies are declared in every package.json files properly (either as devDependency or dependency), runnin pnpm -r run build seems to build projects randomly. The result is that it doesn't compile (complaining it miss some dependent packages).

I thought pnpm is supposed to deal with build order. Is there anything I miss ?

Should I move to more complex tools like turborepo or rush?

Upvotes: 11

Views: 4103

Answers (2)

lgersman
lgersman

Reputation: 2286

That's only half of the truth 😅 - yes, you can !

You can utilize pnpm to resolve the build order of your workspace using pnpm list (https://pnpm.io/cli/list)

pnpm list --parseable --recursive --only-projects will list the dependency of your workspace projects in the order of their dependency for consumption in shell scripts

pnpm list --json --recursive --only-projects will list the dependency of your workspace projects in the order of their dependency and outputs the result as json tree structure.

You can even add pnpm option --filter to limit the introspected package by package name.

Upvotes: 2

Steve B
Steve B

Reputation: 37660

I think, finally, that pnpm is not able, alone, to have such control.

I solved my issue by addin new tool on top of my repo.

I first gave a chance to turbo then nxdev. Both are able to detect the dependency graph and build in the correct order

Upvotes: 3

Related Questions