-
Notifications
You must be signed in to change notification settings - Fork 0
/
yarn.config.cjs
69 lines (59 loc) · 2.19 KB
/
yarn.config.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/** @type {import('@yarnpkg/types')} */
const { defineConfig } = require('@yarnpkg/types')
const { compareVersions } = require('compare-versions')
const workspaceCheckExclusions = []
const dependencyCheckExclusions = []
module.exports = defineConfig({
async constraints({ Yarn }) {
const hasFixFlag = process.argv.some((arg) => arg === '--fix')
// Ensure all workspaces use the same node version and yarn version
for (const workspace of Yarn.workspaces()) {
if (workspaceCheckExclusions.includes(workspace.manifest.name)) {
continue
}
workspace.set('engines.node', `>=18.18.0`)
workspace.set('packageManager', `yarn@4.4.0`)
}
// Collect all dependencies and their versions into a Map<string, Set<string>>
const dependencyToVersions = {}
for (const workspace of Yarn.workspaces()) {
const {
devDependencies = {},
peerDependencies = {},
dependencies = {},
} = workspace.manifest
;[devDependencies, peerDependencies, dependencies].forEach(
(dependencies_) => {
Object.entries(dependencies_).forEach(([name, version]) => {
if (dependencyCheckExclusions.includes(name)) {
return
}
if (name in dependencyToVersions) {
dependencyToVersions[name].add(version)
} else {
dependencyToVersions[name] = new Set([version])
}
})
},
)
}
// Check if a dependency has multiple versions
// If so, update all dependencies to the latest version
Object.entries(dependencyToVersions).forEach(([name, versions]) => {
if (versions.size > 1) {
const sortedVersions = Array.from(versions).sort(compareVersions)
const latestVersion = sortedVersions[sortedVersions.length - 1]
if (!hasFixFlag) {
console.log(
`🚨 ${name} has multiple versions: ${Array.from(versions).join(
', ',
)}. Run yarn constraints --fix to update to ${latestVersion}.\n`,
)
}
Yarn.dependencies({ ident: name }).forEach((dependency) => {
dependency.update(latestVersion)
})
}
})
},
})