Skip to content

Instantly share code, notes, and snippets.

@simon360
Created April 20, 2018 11:58
Show Gist options
  • Save simon360/a419ded3d0279384efb2538b64d789d7 to your computer and use it in GitHub Desktop.
Save simon360/a419ded3d0279384efb2538b64d789d7 to your computer and use it in GitHub Desktop.
Compare different package.json files in a monorepo to see if dependency versions differ
const chalk = require("chalk");
const packages = [
require("./package.json"),
require("./packages/cec-scripts/package.json"),
require("./packages/generator-cec/package.json"),
require("./packages/utility-cec-simulator/package.json")
];
const compareDeps = p => {
console.log(`Comparing ${chalk.cyan(p.name)}`);
console.log();
const pDependencies = {
...(p.dependencies || {}),
...(p.devDependencies || {})
};
for (const p2 of packages) {
if (p2.dependencies) {
const p2Dependencies = {
...p2.dependencies,
...p2.devDependencies
};
for (const d of Object.keys(p2Dependencies)) {
if (pDependencies[d] && pDependencies[d] !== p2Dependencies[d]) {
console.log(`* Dependency ${chalk.yellow(d)} differs:
${chalk.cyan(p.name)}: ${chalk.green(pDependencies[d])}
${chalk.cyan(p2.name)}: ${chalk.green(p2Dependencies[d])}`);
}
}
}
}
console.log();
console.log();
};
while (packages.length > 0) {
console.log();
const p = packages.pop();
compareDeps(p);
}
@yoni333
Copy link

yoni333 commented Nov 9, 2023

great script. thank you

@coolcorexix
Copy link

love it man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment