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: Avoid infinite loop scenario for self-linked module parents #4

Merged
merged 1 commit into from
Apr 12, 2018
Merged
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
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ var find_package_json = function(location) {
return location;
}

// Get the parent module, or null if parent links itself
var get_parent_module = function(module) {
return (module !== module.parent) ? module.parent : null;
}

// Find the package.json object of the module closest up the module call tree that contains name in that module's peerOptionalDependencies
var find_package_json_with_name = function(name) {
// Walk up the module call tree until we find a module containing name in its peerOptionalDependencies
Expand All @@ -33,7 +38,7 @@ var find_package_json_with_name = function(name) {
location = currentModule.filename;
var location = find_package_json(location)
if (!location) {
currentModule = currentModule.parent;
currentModule = get_parent_module(currentModule);
continue;
}

Expand All @@ -44,7 +49,7 @@ var find_package_json_with_name = function(name) {

// Check whether this package.json contains peerOptionalDependencies containing the name we're searching for
if (!object.peerOptionalDependencies || (object.peerOptionalDependencies && !object.peerOptionalDependencies[parts[0]])) {
currentModule = currentModule.parent;
currentModule = get_parent_module(currentModule);
continue;
}
found = true;
Expand Down