Revert "PERF: Skip compressing locales for faster rebuilds (#7501)" (#7502)

Revert “PERF: Skip compressing locales for faster rebuilds (#7501)” (#7502)

diff --git a/config/environments/production.rb b/config/environments/production.rb
index fd344fa..c12ed4e 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -12,8 +12,7 @@ Discourse::Application.configure do
   # Disable Rails's static asset server (Apache or nginx will already do this)
   config.public_file_server.enabled = GlobalSetting.serve_static_assets || false
 
-  require 'uglifier'
-  config.assets.js_compressor = Uglifier.new(harmony: true)
+  config.assets.js_compressor = :uglifier
 
   # stuff should be pre-compiled
   config.assets.compile = false
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index 47ee8f5..fe37448 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -16,7 +16,7 @@ task 'assets:precompile:before' do
   # is recompiled
   Emoji.clear_cache
 
-  if !`which uglifyjs`.empty? && !ENV['SKIP_NODE_UGLIFY']
+  if Rails.configuration.assets.js_compressor == :uglifier && !`which uglifyjs`.empty? && !ENV['SKIP_NODE_UGLIFY']
     $node_uglify = true
   end
 
@@ -79,7 +79,7 @@ def compress_node(from, to)
   source_map_root = assets + ((d = File.dirname(from)) == "." ? "" : "/#{d}")
   source_map_url = cdn_path "/assets/#{to}.map"
 
-  cmd = "uglifyjs '#{assets_path}/#{from}' -p relative -m -c -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '#{source_map_url}'"
+  cmd = "uglifyjs '#{assets_path}/#{from}' -p relative -c -m -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '#{source_map_url}'"
 
   STDERR.puts cmd
   result = `#{cmd} 2>&1`
@@ -128,16 +128,6 @@ def brotli(path)
   raise "chmod failed: exit code #{$?.exitstatus}" if $?.exitstatus != 0
 end
 
-def should_compress?(path, locales)
-  return false if Rails.configuration.assets.skip_minification.include? path
-  return true unless path.include? "locales/"
-
-  path_locale = path.delete_prefix("locales/").delete_suffix(".js")
-  return true if locales.include? path_locale
-
-  false
-end
-
 def compress(from, to)
   if $node_uglify
     compress_node(from, to)
@@ -173,15 +163,10 @@ task 'assets:precompile' => 'assets:precompile:before' do
 
   if $bypass_sprockets_uglify
     puts "Compressing Javascript and Generating Source Maps"
-    startAll = Process.clock_gettime(Process::CLOCK_MONOTONIC)
     manifest = Sprockets::Manifest.new(assets_path)
-    locales = Set.new(["en"])
-
-    RailsMultisite::ConnectionManagement.each_connection do |db|
-      locales.add(SiteSetting.default_locale)
-    end
 
     concurrent? do |proc|
+      to_skip = Rails.configuration.assets.skip_minification || []
       manifest.files
         .select { |k, v| k =~ /\.js$/ }
         .each do |file, info|
@@ -197,7 +182,8 @@ task 'assets:precompile' => 'assets:precompile:before' do
               start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
               STDERR.puts "#{start} Compressing: #{file}"
 
-              if should_compress?(info["logical_path"], locales)
+              # We can specify some files to never minify
+              unless (ENV["DONT_MINIFY"] == "1") || to_skip.include?(info['logical_path'])
                 FileUtils.mv(path, _path)
                 compress(_file, file)
               end
@@ -205,7 +191,7 @@ task 'assets:precompile' => 'assets:precompile:before' do
               info["size"] = File.size(path)
               info["mtime"] = File.mtime(path).iso8601
               gzip(path)
-              brotli(path) if should_compress?(info["logical_path"], locales)
+              brotli(path)
 
               STDERR.puts "Done compressing #{file} : #{(Process.clock_gettime(Process::CLOCK_MONOTONIC) - start).round(2)} secs"
               STDERR.puts
@@ -214,9 +200,6 @@ task 'assets:precompile' => 'assets:precompile:before' do
       end
     end
 
-    STDERR.puts "Done compressing all JS files : #{(Process.clock_gettime(Process::CLOCK_MONOTONIC) - startAll).round(2)} secs"
-    STDERR.puts
-
     # protected
     manifest.send :save

GitHub sha: 6ea811c9

Revert "Revert "PERF: Skip compressing locales for faster rebuilds (#7501)" (#7502)"