271 points · by pajoda · 9y ago · 114 comments
Couple questions:
Question 1: Does anyone else who's been around more than a couple years share my view that Yarn : NPM :: IO.JS : Node?
IOW: healthy competition, catalyst for necessary change, ultimately a bridge or stopgap.
Question 2: Any good comprehensive writeups on best practices?Committing lockfiles is a no-brainer. But what about globals? Per-node-version seems logical, but there are also semantic problems with "global" packages vs concept of executable binaries. I'd love to see a strong writeup outlining and defending a standard approach.
1. Node.js was abandoned and replaced with io.js.
2. Io.js was relabelled as node.js.
3. The node.js project was put under open governance via the creation of the Node Foundation.
This doesn't really compare to npm:
* The npm-cli's name is using npm Inc's trademark: giving it away would leave the company with no name or create unwanted ambiguity between npm Inc the company and npm-cli the (then) community-owned open source project unaffiliated with the company.
* Yarn does not share any source code directly with npm-cli, it's a complete reimplementation of a similar feature set. It's currently backed by a mirror of the npm registry but that's the extent of the overlap.
* The Node Foundation already exists and Yarn is already owned by the community. I could see Yarn joining the Node Foundation and the Node Foundation replacing its bundled dependency on the commercially owned npm-cli but even then npm Inc has nothing to contribute to the process.
Personally I would much rather see Yarn join the JavaScript Foundation because it speaks to the broader appeal of Yarn outside the traditional "Node community" and the politics involved in the latter and its close ties to npm Inc.
FWIW I consider the close ties between the Node project and npm Inc nothing more than a historical accident that has resulted in a conflict of interest that is overdue to be resolved by dropping npm-cli from the official releases.
Now that yarn is no longer distributed using npm (although it's still possible to install it that way) that seems more realistic than ever.
But that would break 7 years of documentation and tutorials, likely bad for newcomers and thus the ecosystem
Answer 2: I don't use global packages often. For binaries I generally add a "scripts" entry to package.json for common tasks, which automatically adds "./node_modules/.bin" to the PATH. For one-off tasks I just run "./node_modules/.bin/executable"
Same team, performing a big refactoring and significant improvement and modernization of some bits that were outdated and difficult to improve without a controlled demolition and rebuild.
The analogy breaks down, of course, because the governance didn't change, the project's relationship to its corporate backer wasn't standing in the way of progress, etc. (Except, I guess, that it might have gone faster if we'd had more money to hire more devs? But some of this was just a slog through a very old codebase with a lot of scar tissue, and it's hard to speed that up by putting more hands on it.)
Everything in npm 5 was literally planned years in advance. When we have this many people depending on a thing, we have to be careful about how we make drastic changes. Yarn was a strong signal from the community that we were on the right track, but it only seems like a "catalyst" when seen from the outside. Correlation is not causation, even when it lands first.
I agree... I like the theoretical concept that our dependencies, could be automatically managed/upgraded behind the scenes via a declarative versioning system, like semver. That, in my view, was the paradigm behind not having defaulted to dependency graph snapshot (lock/shrinkwrap) by default. In practice, people don't follow semver correctly and autoupdating patch+minor versions can cause you a lot of pain. It would be cool to make versioning more tied to actual API signature, so that changes to the signature could not actually be published as minor/patch changes... but would be forced to use a major version bump in publish. I don't know how this would work particularly in a language like javacscript w/out a typed interface... but I'm just theorizing...
However, npm could certainly compete with more of yarn's features (fast local cache[0], shorter syntax for running scripts like `npm start`, etc)
[0] turns out they did that: https://twitter.com/maybekatz/status/865393382260056064 wow!
What a time those days were, feels like a million years ago already.
https://docs.npmjs.com/cli/shrinkwrap provides deterministic builds and has been around far longer than yarn. Since Oct 2014 npm v3 started automatically updating shrinkwrap whenever '--save' was used. See https://github.com/npm/npm/pull/4918#issuecomment-61344871
Calling npm 'the naked emperor' for not implementing something it did, infact, implement is uncalled for.
Edit: added links in response to unexplained downmods. The parent is simply, provably wrong.
1. Dependency install was taking too long.
2. Inconsistent builds between devs because of no lock file.
3. Could not search the registry from the command line in a timely manner.
Having just done a quick test on a random project, I'm pleased to see that all of those concerns are now taken care of, plus the install (for this project at least) is ~30% faster than it is with yarn.The new lockfile is basically shrinkwrap 2.0 using what's been learned since
On cold cache: Yarn: 20.94 seconds NPM5: 21.11 seconds
With cache: Yarn: 10.35 seconds NPM5: 15.20 seconds
For some reason, when node_modules folder is still there, yarn exits in a couple hundres milliseconds but npm5 does something for around 5 seconds.
Haven't checked lock file / installation consistency stuff. Yarn has been great on that too so we have no intention to go back but this is a decent release.
* yarn: 25s
* npm@5: 28s
* npm@4: 63s
* npm@3: 68s
So performance is now comparable, which is awesome, but I'd still stick to yarn because we have been burned too many times by npm v2/v3 with call stack issues and other errors. I don't have the energy (or the time/faith) to go through that again.Competition is wonderful though. I'll check npm again in 6-12 months and see what the community thinks of it before switching again.
npm@5 28.274s vs 11.60s Yarn
@Windows10, SSD, warn cache
Like wtf, who thought that saving something you download maybe for the first time as a dependency is a good idea?
If you want to try something install it and then remove it. That's the more conscious decision. I don't want to have to remember to save the module if I end up liking it, but I will remember to remove it when tearing it down from the codebase, and if I don't, nothing bad happens.
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm i -g npm-windows-upgrade
npm-windows-upgrade --npm-version latest
Surely it would be much better to follow standard lock file naming conventions and name the file package.lock
Rather than just talk here, I've posted against the issue suggesting this approach basically asking for up/down votes. https://github.com/npm/npm/pull/16441#issuecomment-304458746
I want to be able to search by tag, constrained by license and with packages that use dependencies I already have installed floated to the top. There are so many ways this could be nicer.
My experience a couple months ago was that almost anything slightly off the path of the most basic use case rapidly entered "here be dragons" territory, such that every problem became "are we doing something wrong, or is yarn broken again?", which wasn't worth any benefits it provided. If you're just installing packages from NPM, and those packages don't do anything even slightly weird, it's probably fine.
[EDIT] a running theme of the issues is that a lot of correctness-checking and edge-case handling is missing or incomplete, in addition to some "strange" npm features not being supported. Anyway, here are a couple examples of what I'm talking about:
https://github.com/yarnpkg/yarn/issues/3433
https://github.com/yarnpkg/yarn/issues/3507
https://github.com/yarnpkg/yarn/issues/2090
(last one has a lovely "why are you doing this?" as its first response, from the repo owner for bonus LULZ)
FAR from the only ones. IIRC one of our issues had something to do with Yarn totally rewriting the package.json of a package installed from a local directory, removing the "main" entry entirely, which broke it (obviously). Maybe it'll be something I use later, but right now I don't really want to have to wonder whether any given problem is due to some obscure breakage in my package manager when I can... just use npm and not worry about it.
- native packages are not well-supported by yarn yet, notably node-sass since it's so widely-used
- no private module support
npm install npm@latest -g
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/lib
└── npm@4.6.1
How do I install it? Or... it's not quite released yet after all?Edit: nevermind, I found it --> https://github.com/npm/npm/releases this is the 'prerelease' release.
npm install -g npm@5
Then see: npm -g ls npm
Which returns: +-- npm@5.0.0 npm install npm@next -g
works :)Generally speaking the main tool is slow, or otherwise suboptimal but does a lot. A different tool is built with an emphasis on speed. Eventually, the main stream tools picks up the speed features of the other tool and then "wins" because it does more. (Side note: I have no idea when Gradle came out in comparison to Buck/Bazel) For context, Gradle in the 4.0 version is starting to really support build cache support.
Edit: this comment is a reaction to all the other comments I see here about yarn vs npm.
The different shows how much better npm@5 is :)
It installs two node.js projects (react & ghost) and shows how long it takes to do under multiple scenarios (cold cache, installed and lockfile). It is automatically run each day. It also creates an average if one version is run multiple times.
Definitely will give this a try once it is moved out from pre-release.
>since npm@3, npm will automatically update npm-shrinkwrap.json when you save
All installs update shrinkwrap then? doesn't that start to make it redundant to package.json in the first place now. Does this make git tracking package and shrinkwrap mandatory in-case you want to install, test but then roll back the version, as shrinkwrap will already have changed.
edit: Oh I'm supposed to --no-save now for that described flow?
It's great at what it does, and great for the simple case, but it's only a subset of functionality.
- NPM comes pre-installed with Node.
Is it finally save to install 2 times and get 100% the same packages?
Even the shrinkwrap file itself contained a lot of trash and generated massive diff noise. I had a file full of scripts to make the shrinkwrap file usable and even then we had (production!!!) issues due to changing subdeps. We reworked our build processes to zip & deploy the exact code that passed the tests to work around that, but it was still a massive pain that installs at different points in time would yield different trees.
When yarn came out, I deleted a folder full of hacky scripts, cut my install time by 60% and finally got deterministic installs. Needless to say, I was ecstatic.
Aside from that, what is the use case that flat installs solve?
Nice.
Finally! :-)
Bundler led to yarn. The JS community should start looking what other ecosystems do and have done (right and wrong).
Such a waste of time these past 20 years and it happens over and over.