Rails 4.0 patterns: correct JS-compressor fix, revert ASSETS_COMPRESS over-specification#106
Open
JuanVqz wants to merge 3 commits into
Open
Rails 4.0 patterns: correct JS-compressor fix, revert ASSETS_COMPRESS over-specification#106JuanVqz wants to merge 3 commits into
JuanVqz wants to merge 3 commits into
Conversation
The previous fix said simply "Replace with config.assets.js_compressor = :uglifier and config.assets.css_compressor = :sass." That advice silently fails on dual-boot setups where the next? and !next? bundles ship different JS-compressor gems. The :uglifier / :terser / :sass symbol values are resolved against the actual gem at boot. If terser is in the current bundle and uglifier is in the next bundle, an unconditional `config.assets.js_compressor = :uglifier` raises NameError: uninitialized constant Uglifier on the side that lacks the gem. Updated explanation calls out the symbol-vs-gem dependency directly. Updated fix adds the rule of thumb: unconditional symbol assignment is safe only when the named compressor gem is present in BOTH bundles. When the Gemfile gates the gem, gate the symbol assignment too with NextRails.next?. Example included in the fix so operators recognize the safe shape: config.assets.js_compressor = NextRails.next? ? :uglifier : :terser Same priority and kind — high_priority, breaking.
Modern JS-compressor gems (terser, recent uglifier lines, closure-compiler builds) declare a runtime dependency on sprockets/digest_utils, which lives in Sprockets >= 4. Rails 4.x and 5.x lock Sprockets to the 2.x / 3.x line via sprockets-rails constraints. The next bundle resolves cleanly — gemspec passes railsbump's dependency check — but loading the gem at boot raises: LoadError: cannot load such file -- sprockets/digest_utils This is a class of gem-compat issue invisible to railsbump because bundle install succeeds against the gemspec; the failure happens at require-time, after the bundle is locked. Catalog the pattern so operators recognize the LoadError stack trace immediately during a Workflow 06 Step 12 boot smoke or a Workflow 09 test-suite run. Detection: regex matches `gem "terser"` and `gem "closure-compiler"` in the Gemfile explicitly. For uglifier the breaking versions are 4.x+; a hit on a bare `gem "uglifier"` needs a version-pin check, called out in the explanation. Fix: gate the gem in the Gemfile so the next side gets a Rails-4-era equivalent (`gem "uglifier", ">= 1.3.0"`) while the current side keeps the modern gem. Pair with the ASSETS_COMPRESS pattern's gated symbol assignment so the :uglifier symbol resolves on the next side and terser's auto-registration handles the current side. Classified high_priority / kind: breaking — boot-fatal at gem require time on the next side.
- JS_COMPRESSOR_GEM_MISMATCH: previous fix swapped terser for uglifier on the next side, which discards the modern-JS assets terser was added for. Rewrite to the real recipe (terser require:false + uglifier symbol shim + runtime rake swap) and move the full writeup to a reference file. Trim the cross-version boundary text; this is the 4.0 file. - ASSETS_COMPRESS: revert to the plain documented fix. The Form-2/NameError dual-boot caveat was engagement-specific and misleading for general users. - Add references/js-compressor-sprockets-dual-boot.md.
4ba8894 to
577d262
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I was unsure if adding this as PR, because the usage of
terserseems too specific, but then I thought there might be more apps using it in Rails 3.2, and it is better if we got a reference on how we solved it one time.But I'm open to your opinions on whether we should keep them or not.