# Dependency lockfile

## What it is

A dependency lockfile records the result of a package manager's resolution. A project manifest might say that the application can use any compatible release within a range. Installation must choose a particular release of that library and work through its dependencies until it has a graph it can install. A lockfile saves that choice. The next installation can follow the recorded graph even if the registry’s available versions and metadata have changed since yesterday.

The information recorded varies by ecosystem. npm's `package-lock.json` describes the resolved tree and can record both a resolved location and a package integrity value. The Cargo guide explains how `Cargo.toml` expresses dependency choices while `Cargo.lock` records their concrete resolution, including a Git commit in the example of a dependency retrieved from a Git repository. Optional features, platform conditions and separate build requirements may affect the graph the package manager actually uses. Read the format and install mode together before assuming one lockfile covers every environment the same way.

A lockfile is one part of reproducibility. The package manager and compiler versions, build flags, operating system, native libraries, environment and generated input can all affect what ships. A lockfile records which dependency graph should be installed from that source revision. Keep the material needed to obtain that graph, including access to the declared registry, alongside the choices needed to turn it into an artifact.

## Why it matters

Dependency changes can arrive indirectly. An application may declare a small number of packages, each of which depends on packages outside the application's own manifest. A resolver running next week can choose a different compatible version of one of those indirect dependencies. The application source can stay byte-for-byte the same while its tests change behaviour. With a lockfile, a change to the resolved dependency can be reviewed along with any change it requires in the application.

That review has value beyond debugging. A transitive dependency can adopt a different licence, change which platform it supports or introduce a native build step. A package count by itself gives little information about these changes. Inspect the changed edges, why each package was pulled in, and whether environment-specific branches of the graph are still represented. Record why an update is required and check the installed graph in each environment the release will use.

Locks also improve diagnosis. Given the source and its lock, an operator can identify the dependency versions selected at the time a test failed. With access to the recorded releases, a reproduction can use the same versions. Separating dependency resolution from the act of installing makes it easier to tell whether a failure came from a resolution update, a tool change or code that uses the dependencies differently.

## What it looks like in practice

Suppose an application has a frontend builder and a command-line tool used for release reports. Its JavaScript manifest allows a range of releases for its renderer. A team member asks to update that dependency and runs the package manager's update command. They review the resulting lock diff. A second renderer appears under one transitive tool because its version requirements do not overlap those of the first dependency. That duplication might be expected, or it might reveal a stale wrapper that the team should update as well. The diff makes the issue visible before deployment.

Automation then installs in a mode that respects the checked-in resolution. In npm, `npm ci` expects an existing lockfile and fails when it does not agree with the manifest. Its documentation also notes that install-shaping flags used to create the lock can matter for later clean installation. Record relevant settings with the project so a teammate and the build runner both use the same install policy. After installation, the release test exercises the parts of the application affected by the update. A frozen install proves the dependency input, while the tests prove things about the application built with it.

Keep a way to recreate the previous release. Record the lock and toolchain together with the artifact identity. A clean environment that installed from the old lock today should obtain the intended versions, provided the referenced objects are still available and compatible with that operating system. If your registry deletes historical builds or its private credentials have expired, a lockfile cannot restore the missing bytes. Retaining a verified artifact or using a controlled cache with a clear retention plan addresses that risk.

Engineer ApS's licence audit case study describes reviewing an entire Rust dependency graph and testing how licence expressions are evaluated. That case shows why indirect changes matter even when the application's own dependency list looks stable. It also records the limit of declared metadata. A lock helps name the components chosen for that review. Review the declarations separately for accuracy.

## Where it goes wrong

A project commits its manifest but ignores the lock that was produced by routine installation. The developer who opens the change sees one graph while CI may resolve another. Align the repository policy with the package manager and the project type. An application that controls its reproducible delivery has a different role from a library manifest that hands a consumer a compatible range. Write down which file is reviewed and which command is allowed to modify it.

Some teams treat a lockfile as a reason to leave dependencies untouched indefinitely. Choose update intervals and have a way to make a deliberate emergency update. Test a package update in isolation when possible, and keep the lock-derived graph connected to component and licence inventory. Responding to an advisory is easier when the affected versions and paths into the graph are already visible.

Large lock diffs can hide a change caused by updating the package manager itself. Pin the tool version used for maintenance or make format migration a separate change. When a conflict appears during a merge, regenerate from the merged manifest using the expected tool, review the actual resolution and rerun the frozen install. Resolving generated graph entries by hand can leave an internally inconsistent file that looks plausible in a text comparison.

## Further reading
* npm package-lock.json format defines the dependency tree record and describes its scope.
* npm ci describes the clean, lock-bound install behaviour.
* Cargo.toml and Cargo.lock explains the difference between dependency requirements and their chosen resolution.

=> /portfolio/know-the-licence-of-everything-you-ship/ licence audit case study
=> https://docs.npmjs.com/files/package-lock.json/ npm package-lock.json format
=> https://docs.npmjs.com/cli/v11/commands/npm-ci/ npm ci
=> https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html Cargo.toml and Cargo.lock

=> https://engineer.company/glossary/dependency-lockfile/ This page on the web
