Examples
Reproduce a failing npm dependency check and update a Docker base image.
Catch a mismatched package version
Start in an empty directory with these two files. The app declares lodash 4.17.20, but the project requires 4.17.21.
{
"name": "web-app",
"private": true,
"dependencies": { "lodash": "4.17.20" }
}
{
"config": {
"web": {
"path": "package.json",
"manager": "npm",
"codependencies": [{ "lodash": "4.17.21" }]
}
}
}
- Manifest — This path selects the package.json beside the config file.
- Required version — The check compares the declared lodash version with 4.17.21. Other packages are outside this rule.
Run the check from that directory. The output lists lodash with current version 4.17.20 and available version 4.17.21. The exit status is 1.
npx codependence
Apply the update, then run the same check again.
npx codependence --update
npx codependence
The second check exits with status 0. Codependence updates lodash and fills in the empty dependency sections.
"name": "web-app",
"private": true,
- "dependencies": { "lodash": "4.17.20" }
+ "dependencies": {
+ "lodash": "4.17.21"
+ },
+ "devDependencies": {},
+ "peerDependencies": {},
+ "optionalDependencies": {}
- Lodash version — The manifest now declares the exact version required by the policy.
Update a Docker base image
In a second directory, create a Dockerfile that takes its Alpine version from a build argument.
ARG ALPINE_VERSION=3.19
FROM alpine:${ALPINE_VERSION}
RUN cat /etc/alpine-release
Save this policy alongside it. The docker manager checks the base image declaration. You can run the example without building an image.
{
"config": {
"container": {
"path": "Dockerfile",
"manager": "docker",
"codependencies": [{ "alpine": "3.20" }]
}
}
}
Preview the change. The CLI reports 3.19 and 3.20 and leaves the Dockerfile untouched.
npx codependence --target docker --update --dryRun
Apply it and check the result.
npx codependence --target docker --update
npx codependence --target docker
-ARG ALPINE_VERSION=3.19
+ARG ALPINE_VERSION=3.20
FROM alpine:${ALPINE_VERSION}
RUN cat /etc/alpine-release
- Updated tag — The FROM instruction reads this build argument. The next build uses Alpine 3.20.
See all CLI and configuration options.