From 5f0a6f07bb0edb4e5fbdf7fc61121e68fd0783f6 Mon Sep 17 00:00:00 2001 From: Luigi Mannoni Date: Thu, 3 May 2018 15:51:18 +0100 Subject: [PATCH 1/2] Check if the currentModule.filename is reporting the actual entrypoint and strip it out --- index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5110066..d892df5 100644 --- a/index.js +++ b/index.js @@ -23,11 +23,6 @@ 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 @@ -36,9 +31,16 @@ var find_package_json_with_name = function(name) { while (currentModule) { // Check currentModule has a package.json location = currentModule.filename; + + if (typeof location === 'string' && location.indexOf('.js') > 0) { + location = location.split('/') + location.pop(); + location = location.join('/'); + } + var location = find_package_json(location) if (!location) { - currentModule = get_parent_module(currentModule); + currentModule = currentModule.parent; continue; } @@ -49,7 +51,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 = get_parent_module(currentModule); + currentModule = currentModule.parent; continue; } found = true; From 4ba03ee855c95f0c83307652856f3319b53844e5 Mon Sep 17 00:00:00 2001 From: Luigi Mannoni Date: Thu, 3 May 2018 15:54:09 +0100 Subject: [PATCH 2/2] Bringing up to date with current commit --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d892df5..4675498 100644 --- a/index.js +++ b/index.js @@ -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 @@ -31,16 +36,16 @@ var find_package_json_with_name = function(name) { while (currentModule) { // Check currentModule has a package.json location = currentModule.filename; - + if (typeof location === 'string' && location.indexOf('.js') > 0) { location = location.split('/') location.pop(); location = location.join('/'); } - + var location = find_package_json(location) if (!location) { - currentModule = currentModule.parent; + currentModule = get_parent_module(currentModule); continue; } @@ -51,7 +56,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; @@ -132,4 +137,4 @@ require_optional.exists = function(name) { } } -module.exports = require_optional; +module.exports = require_optional;