Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2022-01-26 23:44:18 +0300
committerGitHub <noreply@github.com>2022-01-26 23:44:18 +0300
commitfbe48a84047e0c5de31bdaa84707f0f8fdcef71d (patch)
tree271f116ce36a7c3bfc9b49cb4161ab535d031158 /workspaces/arborist/lib
parent1f853f8bf7cecd1222703dde676a4b664526141d (diff)
feat(arborist): add named updates validation (#4307)
* feat(arborist): add named updates validation Arborist update does not support anything other than dependency names, that is confusing to some users that are used to provide semver ranges when using `npm install` and other commands. This changeset adds validation to the values provided as arguments in `npm update` and will throw a `EUPDATEARGS` error in case the user tries to use semver ranges, e.g: `npm update abbrev@1.0.0` Relates to: https://github.com/npm/cli/issues/4240
Diffstat (limited to 'workspaces/arborist/lib')
-rw-r--r--workspaces/arborist/lib/arborist/build-ideal-tree.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/workspaces/arborist/lib/arborist/build-ideal-tree.js b/workspaces/arborist/lib/arborist/build-ideal-tree.js
index df4f50159..0375e1851 100644
--- a/workspaces/arborist/lib/arborist/build-ideal-tree.js
+++ b/workspaces/arborist/lib/arborist/build-ideal-tree.js
@@ -269,6 +269,22 @@ module.exports = cls => class IdealTreeBuilder extends cls {
this[_complete] = !!options.complete
this[_preferDedupe] = !!options.preferDedupe
this[_legacyBundling] = !!options.legacyBundling
+
+ // validates list of update names, they must
+ // be dep names only, no semver ranges are supported
+ for (const name of update.names) {
+ const spec = npa(name)
+ const validationError =
+ new TypeError(`Update arguments must not contain package version specifiers
+
+Try using the package name instead, e.g:
+ npm update ${spec.name}`)
+ validationError.code = 'EUPDATEARGS'
+
+ if (spec.fetchSpec !== 'latest') {
+ throw validationError
+ }
+ }
this[_updateNames] = update.names
this[_updateAll] = update.all