Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
install/deps: Stop weird call-back-to-self in resolveWithNewModule
Browse files Browse the repository at this point in the history
We were doing a weird thing where we used a package.json field _installable_
to check to see if we'd checked for platform compatibility, and if not did
so.  But this was the only place that was ever done so there was no reason to
implement it in such an obfuscated manner.

Instead it now just directly checks and then records that its done so on the
node object with `knownInstallable`.  This is useful to know because modules
expanded via shrinkwrap don't go through this– `inflateShrinkwrap` does not
currently have any rollback semantics and so checking this sort of thing there
is unhelpful.

PR-URL: #13692
Credit: @iarna
Reviewed-By: @zkat
  • Loading branch information
iarna authored and zkat committed Sep 8, 2016
1 parent f45f85d commit 03efc89
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions lib/install/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,50 +490,46 @@ function replaceModule (obj, key, child, matchBy) {
function resolveWithNewModule (pkg, tree, log, next) {
validate('OOOF', arguments)

if (!pkg._installable) {
log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
return isInstallable(pkg, iferr(next, function () {
pkg._installable = true
resolveWithNewModule(pkg, tree, log, next)
}))
}

if (!pkg._from) {
pkg._from = pkg._requested.name + '@' + pkg._requested.spec
}
addShrinkwrap(pkg, iferr(next, function () {
addBundled(pkg, iferr(next, function () {
var parent = earliestInstallable(tree, tree, pkg) || tree
var child = createChild({
package: pkg,
parent: parent,
path: path.join(parent.path, 'node_modules', pkg.name),
realpath: path.resolve(parent.realpath, 'node_modules', pkg.name),
children: pkg._bundled || [],
isLink: tree.isLink
})
delete pkg._bundled
var hasBundled = child.children.length
log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
return isInstallable(pkg, iferr(next, function () {
if (!pkg._from) {
pkg._from = pkg._requested.name + '@' + pkg._requested.spec
}
addShrinkwrap(pkg, iferr(next, function () {
addBundled(pkg, iferr(next, function () {
var parent = earliestInstallable(tree, tree, pkg) || tree
var child = createChild({
package: pkg,
parent: parent,
path: path.join(parent.path, 'node_modules', pkg.name),
realpath: path.resolve(parent.realpath, 'node_modules', pkg.name),
children: pkg._bundled || [],
isLink: tree.isLink,
knownInstallable: true
})
delete pkg._bundled
var hasBundled = child.children.length

var replaced = replaceModuleByName(parent, 'children', child)
if (replaced) removeObsoleteDep(replaced)
addRequiredDep(tree, child, function () {
child.location = flatNameFromTree(child)
var replaced = replaceModuleByName(parent, 'children', child)
if (replaced) removeObsoleteDep(replaced)
addRequiredDep(tree, child, function () {
child.location = flatNameFromTree(child)

if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child)
if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child)

if (hasBundled) {
inflateBundled(child, child.children)
}
if (hasBundled) {
inflateBundled(child, child.children)
}

if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) {
return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) {
next(er, child, log)
})
}
if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) {
return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) {
next(er, child, log)
})
}

next(null, child, log)
})
next(null, child, log)
})
}))
}))
}))
}
Expand Down

0 comments on commit 03efc89

Please sign in to comment.