Use a standard format (yaml) for yarn.lock

I’m reopening #2250 which was closed a bit too hastily. I just hit the use case of wanting to read yarn.lock from Python (as an introspection step), and although I thought yarn.lock was yaml, it’s actually not. It’s almost yaml.

Pipenv, which is heavily inspired by yarn, uses json for its lockfile which makes it very easy to parse.

I suggest either using json or yaml for the lockfile v2. If yaml’s large featureset is an issue, I know there’s “strict yaml” subsets (at least here for Python, I don’t know for JS). JSON would make the most sense but that does mean comments would no longer be available.

Author: Fantashit

3 thoughts on “Use a standard format (yaml) for yarn.lock

  1. The initial design goals, iirc:

    • Must be easy to read by a human
    • Must be easy to diff
    • Must be fast to parse

    JSON didn’t meet 1 (which was an arbitrary choice in some extent, I don’t see the point of debating whether or not you agree with it), and YAML didn’t meet 3. The flat style of the file was required by 2 and some internal architectural choices.

    Imo we should have used a stricter subset of yaml (one missing feature however is that our lockfile supports multi-keys properties, which are annoying to do in yaml without backreferences; so we would have had to reparse the keys to split on , anyway), but now the ecosystem is what it is, and we have to deal with it.

    Was the intention to discourage languages such as Java or C# from being able to read the file? 😛

    Of course not… 😒

  2. I can’t tell for sure, but I think it just was called this way because a) it “locks” the dependencies and b) the shrinkwrap files produced by the NPM cli were riddled with bugs and I guess Yarn wanted to make the distinction super clear.

    As a non anglophone speaker, I can also say that even after two years working on Yarn, I still had no idea what the literal meaning of the word shrinkwrap was until you brought the subject, so I guess calling it lockfile also helps international users 😝

Comments are closed.