days
0
-13
-9
hours
-1
-3
minutes
-1
-5
seconds
-5
-9
search
Don't be a-fray-ed of change

Yarn v2 changes migrates codebase from Flow to TypeScript

Sarah Schlothauer
yarn
© Shutterstock / Olga Evans

Last year, Yarn laid out its goals for the future, including plans for an overhauled log system, becoming an API, a switch to TypeScript, and support for plugins and new commands. Now, that vision is fulfilled and the latest version has arrived. Let’s meet Yarn version 2, see the latest changes, and take a look down the road ahead for this JavaScript package manager.

The JavaScript package manager Yarn unraveled a new version. Yarn version 2 was unveiled on January 24th. This update includes major changes to Yarn’s architecture and updates the plans for the road ahead.

Its full changelog is available on GitHub, detailing all the new additions.

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 dlx command: 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.

SEE ALSO: How can you make a JavaScript website successful in Google?

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).

SEE ALSO: JavaScript developers average 2020 salaries hits $114,986 in the US

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?

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Leave a Reply