grunt
grunt copied to clipboard
Don't use `process.chdir()`
Since Grunt can also be used via its API, I would suggest avoiding process.chdir.
One problem is if Grunt is used inside an Express app as views expects process.cwd to be the root of the app folder.
Another problem is if I want to run several Grunt files in parallel. Spawning is expensive.
With Bower it is possible to set the working dir with bower.config.cwd = 'otherfolder'. Something like that would be great with Grunt.
I'm using the Grunt API as I'm building a service that runs a repositorys Bower, Grunt etc when changes have been made in the master branch.
process.chdir should be in grunt-cli, not grunt itself.
Are you saying that I should be able to use the Grunt API without process.chdir?
@sindresorhus is correct. Grunt will move this logic to grunt-cli when it adopts node-liftoff.
There is another scenario, but it might deserve a different issue.
I want to run different sets of tasks depending on the directory I'm in.
Say, when I run grunt from the project root, I want the whole thing, but when I run it from a component subdirectory, I want to only build a single component.
Currently I need to have a separate gruntfile in every subdirectory, while having some INITIAL_DIR environment variable would help a lot.