Yarn v2 changes migrates codebase from Flow to TypeScript
Its full changelog is available on GitHub, detailing all the new additions.
Introducing Yarn 2! https://t.co/PZMf0IChFu
— Maël (@arcanis) January 24, 2020
v2 changes and highlights
Some of the notable changes included in v2:
- Redesigned CLI Output: New colors and new searchable error codes which include suggested fixes.
- “Zero-installs” philosophy: Yarn reads vendor files directly from cache.
yarn dlxcommand: Download and execute remote scripts
yarn workspaces foreach command: Extends Yarn across multiple repos with a plugin
patch:protocol: Apply changes to a package in the dependency tree
- New workflow plugin: A new incubating plugin adds deferred versioning and includes a visual interface.
- Constraints: Specify generic rules for workspaces using Prolog.
- Zip cache files: Zip now replaces tgz
- Read-only packages: Packages in cache archives are mounted as read-only drives
- Updated homepage and documentation. (The adorable mascot is conspicuously missing from the v2 site. Catch him on the legacy code site.)
Many new features in v2 are currently experimental and still incubating, so keep this in mind if you decide to migrate to the newest version and watch for updates.
Migrating from Flow to TypeScript
One of the biggest changes under the hood in v2 is the switch from Flow to TypeScript.
From the announcement blog post by Yarn maintainer Maël Nison:
While it might not directly impact you as a user, we’ve fully migrated from Flow to TypeScript. One huge advantage is that our tooling and contribution workflow is now easier than ever. And since we now allow building Yarn plugins, you’ll be able to directly consume our types to make sure your plugins are safe between updates.
This is another drop in the bucket towards making TypeScript the new JS developer standard and marks yet another project moving their codebase from Flow to TypeScript. (Back in 2018, Facebook’s Jest also made the switch.)
The road ahead
If you choose to migrate, note that Yarn no longer supports Node 8. You should upgrade to Node 10 or 12.
In addition, if you use Webpack 4 you have to add a PnP plugin manually (or upgrade to Webpack 5, which includes native Plug’n’Play support).
Follow the migration guide for the guided process and begin your switch over from v1 to v2. Yarn 1.22 will arrive soon and it will be the last release of the 1.x branch. After that, version 1.x will enter maintenance mode and will no longer receive any new features.
Future plans include a number of large changes and reworkings. According to the roadmap, the plan is to make Yarn an API in addition to its role as a CLI. Support for plugins will continue and the log system will take a page out of TypeScript’s diagnostic error codes.
For years, Yarn and npm have been pitted against each other. Does this new update change the rankings in the package manager race?