diff --git a/lib/config/__snapshots__/migration.spec.ts.snap b/lib/config/__snapshots__/migration.spec.ts.snap index eb7ccf4579766693ed9746b02da1ac6e4f7bad2c..9bcf41779611bb1d817518246ceb40b5e8bff6fa 100644 --- a/lib/config/__snapshots__/migration.spec.ts.snap +++ b/lib/config/__snapshots__/migration.spec.ts.snap @@ -153,14 +153,6 @@ Object { }, "onboarding": false, "packageRules": Array [ - Object { - "extends": Array [ - "foo", - ], - "matchPaths": Array [ - "examples/**", - ], - }, Object { "excludePackageNames": "foo", "groupName": "angular packages", @@ -196,6 +188,14 @@ Object { "foo", ], }, + Object { + "extends": Array [ + "foo", + ], + "matchPaths": Array [ + "examples/**", + ], + }, Object { "matchDepTypes": Array [ "peerDependencies", diff --git a/lib/config/migration.ts b/lib/config/migration.ts index d17bce97ff9d599586505a8b195bd188b397cee6..d2b7ff357ffba7865f04e175f69fe87c09cf2b73 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -46,15 +46,7 @@ export function migrateConfig( ]; const { migratePresets } = GlobalConfig.get(); for (const [key, val] of Object.entries(newConfig)) { - if (key === 'pathRules') { - if (is.array(val)) { - migratedConfig.packageRules = is.array(migratedConfig.packageRules) - ? migratedConfig.packageRules - : []; - migratedConfig.packageRules = val.concat(migratedConfig.packageRules); - } - delete migratedConfig.pathRules; - } else if (key === 'suppressNotifications') { + if (key === 'suppressNotifications') { if (is.nonEmptyArray(val) && val.includes('prEditNotification')) { migratedConfig.suppressNotifications = migratedConfig.suppressNotifications.filter( diff --git a/lib/config/migrations/custom/path-rules-migration.spec.ts b/lib/config/migrations/custom/path-rules-migration.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..e7ab02691957b9c95c7537188b98638abbcc0b17 --- /dev/null +++ b/lib/config/migrations/custom/path-rules-migration.spec.ts @@ -0,0 +1,86 @@ +import { PathRulesMigration } from './path-rules-migration'; + +describe('config/migrations/custom/path-rules-migration', () => { + it('should migrate to packageRules', () => { + expect(PathRulesMigration).toMigrate( + { + pathRules: [ + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], + }, + { + packageRules: [ + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], + } + ); + }); + + it('should rewrite packageRules when it is not array', () => { + expect(PathRulesMigration).toMigrate( + { + packageRules: 'test', + pathRules: [ + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], + } as any, + { + packageRules: [ + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], + } + ); + }); + + it('should not migrate non array value', () => { + expect(PathRulesMigration).toMigrate( + { + pathRules: 'test', + }, + {} + ); + }); + + it('should concat with existing package rules', () => { + expect(PathRulesMigration).toMigrate( + { + pathRules: [ + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], + packageRules: [ + { + packageNames: ['guava'], + versionScheme: 'maven', + }, + ], + }, + { + packageRules: [ + { + packageNames: ['guava'], + versionScheme: 'maven', + }, + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], + } + ); + }); +}); diff --git a/lib/config/migrations/custom/path-rules-migration.ts b/lib/config/migrations/custom/path-rules-migration.ts new file mode 100644 index 0000000000000000000000000000000000000000..1aaff3d89f44b14025d8a1db6745c960ac0f1c48 --- /dev/null +++ b/lib/config/migrations/custom/path-rules-migration.ts @@ -0,0 +1,17 @@ +import { AbstractMigration } from '../base/abstract-migration'; + +export class PathRulesMigration extends AbstractMigration { + override readonly deprecated = true; + override readonly propertyName = 'pathRules'; + + override run(value: unknown): void { + const packageRules = this.get('packageRules'); + + if (Array.isArray(value)) { + this.setHard( + 'packageRules', + Array.isArray(packageRules) ? packageRules.concat(value) : value + ); + } + } +} diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 01685187b3c20a527460974797532de404220ae0..accd7d5b56daeb5d0dd5877ff079333cbf5fc6b0 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -9,6 +9,7 @@ import { EnabledManagersMigration } from './custom/enabled-managers-migration'; import { GoModTidyMigration } from './custom/go-mod-tidy-migration'; import { HostRulesMigration } from './custom/host-rules-migration'; import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; +import { PathRulesMigration } from './custom/path-rules-migration'; import { PinVersionsMigration } from './custom/pin-versions-migration'; import { RaiseDeprecationWarningsMigration } from './custom/raise-deprecation-warnings-migration'; import { RebaseConflictedPrs } from './custom/rebase-conflicted-prs-migration'; @@ -56,6 +57,7 @@ export class MigrationsService { GoModTidyMigration, HostRulesMigration, IgnoreNodeModulesMigration, + PathRulesMigration, PinVersionsMigration, RaiseDeprecationWarningsMigration, RebaseConflictedPrs,