Fix Bundler Inline XDG configuration detection
bkuhlmann opened this issue ยท 3 comments
Description
Hello. ๐ I'm hitting an issue with XDG configuration detection where if $XDG_CONFIG_HOME
is set and I'm using $HOME/.config/irb/irbrc
, my XDG configuration won't be used.
Result of irb_info
Ruby version: 3.2.2
IRB version: irb 1.9.1 (2023-11-21)
InputMethod: RelineInputMethod with Reline 0.4.0 and /Users/bkuhlmann/.inputrc
Completion: Autocomplete, RegexpCompletor
.irbrc path: /Users/bkuhlmann/.config/irb/irbrc
RUBY_PLATFORM: arm64-darwin22.4.0
LANG env: en_US.UTF-8
East Asian Ambiguous Width: 1
Terminal Emulator
iTerm
Setting Files
Are you using ~/.irbrc
and ~/.inputrc
? Yes, both. You can find the source for them here:
Steps to Recreate
Here's my Bundler Inline script that I'm using to recreate the issue:
#! /usr/bin/env ruby
# frozen_string_literal: true
# Save as `demo`, then `chmod 755 demo`, and run as `./demo`.
require "bundler/inline"
gemfile true do
source "https://rubygems.org"
gem "amazing_print"
# gem "debug"
end
binding.irb
When running the above script, two things will happen as my IRB info will show I'm using IRB 1.6.2:
Ruby version: 3.2.2
IRB version: irb 1.6.2 (2022-12-13)
InputMethod: RelineInputMethod with Reline 0.3.2 and /Users/bkuhlmann/.inputrc
.irbrc path: /Users/bkuhlmann/.config/irb/irbrc
RUBY_PLATFORM: arm64-darwin22.4.0
LANG env: en_US.UTF-8
East Asian Ambiguous Width: 1
...and when I attempt to use code completion my custom Reline::Face
configuration isn't recognized:
bad.mp4
However, if I uncomment the Debug gem -- in the script shown above -- then I get expected behavior:
good.mp4
With the Debug gem required in my Bundler Inline script, the correct version of IRB is loaded and my IRB XDG configuration is detected and fully loaded.
The workaround is to ensure the Debug gem is always requried for inline scripts.
This is the behavior of bundler.
If your Gemfile (or bundler inline script) does not include irb or reline or other default gem, bundle exec
will use pre-installed version bundled with ruby. (irb-1.6.2 and reline-0.3.2 is bundled in ruby 3.2.0)
$ echo > Gemfile; bundle exec irb -v
irb 1.6.2 (2022-12-13)
$ echo "gem 'irb'"> Gemfile; bundle exec irb -v
irb 1.9.1 (2023-11-21)
This is not only for IRB and Reline but also for other default gems.
$ echo > Gemfile; bundle exec ruby -rrdoc -e "puts RDoc::VERSION"
6.5.0
$ echo 'gem "rdoc"' > Gemfile; bundle exec ruby -rrdoc -e "puts RDoc::VERSION"
6.6.0 # if you installed 6.6.0
If you add 'irb' or 'reline' or another library like debug that depends on it to Gemfile, the latest version will be used.
Thanks. Should this be true even when IRB 1.9.1 is my current default gem and 1.6.2 is not installed. Example:
gem list irb
# *** LOCAL GEMS ***
# irb (default: 1.9.1)
bundle exec irb -v
# irb 1.9.1 (2023-11-21)
I didn't know about default version can be changed.
I think the default 1.9.1, (not 1.6.2) will be used in that case.
Even though irb-1.6.2 is used for some reason, wrong gem version used is not IRB's problem, I think. There is nothing IRB can do to re-require latest irb.