What is yarn ?
Yarn
is a node package manager developed by facebook. It's performant, lightweight, and easily customizable, and have become the package manager of choice for most Javascript developers.
Why the hype of yarn berry ?
The flexibilty and customizability of yarn stems from yarn berry
, hence the reason most Javascript developers are upgrading to yarn berry. Berry is the active development trunk of yarn. With berry, yarn now doubles down as both a package manager and as a project manager, providing a wholesome experience for running monorepos. Berry has popularized the concept of Plug’n’Play . The plugin architecture of berry makes it very flexible and easily extensible - the package manager of a project using berry will basically consist of a tiny core and a bunch of plugins.
As different projects may require different yarn plugins to manage their dependencies, berry encourages per project installation. To use berry for a project:
- Run
npm install -g yarn
to update the global yarn version to latest v1. - Go into your project directory
- Run
yarn set version berry
to enable berry. This downloads berry from i'ts repository, saves it in.yarn/releases/yarn-berry.cjs
, and creates / updates a.yarnrc.yml
file with the content,yarnPath: ".yarn/releases/yarn-berry.cjs"
. Whenever you install a Yarn plugin, it will be saved at.yarn/plugins/
and a corresponding entry added to to theplugins
field of.yarnrc.yml
. - To use Plug’n’Play as node modules linker ( recommended - see yarnpkg.com/features/pnp ) , add
nodeLinker: "pnp"
in your.yarnrc.yml
file . - If you wish to use node_modules as the linker that should be used for installing Node packages, add
nodeLinker: node-modules
in your.yarnrc.yml
file . This plugin (@yarnpkg/plugin-node-modules
) is included by default in berry, you don't need to install it.
Debian Javascript Packages
Over the years, Debian Developers have worked hard to package thousands of node modules for Debian, for different purposes. This raises the question of how these packaged node modules installable via apt, can be used and re-used in node projects. Here is where berry comes to the rescue.
How do we use Debian Javascript Packages in Node Projects ?
If we can have berry packaged for Debian, we can create a yarn plugin to resolve node modules installed from the Debian archive via apt. A major blocker in the conceptualization of this idea was the fact that the package management commands of yarn still resides in classic yarn1. This is why to use berry, you'd always have classic Yarn installed globally and enable berry per project . How then do we get past this one🤔? The ingenuity of ever-inventive developers of the Debian Project came to the rescue. As per successful build and test by Pirate Praveen, Akshay Dinesh and co, berry can be built with corepack node module and a few other dependencies.
Corepack
Corepack is a node module that intends to bridge the gap between node projects and their package managers. As a matter of fact, corepack lets you use yarn and npm without installing them. It is as good as it sounds 🕺🕺🕺. You can hack around corepack to serve as the core package manager upon with pluggable codes can be layered 😊 . This is how my Debian Outreachy internship project ( Build a yarn plugin to resolve node modules installed via apt ) was birthed.
Project Goals
Upon the completion of this project, Debian users will be able to enjoy the flexibility that comes with Debian packaged node modules. One of such is the ease to patch a module locally how you want it, in a more organised and manageable way. I think this will give us super powers over packages that our projects depends on. This plugin should be able to:
- Resolve and satisfy package.json with node modules installed via apt.
- Allow mixed usage of packaged modules and non packaged modules when the number of modules is large and will take a long time for all to be packaged.
- Help us in verifying if all dependencies mentioned in package.json is installed by apt.
These we want to enable as an autopkgtest for all node packages.