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/grunt
Win:
[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.execPath
is the same asprocess.argv[1]
. On Windows,process.execPath
is different:C:\Program Files\nodejs\
whereprocess.argv[1]
would beAppData\Roaming\npm\node_modules\grunt\bin\grunt
. So appending.cmd
doesn't work with this option on Windows currently.It should be
AppData\Roaming\npm\grunt.cmd
so maybe a findup fromprocess.argv[1]
is the solution for Windows. -
Running Tests While Developing
grunt-contrib-watch
Unix:
[__dirname]/../node_modules/.bin/grunt
Win:
[__dirname]/../node_modules/.bin/grunt.cmd
This is because the tests use a different
cwd
for fixtures and they don't install grunt locally to each fixture. -
Running Watch While Developing
grunt
Since
node_modules/.bin/grunt
doesn'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.cmd
doesn't exist.