diff options
author | Rebecca Turner <me@re-becca.org> | 2015-04-20 11:36:31 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:26:52 +0300 |
commit | 832fe13a05f2ee1a2c121329c39fd8f3bd282e5a (patch) | |
tree | 7c8358a92cbdbc4dc839e86c158667271e9d2b89 /lib/install | |
parent | 4767de606654d59c528ffe07d156dbee0413195d (diff) |
Factor out extraneous and dev module detection into stand alone packages
Diffstat (limited to 'lib/install')
-rw-r--r-- | lib/install/is-dev.js | 7 | ||||
-rw-r--r-- | lib/install/is-extraneous.js | 11 | ||||
-rw-r--r-- | lib/install/logical-tree.js | 10 |
3 files changed, 20 insertions, 8 deletions
diff --git a/lib/install/is-dev.js b/lib/install/is-dev.js new file mode 100644 index 000000000..2bbf4478e --- /dev/null +++ b/lib/install/is-dev.js @@ -0,0 +1,7 @@ +'use strict' +var isDev = exports.isDev = function (node) { + return node.package._requiredBy.filter(function (req) { return req === '#DEV:/' }).length +} +exports.isOnlyDev = function (node) { + return node.package._requiredBy.length === 1 && isDev(node) +} diff --git a/lib/install/is-extraneous.js b/lib/install/is-extraneous.js new file mode 100644 index 000000000..cf44a4826 --- /dev/null +++ b/lib/install/is-extraneous.js @@ -0,0 +1,11 @@ +'use strict' +var isDev = require('./is-dev.js').isDev + +module.exports = function (tree) { + var pkg = tree.package + var requiredBy = pkg._requiredBy.filter(function (req) { return req[0] !== '#' }) + var isTopLevel = tree.parent == null + var isChildOfTop = !isTopLevel && tree.parent.parent == null + var topHasNoPackageJson = isChildOfTop && tree.parent.package.name === undefined && tree.parent.package.version === undefined && tree.parent.package._id === undefined + return !isTopLevel && (!isChildOfTop || !topHasNoPackageJson) && requiredBy.length === 0 && !isDev(tree) +} diff --git a/lib/install/logical-tree.js b/lib/install/logical-tree.js index 06c8a8183..e6c8d5c95 100644 --- a/lib/install/logical-tree.js +++ b/lib/install/logical-tree.js @@ -5,6 +5,7 @@ var without = require('lodash.without') var validate = require('aproba') var flattenTree = require('./flatten-tree.js') var npm = require('../npm.js') +var isExtraneous = require('./is-extraneous.js') var logicalTree = module.exports = function (tree) { validate('O', arguments) @@ -58,14 +59,7 @@ function translateTree (tree) { }) pkg.path = tree.path - // All package-only requiredBys (exclude #USER and #EXISTING) - var requiredBy = pkg._requiredBy.filter(function (req) { return req[0] !== '#' }) - var isDev = pkg._requiredBy.filter(function (req) { return req.substr(0,4) === '#DEV' }).length - - var isTopLevel = tree.parent == null - var isChildOfTop = !isTopLevel && tree.parent.parent == null - var topHasNoPackageJson = isChildOfTop && tree.parent.package.name === undefined && tree.parent.package.version === undefined && tree.parent.package._id === undefined - pkg.extraneous = !isTopLevel && (!isChildOfTop || !topHasNoPackageJson) && requiredBy.length === 0 && !isDev + pkg.extraneous = isExtraneous(tree) if (tree.target && tree.parent && !tree.parent.target) pkg.link = tree.realpath return pkg } |