From ce22a0f4104b620322ea1f4e9c6c83c8d69ea9a4 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:37:11 +0900 Subject: [PATCH] Reduce gem size This reduces the Auth0 gem size by changing `files` in the gemspec. Currently, the gem contains many unnecessary files for execution, such as tests or examples. Besides, since `test_files` in the gemspec is unsupported, we can remove it. See https://guides.rubygems.org/specification-reference/ To verify this change locally, run the command for each branch and compare each output: ```sh gem build ``` Here's a size diff in my local environment: ```sh-session $ du -h auth0-*.gem* 40K auth0-5.17.0.gem 216K auth0-5.17.0.gem.current ``` In addition, we can compare included files in the gem as well: ```shell bundle exec ruby -e 's = Gem.loaded_specs["auth0"]; puts s.files + s.executables' ``` For example: ```shell git switch master bundle exec ruby -e 's = Gem.loaded_specs["auth0"]; puts s.files + s.executables' > before git switch reduce-gem-size bundle exec ruby -e 's = Gem.loaded_specs["auth0"]; puts s.files + s.executables' > after diff -u before after ``` --- auth0.gemspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/auth0.gemspec b/auth0.gemspec index 2074d027..5f382b66 100644 --- a/auth0.gemspec +++ b/auth0.gemspec @@ -11,9 +11,8 @@ Gem::Specification.new do |s| s.summary = 'Auth0 API Client' s.description = 'Ruby toolkit for Auth0 API https://auth0.com.' - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } + s.files = `git ls-files -z -- LICENSE README.md lib`.split("\x0") + s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) } s.require_paths = ['lib'] s.add_runtime_dependency 'rest-client', '~> 2.1'