Task runnerGuidesSmart Lockfile Hashing

Smart Lockfile Hashing

Only bust cache for packages affected by lockfile changes

Smart Lockfile Hashing

By default, lockfiles (package-lock.json, pnpm-lock.yaml, yarn.lock) are included in the global hash. This means any lockfile change invalidates every task's cache.

Smart lockfile hashing parses the lockfile and only hashes the resolved versions of each package's actual dependencies. A lockfile change only busts cache for affected packages.

Enable

const results = await defaultTaskRunner(tasks, {
    smartLockfileHashing: true,
}, context);

How It Works

  1. Parse lockfile - Reads package-lock.json, pnpm-lock.yaml, or yarn.lock
  2. Read package.json - Gets each project's declared dependencies
  3. Filter - Extract only the resolved versions relevant to each project
  4. Hash - Include filtered versions in the task hash as __lockfile__ implicit dep

Supported Lockfile Formats

  • package-lock.json - npm v1, v2, v3
  • pnpm-lock.yaml - pnpm v6+
  • yarn.lock - Yarn Classic (v1) and Berry (v2+)

Example

Given a monorepo with packages A (depends on lodash) and B (depends on express):

  • Updating lodash in the lockfile → only package A's cache is busted
  • Updating express in the lockfile → only package B's cache is busted
  • Updating both → both caches are busted

Standalone Usage

import { LockfileHasher } from "@visulima/task-runner";

const hasher = new LockfileHasher("/path/to/workspace");
const result = await hasher.hashForPackage("packages/my-app/package.json");

console.log(result?.hash);          // SHA-256 hash of resolved deps
console.log(result?.dependencies);  // [{ name: "lodash", version: "4.17.21" }]
console.log(hasher.lockfileType);   // "npm" | "pnpm" | "yarn"
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues