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
Monorepo support #533
Comments
yes, but probably not for a little while |
Related: The |
can the implementation of workspaces include:
|
I just want to say that I haven't missed |
@factoidforrest yarn has |
Maybe consider monorepo support similar to |
I prefer pnpm |
|
He probably meant to pnpm workspaces. |
Yarn 2+ Plug n Play also has full scope isolation for each package. A main reason the pnpm resolution strategy might be preferable to Plug n Play is because notable projects such as React Native are currently incompatible with Plug n Play. On the flip side, Plug n Play might be considered preferable because it may solve the doppleganger problem differently than pnpm (someone ought to investigate this comparison in detail). Personally I find the "non-single singletons" doppleganger consequence the most important one because it's the root cause behind monorepo bugs involving popular libraries such as graphql-js. Overall though I think Bun should make an authoritative choice for workspaces/monorepo support rather than letting this be highly configurable. Too much configurability leads to too much project complexity both in implementation and from a client's point of view w/ too many options to choose from & too much boilerplate. Bun needs to have a clear story for workspace/monorepos before it can be seriously considered for adoption by medium to large projects. |
Agree. IMO The point I want to make by bring yo For example: |
turborepo is greate. |
It does not. |
Hi, IMHO the only responsibility from Bun regarding workspaces is dependency resolution, the rest should be handled by a monorepo tool like Turbo or NX. |
Is Related to previous comments: #533 (comment), #533 (comment) |
Per #83 it looks like some support for |
Probably, related: #2517 |
Speed and disk space are the reasons pnpm is best for monorepos. Whenever multiple workspaces within a monorepo depend on the same npm package, npm and yarn download and install a separate copy of the npm package for each workspace, whereas pnpm symbolically links them all to the same download of the package. Yarn's PnP does muddy the waters a bit, but its problems keep me from using it. See the benchmarks. |
For yarn, it's configurable: https://yarnpkg.com/configuration/yarnrc#nmMode |
Will migrate to bun when this works |
I am not sure now, it isn't supported and described here? https://bun.sh/docs/install/workspaces Do I miss something or can this issue be closed as completed? EDIT: I see it miss support for script execution inside monorepo, ex. |
@Hebilicious Thank you very much for the excellent overview! I am still of the opinion that documented basic use cases should work. So, the binary answer to this issue is "yes, a monorepo is supported". I am not opposed to leaving this issue open, but, in my opinion, it distracts from addressing actual problems. Alternatively, @wbcs could add your list to the top of this issue, making it a meta-issue for outstanding work. |
I feel it's relevant to share this tweet that I saw from Jarred a couple of months ago. He mentioned wanting to have another go at implementing workspaces as he didn't think the support was that good, although I'm not sure if they ever got around to redoing it. |
Additionally plugging this issue: #4844 |
It's hard to argue that bun has monorepo support in terms of a drop in replacement for pnpm. Replacing pnpm works for the most part, but as soon as you come to monorepos (which is very common in OSS and other projects these days), you have to redesign your whole CI/CD pipelines or have challenges that can be very hard to solve. |
@itpropro I think (1) "doesn't fail when used in a monorepo", (2) "supports monorepos", and (3) "includes tools that make working with monorepos easy" are all valid but very different definitions of "monorepo support". Bun currently meets the criteria for (1), sort of meets the criteria for (2), but definitely does not meet the criteria for (3). As evidenced by @Hebilicious's list (#533 (comment)) and other comments here, there's a lot of work to do before that last criteria is met. Documentation should probably reflect that. |
Criteria 1 is not met yet, Bun 1.0 still fails for me when adding packages as described in #3502. |
@Bessonov You can see project structure there: I want to type bun install or whatever other command in the root of my project, which will install all my local packages inside /packages folder. As the result, all my dependencies are in the root package.json and I can use dependecies from packages by typing ONLY one command |
I haven't used Yarn for many years, but what you probably mean is that you specify all your dependencies in the root package.json instead of specifying them in the place where they are really used. More reliable dependency managers, such as PNPM, disallow this. I would suggest that you consider stopping this bad practice. What specific issue are you trying to address by doing this? Perhaps you are trying to keep versions in sync? |
While I agree each package's dependencies should be independent, there are times that hoisting of Here are some specific guidelines I can think of:
by the way, As for myself, I also try to avoid hoisting as much as possible. But I do encounter cases in my company around |
pnpm will soon have a feature to keep dependencies in sync across multiple packages in a monorepo (and more) pnpm/rfcs#1. A lot of thought and discussion has gone into the design and I think it's really solid so maybe something for bun to emulate. As far as package management in bun goes, I think emulating pnpm in general would be a good choice. The patterns used by pnpm (content addressable store, "safe" no hoisting node_modules, etc) is overall safer, more correct, and eliminates a lot of problems common to yarn and npm. IMO keeping the old hoisted/flattened node_modules pattern around would be a step back when pnpm offers thoroughly proven solutions that could be emulated. |
@unional ...
"devDependencies": {
"typescript": "4.7.2"
},
... cd root/packages/mymodule
bun run tsc -v
Version 4.7.2 Even worse, @evelant I agree that |
Yeah, don't get me wrong,
Um, that doesn't look right. |
A obvious one for me is that |
Bun, please do NOT consider to emulate If Bun starts to emulate |
I always use conflict-free versions. I probably still don't fully understand the issue with hoisting, but never mind. (EDIT: of course, I am aware of the react@16 and react@18 conflict. I mean the issue that bun should allow hoisting above). Not really a |
I would disagree. Not saying The doppelganers issue from |
It’s much easier to develop an identical to
Any complication brings more bugs to the already unstable |
That's all fun and cool but I and other people with similar projects structure just will not use bun. No one is going to rewrite project to adapt package manager |
hehe, yeah someone would have to be out of their mind to do that... haha... hehe... quietly makes repository private |
|
What I mean with independent is if you for example have two packages IMO this is pure madness and should not be possible at all. Only if the root But hoisting limits are not enough because it is very often the case that multiple packages use the same dependencies with the exact same version. To prevent data duplication and multiple downloads you can use links (soft- or hardlinks) to either the root The main difference between softlink (symbolic links) and hardlinks resides in the fact that hardlinks point to an actual address on your hardrive while softlinks point to a file path. In other words: if you zip a hardlinked file it will actually zip the file contents, but if you zip a softlinked file it will just zip the path to a file, which is (if you didn't also zip it) not part of the resulting zip file. Now if you unzip that file on another machine (or other location) your softlink is most likely invalid. This is why I previously said:
But you may ask why?
I hope this answers your question. |
This isn't the case with
Well, we are in the same boot 👍 It wasn't clear to my what do you exactly mean by hoisting, because i have different understanding of that.
pnpm uses symlinks, like shown above. Bun uses hardlinks.
hardlinks don't work across mounts. |
A concrete example is that And on the same subject, auto install does not work with mono repo, because |
I wanted to switch to bun. I was really excited about it. I was able to remove a ton of dependencies from the packages in my monorepo. It really cleaned things up... UNTIL I learned that every Hoisting is a mistake in monorepo management, it sounds good in principle but node's module resolution algorithm makes it unsafe. I am sad to see that most of the commentary from people trying to use Bun in a monorepo configuration is from September 2023. That means it's been almost six months with no roadmap for developing a more robust solution in bun. I'll subscribe to this thread and others but ATM I'm going to have to switch back to PNPM. |
Some progress has been made since the last time I updated the list here : #533 (comment) I'm personally using a mix of pnpm and bun : pnpm to install deps and bun to basically replace tsx, zx, and node. I'm also using bun itself quite a lot, things like Bun.serve, bun --hot, bun test etc ... It's great! However as a package manager it doesn't compete with pnpm now, proper mono-repo support will definitely increase usage, but some important features like patch are still needed. |
@Hebilicious thanks for the follow up. A hybrid approach is interesting and could work. It just seems that it might be hard to evangelize across a development team. An errant |
Currently I have to use
would be nice to see someone given a mandate to go implement this. |
I'm a bit new to the front end world but is this what y'all are talking about? |
Found I can use bun workspaces, but when i build a package i have to execute the build with node, because bun is hoisting all dependencies to root level node_modules, and only node will be able to find those from a /packages/package1/build/app.js by properly checking parent directories in module resolution. Bun seem to only check inside the package which is not where bun install puts the node_module. |
@81reap as I mentioned in my comment and as is mentioned in those workspaces docs, Bun does hoisting but that is an inadequate way to support monorepos because it permits/encourages the phantom dependencies bug class. |
With pnpm I sometimes have to set i.e. shamefully-hoist=true in the .npmrc, but that taps into another highly upvoted issue |
What is the problem this feature will solve?
bun not support monorepo(root package.json
workspaces
field,workspace:*
schema, etc.)What is the feature you are proposing to solve the problem?
The download speed of monorepo will be faster
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: