From 898b913f3ba05dbf83497de561f443d656c86490 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sat, 28 Apr 2018 14:05:39 +0200 Subject: [PATCH] feat: deprecate pathRules (#1881) pathRules are now migrated to packageRules. Closes #1880 --- lib/config/definitions.js | 12 +------ lib/config/migration.js | 9 +++++ lib/manager/index.js | 22 +------------ test/config/__snapshots__/index.spec.js.snap | 1 - .../__snapshots__/migration.spec.js.snap | 22 +++++++++++++ test/config/migration.spec.js | 14 ++++++++ test/config/validation.spec.js | 6 ---- test/manager/resolve.spec.js | 24 -------------- .../2017-10-05-configuration-options.md | 33 +++++++------------ 9 files changed, 59 insertions(+), 84 deletions(-) diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 90eda768f5..62af3b6c62 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -280,20 +280,10 @@ const options = [ stage: 'repository', default: ['**/node_modules/**', '**/bower_components/**'], }, - { - name: 'pathRules', - description: - 'Apply config on a path-based basis. Consists of a paths array plus whatever other configuration objects to apply', - type: 'list', - stage: 'repository', - mergeable: true, - cli: false, - env: false, - }, { name: 'paths', description: - 'List of strings or glob patterns to match against package files. Applicable inside pathRules or packageRules only', + 'List of strings or glob patterns to match against package files. Applicable inside packageRules only', type: 'list', stage: 'repository', cli: false, diff --git a/lib/config/migration.js b/lib/config/migration.js index 7a6d73728e..1153f98082 100644 --- a/lib/config/migration.js +++ b/lib/config/migration.js @@ -33,6 +33,15 @@ function migrateConfig(config) { } let isMigrated = false; const migratedConfig = deepcopy(config); + if ( + Array.isArray(migratedConfig.pathRules) && + migratedConfig.pathRules.length + ) { + migratedConfig.packageRules = (migratedConfig.pathRules || []).concat( + config.packageRules + ); + delete migratedConfig.pathRules; + } for (const [key, val] of Object.entries(config)) { if (removedOptions.includes(key)) { isMigrated = true; diff --git a/lib/manager/index.js b/lib/manager/index.js index df80bf566d..2c083425b6 100644 --- a/lib/manager/index.js +++ b/lib/manager/index.js @@ -206,27 +206,7 @@ async function resolvePackageFiles(config) { } // TODO: throttle how many we resolve in parallel const queue = allPackageFiles.map(p => resolvePackageFile(p)); - let packageFiles = (await Promise.all(queue)).filter(p => p !== null); + const packageFiles = (await Promise.all(queue)).filter(p => p !== null); logger.debug('Checking against path rules'); - packageFiles = packageFiles.map(pf => { - let packageFile = { ...pf }; - for (const pathRule of config.pathRules) { - /* eslint-disable no-loop-func */ - if ( - pathRule.paths.some( - rulePath => - packageFile.packageFile.includes(rulePath) || - minimatch(packageFile.packageFile, rulePath) - ) - ) { - logger.debug({ pathRule, packageFile }, 'Matched pathRule'); - packageFile = mergeChildConfig(packageFile, pathRule); - delete packageFile.paths; - } - /* eslint-enable */ - } - return packageFile; - }); - return checkMonorepos({ ...config, packageFiles }); } diff --git a/test/config/__snapshots__/index.spec.js.snap b/test/config/__snapshots__/index.spec.js.snap index 49b3da4405..4a04672a6e 100644 --- a/test/config/__snapshots__/index.spec.js.snap +++ b/test/config/__snapshots__/index.spec.js.snap @@ -148,7 +148,6 @@ Object { "automerge": true, "branchTopic": "{{{depNameSanitized}}}-{{{newVersionMajor}}}.{{{newVersionMinor}}}.x", }, - "pathRules": Array [], "paths": Array [], "peerDependencies": Object { "enabled": false, diff --git a/test/config/__snapshots__/migration.spec.js.snap b/test/config/__snapshots__/migration.spec.js.snap index c20a036e99..2fdcf10753 100644 --- a/test/config/__snapshots__/migration.spec.js.snap +++ b/test/config/__snapshots__/migration.spec.js.snap @@ -44,6 +44,18 @@ Object { "minor": Object { "automerge": true, }, + "nvmrc": Object { + "pathRules": Array [ + Object { + "extends": Array [ + "node", + ], + "paths": Array [ + "node/**", + ], + }, + ], + }, "onboarding": false, "optionalDependencies": Object { "major": Object { @@ -80,6 +92,16 @@ Object { "patch": Object { "automerge": true, }, + "pathRules": Array [ + Object { + "extends": Array [ + "foo", + ], + "paths": Array [ + "examples/**", + ], + }, + ], "prTitle": "{{#if semanticCommitType}}{{semanticCommitType}}{{#if semanticCommitScope}}({{semanticCommitScope}}){{/if}}: {{/if}}some pr title", "schedule": "on the first day of the month", "semanticCommitScope": "deps", diff --git a/test/config/migration.spec.js b/test/config/migration.spec.js index 076df2910e..94f61b766a 100644 --- a/test/config/migration.spec.js +++ b/test/config/migration.spec.js @@ -24,6 +24,12 @@ describe('config/migration', () => { commitMessage: '{{semanticPrefix}}some commit message', prTitle: '{{semanticPrefix}}some pr title', semanticPrefix: 'fix(deps): ', + pathRules: [ + { + paths: ['examples/**'], + extends: ['foo'], + }, + ], packageRules: [ { packagePatterns: '^(@angular|typescript)', @@ -48,6 +54,14 @@ describe('config/migration', () => { automerge: 'minor', schedule: null, }, + nvmrc: { + pathRules: [ + { + paths: ['node/**'], + extends: ['node'], + }, + ], + }, depTypes: [ 'dependencies', { diff --git a/test/config/validation.spec.js b/test/config/validation.spec.js index 88a64ef4c9..d010aaf597 100644 --- a/test/config/validation.spec.js +++ b/test/config/validation.spec.js @@ -43,12 +43,6 @@ describe('config/validation', () => { semanticCommitType: 7, lockFileMaintenance: false, extends: [':timezone(Europe/Brussel)'], - pathRules: [ - { - paths: ['examples/**'], - labels: ['examples'], - }, - ], packageRules: [ { excludePackageNames: ['foo'], diff --git a/test/manager/resolve.spec.js b/test/manager/resolve.spec.js index 3ae257a8bb..bb8c76bed5 100644 --- a/test/manager/resolve.spec.js +++ b/test/manager/resolve.spec.js @@ -130,30 +130,6 @@ describe('manager/resolve', () => { const res = await resolvePackageFiles(config); expect(res.packageFiles).toMatchSnapshot(); }); - it('applies package rules', async () => { - config.pathRules = [ - { - paths: ['examples/**'], - prTitle: 'abcdefg', - }, - ]; - config.packageFiles = [ - 'package.json', - 'examples/a/package.json', - 'packages/examples/package.json', - ]; - platform.getFileList.mockReturnValue([ - 'package.json', - 'examples/a/package.json', - 'packages/examples/package.json', - ]); - platform.getFile.mockReturnValue('{}'); - const res = await resolvePackageFiles(config); - expect(res.packageFiles).toHaveLength(3); - expect(res.packageFiles[0].prTitle).not.toEqual('abcdefg'); - expect(res.packageFiles[1].prTitle).toEqual('abcdefg'); - expect(res.packageFiles[2].prTitle).not.toEqual('abcdefg'); - }); it('strips npmrc with NPM_TOKEN', async () => { manager.detectPackageFiles = jest.fn(() => [ { packageFile: 'package.json', manager: 'npm' }, diff --git a/website/docs/_posts/2017-10-05-configuration-options.md b/website/docs/_posts/2017-10-05-configuration-options.md index d5cba5254d..7ae7b7221f 100644 --- a/website/docs/_posts/2017-10-05-configuration-options.md +++ b/website/docs/_posts/2017-10-05-configuration-options.md @@ -835,6 +835,17 @@ Note how the above uses `packageNames` instead of `packagePatterns` because it i The above rule will group together the `neutrino` package and any package matching `@neutrino/*`. +Path rules are convenient to use if you wish to apply configuration rules to certain package files without needing to configure them all in the `packageFiles` array. For example, if you have an `examples` directory and you want all updates to those examples to use the `chore` prefix instead of `fix`, then you could add this configuration: + +```json + "packageRules": [ + { + "paths": ["examples/**"], + "extends": [":semanticCommitTypeAll(chore)"] + } + ] +``` + ## patch Configuration specific for patch dependency updates. @@ -846,29 +857,9 @@ Configuration specific for patch dependency updates. Add to this object if you wish to define rules that apply only to patch updates. See also `major` and `minor` configuration options. -## pathRules - -Apply config on a path-based basis. Consists of a `paths` array plus whatever other configuration objects to apply. - -| name | value | -| ------- | ----- | -| type | list | -| default | [] | - -Path rules are convenient to use if you wish to apply configuration rules to certain package files without needing to configure them all in the `packageFiles` array. For example, if you have an `examples` directory and you want all updates to those examples to use the `chore` prefix instead of `fix`, then you could add this configuration: - -```json - "pathRules": [ - { - "paths": ["examples/**"], - "extends": [":semanticCommitTypeAll(chore)"] - } - ] -``` - ## paths -List of strings or glob patterns to match against package files. Applicable inside pathRules or packageRules only. +List of strings or glob patterns to match against package files. Applicable inside packageRules only. | name | value | | ------- | ----- | -- GitLab