Skip to content

Commit

Permalink
fix: Sessions generator adds bcrypt more robustly
Browse files Browse the repository at this point in the history
Use Thor's `uncomment_lines` instead of `gsub_file`.

If the Gemfile does not contain bcrypt, either commented or
uncommented, then run `bundle add bcrypt`.

Make sure all bundler commands run within `Bundler.with_original_env`
to avoid bundler resolution problems while trying to resolve bundler
dependencies. Typically the failure mode here is seeing:

> Could not find bcrypt-3.1.20 in cached gems or installed locally (Bundler::GemNotFound)

while bootstrapping the process that will run bundle-install or bundle-add.
  • Loading branch information
flavorjones committed Jul 16, 2024
1 parent 0ba0108 commit 3fdc66a
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ def configure_application
end

def enable_bcrypt
# FIXME: Make more resilient in case the default comment has been removed
gsub_file "Gemfile", /# gem "bcrypt"/, 'gem "bcrypt"'
execute_command :bundle, ""
if File.read("Gemfile").include?('gem "bcrypt"')
uncomment_lines "Gemfile", /gem "bcrypt"/
Bundler.with_original_env { execute_command :bundle, "" }
else
Bundler.with_original_env { execute_command :bundle, "add bcrypt" }
end
end

def add_migrations
Expand Down

0 comments on commit 3fdc66a

Please sign in to comment.