rails / sprockets

Rack-based asset packaging system
MIT License
932 stars 792 forks source link

sprockets does not respect the filename extension I specified in link_directory (manifest.js) in ambiguous cases #796

Open mildred opened 8 months ago

mildred commented 8 months ago

Actual behavior

Given that I configure in an initializer Sprockets.register_mime_type 'application/javascript, extensions: ['.mjs'] and that I have a directory where two files share the same basename but with different extensions (one .js and one .mjs)

Currently, it is as if when I put in the manifest a directive like //= link_directory path/to file.mjs, sprockets would strip the .mjs extension and register that I want to link the directory path/to and inside the file with the basename file and an extension that match application/javascript. But this is ambiguous and not what I specified.

Currently, in that circumstance, when I ask sprockets for the file path/to/file.mjs it will instead serve me the file public/assets/path/to/file-HASH.js, but the file content differs.

Expected behavior

When in app/assets/config/manifest.js I reference a file, its file extension should be preserved even when there are multiple files with different extensions but the same content-type

System configuration

Example App (Reproduction)

I wish I could but I tried to create a new app wuith rails new and sprockets fails out of the box with a "\xE2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to UTF-32LE (Encoding::UndefinedConversionError)

Reproducing the example should be easy from any app that is working:

edit: by the way it would be great if there was a working example app we could fork to demonstrate the issues.