pnpmpnpm-workspace

pnpm run on multiples projects based on location


I work within a pnpm workspace that contains some shared libraries, some front apps and some back apps. Schematically:

├── apps-front
│   ├── f1
│   └── f2
├── apps-back
│   ├── b1
│   └── b2
├── packages
│   ├── shared-common
│   └── shared-front

└── package.json

I'd like to run pnpm scripts on a subset of the packages. For example, when I'm working on the front apps, I'd like to enable "watch" for both shared and both front apps, but not the back. Typically, shared react components are built in real conditions and code changes can occur on either side.

All these packages contains a "dev" script that watch for changes and compile. Theses script are by nature, blocking and must run in parallel.

According the pnpm documentation, the run command is expected to accept workspace and filter parameters.

Here's what I tried :

pnpm run serve -r --parallel --filter {apps-front} --filter {packages}

But it fails with this error : pnpm.CMD: The command parameter was already specified.

How to fix the command ?

PS: if it matters, pnpm is 6.23.6, node is 14.8 and I'm on W10 21H2 X64


Solution

  • Actually, it was due to powershell terminal. Enclosing filters with " solved the issue:

    pnpm run serve --stream --parallel --filter "{apps-front}" --filter "{packages}"
    

    I guess the brackets wasn't interpreted literally.

    I also removed the -r (recursive option) and added the --stream.

    This works well also in the workspace package.json as a script:

    {
        "scripts": {
            "devfront" : "pnpm run serve --stream​ --parallel --filter \"{apps-front}\" --filter \"{packages}\""
        }
    }