npm / npm/cli

[DOCS] package.json overrides parent keySpec overrides parent version

Open
#9,121 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Documentation Needs Triage
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This is a CLI Docs Problem, not another kind of Docs Problem.
  • This is a CLI Docs Problem.
Description of Problem

For overrides, I was surprised to find that the parent key version range is not just a matcher / condition, but also an applied override to the parent. (if it matches the parent)

It fits the docs, once you understood. I needed some testing around, reading code and docs again to get there.

Example: Sub-dependency foo version 19 gets overridden to version 20 for the following overrides:

{ "overrides": {
  "foo@<=20": {
    "bar": "1.2.3"
  }
}}
Potential Solution

How about stating more clearly that parent key version ranges apply overrides too, adding the following?

Parent keys with version ranges override that parent's version too, if matching. Add child override `".": "$foo"` to prevent that.

This seems to do what I actually want:

{ "overrides": {
  ".": "$foo",
  "foo@<=20": {
    "bar": "1.2.3"
  }
}}

❗ I do not know though, if I should actually use reference $foo if it is a sub-dependency itself. Docs state [...] overrides may also be defined as a reference to a spec for a direct dependency [...].

Affected URL

This is regarding https://docs.npmjs.com/cli/v11/configuring-npm/package-json#overrides

The key of an override can also include a version, or range of versions. To override `@npm/foo` to `1.0.0`, but only when it's a child of `@npm/bar@2.0.0`:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the affected package.json#overrides section at the linked documentation URL, then compare the existing explanation with the supplied examples. Done means clearly documenting that a matching parent version range also overrides the parent version, including how the proposed child override reference affects the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.