From af894c265d0753f5ef724a27cbd297799895691d Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Tue, 23 Jul 2019 18:24:50 +0100 Subject: [PATCH] install: correctly exclude dev dependencies when using global and shrinkwrap See report at https://npm.community/t/devdependencies-are-installed-if-global-flag-used-and-shrinkwrap-file-is-present/9019 Signed-off-by: Gergely Imreh --- lib/install/is-only-dev.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/install/is-only-dev.js b/lib/install/is-only-dev.js index 804497393eaa3..fa9651a76d825 100644 --- a/lib/install/is-only-dev.js +++ b/lib/install/is-only-dev.js @@ -5,13 +5,15 @@ const moduleName = require('../utils/module-name.js') const isDevDep = require('./is-dev-dep.js') const isProdDep = require('./is-prod-dep.js') -// Returns true if the module `node` is only required direcctly as a dev +// Returns true if the module `node` is only required directly as a dev // dependency of the top level or transitively _from_ top level dev // dependencies. // Dual mode modules (that are both dev AND prod) should return false. function isOnlyDev (node, seen) { if (!seen) seen = new Set() - return node.requiredBy.length && node.requiredBy.every(andIsOnlyDev(moduleName(node), seen)) + const isRequired = node.requiredBy.length > 0 + const isTranstiveDependency = isRequired && node.requiredBy.every(andIsOnlyDev(moduleName(node), seen)) + return isTranstiveDependency || !isRequired } // There is a known limitation with this implementation: If a dependency is