Antecedents: https://code.facebook.com/posts/1840075619545360
FaceBook offers a seemingly non-NPM installation (MAC):
curl -o- -L https://yarnpkg.com/install.sh | bash
Copy the code
It can be installed on other platforms via installation files or other package management systems, which looks less npm-ish and makes me think it’s an alternative to NPM, although we all love NPM;)
Of course, that’s not the real reason, it’s just that if you install YARN with NPM, it creates the same problems that Yarn is trying to solve, such as speed, semantic versioning deficiencies, etc
What NPM problems does YARN solve? yarn:
Very fast, very, very fast
Yarn caches every module you download, so that the same version of the same module does not send a second download request. For modules that do not have caching, YARN can maximize network resources through parallel network requests. Now there really is no dozens of seconds to install not over of dependence. A 50-dependency WebPack + Babel project can be installed in about 20 seconds.
security
Yarn will use checksums to verify before starting a package installation so you don’t have to worry about local cached packages corrupting and causing installation failures.
reliable
Maintained by a group of cat-loving developers and used by FaceBook in the Production environment. Complete testing and code base based on flow type.
And a lot of touching little improvements
1. Some NPM packages will throw warning messages. In NPM install, there is only one name and you don’t know which package or which package or which package is throwing this message.
2. ‘yarn ls’ highlights dependencies in package.json for readability.
3. The execution time of each command is displayed.
NPM Shrinkwrap loses synchronization if you forget to generate it. Ensure that YARN installs the same version of dependencies every time.
5. ‘YARN Why’ This command tells you why a dependency was installed into your project.
6…. countless…
The yarn structure
Yarn enables concurrent requests, more accurate installation results, and clearer console output by splitting the installation into three steps:
- Processing: Request information for each dependency from Registry
- Fetch: Retrieves downloaded dependencies from the cache. If not, download the compressed package of the dependency and cache it
- Build: Copy dependencies from the cache to the node_modules directory in the project
Fork?
The question then becomes, Yarn has a lot of exciting features, but why can’t these be added by improving NPM instead of developing a new client?
In short, compatibility. These improvements now look like breaking changes in NPM.
npm
Some people start to worry about NPM, some even say it’s finally time to die, NPM! NPM had been involved in the YARN project earlier and encouraged this because it was difficult to directly make these improvements that might cause compatibility problems for a system as widely used as NPM. (Don’t think NPM is better than you.)