Skip to content

Commit 759c46d

Browse files
krororoy-yagi
authored andcommitted
Remove unused files from package
The `.gemspec` file to optimize the gem package size and structure. The changes include: - Modified `files` to exclude test files, Gemfile, and CI related files from the package. - Removed the deprecated `test_files` specification as it is no longer recommended. These changes reduce the extracted package size from from 1.1MB to 340KB. Benefits: - Shorter download times for users - Reduced container sizes when the gem is included References: - rubygems/guides#90 - rubygems/bundler#3207 - [Template for the *.gemspec file generated by bundle gem command](https://github.com/rubygems/rubygems/blob/bundler-v2.6.5/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt)
1 parent ef42e02 commit 759c46d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

draper.gemspec

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ Gem::Specification.new do |s|
1010
s.description = "Draper adds an object-oriented layer of presentation logic to your Rails apps."
1111
s.license = "MIT"
1212

13-
s.files = `git ls-files`.split("\n")
14-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13+
# Specify which files should be added to the gem when it is released.
14+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
15+
gemspec = File.basename(__FILE__)
16+
s.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
17+
ls.readlines("\x0", chomp: true).reject do |f|
18+
(f == gemspec) ||
19+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
20+
end
21+
end
1522
s.require_paths = ["lib"]
1623

1724
s.required_ruby_version = '>= 2.2.2'

0 commit comments

Comments
 (0)