Node
Check a manifest from Node, inspect proposed edits, and apply a dependency policy.
Check a manifest from a script
Suppose your project requires lodash 4.17.21 but its manifest still declares 4.17.20. Start with this file in an empty directory.
{
"name": "policy-example",
"private": true,
"dependencies": { "lodash": "4.17.20" }
}
Run npm install --save-dev codependence. Save the following script beside package.json and run node check.mjs from that directory. The CLI reads repository configuration. When calling the Node API, pass the files and policy directly.
import { checkFiles } from "codependence";
try {
await checkFiles({
files: ["package.json"],
codependencies: [{ lodash: "4.17.21" }],
});
} catch (error) {
process.stderr.write(String(error) + "\n");
process.exitCode = 1;
}
The version mismatch rejects the promise. The script exits with status 1 and leaves package.json untouched. Once the declaration matches, the check resolves.
Inspect the proposed edits
For a report, pass format: "json". In Node this collects JavaScript objects. Your script chooses how to display them and what exit status to return.
import { checkFiles } from "codependence";
const diffs = await checkFiles({
files: ["package.json"],
codependencies: [{ lodash: "4.17.21" }],
format: "json",
});
for (const diff of diffs ?? []) {
if (diff.willUpdate) {
process.stdout.write(`${diff.package}: ${diff.current} -> ${diff.latest}\n`);
}
}
Run node report.mjs before applying the update. It prints:
lodash: 4.17.20 -> 4.17.21
Each VersionDiff includes the package name, its current declaration, the target version (latest), whether the package is listed in the policy (isPinned), and whether it qualifies for an edit (willUpdate). The return type is Promise<VersionDiff[] | void>. A formatted call can still reject, for example when a required lockfile is missing.
Apply the edit
import { checkFiles } from "codependence";
await checkFiles({
files: ["package.json"],
codependencies: [{ lodash: "4.17.21" }],
update: true,
});
Run node update.mjs, then node check.mjs again. The declaration now reads "lodash": "4.17.21" and the check passes. Run npm install to refresh the lockfile and installed packages.
Exports
checkFiles(options)
Run node example.mjs.
import { checkFiles } from "codependence";
const diffs = await checkFiles({
files: ["package.json"],
codependencies: [{ lodash: "4.17.21" }],
format: "json",
});
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — The policy requires 4.17.21. Running the check leaves this edit for you to apply.
Check the manifests selected by a CheckFiles object. A plain check rejects when a version needs updating. Request format to collect diff records and handle the result yourself.
codependence(options)
Run node example.mjs.
import { codependence } from "codependence";
await codependence({ codependencies: [{ lodash: "4.17.21" }] });
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — The policy requires 4.17.21. Running the check leaves this edit for you to apply.
The named codependence export is an alias for checkFiles.
Default import
Run node example.mjs.
import check from "codependence";
await check({ codependencies: [{ lodash: "4.17.21" }] });
-import { checkFiles as check } from "codependence";
+import check from "codependence";
- Changed line — Both imports expose the same check function.
The default export calls the same function as checkFiles.
script(options)
Run node example.mjs.
import { script } from "codependence";
await script({ codependencies: [{ lodash: "4.17.21" }] });
-import { checkFiles } from "codependence";
+import { script } from "codependence";
-await checkFiles(options);
+await script(options);
- Changed line — This call resolves even when lodash fails the check.
Run a check and absorb its failures.
Alert
script resolves to undefined even when a check fails. Use checkFiles when CI needs to report the error.
schema
Run node example.mjs.
import { schema } from "codependence";
const managers = schema.definitions.manager.enum;
+const managers = schema.definitions.manager.enum;
- Changed line — The exported schema includes pnpm in this list.
Read the JSON Schema for repository configuration. The same schema is published at codependence/schema.json.
Select manifests
files
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
files: ["packages/*/package.json"],
});
-package.json
packages/web/package.json
packages/api/package.json
- Changed line — The glob selects the two workspace manifests and skips the root manifest.
string[]. Select manifests by path or glob relative to rootDir. Default patterns depend on the language.
rootDir
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
rootDir: "packages/web",
});
-./
+./packages/web/
- Changed line — File patterns now resolve from the web project.
string. Set the root for file discovery. The default is the current working directory.
ignore
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
files: ["**/package.json"],
ignore: ["**/node_modules/**", "**/fixtures/**"],
});
packages/web/package.json
-tests/fixtures/package.json
- Changed line — The ignore pattern drops this fixture from the check.
string[]. Exclude paths from discovery. Include the node_modules glob when supplying your own exclusion list.
language
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
language: "docker",
files: ["Dockerfile"],
codependencies: [{ alpine: "3.20" }],
});
-FROM alpine:3.19
+FROM alpine:3.20
- Changed line — The Docker policy requires this base image tag. The check reports the mismatch.
SupportedLanguage. Select the manifest provider explicitly. This example checks the tag on an Alpine base image in a Dockerfile.
packageManager
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
packageManager: "pnpm",
});
+ packageManager: "pnpm",
- Changed line — Selects pnpm for this manifest.
DependencyManager. Specify the manager for a manifest, for example pnpm for a Node project or uv for a Python project.
yarnConfig
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
yarnConfig: true,
codependencies: ["lodash"],
});
+ yarnConfig: true,
- Changed line — Looks up lodash using Yarn.
boolean, default false. Select Yarn for Node package lookups.
lockfile
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
lockfile: ["pnpm-lock.yaml"],
});
+ lockfile: ["pnpm-lock.yaml"],
- Changed line — The check rejects if this file is missing.
boolean | string | string[]. Require a standard lockfile with true or specify the paths that must exist. A missing required file rejects the call before edits.
Choose eligible updates
codependencies
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
});
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — The policy requires 4.17.21. Running the check leaves this edit for you to apply.
Array<string | Record<string, string>>. A name requests a lookup. An object sets the required version declaration.
mode
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
mode: "precise",
codependencies: ["react"],
});
-react
+lodash
- Changed line — In this two-package example, precise mode holds back the listed react dependency and checks lodash.
"verbose" | "precise". Verbose mode checks the listed dependencies. Precise mode checks the others and holds the listed packages back.
permissive
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
permissive: true,
codependencies: ["react"],
});
-react
+lodash
- Changed line — In this two-package example, precise mode holds back the listed react dependency and checks lodash.
boolean. Set true for the compatibility form of precise mode.
level
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
level: "patch",
});
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — The last version number changes. This update qualifies for the patch policy.
"patch" | "minor" | "major", default "major". Restrict eligible semver updates. For example, 4.17.20 to 4.17.21 qualifies as a patch.
update
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
update: true,
});
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — Writes the pinned patch version to package.json.
boolean, default false. Write eligible changes to the manifests.
dryRun
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
update: true,
dryRun: true,
format: "json",
});
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — Proposed edit only. The file still declares 4.17.20.
boolean, default false. Preview an update and leave the manifest untouched.
interactive
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
update: true,
interactive: true,
});
- "lodash": "4.17.20"
+ "lodash": "4.17.21"
- Lodash version — Selecting lodash applies this edit.
boolean, default false. Prompt in the terminal to select which eligible changes to write.
noCache
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
noCache: true,
codependencies: ["lodash"],
});
+ noCache: true,
- Changed line — Requests fresh metadata for lodash.
boolean, default false. Request fresh metadata when resolving a package name.
Results and logging
Run node example.mjs.
import { checkFiles } from "codependence";
const diffs = await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
format: "json",
});
process.stdout.write(JSON.stringify(diffs, null, 2) + "\n");
+ format: "json",
- Changed line — Returns diff records with the current and required versions.
"json" | "markdown" | "table". Collect diff records and defer mismatch failures. In Node, the result is an array of objects you can format yourself.
deferFailure
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
deferFailure: true,
quiet: true,
format: "json",
});
+ deferFailure: true,
- Changed line — Lets the caller handle a mismatch after inspecting the result.
boolean, default false. Allow an outdated check to resolve so the caller can decide whether to fail. Pair with format when you need diff records even with quiet logging.
verbose
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
verbose: true,
});
+ verbose: true,
- Changed line — Requests detailed output for the same check.
boolean, default false. Request detailed check output.
debug
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
debug: true,
});
+ debug: true,
- Changed line — Turns on diagnostics for the dependency comparison.
boolean, default false. Enable diagnostic details during version resolution and manifest checks.
silent
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
silent: true,
});
+ silent: true,
- Changed line — Suppresses routine messages. The mismatch still rejects.
boolean, default false. Suppress routine messages and the normal preview table.
quiet
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
quiet: true,
});
+ quiet: true,
- Changed line — Suppresses the preview table. The caller still receives the rejection.
boolean, default false. Suppress ordinary check output. The caller can still handle a rejection.
Callbacks and integration options
onProgress
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: ["lodash", "react"],
onProgress(current, total, packageName) {
process.stderr.write(`${current}/${total} ${packageName}\n`);
},
});
+1/2 lodash
+2/2 react
- Changed line — The callback writes a progress line for each package.
(current, total, packageName) => void. Follow version resolution, for example to update a terminal progress display.
onBeforeOutput
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
onBeforeOutput() { process.stderr.clearLine?.(0); },
});
+ onBeforeOutput() { process.stderr.clearLine?.(0); },
- Changed line — This clears the terminal progress line before the table prints.
() => void. Called before check output such as the dependency table. A terminal integration can clear its progress line here.
isCLI
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
isCLI: true,
format: "json",
});
+ isCLI: true,
- Changed line — An outdated result sets the process exit code to 1.
boolean, default false. Used by CLI integrations. A deferred mismatch on a check can set process.exitCode to 1.
onDeferredFailure
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
isCLI: true,
format: "json",
onDeferredFailure() { process.stderr.write("Dependency update required\n"); },
});
+Dependency update required
- Changed line — The callback prints this message when CLI mode defers a mismatch.
() => void. Called for an outdated CLI-mode check when failure is deferred. An integration can use it to record the failure before the process exits.
isTesting
Run node example.mjs.
import { checkFiles } from "codependence";
await checkFiles({
codependencies: [{ lodash: "4.17.21" }],
isTesting: true,
update: true,
});
update: true,
+ isTesting: true,
- Changed line — The fixture keeps its original lodash declaration.
boolean, default false. Use the library’s test path to suppress file writes and interactive prompts. Version resolution can also differ in this mode.
TypeScript callers can import CheckFiles and VersionDiff as types. CommonJS callers can use const { checkFiles } = require("codependence").