2023-06-05 03:30:48 +03:00
|
|
|
import semver from 'semver'
|
2023-06-04 20:00:33 +03:00
|
|
|
import { fileURLToPath } from 'url'
|
2023-06-05 03:30:48 +03:00
|
|
|
|
2023-06-04 20:00:33 +03:00
|
|
|
import { getPackageJsons } from './utils.mjs'
|
|
|
|
|
|
|
|
export async function validateDepsVersions() {
|
2024-03-18 03:08:07 +03:00
|
|
|
const packageJsons = await getPackageJsons(true)
|
2023-06-04 20:00:33 +03:00
|
|
|
|
|
|
|
const versions = {}
|
|
|
|
const errors = []
|
|
|
|
|
|
|
|
packageJsons.forEach((json) => {
|
|
|
|
function check(key) {
|
|
|
|
const deps = json[key]
|
|
|
|
if (!deps) return
|
|
|
|
|
|
|
|
Object.entries(deps).forEach(([depName, depVersions]) => {
|
|
|
|
if (depName.startsWith('@mtcute/')) return
|
|
|
|
|
|
|
|
if (!versions[depName]) {
|
|
|
|
versions[depName] = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.entries(versions[depName]).forEach(([pkgName, pkgDepVersions]) => {
|
|
|
|
if (!semver.satisfies(depVersions, pkgDepVersions)) {
|
|
|
|
errors.push(
|
2023-06-05 03:30:48 +03:00
|
|
|
`- at ${json.name} -> ${key} has ${depName}@${depVersions}, but ${pkgName} has @${pkgDepVersions}`,
|
2023-06-04 20:00:33 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
versions[depName][json.name] = depVersions
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
check('dependencies')
|
|
|
|
check('devDependencies')
|
|
|
|
check('peerDependencies')
|
|
|
|
check('optionalDependencies')
|
|
|
|
})
|
|
|
|
|
|
|
|
if (errors.length > 0) {
|
|
|
|
console.log('⚠️ Found external dependencies mismatch:')
|
|
|
|
errors.forEach((err) => console.log(err))
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('✅ All external dependencies match!')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (import.meta.url.startsWith('file:')) {
|
2023-06-05 03:30:48 +03:00
|
|
|
const modulePath = fileURLToPath(import.meta.url)
|
|
|
|
|
2023-06-04 20:00:33 +03:00
|
|
|
if (process.argv[1] === modulePath) {
|
|
|
|
validateDepsVersions().catch(console.error)
|
|
|
|
}
|
2023-06-05 03:30:48 +03:00
|
|
|
}
|