FeaturedIT topics

Yarn package manager will be rewritten in TypeScript

Yarn, a JavaScript package manager seen as a rival to NPM, will be rewritten in TypeScript and become API-centric, as part of a comprehensive plan to make the tool more modular, extensible, and developer-friendly.

Builders of Yarn, who want it to become a “development-first” tool in 2019, are emphasizing a “plug ’n’ play” concept that has Yarn telling developers where to find dependent packages instead of relying on Node. Yarn builders refer to the list of planned changes as “Berry,” with a stable release featuring improvements arriving this summer.

Yarn turns to TypeScript

The Yarn development roadmap for version 2 and beyond has the Yarn codebase being ported from Flow to TypeScript, Microsoft’s typed superset of JavaScript, in 2019. This goal is intended to help the community ramp up on Yarn and build new features.

The roadmap also cites plug-in support as a major change. Yarn plug-ins will be able to alter capabilities ranging from the addition of new commands to adding support for new packages sources or install targets. Plug-in support also will impact resolution, fetching, and linking steps.

In a move related to the plug-in system, Yarn will become an API as much as a CLI, with internal components split into modular entities—a goal also slated for 2019. There will no longer be a need to parse package.json as Yarn will abstract away this task. 

Another goal is for Yarn to support different targets than Node. Developers interested in implementing PHP, Python, or Ruby package installers without leaving Yarn are encouraged to open an issue on this.

Also on the drawing board is to make the lockfile and configuration format for Yarn a strict subset of the YAML data serialization standard. Lockfile information will be altered to account for long-awaited changes such as the removal of hostnames, enabling easier switching of the default registry.

Yarn roadmap details

Other major changes and new features on the Yarn roadmap:

  • An overhauling of the log system, including leveraging diagnostic error codes from TypeScript. Errors and warnings will be assigned a unique code.
  • Core features such as autoclean will be moved into contrib plug-ins.
  • The cache file format will be switched from Tar to Zip, offering better characteristics for random access.
  • Out-of-the-box support for nested workspaces, in which a workspace defines additional workspaces. This will expand usages, particularly when used together with Git submodules.
  • A resolution protocol, workspaces:, to force the package manager to link a package against a workspace, preventing accidental use of a version of a package acquired from the remote registry.
  • A yarn constraints command to enforce constraints across packages.
  • The yarn link command will persist changes into package.json files. Linked packages will resolve peer dependencies.
  • Writing Posix commands inside the scripts field will work regardless of the underlying OS.
  • Scripts will be able to put arguments anywhere in the command line.
  • The cache will be fully atomic, with multiple Yarn instances able to run concurrently on the same cache without the risk of corrupting the data.

Support for Node 4 and Node 6 will be dropped. Also, a large volume of bugs are expected to disappear as the codebase is modernized.

The Yarn roadmap is prefaced by remarks about how the landscape has changed since the project began in 2016. Package locking was not a first-class citizen in the JavaScript ecosystem at the time, for one thing. Yarn was developed as part of a collaboration between Facebook, Google, Exponent, and Tilde.

You can download Yarn from the project website.

Related Articles

Back to top button