What is the `version` in yarn.lock `__metadata`?

Viewed 506

At the top of my yarn.lock file I see:

__metadata:
  version: 5
  cacheKey: 8

I have no idea what the version or cacheKey is, and I haven't found any documentation for them on yarn's website. What are they?

1 Answers

It's simply the yarn.lock version, originally introduced here:

When upgraded, the lockfile entries have to be resolved again (but the specific versions are still pinned, no worry). Bump it when you change the fields within the Package type; no more no less.

More details on the currently implemented resolution logic:

github.com/yarnpkg/berry/blob/master/packages/yarnpkg-core/sources/Project.ts


Typical scenario

The lockfile version changed for me because the latest Yarn version via brew was slightly behind/outdated on 3.2.0-rc.10, despite running brew upgrade to get the latest version, then verifying with yarn -v.

However a bot (might be team member) already upgraded Yarn to 3.2.0-rc.12, versioned / committed / locked in .yarnrc.yml and npm.packageManager (example).

This is what we want for consistency, so we can add a package.json script to use it instead

// ...
  "scripts": {
    // ...
    "setup": "yarn",
    // ...
// ...
Related