grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Don't use `process.chdir()`

Open webjay opened this issue 11 years ago • 4 comments

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.

webjay avatar May 21 '14 10:05 webjay

process.chdir should be in grunt-cli, not grunt itself.

sindresorhus avatar May 23 '14 21:05 sindresorhus

Are you saying that I should be able to use the Grunt API without process.chdir?

webjay avatar May 23 '14 21:05 webjay

@sindresorhus is correct. Grunt will move this logic to grunt-cli when it adopts node-liftoff.

tkellen avatar May 25 '14 15:05 tkellen

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.

hoho avatar Nov 08 '16 16:11 hoho