Session Notes: Lockfiles in Library Repositories

Applications commit lockfiles; that part is settled. Libraries are where the arguments start, because a library's lockfile never reaches its users. These notes come from a talk that works through the question ecosystem by ecosystem. The talk exists only as these written notes.

Agenda

  1. What a lockfile does, and for whom
  2. What your consumers actually install
  3. Ecosystem by ecosystem
  4. A testing strategy that covers both worlds
  5. Questions we get asked

1. Who a lockfile is for

A lockfile records the exact versions the resolver chose, so the next install in the same repository is reproducible. In a library repository, that benefits contributors and CI: everyone runs tests against the same tree, and a broken transitive release cannot fail an unrelated pull request overnight. It does nothing for the people who install your library, because their own resolver works from your declared ranges.

2. What consumers install

Picture a user installing your package today. Their package manager reads your dependency ranges, combines them with everything else in their project, and picks versions, perhaps newer than anything you have tested. That gap is the real risk. Committing a lockfile narrows your CI's view to one snapshot; it does not narrow the user's.

3. Ecosystem notes

EcosystemWhat ships to consumersCommon guidance
npmpackage-lock.json is not included when the package is installed as a dependencyCommit it for contributor reproducibility; never use npm-shrinkwrap.json in a library, because a shrinkwrap is published and forces exact versions on users
Rust / CargoA library's Cargo.lock is ignored by dependentsThe Cargo team updated its guidance in 2023 so that committing Cargo.lock is the default for all packages, with a note to also test against the latest compatible versions
PythonOnly the metadata ranges in the wheel matterLock development environments with your tool of choice; keep library dependency ranges broad
Gogo.sum records checksums, not a resolutionMinimal version selection already makes builds reproducible from go.mod; commit both files

Check each ecosystem's own documentation before adopting a rule; guidance in this area has changed over time.

4. A two-lane testing strategy

The talk's recommendation is to run two kinds of CI job:

Some teams add a third, "minimum versions" lane that installs the lowest versions your ranges allow, to prove the lower bounds are honest. Cargo has an unstable flag for this and some Python tools offer a lowest-resolution mode; in npm you generally have to script it.

# fresh lane, illustrative npm job
rm -f package-lock.json
npm install
npm test

5. Questions we get asked

Will a committed lockfile hide breakage from users?

Only if it is your sole lane. With the scheduled fresh lane, you find out roughly when users do.

Lockfile updates create noisy pull requests. Is that a reason not to commit one?

Batch them. Dependency bots can group updates weekly, which keeps history readable.

Does the lockfile matter for security?

For your CI, yes: it pins integrity hashes for what your build runs. For your users, their own lockfile and audit tooling do that job.

Related: the dependency tree figures explain why broad ranges help your consumers, and the semver ranges practice session covers the range syntax.

Related pages

An independent site with articles and free browser tools about building, evaluating, licensing and pricing reusable code modules. Informational only; nothing is sold on this site. Disclaimer