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

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

This issue is difficult to reproduce because it depends on how the source files are stored in the filesystem. There are no tests included with this PR for this reason.

In the future, Ruby 3 provides :sort options that are enabled by default and would fix this issue. Class: Dir (Ruby 3.0.1)


When our company built discourse on different machines, we noticed the asset files would be different. This was causing issues for us. Inspecting the compiled asset files didn’t appear to show any differences, other than a few file lists (plugins, etc.) being in a different order. After diving into the code, we realized that this appeared to be caused by file globbing. We know that Sprockets will sort files [1][2] so this could only be caused by custom file lists within the Discourse application.

We have been using this code change as a patch and have not seen this issue since we started using it 3 months ago.



Thanks, this seems like a good approach and I am a fan of determinism.