jasonm / ngmin-rails

DEPRECATED [Was: Use ngmin in the Rails asset pipeline.]
MIT License
42 stars 13 forks source link

assets:precompile fails with ngmin-rails 0.4.0 and ActiveAdmin 0.6.0 #7

Closed OscarBarrett closed 11 years ago

OscarBarrett commented 11 years ago

We have been migrating a site to a new cluster of servers that are using nodejs as the JS runtime (as therubyracer was causing issues). During asset precompilation, it seems that ngmin-rails is trying to parse one of the ActiveAdmin CoffeScript files as JavaScript instead.

Here is the output of rake assets:precompile:

+ bundle exec rake assets:precompile
/usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby ../ruby/2.0.0/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets
===================================================
/tmp/execjs20130925-12469-1sorgh4.js
===================================================
===================================================
/tmp/execjs20130925-12469-g3omuc.js
===================================================
===================================================
/tmp/execjs20130925-12469-1v9h48p.js
===================================================
===================================================
/tmp/execjs20130925-12469-1s2v70y.js
===================================================
===================================================
/tmp/execjs20130925-12469-hjws4g.js
===================================================
===================================================
/tmp/execjs20130925-12469-17w9xqu.js
===================================================
===================================================
/tmp/execjs20130925-12469-1ypbu0a.js
===================================================
===================================================
/tmp/execjs20130925-12469-1mc71z6.js
===================================================
===================================================
/tmp/execjs20130925-12469-8guyd9.js
===================================================
===================================================
/tmp/execjs20130925-12469-1rvkzra.js
===================================================
rake aborted!
Error: Line 1: Unexpected token ILLEGAL
  (in ../ruby/2.0.0/gems/activeadmin-0.6.0/app/assets/javascripts/active_admin/lib/namespace.js.coffee)
../ruby/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:73:in `extract_result'
../ruby/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:33:in `block in exec'
../ruby/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:46:in `compile_to_tempfile'
../ruby/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
../ruby/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:19:in `eval'
../ruby/2.0.0/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:38:in `call'
../ruby/2.0.0/gems/ngmin-rails-0.4.0/lib/ngmin/processor.rb:15:in `evaluate'
../ruby/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/unprocessed_asset.rb:14:in `initialize'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:16:in `new'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:16:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/asset_with_dependencies.rb:91:in `block in build_required_assets'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/asset_with_dependencies.rb:85:in `each'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/asset_with_dependencies.rb:85:in `build_required_assets'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/unprocessed_asset.rb:27:in `initialize'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:16:in `new'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:16:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/asset_with_dependencies.rb:91:in `block in build_required_assets'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/asset_with_dependencies.rb:85:in `each'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/asset_with_dependencies.rb:85:in `build_required_assets'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/sprockets/unprocessed_asset.rb:27:in `initialize'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:16:in `new'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:16:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb:12:in `initialize'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `new'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:32:in `block in compile'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
../ruby/2.0.0/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:29:in `compile'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/tasks/assets.rake:108:in `internal_precompile'
../ruby/2.0.0/gems/turbo-sprockets-rails3-0.3.10/lib/turbo-sprockets/tasks/assets.rake:115:in `block (3 levels) in <top (required)>'
Tasks: TOP => assets:precompile:all

Here is the contents of the file in question (namespace.js.coffee):

# Make a namespace for ActiveAdmin plugins  

window.AA = {}

As you can see, the first line is a valid comment for CoffeeScript only, and parsing it as JavaScript will throw an illegal token error.

The gems that we are using:

Using rake (10.1.0) 
Using i18n (0.6.1) 
Using multi_json (1.7.8) 
Using activesupport (3.2.13) 
Using builder (3.0.4) 
Using activemodel (3.2.13) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.5) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.3) 
Using tilt (1.4.1) 
Using sprockets (2.2.2) 
Using actionpack (3.2.13) 
Using mime-types (1.23) 
Using polyglot (0.3.3) 
Using treetop (1.4.14) 
Using mail (2.5.4) 
Using actionmailer (3.2.13) 
Using arbre (1.0.1) 
Using sass (3.2.9) 
Using thor (0.18.1) 
Using bourbon (3.1.8) 
Using bcrypt-ruby (3.1.1) 
Using orm_adapter (0.4.0) 
Using rack-ssl (1.3.3) 
Using json (1.8.0) 
Using rdoc (3.12.2) 
Using railties (3.2.13) 
Using warden (1.2.3) 
Using devise (3.0.0) 
Using fastercsv (1.5.5) 
Using formtastic (2.2.1) 
Using has_scope (0.5.1) 
Using responders (0.9.3) 
Using inherited_resources (1.4.0) 
Using jquery-rails (3.0.2) 
Using kaminari (0.14.1) 
Using arel (3.0.2) 
Using tzinfo (0.3.37) 
Using activerecord (3.2.13) 
Using polyamorous (0.5.0) 
Using meta_search (1.1.3) 
Using activeresource (3.2.13) 
Using bundler (1.3.5) 
Using rails (3.2.13) 
Using activeadmin (0.6.0) 
Using pg (0.15.1) 
Using activerecord-postgresql-adapter (0.0.1) 
Using acts_as_paranoid (0.4.2) 
Using addressable (2.3.5) 
Using angularjs-rails (1.0.6) 
Using mini_portile (0.5.1) 
Using nokogiri (1.6.0) 
Using uuidtools (2.1.4) 
Using aws-sdk (1.11.1) 
Using coderay (1.0.9) 
Using better_errors (0.9.0) 
Using debug_inspector (0.0.2) 
Using binding_of_caller (0.7.2) 
Using bootstrap-sass (2.3.2.1) 
Using uniform_notifier (1.2.0) 
Using bullet (4.6.0) 
Using callsite (0.0.11) 
Using cancan (1.6.10) 
Using highline (1.6.19) 
Using net-ssh (2.6.8) 
Using net-scp (1.1.2) 
Using net-sftp (2.1.2) 
Using net-ssh-gateway (1.2.0) 
Using capistrano (2.15.5) 
Using capistrano-ext (1.2.1) 
Using xpath (2.0.0) 
Using capybara (2.1.0) 
Using carrierwave (0.9.0) 
Using carrierwave_backgrounder (0.2.1) 
Using ffi (1.9.0) 
Using childprocess (0.3.9) 
Using choice (0.1.6) 
Using coffee-script-source (1.6.3) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using coffee-rails (3.2.2) 
Using columnize (0.3.6) 
Using country-select (1.1.1) 
Using daemons (1.1.9) 
Using database_cleaner (1.0.1) 
Using debugger-linecache (1.2.0) 
Using debugger-ruby_core_source (1.2.3) 
Using debugger (1.6.0) 
Using delayed_job (3.0.5) 
Using delayed_job_active_record (0.4.4) 
Using diff-lcs (1.2.4) 
Using eventmachine (1.0.3) 
Using exception_notification (4.0.0) 
Using excon (0.20.1) 
Using factory_girl (4.2.0) 
Using factory_girl_rails (4.2.1) 
Using faker (1.1.2) 
Using formatador (0.2.4) 
Using ruby-hmac (0.4.0) 
Using fog (0.7.2) 
Using rb-fsevent (0.9.3) 
Using rb-inotify (0.9.0) 
Using rb-kqueue (0.2.0) 
Using listen (1.2.2) 
Using lumberjack (1.0.4) 
Using method_source (0.8.1) 
Using slop (3.4.5) 
Using pry (0.9.12.2) 
Using guard (1.8.1) 
Using guard-jasmine (1.18.1) 
Using rspec-core (2.14.0) 
Using rspec-expectations (2.14.0) 
Using rspec-mocks (2.14.1) 
Using rspec (2.14.0) 
Using guard-rspec (3.0.2) 
Using haml (4.0.3) 
Using jasminerice (0.0.10) 
Using jquery-fileupload-rails (0.4.1) 
Using jquery-ui-rails (4.0.3) 
Using kaminari-bootstrap (0.1.3) 
Using launchy (2.3.0) 
Using letter_opener (1.1.2) 
Using rack-contrib (1.1.0) 
Using meta_request (0.2.7) 
Using ngmin-rails (0.4.0) 
Using quiet_assets (1.0.2) 
Using ruby-graphviz (1.0.9) 
Using rails-erd (1.1.0) 
Using rails_config (0.3.3) 
Using rest-client (1.6.7) 
Using rmagick (2.13.2) 
Using rspec-rails (2.14.0) 
Using rubyzip (0.9.9) 
Using rufus-scheduler (2.0.24) 
Using rvm-capistrano (1.3.4) 
Using sass-rails (3.2.6) 
Using s3_direct_upload (0.1.6) 
Using websocket (1.0.7) 
Using selenium-webdriver (2.33.0) 
Using shoulda-context (1.1.4) 
Using shoulda-matchers (2.2.0) 
Using shoulda (3.5.0) 
Using simplecov-html (0.7.1) 
Using simplecov (0.7.1) 
Using spinjs-rails (1.3) 
Using strong_parameters (0.2.1) 
Using thin (1.5.1) 
Using turbo-sprockets-rails3 (0.3.10) 
Using uglifier (2.1.1) 
Using yell (1.4.0) 
Using yell-adapters-gelf (1.2.0) from git://github.com/rudionrails/yell-adapters-gelf.git (at master) 
Using yell-rails (1.4.0) 

rake assets:precompile succeeds if we remove ngmin-rails from the Gemfile.

OscarBarrett commented 11 years ago

I just created a test project using activeadmin 0.6.1 (the latest release) and ngmin-rails 0.4.0 and can't reproduce the issue.

Jamedjo commented 10 years ago

I had the same issue processing a .coffee file Error: Line 1: Unexpected token ILLEGAL (in /home/james/.rvm/gems/ruby-1.9.3@mygemset/gems/haml_coffee_assets-1.15.0/vendor/assets/javascripts/hamlcoffee.js.coffee.erb)

My workaround was to bundle open ngmin-rails and insert the following line:

def evaluate(context, locals)
  return data if context.pathname.basename.to_s.match(/.*\.(coffee|jst).*/)

I'm sure there's a less hacky way of doing this. Maybe setting the initializer load order so ngmin-rails operates after coffee processing?