Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport workspaces from package.json #2255
Comments
|
There are some naming conflicts here. I don't know who is right but in pnpm a workspace is a set of projects. In Yarn, a set of workspaces is a project. So pnpm cannot read from a field called But we could check the presence of that field and print an error message suggesting to create a |
|
I'm not sure I understand the scenarios in which this distinction makes a difference. I mean, in both cases, each package in the monorepo gets as few dependencies within it as possible, and the package manager ensures the packages within the monorepo can link to each other via normal specification (as if they were not part of the same monorepo). |
Yarn calls these packages workspaces. pnpm calls them projects. The term "workspace" is used for a different purpose in pnpm. It is like a synonym of monorepo. I created a poll about what people think about these terms: https://twitter.com/ZoltanKochan/status/1214223464363675649 |
|
But what is the difference in practice? If the difference is in name only, and you'll always define the same set in both places, there's no reason to have two places. One could just be used as an alias to the other. |
|
I have posted my thoughts. Let's see what others think |
When I say "package" I mean just "a folder with a package.json in it". With that in mind,
The only difference currently is the way one tells the package manager the mappings between the value you would give in an import/require, and the corresponding [folder with a package.json in it]. In both cases, there are glob patterns that are supposed to match the [folders with package.json in them] from where the import/require name should be extracted, and mapped to that matched folder. And the feature request here is for pnpm to support yarn's mappings in package.json as a possible alias, but still prefer its own settings if both mappings are defined. How exactly are these mappings called in pnpm's own settings vs in package.json is besides the whole point, as they do the same thing. |
|
I think I would be fine with the next solution:
|
|
That's still not a zero config solution though... It would be fine as an additional option, but doesn't quite address the compatibility with yarn. If it's just about the word "workspaces" leaving a very bad taste in your mouth and wanting to encourage users to not use package.json like that, here's a compromise:
In that way, one can easily try out their pipeline with pnpm, and once they verify it works, either make the project "package manager agnostic" by getting rid of the warning, or move entirely to pnpm by getting rid of |
|
This is not only about "bad taste". Almost all commands check if they are executed in the context of a workspace. It means that each pnpm run will search for an additional file in the parent directories. And it will have to read every package.json in every parent directory to find a "workspaces" field. Maybe these additional filesystem operations are negligible but I don't know. It would have to be measured. |
|
To minimize such a penalty, the Sure, this would encourage the creation of I for one would not mind waiting even 1s more for each command if it means not having to take a few minutes researching why the command doesn't "just work", and adding |
|
I can suggest the following. If
|
|
Yes, that would work too. The few extra bytes on HDD per monorepo are nothing compared to the space savings offered by pnpm. Though it would be best if said config uses the previously suggested |
|
Yes, that's what I meant. The autogenerated |
|
I am in full agreement that it would be nice if pnpm could piggyback on my current "workspaces": {
"nohoist": ["react-native/**"],
}So, here is the effective type declaration for the "workspaces" field: workspaces: string[] | {
packages?: string[],
nohoist?: string[]
};Furthermore, yarn has a hard requirement that the root package.json is set as
|
|
Another point to keep Even if |


I have a project that is in a monorepo and uses yarn right now.
I'm considering migrating to pnpm for the monorepo, as well as all other projects I contribute to, as I have a small SSD as local storage (and with Windows...). However, it would be ideal if there was compatibility between yarn's workspaces and pnpm, so that we don't have to jump "all in" to it.
To this end, yarn allows packages in a monorepo to be defined as an array in package.json called "workspaces". I haven't checked if pnmp supports it, but from the absence in the docs, I'm assuming it doesn't.
Considering there's a separate file already, I guess one also has to consider what to do if both are present. I think it would be most intuitive if pnpm-workspace.yaml completely overrides package.json's workspaces if present (for backwards compatibility). There could also be a pnpm-workspace.yaml option on whether to change that to extend the package.json array instead.