mirror of
https://github.com/primer/css.git
synced 2024-11-24 13:15:00 +03:00
add version check script
This commit is contained in:
parent
2c7e1ac79d
commit
07a6560686
62
script/check-versions
Executable file
62
script/check-versions
Executable file
@ -0,0 +1,62 @@
|
||||
#!/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)
|
||||
})
|
Loading…
Reference in New Issue
Block a user