3 min read • Posted on July 27, 2021 (Edited on Sep 5, 2021)
Introduction
Looking at the yarn.lock file can be a bit overwhelming, but it’s actually not that complicated. There isn’t that much difference between yarn v1’s lock files and yarn v2’s lock files so I’ll consider them equal for this blog post (if you want to see the differences, see the changelog).
Simple dependency
Here we can see that the package wrappy is the dependency and requested at the version 1 (wrappy@1). But the resolved, imported version is the version 1.0.2 (with its hash and the URL for the download).
Multiple resolutions
In this snippet, we can see that the package whatwg-mimetype is imported in 2 versions: ^2.2.0 and ^2.3.0. But at the time of the resolution, both were resolving to the same version: 2.3.0. So both, in the end, will use the same node module with the same version.
Dependency with dependencies
Here we can see that which-boxed-primitive is imported with the version ^1.0.2, resolved with the version 1.0.2. But this version requires other modules (here is-bigint, is-boolean-object, is-number-object, is-string, and is-symbol.
Their requested versions are written next to them, but not their resolved versions, and you’ll find them above or below in the lockfile.
Last more complicated example
Here you can see that @babel/core is requested in 4 versions 7.12.9, ^7.12.0, ^7.12.2, and ^7.12.3. But as, at the time of the resolution of ^7.12.0 and ^7.12.2, the latest version was 7.13.15, those 2 were resolved to 7.13.15.
And when 7.12.9 was added, as changing the previously resolved versions could lead to breaking changes, they were kept and @babel/core was duplicated.
Editing the lock file
If you’re interested in editing this file, you can read:
Yarn.lock: How to Update itYarn comes with a lock file `yarn.lock` that isn’t made for human to edit it. But sometimes you need to do a specific edit in it (like dropping a specific package). This article highlights a few different ways to do so