Is there a way to bootstrap only the changed packages and their dependencies?

Viewed 14

I am investigating the features of Lerna to try and speed up our bootstrap process which currently takes quite a long time.

When referring to bootstrap here I am referring to the process of running npm install with hoisting and linking local packages together

One of the things I am trying to do is only build the packages that I have changed in a branch. Take this example project

Package CLI
Package Header
Package Footer
Package WebApp : Depends on Header & Footer

With this scenario what I want to do in CI is:

  • If I only change the CLI project then only the CLI project should go through bootstrap -> build -> test
  • Only changing Header should do the process for Header, Footer and WebApp because we want to ensure the dependency hasn't broken anything
  • Only changing Footer should do the process for Header, Footer and WebApp because we want to ensure the dependency hasn't broken anything
  • Only changing WebApp should do the process for Header, Footer and WebApp because we need to use the dependencies to check WebApp

The first thing I have looked at is using the jobs affected by a PR. This works for executing a script defined in the package.json, but only for the package itself and not its dependencies. In my example if I change CLI then the job only runs in the CLI package as I want, but if I change WebApp then it only runs in WebApp and it doesn't run on the dependencies Header and Footer. This is only for running an npm script rather than bootstrap anyway so I am not even sure this is the correct thing to be looking into.

Secondly I was looking into using task pipelines. So for example in the package.json of the WebApp I have

"dependencies": {
    "header": "*",
    "footer": "*"
}

And then in the Lerna.json I have

{
  "version": "3.0.0",
  ...
    "targetDefaults": {
        "build": {
            "dependsOn": [
                "^build"
            ]
        },
        "test": {
            "dependsOn": [
                "^build"
            ]
        }
    },
  "useNx": true
}

As far as I can tell though when I run test on WebApp using $ npx lerna run test --scope=webapp I can't see any output relating to it doing anything with it's dependencies. Additionally, I still think this doesn't account for the bootstrap process needed before the build step.

0 Answers
Related