-
Notifications
You must be signed in to change notification settings - Fork 387
/
yarn.config.cjs
36 lines (31 loc) · 1.01 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
// @ts-check
/**
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Workspace} Workspace
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Dependency} Dependency
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Context} Context
*/
/** @type {import('@yarnpkg/types')} */
const { defineConfig } = require('@yarnpkg/types');
/**
* 这条规则将强制工作区必须依赖于与其他工作区所使用的相同版本的依赖项。
*
* @param {Context} context
*/
function enforceConsistentDependenciesAcrossTheProject({ Yarn }) {
for (const dependency of Yarn.dependencies()) {
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({
constraints: async (ctx) => {
enforceConsistentDependenciesAcrossTheProject(ctx);
},
});