Skip to content

Commit

Permalink
Merge pull request #3023 from tjwebb/issues/3022/npm-private-modules
Browse files Browse the repository at this point in the history
support npm private modules as hooks
  • Loading branch information
sgress454 committed Jun 19, 2015
2 parents 74ea6e6 + 3e8fa78 commit 764e266
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 @@ -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
});
}

};

0 comments on commit 764e266

Please sign in to comment.