[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Weird issue with bundler



El 25/4/20 a las 18:30, Daniel Leidert escribió:
Am Samstag, den 25.04.2020, 18:11 +0200 schrieb Daniel Leidert:

[..]
The created Gemfile contains this:

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
install_if -> { RUBY_PLATFORM =~ %r!mingw|mswin|java! } do
   gem "tzinfo", "~> 1.2"
   gem "tzinfo-data"
end

# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.0", :install_if => Gem.win_platform?
To summarize: I'm suprised I get a warning that a gem, which I don't even need
on the platform I'm on, cannot be found. Why is bundler even looking for it?

Yeah, I agree this could be avoided and understand your frustration.

So, I had a closer look, and it's apparently due to a bad usage of
`install_if`. `install_if` is a very niche part of Bundler's DSL. It's as a
matter of fact the first realworld usage I see of it, and it seems to be
actually wrong.

This method `:install_if` shouldn't be used for restricting dependencies for
certain platforms, that's what the `:platforms` DSL is for. We have some
examples in our documentation actually suggesting that so I can see how it's
getting used in the wild... :S We'll need to fix that. The original usecase for
`:install_if` is better illustrated here:
https://github.com/rubygems/bundler-features/issues/77.

Anyways, by using `:install_if`, Bundler still considers all dependencies as
relevant for your current platform, and only at installation time it restricts
installation by applying the `:install_if` condition.

A more correct default `Gemfile` for `jekyll` would include:

```
# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
# and associated library.
platforms :mingw, :mswin, :jruby do
  gem "tzinfo", "~> 1.2"
  gem "tzinfo-data"
end

# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.1", :platforms => [:mingw, :mswin]
```

I believe that with that default jekyll `Gemfile`, `bundler` will not get in the middle for `Debian` users, so I'll propose to change it in jekyll's upstream.
And also fix our `:install_if` docs :sweat_smile:.


Reply to: