Skip to content

Commit d697be2

Browse files
committed
Account for Bundler 4
* Fixes #827
1 parent 8aeb6ff commit d697be2

File tree

3 files changed

+101
-46
lines changed

3 files changed

+101
-46
lines changed

bundler.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
6767
}
6868
}
6969

70-
const floatVersion = common.floatVersion(rubyVersion)
71-
7270
if (bundlerVersion === 'default') {
73-
if (common.isBundler2dot2Default(engine, rubyVersion)) {
71+
if (common.isBundler2dot2PlusDefault(engine, rubyVersion)) {
7472
if (common.windows && engine === 'ruby' && (common.isStableVersion(engine, rubyVersion) || rubyVersion === 'head')) {
7573
// https://github.com/ruby/setup-ruby/issues/371
7674
console.log(`Installing latest Bundler for ${engine}-${rubyVersion} on Windows because bin/bundle does not work in bash otherwise`)
7775
bundlerVersion = 'latest'
7876
} else {
79-
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
80-
return '2'
77+
console.log(`Using Bundler shipped with ${engine}-${rubyVersion}`)
78+
return common.isBundler4PlusDefault(engine, rubyVersion) ? '4' : '2'
8179
}
8280
} else if (common.hasBundlerDefaultGem(engine, rubyVersion)) {
8381
// Those Rubies have a old Bundler default gem < 2.2 which does not work well for `gem 'foo', github: 'foo/foo'`:
@@ -90,8 +88,15 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
9088
}
9189
}
9290

91+
const targetRubyVersion = common.targetRubyVersion(engine, rubyVersion)
92+
9393
if (bundlerVersion === 'latest') {
94-
bundlerVersion = '2'
94+
// Bundler 4 requires Ruby 3.2+
95+
if (targetRubyVersion < 3.2) {
96+
bundlerVersion = '2'
97+
} else {
98+
bundlerVersion = '4'
99+
}
95100
}
96101

97102
if (isValidBundlerVersion(bundlerVersion)) {
@@ -100,24 +105,29 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
100105
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
101106
}
102107

103-
// Use Bundler 1 when we know Bundler 2 does not work
104-
if (bundlerVersion.startsWith('2')) {
105-
if (engine === 'ruby' && floatVersion <= 2.2) {
106-
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2')
108+
// Only use Bundler 4 on Ruby 3.2+
109+
if (common.floatVersion(bundlerVersion) >= 4 && targetRubyVersion < 3.2) {
110+
console.log('Bundler 4 requires Ruby 3.2+, using Bundler 2 instead on Ruby < 3.2')
111+
bundlerVersion = '2'
112+
}
113+
114+
// Use Bundler 1 when we know Bundler 2+ does not work
115+
if (common.floatVersion(bundlerVersion) >= 2) {
116+
if (engine === 'ruby' && targetRubyVersion <= 2.2) {
117+
console.log(`Bundler 2+ requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2`)
107118
bundlerVersion = '1'
108119
} else if (engine === 'ruby' && /^2\.3\.[01]/.test(rubyVersion)) {
109120
console.log('Ruby 2.3.0 and 2.3.1 have shipped with an old rubygems that only works with Bundler 1')
110121
bundlerVersion = '1'
111122
} else if (engine === 'jruby' && rubyVersion.startsWith('9.1')) { // JRuby 9.1 targets Ruby 2.3, treat it the same
112-
console.log('JRuby 9.1 has a bug with Bundler 2 (https://github.com/ruby/setup-ruby/issues/108), using Bundler 1 instead on JRuby 9.1')
123+
console.log('JRuby 9.1 has a bug with Bundler 2+ (https://github.com/ruby/setup-ruby/issues/108), using Bundler 1 instead on JRuby 9.1')
113124
bundlerVersion = '1'
114125
}
115126
}
116127

117-
const targetRubyVersion = common.targetRubyVersion(engine, rubyVersion)
118128
// Use Bundler 2.3 when we use Ruby 2.3.2 - 2.5
119129
// Use Bundler 2.4 when we use Ruby 2.6-2.7
120-
if (bundlerVersion == '2') {
130+
if (bundlerVersion === '2') {
121131
if (targetRubyVersion <= 2.5) { // < 2.3.2 already handled above
122132
console.log('Ruby 2.3.2 - 2.5 only works with Bundler 2.3')
123133
bundlerVersion = '2.3'
@@ -137,15 +147,23 @@ export async function installBundler(bundlerVersionInput, rubygemsInputSet, lock
137147
return bundlerVersion
138148
}
139149

150+
function bundlerConfigSetArgs(bundlerVersion, key, value) {
151+
if (bundlerVersion.startsWith('1')) {
152+
return ['config', '--local', key, value]
153+
} else {
154+
return ['config', 'set', '--local', key, value]
155+
}
156+
}
157+
140158
export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion, cacheVersion) {
141159
if (gemfile === null) {
142160
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
143161
return false
144162
}
145163

146164
let envOptions = {}
147-
if (bundlerVersion.startsWith('1') && common.isBundler2Default(engine, rubyVersion)) {
148-
// If Bundler 1 is specified on Rubies which ship with Bundler 2,
165+
if (bundlerVersion.startsWith('1') && common.isBundler2PlusDefault(engine, rubyVersion)) {
166+
// If Bundler 1 is specified on Rubies which ship with Bundler 2+,
149167
// we need to specify which Bundler version to use explicitly until the lockfile exists.
150168
console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler 1 is used`)
151169
envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
@@ -156,10 +174,10 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
156174
// An absolute path, so it is reliably under $PWD/vendor/bundle, and not relative to the gemfile's directory
157175
const bundleCachePath = path.join(process.cwd(), cachePath)
158176

159-
await exec.exec('bundle', ['config', '--local', 'path', bundleCachePath], envOptions)
177+
await exec.exec('bundle', bundlerConfigSetArgs(bundlerVersion, 'path', bundleCachePath), envOptions)
160178

161179
if (fs.existsSync(lockFile)) {
162-
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], envOptions)
180+
await exec.exec('bundle', bundlerConfigSetArgs(bundlerVersion, 'deployment', 'true'), envOptions)
163181
} else {
164182
// Generate the lockfile so we can use it to compute the cache key.
165183
// This will also automatically pick up the latest gem versions compatible with the Gemfile.

common.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function isStableVersion(engine, rubyVersion) {
8080
}
8181

8282
export function hasBundlerDefaultGem(engine, rubyVersion) {
83-
return isBundler1Default(engine, rubyVersion) || isBundler2Default(engine, rubyVersion)
83+
return isBundler1Default(engine, rubyVersion) || isBundler2PlusDefault(engine, rubyVersion)
8484
}
8585

8686
export function isBundler1Default(engine, rubyVersion) {
@@ -95,7 +95,7 @@ export function isBundler1Default(engine, rubyVersion) {
9595
}
9696
}
9797

98-
export function isBundler2Default(engine, rubyVersion) {
98+
export function isBundler2PlusDefault(engine, rubyVersion) {
9999
if (engine === 'ruby') {
100100
return floatVersion(rubyVersion) >= 2.7
101101
} else if (engine.startsWith('truffleruby')) {
@@ -107,7 +107,7 @@ export function isBundler2Default(engine, rubyVersion) {
107107
}
108108
}
109109

110-
export function isBundler2dot2Default(engine, rubyVersion) {
110+
export function isBundler2dot2PlusDefault(engine, rubyVersion) {
111111
if (engine === 'ruby') {
112112
return floatVersion(rubyVersion) >= 3.0
113113
} else if (engine.startsWith('truffleruby')) {
@@ -119,6 +119,13 @@ export function isBundler2dot2Default(engine, rubyVersion) {
119119
}
120120
}
121121

122+
const UNKNOWN_TARGET_RUBY_VERSION = 9.9
123+
124+
export function isBundler4PlusDefault(engine, rubyVersion) {
125+
const version = targetRubyVersion(engine, rubyVersion)
126+
return version != UNKNOWN_TARGET_RUBY_VERSION && version >= 4.0
127+
}
128+
122129
export function targetRubyVersion(engine, rubyVersion) {
123130
const version = floatVersion(rubyVersion)
124131
if (engine === 'ruby') {
@@ -132,6 +139,8 @@ export function targetRubyVersion(engine, rubyVersion) {
132139
return 2.6
133140
} else if (version === 9.4) {
134141
return 3.1
142+
} else if (version === 10.0) {
143+
return 3.4
135144
}
136145
} else if (engine.startsWith('truffleruby')) {
137146
if (version < 21.0) {
@@ -147,11 +156,11 @@ export function targetRubyVersion(engine, rubyVersion) {
147156
}
148157
}
149158

150-
return 9.9 // unknown, assume recent
159+
return UNKNOWN_TARGET_RUBY_VERSION // unknown, assume recent
151160
}
152161

153162
export function floatVersion(rubyVersion) {
154-
const match = rubyVersion.match(/^\d+\.\d+/)
163+
const match = rubyVersion.match(/^\d+(\.\d+|$)/)
155164
if (match) {
156165
return parseFloat(match[0])
157166
} else if (isHeadVersion(rubyVersion)) {

dist/index.js

Lines changed: 52 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)