1
1
mirror of https://github.com/primer/css.git synced 2024-11-30 01:04:04 +03:00
css/script/check-versions
2018-11-13 15:23:19 -08:00

71 lines
1.9 KiB
JavaScript
Executable File

#!/usr/bin/env node
const getPackages = require('./get-packages')
const DEP_FIELDS = [
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies',
]
getPackages()
.then(paths => {
return paths.reduce((packages, path) => {
const pkg = require(`../${path}/package.json`)
packages[pkg.name] = pkg
return packages
}, {})
})
.then(packages => {
console.log('checking %d packages...', Object.keys(packages).length)
const matches = []
for (const [name, pkg] of Object.entries(packages)) {
for (const field of DEP_FIELDS) {
const deps = pkg[field]
if (deps instanceof Object) {
const keys = Object.keys(deps).filter(dep => dep in packages)
for (const dep of keys) {
const version = deps[dep]
let match = false
const expected = packages[dep].version
if (version.indexOf('file:') === 0) {
console.warn(`${name}.${field}.${dep} uses file specifier: "${version}"`)
match = true
} else {
match = expected === version
}
matches.push({
from: name,
to: dep,
field,
version,
expected,
match
})
}
}
}
}
return matches
})
.then(matches => {
let fail = 0
for (const item of matches) {
if (!item.match) {
const {from, to, field, expected, version} = item
console.warn(`X ${from}.${field}.${to} is "${version}", but should be "${expected}"`)
fail++
}
}
if (fail > 0) {
console.error('failed %d of %d cross-dependencies', failed, matches.length)
process.exitCode = 1
} else {
console.warn('all %d cross-dependencies checked out!', matches.length)
}
})
.catch(error => {
console.error(error.message)
process.exitCode = 1
})