pnpm recursive install order

492 views Asked by At

I have a monorepo project, which contains workspace A and B, where A depends on B being built first. Each is in its own folder, defined in pnpm-workspace.yaml

packages:
 - 'src/mydepa'
 - 'src/mydepb'
{
   "name": "@mydep/a",
   "scripts": {
      "build": "standard build script"
   }
}
{
   "name": "@mydep/b",
   "scripts": {
      "build": "standard build script"
   },
   "dependencies: {
      "@mydep/a": "link:../mydepb
   }
}

I am at a complete loss at how to tell pnpm to build A first, before building B (and C and D). The monorepo builds fine using standard npm because the order of the workspace packages define the build execution. I remove the workspaces entry from the root package.json before running pnpm.

"workspaces": [
    "src/mydepa",
    "src/mydepb",
],

When I try the following, pnpm continues to build out of order.

pnpm run --recursive --workspace-concurrency=1 --aggregate-output --report-summary build
{
    "executionStatus": {
        "/path/to/mydepb": {
            "status": "failure",
            "duration": 1804.710345,
            "error": {
                "code": "ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL",
                "errno": 2,
                "pkgid": "@mydep/b@",
                "stage": "build",
                "script": "standard build script",
                "pkgname": "@mydep/b",
                "prefix": "/path/to/mydepb"
            },
            "message": "@mydep/b@ build: `standard build script`\nExit status 2",
            "prefix": "/path/to/mydepb"
        },
        "/path/to/mydepa": {
            "status": "queued"
        }
    }
}

When executed in order manually, the monorepo builds as expected, and builds correctly with npm workspaces due to the folder order in the workspaces array.

I tried adding --reverse=true but this had no effect on the executionStatus and I also tried --resume-from=@mydep/a which didn't seem to have any effect either

1

There are 1 answers

0
Zoltan Kochan On

Try replacing "@mydep/a": "link:../mydepb in the package b package.json with @mydep/a": "workspace:*".

So the b package.json should become:

{
   "name": "@mydep/b",
   "scripts": {
      "build": "standard build script"
   },
   "dependencies: {
      "@mydep/a": "workspace:*"
   }
}