I have created a monorepo with pnpm workspaces and Lerna. The applications live under packages/* and some libraries under lib/*
I have one library under lib that needs to be built before being installed. During development I was able to install dependencies for all packages and build this library manually, but that's not a feasible approach in a pipeline where I want to build and deploy specific applications.
I installed this lib my-lib
to an application @myapp/package1
using
pnpm add my-lib --filter @myapp/package1
.
This causes the dependency to appear as
{
"name": "@myapp/package1",
"dependencies": {
"my-lib": "workspace:^"
}
}
With this, webpack is not able to resolve the paths (any help with this will be appreciated).
So, I've changed it to
"my-lib": "../../lib/my-lib",
I'm now unsure, how to install and build dependencies of specific application(s) in pipeline.
Locally, I've tried few commands, but they ignore my-lib
for some reason.
- Only considers
@myapp/package1
npx lerna run build --since HEAD
- Again only considers @myapp/package1 and not its dependencies
npx lerna run build --scope=@myapp/package1
- builds all packages, keeping dependency order intact, but I want to limit it to dependencies of specific changed packages.
npx lerna run build
Also how to extend this behavior to pnpm install
to install dependencies of specific packages. For @myapp/package1
, it would mean installing dependencies of mylib
as well.
Edit
I was able to achieve some of the things asked here:
To build the library before it's installed in another application, I created a postinstall script in the library
{
"scripts": {
"postinstall": "pnpm run build"
}
}
To install dependencies of specific package and also the dependencies of its transitive dependencies
pnpm recursive install --filter @myapp/package1
To build a specific package, and before that build all its dependencies
npx lerna run build --scope=@myapp/package1 --include-dependencies