未加星标

Editorial: Are We Heading for Package Manager Fatigue?

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This is the editorial from my latest javascript newsletter, you cansubscribe here.

More from this author Editorial: A Spotlight on Interesting JavaScript Projects File Bundling and HTTP/2: Rethinking Best Practices

Facebook has made a big splash this past week with the announcement of its new JavaScript package manager, Yarn. Your initial reaction may be similar to mine when I first heard this: isn’t another package manager the last thing we need?! It seemed that, despite the upheaval of a seemingly never-ending parade of new frameworks, the JavaScript community had at least settled on npm as the defacto package manager.

But wait, before you take to Twitter or your blog to decry package manager fatigue, Yarn is actually not that bad. For a start, Yarn is not a new package repository: it’s more of a drop-in replacement for the npm client, designed to improve upon some of npm’s shortcomings. As an added bonus, not only does it work with npm packages, it also supports Bower! Change to a project folder with either a package.json or a bower.json file, run yarn , and you’re in business.

“OK, but I don’t use Bower, so why would I change to Yarn?” I hear you ask. Well, the Yarn team built it to address issues with speed, reliability, and security that they have had when using npm on projects internally at Facebook. To achieve this, Yarn generates a lockfile which helps it to keep track of exactly how each dependency is resolved.

One of the benefits of the lockfile is a speedup of install times. I’ve seen some differing accounts so far on just how much difference it makes (and in some cases, whether it makes a difference at all) but there are some very interesting comparisons between Yarn and npm here . One of the other things Yarn does differently is to keep a cache of downloaded packages, making reinstalls blazingly fast. It also means they can be done offline.

Another important consideration is making sure that a project can be installed predictably on different machines. Yarn uses a deterministic algorithm when figuring out which dependencies are required to ensure that they are always installed in the same order. This avoids potential hard-to-debug errors that can sometimes occur with npm.

Yarn also improves the reliability of the installation process. Rather than aborting the install, a failed dependency request will be queued to be retried. The request queue is intelligently handled to parallelize requests and minimize download time.

If you’re really trying to streamline your project, Yarn offers the option to perform a flat install. You may have multiple packages in your project that depend on different versions of a specific library. By choosing a flat install, Yarn will prompt you about each package that is being required in more that one version and allow you to manually select which version to install, preventing the need for multiple copies at different versions.

It’s worth having a dig through the CLI documentation , as there are some other interesting commands available. Running yarn why <package-name> will let you know why a specific package has been installed, how much space it takes up, and how many shared dependencies it uses. yarn clean is still experimental, but will attempt to remove unneeded files from the node_modules folder and reclaim some disk space. Another potentially useful command is yarn licenses , which will list out the type of license for each package your project is using.

For those concerned about Yarn fragmenting the ecosystem, it’s worth point out that this is not the first third-party npm client by any means. The maintainers of npm see this as a positive development , saying it demonstrates that Facebook “is invested in and committed to the ongoing health of the npm community. That’s great news for JavaScript devs everywhere.”

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: JavaScriptJavaFacebookHeadTwitter
分页:12
转载请注明
本文标题:Editorial: Are We Heading for Package Manager Fatigue?
本站链接:http://www.codesec.net/view/484280.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(33)