-
Notifications
You must be signed in to change notification settings - Fork 620
Expand file tree
/
Copy pathyarn.config.cjs
More file actions
93 lines (82 loc) · 2.76 KB
/
yarn.config.cjs
File metadata and controls
93 lines (82 loc) · 2.76 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/** @type {import('@yarnpkg/types')} */
const { defineConfig } = require('@yarnpkg/types')
const DEPS_TO_CHECK = [
'typescript',
'react',
'redux',
'react-redux',
'@reduxjs/toolkit',
'eslint',
'prettier',
'jest',
'jest-fixed-jsdom',
'msw',
'date-fns',
'@ledgerhq/context-module',
'@ledgerhq/device-management-kit',
'@ledgerhq/device-signer-kit-ethereum',
'@types/jest',
'@safe-global/protocol-kit',
'@safe-global/safe-apps-sdk',
'@safe-global/safe-deployments',
'@safe-global/safe-modules-deployments',
'@cowprotocol/app-data',
]
/**
* Detect and report different versions of specified dependencies across workspaces
*
* @param {Context} context
* @param {string[]} depsToCheck - Array of dependency names to check
*/
function detectInconsistentVersions({ Yarn }, depsToCheck = DEPS_TO_CHECK) {
const inconsistentDeps = new Map()
for (const depName of depsToCheck) {
const depVersions = new Map()
// Collect all dependencies of this type across workspaces
for (const dependency of Yarn.dependencies({ ident: depName })) {
if (dependency.type === `peerDependencies`) continue
// Try different ways to get the workspace name
let workspaceName = 'unknown'
if (dependency.workspace) {
workspaceName =
dependency.workspace.manifest?.name ||
dependency.workspace.locator?.name ||
dependency.workspace.cwd?.split('/').pop() ||
dependency.workspace.anchoredDescriptor?.name ||
'root'
} else {
workspaceName = 'root'
}
const version = dependency.range
if (!depVersions.has(version)) {
depVersions.set(version, [])
}
depVersions.get(version).push(workspaceName)
}
// Only report if there are inconsistencies
if (depVersions.size > 1) {
inconsistentDeps.set(depName, depVersions)
} else if (depVersions.size === 1) {
const [version, workspaces] = depVersions.entries().next().value
console.log(`✅ ${depName} version ${version} is consistent across ${workspaces.length} workspace(s)`)
}
}
// Report inconsistencies
if (inconsistentDeps.size > 0) {
console.log('\n🔍 Version inconsistencies detected:')
for (const [depName, versions] of inconsistentDeps.entries()) {
console.log(`\n📦 ${depName}:`)
for (const [version, workspaces] of versions.entries()) {
console.log(` - ${version}: ${workspaces.join(', ')}`)
}
}
console.log('\n⚠️ Consider standardizing these dependency versions across all workspaces.\n')
} else {
console.log('\n✅ All specified dependencies have consistent versions across workspaces.\n')
}
}
module.exports = defineConfig({
constraints: async (ctx) => {
detectInconsistentVersions(ctx)
},
})