From 7afa95114edcc3af163a24fad74071e43ee33b57 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 17 Jul 2024 10:35:31 +0200 Subject: [PATCH] Fix bootsnap setup in environments without bundler Fix: https://github.com/Shopify/bootsnap/issues/488 `ExplicitRequire.with_gems` assumed the provided gems were activated which is only true if `bundler/setup` was required. If bootsnap is used without bundler, then we need to explictly activate the gem before mutating the `$LOAD_PATH`, otherwise the paths appended during gems activation will be lost once we exit `with_gems`. --- CHANGELOG.md | 1 + lib/bootsnap/explicit_require.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca58cdaa..96d5a6b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +* Allow using bootsnap without bundler. See #488. * Fix startup failure if the cache directory points to a broken symlink. # 1.18.3 diff --git a/lib/bootsnap/explicit_require.rb b/lib/bootsnap/explicit_require.rb index 29ce5a43..4a46bee9 100644 --- a/lib/bootsnap/explicit_require.rb +++ b/lib/bootsnap/explicit_require.rb @@ -25,6 +25,11 @@ def self.from_archdir(feature) # This is useful before bootsnap is fully-initialized to load gems that it # depends on, without forcing full LOAD_PATH traversals. def self.with_gems(*gems) + # Ensure the gems are activated (their paths are in $LOAD_PATH) + gems.each do |gem_name| + gem gem_name + end + orig = $LOAD_PATH.dup $LOAD_PATH.clear gems.each do |gem|