-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component method in main Gemfile generates error when running 'bundle install' #3
Comments
Interesting; why Which Bundler version do you use? |
Gemfile.lock:
|
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 |
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 Thanks in advance |
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 |
@maiksimov Have you added the |
@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 I've updated the guides and docs to fix this: 27a77c5 tl;dr We need 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.
The text was updated successfully, but these errors were encountered: