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
- What a lockfile does, and for whom
- What your consumers actually install
- Ecosystem by ecosystem
- A testing strategy that covers both worlds
- 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
| Ecosystem | What ships to consumers | Common guidance |
|---|---|---|
| npm | package-lock.json is not included when the package is installed as a dependency | Commit it for contributor reproducibility; never use npm-shrinkwrap.json in a library, because a shrinkwrap is published and forces exact versions on users |
| Rust / Cargo | A library's Cargo.lock is ignored by dependents | The 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 |
| Python | Only the metadata ranges in the wheel matter | Lock development environments with your tool of choice; keep library dependency ranges broad |
| Go | go.sum records checksums, not a resolution | Minimal 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:
- Locked lane: install from the committed lockfile on every pull request. Failures here mean your change broke something.
- Fresh lane: on a schedule, install without the lockfile (or after refreshing it) so the resolver picks the newest allowed versions, the same thing a new user would get. Failures here mean the world moved, and you should either fix compatibility or tighten a range.
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.