Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:0sec labs 0 Dependency Locking

From Leeroopedia
Knowledge Sources
Domains Tooling, Dependency_Management, Reproducibility
Last Updated 2026-10-30 00:00 GMT

Overview

A mechanism that pins every direct and transitive dependency in a project to an exact resolved version and integrity hash, guaranteeing reproducible installs across environments.

Description

Dependency Locking is the practice of recording the fully resolved dependency graph — including all transitive dependencies, their versions, and cryptographic integrity hashes — in a lockfile that is committed to version control. It solves the problem of floating version specifiers (e.g., ^1.2.0) producing different dependency trees over time or across machines as new versions are published.

A lockfile captures three things a package.json alone cannot:

  1. Exact versions: The specific version resolved for every package in the tree, not just a range.
  2. Integrity hashes: A sha512 hash per resolved package, enabling tamper and corruption detection.
  3. Override propagation: A mechanism to force a minimum version of a transitive dependency across the entire tree, used to apply security patches to packages deep in the dependency graph.

This ensures that pnpm install --frozen-lockfile in CI produces a byte-identical node_modules tree to what a developer committed, eliminating "works on my machine" dependency drift and supply-chain surprises.

Usage

Apply this principle when managing any multi-package monorepo or project where reproducible builds and supply-chain integrity are required. It is the right choice whenever:

  • CI must fail if dependencies have drifted from the committed lockfile.
  • Security advisories require forcing a patched version of a transitive dependency.
  • Multiple developers or pipelines must produce identical dependency trees.

Theoretical Basis

The core invariant is a deterministic resolution function:

# Abstract algorithm (NOT real implementation)
def resolve(manifests, overrides, registry):
    tree = {}
    for manifest in manifests:
        for dep, specifier in manifest.dependencies.items():
            # Apply override if one exists for this package
            if dep in overrides:
                specifier = overrides[dep]
            # Resolve to exact version from registry
            exact = registry.resolve(dep, specifier)
            # Record integrity hash for tamper detection
            tree[dep] = {
                "version": exact.version,
                "integrity": exact.integrity_sha512,
            }
    return tree  # This tree is the lockfile

The lockfile is the output of this resolution, persisted so future installs skip resolution entirely. The frozen install mode verifies that the manifests still hash to the same lockfile, failing if a specifier changed without a lockfile regeneration.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment