diff --git a/lib/config/__snapshots__/migration.spec.ts.snap b/lib/config/__snapshots__/migration.spec.ts.snap index 7713dfac4bc167..f1833e7c0c0b79 100644 --- a/lib/config/__snapshots__/migration.spec.ts.snap +++ b/lib/config/__snapshots__/migration.spec.ts.snap @@ -1,5 +1,37 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`config/migration it migrates nested packageRules 1`] = ` +Object { + "packageRules": Array [ + Object { + "enabled": false, + "matchDepTypes": Array [ + "devDependencies", + ], + }, + Object { + "automerge": true, + "excludePackageNames": Array [ + "@types/react-table", + ], + "groupName": "definitelyTyped", + "matchPackagePrefixes": Array [ + "@types/", + ], + }, + Object { + "automerge": false, + "excludePackageNames": Array [ + "@types/react-table", + ], + "matchDepTypes": Array [ + "dependencies", + ], + }, + ], +} +`; + exports[`config/migration migrateConfig(config, parentConfig) does not migrate multi days 1`] = ` Object { "schedule": "after 5:00pm on wednesday and thursday", @@ -173,6 +205,15 @@ Object { ], "versioning": "maven", }, + Object { + "automerge": true, + "matchDepTypes": Array [ + "bar", + ], + "matchPackageNames": Array [ + "foo", + ], + }, Object { "matchDepTypes": Array [ "peerDependencies", @@ -204,15 +245,6 @@ Object { "respectLatest": false, "schedule": "before 5am on Monday", }, - Object { - "automerge": true, - "matchDepTypes": Array [ - "bar", - ], - "matchPackageNames": Array [ - "foo", - ], - }, ], "patch": Object { "automerge": true, diff --git a/lib/config/migration.spec.ts b/lib/config/migration.spec.ts index dfa75a1599f4b6..29fffe448efd68 100644 --- a/lib/config/migration.spec.ts +++ b/lib/config/migration.spec.ts @@ -628,4 +628,35 @@ describe(getName(), () => { expect(migratedConfig).toMatchSnapshot(); }); }); + it('it migrates nested packageRules', () => { + const config: RenovateConfig = { + packageRules: [ + { + matchDepTypes: ['devDependencies'], + enabled: false, + }, + { + automerge: true, + excludePackageNames: ['@types/react-table'], + packageRules: [ + { + groupName: 'definitelyTyped', + matchPackagePrefixes: ['@types/'], + }, + { + matchDepTypes: ['dependencies'], + automerge: false, + }, + ], + }, + ], + }; + const { isMigrated, migratedConfig } = configMigration.migrateConfig( + config, + defaultConfig + ); + expect(isMigrated).toBe(true); + expect(migratedConfig).toMatchSnapshot(); + expect(migratedConfig.packageRules).toHaveLength(3); + }); }); diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 44e7842cc2fbad..908448c0c10d0c 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -554,7 +554,9 @@ export function migrateConfig( } // Migrate nested packageRules if (is.nonEmptyArray(migratedConfig.packageRules)) { - for (const packageRule of migratedConfig.packageRules) { + const existingRules = migratedConfig.packageRules; + migratedConfig.packageRules = []; + for (const packageRule of existingRules) { if (is.array(packageRule.packageRules)) { logger.debug('Flattening nested packageRules'); // merge each subrule and add to the parent list @@ -563,22 +565,10 @@ export function migrateConfig( delete combinedRule.packageRules; migratedConfig.packageRules.push(combinedRule); } - // delete the nested packageRules - delete packageRule.packageRules; - // mark the original rule for deletion if it's now pointless - if ( - !Object.keys(packageRule).some( - (key) => !key.startsWith('match') && !key.startsWith('exclude') - ) - ) { - packageRule._delete = true; - } + } else { + migratedConfig.packageRules.push(packageRule); } } - // filter out any rules which were marked for deletion in the previous step - migratedConfig.packageRules = migratedConfig.packageRules.filter( - (rule) => !rule._delete - ); } const isMigrated = !dequal(config, migratedConfig); if (isMigrated) {