News for hackers. Stuff that matters.
Re:Node.js 15.0 by crubier on Friday October 23, 2020 @09:52AM (#24869475)
Yarn v2 PnP is simply a lifesaver if you have a medium+ sized monorepo.

We have a monorepo with 180 packages here. Without pnp, it takes 1h+ just to npm install any new third party package in any local package, it’s a joke. With pnp it takes 18s.

So yes, from my point of view NPM is completely inadequate for any serious JS codebase.

Re:Node.js 15.0 by lhorie on Friday October 23, 2020 @12:09PM (#24870979)
We have a pretty large monorepo codebase (460 packages and counting) that we're migrating from yarn v1 to yarn v2. I'll say it's definitely not a plug-n-play migration (pardon the pun).

Some issues we ran into:

- it can be difficult to reason about the layout of peer dependencies. Often times libraries that rely on Symbols or referential equality break and you need to mess with packageExtensions or add resolutions or unplug. Debugging mostly consists of throwing stuff at a wall and see what sticks

- file watching at large enough projects breaks w/ file descriptor exhaustion errors, forcing you to find and unplug the offending libraries

- there's a number of known incompatible libraries (flow being one of the most prominent) and the core team approach to these at this point follows paretto (20% effort for 80% results, e.g. special casing for typescript), meaning I don't believe there will ever be a 100% compatibility milestone w/ the ecosystem

- it's much more black-boxy in terms of day-to-day debugging (e.g. it's much harder to manually edit files in node_modules to trace some root cause)

- we ran into inscrutable errors deep in packages that interface w/ C++ and basically were only able to fix by pinning to an earlier version of a library that did not depend on said package.

- migration cost is heavily proportional to codebase complexity. My understanding is that Facebook gave up on it completely for the foreseeable future and ours has similarly been a significant time investment (and we're not even targeting strict mode yet)

The pros:

- install times and project switching times are indeed fast, even in our codebase that contains multiple major versions of various packages

- yarn v2 has many interesting features, such as protocols (though it's debatable if you want to commit to lock-in to benefit from those)

Re:Node.js 15.0 by arcatek on Friday October 23, 2020 @02:02PM (#24872134)
Regarding TypeScript, I think it's important to point out that we have a working PR in the TypeScript repository that we've been maintaining for about a year now. It's not so much special casing as being ahead of trunk. I still hope the TypeScript team will show interest eventually and we'll be able to streamline the development.

[1] https://github.com/microsoft/TypeScript/pull/35206

Re:Node.js 15.0 by lhorie on Friday October 23, 2020 @02:30PM (#24872386)
I meant special casing in the sense that this a conscious effort specifically targeted at Typescript support, as opposed to some generic design that would cater to a large class of projects.

Mind you, I understand that there are legitimate reasons to approach it this way now (e.g. technical limitations, differences in opinion wrt project governance, cost/benefit on long tail, etc). I'm mostly cautioning the unaware that one shouldn't necessarily expect that every package will work under yarn v2 (though an overwhelmingly large majority does work just fine).

Re:Node.js 15.0 by acemarke on Friday October 23, 2020 @01:21PM (#24871751)
From what I've seen, the "unplug" command is supposed to allow you the ability to temporarily unzip a package so that you can do the traditional "hand-edit a file in a dependency" debugging approach.
Re:Node.js 15.0 by lhorie on Friday October 23, 2020 @02:26PM (#24872344)
Yes, but when you're dealing w/ transitive dependencies, often times you need to jump between many packages. And you then need to clean up after your debugging since you typically don't want to leave things unplugged if they don't need to be (as that affects performance).

I'm not saying it's impossible to debug, just that you end up having to jump through more hoops.

Re:Node.js 15.0 by acemarke on Friday October 23, 2020 @03:07PM (#24872740)
Well, you gotta clean up files you've hand-edited in `node_modules`, too, if you've been adding a bunch of `console.log` statements :)

at least this way it's just deleting the temp package folder or running whatever the "replug" command is, instead of having to go figure out all the files you were editing.

Re:Node.js 15.0 by lhorie on Friday October 23, 2020 @03:30PM (#24872939)
Eh, node_modules hacking is certainly not great by any stretch of the imagination, but once you work with it long enough, there's a bunch of stuff that you just get efficient at. Spamming undos in open files is fairly easy. If the editing ends up being a real fix, then you upstream it and install again. There's also considerations about jump-to-definition and similar tools, etc.

You can't accidentally commit your debugging (unplug edits package.json and there's no replug command) and you don't end up with 3 unplugged folders for the same package (that's a whole can of worms on its own). There's also some yarn 2 specific pitfalls regarding __dirname in local packages, symlinking semantics, etc.

Anyways, getting way too into the weeds here, I better stop now lol :)

Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @11:34AM (#24870560)
I tried yarn 2 on a greenfield project, but discovered:

- pnp is made possible in part by mysterious “patches” to certain dependencies that don’t work well with it. Mysterious as in they’re obfuscated, and there isn’t much detail besides commit history. This is blocking if you wanna try out, say, the TypeScript 4.1 beta and the patch isn’t ready yet. But more importantly um... I do not want my dependency manager mysteriously patching stuff with obfuscated code?????

- it applies these patches even if you disable pnp, so same objections to the entire yarn 2 approach (currently)

So I’m back on yarn 1 and apparently gonna need to look at npm 7 at this point.

Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @01:32PM (#24871838)
I wrote the above before caffeine really kicked in, so I neglected to add: pnp is itself achieved in part by obfuscating your entire dependency tree. That takes a loooot of trust, on a matter where trust has already exceedingly deteriorated. In hindsight, I regret even considering it.
Re:Node.js 15.0 by acemarke on Friday October 23, 2020 @01:46PM (#24871981)
Can you clarify what you mean by "obfuscating the dependency tree"?
Re:Node.js 15.0 by desert_boi on Friday October 23, 2020 @06:16PM (#24874873)
They probably mean the idea that once you're in PnP, you can "kind of, sort of" peer into zipfs deps, but not in the same way that was possible in bare node_modules.

That said, I think yarn 2's PnP + zero installs (https://yarnpkg.com/features/zero-installs) is lovely with CI. Instead of tacking 40+ seconds to resolve deps every build, vending deps with PnP on is much cheaper than the node_modules equivalent.

Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @06:36PM (#24875059)
A gigantic single file encoded version of `node_modules` is just modules I can’t go look in.
Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @06:46PM (#24875138)
(Not a real edit): my last gig was with a lot of well prepared juniors, but they lacked the confidence to go look inside dependencies to find out what was happening. I tried to encourage setting breakpoints or logging or whatever felt comfortable in required packages. It was hard.

Turning that into a blob is even more discouraging.

Re:Node.js 15.0 by acemarke on Friday October 23, 2020 @06:44PM (#24875122)
As I mentioned elsewhere in the thread, Yarn v2 does have an "unplug" command that will extract a given dep into a folder for the time being. Does help with that use case.
Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @09:30PM (#24876161)
And if you trust that they’re fundamentally the same thing, that’s a great escape hatch. I personally tried to use two new things together and discovered that one is transparent and one is opaque magic... and given the opportunity to do harm, I found the opacity of one alarming. I don’t trust yarn to manage dependencies in pnp, because what I saw in how they handled a special case was completely black box. Literally binary blob patches with no explanation of what it’s doing or why. Completely impossible to audit without reverse engineering or auditing the entire tool. Why would I trust “unplug” to do anything but misdirect?
Re:Node.js 15.0 by acemarke on Friday October 23, 2020 @09:43PM (#24876219)
What "binary blob patches" are you referring to?

FWIW, if I wanted to confirm whether an "unplugged" package had been modified, I'd just download the original tarball from NPM, extract it, and diff the two folders.

Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @11:55PM (#24876820)
I mean the way that yarn 2 “installs” typescript is by patching it with some manually maintained base64 blob that (I assume) corresponds in some way to the base64 blob that pnp produces. Both are probably something you can reverse engineer... if that’s how you want to trust your package manager I guess? Idk I only learned that the patching was a thing because it failed when I tried to install an “unsupported” package. I was alarmed by trying to track down what was happening and saw the patch has no explanation. I was more alarmed when yarn2 tried to apply the patch even with pnp disabled.
Re:Node.js 15.0 by acemarke on Saturday October 24, 2020 @12:14AM (#24876886)
Hmm. Okay, digging around in the Yarn repo, I see this "generate patch" setup code [0]. Looks like they're trying to cherry-pick some specific commits from the TS repo based on the TS version, and specifically apply them to the TS file.

The "base64" bit is referenced here [1].

I would assume this specifically relates to the fact that TS does not have native support for Yarn PnP as a filesystem approach. The Yarn team has been keeping an open PR against TS [2] and trying to convince the TS maintainers to merge it, but it hasn't happened yet.

A bit odd, and I can understand why you're concerned, but it also looks like there's a very understandable reason for this.

I would have assumed that this doesn't get applied if you install TypeScript via the Yarn v2 `node_modules` linker, but would have to try it out and actually see.

[0] https://github.com/yarnpkg/berry/blob/f384f0f40e87d636e4021b...

[1] https://github.com/yarnpkg/berry/blob/f384f0f40e87d636e4021b...

[2] https://github.com/microsoft/TypeScript/pull/35206

Re:Node.js 15.0 by arcatek on Saturday October 24, 2020 @03:43AM (#24877622)
This blob is literally our open PR, applied to the various TS releases. You can rebuild it using `gen-typescript-patch.sh` (we actually have a GH Action that does this on CI, to prevent malicious uncontrolled changes), and the sources are auditable in my PR.

Note that it gets applied regardless of the linker since it would cause the cache to change when going from a linker to another, and we wanted to make the experience smoother, but that it's a noop for non-PnP environments.

Re:Node.js 15.0 by eyelidlessness on Saturday October 24, 2020 @11:38AM (#24879836)
It definitely applies the patch even with the node_modules linker. That was why I gave up and went back to yarn 1
Re:Node.js 15.0 by chrisweekly on Friday October 23, 2020 @05:55PM (#24874685)
Sorry if this makes it harder but I honestly recommend reading up on pnpm (https://pnpm.js.org/) before committing to npm7. Npm7 auto-installs peer dependencies(!) and pnpm has some remarkable advantages over npm or yarn.
Re:Node.js 15.0 by crubier on Friday October 23, 2020 @06:17PM (#24874878)
Pnpm is indeed better than npm but I found it’s symlinking approach less compatible than yarn v2, (nextJS for example didn’t support pnpm until very recently) while also having less deterministic module resolution, creating version compatibility problems that disappeared with yarn v2.
Re:Node.js 15.0 by eyelidlessness on Friday October 23, 2020 @06:40PM (#24875089)
I had already been meaning to look at it but had written it off because I wanted what yarn 2 was selling... but definitely gonna give it another look.
Re:Node.js 15.0 by vosper on Friday October 23, 2020 @12:56PM (#24871469)
Did you try out pnpm, by chance? I’ve read a few good things, but it doesn’t seem to get mentioned all that often. So I’m curious what people with larger projects think about it.

https://pnpm.js.org/

Re:Node.js 15.0 by andrew_ on Friday October 23, 2020 @02:58PM (#24872655)
I use it in some rather large repos and am a very big fan. It's simply fantastic for every type of repo and project I've thrown it into.
Re:Node.js 15.0 by crubier on Friday October 23, 2020 @06:20PM (#24874913)
I did try it but it caused two problems as compared to yarn v2: the dependency resolution algorithm seems less deterministic or strict, causing version incompatibilities that yarn v2 did solve, and also the symlinks are poorly supported by many tools (nextJS until very recently, react native etc...). Also the install is longer with pnpm. However it has less runtime performance impact.
Re:Node.js 15.0 by georgyo on Friday October 23, 2020 @10:07AM (#24869630)
Cannot figure out why you are being down voted. YarnV1 and NPM are horrible if you have a large dependency tree. YarnV2 was the first time I enjoyed the package manager.
Re:Node.js 15.0 by 411111111111111 on Friday October 23, 2020 @11:39AM (#24870643)
Likely because he indirectly said that projects using less then 180 dependencies aren't serious.
Re:Node.js 15.0 by romanoderoma on Friday October 23, 2020 @01:07PM (#24871595)
could it be that in some languages (like my language for example) serious is kinda of a synonym for large?

I've been downvoted at times for using it to mean exactly that, but I can't help it after more than 40 years of thinking in a language different from English.

Re:Node.js 15.0 by crubier on Friday October 23, 2020 @06:24PM (#24874950)
By serious I meant large indeed, I’m not a native speaker. I have some serious projects that have less than 180 packages too aha.

But if you start an ambitious company with a JS codebase today, start with yarn v2, you’ll save yourself some pain in the future.

Re:Node.js 15.0 by untog on Friday October 23, 2020 @11:34AM (#24870561)
I'd push back against "serious JS codebase", there.

Maybe it's just me but a monorepo with 180 packages sounds like a hole you've dug yourself into and you're propping yourself up with yarn.

I certainly don't think that anyone who keeps their packages separate (you could do that even within a monorepo, surely) has a "non-serious" codebase.

Re:Node.js 15.0 by crubier on Friday October 23, 2020 @06:10PM (#24874826)
Well yarn exists for this purpose so I guess I’m not the only one doing this. And if the alternative involves having to manage independent versioning of 180 packages and their inter-dependencies then no thanks.

I’m not saying the situation is completely perfect (yarn v2 had its rough edges in the beginning for example), but it’s not too bad either. This monorepo is the best organized codebase of this size and diversity I’ve ever seen.

Feel free to explain alternative methods to manage 180 packages with 7 developers while sleeping at night.

Re:Node.js 15.0 by cute_boi on Friday October 23, 2020 @11:08AM (#24870264)
I don't know why you are down voted but I agree here. PNP is so good it takes less time less storage. Yarn v2 is very superior than yarn v1/npm
Re:Node.js 15.0 by madjam002 on Friday October 23, 2020 @12:37PM (#24871278)
Yarn 2 is very nice. The portal: protocol is great and it works well with Nix package manager.
Re:Node.js 15.0 by croes on Friday October 23, 2020 @11:48AM (#24870746)
Some would say the same about NodeJS especially since Deno exists.
Re:Node.js 15.0 by benologist on Friday October 23, 2020 @11:05AM (#24870231)
This NPM cache been a huge time-saver for me, you can run it locally or across your whole network for a shared cache -

https://guides.sonatype.com/repo3/quick-start-guides/proxyin...

https://hub.docker.com/r/sonatype/nexus/