2018-04-26 19:32:05 +00:00
# Adding a Package Manager
2020-11-12 09:49:53 +00:00
This document describes the steps to take if you want to add a new language/package manager.
2018-04-26 19:32:05 +00:00
2020-11-12 09:49:53 +00:00
## Code structure
2018-04-26 19:32:05 +00:00
2020-11-12 09:49:53 +00:00
Each package manager lives under `lib/manager/*` , and is often tightly coupled to datasources under `lib/datasource/*` .
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
Versioning logic (e.g. SemVer, PEP 440) lives under `lib/versioning/*` .
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
Common application logic for Renovate, not specific to particular managers, usually lives under `lib/workers/*` .
2018-04-26 19:32:05 +00:00
2020-11-12 09:49:53 +00:00
## Manager requirements
2018-04-26 19:32:05 +00:00
2020-08-05 20:14:06 +00:00
The manager's `index.ts` file supports the following values/functions:
2018-04-26 19:32:05 +00:00
2018-11-04 17:51:23 +00:00
- extractPackageFile
2018-11-05 06:47:44 +00:00
- extractAllPackageFiles
2018-06-25 09:26:12 +00:00
- getRangeStrategy (optional)
- language (optional)
- supportsLockFileMaintenance (optional)
2018-04-26 19:32:05 +00:00
2020-11-12 09:49:53 +00:00
### `extractPackageFile(content, packageFile, config)` (async, semi-mandatory)
2018-04-26 19:32:05 +00:00
2020-11-02 08:52:37 +00:00
This function is mandatory unless you use `extractAllPackageFiles` instead.
2020-11-12 09:49:53 +00:00
It takes as arguments the file's content and optionally the file's full file pathname and config.
The function returns an array of detected/extracted dependencies, including:
2018-04-26 19:32:05 +00:00
2018-05-28 07:26:22 +00:00
- dependency name
- dependency type (e.g. dependencies, devDependencies, etc)
2018-06-04 03:48:20 +00:00
- currentValue
2020-11-12 09:49:53 +00:00
- versioning used (e.g. SemVer, PEP 440)
2018-04-26 19:32:05 +00:00
2020-11-12 09:49:53 +00:00
The `extractPackageFile` function doesn't need to fully _understand_ the file or syntax that it receives.
It needs to understand enough to extract an accurate list of dependencies.
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
As a general approach, we extract _all_ dependencies from each dependency file, even if they contain values we don't support.
Any dependency file that has values we cannot renovate, should have a `skipReason` message added to the `extractPackageFile` function.
Make sure the `skipReason` variable string is helpful to someone reading the logs.
2018-06-25 09:26:12 +00:00
2020-08-05 20:14:06 +00:00
Also, if a file is passed to `extractPackageFile` which is a "false match" (e.g. not an actual package file, or contains no dependencies) then this function can return `null` to have it ignored and removed from the list of package files.
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
### `extractAllPackageFiles(packageFiles)` (async, optional)
2018-11-05 06:47:44 +00:00
2020-11-12 09:49:53 +00:00
Use this function instead of `extractPackageFile` if the package manager cannot parse/extract all package files in parallel.
2018-11-05 06:47:44 +00:00
2020-10-23 15:42:57 +00:00
For example, npm/Yarn needs to correlate package files together for features such as Lerna and Workspaces, so it's necessary to iterate through them all together after initial parsing.
2018-11-05 06:47:44 +00:00
2020-11-12 09:49:53 +00:00
As another example, Gradle needs to call a command via a child process in order to extract dependencies, so that must be done first.
2018-11-05 06:47:44 +00:00
2020-11-12 09:49:53 +00:00
The `extractAllPackageFiles` function takes an array of filenames as input.
It returns an array of filenames and dependencies.
2018-11-05 06:47:44 +00:00
2020-11-12 09:49:53 +00:00
### `getRangeStrategy(config)` (optional)
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
Write this optional function if you want the manager to support "auto" range strategies.
For example, pinning or not pinning a dependency, depending on other values in the package file.
The `npm` manager uses the `getRangeStrategy` function to pin `devDependencies` but not `dependencies` unless the package file is detected as an app.
2018-06-25 09:26:12 +00:00
If left undefined, then a default `getRangeStrategy` will be used that always returns "replace".
2020-11-12 09:49:53 +00:00
### `language` (optional)
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
This is used when more than one package manager shares settings from a common language.
2018-06-25 09:26:12 +00:00
2020-11-12 09:49:53 +00:00
### `supportsLockFileMaintenance` (optional)
2018-04-30 11:18:51 +00:00
2018-06-25 09:26:12 +00:00
Set to true if this package manager needs to update lock files in addition to package files.