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

Commit 03efc89

Browse files
iarnazkat
authored andcommitted
install/deps: Stop weird call-back-to-self in resolveWithNewModule
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
1 parent f45f85d commit 03efc89

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

lib/install/deps.js

+35-39
Original file line numberDiff line numberDiff line change
@@ -490,50 +490,46 @@ function replaceModule (obj, key, child, matchBy) {
490490
function resolveWithNewModule (pkg, tree, log, next) {
491491
validate('OOOF', arguments)
492492

493-
if (!pkg._installable) {
494-
log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
495-
return isInstallable(pkg, iferr(next, function () {
496-
pkg._installable = true
497-
resolveWithNewModule(pkg, tree, log, next)
498-
}))
499-
}
500-
501-
if (!pkg._from) {
502-
pkg._from = pkg._requested.name + '@' + pkg._requested.spec
503-
}
504-
addShrinkwrap(pkg, iferr(next, function () {
505-
addBundled(pkg, iferr(next, function () {
506-
var parent = earliestInstallable(tree, tree, pkg) || tree
507-
var child = createChild({
508-
package: pkg,
509-
parent: parent,
510-
path: path.join(parent.path, 'node_modules', pkg.name),
511-
realpath: path.resolve(parent.realpath, 'node_modules', pkg.name),
512-
children: pkg._bundled || [],
513-
isLink: tree.isLink
514-
})
515-
delete pkg._bundled
516-
var hasBundled = child.children.length
493+
log.silly('resolveWithNewModule', packageId(pkg), 'checking installable status')
494+
return isInstallable(pkg, iferr(next, function () {
495+
if (!pkg._from) {
496+
pkg._from = pkg._requested.name + '@' + pkg._requested.spec
497+
}
498+
addShrinkwrap(pkg, iferr(next, function () {
499+
addBundled(pkg, iferr(next, function () {
500+
var parent = earliestInstallable(tree, tree, pkg) || tree
501+
var child = createChild({
502+
package: pkg,
503+
parent: parent,
504+
path: path.join(parent.path, 'node_modules', pkg.name),
505+
realpath: path.resolve(parent.realpath, 'node_modules', pkg.name),
506+
children: pkg._bundled || [],
507+
isLink: tree.isLink,
508+
knownInstallable: true
509+
})
510+
delete pkg._bundled
511+
var hasBundled = child.children.length
517512

518-
var replaced = replaceModuleByName(parent, 'children', child)
519-
if (replaced) removeObsoleteDep(replaced)
520-
addRequiredDep(tree, child, function () {
521-
child.location = flatNameFromTree(child)
513+
var replaced = replaceModuleByName(parent, 'children', child)
514+
if (replaced) removeObsoleteDep(replaced)
515+
addRequiredDep(tree, child, function () {
516+
child.location = flatNameFromTree(child)
522517

523-
if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child)
518+
if (tree.parent && parent !== tree) updatePhantomChildren(tree.parent, child)
524519

525-
if (hasBundled) {
526-
inflateBundled(child, child.children)
527-
}
520+
if (hasBundled) {
521+
inflateBundled(child, child.children)
522+
}
528523

529-
if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) {
530-
return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) {
531-
next(er, child, log)
532-
})
533-
}
524+
if (pkg._shrinkwrap && pkg._shrinkwrap.dependencies) {
525+
return inflateShrinkwrap(child, pkg._shrinkwrap.dependencies, function (er) {
526+
next(er, child, log)
527+
})
528+
}
534529

535-
next(null, child, log)
536-
})
530+
next(null, child, log)
531+
})
532+
}))
537533
}))
538534
}))
539535
}

0 commit comments

Comments
 (0)