phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.2k stars 2.86k forks source link

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

Open kyleboe opened 8 months ago

kyleboe commented 8 months ago

Environment

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:

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
kyleboe commented 8 months ago

I'm happy to open a PR for the proposed solution. Just want to see if there is a more apt name than depends-on or if there is some configuration I am missing.

kyleboe commented 8 months ago

I'm a dummy. That's what the --app flag does.

kyleboe commented 8 months ago

Ok actually I'm not as dumb as I thought (what a sentence).

There are some subtle differences that should be addressed. When passing the --app flag there are other collisions in the generator.

chrismccord commented 8 months ago

Please share the details of the collisions you hit. Thanks!

kyleboe commented 8 months ago

Ah yeah sorry I've been working on the PR to fix it. The collisions were in the generated app name. While the parent folder reflects the name passed as the argument (bar in my example) the contents the folder reflect value of the --app flag.

The most clear example of this was in the apps/bar/mix.exs that started with:

defmodule Foo.MixProject do

As well as apps/bar/lib/foo.ex

kyleboe commented 8 months ago

PR #5691 fixes things in the context of the test suite as well as local manual testing.