Skip to content

Commit

Permalink
Update: Add docs for selective version resolutions
Browse files Browse the repository at this point in the history
**Summary**

Fixes #605.
  • Loading branch information
BYK committed Sep 7, 2017
1 parent 1c04a88 commit 8864d2d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _data/guides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@
path: /docs/dependency-versions
tags: ["dependencies-versions"]
description: docs_dependency_versions_description
- id: docs_selective_version_resolutions
path: /docs/selective-version-resolutions
description: docs_dependency_versions_description

- id: docs_configuration
title: docs_configuration_title
Expand Down
3 changes: 3 additions & 0 deletions _data/i18n/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ docs_workspaces_title: Workspaces
docs_workspaces_description: |
Link together your projects for easier maintenance.
docs_selective_version_resolutions_description: |
Override sub-dependency version resolutions with Yarn.
yarn_organization_title: Yarn Organization
yarn_organization_description: |
The Yarn organization is a collaboration of many companies and
Expand Down
53 changes: 53 additions & 0 deletions lang/en/docs/selective-version-resolutions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
id: docs_selective_version_resolutions
guide: docs_selective_version_resolutions
layout: guide
---

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
require manual edits in the `yarn.lock` file.

### 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>

- 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.

- 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.

- 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.

- 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.

### How to use it? <a class="toc" id="toc-how-to-use-it" href="#toc-how-to-use-it"></a>

Add a `resolutions` field to your `package.json` file and define your version overrides:

**package.json**

```json
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"left-pad": "1.0.0",
"c": "file:../c-1",
"d2": "file:../d2-1"
},
"resolutions": {
"d2/left-pad": "1.1.1",
"c/**/left-pad": "1.1.2"
}
}
```

Then run `yarn install`.

### Tips & Tricks <a class="toc" id="toc-tips-tricks" href="#toc-tips-tricks"></a>

- You will receive a warning if you define an invalid resolution (such as with an invalid package name)
- You will receive a warning if your resolution version or range is not valid.
- You will receive a warning if your resolution version or range is not compatible with the original version range.

### Limitations & Caveheats <a class="toc" id="toc-limitations-caveheats" href="#toc-limitations-caveheats"></a>

- Nested packages may nor work properly.
- Certain edge-cases may not work properly since this is a fairly new feature.

0 comments on commit 8864d2d

Please sign in to comment.