Never mind about everything below. I overcomplicated something very simple. Spawn child process with process.argv[0] and use process.argv[1] as the first argument. Duh.
Instances Where The Grunt Bin Is Needed
-
Project w/ Locally Installed Grunt
Unix:
[cwd]/node_modules/.bin/gruntWin:
[cwd]/node_modules/.bin/grunt.cmd -
Project w/ Globally Installed Grunt (not installed locally, Grunt v0.3)
Unix:
process.argv[1] ([npm]/grunt)Win:
process.argv[1] (AppData\Roaming\npm\node_modules\grunt\bin\grunt)On Unix,
process.execPathis the same asprocess.argv[1]. On Windows,process.execPathis different:C:\Program Files\nodejs\whereprocess.argv[1]would beAppData\Roaming\npm\node_modules\grunt\bin\grunt. So appending.cmddoesn't work with this option on Windows currently.It should be
AppData\Roaming\npm\grunt.cmdso maybe a findup fromprocess.argv[1]is the solution for Windows. -
Running Tests While Developing
grunt-contrib-watchUnix:
[__dirname]/../node_modules/.bin/gruntWin:
[__dirname]/../node_modules/.bin/grunt.cmdThis is because the tests use a different
cwdfor fixtures and they don't install grunt locally to each fixture. -
Running Watch While Developing
gruntSince
node_modules/.bin/gruntdoesn't exist on grunt itself we have to use the globally installed grunt in instance 2.When Grunt v0.4 must be installed locally, the watch would do:
[cwd]/bin/grunt. Although still won't work with Windows as[cwd]\bin\grunt.cmddoesn't exist.