Skip to content

Commit

Permalink
Merge pull request #466 from Shopify/precompile-app
Browse files Browse the repository at this point in the history
Make `precompile --gemfile` consider the entire gem not just `lib/`
  • Loading branch information
casperisfine authored Jan 29, 2024
2 parents 06497da + d99b076 commit e0a11fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* `bootsnap precompile --gemfile` now look for `.rb` files in the whole gem and not just the `lib/` directory. See #466.

# 1.17.1

* Fix a compatibility issue with the `prism` library that ships with Ruby 3.3. See #463.
Expand Down
12 changes: 7 additions & 5 deletions lib/bootsnap/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def precompile_command(*sources)
precompile_json_files(main_sources)

if compile_gemfile
# Some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling.
gem_exclude = Regexp.union([exclude, "/spec/", "/test/"].compact)
precompile_ruby_files($LOAD_PATH.map { |d| File.expand_path(d) }, exclude: gem_exclude)

# Gems that include JSON or YAML files usually don't put them in `lib/`.
# So we look at the gem root.
# Similarly, gems that include Rails engines generally file Ruby files in `app/`.
# However some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling.
gem_exclude = Regexp.union([exclude, "/spec/", "/test/"].compact)

gem_pattern = %r{^#{Regexp.escape(Bundler.bundle_path.to_s)}/?(?:bundler/)?gems/[^/]+}
gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] }.compact.uniq
gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] || p }.uniq

precompile_ruby_files(gem_paths, exclude: gem_exclude)
precompile_yaml_files(gem_paths, exclude: gem_exclude)
precompile_json_files(gem_paths, exclude: gem_exclude)
end
Expand Down

0 comments on commit e0a11fe

Please sign in to comment.