greensync/json-sequence

json-sequence.gemspec uses 'git'

Closed this issue · 3 comments

I've not had much experience creating rubygems however the file json-sequence.gemspec calls out to git. As dex-visibility is now vendoring this gem (and the dex-api-client) I'd like to remove the dependency on having access to git at runtime.

The current json-sequence.gemspec lists the files using:

irb(main):001:0> files = `git ls-files -z`.split("\x0").reject do |f|
irb(main):002:1*     f.match(%r{^(test|spec|features)/})
irb(main):003:1>   end
=> [".gitignore", ".rspec", ".rubocop.yml", ".ruby-version", "Gemfile", "Gemfile.lock", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "json-sequence.gemspec", "lib/json_sequence.rb", "lib/json_sequence/parser.rb", "lib/json_sequence/result.rb", "lib/json_sequence/version.rb"]

Yehuda recommends that we use Dir.glob
https://github.com/greensync/json-sequence/blob/master/json-sequence.gemspec

So I propose that we update the gemspec to Dir.glob("{bin,lib}/**/*") + %w(README.md Gemfile Gemfile.lock Rakefile)

ruby -e 'puts Dir.glob("{bin,lib}/**/*") + %w(README.md Gemfile Gemfile.lock Rakefile LICENSE.txt json-sequence.gemspec)'
bin/setup
bin/console
lib/json_sequence
lib/json_sequence/result.rb
lib/json_sequence/parser.rb
lib/json_sequence/version.rb
lib/json_sequence.rb
README.md
Gemfile
Gemfile.lock
Rakefile
LICENSE.txt
json-sequence.gemspec
yob commented

I'm not sure how this gem was generated, but shelling out to git ls-files is a super common pattern in the wider ruby community. It could be because gems generated by bundler (ie. bundle gem foo) default to the git style.

I'm 100% for the pure ruby Dir.glob approach 👍

wezm commented

I used bundler to scaffold the gem. The benefit of git ls-files is that it means when publishing a gem you'll never accidentally upload untracked files, which a glob would do. However we aren't publishing the gem so this is a bit of a moot point. Additionally since we're vendoring we get the same benefit when the upstream repo is imported so Dir.glob seems fine.

PR #4 resolves this issue. I've also updated the gem to version 0.1.2 (tagged and released)

I'll close this now