fix: Avoid infinite loop scenario for self-linked module parents #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ran into an infinite loop, under a big stack of dependencies in another project. Jest was testing something using mongodb, which required a bunch of different connection modules, which require_optional'd "snappy", which it searched up in the package.jsons for. Unfortunately the project's root-level package.json appeared to link itself as its own
parent
, which hangs the entire instance in an infinite loop. It continually reads the package.json, sees there's no"peerOptionalDependencies"
in it for the module it's looking for, then reloads the same package.json and tries again.This fix takes the safe approach and sets the
currentModule
tonull
, if its parent is itself. It's not necessary we know all the scenarios that can cause this, only that it did happen, so it should throw an exception. The current exception for when thewhile (currentModule)
loop is done will now be thrown.