Skip to content

Commit

Permalink
feat!: merge matchPaths and matchFiles into matchFileNames (#22406)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jun 15, 2023
1 parent 058afd0 commit c9f653d
Show file tree
Hide file tree
Showing 23 changed files with 118 additions and 170 deletions.
77 changes: 36 additions & 41 deletions docs/usage/configuration-options.md
Expand Up @@ -1863,28 +1863,28 @@ Example:

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 using patterns.
File name matches are convenient to use if you wish to apply configuration rules to certain package or lock files using patterns.
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": [
{
"matchPaths": ["examples/**"],
"matchFileNames": ["examples/**"],
"extends": [":semanticCommitTypeAll(chore)"]
}
]
}
```

If you wish to limit Renovate to apply configuration rules to certain files in the root repository directory, you have to use `matchPaths` with a `minimatch` pattern or use [`matchFiles`](#matchfiles) with an exact match.
If you wish to limit Renovate to apply configuration rules to certain files in the root repository directory, you have to use `matchFileNames` with a `minimatch` pattern (which can include an exact file name match).
For example you have multiple `package.json` and want to use `dependencyDashboardApproval` only on the root `package.json`:

```json
{
"packageRules": [
{
"matchFiles": ["package.json"],
"matchFileNames": ["package.json"],
"dependencyDashboardApproval": true
}
]
Expand Down Expand Up @@ -2179,23 +2179,50 @@ Use the syntax `!/ /` like this:
}
```

### matchFiles
### matchFileNames

Renovate will compare `matchFiles` for an exact match against the dependency's package file or lock file.
Renovate will compare `matchFileNames` glob matching against the dependency's package file or lock file.

For example the following would match `package.json` but not `package/frontend/package.json`:
The following example matches `package.json` but _not_ `package/frontend/package.json`:

```json
{
"packageRules": [
{
"matchFiles": ["package.json"]
"matchFileNames": ["package.json"],
"labels": ["npm"]
}
]
}
```

Use [`matchPaths`](#matchpaths) instead if you need more flexible matching.
The following example matches any `package.json`, including files like `backend/package.json`:

```json
{
"packageRules": [
{
"description": "Group dependencies from package.json files",
"matchFileNames": ["**/package.json"],
"groupName": "All package.json changes"
}
]
}
```

The following example matches any file in directories starting with `app/`:

```json
{
"packageRules": [
{
"description": "Group all dependencies from the app directory",
"matchFileNames": ["app/**"],
"groupName": "App dependencies"
}
]
}
```

### matchDepNames

Expand Down Expand Up @@ -2255,38 +2282,6 @@ See also `excludePackagePrefixes`.

Like the earlier `matchPackagePatterns` example, the above will configure `rangeStrategy` to `replace` for any package starting with `angular`.

### matchPaths

Renovate finds the file(s) listed in `matchPaths` with a `minimatch` glob pattern.

For example the following matches any `package.json`, including files like `backend/package.json`:

```json
{
"packageRules": [
{
"description": "Group dependencies from package.json files",
"matchPaths": ["**/package.json"],
"groupName": "All package.json changes"
}
]
}
```

The following matches any file in directories starting with `app/`:

```json
{
"packageRules": [
{
"description": "Group all dependencies from the app directory",
"matchPaths": ["app/**"],
"groupName": "App dependencies"
}
]
}
```

### matchSourceUrlPrefixes

Here's an example of where you use this to group together all packages from the `renovatebot` GitHub org:
Expand Down
16 changes: 8 additions & 8 deletions lib/config/__snapshots__/migration.spec.ts.snap
Expand Up @@ -164,7 +164,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates config 1`
"extends": [
"node",
],
"matchPaths": [
"matchFileNames": [
"node/**",
],
},
Expand Down Expand Up @@ -211,7 +211,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates config 1`
"extends": [
"foo",
],
"matchPaths": [
"matchFileNames": [
"examples/**",
],
},
Expand Down Expand Up @@ -293,7 +293,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates more pack
"matchDepTypes": [
"devDependencies",
],
"matchPaths": [
"matchFileNames": [
"package.json",
],
"rangeStrategy": "pin",
Expand All @@ -302,7 +302,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates more pack
"matchDepTypes": [
"dependencies",
],
"matchPaths": [
"matchFileNames": [
"package.json",
],
"rangeStrategy": "pin",
Expand Down Expand Up @@ -332,13 +332,13 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates packageFi
],
"packageRules": [
{
"matchPaths": [
"matchFileNames": [
"backend/package.json",
],
"rangeStrategy": "replace",
},
{
"matchPaths": [
"matchFileNames": [
"frontend/package.json",
],
"rangeStrategy": "pin",
Expand All @@ -347,7 +347,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates packageFi
"matchDepTypes": [
"devDependencies",
],
"matchPaths": [
"matchFileNames": [
"other/package.json",
],
"rangeStrategy": "pin",
Expand All @@ -356,7 +356,7 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates packageFi
"matchDepTypes": [
"dependencies",
],
"matchPaths": [
"matchFileNames": [
"other/package.json",
],
"rangeStrategy": "pin",
Expand Down
30 changes: 29 additions & 1 deletion lib/config/migration.spec.ts
Expand Up @@ -568,13 +568,41 @@ describe('config/migration', () => {
matchManagers: ['dockerfile'],
matchPackageNames: ['foo'],
matchPackagePatterns: ['^bar'],
matchPaths: ['package.json'],
matchFileNames: ['package.json'],
matchSourceUrlPrefixes: ['https://github.com/lodash'],
matchUpdateTypes: ['major'],
},
],
});
});

it('migrates in order of precedence', () => {
const config: TestRenovateConfig = {
packageRules: [
{
matchFiles: ['matchFiles'],
matchPaths: ['matchPaths'],
},
{
matchPaths: ['matchPaths'],
matchFiles: ['matchFiles'],
},
],
};
const { isMigrated, migratedConfig } =
configMigration.migrateConfig(config);
expect(isMigrated).toBeTrue();
expect(migratedConfig).toEqual({
packageRules: [
{
matchFileNames: ['matchPaths'],
},
{
matchFileNames: ['matchFiles'],
},
],
});
});
});

it('it migrates nested packageRules', () => {
Expand Down
Expand Up @@ -19,13 +19,13 @@ describe('config/migrations/custom/automerge-major-migration', () => {
{
automergeMajor: 'some-value',
major: {
matchFiles: ['test'],
matchFileNames: ['test'],
},
},
{
major: {
automerge: true,
matchFiles: ['test'],
matchFileNames: ['test'],
},
}
);
Expand Down
Expand Up @@ -19,13 +19,13 @@ describe('config/migrations/custom/automerge-minor-migration', () => {
{
automergeMinor: 'some-value',
minor: {
matchFiles: ['test'],
matchFileNames: ['test'],
},
},
{
minor: {
automerge: true,
matchFiles: ['test'],
matchFileNames: ['test'],
},
}
);
Expand Down
Expand Up @@ -19,13 +19,13 @@ describe('config/migrations/custom/automerge-patch-migration', () => {
{
automergePatch: 'some-value',
patch: {
matchFiles: ['test'],
matchFileNames: ['test'],
},
},
{
patch: {
automerge: true,
matchFiles: ['test'],
matchFileNames: ['test'],
},
}
);
Expand Down
Expand Up @@ -48,7 +48,7 @@ describe('config/migrations/custom/package-rules-migration', () => {
{
packageRules: [
{
matchPaths: [],
matchFileNames: [],
packgageRules: {
languages: ['javascript'],
},
Expand Down
4 changes: 3 additions & 1 deletion lib/config/migrations/custom/package-rules-migration.ts
Expand Up @@ -2,7 +2,9 @@ import type { PackageRule } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

export const renameMap = {
paths: 'matchPaths',
matchFiles: 'matchFileNames',
matchPaths: 'matchFileNames',
paths: 'matchFileNames',
languages: 'matchLanguages',
baseBranchList: 'matchBaseBranches',
managers: 'matchManagers',
Expand Down
13 changes: 1 addition & 12 deletions lib/config/options/index.ts
Expand Up @@ -1294,7 +1294,7 @@ const options: RenovateOptions[] = [
env: false,
},
{
name: 'matchFiles',
name: 'matchFileNames',
description:
'List of strings to do an exact match against package and lock files with full path. Only works inside a `packageRules` object.',
type: 'array',
Expand All @@ -1304,17 +1304,6 @@ const options: RenovateOptions[] = [
cli: false,
env: false,
},
{
name: 'matchPaths',
description:
'List of glob patterns to match against package files. Only works inside a `packageRules` object.',
type: 'array',
subType: 'string',
stage: 'repository',
parent: 'packageRules',
cli: false,
env: false,
},
// Version behaviour
{
name: 'allowedVersions',
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/default.ts
Expand Up @@ -361,7 +361,7 @@ export const presets: Record<string, Preset> = {
'Use semanticCommitType `{{arg0}}` for all package files matching path `{{arg1}}`.',
packageRules: [
{
matchPaths: ['{{arg0}}'],
matchFileNames: ['{{arg0}}'],
semanticCommitType: '{{arg1}}',
},
],
Expand Down
4 changes: 2 additions & 2 deletions lib/config/types.ts
Expand Up @@ -315,8 +315,7 @@ export interface PackageRule
Record<string, unknown> {
description?: string | string[];
isVulnerabilityAlert?: boolean;
matchFiles?: string[];
matchPaths?: string[];
matchFileNames?: string[];
matchLanguages?: string[];
matchBaseBranches?: string[];
matchManagers?: string | string[];
Expand Down Expand Up @@ -461,6 +460,7 @@ export type RenovateOptions =
export interface PackageRuleInputConfig extends Record<string, unknown> {
versioning?: string;
packageFile?: string;
lockFiles?: string[];
depType?: string;
depTypes?: string[];
depName?: string;
Expand Down
3 changes: 1 addition & 2 deletions lib/config/validation.ts
Expand Up @@ -311,8 +311,7 @@ export async function validateConfig(
}

const selectors = [
'matchFiles',
'matchPaths',
'matchFileNames',
'matchLanguages',
'matchBaseBranches',
'matchManagers',
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/npm/extract/index.ts
Expand Up @@ -64,7 +64,7 @@ export async function extractPackageFile(
const error = new Error(CONFIG_VALIDATION);
error.validationSource = packageFile;
error.validationError =
'Nested package.json must not contain renovate configuration. Please use `packageRules` with `matchPaths` in your main config instead.';
'Nested package.json must not contain Renovate configuration. Please use `packageRules` with `matchFileNames` in your main config instead.';
throw error;
}
const packageJsonName = packageJson.name;
Expand Down

0 comments on commit c9f653d

Please sign in to comment.