Skip to content

Setup generator namespace in generator#6310

Merged
tvdeyen merged 2 commits intosolidusio:mainfrom
mamhoff:revert-6237
Aug 5, 2025
Merged

Setup generator namespace in generator#6310
tvdeyen merged 2 commits intosolidusio:mainfrom
mamhoff:revert-6237

Conversation

@mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Jul 27, 2025

Summary

#6237 introduced setting the generator namespace in an initializer - however, that broke the sandbox and rails server, because in that initializer Rails::Generator would only be defined if we're actually running a generator, but not when running rails server or rails console.

This PR reverts that commit, and instead proposes moving setting the generator namespace to the generator itself. That way, we control a little better what's going on.

I'm not sure this is the best solution out there. My questions are:

  • do we need to namespace things in SolidusAdmin? Should we assume that all components ever defined for the new admin live in that namespace?
  • How is Rails::Generators.namespace usually set? Should we even set it?

I do not have answers to these questions. But this PR allows us to run both the component generator and rails server.

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.

mamhoff added 2 commits July 27, 2025 15:15
…rator"

This reverts commit 48de765, reversing
changes made to 13a7bbd.
A previous solution for this bug tried to set the generator namespace in
an app initializer, but that required `rails/generators/base` to be
required - which it is not always when starting up e.g. a server.

I've tried to dig a bit into how this `mattr_accessor :namespace` on
`Rails::Generators::Base` is supposed to be used. It seems like it is
run when loading an engine's generators here[1], but that does not work
in this context.

I don't fully understand how Rails::Generators.namespace is supposed to
be set, but this at least sets it only when needed. There's probably
some magic that we could invoke, but I can't find it documented
anywhere.

[1] https://github.com/rails/rails/blob/main/railties/lib/rails/command/actions.rb#L38
@codecov
Copy link

codecov bot commented Jul 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@424f284). Learn more about missing BASE report.
⚠️ Report is 40 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6310   +/-   ##
=======================================
  Coverage        ?   89.31%           
=======================================
  Files           ?      959           
  Lines           ?    20118           
  Branches        ?        0           
=======================================
  Hits            ?    17969           
  Misses          ?     2149           
  Partials        ?        0           

☔ 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.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read some Rails source code as well and I "think" we can simply move the component generator into the Generators namespace and it "should work"™️

https://github.com/rails/rails/blob/main/railties/lib/rails/generators/base.rb#L56

Can we try that?

@mamhoff
Copy link
Contributor Author

mamhoff commented Aug 5, 2025

I tried that, it doesn't seem to do the thing.

@tvdeyen
Copy link
Member

tvdeyen commented Aug 5, 2025

I tried that, it doesn't seem to do the thing.

Ok, thanks for checking

@tvdeyen tvdeyen merged commit fa8e686 into solidusio:main Aug 5, 2025
39 checks passed
@tvdeyen tvdeyen added this to the 4.6 milestone Aug 5, 2025
@tvdeyen tvdeyen removed this from Solidus Admin Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants