r/javascript • u/enkideridu • May 26 '17
NPM v5.0.0 released, --save by default, lockfile, better support for git dependencies, better support for monorepos, and more!
http://blog.npmjs.org/post/161081169345/v50069
u/greymalik May 26 '17
Can I stop using yarn now, or does it still have some advantages? And are there any efforts underway for an npm/yarn merge ala node/io.js, or are we going to keep jumping back and forth as each one-ups the other in a feature war?
33
May 26 '17
I'm wondering this myself. We switched to Yarn because it was insanely faster and the lock file feature. Npm5 now appears to be faster than Yarn and has a lock file... They should just kill Yarn.
57
u/vexii May 26 '17
i think we are seeing these features because yarn have show it's good/what people want (at least on an opt in basis). let yarn be the "playground" for experimental features/ideas, like coffee/typescript influenced es6
3
u/maybekatz May 27 '17
it's a bit of both, tbh: it's almost all stuff we planned, but having someone else show that it was actually a good decision and people were happy about it made it much easier to go ahead, instead of taking more careful steps. There's only so much cheese-moving we can risk doing without breaking a great number of people who rely on exactly the way npm does things. :) I, for one, think it's great to have an unstable playground that can afford to ruin people's day (and we've been talking about having a "canary" npm where we can try new ideas on responsive users)
14
u/dmitri14_gmail_com May 26 '17
Is it anywhere documented to be faster than yarn?
18
u/OverBelief May 26 '17 edited May 30 '17
I can't find any "official documentation", but over on HackerNews there have been some users who have ran their own code with Yarn && versions of NPM.
This user had these results
Also ran some numbers here (with warm cache. node 6.10.3).
yarn: 25s .
npm@5: 28s .
npm@4: 63s .
npm@3: 68s .
Another user had these results
On cold cache: Yarn: 20.94 seconds NPM5: 21.11 seconds
With cache: Yarn: 10.35 seconds NPM5: 15.20 secondsSo, in general, it seems the speeds are very close but that Yarn is still a tiny bit faster.
0
May 26 '17
[deleted]
16
u/dankelleher May 26 '17
With those small differences between yarn and npm5 we don't, really (although those split seconds will add up in e.g. a CI environment). But the difference between npm4 and yarn was huge.
3
u/honigbadger May 27 '17
Because, when using something "a little" less powerful that your average MacBook Pro (like a docker container) the algorithm used to resolve dependencies for packages makes big difference in build times. Sometimes you're using containers on a dev env, sometimes on staging and sometimes even on prod, that's just one case where speed matters... But in general we should not be thinking about "few seconds more or less on powerful hardware" instead we should be aiming to build on top of solutions that work fast in almost any hardware used out there. Not everyone is developing on i7's with 16GB of RAM and the lower you go on the specs scale, the more precious the seconds you're getting off one tool or another
3
May 27 '17
While that is true, the difference in build times was still not that huge. NPM install is not the longest thing that happens when i build or test. And i'd rather focus on my live reloading stuff instead. I can understand the need for it being faster, but i've never really thought "oh boy that NPM installation sure takes up a lot of my day".
3
u/learn_to_model May 27 '17
As someone who unfortunately has to fiddle with different CI configs and legacy deployment setups at work, I kindly disagree. We're currently moving everything over to docker and during our first experiments we obviously needed to get familiar with it and rebuild our containers constantly. yarn was a huge timesaver for that. With npm it would've taken ages to test
2
u/kenman May 27 '17
I work with a couple of megarepos (really complex projects), and when I still had my macbook air, a fresh install would take anywhere from 30-45 mins, with at least 90% of that time being consumed by
npm i. With Yarn, that time went down considerably, to around 15 mins, and when using Yarn's cache, that went down to under 5 mins.Due to having to support multiple versions of those projects, it wasn't uncommon to
git clean -xfd && git checkout release/some-other-version && npm iseveral times a day. Yarn literally gave me several hours a week back that I otherwise would have wasted waiting on NPM. That's huge.1
u/kylemh Jun 09 '17
Depending on how large the project is the speedier dependency download saved minutes sometimes. Before npm v5, it was also better because of lockfiles.
The real question is, what has npm v5 done to encourage a switch back from yarn? Now, they offer the same thing except yarn is just a tiny bit faster.
2
u/subvertallchris May 26 '17 edited May 26 '17
And even if it is, is yarn so slow and the improvement so profound that it's worth migrating? I doubt it.
4
u/Akkuma May 26 '17
Yes the improvements to npm 5 are profound. You can now use semver for git dependencies, while yarn still seems to be buggier on projects I've used it on.
1
u/subvertallchris May 27 '17
That is a nice improvement. I stand corrected, I guess?
But really, I don't understand all the yarn hate. It's worked perfectly for me since I switched to it and with every project since then. It feels like a slicker Bundler (Ruby).
3
May 26 '17
I used yarn on a recent project that I forked from GitHub that wouldn't work until I just went ahead and did an 'npm install'. Anyone else had this problem?
0
0
May 26 '17
[deleted]
2
u/BritainRitten May 27 '17
The command is just 'yarn' to install all dependencies listed in package.json
0
May 27 '17
[deleted]
1
May 27 '17
I know it should be equivalent but it didn't work for me and npm install did.
1
u/chesterjosiah Staff Software Engineer / 18 yoe May 27 '17
Me too boss, I'm agreeing with you.
→ More replies (0)1
May 27 '17
Regardless of the downvotes you're getting, i am willing to wait an extra 20 seconds on initial build if it works. How often are you doing that? With npm V5 improving load time, why not?
1
u/patrickfatrick May 29 '17
The one thing Yarn still has that is killer is
yarn upgrade-interactive.0
u/Akkuma May 26 '17
https://github.com/JamieMason/npm-cache-benchmark
Yarn really has very little reason to exist now. The only one that has a reason to exist as well is pnpm due to it having additional goals of reducing memory consumption on disk.
5
u/vinnl May 26 '17
Doesn't really look like it, although there's no word about parallel installations which I seem to recall was the main reason Yarn was fast? It's a shame that there's no mention of Yarn here. Let's wait and see what the Yarn maintainers will have to say about this.
12
u/blood_bender May 26 '17
Uh, excuse me, but npm doesn't have
npm create.Dealbreaker.
10
u/redonkulus May 26 '17
Sarcasm?
17
u/blood_bender May 26 '17
Lol very poorly received sarcasm, apparently.
I can't believe they put resources into
yarn create. So ridiculous.4
u/redonkulus May 26 '17
Ya I agree. Seems like a weird feature to add.
7
May 27 '17
Yarn is from Facebook. React is from Facebook. Create React App is from Facebook. Facebook devs probably create 10 new React apps per day to test some prototype or feature.
Are you still surprised?
2
-1
29
u/the-prophet-harambe May 26 '17
to install: npm install npm@5 -g
6
May 26 '17
Thank you! I tried npm@latest and got nowhere.
8
u/TheDarkIn1978 May 26 '17
Yup, as revealed in
npm view npm, theirlatestis currently still set to4.6.1andnextis currently set to5.0.0{ latest: '4.6.1', next: '5.0.0', 'latest-2': '2.15.12', 'next-2': '2.15.12', 'latest-1': '1.4.29', lts: '2.15.11', 'latest-3': '3.10.10', 'next-3': '3.10.10', 'latest-4': '4.6.1', 'next-4': '4.6.1' },Alternatively, you can always check what's available with
npm view npm version -json. The JSON flag forces the complete print out of every version instead of truncating the list with ellipsis. So it will show this:... "4.5.0", "4.6.0", "4.6.1", "5.0.0" ]instead of this:
... '2.1.10', '2.1.11', '2.1.12', ... 160 more items ]
24
u/TheDarkIn1978 May 26 '17
npm will now scold you if you capitalize its name. seriously it will fight you
defiant fist in the air
You'll never stop me from calling it "NPM" on my resume, NNNNNNNNNNEEEEEEEEEEEEVVVVVVVVVVVVEEEEEEEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRR!!!
11
9
3
1
1
May 30 '17
"NPM" on my resume
Why even put it there?
1
u/TheDarkIn1978 May 30 '17 edited May 30 '17
I have a "Skills" section on my CV that contains 2 lists under the subheadings "Developer Tools / IDEs" and "Languages / Libraries". There's ~40 items listed, but it takes up less than 25% of my one page resume. I think it's important to list an overview of my professional skillset on my resume so potential employers have an idea of what to expect before reviewing my accompanying online portfolio.
1
u/hackel May 26 '17
How would that even work? Renaming the binary or symlinking? That's bizarre.
Edit: I tried symlinking it to NPM and it worked just fine. No idea what they're talking about, unless it was just a joke.
3
u/arstechnophile May 26 '17
I think it was a joke. Invoking it as "NPM" on Windows (which is case-insensitive) results in normal behavior.
3
3
3
u/Arsketeer_ May 29 '17
Yarn is the future. I'm sticking with it. npm has shown time and again that they are incapable of making good technical decisions unless the decisions are made for them.
It's truly dumbfounding how the makers of a tool that's the foundation of an entire ecosystem can't understand the importance of basic lockfile features or remotely fast install times, to the point where someone has to go out and write a competing product to make a point. Let's not forget how long it took to get rid of the infinite dependency trees in npm2 as well. Oh, and how npmjs.org somehow allowed users to withhold packages, which led to the left-pad incident. How on earth does that even happen? Allowing a package to get pulled from the repo when thousands of other packages depend on it, including giants like Babel?
And it's not like yarn is that hard to switch to. JS fatigue doesn't even apply; they're both package managers and accomplish the same thing with very similar commands and processes, same as all other package managers. Yarn is simply objectively better in every way, aside from npm coming built-in.
3
u/papers_ May 26 '17 edited May 26 '17
Yarn is still beating npm on my project by 10s. Looks like I'll be sitcking with it for a while longer. Will definitely use v5 on CI though.
1
u/tobegiannis Jun 02 '17
Probably not a good idea, stick with one or the other and get deterministic installs/builds.
1
u/markzzy May 26 '17 edited May 26 '17
I'm sorry but I find it extremely hilarious that this version adds most if not all the features yarn touts. I never understood why the yarn team didnt just submit there features directly to the npm codebase. Oh well.
26
u/Geldan May 26 '17
They talk about that here: https://code.facebook.com/posts/1840075619545360.
tl;dr, they tried to get npm to behave, but it was a nightmare.
Also, they probably just didn't want to deal with npm who are known for letting politics dictate engineering direction more often then they should.
4
u/markzzy May 27 '17
Not sure why you're getting downvoted. You've provided a helpful link. But thanks for that. Upvote for you!
3
u/vinnl May 27 '17
tl;dr, they tried to get npm to behave, but it was a nightmare.
But the way they did that was by using existing npm features, not modifying npm's code and submitting pull requests. It is a somewhat valid question to ask why they didn't attempt that, I think.
1
u/Geldan May 27 '17
The changes they would have had to make couldn't be classified as "modifying." It would have basically been a complete rewrite. If you have to do all that work anyway why would you choose to deal with the pull request process and thus submitting yourself to the will of other people who clearly didn't share your vision?
1
u/vinnl May 27 '17
So is npm@5 basically a complete rewrite as well? And how did they know they "clearly" didn't share the vision even though npm has now implemented the most important features?
Note that I'm not saying there are no good reasons, just that it's striking that there's no mention of them trying it in the announcement post, which leads me to wonder whether it was even considered.
5
u/maybekatz May 27 '17
npm5 is a rewrite of a fairly core component of npm: the entire package downloading and caching infrastructure. Everything else stayed mostly the same -- the other big chunk that was changed was the way the installer interacts with package-lock.json (nÊe npm-shrinkwrap.json), in order to take advantage of it having sha512sums, and short-circuiting a bunch of early-phase work we'd otherwise need to do.
The rest of the CLI code is mostly the same -- we did some refactoring to use promises in more places, some fixes to make the new changes uhhh... work at all, but nothing earth-shattering.
The entire download and caching infrastructure now exists in standalone packages now: https://npm.im/pacote (literally can do
pacote.extract('somepkg@^3', './here')), https://npm.im/cacache (the new cache!), and https://npm.im/make-fetch-happen (the new http client!). Plus a few others. node-tar was upgraded as part of all this but hasn't landed yet.We're working on tearing apart the CLI into smaller chunks that people can use to build their own CLIs without having to first reinvent the universe in their own image. The dream is for people to be able to spin up custom, full-featured package managers in an afternoon that can compete with the latest npm right out the door, and for npm's overall codebase to be in small enough chunks that people can make significant contributions without having to know the entirety of the (massive, terrifying) npm codebase. Seriously, it took me like a year to catch my footing. And that's pretty much everyone else's experience on the team.
2
u/tbranyen May 27 '17
That's a pretty great vision and aligns with reasons I never contributed to npm. Too massive and unconventional. I'm currently experimenting on an HTTP2 package manager geared towards ESM projects and these tools will help immensely to integrate with npm.
Thanks!
2
u/maybekatz May 27 '17
We're redesigning the registry API, and http2 is one thing we're looking at closely. ESM-awareness as well :)
Just sayin' that if you integrate your http2 stuff with
make-fetch-happen, I'd totally consider the patch, and npm would be able to take advantage of it as soon as a service is available for it đ1
u/vinnl May 27 '17
Thanks for the details, that's really interesting! So has the Yarn team contacted you to try and see whether npm could be modified to incorporate the features Yarn introduced (and that have now been incorporated into npm)? And do you happen to know why that route was not chosen - was it to make sure it was a desirable direction for npm?
6
u/maybekatz May 27 '17
The Yarn team has never expressed the intention of moving their efforts to anything but Yarn, regardless of the state of npm, nor have they expressed the remotest intention of contributing to our codebase in any significant way. They even seem to have avoided most of the dependencies npm uses (many of which take care of doing certain tasks in npm-compatible ways). I don't think I have ever seen a patch come through our issue tracker by any member of the Yarn team, except for one person who started bouncing around all our deps and adding
"files: [...]"to them so we'd stop publishingtest/for the ones that still did. And that was a long time ago now.To be fair, the way the project was running as of last year, we were being much much more conservative about making big changes to the codebase or UX, even with the changes that were scheduled for Q1 2017. We've changed that now, so change is happening a lot faster (while still being careful about backwards-compat), and we're putting more effort into making the codebase easier to pick up and contribute to AND letting community devs have more influence over its direction. A lot of the little details in npm5 were things people directly asked us to include, some of which were turned down years ago (before my time!), and we just went "ok sure why not that sounds easy enough". :)
(For the record: the cache rewrite, which enabled offline, did most of the speed improvements, and enabled checksums in the lockfile, as well as "make shrinkwrap what the community wants it to be", has been on our roadmap for about 18 months now, and has been on our backlog as an important item for something like 4 years. I have a conference talk video where I'm outlining the plan, before Yarn was even announced.)
2
u/vinnl May 28 '17
Thanks, this clears up a lot. It's a shame you the Yarn developers didn't jump in, although it does sound indeed like it probably wouldn't have been that easy at first either. Then again, now they're stuck with maintaining a package manager that might lose a lot of the interest it initially gathered, so...
2
u/Geldan May 27 '17 edited May 27 '17
I guess it seemed clear to me because of the particular struggles I went through. When I switched asset bundling over to gulp/webpack in October of 2015 I knew I needed reproducible builds, so naturally I used shrinkwrap.
Shrinkwrap was a nightmare and I dreaded modifying dependencies when I used npm. Even worse was when other devs who hadn't devoted as much time as I had to understanding how it works needed to add dependencies. Forgetting to shrinkwrap or doing it incorrectly had unfun consequences that took time to work through. To me it was a huge issue that nobody at npm seemed to care about (or at least not the right people).
Fast forward a year to October 2016 when yarn came out and my builds got much faster and all of my shrinkwrap issues magically went away. I now have the ability to effortlessly make quick, reproducible builds.
npm had a lot of time to make this happen before yarn, but they didn't. That's why I believe that the vision wasn't shared.
0
u/vinnl May 28 '17
An npm developer just gave some clarification: it had been on their radar, but they were more conservative back then (although they also hadn't been contacted by Yarn).
2
u/Geldan May 28 '17
Yeah, but "radar" is a very loose term. Anywhere I have ever worked this just means that the idea is recognized as good, not necessarily that it will be done anytime soon.
I definitely believe that it was "on the radar," because I know there are some great engineers at npm who saw the value and would likely have advocated for it. I just don't believe that the people making choices about how time is allocated shared that vision.
With past large changes to npm like when it went to flat dependency structure, the public knew it was coming for a long time. As far as i know there was no such public knowledge about these changes until after yarn came out. This certainly makes it look like a reaction.
1
2
u/temp069859085 May 26 '17
This version does not add most if not all the features yarn touts. It adds the superficial stuff, and what can be easily integrated. Yarn is fundamentally different, and still fundamentally more reliable and faster.
6
u/markzzy May 27 '17
Not sure what you mean by "superficial stuff". If you read the release notes you clearly see that npm offers a lot of yarn's features in its v5 version. You work for yarn or sumthin? Couldnt help but notice you created a new profile just to respond to my comment.
-1
0
-16
u/hackel May 26 '17
Why? Does anyone even use npm anymore? I thought we had all just abandoned it and moved over to Yarn.
3
May 27 '17
The Yarn CLI really messes with me. It just doesn't feel as intuitive as npm, it's been over a month now and I still have to constantly look up commands for Yarn.
0
12
May 26 '17
[removed] â view removed comment
7
4
36
u/edanschwartz May 26 '17
Can someone explain the npm-shrinkwap.json vs package-lock.json thing? Why are there two? Do we need both?