From 987ee45d01c219bf78506611bf8fd76cec0b82a6 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 17 Sep 2020 15:31:16 -0700 Subject: [PATCH] Add `--strict-peer-deps` option This is the CLI portion of https://github.com/npm/arborist/pull/136 --- docs/content/using-npm/config.md | 18 ++++++++++++++++++ lib/utils/config.js | 3 ++- lib/utils/flat-options.js | 1 + .../test-lib-utils-config.js-TAP.test.js | 9 ++++++--- .../test-lib-utils-flat-options.js-TAP.test.js | 1 + 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/content/using-npm/config.md b/docs/content/using-npm/config.md index 132f0bf580aac..2982e41dbbec7 100644 --- a/docs/content/using-npm/config.md +++ b/docs/content/using-npm/config.md @@ -1161,6 +1161,24 @@ should be polled while the user is completing authentication. If `--auth-type=sso`, the type of SSO type to use. +#### strict-peer-deps + +* Default: false +* Type: Boolean + +If set to `true`, and `--legacy-peer-deps` is not set, then _any_ +conflicting `peerDependencies` will be treated as an install failure, even +if npm could reasonably guess the appropriate resolution based on non-peer +dependency relationships. + +By default, conflicting `peerDependencies` in the dependency graph will be +resolved using the nearest non-peer dependency specification, even if doing +so will result in some packages receiving a peer dependency outside the +range set in their package's `peerDependencies` object. When such and +override is performed, a warning is printed, explaining the conflict and +the packages involved. If `--strict-peer-deps` is set, then the warning is +treated as a failure. + #### strict-ssl * Default: true diff --git a/lib/utils/config.js b/lib/utils/config.js index a7fd131d45590..d273ae8a5c459 100644 --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -111,6 +111,7 @@ const defaults = { key: null, 'legacy-bundling': false, 'legacy-peer-deps': false, + 'strict-peer-deps': false, link: false, 'local-address': undefined, loglevel: 'notice', @@ -229,7 +230,6 @@ const types = { group: [Number, String], 'https-proxy': [null, url], 'user-agent': String, - 'ham-it-up': Boolean, heading: String, 'if-present': Boolean, include: [Array, 'prod', 'dev', 'optional', 'peer'], @@ -246,6 +246,7 @@ const types = { key: [null, String], 'legacy-bundling': Boolean, 'legacy-peer-deps': Boolean, + 'strict-peer-deps': Boolean, link: Boolean, 'local-address': getLocalAddresses(), loglevel: [ diff --git a/lib/utils/flat-options.js b/lib/utils/flat-options.js index 2ace852d1e36a..d6decdbf79361 100644 --- a/lib/utils/flat-options.js +++ b/lib/utils/flat-options.js @@ -170,6 +170,7 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({ shell: npm.config.get('shell'), omit: buildOmitList(npm), legacyPeerDeps: npm.config.get('legacy-peer-deps'), + strictPeerDeps: npm.config.get('strict-peer-deps'), // npx stuff call: npm.config.get('call'), diff --git a/tap-snapshots/test-lib-utils-config.js-TAP.test.js b/tap-snapshots/test-lib-utils-config.js-TAP.test.js index eb3ad9e315044..771837959f20b 100644 --- a/tap-snapshots/test-lib-utils-config.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-config.js-TAP.test.js @@ -117,6 +117,7 @@ Object { "sign-git-tag": false, "sso-poll-frequency": 500, "sso-type": "oauth", + "strict-peer-deps": false, "strict-ssl": true, "tag": "latest", "tag-version-prefix": "v", @@ -347,7 +348,6 @@ Object { "{Number TYPE}", "{String TYPE}", ], - "ham-it-up": "{Boolean TYPE}", "heading": "{String TYPE}", "https-proxy": Array [ null, @@ -495,6 +495,7 @@ Object { "oauth", "saml", ], + "strict-peer-deps": "{Boolean TYPE}", "strict-ssl": "{Boolean TYPE}", "tag": "{String TYPE}", "tag-version-prefix": "{String TYPE}", @@ -625,6 +626,7 @@ Object { "sign-git-tag": false, "sso-poll-frequency": 500, "sso-type": "oauth", + "strict-peer-deps": false, "strict-ssl": true, "tag": "latest", "tag-version-prefix": "v", @@ -855,7 +857,6 @@ Object { "{Number TYPE}", "{String TYPE}", ], - "ham-it-up": "{Boolean TYPE}", "heading": "{String TYPE}", "https-proxy": Array [ null, @@ -1003,6 +1004,7 @@ Object { "oauth", "saml", ], + "strict-peer-deps": "{Boolean TYPE}", "strict-ssl": "{Boolean TYPE}", "tag": "{String TYPE}", "tag-version-prefix": "{String TYPE}", @@ -1133,6 +1135,7 @@ Object { "sign-git-tag": false, "sso-poll-frequency": 500, "sso-type": "oauth", + "strict-peer-deps": false, "strict-ssl": true, "tag": "latest", "tag-version-prefix": "v", @@ -1363,7 +1366,6 @@ Object { "{Number TYPE}", "{String TYPE}", ], - "ham-it-up": "{Boolean TYPE}", "heading": "{String TYPE}", "https-proxy": Array [ null, @@ -1513,6 +1515,7 @@ Object { "oauth", "saml", ], + "strict-peer-deps": "{Boolean TYPE}", "strict-ssl": "{Boolean TYPE}", "tag": "{String TYPE}", "tag-version-prefix": "{String TYPE}", diff --git a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js index 89a5527299f7d..d9aa8e8b631f3 100644 --- a/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js +++ b/tap-snapshots/test-lib-utils-flat-options.js-TAP.test.js @@ -111,6 +111,7 @@ Object { "signGitTag": "sign-git-tag", "ssoPollFrequency": undefined, "ssoType": undefined, + "strictPeerDeps": undefined, "strictSSL": "strict-ssl", "tag": "tag", "tagVersionPrefix": "tag-version-prefix",