Skip to content

Commit

Permalink
resolves balderdashy#3022. support npm private modules as hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwebb authored and ctartist621 committed Feb 3, 2016
1 parent fbf27ed commit 151a3bc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -564,4 +570,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
});
}

};

0 comments on commit 151a3bc

Please sign in to comment.