diff --git a/lib/config/migration.js b/lib/config/migration.js index b65c8500a656b1df0fbeed1f7f40375619a29943..59cbaf7435f28e485d3dcc5319d1ee0fc57f8f58 100644 --- a/lib/config/migration.js +++ b/lib/config/migration.js @@ -94,12 +94,31 @@ function migrateConfig(config, parentConfig) { } else if (val === 'false') { migratedConfig[key] = false; } + } else if ( + optionTypes[key] === 'string' && + Array.isArray(val) && + val.length === 1 + ) { + migratedConfig[key] = `${val[0]}`; } else if (isObject(val)) { const subMigrate = migrateConfig(val); if (subMigrate.isMigrated) { isMigrated = true; migratedConfig[key] = subMigrate.migratedConfig; } + } else if (Array.isArray(val)) { + migratedConfig[key] = []; + for (const item of val) { + if (isObject(item)) { + const arrMigrate = migrateConfig(item); + migratedConfig[key].push(arrMigrate.migratedConfig); + if (arrMigrate.isMigrated) { + isMigrated = true; + } + } else { + migratedConfig[key].push(item); + } + } } } return { isMigrated, migratedConfig }; diff --git a/test/config/__snapshots__/migration.spec.js.snap b/test/config/__snapshots__/migration.spec.js.snap index 6a70ff1546fdce3d469ba0eb81b35397088ae617..74623d899b43bf7bc37b841997890593f247ed71 100644 --- a/test/config/__snapshots__/migration.spec.js.snap +++ b/test/config/__snapshots__/migration.spec.js.snap @@ -11,6 +11,16 @@ Object { "respectLatest": false, }, "packageRules": Array [ + Object { + "groupName": "angular packages", + "packagePatterns": "^(@angular|typescript)", + }, + Object { + "groupName": "foo", + "packagePatterns": Array [ + "^foo", + ], + }, Object { "enabled": false, "packageNames": Array [ @@ -29,6 +39,17 @@ Object { } `; +exports[`config/migration migrateConfig(config, parentConfig) it migrates packages 1`] = ` +Object { + "packageRules": Array [ + Object { + "groupName": "angular packages", + "packagePatterns": "^(@angular|typescript)", + }, + ], +} +`; + exports[`config/migration migrateConfig(config, parentConfig) it migrates subconfig 1`] = ` Object { "lockFileMaintenance": Object { diff --git a/test/config/migration.spec.js b/test/config/migration.spec.js index 6d9307dc370f8cec09bf891e2cf6f29147ef962f..7952d0cbc524211967a5fdcad4ddf200e3040d34 100644 --- a/test/config/migration.spec.js +++ b/test/config/migration.spec.js @@ -15,7 +15,15 @@ describe('config/migration', () => { prTitle: '{{semanticPrefix}}some pr title', semanticPrefix: 'fix(deps): ', semanticCommits: false, - packages: [ + packageRules: [ + { + packagePatterns: '^(@angular|typescript)', + groupName: ['angular packages'], + }, + { + packagePatterns: ['^foo'], + groupName: ['foo'], + }, { packageName: 'angular', packagePattern: 'ang', @@ -41,6 +49,23 @@ describe('config/migration', () => { expect(migratedConfig.automerge).toEqual('none'); expect(migratedConfig).toMatchSnapshot(); }); + it('it migrates packages', () => { + const config = { + packages: [ + { + packagePatterns: '^(@angular|typescript)', + groupName: ['angular packages'], + }, + ], + }; + const parentConfig = { ...defaultConfig }; + const { isMigrated, migratedConfig } = configMigration.migrateConfig( + config, + parentConfig + ); + expect(isMigrated).toBe(true); + expect(migratedConfig).toMatchSnapshot(); + }); it('it does not migrate config', () => { const config = { enabled: true,