FIX: Sort filelists to ensure consistant asset precompilation hash (#13393)

FIX: Sort filelists to ensure consistant asset precompilation hash (#13393)

Dir.glob does not guarantee file order and can change when ran on different machines. This means that running asset precompilation on the exact same codebase will output different content hashes.

diff --git a/lib/i18n/backend/discourse_i18n.rb b/lib/i18n/backend/discourse_i18n.rb
index 2fd498f..9962206 100644
--- a/lib/i18n/backend/discourse_i18n.rb
+++ b/lib/i18n/backend/discourse_i18n.rb
@@ -38,7 +38,7 @@ module I18n
       end
 
       def self.sort_locale_files(files)
-        files.sort_by do |filename|
+        files.sort.sort_by do |filename|
           matches = /(?:client|server)-([1-9]|[1-9][0-9]|100)\..+\.yml/.match(filename)
           matches&.[](1)&.to_i || 0
         end
diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb
index a793398..2a92c6d 100644
--- a/lib/plugin/instance.rb
+++ b/lib/plugin/instance.rb
@@ -755,7 +755,7 @@ class Plugin::Instance
       root_path = "#{File.dirname(@path)}/assets/javascripts"
       admin_path = "#{File.dirname(@path)}/admin/assets/javascripts"
 
-      Dir.glob(["#{root_path}/**/*", "#{admin_path}/**/*"]) do |f|
+      Dir.glob(["#{root_path}/**/*", "#{admin_path}/**/*"]).sort.each do |f|
         f_str = f.to_s
         if File.directory?(f)
           yield [f, true]

GitHub sha: 20dbcbf022068069172dd3af807c2d5edcb0e773

This commit appears in #13393 which was approved by eviltrout. It was merged by eviltrout.

Why do we need to sort twice?

It’s true, we don’t. I doubt we’ll ever notice though!