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

71 lines
1.9 KiB
Plaintext
Raw Normal View History

2017-10-11 07:28:45 +03:00
#!/usr/bin/env node
2018-10-25 23:21:19 +03:00
const getPackages = require('./get-packages')
2017-10-11 07:28:45 +03:00
const DEP_FIELDS = [
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies',
]
2018-10-25 23:21:19 +03:00
getPackages()
2017-10-11 07:28:45 +03:00
.then(paths => {
return paths.reduce((packages, path) => {
2018-10-25 23:21:19 +03:00
const pkg = require(`../${path}/package.json`)
packages[pkg.name] = pkg
2017-10-11 07:28:45 +03:00
return packages
2018-10-25 23:21:19 +03:00
}, {})
2017-10-11 07:28:45 +03:00
})
.then(packages => {
2018-10-25 23:21:19 +03:00
console.log('checking %d packages...', Object.keys(packages).length)
2017-10-11 07:28:45 +03:00
const matches = []
2018-10-25 23:21:19 +03:00
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
2017-10-11 07:28:45 +03:00
})
2018-10-25 23:21:19 +03:00
}
}
}
}
2017-10-11 07:28:45 +03:00
return matches
})
2018-10-25 23:21:19 +03:00
.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)
}
})
2017-10-11 07:28:45 +03:00
.catch(error => {
console.error(error.message)
2018-10-25 23:21:19 +03:00
process.exitCode = 1
2017-10-11 07:28:45 +03:00
})