Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function installMany (what, where, context, cb) {
// what is a list of things.
// resolve each one.
asyncMap( what
, targetResolver(where, context, d)
, targetResolver(where, context, d, wrap)
, function (er, targets) {

if (er) return cb(er)
Expand All @@ -499,24 +499,56 @@ function installMany (what, where, context, cb) {
})
asyncMap(targets, function (target, cb) {
log.info("installOne", target._id)
var newWrap = wrap ? wrap[target.name].dependencies || {} : null
var newContext = { family: newPrev

var newWrap = (wrap && wrap[target.name])? wrap[target.name].dependencies || {} : null
, newContext = { family: newPrev
, ancestors: newAnc
, parent: parent
, explicit: false
, wrap: newWrap }
installOne(target, where, newContext, cb)

// if the package already installed and has the version equal to the shrinkwrap
// call installMany for the package deps
if (target.depsOnly && target.depsOnly[where]) {

var newWhere = path.join(where, 'node_modules', target.name)

readDependencies(newContext, where, opt, function(er, data, wrap) {
var deps = Object.keys(data.dependencies || {})

var newContext = { family: newPrev
, ancestors: newAnc
, parent: parent
, explicit: false
, wrap: wrap }

installMany(deps.map(function(d) {
return d + "@" + data.dependencies[d]
}), newWhere, newContext, function(er, d) {

log.verbose("about to build", newWhere)
if (er) return cb(er)
npm.commands.build([newWhere]
, npm.config.get("global")
, true
, function(er) {
return cb(er, d)
})
})
})
}
else installOne(target, where, newContext, cb)
}, cb)
})
})
}

function targetResolver (where, context, deps) {
function targetResolver (where, context, deps, wrap) {
var alreadyInstalledManually = context.explicit ? [] : null
, nm = path.resolve(where, "node_modules")
, parent = context.parent
, wrap = context.wrap

, wrap = context.wrap || wrap
if (!context.explicit) fs.readdir(nm, function (er, inst) {
if (er) return alreadyInstalledManually = []
asyncMap(inst, function (pkg, cb) {
Expand Down Expand Up @@ -550,8 +582,20 @@ function targetResolver (where, context, deps) {
// now we know what's been installed here manually,
// or tampered with in some way that npm doesn't want to overwrite.
if (alreadyInstalledManually.indexOf(what.split("@").shift()) !== -1) {
log.verbose("already installed", "skipping %s %s", what, where)
return cb(null, [])
if (!wrap) {
log.verbose("already installed", "skipping %s %s", what, where)
return cb(null, [])
}

var name = what.split(/@/).shift()

return cache.read(name, wrap[name].version, false, function(er, data) {
// depsOnly will tell later that the package is ok but we should to check its deps
data.depsOnly = data.depsOnly || {}
data.depsOnly[where] = true;
data._from = what
return cb(er, data)
})
}

// check for a version installed higher in the tree.
Expand Down