ElMassimo / vite_ruby

⚡️ Vite.js in Ruby, bringing joy to your JavaScript experience
https://vite-ruby.netlify.app/
MIT License
1.28k stars 117 forks source link

clean command not detecting versions properly #438

Closed philippevezina closed 3 weeks ago

philippevezina commented 6 months ago

Description 📖

vite_ruby uses the mtime as a reference to detect different versions of the app: https://github.com/ElMassimo/vite_ruby/blob/main/vite_ruby/lib/vite_ruby/commands.rb#L148 That being said, a single Vite build can generate files with more than one mtime. For example, vite-plugin-rails uses rollup-plugin-gzip at the end of the build which will write many files with different mtimes.

This causes files to delete unexpectedly when running bin/vite clean. It's possible this bug is hard to reproduce with a small project as all written files may end up having the same mtime.

Reproduction 🐞

Vite Ruby Info - Run `bin/rake vite:build` on a big project with no currently built assets. - Run `bin/rake vite:clean[1,0]` Result: files will be deleted while there is only a single version of the built assets.
ElMassimo commented 5 months ago

Hi Philippe, thanks for reporting!

Fixing this will likely require grouping files by modified time using a certain range (maybe 5 minutes is a reasonable default).

benlangfeld commented 2 months ago

This is a duplicate of #404, right?

benlangfeld commented 2 months ago

Fix proposed in #477 which mirrors the behaviour of vite_ruby before a recent tangentially related bugfix, as well as Webpacker.

philippevezina commented 2 months ago

Fix proposed in #477 which mirrors the behaviour of vite_ruby before a recent tangentially related bugfix, as well as Webpacker.

This PR won't fix the issue described here. The issue still remains that Vite Ruby relies on common mtimes on files to determine the set of files belonging to a certain version. That said, when trying to keep 2 versions of the assets, the returned files may all belong to only a single build rather than 2 because the mtime could be 1 second off for some files.

benlangfeld commented 2 months ago

Fix proposed in #477 which mirrors the behaviour of vite_ruby before a recent tangentially related bugfix, as well as Webpacker.

This PR won't fix the issue described here. The issue still remains that Vite Ruby relies on common mtimes on files to determine the set of files belonging to a certain version. That said, when trying to keep 2 versions of the assets, the returned files may all belong to only a single build rather than 2 because the mtime could be 1 second off for some files.

Ok, but it will fix guaranteeing you retain at least the most recent version.