Last active
March 14, 2018 04:14
-
-
Save martinwheeler/ee7dc68a506cf5c6e70f0d37c1327207 to your computer and use it in GitHub Desktop.
Find the difference between your package.json and yarn.lock versions
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 fs = require('fs'); | |
const path = require('path'); | |
const dependencies = require('../package.json').dependencies; | |
const devDependencies = require('../package.json').devDependencies; | |
const yarnFile = fs.readFileSync(path.join(__dirname, '../yarn.lock'), 'utf8'); | |
// Grabs the version from package.json file | |
const versionRegexp = new RegExp(/[0-9]+\.[0-9]+\.[0-9]+(\-(beta|rc).*)?/i); | |
function logDifferingVersions (dependencyObject) { | |
Object.keys(dependencyObject).map((key) => { | |
const packageName = key; | |
const packageVersion = versionRegexp.exec(dependencyObject[key])[0]; | |
const regExpSafeName = packageName.replace(/\//g, '\\/'); | |
const yarnLockRegExp = new RegExp(`\\n"?${regExpSafeName}@.*\\n.*version\\s?"(.*)"`, 'i'); | |
const foundYarnVersions = yarnLockRegExp.exec(yarnFile); | |
const yarnLockVersion = foundYarnVersions[foundYarnVersions.length - 1]; | |
if (yarnLockVersion !== packageVersion) { | |
console.group(packageName) | |
console.log('\x1b[36m%s\x1b[0m', `yarn.lock: ${yarnLockVersion}`); | |
console.log('\x1b[31m%s\x1b[0m', `package.json: ${packageVersion}`); | |
console.groupEnd(); | |
} | |
}); | |
} | |
logDifferingVersions(dependencies); | |
logDifferingVersions(devDependencies); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment