Open maiksimov opened 3 years ago
You specified that admin_panel (>= 0) should come from source at
engines/admin_panel
and source at.
Interesting; why .
?
Which Bundler version do you use?
Gemfile.lock:
BUNDLED WITH
1.17.3
That's probably the reason.
I couldn't find a relevant issue nor personal notes, but I had a feeling that we specifically upgraded to Bundler 2 to make eval_gemfile
work as we expected.
I updated the version of the bundler to 2. But nothing changed, the errors remained the same
Unfortunately, I don't have an access to any engined codebase right now; would you be able to provide a minimal reproduction, so I can debug it?
Hi. I'm having this same problem. But I actually did not understand where to place class Bundler::Dsl
component
function to be accessible inside the root Gemfile. I've tried placing inside /lib/scripts/component.rb, /lib/scripts/bunder/component.rb... but only because @maiksimov pointed out.
Thanks in advance
where to place class Bundler::Dsl component function to be accessible inside the root Gemfile
You can put the patch anywhere you want, just don't forget to require it at the top of the Gemfile.
We put the patch right in the Gemfile:
# frozen_string_literal: true
unless Bundler::Dsl.instance_methods.include?(:eval_gemfile_original)
class Bundler::Dsl
alias eval_gemfile_original eval_gemfile
def eval_gemfile(gemfile, contents = nil)
expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
return if @gemfiles.any? { |path| path == expanded_gemfile_path }
eval_gemfile_original(gemfile, contents)
end
alias eval_gemfile_without_duplication eval_gemfile
def component(name, namespace: "engines")
Dir.chdir(__dir__) do
group name.to_sym do
group :default do
# Add engine as a dependency
gem name, path: "#{namespace}/#{name}"
# Add runtime non-RubyGems specs
if File.readable?("#{namespace}/#{name}/Gemfile.runtime")
eval_gemfile_without_duplication "#{namespace}/#{name}/Gemfile.runtime"
end
end
# Add development deps to development and test groups
expanded_spec_path = Pathname.new("#{namespace}/#{name}/#{name}.gemspec").expand_path(@gemfile&.parent)
spec = Gem::Specification.load(expanded_spec_path.to_s)
spec.dependencies.select { |s| s.type == :development }.each do |dep|
next if @dependencies.find { |current_dep| current_dep.name == dep.name }
gem dep.name, dep.requirement, group: [:development, :test]
end
end
end
end
end
end
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby File.read(File.join(__dir__, ".ruby-version")).strip
rails_version = File.read(File.join(__dir__, ".rails-version"))
gem "rails", rails_version
# == Core ==
gem "pg"
gem "puma"
gem "redis"
gem "webpacker"
# ...
group :development, :test do
# ...
end
group :development do
# ...
end
group :test do
# ...
end
# == Engines ==
# NOTE: components must be loaded after everything to ensure we do not
# load already defined deps twice (we do check for that in the #component method).
#
# Loading the same dependency twice makes Bundler crazy in some cases.
# Core engine
component "core"
# Authentication engine
component "auth"
# Admin dashboard engine
component "admin"
@maiksimov btw, check the commend above; do you have component
calls in the end of the Gemfile? Looks like there were some "crazy" issues I don't remember 🙂
@palkan Hello! I created a public rails test project, added your scripts and created a test gem inside as it was written in the manual. I have errors like above (when run bundle install). Can you check it out? Maybe I did something wrong.
Thanks for the demo project!
I found the problem: evaling Gemfile
within gemspec
inside doesn't really work (we actually didn't have this line in our setup, don't know where it came from).
I've updated the guides and docs to fix this: https://github.com/palkan/engems/commit/27a77c53166c48c745000eaae45213b1a6d3a2cd
tl;dr We need Gemfile.dev
as well 🙂
Here is the fix for the demo project: https://github.com/palkan/test-rails-project/commit/a3079f4b9b3932946a742544122aafd23c2bad4b
@palkan Thanks!
I am trying to attempt your code into my project. I added component and eval_gemfile_patch scripts the lib folder of my main application. I have an admin_panel engine that is included in the main Gemfile as written in the guide:
Engine Gemfile looks like:
Engine admin_panel.gemspec looks like:
When I run bundle install I had an error:
If I remove the gemspec call from the engine Gemfile, everything works fine, but it looks strange because I want to reuse this engine in other applications. The same will happen if I use your generators and create some kind of test engine or gem. It generates engine with Gemfile with gemspec call inside. And "bundle install" will throw an error again.