@@ -372,16 +372,22 @@ task.loadNpmTasks = function(name) {
372372 var root = path . resolve ( 'node_modules' ) ;
373373 var pkgpath = path . join ( root , name ) ;
374374 var pkgfile = path . join ( pkgpath , 'package.json' ) ;
375+ var pkgDistDir = '' ;
375376 // If package does not exist where grunt expects it to be,
376377 // try to find it using Node's package path resolution mechanism
377378 if ( ! grunt . file . exists ( pkgpath ) ) {
378379 var nameParts = name . split ( '/' ) ;
379380 // In case name points to directory inside module,
380381 // get real name of the module with respect to scope (if any)
381382 var normailzedName = ( name [ 0 ] === '@' ? nameParts . slice ( 0 , 2 ) . join ( '/' ) : nameParts [ 0 ] ) ;
383+ // Sometimes a module's task are not at the root of the package, the "name" could contain
384+ // the directory to find the tasks (e.g. grunt-foo/dist/tasks). Therefore, if the name
385+ // contains more than two part, then treat the last part as the directory to find the tasks.
386+ if ( nameParts . length > 2 ) {
387+ pkgDistDir = nameParts . slice ( 2 ) . join ( '/' ) ;
388+ }
382389 try {
383390 pkgfile = require . resolve ( normailzedName + '/package.json' ) ;
384- root = pkgfile . substr ( 0 , pkgfile . length - normailzedName . length - '/package.json' . length ) ;
385391 } catch ( err ) {
386392 grunt . log . error ( 'Local Npm module "' + normailzedName + '" not found. Is it installed?' ) ;
387393 return ;
@@ -409,11 +415,11 @@ task.loadNpmTasks = function(name) {
409415 }
410416
411417 // Process task plugins.
412- var tasksdir = path . join ( path . dirname ( pkgfile ) , 'tasks' ) ;
418+ var tasksdir = path . join ( path . dirname ( pkgfile ) , pkgDistDir , 'tasks' ) ;
413419 if ( grunt . file . exists ( tasksdir ) ) {
414420 loadTasks ( tasksdir ) ;
415421 } else {
416- grunt . log . error ( 'Local Npm module "' + name + '" not found. Is it installed?' ) ;
422+ grunt . log . error ( 'Local Npm module "' + name + '" not found. Is it installed?????? ' ) ;
417423 }
418424} ;
419425
0 commit comments