gruntjs / grunt-cli

Grunt's command line interface.
http://gruntjs.com/
MIT License
706 stars 248 forks source link

Installing grunt-cli locally and using npm scripts produces warning message #98

Closed jasonrhodes closed 8 years ago

jasonrhodes commented 8 years ago

When doing this: https://github.com/gruntjs/grunt-cli#installing-grunt-cli-locally and then running grunt whatever from an npm script, I always see this warning:

>> Local Npm module "grunt-cli" not found. Is it installed?

and then everything seems to proceed fine after that. How can I silence that warning? I can't seem to find the text of the warning in this repo at all...

Note: this article mentions the same warning for the same reason -- https://glebbahmutov.com/blog/you-dont-need-global-grunt/

vladikoff commented 8 years ago

Are you loading grunt-cli as a task in your file?

jasonrhodes commented 8 years ago

No... so grunt dev-validate worked fine with globally installed grunt-cli, so i did npm install grunt-cli and set up an npm script:

{
  "scripts": {
    "test:dev": "grunt dev-validate"
  }
}

and now doing npm run test:dev produces that warning. I don't really get why.

jasonrhodes commented 8 years ago

Figured it out! See: maenu/grunt-template-jasmine-istanbul#8 where @jdelight figured out the same issue:

It was to do with calling grunt.loadNpmTasks("grunt-template-jasmine-istanbul"). I had some script which automatically loaded anything starting with "grunt-".

So I've filter these template tasks out and it's fine now :)

So in our Gruntfile I've had to change this:

// load npm tasks for grunt-* libs
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

to this:

// load npm tasks for grunt-* libs, excluding grunt-cli
require('matchdep').filterDev('grunt-*').filter(function(pkg) {
  return ['grunt-cli'].indexOf(pkg) < 0;
}).forEach(grunt.loadNpmTasks);
vladikoff commented 8 years ago

Yeap yeap!