Skip to content

Commit 90784b4

Browse files
author
Sebastian McKenzie
committed
handle case where we weren't properly restricting the keys of modules deep in the tree who could be satisfied by one higher in the tree
1 parent 3662ef9 commit 90784b4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/package-linker.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ export default class PackageLinker {
121121
let checkParts = ownParts.slice(0, i).concat(pkg.name);
122122
let checkKey = checkParts.join("#");
123123
let check = tree[checkKey];
124-
if (check && check.loc === loc) return [];
124+
if (check && check.loc === loc) {
125+
// we have a compatible module above us, we should mark the current
126+
// module key as restricted and continue on
127+
unflattenedKeys.add(ownParts.concat(pkg.name).join("#"));
128+
return [];
129+
}
125130
}
126131
ownParts.push(pkg.name);
127132

@@ -213,16 +218,20 @@ export default class PackageLinker {
213218
tree[newKey] = info;
214219
pair[0] = newKey;
215220

216-
// go through and update all transitive dependencies and update to new hoisting position
221+
// go through and update all transitive dependencies and update their keys to the new
222+
// hoisting position
217223
let pairs = subPairs.get(info) || [];
218224
for (let pair of pairs) {
219225
let [subKey] = pair;
220-
221226
if (subKey === newKey) continue;
222227

223228
let newSubKey = subKey.replace(new RegExp(`^${oldKey}#`), `${newKey}#`);
224229
if (newSubKey === subKey) continue;
225230

231+
// restrict use of the new key in case we hoist it further from here
232+
unflattenedKeys.add(newSubKey);
233+
234+
// update references
226235
tree[newSubKey] = tree[subKey];
227236
pair[0] = newSubKey;
228237
delete tree[subKey];

0 commit comments

Comments
 (0)