Skip to content

Commit 532f1c1

Browse files
committed
Revert "install/dedupe: fix hoisting of packages with peerDeps (#147)"
This reverts commit 91314e7. Fixes: https://npm.community/t/npm-6-8-0-next-0-regression-in-maximally-flat-install/5118
1 parent 309260d commit 532f1c1

File tree

4 files changed

+10
-209
lines changed

4 files changed

+10
-209
lines changed

lib/dedupe.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ function hoistChildren_ (tree, diff, seen, next) {
142142
[andComputeMetadata(tree)]
143143
], done)
144144
}
145-
// find a location where it's installable
146-
var hoistTo = earliestInstallable(tree, tree, child.package, log, child)
147-
if (hoistTo && hoistTo !== tree) {
145+
var hoistTo = earliestInstallable(tree, tree.parent, child.package, log)
146+
if (hoistTo) {
148147
move(child, hoistTo, diff)
149148
chain([
150149
[andComputeMetadata(hoistTo)],

lib/install/deps.js

+6-23
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ function resolveWithNewModule (pkg, tree, log, next) {
650650
return isInstallable(pkg, (err) => {
651651
let installable = !err
652652
addBundled(pkg, (bundleErr) => {
653-
var parent = earliestInstallable(tree, tree, pkg, log, null) || tree
653+
var parent = earliestInstallable(tree, tree, pkg, log) || tree
654654
var isLink = pkg._requested.type === 'directory'
655655
var child = createChild({
656656
package: pkg,
@@ -755,11 +755,11 @@ function preserveSymlinks () {
755755
// Find the highest level in the tree that we can install this module in.
756756
// If the module isn't installed above us yet, that'd be the very top.
757757
// If it is, then it's the level below where its installed.
758-
var earliestInstallable = exports.earliestInstallable = function (requiredBy, tree, pkg, log, ignoreChild) {
759-
validate('OOOOZ|OOOOO', arguments)
758+
var earliestInstallable = exports.earliestInstallable = function (requiredBy, tree, pkg, log) {
759+
validate('OOOO', arguments)
760760

761761
function undeletedModuleMatches (child) {
762-
return child !== ignoreChild && !child.removed && moduleName(child) === pkg.name
762+
return !child.removed && moduleName(child) === pkg.name
763763
}
764764
const undeletedMatches = tree.children.filter(undeletedModuleMatches)
765765
if (undeletedMatches.length) {
@@ -778,7 +778,7 @@ var earliestInstallable = exports.earliestInstallable = function (requiredBy, tr
778778
// If any of the children of this tree have conflicting
779779
// binaries then we need to decline to install this package here.
780780
var binaryMatches = pkg.bin && tree.children.some(function (child) {
781-
if (child === ignoreChild || child.removed || !child.package.bin) return false
781+
if (child.removed || !child.package.bin) return false
782782
return Object.keys(child.package.bin).some(function (bin) {
783783
return pkg.bin[bin]
784784
})
@@ -804,23 +804,6 @@ var earliestInstallable = exports.earliestInstallable = function (requiredBy, tr
804804

805805
if (tree.phantomChildren && tree.phantomChildren[pkg.name]) return null
806806

807-
// if any of the peer dependencies is a dependency of the current
808-
// tree locations, we place the package here. This is a safe location
809-
// where we don't violate the peer dependencies contract.
810-
// It may not be the perfect location in some cases, but we don't know
811-
// if dependencies are hoisted to another location yet, as they
812-
// may not be loaded into the tree yet.
813-
// We can ignore dev deps here as they are only installed on top-level
814-
// and we can't hoist further than that anyway.
815-
var peerDeps = pkg.peerDependencies
816-
if (peerDeps) {
817-
if (Object.keys(peerDeps).some(function (name) {
818-
return deps[name]
819-
})) {
820-
return tree
821-
}
822-
}
823-
824807
if (tree.isTop) return tree
825808
if (tree.isGlobal) return tree
826809

@@ -829,5 +812,5 @@ var earliestInstallable = exports.earliestInstallable = function (requiredBy, tr
829812

830813
if (!preserveSymlinks() && /^[.][.][\\/]/.test(path.relative(tree.parent.realpath, tree.realpath))) return tree
831814

832-
return (earliestInstallable(requiredBy, tree.parent, pkg, log, ignoreChild) || tree)
815+
return (earliestInstallable(requiredBy, tree.parent, pkg, log) || tree)
833816
}

test/tap/hoist-peer-dependencies.js

-130
This file was deleted.

test/tap/unit-deps-earliestInstallable.js

+2-53
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test('earliestInstallable should consider devDependencies', function (t) {
6767
dep2a.parent = dep1
6868
dep2.parent = pkg
6969

70-
var earliest = earliestInstallable(dep1, dep1, dep2a.package, log, null)
70+
var earliest = earliestInstallable(dep1, dep1, dep2a.package, log)
7171
t.isDeeply(earliest, dep1, 'should hoist package when an incompatible devDependency is present')
7272
t.end()
7373
})
@@ -108,58 +108,7 @@ test('earliestInstallable should reuse shared prod/dev deps when they are identi
108108
dep1.parent = pkg
109109
dep2.parent = pkg
110110

111-
var earliest = earliestInstallable(dep1, dep1, dep2.package, log, null)
111+
var earliest = earliestInstallable(dep1, dep1, dep2.package, log)
112112
t.isDeeply(earliest, pkg, 'should reuse identical shared dev/prod deps when installing both')
113113
t.end()
114114
})
115-
116-
test('earliestInstallable should consider peerDependencies', function (t) {
117-
var dep1 = {
118-
children: [],
119-
package: {
120-
name: 'dep1',
121-
dependencies: {
122-
dep2: '1.0.0',
123-
dep3: '1.0.0'
124-
}
125-
},
126-
path: '/dep1',
127-
realpath: '/dep1'
128-
}
129-
130-
var dep2 = {
131-
package: {
132-
name: 'dep2',
133-
version: '1.0.0',
134-
peerDependencies: {
135-
dep3: '1.0.0'
136-
},
137-
_requested: npa('dep2@^1.0.0')
138-
},
139-
parent: dep1,
140-
path: '/dep1/node_modules/dep2',
141-
realpath: '/dep1/node_modules/dep2'
142-
}
143-
144-
var pkg = {
145-
isTop: true,
146-
children: [dep1],
147-
package: {
148-
name: 'pkg',
149-
dependencies: { dep1: '1.0.0' }
150-
},
151-
path: '/',
152-
realpath: '/'
153-
}
154-
155-
dep1.parent = pkg
156-
157-
var earliest = earliestInstallable(dep1, dep1, dep2.package, log, null)
158-
t.isDeeply(earliest, dep1, 'should not be able to hoist the package to top-level')
159-
160-
dep1.children.push(dep2)
161-
162-
var earliestWithIgnore = earliestInstallable(dep1, dep1, dep2.package, log, dep2)
163-
t.isDeeply(earliestWithIgnore, dep1, 'should not be able to hoist the package to top-level')
164-
t.end()
165-
})

0 commit comments

Comments
 (0)