Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop when hoisting cyclic dependencies #8979

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/package-hoister.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class HoistManifest {
this.parts = parts;
this.originalKey = key;
this.previousPaths = [];
this.previousPatterns = new Set();

this.history = [];
this.addHistory(`Start position = ${key}`);
Expand All @@ -58,6 +59,7 @@ export class HoistManifest {
loc: string;
parts: Parts;
previousPaths: Array<string>;
previousPatterns: Set<string>;
history: Array<string>;
key: string;
originalKey: string;
Expand Down Expand Up @@ -210,6 +212,11 @@ export default class PackageHoister {
pattern: string,
{isDirectRequire, parent}: {isDirectRequire: boolean, parent?: HoistManifest},
): ?HoistManifest {
// Detected a cyclic dependency, so break the cycle.
if (parent != null && parent.previousPatterns.has(pattern)) {
return null;
}

//
const pkg = this.resolver.getStrictResolvedPattern(pattern);
const ref = pkg._reference;
Expand Down Expand Up @@ -240,6 +247,7 @@ export default class PackageHoister {
const parts = parentParts.concat(pkg.name);
const key: string = this.implodeKey(parts);
const info: HoistManifest = new HoistManifest(key, parts, pkg, loc, isDirectRequire, isRequired, isIncompatible);
info.previousPatterns = new Set(parent == null ? [] : parent.previousPatterns).add(pattern);

this.nohoistResolver.initNohoist(info, parent);

Expand Down