node.jsnpmmonorepopnpmpnpm-workspace

Publish NPM package that uses a workspaces as dependencies


so I have a project that I'm working on that is a Monorepo. So I have a packages directory in the root directory that contains all my npm packages. Some of these packages rely on eachother e.g. in a package.json I might have

{
    "dependencies": {
        "foo": "workspace:*",
        "bar": "workspace:*",
    }
}

(I use pnpm)

So I was wondering, if I were to post these packages, would all the dependencies still work the way they should?

Thanks!


Solution

  • Pnpm will do all the work for you when using pnpm publish (instead of npm publish).

    It will automatically replace this:

    {
        "dependencies": {
            "foo": "workspace:*",
            "bar": "workspace:*",
        }
    }
    

    with the current version, for example:

    {
        "dependencies": {
            "foo": "1.5.0",
            "bar": "1.5.0",
        }
    }
    

    cf https://pnpm.io/workspaces#publishing-workspace-packages