From c996d412efaba11c455918470bcac058d94630df Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Fri, 19 Jun 2015 01:18:07 -0400 Subject: [PATCH 1/3] resolves #3022. support npm private modules as hooks --- lib/hooks/moduleloader/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/hooks/moduleloader/index.js b/lib/hooks/moduleloader/index.js index ec5ae3adfa..8c7460af5e 100644 --- a/lib/hooks/moduleloader/index.js +++ b/lib/hooks/moduleloader/index.js @@ -454,6 +454,12 @@ module.exports = function(sails) { try { _.extend(hooks, _.reduce(results.nodeModulesFolder, function(memo, module, identity) { + var privateModule = isPrivateModule(module); + + if (privateModule) { + module = privateModule; + identity = privateModule.identity; + } // Hooks loaded from "node_modules" need to have "sails.isHook: true" in order for us // to know that they are a sails hook @@ -562,4 +568,22 @@ module.exports = function(sails) { }; } + function isPrivateModule(module) { + var keys = _.keys(module); + + if (keys.length !== 3 || !/^@/.test(module.identity)) return; + + var name = keys[0]; + var privateModule = module[name]; + + if (!privateModule['package.json']) return; + + var identity = privateModule['package.json'].name; + + return _.extend(privateModule, { + identity: identity, + globalId: name + }); + } + }; From 0e9f46193be4300e816ea30e77f1b4a93b2cd41f Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Fri, 19 Jun 2015 01:49:31 -0400 Subject: [PATCH 2/3] corrected buildDictionary depth setting --- lib/hooks/moduleloader/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/hooks/moduleloader/index.js b/lib/hooks/moduleloader/index.js index 8c7460af5e..6cd6058733 100644 --- a/lib/hooks/moduleloader/index.js +++ b/lib/hooks/moduleloader/index.js @@ -441,7 +441,7 @@ module.exports = function(sails) { dirname: path.resolve(sails.config.appPath, "node_modules"), filter: /^(package\.json)$/, excludeDirs: /^\./, - depth: 2 + depth: 3 }, cb); } }, function(err, results) { @@ -576,7 +576,10 @@ module.exports = function(sails) { var name = keys[0]; var privateModule = module[name]; - if (!privateModule['package.json']) return; + console.log(module) + console.log(name); + + if (!privateModule || !privateModule['package.json']) return; var identity = privateModule['package.json'].name; From 3e8fa789595bf39b660ba3249fd7eca9c8e7e26f Mon Sep 17 00:00:00 2001 From: Travis Webb Date: Fri, 19 Jun 2015 01:50:13 -0400 Subject: [PATCH 3/3] removed log statements --- lib/hooks/moduleloader/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/hooks/moduleloader/index.js b/lib/hooks/moduleloader/index.js index 6cd6058733..7ef6a47db2 100644 --- a/lib/hooks/moduleloader/index.js +++ b/lib/hooks/moduleloader/index.js @@ -576,9 +576,6 @@ module.exports = function(sails) { var name = keys[0]; var privateModule = module[name]; - console.log(module) - console.log(name); - if (!privateModule || !privateModule['package.json']) return; var identity = privateModule['package.json'].name;