Skip to content

Commit d77b3a0

Browse files
authored
Fix: prevent hoister from adding an ancesstor when there is none (#4132)
**Summary** Just fixes a small bug in the hoisting code where it pushed `undefined` to the ancestor list when traversing the-level dependencies. **Test plan** N/A
1 parent d42b81c commit d77b3a0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/package-hoister.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,13 @@ export default class PackageHoister {
411411
*/
412412

413413
hoist(info: HoistManifest) {
414-
const {key, parts: rawParts} = info;
414+
const {key: oldKey, parts: rawParts} = info;
415415

416416
// remove this item from the `tree` map so we can ignore it
417-
this.tree.delete(key);
417+
this.tree.delete(oldKey);
418418

419-
const {parts, duplicate} = this.getNewParts(key, info, rawParts.slice());
419+
const {parts, duplicate} = this.getNewParts(oldKey, info, rawParts.slice());
420420
const newKey = this.implodeKey(parts);
421-
const oldKey = key;
422421
if (duplicate) {
423422
info.addHistory(`Satisfied from above by ${newKey}`);
424423
this.declareRename(info, rawParts, parts);
@@ -428,7 +427,7 @@ export default class PackageHoister {
428427
// update to the new key
429428
if (oldKey === newKey) {
430429
info.addHistory("Didn't hoist - conflicts above");
431-
this.setKey(info, oldKey, parts);
430+
this.setKey(info, oldKey, rawParts);
432431
return;
433432
}
434433

@@ -513,7 +512,10 @@ export default class PackageHoister {
513512
occurences: new Set(),
514513
pattern,
515514
});
516-
version.occurences.add(ancestry[ancestry.length - 1]);
515+
516+
if (ancestry.length) {
517+
version.occurences.add(ancestry[ancestry.length - 1]);
518+
}
517519

518520
for (const depPattern of ref.dependencies) {
519521
add(depPattern, ancestry.concat(pkg));

0 commit comments

Comments
 (0)