Skip to content

Instantly share code, notes, and snippets.

@arminrosu
Created May 9, 2021 11:23
Show Gist options
  • Save arminrosu/fd18e16346c37b8df7d4b0a26154654a to your computer and use it in GitHub Desktop.
Save arminrosu/fd18e16346c37b8df7d4b0a26154654a to your computer and use it in GitHub Desktop.
List @types/ to dependency version mismatches
// @TODO Validate new version exists
// @TODO Validate installed versions satisfy each other before reporting
const package = require('./package.json')
const deps = package.dependencies
const devDeps = package.devDependencies
const allDeps = {
...deps,
...devDeps
}
const typeDeps = Object.fromEntries(Object.entries(allDeps).filter(([key, value]) => key.startsWith('@types/')))
const updates = []
function cleanVersion(version) {
return version
.replace('^', '')
.replace('~', '')
}
Object.entries(typeDeps).forEach(([key, version]) => {
const typeDepName = key
const typeVersion = cleanVersion(version)
const moduleDepName = key
.replace('@types/', '')
const moduleDepVersion = moduleDepName && allDeps[moduleDepName] && cleanVersion(allDeps[moduleDepName])
if (moduleDepName && moduleDepVersion !== typeVersion) {
console.log(`Version mismatch: ${typeDepName}@${typeVersion} vs ${moduleDepName}@${moduleDepVersion}`)
updates.push(`${typeDepName}@${moduleDepVersion}`)
}
})
if (updates.length > 0) {
console.log(`🐛 Found ${updates.length} mismatches`)
updates.forEach((v) => {
console.log(`npm install ${v}`)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment