Created
April 20, 2018 11:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great script. thank you