-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathrenovate-config-generator.mjs
209 lines (197 loc) · 5.55 KB
/
renovate-config-generator.mjs
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import fs from 'fs-extra';
import { globby } from 'globby';
import JSON5 from 'json5';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIR = path.join(__dirname, '..');
const rules = new Map();
/**
* @typedef PackageRule
* @property {string} [groupName]
* @property {string} [commitMessageTopic]
* @property {string} [groupSlug]
* @property {string[]} [matchFileNames]
* @property {string[]} [matchUpdateTypes]
* @property {string[]} [matchDepTypes]
* @property {string[]} [matchPackageNames]
* @property {string[]} [matchPackagePatterns]
* @property {boolean} [automerge]
* @property {boolean} [dependencyDashboardApproval]
* @property {string} [additionalBranchPrefix]
* @property {boolean} [enabled]
*/
/**
* @type {Array.<PackageRule>}
*/
const defaultRules = [
{
matchManagers: ['npm'],
matchDepTypes: ['engines'],
matchPackageNames: ['node'],
enabled: false,
},
// Don't bump @clerk/ packages since changesets will handle this
{
matchPackagePatterns: ['^@clerk/'],
enabled: false,
},
{
groupName: 'Clerk monorepo',
groupSlug: 'clerk-monorepo',
matchFileNames: ['+(package.json)'],
matchDepTypes: ['devDependencies'],
matchUpdateTypes: ['major', 'minor', 'patch'],
dependencyDashboardApproval: false,
commitMessageTopic: 'Dependencies for Clerk Monorepo',
},
{
groupName: 'ESLint',
matchPackageNames: [
'@eslint/{/,}**',
'@types/eslint',
'@stylistic/eslint-plugin{/,}**',
'@types/eslint__{/,}**',
'@typescript-eslint/{/,}**',
'eslint{/,}**',
'typescript-eslint{/,}**',
],
},
{
groupName: 'linting & formatting',
matchPackageNames: [
'prettier',
'publint',
'@arethetypeswrong/cli',
'@commitlint/cli',
'@commitlint/config-conventional',
],
},
{
groupName: 'testing',
matchPackageNames: [
'@types/chai',
'@types/jest',
'@types/sinon',
'nock',
'nyc',
'ts-jest',
'vitest',
'@testing-library{/,}**',
'@types/testing-library__{/,}**',
'@vitest{/,}**',
'chai{/,}**',
'jest{/,}**',
'qunit{/,}**',
'should{/,}**',
'sinon{/,}**',
'@playwright{/,}**',
],
},
{
groupName: 'TypeScript',
matchPackageNames: ['typescript'],
rangeStrategy: 'bump',
},
{
groupName: 'common TypeScript types',
matchPackageNames: ['@types/node'],
rangeStrategy: 'bump',
},
{
extends: ['monorepo:remix'],
groupName: 'Remix monorepo',
matchUpdateTypes: ['patch', 'minor', 'major'],
},
];
const getPackageNames = async () => {
const files = await globby('./packages/*/package.json', { cwd: ROOT_DIR });
let names = [];
for (const file of files) {
const content = await fs.readFile(file, 'utf8');
const json = JSON.parse(content);
names.push(json.name.split('/').pop());
}
// Sort alphabetically to make the output stable
return names.sort();
};
const packageNames = await getPackageNames();
for (const pkg of packageNames) {
/**
* @type {Array.<PackageRule>}
*/
const pkgRules = [
{
groupName: `[DEV] minor & patch dependencies`,
groupSlug: `${pkg}-dev-minor`,
matchFileNames: [`packages/${pkg}/package.json`],
matchDepTypes: [`devDependencies`],
matchUpdateTypes: [`patch`, `minor`],
automerge: true,
semanticCommitScope: pkg,
},
{
groupName: `[DEV] major dependencies`,
groupSlug: `${pkg}-dev-major`,
matchFileNames: [`packages/${pkg}/package.json`],
matchDepTypes: [`devDependencies`],
matchUpdateTypes: [`major`],
semanticCommitScope: pkg,
},
{
groupName: `minor & patch dependencies`,
groupSlug: `${pkg}-prod-minor`,
matchFileNames: [`packages/${pkg}/package.json`],
matchDepTypes: [`dependencies`],
matchUpdateTypes: [`patch`, `minor`],
semanticCommitScope: pkg,
},
{
groupName: `major dependencies`,
groupSlug: `${pkg}-prod-major`,
matchFileNames: [`packages/${pkg}/package.json`],
matchDepTypes: [`dependencies`],
matchUpdateTypes: [`major`],
semanticCommitScope: pkg,
},
];
rules.set(pkg, pkgRules);
}
const renovateConfig = {
commitMessageLowerCase: 'never',
extends: [
':combinePatchMinorReleases',
':dependencyDashboard',
':disablePeerDependencies',
':enableVulnerabilityAlerts',
':ignoreModulesAndTests',
':ignoreUnstable',
':label(dependencies)',
':maintainLockFilesDisabled',
':prImmediately',
':semanticPrefixFixDepsChoreOthers',
':separateMajorReleases',
'group:monorepos',
'group:recommended',
],
ignorePaths: ['**/node_modules/**', '.nvmrc', 'integration/templates/**', 'playground/**'],
includePaths: ['package.json', 'packages/**', 'pnpm-workspace.yaml'],
major: { dependencyDashboardApproval: true },
minimumReleaseAge: '3 days',
nvm: { enabled: false },
packageRules: Array.from(rules.values()).flat().concat(defaultRules),
postUpdateOptions: ['pnpmDedupe'],
prConcurrentLimit: 16,
prCreation: 'immediate',
prHourlyLimit: 4,
rangeStrategy: 'bump',
schedule: ['before 7am on the first day of the week'],
semanticCommitScope: 'repo',
timezone: 'GMT',
updateNotScheduled: false,
};
await fs.writeFile(
path.join(ROOT_DIR, 'renovate.json5'),
'// This file is automatically generated. Do not edit directly but run the "renovate-config-generator.mjs" script.\n' +
JSON5.stringify(renovateConfig, { quote: `"`, space: 2 }),
);