
What the Heck is Yarn?
If you’re a Javascript engineer, you’ve probably heard the big news drop today that Facebook released a new package manager called Yarn. As of today, npm is officially “so 2016” or quite literally “so yesterday” (this news got dropped today — cue Hilary Duff).
So what is a package manager again?
A package manager is a brilliant tool used by developers to share codebases in order to avoid re-writing and re-creating the same things over and over again. This also open sources things for community development and is better for the tech industry as a whole. Bower is another popular package manager that is used for mostly front-end (client) packages. npm is by far the most popular anyone using NodeJS and allows you to download node modules for use on the backend for servers (ie. Passport or Express), authentication, etc.
Fun Side Note: Npm does not stand for Node package manager. It is a recursive bacronymic abbreviation for “npm is not an acronym.” I am still trying to figure out what those words mean.
“The most popular JavaScript package manager is the npm client, which provides access to more than 300,000 packages in the npm registry. More than 5 million engineers use the npm registry, which sees up to 5 billion downloads every month.” — Facebook
So as you can see, this is a pretty big deal for the software developer community.
So if npm is so great, why create Yarn?
However, with the increase of Facebook’s codebase and endless gobbling up of every able software engineer, they faced problems around “consistency, security, and performance.” Enter Facebook with their own npm client alternative that they’ve worked on with Exponent, Google, and Tilde. Not intimidating at all, huh?
Some problems Yarn will tackle:
- Solve issues around continuous integrations or sandboxed environments (for security and testing before deployment)
- Cut down on the tremendous amount of React node module dependencies (after running an
npm installfor the React native package.json — the folder would end up with over 12,358 files) - Get rid of dealing with the headache of shrinkwraps for your app deployment, which is a way to lock down a certain node dependency version (in case there are compatibility or security issues)
Okay you got me. How do I get started?
Glad you asked. Looks like Facebook has already been deploying Yarn in production and has been having great results.
“The install process is broken down into three steps:
Resolution: Yarn starts resolving dependencies by making requests to the registry and recursively looking up each dependency.
Fetching: Next, Yarn looks in a global cache directory to see if the package needed has already been downloaded. If it hasn’t, Yarn fetches the tarball for the package and places it in the global cache so it can work offline and won’t need to download dependencies more than once. Dependencies can also be placed in source control as tarballs for full offline installs.
Linking: Finally, Yarn links everything together by copying all the files needed from the global cache into the local node_modules directory.”
Step 1: Install Yarn globally through your terminal
npm install -g yarn
Step 2: Run yarn
Simply typing yarn in your terminal is enough to now get you started. It is essentially replacing the tried and true npm install
Step 3 (Optional): Add any additional dependencies and enjoy
Using yarn add <name> is akin to typing npm install --save <name>
For more in-depth developments around Yarn: take a look at Facebook’s official statement