Skip to content

fix admin component generator namespace #6237

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ccarruitero
Copy link
Contributor

This PR is sponsored by 🌋 MagmaLabs

Summary

Admin component generator is failing on a clean solidus installation.

$ ./bin/rails g solidus_admin:component event
[WARNING Spree] Missing migrations.
[WARNING Spree] - add_reverse_charge_status_to_store
[WARNING Spree] - add_vat_id_email_and_reverse_charge_status_to_addresses
[WARNING Spree]
[WARNING Spree] Run `bin/rails railties:install:migrations` to get them.
[WARNING Spree] You can silence this warning by setting the `SOLIDUS_SKIP_MIGRATIONS_CHECK` environment variable.
      create  app/components/event/component.html.erb
/home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/railties-8.0.2/lib/rails/generators/base.rb:321:in `namespace_dirs': undefined method `name' for nil (NoMethodError)

          @namespace_dirs ||= namespace.name.split("::").map(&:underscore)
                                       ^^^^^
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/railties-8.0.2/lib/rails/generators/base.rb:325:in `namespaced_path'
	from /home/yoh/tmp/solidus/admin/lib/generators/solidus_admin/component/templates/component.rb.tt:3:in `template'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/erb-5.0.1/lib/erb.rb:427:in `eval'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/erb-5.0.1/lib/erb.rb:427:in `result'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/file_manipulation.rb:128:in `block in template'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/create_file.rb:54:in `render'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/create_file.rb:64:in `block (2 levels) in invoke!'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/create_file.rb:64:in `open'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/create_file.rb:64:in `block in invoke!'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/empty_directory.rb:117:in `invoke_with_conflict_check'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/create_file.rb:61:in `invoke!'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions.rb:93:in `action'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/create_file.rb:25:in `create_file'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/actions/file_manipulation.rb:124:in `template'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/railties-8.0.2/lib/rails/generators/named_base.rb:25:in `block in template'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/railties-8.0.2/lib/rails/generators/named_base.rb:45:in `inside_template'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/railties-8.0.2/lib/rails/generators/named_base.rb:24:in `template'
	from /home/yoh/tmp/solidus/admin/lib/generators/solidus_admin/component/component_generator.rb:29:in `create_component_files'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/invocation.rb:134:in `block in invoke_all'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/invocation.rb:134:in `each'
	from /home/yoh/.rvm/gems/ruby-3.3.7@commerze/gems/thor-1.3.2/lib/thor/invocation.rb:134:in `map'

Error comes from https://github.com/rails/rails/blob/3235827585d87661942c91bc81f64f56d710f0b2/railties/lib/rails/generators/base.rb#L321 due to namespace is returning nil.

This method was called from component.rb template
https://github.com/solidusio/solidus/blob/main/admin/lib/generators/solidus_admin/component/templates/component.rb.tt#L3
https://github.com/rails/rails/blob/3235827585d87661942c91bc81f64f56d710f0b2/railties/lib/rails/generators/base.rb#L324

So we need to define namespace into gem or host app to fix it. For now, I think would be easier to fix by adding into initializer template.

Let me know what you think?

Looking into specs found that are passing because we already seated namespace for generators specs
https://github.com/solidusio/solidus/blob/main/admin/spec/spec_helper.rb#L115

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.82%. Comparing base (cfb5acb) to head (dc0495d).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6237   +/-   ##
=======================================
  Coverage   88.82%   88.82%           
=======================================
  Files         851      851           
  Lines       18349    18349           
=======================================
  Hits        16299    16299           
  Misses       2050     2050           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvdeyen tvdeyen force-pushed the admin_generator branch from 19b21d0 to b0d39be Compare May 29, 2025 08:51
@tvdeyen tvdeyen added the backport-v4.5 Backport this pull-request to v4.5 label May 30, 2025
@tvdeyen tvdeyen force-pushed the admin_generator branch from b0d39be to dc0495d Compare May 31, 2025 06:46
@tvdeyen tvdeyen moved this to In Progress in Solidus Admin May 31, 2025
@tvdeyen tvdeyen moved this from In Progress to Review in Solidus Admin May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v4.5 Backport this pull-request to v4.5 changelog:solidus_admin
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

3 participants