Publish NPM package that uses a workspaces as dependencies
Asked Answered
T

1

6

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!

Trumantrumann answered 12/10, 2022 at 23:52 Comment(0)
R
5

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

Rasputin answered 24/11, 2022 at 22:59 Comment(1)
Is there an equivalent feature in npm?Myxoma

© 2022 - 2024 — McMap. All rights reserved.