Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nospawn + interrupt causes watch to end #377

Open
rbrcurtis opened this issue Oct 2, 2014 · 7 comments
Open

nospawn + interrupt causes watch to end #377

rbrcurtis opened this issue Oct 2, 2014 · 7 comments

Comments

@rbrcurtis
Copy link

I use spawn:false and interrupt:true and what I'm seeing happen is that when I save a file, triggering a build, then save again interrupting the first build, that grunt will exit successfully back to the command line after the second build finishes (which obv watch is supposed to keep hanging).

Any ideas why this would happen?

@shama
Copy link
Member

shama commented Oct 2, 2014

Which os and version of node? Also which task is the watch running? Some tasks call process.exit() explicitly and with spawn: false, it will exit the same process the watch is running as.

@rbrcurtis
Copy link
Author

OSX Mavericks, node 0.10.31. My build chain is pretty long but I'd bet the culprit is mochaTest. Its the longest running so the most likely to be interrupted and I believe it calls exit... The full list is below if you think that's unlikely.

rebuild: [
'clear_cache'
'markStart'
'copy:index'
'newer:copy:static'
'newer:copy:js'
'newer:concat'
'newer:coffeelint'
'newer:jshint'
'newer:coffee'
'ngtemplates'
'indexify' # CLI commands to rewrite the index
'newer:stylus'
'newer:autoprefixer'
'notify:build_complete'
'karma'
'mochaTest'
]

@shama
Copy link
Member

shama commented Oct 2, 2014

Yeah the mocha test runner doesn't play nice with spawn: false unfortunately. I think you'll need to enable spawn to run those tasks without stopping.

@rbrcurtis
Copy link
Author

Ok, I'll see if I can work around that. Thanks for the help.

@rbrcurtis
Copy link
Author

Ok, I've ripped mocha out and I still have problems, so I've tried a number of things including wrapping/rewriting process.exit and pretty much nothing is working. I'd be happy to switch to using spawn:true except there's one thing I can do with spawn:false that I can't with spawned threads, and that's defer web requests to load files until the build finishes.

IE, with spawn off, I can tell middleware in grunt-contrib-connect to hold off on fullfilling a request until the build has finished. With spawn on, I don't know when the build has finished because emitting an event in the build emits in a different process. Am I explaining that clearly?

So Assuming that resolving this at face value is implausible, how hard would it be to update this project to have an option that takes a function that executes when the watch task starts and another when it finishes in the parent process? IE, something like

  build:
    files: ['src/**/*.{css,styl,coffee,js,html,json}']
    tasks: [
      'rebuild'
      'karma'
      'mochaTest'
    ]
    options:
      spawn: true
      interrupt: true
      started: -> process.emit('build_started')
      ended: -> process.emit('build_finished')

@rbrcurtis rbrcurtis reopened this Oct 8, 2014
@joewood
Copy link

joewood commented Dec 24, 2014

Not sure if this is related, but I'm seeing the watch abort now whenever there's an error in the task when spawn is false. I see this with grunt-browserify and livereload. Setting spawn to true fixes this. I also set forever to true, just to be sure.

@faridnsh
Copy link

faridnsh commented Jan 4, 2015

@joewood Try running grunt with --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants