Upgrade versions in a package.json by referencing dependencies from other projects.
- Reads the
dependenciesanddevDependenciesfields from the list of inputpackage.jsonfiles. - Builds a map of the highest version string seen for each dependency using JavaScript's string comparison (lexicographic order). This means
"9.0.0"is considered higher than"10.0.0"in the current implementation, which may not match semver expectations. - Updates the target
package.jsonin place for any matching dependencies/devDependencies.
Provide one or more package.json files to read from and a --target file to update:
# Using bun (can run TypeScript directly)
bun main.ts ../project-a/package.json ../project-b/package.json --target ./package.json
# Using ts-node
npm install
npx ts-node main.ts ../project-a/package.json --target ./package.jsonThe target file is rewritten with updated version strings.
To install this as a local CLI command on your machine:
- run
bun run compilethis will create a
version-matchexecutable for you - move executable into your $PATH.
-
Build the TypeScript file to JavaScript:
npx --yes typescript@5.3.3 tsc main.ts --outDir dist --module commonjs --target es2020
-
Add a Node shebang and make the output executable:
printf '#!/usr/bin/env node\n' | cat - dist/main.js > dist/version-match chmod +x dist/version-match
-
Point a CLI name to the executable and link it locally:
npm pkg set bin.version-match=dist/version-match npm link
After linking, you can run version-match --target ./package.json <other package.json files> from anywhere.