
Keeping dependencies up to date is important for every codebase, and there are a few strategies for Lerna monorepos.
I migrated 15 Node.js projects to a Lerna monorepo earlier this year for easier maintenance and then let it stagnate because so few people are using the packages. The projects previously had a Renovate config that would automatically bump the patch version & publish to npm once a month, and I wanted to bring that back.

Migrating Existing Repos to a Lerna Monorepo
Feb 20, 2023 · 9 min read
As of writing, I maintain 15 Metalsmith plugins, and it has become a pain to manage all of them independently.
Here's the methodology I used, and some alternatives you could consider.
My situation
My requirements for a new Renovate setup were:
- Separate versions - all packages have separate versions from before they were migrated to a monorepo, and I want to keep them separate for semver reasons
- Automated releases - I want updates to dependencies (and not dev dependencies) to bump each package's patch version, such that they will be automatically published to npm
- Minimal oversight - I haven't been investing in these packages due to their low usage, so I want their ongoing maintenance to be as automated as possible
- Limited schedule - to reduce the potential spam of new versions being published to npm, I want to limit automated version bumps to once a month
Strategy: grouping dependency types
My packages share a lot of the same libraries, especially dev dependencies such as Jest and ESLint . Each package has its own package.json that contains out these libraries and their version range.
By default, Renovate will create one pull request per library being updated, and every usage of that library will be updated at once. That means only a single pull request would be opened for a single ESLint update, and it would update every package.json file at once.
That's great, that's what I want! That keeps the amount of pull requests being created to a minimum, and I'd rather every Lerna package have the same library versions. But that can still be a lot of pull request spam if you make use of a lot of libraries.
I like grouping by dependency types (dependency, dev dependency, peer dependency, etc.), with major version updates of any kind always being in their own pull request. This type of grouping runs the risk of a single faulty patch or minor version update holding back updates to other libraries, but that's acceptable to me.
The Renovate config for that would look something like this:
1{
2 $schema: 'https://docs.renovatebot.com/renovate-schema.json',
3 extends: ['config:recommended'],
4
5 // If multiple major updates are available, create a separate pull request for each
6 separateMultipleMajor: true,
7
8 npm: {
9 packageRules: [
10 // Dependencies
11 {
12 // Group non-major dependency updates together
13 groupName: 'dependencies',
14 matchDepTypes: ['dependencies'],
15 matchUpdateTypes: ['patch', 'minor']
16 },
17
18 // Dev dependencies
19 {
20 // Group non-major devDependencies together
21 matchDepTypes: ['devDependencies'],
22 groupName: 'dev dependencies',
23 matchUpdateTypes: ['patch', 'minor']
24 },
25 {
26 // Group ESLint together
27 matchPackagePatterns: [
28 '^@typescript-eslint',
29 '^eslint'
30 ],
31 groupName: 'ESLint'
32 },
33 {
34 // Group Jest together
35 matchPackageNames: [
36 '@jest/globals',
37 '@types/jest',
38 'jest',
39 'jest-junit',
40 'ts-jest'
41 ],
42 groupName: 'Jest',
43 },
44 {
45 // Separate Lerna
46 matchPackageNames: ['lerna'],
47 groupName: 'Lerna',
48 prPriority: -10
49 },
50
51 // Everything else
52 {
53 matchDepTypes: ['optionalDependencies', 'peerDependencies', 'engines'],
54 enabled: false
55 }
56 ]
57 }
58}
That will cut down on a lot of pull requests!
Alternative strategy: grouping by Lerna package
Maybe you would prefer to manage each package separately, creating separate pull requests for each package. Doing so will likely increase the number of pull requests, but it means library updates affecting one Lerna package won't hold back updates to other packages.
The Renovate config for that would look something like this:
1{
2 $schema: 'https://docs.renovatebot.com/renovate-schema.json',
3 extends: ['config:recommended'],
4
5 npm: {
6 // Group by each package.json's parent directory name
7 additionalBranchPrefix: '{{{parentDir}}}-',
8 commitMessagePrefix: '{{#if parentDir}}{{{parentDir}}}:{{/if}}',
9
10 packageRules: [
11 {
12 // Group non-major dependency updates together
13 groupName: 'non-major dependencies',
14 matchUpdateTypes: ['patch', 'minor']
15 }
16 ]
17 }
18}
Strategy: automatic version bumps
I have a GitHub Action workflow that runs lerna publish on every commit to the main branch. This ensures that any version bump in any pull request will result in a release.
Because I want Renovate dependency updates to be as automated as possible, I want the patch version of every relevant package.json to get bumped on dependency updates only (not dev dependencies, peer dependencies, etc.).
The Renovate config for that would look something like this:
1{
2 $schema: 'https://docs.renovatebot.com/renovate-schema.json',
3 extends: ['config:recommended'],
4
5 // Automatically merge PRs without a human approval, creating automated releases
6 automerge: true,
7 platformAutomerge: true,
8
9 npm: {
10 // Bump version ranges even if the new library version is in the old range
11 rangeStrategy: 'bump',
12
13 packageRules: [
14 {
15 // Dependency updates bump the patch version
16 matchDepTypes: ['dependencies'],
17 bumpVersion: 'patch'
18 }
19 ]
20 }
21}
Strategy: reducing pull request spam
Because I want dependency updates to create new patch versions, this has the possibility of publishing new versions to npm frequently. That would be really annoying to users, so I want to reduce how often versions might get published.
There are a few Renovate settings you should consider:
1{
2 $schema: 'https://docs.renovatebot.com/renovate-schema.json',
3 extends: ['config:recommended'],
4
5 // Open PRs immediately for vulnerability alerts, ignoring any other schedule
6 // Requires "dependency graph" as well as Dependabot "alerts" and "security updates" enabled for the repo
7 vulnerabilityAlerts: {
8 // Renovate's defaults for `vulnerabilityAlerts`
9 groupName: null,
10 schedule: [],
11 dependencyDashboardApproval: false,
12 minimumReleaseAge: null,
13 rangeStrategy: 'update-lockfile',
14 commitMessageSuffix: '[SECURITY]',
15 branchTopic: '{{{datasource}}}-{{{depName}}}-vulnerability',
16 prCreation: 'immediate'
17 },
18
19 // Limit dependency updates to once a month
20 schedule: 'on the 1st day of the month',
21 prCreation: 'immediate', // default
22 prHourlyLimit: 0, // no limit
23 automerge: true,
24 platformAutomerge: true,
25
26 npm: {
27 // Update lockfiles, but do it one day after dependencies to reduce conflicts
28 lockFileMaintenance: {
29 enabled: true,
30 schedule: 'on the 2nd day of the month'
31 },
32
33 packageRules: [
34 // Group/separate all dependency pinning, perform it immediately
35 {
36 matchUpdateTypes: ['pin'],
37 groupName: 'dependency ranges',
38 // Renovate's defaults for these options
39 schedule: 'at any time',
40 prCreation: 'immediate'
41 }
42 ]
43 }
44}
Bringing it all together
The current emmercm/metalsmith-plugins Renovate config combines all of these strategies together, resulting in a Lerna monorepo with unattended version updates:
1{
2 $schema: 'https://docs.renovatebot.com/renovate-schema.json',
3 extends: [
4 'config:recommended',
5 ],
6 dependencyDashboard: true,
7 configMigration: true,
8
9 // Personal preferences
10 timezone: 'America/Los_Angeles',
11 assignees: ['@emmercm'],
12 reviewers: ['@emmercm'],
13 assignAutomerge: false, // default
14
15 // Open PRs immediately for vulnerability alerts
16 // Requires "dependency graph" as well as Dependabot "alerts" and "security updates" enabled for the repo
17 vulnerabilityAlerts: {
18 labels: ['security'],
19 platformAutomerge: true,
20 // Renovate's defaults for `vulnerabilityAlerts`
21 groupName: '',
22 schedule: [],
23 dependencyDashboardApproval: false,
24 minimumReleaseAge: '',
25 rangeStrategy: 'update-lockfile',
26 commitMessageSuffix: '[SECURITY]',
27 branchTopic: '{{{datasource}}}-{{{depName}}}-vulnerability',
28 prCreation: 'immediate',
29 },
30 // WARN: "When the lockfileVersion is higher than 1 in package-lock.json, remediations are only possible when changes are made to package.json."
31 transitiveRemediation: true,
32
33 // Separate potentially breaking updates, group others
34 separateMultipleMajor: true,
35 separateMajorMinor: true, // default
36 separateMinorPatch: false, // default
37
38 // Allow auto-merging of PRs, but reduce their spam on the commit log
39 schedule: 'on the 1st day of the month',
40 prCreation: 'immediate', // default
41 prHourlyLimit: 0, // no limit
42 automerge: true,
43 platformAutomerge: true,
44
45 // Don't update any Node.js versions (nvm, Volta, etc.)
46 packageRules: [
47 {
48 matchCategories: ['node'],
49 enabled: false
50 },
51 ],
52
53 npm: {
54 lockFileMaintenance: {
55 // These options are required to override the `lockFileMaintenance` defaults
56 enabled: true,
57 schedule: 'on the 2nd day of the month', // one day after the above, to de-conflict
58 },
59
60 // Stability settings: don't raise a PR until a dependency is at least 3 days old
61 rangeStrategy: 'bump',
62 minimumReleaseAge: '3 days',
63 internalChecksFilter: 'strict',
64
65 packageRules: [
66 // Dependencies
67 {
68 // Group non-major dependency updates together
69 groupName: 'dependencies',
70 matchDepTypes: ['dependencies'],
71 matchUpdateTypes: ['patch', 'minor']
72 },
73 {
74 // Dependency updates bump the patch version
75 matchDepTypes: ['dependencies'],
76 bumpVersion: 'patch'
77 },
78
79 // Dev dependencies
80 {
81 // Group devDependencies together
82 matchDepTypes: ['devDependencies'],
83 groupName: 'dev dependencies',
84 // Only group non-major updates
85 matchUpdateTypes: ['patch', 'minor']
86 },
87 {
88 // Group ESLint together so files can be fixed automatically
89 matchPackagePatterns: [
90 '^@typescript-eslint',
91 '^eslint',
92 ],
93 groupName: 'ESLint'
94 },
95 {
96 // Group Jest together because of peerDependencies
97 matchPackageNames: [
98 '@jest/globals',
99 '@types/jest',
100 'jest',
101 'jest-junit',
102 'ts-jest',
103 ],
104 groupName: 'Jest'
105 },
106 {
107 // Separate Lerna
108 matchPackageNames: ['lerna'],
109 groupName: 'Lerna',
110 prPriority: -10,
111 },
112
113 // Group/separate all dependency pinning, perform it immediately
114 {
115 matchUpdateTypes: ['pin'],
116 groupName: 'dependency ranges',
117 // Renovate's defaults for these options
118 schedule: 'at any time',
119 prCreation: 'immediate',
120 platformAutomerge: true
121 },
122
123 // Everything else
124 {
125 matchDepTypes: ['optionalDependencies', 'peerDependencies', 'engines'],
126 enabled: false
127 }
128 ]
129 }
130}




