jsoverson / grunt-open

Open urls and files from a grunt task
MIT License
109 stars 19 forks source link

grunt-open doesn't operate properly with grunt-contrib-watch on Windows 8 #6

Closed iamolivinius closed 11 years ago

iamolivinius commented 11 years ago

This is a minimal example to point out the problem.

Assuming a basic grunt installation exists, copy these three files in an empty folder and run npm install. Next run grunt. Now a browser should open and load "www.google.com". Then modify and save the test.coffee file. The browser should open www.google.de every time you modify the file test.coffee.

On my system Windows8 x64, node v0.10.13, and grunt v0.4.1 just the first open before "watching" is executed properly.

Gruntfile.coffee

module.exports = (grunt) ->
    require('matchdep').filterDev('grunt-*').forEach grunt.loadNpmTasks
    grunt.initConfig
        watch:
            test:
                files: ['test.coffee']
                tasks: ['open']
        open:
            server:
                path: 'http://www.google.com'
    grunt.registerTask 'live', [
        'open'
        'watch'
    ]
    grunt.registerTask 'default', ['live']

package.json

{
  "name": "openwatch",
  "version": "0.0.1",
  "dependencies": {},
  "devDependencies": {
    "grunt": "~0.4.1",
    "matchdep": "~0.1.2",
    "grunt-contrib-watch": "~0.4.4",
    "grunt-open": "~0.2.0"
  },
  "engines": {
    "node": ">=0.8.0"
  }
}

test.coffee

test = true
iamolivinius commented 11 years ago

No problems on Ubuntu 13.04 and the same node and grunt versions.

iamolivinius commented 11 years ago

Running grunt open doesn't work neither.

Debugging step by step with node-inspector leds to normal behavior. After line number 915 a new browser window pops up and loads www.google.com

C:\Users\Oliver\Desktop\tester>node --debug-brk C:\Users\Oliver\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt open

debug

jsoverson commented 11 years ago

I looked into this enough to confirm and see what's going on, but debugging in a windows 8 vm is not going very quickly for me.

I wonder if it has anything to do with the parent exiting normally very quickly after doing the 'open' since that is executed and grunt moves on. On a watch spawn and grunt open that would be very quick, but open before watch would cause grunt to stay open longer, as would debugging.

I'd test making this an async task with an arbitrary setTimeout beforring moving on, but my windows VM just started installing three hundred thousand updates.

Feel free to try setTimeout(this.async(), 200); before or after the call to open and see if that helps. I'll try as soon as my VM's updated.

iamolivinius commented 11 years ago

Well, ... you nailed it!

jsoverson commented 11 years ago

awesome, i'll publish something today. Thanks for your help and info, this would have taken ages for me to troubleshoot.

jsoverson commented 11 years ago

published in 0.2.1