Skip to content

Commit 1397ef7

Browse files
committed
Update: Add docs for selective version resolutions
**Summary** Fixes #605.
1 parent 43465fe commit 1397ef7

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
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_dependency_versions_description
177180

178181
- id: docs_configuration
179182
title: docs_configuration_title

_data/i18n/en.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ docs_offline_mirror_description: |
200200
201201
docs_prune_offline_mirror: Pruning an Offline Mirror
202202

203+
docs_selective_version_resolutions_description: |
204+
Override sub-dependency version resolutions
205+
203206
yarn_organization_title: Yarn Organization
204207
yarn_organization_description: |
205208
The Yarn organization is a collaboration of many companies and
@@ -349,7 +352,7 @@ script:
349352
display_all: Display all
350353
hide: Hide
351354

352-
not_found:
355+
not_found:
353356
whoa: Whoa, {package_name} does not exist yet
354357
yours: But that means it is now yours!
355358
make: Make your package
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_selective_version_resolutions
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)