-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
yarn.config.cjs
75 lines (64 loc) · 2.37 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
70
71
72
73
74
75
/*
* (c) Copyright 2024 Palantir Technologies Inc. All rights reserved.
*/
// @ts-check
/** @type {import('@yarnpkg/types')} */
const { defineConfig } = require("@yarnpkg/types");
/**
* @typedef {import("@yarnpkg/types").Yarn.Constraints.Context} Context
*/
/**
* Packages which we need to ensure the declared version range is fixed for backwards-compatibility.
*/
const FIXED_DEPENDENCY_RANGES = {
// newer versions of classnames require esModuleInterop, see https://github.com/palantir/blueprint/pull/5687
classnames: "^2.3.1",
// 2.29.0+ has some potential bundle size regressions, and we are due to upgrade to 3.0 soon anyway
"date-fns": "^2.28.0",
};
/**
* Packages which are allowed to exist as dependencies of various packages with different version ranges.
*/
const EXCLUDED_FROM_CONSISTENCY_CHECK = new Set([
// we support multiple versions of react-day-picker: v7 in datetime and v8 in datetime2
"react-day-picker",
// tooling packages declare a wider dependency range in 'dependencies' & 'peerDependencies' than our local 'devDependencies'
"typescript",
...Object.keys(FIXED_DEPENDENCY_RANGES),
]);
function enforceSpecificDependencyRanges({ Yarn }) {
for (const [ident, range] of Object.entries(FIXED_DEPENDENCY_RANGES)) {
for (const dependency of Yarn.dependencies({ ident })) {
dependency.update(range);
}
}
}
/**
* This rule will enforce that a workspace MUST depend on the same version of
* a dependency as the one used by the other workspaces.
*
* @see https://yarnpkg.com/features/constraints#restrict-dependencies-between-workspaces
* @param {Context} context
*/
function enforceConsistentDependenciesAcrossTheProject({ Yarn }) {
for (const dependency of Yarn.dependencies()) {
if (EXCLUDED_FROM_CONSISTENCY_CHECK.has(dependency.ident)) {
continue;
}
if (dependency.type === `peerDependencies`) {
continue;
}
for (const otherDependency of Yarn.dependencies({ ident: dependency.ident })) {
if (otherDependency.type === `peerDependencies`) {
continue;
}
dependency.update(otherDependency.range);
}
}
}
module.exports = defineConfig({
async constraints(ctx) {
enforceSpecificDependencyRanges(ctx);
enforceConsistentDependenciesAcrossTheProject(ctx);
},
});