Skip to content

Commit e25c4e4

Browse files
authored
Update: Add docs for selective version resolutions (#633)
**Summary** Fixes #605.
1 parent 43fbd2c commit e25c4e4

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

_data/guides.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@
174174
path: /docs/dependency-versions
175175
tags: ["dependencies-versions"]
176176
description: docs_dependency_versions_description
177+
- id: docs_selective_version_resolutions
178+
path: /docs/selective-version-resolutions
179+
description: docs_selective_version_resolutions_description
177180

178181
- id: docs_configuration
179182
title: docs_configuration_title

_data/i18n/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ docs_workspaces_title: Workspaces
205205
docs_workspaces_description: |
206206
Link together your projects for easier maintenance.
207207
208+
docs_selective_version_resolutions_description: |
209+
Override sub-dependency version resolutions with Yarn.
210+
208211
yarn_organization_title: Yarn Organization
209212
yarn_organization_description: |
210213
The Yarn organization is a collaboration of many companies and
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
id: docs_selective_version_resolutions
3+
guide: docs_dependencies
4+
layout: guide
5+
---
6+
7+
Yarn supports selective version resolutions, which lets you define custom package versions inside your dependencies through the `resolutions` field in your `package.json` file. Normally, this would
8+
require manual edits in the `yarn.lock` file.
9+
10+
### Why would you want to do this? <a class="toc" id="toc-why-would-you-want-to-do-this" href="#toc-why-would-you-want-to-do-this"></a>
11+
12+
- You may be depending on a package that is not updated frequently, which depends on another package that got an important upgrade. In this case, if the version range specified by your direct dependency does not cover the new sub-dependency version, you are stuck waiting for the author.
13+
14+
- A sub-dependency of your project got an important security update and you don't want to wait for your direct-dependency to issue a minimum version update.
15+
16+
- You are relying on an unmaintained but working package and one of its dependencies got upgraded. You know the ugprade would not break things and you also don't want to fork the package you are relying on, just to update a minor dependency.
17+
18+
- Your dependency defines a broad version range and your sub-dependency just got a problematic update so you want to pin it to an earlier version.
19+
20+
### How to use it? <a class="toc" id="toc-how-to-use-it" href="#toc-how-to-use-it"></a>
21+
22+
Add a `resolutions` field to your `package.json` file and define your version overrides:
23+
24+
**package.json**
25+
26+
```json
27+
{
28+
"name": "project",
29+
"version": "1.0.0",
30+
"dependencies": {
31+
"left-pad": "1.0.0",
32+
"c": "file:../c-1",
33+
"d2": "file:../d2-1"
34+
},
35+
"resolutions": {
36+
"d2/left-pad": "1.1.1",
37+
"c/**/left-pad": "1.1.2"
38+
}
39+
}
40+
```
41+
42+
Then run `yarn install`.
43+
44+
### Tips & Tricks <a class="toc" id="toc-tips-tricks" href="#toc-tips-tricks"></a>
45+
46+
- You will receive a warning if you define an invalid resolution (such as with an invalid package name)
47+
- You will receive a warning if your resolution version or range is not valid.
48+
- You will receive a warning if your resolution version or range is not compatible with the original version range.
49+
50+
### Limitations & Caveheats <a class="toc" id="toc-limitations-caveheats" href="#toc-limitations-caveheats"></a>
51+
52+
- Nested packages may nor work properly.
53+
- Certain edge-cases may not work properly since this is a fairly new feature.

0 commit comments

Comments
 (0)