renovate/website/docs/config-presets.md
2018-06-16 09:55:16 +02:00

4.5 KiB

title description
Shareable Config Presets Renovate's support for eslint-like shareable configs

Shareable Config Presets

Renovate supports an eslint-like approach to shareable configs, which we usually refer to as "presets". These are added/configured via the "extends" field in any configuration object.

Goals of Preset Configs

The main reason for supporting preset configs is to decrease duplication:

  1. You shouldn't need copy/paste config across all your repositories
  2. You shouldn't need to reinvent any config "wheels" that others have invented before

A further reason was to make Renovate configuration "self-documenting", by adding the "description" field to all preset configs.

Implementation Approach

In order to achieve the above goals, preset configs have been implemented to allow a very modular approach - preset configs may be as small as a partial package rule or as extensive as an entire configuration, like an eslint config.

Example configs

An example of a small rule is ":preserveSemverRanges", which has the description "Preserve (but continue to upgrade) any existing semver ranges". It simply sets the configuration option rangeStrategy to replace.

An example of a full config is "config:base", which is Renovate's default configuration. It mostly uses Renovate config defaults but adds a few smart customisations such as grouping monorepo packages together.

Special note: the :xyz naming convention (with : prefix) is a special shorthand for the default presets. i.e. :xyz is equivalent to default:xyz.

How to Use Preset Configs

By default, the Renovate onboarding process will suggest ["config:base]". A typical onboarding renovate.json will therefore look like this:

{
  "extends": ["config:base"]
}

Let's say you wish to modify that default behaviour, such as to schedule Renovate to process upgrades only during non-office hours. In that case you could modify the default renovate.json to be like this:

{
  "extends": ["config:base", "schedule:nonOfficeHours"]
}

This makes use of the schedules presets. To see all presets published by the Renovate team then browse https://github.com/singapore/renovate-config/tree/master/packages

How to Publish Preset Configs

If you manage multiple repositories (e.g. you're a GitHub org or an active private developer) and want the same custom config across all or most of them, then you might want to consider publishing your own preset config so that you can "extend" it in every applicable repository. That way when you want to change your Renovate configuration you can make the change in one location rather than having to copy/paste it to every repository individually.

Let's say that your username on npm and elsewhere is "fastcore". In that case, you can choose between publishing your preset config package as @fastcore/renovate-config or renovate-config-fastcore. Let's assume you choose renovate-config-fastcore as the package name:

You then need to publish the renovate-config-fastcore package where the package.json contains the field renovate-config and then put your config under the field default. For example:

{
  "name": "renovate-config-fastcore",
  "version": "0.0.1",
  ...
  "renovate-config": {
    "default": {
      "extends": ["config:base", "schedule:nonOfficeHours"]
    }
  }
}

Then in each of your repositories you can add your renovate config like:

  "extends": ["fastcore"]

Any repository including this config will then adopt the rules of the default library preset but schedule it on weeknights or weekends.

Note: if you prefer to publish using the namespace @fastcore/renovate-config then you would use the @ prefix instead:

  "extends": ["@fastcore"]

Contributing to presets

Have you configured a rule that you think others might benefit from? Please consider contributing it to the renovate-config repository so that it gains higher visibility and saves others from reinventing the same thing.