Skip to content

Commit

Permalink
feat(packageRules): migrate matchers and excludes (#28602)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <[email protected]>
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
3 people committed May 31, 2024
1 parent 7f63efd commit b66597a
Show file tree
Hide file tree
Showing 51 changed files with 570 additions and 1,641 deletions.
192 changes: 24 additions & 168 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Consider this example:
"labels": ["dependencies"],
"packageRules": [
{
"matchPackagePatterns": ["eslint"],
"matchPackageNames": ["/eslint/"],
"labels": ["linting"]
},
{
Expand Down Expand Up @@ -1080,7 +1080,7 @@ If you want to approve _specific_ packages, set `dependencyDashboardApproval` to
{
"packageRules": [
{
"matchPackagePatterns": ["^@package-name"],
"matchPackageNames": ["/^@package-name/"],
"dependencyDashboardApproval": true
}
]
Expand Down Expand Up @@ -1161,7 +1161,7 @@ To disable Renovate for all `eslint` packages, you can configure a package rule
{
"packageRules": [
{
"matchPackagePatterns": ["^eslint"],
"matchPackageNames": ["eslint**"],
"enabled": false
}
]
Expand Down Expand Up @@ -2170,7 +2170,7 @@ Consider this example:
"labels": ["dependencies"],
"packageRules": [
{
"matchPackagePatterns": ["eslint"],
"matchPackageNames": ["/eslint/"],
"labels": ["linting"]
}
]
Expand Down Expand Up @@ -2408,14 +2408,14 @@ Here is an example if you want to group together all packages starting with `esl
{
"packageRules": [
{
"matchPackagePatterns": ["^eslint"],
"matchPackageNames": ["eslint**"],
"groupName": "eslint packages"
}
]
}
```

Note how the above uses `matchPackagePatterns` with a regex value.
Note how the above uses `matchPackageNames` with a prefix pattern.

Here's an example config to limit the "noisy" `aws-sdk` package to weekly updates:

Expand All @@ -2432,24 +2432,22 @@ Here's an example config to limit the "noisy" `aws-sdk` package to weekly update

For Maven dependencies, the package name is `<groupId:artefactId>`, e.g. `"matchPackageNames": ["com.thoughtworks.xstream:xstream"]`

Note how the above uses `matchPackageNames` instead of `matchPackagePatterns` because it is an exact match package name.
This is the equivalent of defining `"matchPackagePatterns": ["^aws\-sdk$"]`.
However you can mix together both `matchPackageNames` and `matchPackagePatterns` in the same package rule and the rule will be applied if _either_ match.
Note how the above uses an exact match string for `matchPackageNames` instead of a pattern
However you can mix together both patterns and exact matches in the same package rule and the rule will be applied if _either_ match.
Example:

```json
{
"packageRules": [
{
"matchPackageNames": ["neutrino"],
"matchPackagePatterns": ["^@neutrino/"],
"matchPackageNames": ["neutrino", "@neutrino/**"],
"groupName": "neutrino monorepo"
}
]
}
```

The above rule will group together the `neutrino` package and any package matching `@neutrino/*`.
The above rule will group together the `neutrino` package and any package starting with `@neutrino/`.

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:
Expand Down Expand Up @@ -2574,88 +2572,6 @@ Instead you should do `> 13 months`.
Use this field if you want to limit a `packageRule` to certain `depType` values.
Invalid if used outside of a `packageRule`.

For more details on supported syntax see Renovate's [string pattern matching documentation](./string-pattern-matching.md).

### excludeDepNames

### excludeDepPatterns

### excludeDepPrefixes

### excludePackageNames

**Important**: Do not mix this up with the option `ignoreDeps`.
Use `ignoreDeps` instead if all you want to do is have a list of package names for Renovate to ignore.

Use `excludePackageNames` if you want to have one or more exact name matches excluded in your package rule.
See also `matchPackageNames`.

```json
{
"packageRules": [
{
"matchPackagePatterns": ["^eslint"],
"excludePackageNames": ["eslint-foo"]
}
]
}
```

The above will match all package names starting with `eslint` but exclude the specific package `eslint-foo`.

### excludePackagePatterns

Use this field if you want to have one or more package name patterns excluded in your package rule.
See also `matchPackagePatterns`.

```json
{
"packageRules": [
{
"matchPackagePatterns": ["^eslint"],
"excludePackagePatterns": ["^eslint-foo"]
}
]
}
```

The above will match all package names starting with `eslint` but exclude ones starting with `eslint-foo`.

### excludePackagePrefixes

Use this field if you want to have one or more package name prefixes excluded in your package rule, without needing to write a regex.
See also `matchPackagePrefixes`.

```json
{
"packageRules": [
{
"matchPackagePrefixes": ["eslint"],
"excludePackagePrefixes": ["eslint-foo"]
}
]
}
```

The above will match all package names starting with `eslint` but exclude ones starting with `eslint-foo`.

### excludeRepositories

Use this field to restrict rules to a particular repository. e.g.

```json
{
"packageRules": [
{
"excludeRepositories": ["literal/repo", "/^some/.*$/", "**/*-archived"],
"enabled": false
}
]
}
```

This field supports Regular Expressions if they begin and end with `/`, otherwise it will use `minimatch`.

### matchCategories

Use `matchCategories` to restrict rules to a particular language or group.
Expand Down Expand Up @@ -2706,7 +2622,7 @@ Use this field to restrict rules to a particular branch. e.g.
"packageRules": [
{
"matchBaseBranches": ["main"],
"excludePackagePatterns": ["^eslint"],
"matchPackageNames": ["eslint**"],
"enabled": false
}
]
Expand All @@ -2720,7 +2636,7 @@ This field also supports Regular Expressions if they begin and end with `/`. e.g
"packageRules": [
{
"matchBaseBranches": ["/^release/.*/"],
"excludePackagePatterns": ["^eslint"],
"matchPackageNames": ["eslint**"],
"enabled": false
}
]
Expand Down Expand Up @@ -2796,7 +2712,7 @@ Regular Expressions must begin and end with `/`.
{
"packageRules": [
{
"matchPackagePatterns": ["io.github.resilience4j"],
"matchPackageNames": ["io.github.resilience4j**"],
"matchCurrentValue": "/^1\\./"
}
]
Expand All @@ -2810,7 +2726,7 @@ Use the syntax `!/ /` like this:
{
"packageRules": [
{
"matchPackagePatterns": ["io.github.resilience4j"],
"matchPackageNames": ["io.github.resilience4j**"],
"matchCurrentValue": "!/^0\\./"
}
]
Expand Down Expand Up @@ -2851,7 +2767,7 @@ For example, the following enforces that only `1.*` versions will be used:
{
"packageRules": [
{
"matchPackagePatterns": ["io.github.resilience4j"],
"matchPackageNames": ["io.github.resilience4j**"],
"matchCurrentVersion": "/^1\\./"
}
]
Expand All @@ -2865,7 +2781,7 @@ Use the syntax `!/ /` like this:
{
"packageRules": [
{
"matchPackagePatterns": ["io.github.resilience4j"],
"matchPackageNames": ["io.github.resilience4j**"],
"matchCurrentVersion": "!/^0\\./"
}
]
Expand Down Expand Up @@ -2925,20 +2841,6 @@ For more details on supported syntax see Renovate's [string pattern matching doc

This field behaves the same as `matchPackageNames` except it matches against `depName` instead of `packageName`.

### matchDepPatterns

<!-- prettier-ignore -->
!!! note
`matchDepNames` now supports pattern matching and should be used instead.
Use of `matchDepPatterns` is now deprecated and will be migrated in future.

### matchDepPrefixes

<!-- prettier-ignore -->
!!! note
`matchDepNames` now supports pattern matching and should be used instead.
Use of `matchDepPrefixes` is now deprecated and will be migrated in future.

### matchNewValue

This option is matched against the `newValue` field of a dependency.
Expand All @@ -2963,7 +2865,7 @@ Regular Expressions must begin and end with `/`.
{
"packageRules": [
{
"matchPackagePatterns": ["io.github.resilience4j"],
"matchPackageNames": ["io.github.resilience4j**"],
"matchNewValue": "/^1\\./"
}
]
Expand All @@ -2977,7 +2879,7 @@ Use the syntax `!/ /` like this:
{
"packageRules": [
{
"matchPackagePatterns": ["io.github.resilience4j"],
"matchPackageNames": ["io.github.resilience4j**"],
"matchNewValue": "!/^0\\./"
}
]
Expand Down Expand Up @@ -3012,15 +2914,14 @@ The above will configure `rangeStrategy` to `pin` only for the npm package `angu
{
"packageRules": [
{
"matchDatasources": ["npm"],
"matchPackageNames": ["@angular/*", "!@angular/abc"],
"groupName": "Angular"
"matchPackagePatterns": ["^angular", "!@angular/abc"],
"rangeStrategy": "replace"
}
]
}
```

The above will group together any npm package which starts with `@angular/` except `@angular/abc`.
The above will set a replaceStrategy for any npm package which starts with `@angular/` except `@angular/abc`.

```json title="pattern match using RegEx"
{
Expand All @@ -3036,51 +2937,6 @@ The above will group together any npm package which starts with `@angular/` exce

The above will group together any npm package which starts with the string `angular`.

### matchPackagePatterns

<!-- prettier-ignore -->
!!! note
`matchPackageNames` now supports pattern matching and should be used instead.
Use of `matchPackagePatterns` is now deprecated and will be migrated in future.

### matchPackagePrefixes

<!-- prettier-ignore -->
!!! note
`matchPackageNames` now supports pattern matching and should be used instead.
Use of `matchPackagePrefixes` is now deprecated and will be migrated in future.

Use this field to match a package prefix without needing to write a regex expression.
See also `excludePackagePrefixes`.

```json
{
"packageRules": [
{
"matchPackagePrefixes": ["angular"],
"rangeStrategy": "replace"
}
]
}
```

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

### matchSourceUrlPrefixes

Here's an example of where you use this to group together all packages from the `renovatebot` GitHub org:

```json
{
"packageRules": [
{
"matchSourceUrlPrefixes": ["https://github.com/renovatebot/"],
"groupName": "All renovate packages"
}
]
}
```

### matchSourceUrls

Here's an example of where you use this to group together all packages from the Vue monorepo:
Expand Down Expand Up @@ -3215,7 +3071,7 @@ For example, the following package rule can be used to replace the registry for
"packageRules": [
{
"matchDatasources": ["docker"],
"matchPackagePatterns": ["^docker\\.io/.+"],
"matchPackageNames": ["docker.io/**"],
"replacementNameTemplate": "{{{replace 'docker\\.io/' 'ghcr.io/' packageName}}}"
}
]
Expand All @@ -3230,13 +3086,13 @@ Or, to add a registry prefix to any `docker` images that do not contain an expli
{
"description": "official images",
"matchDatasources": ["docker"],
"matchPackagePatterns": ["^[a-z-]+$"],
"matchPackageNames": ["/^[a-z-]+$/"],
"replacementNameTemplate": "some.registry.org/library/{{{packageName}}}"
},
{
"description": "non-official images",
"matchDatasources": ["docker"],
"matchPackagePatterns": ["^[a-z-]+/[a-z-]+$"],
"matchPackageNames": ["/^[a-z-]+/[a-z-]+$/"],
"replacementNameTemplate": "some.registry.org/{{{packageName}}}"
}
]
Expand Down
8 changes: 4 additions & 4 deletions docs/usage/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ The basic idea is that you create a new `packageRules` entry and describe what k
{
"packageRules": [
{
"matchPackagePatterns": ["^jest"],
"matchPackageNames": ["jest"],
"matchUpdateTypes": ["major"],
"dependencyDashboardApproval": true
}
Expand Down Expand Up @@ -223,13 +223,13 @@ e.g.

### Apply a rule, but only for packages starting with `abc`

Do the same as above, but instead of using `matchPackageNames`, use `matchPackagePatterns` and a regex:
Do the same as above, but instead of an exact match, use a glob prefix:

```json
{
"packageRules": [
{
"matchPackagePatterns": "^abc",
"matchPackageNames": "abc**",
"assignees": ["importantreviewer"]
}
]
Expand All @@ -244,7 +244,7 @@ As above, but apply a `groupName`:
{
"packageRules": [
{
"matchPackagePatterns": "^abc",
"matchPackageNames": "abc**",
"groupName": ["abc packages"]
}
]
Expand Down
Loading

0 comments on commit b66597a

Please sign in to comment.