Skip to content

Commit

Permalink
inflate-shrinkwrap: Allow shrinkwraps to elide dev dependencies
Browse files Browse the repository at this point in the history
If your shrinkwrap contains NO dev dependencies then we'll still try to
install them from your package.json instead of assuming you NEVER want dev
dependencies.

Credit: @iarna
Reviewed-By: @zkat
PR-URL: npm/npm#14327
  • Loading branch information
iarna committed Oct 20, 2016
1 parent 0ae1f4b commit f22a1ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ function loadDeps (tree, log, next) {
exports.loadDevDeps = function (tree, log, next) {
validate('OOF', arguments)
if (!tree.package.devDependencies) return andFinishTracker.now(log, next)
// if any of our prexisting children are from a shrinkwrap then we skip
// loading dev deps as the shrinkwrap will already have provided them for us.
if (tree.children.some(function (child) { return child.shrinkwrapDev })) {
return andFinishTracker.now(log, next)
}
asyncMap(Object.keys(tree.package.devDependencies), function (dep, done) {
// things defined as both dev dependencies and regular dependencies are treated
// as the former
Expand Down
11 changes: 10 additions & 1 deletion lib/install/inflate-shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ function inflateShrinkwrap (topPath, tree, swdeps, finishInflating) {
validate('SOOF', arguments)
var onDisk = {}
tree.children.forEach(function (child) { onDisk[moduleName(child)] = child })
tree.children = []
var dev = npm.config.get('dev') || (!/^prod(uction)?$/.test(npm.config.get('only')) && !npm.config.get('production')) || /^dev(elopment)?$/.test(npm.config.get('only'))
var prod = !/^dev(elopment)?$/.test(npm.config.get('only'))

// If the shrinkwrap has no dev dependencies in it then we'll leave the one's
// already on disk. If it DOES have dev dependencies then ONLY those in the
// shrinkwrap will be included.
var swHasDev = Object.keys(swdeps).some(function (name) { return swdeps[name].dev })
tree.children = swHasDev ? [] : tree.children.filter(function (child) {
return tree.package.devDependencies[moduleName(child)]
})

return asyncMap(Object.keys(swdeps), doRealizeAndInflate, finishInflating)

function doRealizeAndInflate (name, next) {
Expand All @@ -41,6 +49,7 @@ function inflateShrinkwrap (topPath, tree, swdeps, finishInflating) {
var child = onDisk[name]
if (childIsEquivalent(sw, requested, child)) {
if (!child.fromShrinkwrap) child.fromShrinkwrap = requested.raw
if (sw.dev) child.shrinkwrapDev = true
tree.children.push(child)
annotateMetadata(child.package, requested, requested.raw, topPath)
return inflateShrinkwrap(topPath, child, dependencies || {}, next)
Expand Down

0 comments on commit f22a1ae

Please sign in to comment.