moshen / jekyll-asset_bundler

A small plugin for Jekyll to easily bundle and compress site assets
MIT License
101 stars 21 forks source link

Syntax error if last line is a comment #21

Closed michel-kraemer closed 10 years ago

michel-kraemer commented 10 years ago

Hi!

First of all, thanks for this great tool! I think I found a bug though (kind of). I get a syntax error in the resulting bundle when one of the source files has a comment as its last line. Look at this file for example: https://raw.githubusercontent.com/jquery/jquery/2.1.1/dist/jquery.min.js

Since the next file is just appended to this one (without a line break), the next file's first line will be swallowed.

I know it doesn't make sense to bundle already minified files like jquery.min.js, and comments in the last line without a final line break are rather rare, so I consider this issue a corner case. However, you may want to have a look at it. It might save others the trouble I had finding the reason for the syntax error.

Cheers, Michel

moshen commented 10 years ago

I'm having trouble re-creating this. Could you post some more details on your config? Thanks!

michel-kraemer commented 10 years ago

I'm sorry for the delay. I'm going to create a minimal example. However, since I'm on the road at the moment it might take a couple of days.

Cheers, Michel

moshen commented 10 years ago

An example would be great, Thanks.

michel-kraemer commented 10 years ago

I created a small test project: https://github.com/michel-kraemer/jekyll-asset_bundler_issue-23

It has only two commits so you can exactly see what I did. First I ran jekyll new . to create a new website in the current directory (commit 1). Then I added two javascript files and specified a bundle in _includes/footer.html (commit 2).

Steps to reproduce:

  1. Clone the repository
  2. cd into the cloned directory
  3. Run jekyll build

You will get the following error message:

org.mozilla.javascript.EvaluatorException: Compilation produced 1 syntax errors.
..... long stack trace
Liquid Exception: Command 'java -jar /home/mkraemer/.rvm/gems/ruby-2.0.0-p481/gems/yui-compressor-0.12.0/lib/yui/../yuicompressor-2.4.8.jar --type js --charset utf-8 --nomunge /tmp/yui_compress20140529-10164-rsclt2' returned non-zero exit status in _includes/footer.html, included in _layouts/default.html

The problem is that the first javascript file jquery.min.js ends with a comment but not with a new line character. jekyll-asset_bundler appends the next file directly to the first one which makes the first line of the second file to be swallowed (commented out).

Hope this helps. Please let me know if you need something else.

Michel

moshen commented 10 years ago

Thanks! I will confirm later, but at first glance I can see there is definitely something wrong.

michel-kraemer commented 10 years ago

Thanks for the fix!