Skip to content

Creating Umbrella Web App With phx.new.web Results in App That Cannot Be Compiled #5690

@kyleboe

Description

@kyleboe

Environment

  • Elixir version (elixir -v): 1.16.0
  • Phoenix version (mix deps): 1.7.10
  • Operating system: macOS 14.2.1

Actual Behavior

  1. mix phx.new foo --umbrella
  2. cd foo_umbrella/apps
  3. mix phx.new.web bar
  4. cd ..
  5. mix

There are a couple errors that occur:

  • Related to the appended configuration in config/config.exs:
    config :bar,
      ecto_repos: [Bar.Repo],
      generators: [context_app: false]
    Bar.Repo should not exist in the context of specifically a web application. It is inconsistent with the generated foo_web configuration:
    config :foo_web,
      ecto_repos: [Foo.Repo],
      generators: [context_app: :foo]
  • Related to the generated bar/test/support/conn_case.exs file:
    Bar.DataCase.setup_sandbox(tags)
    Similar to the above, I don't believe this should exist and should instead reference the dependent support module. Also inconsistent with the generated foo_web config:
    Foo.DataCase.setup_sandbox(tags)

Expected Behavior

The app should be able to be compiled when a new web app is generated in the context of an umbrella app.

Proposed Solution

Adding something like a --depends-on flag to the phx.new.web generator so that the backing app can be specified in the generator. The additional context of the flag would also enable adding {:foo, in_umbrella: true}, automatically to deps inside of bar/mix.exs

Example:

mix phx.new.web bar --depends-on foo

Resulting in:

# config/config.exs
config :bar,
  ecto_repos: [Foo.Repo],
  generators: [context_app: :foo]
# bar/test/support/conn_case.exs
Foo.DataCase.setup_sandbox(tags)
# bar/mix.exs
defp deps do
  [
    . . .
    {:foo, in_umbrella: true}
  ]
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions