-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
yarn.config.cjs
81 lines (72 loc) · 2.34 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
76
77
78
79
80
81
// @ts-check
/**
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Context} Context
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Workspace} Workspace
*/
/**
* This rule will enforce that a workspace MUST depend on the same version of a dependency as the one used by the other workspaces
* @param {Context} context
*/
const 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;
if (
(dependency.type === "devDependencies" ||
otherDependency.type === "devDependencies") &&
Yarn.workspace({ ident: otherDependency.ident })
)
continue;
dependency.update(otherDependency.range);
}
}
};
/**
* @param {Context} context
* @param {Record<string, ((workspace: Workspace) => any) | string>} fields
*/
const enforceFieldsOnAllWorkspaces = ({ Yarn }, fields) => {
for (const workspace of Yarn.workspaces()) {
for (const [field, value] of Object.entries(fields)) {
workspace.set(
field,
typeof value === "function" ? value(workspace) : value,
);
}
}
};
/**
* @param {Context} context
*/
const enforcePublishingConfig = ({ Yarn }) => {
for (const workspace of Yarn.workspaces()) {
if (workspace.manifest.private) continue;
workspace.set("publishConfig", {
access: "public",
provenance: true,
registry: "https://registry.npmjs.org",
});
}
};
/** @type {import('@yarnpkg/types').Yarn.Config} */
module.exports = {
constraints: async (context) => {
enforceFieldsOnAllWorkspaces(context, {
"bugs.url": "https://github.com/catppuccin/vscode/issues",
homepage: ({ cwd }) => {
if (cwd === ".") return;
return `https://github.com/catppuccin/vscode/tree/main/${cwd}#readme`;
},
license: "MIT",
"repository.directory": (workspace) => workspace.cwd,
"repository.type": "git",
"repository.url": "https://github.com/catppuccin/vscode.git",
"sponsor.url": "https://opencollective.com/catppuccin",
});
enforceConsistentDependenciesAcrossTheProject(context);
enforcePublishingConfig(context);
},
};