grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Get rid of "global" plugins.

Open cowboy opened this issue 14 years ago • 11 comments

The reason that global grunt plugins exist was to basically provide an easy way for task authors to bundle their custom tasks and init templates in a single easy-to-install package. That plugin would include grunt internally, as a dependency, and would thus have access to everything grunt had to offer, plus some extra stuff.

The problem with this, of course, is that globally installing one version of a thing-that-has-multiple-versions is irreconcilable with working on multiple projects that require different versions of that thing. If you have plugin-foo v1.0.0 installed globally, project bar that requires plugin-foo v1.0.0 will work great, but project baz that requires plugin-foo v1.5.0 won't necessarily work great.

This problem is already addressed in npm by installing npm modules locally. If the project-appropriate version of plugin-foo is installed local to projects bar and baz, there are no problems.

Of course, this doesn't work with init templates, because since init templates are used to create projects, they need to exist somewhere already. Which means that init templates can't be installed as npm modules.

Which brings me to the grunt.npmTasks method. It was created for use in grunt plugins that will be installed globally. It's a total hack created back when I thought grunt was going to be installed globally, and not locally. It tells grunt to load tasks bundled with the plugin as a dependency. This method has to go.

Of course, it can only be removed if there is, in fact, an alternative to globally installed plugins. Which there will be when the init task is improved to load templates dynamically. See #239.

cowboy avatar Sep 19 '12 16:09 cowboy

So the concept of global plugins (like installing grunt-contrib-less or grunt-exec globally with the -g flag) will no longer exist and will simply have to be installed with the project in node_modules/. Is that basically what you're saying?

ghost avatar Sep 25 '12 16:09 ghost

@littlejim84 correct. You'd install grunt globally as a convenient way to initialize new projects and run a locally-installed grunt from within any subdirectory of a project via grunt, but you wouldn't install grunt plugins globally.

cowboy avatar Sep 25 '12 17:09 cowboy

I'm working in a project with several modules that use their own grunt build, but where every build is supposed to use the same version of grunt and contrib plugins. This is today done by having the npm plugins "globally", higher up in the folder tree.

If this isn't the way you want grunt to behave, do you have any suggestions to how we should solve our wanted behaviour? Locally installing the same npm plugins for every module seems like a big waste.

Chrazy avatar Oct 03 '12 07:10 Chrazy

@Chrazy you could use symlinks to share node_modules folders between projects. Also, talk to isaacs and see if he has any suggestions. He wrote npm.

cowboy avatar Oct 03 '12 12:10 cowboy

@Chrazy npm link may help.

@cowboy what do you recommend as the best way for users to install custom init templates? I'm building one right now and am wondering how to make the process super easy for people. I have an idea: what if the user didn't have to install the template beforehand at all— just specify the name and (optional) version. Grunt init would then do a temp npm install of the init template specified, perhaps hanging on to it internally for the next time, but always checking for the latest specified version each time init is run. Some examples:

$ grunt init:jquery

$ grunt init:[email protected]

$ grunt init:[email protected]

$ grunt init:https://whatever.domain.org/my.custom.template.tar.gz

Of course the names would have to match what's in the npm registry, so it would have to be more like

$ grunt init:grunt-jquery

End result:

  • people can generate a new project using any custom (public or private) template easily
  • nothing to install beforehand but grunt
  • global/versioned init templates problem solved

Thoughts?

geddski avatar Oct 10 '12 07:10 geddski

Probably, someone will come here and was seeking for a solution to make working grunt tasks with his/her virtualbox shared folder.

Indeed, npm can't do symlink on virtualbox shared folder, so you have to install node modules as global. For example, if you want to install grunt-compass, do:

$ npm install -g grunt-compass

and do:

$ cp -R /usr/lib/node_modules/grunt-compass ~/projects/your-project/node_modules

kud avatar Oct 10 '12 22:10 kud

So, I know this is a closed issue but I just gotta ask... If one of the main reasons is that ' globally installing one version of a thing-that-has-multiple-versions is irreconcilable with working on multiple projects that require different versions of that thing.' why not add a mechanism to require a specific version of the task (is a good thing you have access to a package.js, isn't it?) or just add a failback mechanism to the global plugin.

Most projects do that, I'm curious why such a mechanism was not considered, and if it was, I'd be double curious to know the reasoning behind outright banning global plugin, before implementing something like it.

neurogeek avatar May 15 '13 18:05 neurogeek

@neurogeek node.js/npm does not and will not do that so we should not as well since this is a node project. See https://npmjs.org/doc/faq.html#I-installed-something-globally-but-I-can-t-require-it

shama avatar May 15 '13 19:05 shama

I'm in the same situation as @Chrazy - with many hundreds of small projects (none of which are proper node projects) that I'd like to be able to just drop a Gruntfile.js into and run a grunt command with shared plugins.

Since grunt-cli is already locating and using grunt instances that it finds by traversing up the folder tree - why can't it (at least optionally) do the same thing for grunt plugins?

maranomynet avatar Sep 19 '13 11:09 maranomynet

Im getting this thing popping up in my project because you insist to install locally, which does not make any sense because is the only one project I have to manage, and is breaking things because the paths are too large

FileNotFoundError: [WinError 3] The system cannot find the path specified: 'S:\www\asd.data\compile\node_modules\grunt-contrib-uglify\node_modules\maxmin\node_modules\pretty-bytes\node_modules\meow\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-correct\node_modules\spdx-license-ids_._'

I'm gonna get ride of this non-sense-shiny-grunt-do-as-i-wish-gonna-be-obsolete-in-a-few-years-losing-time with a bunch of python scripts as soon as I have time.

titoBouzout avatar Feb 10 '16 15:02 titoBouzout

Thank you

titoBouzout avatar Feb 10 '16 15:02 titoBouzout