rails / coffee-rails

CoffeeScript adapter for the Rails asset pipeline. Also adds support for .coffee views.
MIT License
230 stars 64 forks source link

Register ERBTracker as DependencyTracker for .coffee files to support… #91

Closed richseviora closed 7 years ago

richseviora commented 7 years ago

While researching rails#28503 I noticed that .coffee files do not resolve dependencies because they have not had a dependency tracker registered.

Given objects/show.coffee:

resourceHtml = ('<%= j render partial: 'resource', locals: {resource: resource} %>')

Running rake cache_digest:nested_dependencies TEMPLATE=objects/show would return an empty array (no dependencies).

However, once ActionView::DependencyTracker::ERBTracker has been registered as a tracker for .coffee files, running the same rake task properly resolves the dependencies.

I don't know how we can test this particular behaviour within this gem given that ActionView isn't available here, but if there's way to do so I'd love to include a few.

rails-bot commented 7 years ago

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

rafaelfranca commented 7 years ago

This broke the test suite

richseviora commented 7 years ago

Sorry about that!

OK, the problem is that ActionView does not eager_autoload DependencyTracker, it is only loaded when required through Digestor. I've added a require statement at the appropriate step.