Inspect Node package-manager lockfile consistency with structured diagnostics.
node-lockfile-doctor-kit is a clean-room TypeScript package for checking a project snapshot before a CI install surprises you. The core accepts file contents in memory, has no runtime dependencies, and stays browser-friendly. A small optional CLI reads files from disk when used in Node.
Try the browser preview: packages.wasta-wocket.fr/node-lockfile-doctor-kit.
- TypeScript types are generated from the source.
- ESM-only package with no runtime dependencies.
- Marked as side-effect free for bundlers.
- CI runs
npm ci,typecheck,build, andtest. - Tested on Node.js 20 and 22 with GitHub Actions.
- Browser-friendly core with no Node-only APIs; only the optional CLI reads files from disk.
npm install node-lockfile-doctor-kitimport { inspectNodeLockfiles } from "node-lockfile-doctor-kit";
const result = inspectNodeLockfiles({
"package.json": JSON.stringify({
packageManager: "pnpm@9.1.0",
dependencies: { zod: "^3.0.0" },
workspaces: ["packages/*"]
}),
"pnpm-lock.yaml": "lockfileVersion: '9.0'\n\nimporters:\n .:\n dependencies:\n zod: {}\n"
});
console.log(result.ok);
console.log(result.diagnostics);npx node-lockfile-doctor .
npx node-lockfile-doctor . --jsonThe CLI reads package.json, package-lock.json, npm-shrinkwrap.json, pnpm-lock.yaml, yarn.lock, bun.lock and bun.lockb from one directory. The reusable core does not read the filesystem.
Lockfile failures are often caused by boring drift: packageManager says one thing, the repo contains another lockfile, workspaces are present without the expected root lockfile, a merge conflict marker slipped through, or a dependency was added to package.json without a matching lockfile update.
This package does not try to be a dependency graph solver. It gives a small, inspectable consistency report that can run in tests, CI comments, browser workbenches or local CLIs.
Returns:
type NodeLockfileDoctorResult = {
ok: boolean;
manager: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
packageJson?: PackageSummary;
lockfiles: LockfileSummary[];
diagnostics: NodeLockfileDoctorDiagnostic[];
};Formats a stable text report for CLIs, logs or pull request comments.
Creates a reusable inspector with default options.
| Option | Default | Description |
|---|---|---|
expectedManager |
from packageManager or lockfiles |
Force the expected package manager. |
packageJsonPath |
package.json |
Read package metadata from a different key in the file map. |
workspaceGlobs |
from workspaces |
Override workspace globs for generated snapshots. |
Stable diagnostic codes:
invalid-filesinvalid-optionsmissing-package-jsoninvalid-package-jsonmissing-lockfilemultiple-lockfilesmanager-mismatchmissing-package-managerunknown-package-managermissing-dependency-in-lockfileworkspace-missing-lockfilemerge-conflict-markerunsupported-binary-lockfile
- It only inspects the top-level files supplied to the core.
- It does not parse full npm, pnpm, Yarn or Bun dependency graphs.
bun.lockbis detected as binary but not decoded.- Dependency presence checks are deliberately shallow string checks, useful for drift hints but not a proof of graph correctness.
MPL-2.0