1
1
mirror of https://github.com/primer/css.git synced 2024-12-01 04:21:12 +03:00
css/script/check-versions
2017-10-10 21:28:45 -07:00

63 lines
1.6 KiB
JavaScript
Executable File

#!/usr/bin/env node
const globby = require('globby')
const lernaConfig = require('../lerna.json')
const DEP_FIELDS = [
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies',
]
globby(lernaConfig.packages)
.then(paths => {
return paths.reduce((packages, path) => {
try {
const pkg = require(`../${path}/package.json`)
pkg.path = path
packages.push(pkg)
} catch (error) {
}
return packages
}, [])
})
.then(packages => {
console.log('⏱ checking %d packages...', packages.length)
const map = new Map()
const matches = []
packages.forEach(pkg => map.set(pkg.name, pkg))
packages.forEach(pkg => {
DEP_FIELDS
.filter(field => field in pkg)
.forEach(field => {
const deps = pkg[field]
Object.keys(deps)
.filter(dep => map.has(dep))
.forEach(dep => {
const expected = map.get(dep).version
const actual = deps[dep]
if (expected !== actual) {
throw new Error(
`${pkg.name}.${field} has bad version for ${dep}: ${expected} != ${actual}`
)
} else {
matches.push({
from: pkg.name,
to: dep,
field,
version: expected
})
}
})
})
})
return matches
})
.catch(error => {
console.error(error.message)
process.exit(1)
})
.then(matches => {
console.warn('✅ checked %d matching version dependencies', matches.length)
})