amatsuda / database_rewinder

minimalist's tiny and ultra-fast database cleaner
MIT License
806 stars 92 forks source link

Include minimum files in packed gem #91

Closed ybiquitous closed 4 months ago

ybiquitous commented 4 months ago

This aims to reduce the gem size by excluding unneeded files like test files, CI files, etc. Note that test_files in a gemspec is no longer supported.

Gem size diff:

$ du -h database_rewinder-1.0.1.gem*
 12K    database_rewinder-1.0.1.gem
 16K    database_rewinder-1.0.1.gem.old

Newly included files in the gem:

$ tree -aF database_rewinder-1.0.1
database_rewinder-1.0.1/
├── MIT_LICENSE
├── README.md
└── lib/
    ├── database_rewinder/
    │   ├── active_record_monkey.rb
    │   ├── cleaner.rb
    │   ├── compatibility.rb
    │   ├── dummy_model.rb
    │   ├── multiple_statements_executor.rb
    │   └── railtie.rb
    └── database_rewinder.rb

3 directories, 9 files
amatsuda commented 4 months ago

@ybiquitous Good catch! Thank you for the patch!

However, I still prefer to use git ls-files which very effectively prevents local temporary files or any other unrelated files being mixed into the gem package by accident. So, could you rewrite the patch to use git ls-files?

While the bundle gem command today generates this ugly and complex code block, For example, here's the default code that bundle gem command today generates (which to me seems too ugly and complex). https://github.com/rubygems/rubygems/blob/dd0a6163530b58229eb36141aa2e8c426231dbbd/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt#L28-L36

I guess something equally simple with your code like this would just work in our case, and would produce a similar result with your code.

`git ls-files lib`.split << 'README.md' <<'MIT_LICENSE'
ybiquitous commented 4 months ago

@amatsuda Thanks for the review! Your thoughts on git ls-files make sense to me.

And, I also agree that bundle gem generates too ugly spec.files =. 😅

I just pushed 5206374 based on your suggestion. Can you take a look again? Thanks.

amatsuda commented 4 months ago

@ybiquitous Thank you!