package.json that declares it. dependencies() from codemod/deps does each of these in a line, in monorepos too, with pnpm, Yarn and bun catalogs. The full API is in the reference.
Skip repositories that don’t use the library
dependencies() runs inside a step. It reads the package.json files (and pnpm-workspace.yaml or .yarnrc.yml for workspaces and catalogs), so it works without a lockfile, and a lockfile that is missing or can’t be read doesn’t get in the way:
workflow.ts
package.json and the workspaces it declares (workspaces, or packages in pnpm-workspace.yaml, with ! excludes). Without a workspace declaration that’s the root alone, so a fixture’s or an example’s package.json doesn’t make the repository “use” something; dependencies().packages({ all: true }) lists every package.json when you want them.
resolved is the range a declaration means: for "solid-js": "catalog:" it is the catalog’s entry, for "@acme/ui": "workspace:^" the local package’s version. A range semver can’t read (a git URL, latest) has readable: false and semver.major gives null.
To scope a forEachFile callback to files whose package uses something, ask for the file’s package:
Bump, add, remove and rename
Edits change thepackage.json files where the dependency is declared, and nothing else in them:
{ file, package, name, kind, from, to }, and what it left alone as skipped.
- A
catalog:declaration is bumped in its catalog (pnpm-workspace.yaml, bun’spackage.json, or Yarn’s.yarnrc.yml), once for every package that uses it. An entry with a YAML anchor (react: &react ^18.2.0) keeps it, so entries that alias it (react-dom: *react) follow, and are listed in the edits too. - Peer dependencies are left alone unless
kindsnames"peer": a library’s"solid-js": "^1.8.0"peer range stays when you bump Solid. They’re listed inskippedwithreason: "peer". - A
workspace:declaration points at one of your packages and is left alone (reason: "workspace"). - A range that doesn’t come from the registry, such as
file:,link:, a git URL,github:owner/repoor a tarball URL, is left alone too (reason: "protocol"). Annpm:alias keeps its target: bumping"sw": "npm:string-width@^4.2.0"to^5.0.0givesnpm:string-width@^5.0.0. - The root’s overrides follow: when
overrides(npm, bun),resolutions(Yarn, bun),pnpm.overridesorpnpm-workspace.yaml’soverridespin the package by name ("react", or Yarn’s"**/react"),bumpsets them to the new range,removeremoves them andrenamerenames them, so an old override doesn’t keep forcing the old version. A"$react"reference follows the declaration by itself. Overrides that only pin the package in some places ("foo>react","react@<18","foo/react", npm’s nested{ "foo": { "react": ... } }) or that point at a path are left, and listed inskippedwithreason: "override". renameto a name the package already declares removes the old declaration: the existing one keeps its range, or getsrangewhen you pass it.bumptakes a function to decide per declaration:deps.bump("lodash", (d) => semver.major(d.resolved ?? "") === 3 ? "^4.17.21" : undefined).{ kinds, in }limit an edit to sections and packages:deps.bump("solid-js", "^1.9.0", { kinds: ["prod", "dev"], in: "apps/web" }). Within, nothing outside those packages changes: a catalog entry other packages share is left (reason: "catalog"), and so are the root’s overrides (reason: "override"). To give one package its own range,addit there:deps.package("apps/web").add("solid-js", "^1.9.0")replaces itscatalog:with the range.
forEachFile callback’s: with --dry-run they show in the diff and later steps see them, and nothing is written.
Edits change the manifests, not the lockfile, and codemod/deps does not run the package manager. To refresh the lockfile, run it as a shell step after the edits, such as shell("pnpm install --lockfile-only").
Ask the lockfile
Installed versions and the dependency graph come from the lockfile, which is read the first time you ask, not before:deps.chains({ to: deps.node("solid-js", "1.8.22") }) finds who reaches an older copy through other packages, such as @demo/web@1.0.0 > vite-plugin-solid@2.11.6 > solid-refresh@0.6.3 > solid-js@1.8.22. A root lockfile that can’t be read is left out of the graph and listed in deps.skipped.
A step that edits and then asks the lockfile sees the lockfile as it was: the edit changes what is declared, not what is installed. deps.needsInstall() tells whether the lockfile is behind the manifests, catalog entries included: it compares them with the catalogs pnpm-lock.yaml or bun.lock recorded, or else with the installed version.
A package.json that can’t be read (it isn’t JSON) isn’t one of deps.packages(); deps.unreadable lists each with why. A byte order mark at the start of a file is fine, and edits keep it.
dependencies() runs with the codemod CLI. The Node.js host that codemod/testing uses by default doesn’t have it yet: test a workflow that uses it with { host: "quickjs" }.