diff --git a/lib/hooks/moduleloader/index.js b/lib/hooks/moduleloader/index.js index ec5ae3adfa..7ef6a47db2 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) { @@ -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 || !privateModule['package.json']) return; + + var identity = privateModule['package.json'].name; + + return _.extend(privateModule, { + identity: identity, + globalId: name + }); + } + };