Skip to content

Commit d99b076

Browse files
committed
Make precompile --gemfile consider the entire gem not just lib/
Fix: #465 Should catch things such as Rails engines and other Ruby source files not directly in the load path.
1 parent 06497da commit d99b076

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

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

57
* Fix a compatibility issue with the `prism` library that ships with Ruby 3.3. See #463.

lib/bootsnap/cli.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ def precompile_command(*sources)
6060
precompile_json_files(main_sources)
6161

6262
if compile_gemfile
63-
# Some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling.
64-
gem_exclude = Regexp.union([exclude, "/spec/", "/test/"].compact)
65-
precompile_ruby_files($LOAD_PATH.map { |d| File.expand_path(d) }, exclude: gem_exclude)
66-
6763
# Gems that include JSON or YAML files usually don't put them in `lib/`.
6864
# So we look at the gem root.
65+
# Similarly, gems that include Rails engines generally file Ruby files in `app/`.
66+
# However some gems embed their tests, they're very unlikely to be loaded, so not worth precompiling.
67+
gem_exclude = Regexp.union([exclude, "/spec/", "/test/"].compact)
68+
6969
gem_pattern = %r{^#{Regexp.escape(Bundler.bundle_path.to_s)}/?(?:bundler/)?gems/[^/]+}
70-
gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] }.compact.uniq
70+
gem_paths = $LOAD_PATH.map { |p| p[gem_pattern] || p }.uniq
71+
72+
precompile_ruby_files(gem_paths, exclude: gem_exclude)
7173
precompile_yaml_files(gem_paths, exclude: gem_exclude)
7274
precompile_json_files(gem_paths, exclude: gem_exclude)
7375
end

0 commit comments

Comments
 (0)