@@ -222,7 +222,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi
222222 bundlerVersion = '1'
223223 }
224224
225- if ( ( engine === 'ruby' || engine === 'truffleruby' ) && common . isHeadVersion ( rubyVersion ) && bundlerVersion === '2' ) {
225+ if ( common . isHeadVersion ( rubyVersion ) && common . isBundler2Default ( engine , rubyVersion ) && bundlerVersion === '2' ) {
226226 console . log ( `Using Bundler 2 shipped with ${ engine } -${ rubyVersion } ` )
227227 } else if ( engine === 'truffleruby' && ! common . isHeadVersion ( rubyVersion ) && bundlerVersion === '1' ) {
228228 console . log ( `Using Bundler 1 shipped with ${ engine } ` )
@@ -240,20 +240,25 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b
240240 return false
241241 }
242242
243- // Before the lockfile exists, we need to specify which Bundler version to use explicitly
244- const optionsWithBundlerVersion = { env : { ...process . env , BUNDLER_VERSION : bundlerVersion } }
243+ let envOptions = { }
244+ if ( bundlerVersion . startsWith ( '1' ) && common . isBundler2Default ( engine , rubyVersion ) ) {
245+ // If Bundler 1 is specified on Rubies which ship with Bundler 2,
246+ // we need to specify which Bundler version to use explicitly until the lockfile exists.
247+ console . log ( `Setting BUNDLER_VERSION=${ bundlerVersion } for "bundle config|lock" commands below to ensure Bundler 1 is used` )
248+ envOptions = { env : { ...process . env , BUNDLER_VERSION : bundlerVersion } }
249+ }
245250
246251 // config
247252 const path = 'vendor/bundle'
248253
249- await exec . exec ( 'bundle' , [ 'config' , '--local' , 'path' , path ] , optionsWithBundlerVersion )
254+ await exec . exec ( 'bundle' , [ 'config' , '--local' , 'path' , path ] , envOptions )
250255
251256 if ( fs . existsSync ( lockFile ) ) {
252- await exec . exec ( 'bundle' , [ 'config' , '--local' , 'deployment' , 'true' ] , optionsWithBundlerVersion )
257+ await exec . exec ( 'bundle' , [ 'config' , '--local' , 'deployment' , 'true' ] , envOptions )
253258 } else {
254259 // Generate the lockfile so we can use it to compute the cache key.
255260 // This will also automatically pick up the latest gem versions compatible with the Gemfile.
256- await exec . exec ( 'bundle' , [ 'lock' ] , optionsWithBundlerVersion )
261+ await exec . exec ( 'bundle' , [ 'lock' ] , envOptions )
257262 }
258263
259264 // cache key
0 commit comments