npm / rfcs

Public change requests/proposals & ideation
Other
729 stars 239 forks source link

[RRFC] Accepting version references within `dependencies` and `devDependencies` #677

Open mon-jai opened 1 year ago

mon-jai commented 1 year ago

Motivation ("The Why")

There are some use cases where you need to switch dependencies' to a different version (e.g. downgrading/switching to beta version, etc.). But by doing so, you maybe end up with wrong version of typings (@type/*) or incompatible version of other packages (such as Babel).

Version references are already valid within the overrides field:

{
  "dependencies": {
    "foo": "^1.0.0"
  },
  "overrides": {
    // BEST, the override is defined as a reference to the dependency
    "foo": "$foo",
    // the referenced package does not need to match the overridden one
    "bar": "$foo"
  }
}

It would be nice if we also accept them in dependencies and devDependencies, making it seamlessly to update dependencies' version, without risking to break something unintended.

Example

Usage with Babel:

{
  "devDependencies": {
    "@babel/cli": "^7.0.0",
-   "@babel/core": "^7.0.0"
+   "@babel/core": "$@babel/cli"
  }
}

Usage with types:

{
  "dependencies": {
    "react-native": "^0.70.5",
  },
  "devDependencies": {
-   "@types/react-native": "^0.70.5"
+   "@types/react-native": "$react-native"
  }
}

How

Current Behaviour

npm update @babel/cli
{
  "devDependencies": {
    "@babel/cli": "^7.20.7",
    "@babel/core": "^7.0.0" // Not updated
  }
}
npm update react-native
{
  "dependencies": {
    "react-native": "^0.71.3",
  },
  "devDependencies": {
    "@types/react-native": "^0.70.5" // Wrong version
  }
}

References