-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathyarn.config.cjs
More file actions
145 lines (131 loc) · 3.77 KB
/
Copy pathyarn.config.cjs
File metadata and controls
145 lines (131 loc) · 3.77 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* The constraints defined in https://github.com/babel/babel/blob/main/yarn.config.cjs were used as a starting
* point for this file, see also: https://yarnpkg.com/features/constraints
*/
/** @type {import('@yarnpkg/types')} */
const {defineConfig} = require("@yarnpkg/types");
/**
* Enforces consistent package metadata
*/
function enforcePackageInfo({Yarn}) {
for (const workspace of Yarn.workspaces()) {
if (workspace.manifest.private) {
continue;
}
const info = {
author: "Embrace <support@embrace.io> (https://embrace.io/)",
bugs: {
url: "https://github.com/embrace-io/embrace-react-native-sdk/issues",
email: "support@embrace.io",
},
homepage: "https://github.com/embrace-io/embrace-react-native-sdk",
license: "Apache-2.0",
repository: {
type: "git",
url: "https://github.com/embrace-io/embrace-react-native-sdk",
directory: workspace.cwd,
},
publishConfig: {
access: "public",
},
};
for (const key of Object.keys(info)) {
if (workspace.manifest.private) {
workspace.unset(key);
} else {
workspace.set(key, info[key]);
}
}
if (workspace.manifest.private) {
workspace.unset("keywords");
} else {
workspace.set("keywords", [
...new Set([
...(workspace.manifest.keywords || []),
"embrace",
"react-native",
"tracking",
"observability",
"instrumentation",
"telemetry",
"bug tracker",
]),
]);
}
}
}
/**
* Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
*/
function enforceNoDualTypeDependencies({Yarn}) {
for (const dependency of Yarn.dependencies({type: "devDependencies"})) {
const otherDependency = Yarn.dependency({
workspace: dependency.workspace,
ident: dependency.ident,
type: "dependencies",
});
if (otherDependency !== null) {
dependency.delete();
}
}
}
/**
* Enforces each package having a peerDependency on React Native
*/
function enforceReactNativePeerDependency({Yarn}) {
for (const dependency of Yarn.dependencies({ident: "react-native"})) {
if (dependency.type === "peerDependencies") {
dependency.update(">=0.56.0");
}
}
}
/**
* Enforces each package having a common typescript version
*/
function enforceCommonTypescript({Yarn}) {
for (const dependency of Yarn.dependencies({ident: "typescript"})) {
dependency.update("^5.6.3");
}
}
/**
* Enforces that a workspace MUST depend on the same version of a dependency as the one used by the other workspaces
* Taken from: https://yarnpkg.com/features/constraints
*/
function enforceConsistentDependenciesAcrossTheProject({Yarn}) {
for (const dependency of Yarn.dependencies()) {
const isPeer = dependency.type === "peerDependencies";
for (const otherDependency of Yarn.dependencies({
ident: dependency.ident,
})) {
const isOtherPeer = otherDependency.type === "peerDependencies";
if (isPeer !== isOtherPeer) {
continue;
}
dependency.update(otherDependency.range);
}
}
}
/**
* Enforces each package having the same Embrace metadata
*/
function enforceEmbraceMetadata({Yarn}) {
for (const workspace of Yarn.workspaces()) {
if (workspace.manifest.private) {
continue;
}
workspace.set("embrace", {
iosVersion: "6.19.0",
androidVersion: "8.4.0",
});
}
}
module.exports = defineConfig({
constraints: async ctx => {
enforcePackageInfo(ctx);
enforceNoDualTypeDependencies(ctx);
enforceConsistentDependenciesAcrossTheProject(ctx);
enforceEmbraceMetadata(ctx);
enforceReactNativePeerDependency(ctx);
enforceCommonTypescript(ctx);
},
});