-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Mix: warn when project app name matches a dependency #15013
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
Mix: warn when project app name matches a dependency #15013
Conversation
|
Hi @pckrishnadas88, thank you for the PR! Although I would likely move the check elsewhere, perhaps on Mix.Dep.Loader or somewhere else where we already traverse the dependencies... |
This ensures Mix emits a warning if a project's app name conflicts with one of its dependencies.
|
Hi @josevalim, Thanks for the feedback! I’ve moved the check to Mix.Dep.Loader and added a test that verifies the warning prints when the project app name matches a dependency. Verified locally with a temporary project. I’m still learning Elixir, so any guidance or feedback is greatly appreciated. PTAL! —Krishnadas |
lib/mix/lib/mix/dep/loader.ex
Outdated
| mix_children(Mix.Project.config(), locked?, []) ++ Mix.Dep.Umbrella.unloaded() | ||
| deps = mix_children(Mix.Project.config(), locked?, []) ++ Mix.Dep.Umbrella.unloaded() | ||
| # warn if project app matches a dep | ||
| warn_on_duplicate_app_name(Mix.Project.config()[:app], deps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move it inside the with_scm_and_app, so we don't have to traverse deps twice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback!
I’ve moved the duplicate app name warning into with_scm_and_app. Please let me know if anything else is needed.
lib/mix/lib/mix/dep/loader.ex
Outdated
|
|
||
| {scm, opts} = | ||
| if is_nil(scm) and Mix.Hex.ensure_installed?(locked?) do | ||
| if is_nil(scm) and locked? and Mix.Hex.ensure_installed?(locked?) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the question — I might be missing something here.
I added the locked? check because when I remove it, the following test starts failing:
test raises when no SCM is specified (Mix.DepTest)
test/mix/dep_test.exs:115
Expected exception Mix.Error but got MatchError (no match of right hand side value:
{:error, {:hex, {~c"no such file or directory", ~c"hex.app"}}}
)
code: with_deps(deps, fn ->
stacktrace:
lib/hex.ex:5: Hex.start/0
(mix 1.20.0-dev) lib/mix/hex.ex:64: Mix.Hex.start/0
(mix 1.20.0-dev) lib/mix/dep/loader.ex:193: Mix.Dep.Loader.with_scm_and_app/5
(mix 1.20.0-dev) lib/mix/dep/loader.ex:145: Mix.Dep.Loader.to_dep/4
(elixir 1.20.0-dev) lib/enum.ex:1717: Enum."-map/2-lists^map/1-1-"/2
(mix 1.20.0-dev) lib/mix/dep/loader.ex:376: Mix.Dep.Loader.mix_children/3
(mix 1.20.0-dev) lib/mix/dep/loader.ex:22: Mix.Dep.Loader.children/1
(mix 1.20.0-dev) lib/mix/dep/converger.ex:101: Mix.Dep.Converger.all/4
(mix 1.20.0-dev) lib/mix/dep/converger.ex:93: Mix.Dep.Converger.converge/4
(mix 1.20.0-dev) lib/mix/dep/converger.ex:76: Mix.Dep.Converger.converge/1
(elixir 1.20.0-dev) lib/file.ex:2013: File.cd!/2
test/test_helper.exs:174: MixTest.Case.in_fixture/3
test/mix/dep_test.exs:35: Mix.DepTest.with_deps/2
test/mix/dep_test.exs:118: (test)
I’m not fully sure what the intended behavior is here, so I added the guard to keep the existing test behavior.
Happy to change this if there’s a better approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at test/mix/tasks/deps_test.exs and see how tests with dependencies are handled. We already have some dependencies that we can handle, such as ok and git_repo, and you can create a project with the same name as one of those deps. You can then also move the test to test/mix/tasks/deps_test.exs :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I’ve moved the test to test/mix/tasks/deps_test.exs and reused the existing :ok dependency fixture as suggested. All make test_mix passes locally.
|
💚 💙 💜 💛 ❤️ |
|
Thank you! 💚💙💜💛❤️ |
Summary
This PR adds a warning in Mix.Project when a project’s application name is the same as one of its dependencies.
Details
Currently, if a project declares an app name that is identical to one of its dependencies, Elixir doesn’t warn the user. This can lead to unexpected behaviors, such as hanging compilers when trying to start tasks from the dependency.
This fix implements
warn_on_duplicate_app_name/1inmix/project.exthat prints a warning usingMix.shell().error/1. The associated testMix.ProjectTestverifies the behavior.Example
If a user creates a project with:
and adds
{:aoc, "~> 0.16.0"}todeps, running:will print:
Related Issue
Fixes: [elixir-lang/elixir#14972](#14972)