documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

How to get verbose output when compile javascript with errors #50

Closed jwilsonsprings closed 14 years ago

jwilsonsprings commented 14 years ago

First, love this package. Second, I noticed while integrating this with my site, I made a typo in one of my .js files. When it gets compressed via jammit, it just produces a zero length file. No errors, nothing...

I looked thru source and did not find anything obvious about how to make the ruby-yui-compressor generate errors (or whatever) when it compresses and discovers a problem.

Suggestions?

jashkenas commented 14 years ago

Oh man ... I know this problem only too well. It's extremely difficult, using the Ruby standard library, to read the exit status, as well as stdout and stderr from a child process, and to do in on Windows as well as Nix. The ruby-yui-compressor gem simply ignores stderr and failed compilation. I had to jump through hoops with the closure-compiler gem, in order to get a nearly cross-plaform version of popen to work:

http://github.com/documentcloud/closure-compiler/blob/master/lib/closure/popen.rb

So, I'd say that the easy fix would be to use the Closure Compiler instead, which will throw an exception with the syntax error and line number. You can use it by adding a line to the top of your assets.yml.

javascript_compressor: closure

I've pinged sstephenson about the YUI Compressor error problem before, but he didn't write back. Your other option is to open a ruby-yui-compressor ticket to get it fixed.