-
-
Notifications
You must be signed in to change notification settings - Fork 960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support 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 cc @pnpm/collaborators |
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 |
@leonardfactory Well I think other tools can identify the pnpm by using |
npm 7 supports |
Since npm v7 seems to have adopted the same definition of |
any progress? |
I've also considered moving to pnpm and found out that it does not use the same convention as yarn and npm. I think pnpm should support the |
We are learning about this constraint and missing Edit: Welp. Yarn or rather Rush with Yarn has other issues. Seems Rush doesn't support Yarn's workspaces and thus can't use Yarn's workspaces features. Buggers.... Edit2: We've gotten the package to work by installing dependencies of a particular sub-package in our package. It's ugly, but shows that somehow Webpack's module resolution doesn't jive at all with PNMP's methodologies (at least I couldn't get it to jive). 🤷 Oh, and I tried a number of the hoist config options that PNPM works with to no avail. I appreciate that they were there and gave me some hope to make this one package work, but alas, it didn't. I also know this frontend framework package is working on a future major version of its CLI, which will dump Webpack for Vite and will then support PNPM. Yay! I can't wait. 😁 Scott |
I think this thread is more than one year old now. If the backward-compatible features aren't implemented it's worth to fork it and collaborate to establish one. In modern software development backward compatibility is a kill feature. If one don't get it, his project is doomed to fail. |
I suggested a solution here: #2255 (comment) We received no pull requests implementing it.
Don't be ridiculous. |
Btw, I got my problem solved by manually hoisting dependencies i.e. installing them myself. It makes my project's package.json mofugly, but I can continue my work. Scott |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I don't see any constructive feedback here, so I am locking this to contributors only. I have suggested a solution that will work #2255 (comment) Contributions are welcomed. |
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.
The text was updated successfully, but these errors were encountered: