Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include minimum files in packed gem #91

Merged

Conversation

ybiquitous
Copy link
Contributor

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

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:

```sh-session
$ 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:

```sh-session
$ 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
Copy link
Owner

@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
Copy link
Contributor Author

@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 amatsuda merged commit 551e547 into amatsuda:master Jul 10, 2024
67 of 78 checks passed
@amatsuda
Copy link
Owner

@ybiquitous Thank you!

@ybiquitous ybiquitous deleted the include-minimum-files-in-packed-gem branch July 10, 2024 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants