Skip to content

Commit

Permalink
🐛 fix usage inside Elixir scripts Mix.install
Browse files Browse the repository at this point in the history
  • Loading branch information
IanLuites committed Aug 12, 2022
1 parent 9bbdf1b commit bb2a086
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
14 changes: 9 additions & 5 deletions README.md
Expand Up @@ -25,14 +25,18 @@ The docs can be found at [https://hexdocs.pm/common_x](https://hexdocs.pm/common

The following modules have extension:

- `ApplicationX` (`Application` extension)
- `CodeX` (`Code` extension)
- `EnumX` (`Enum` extension)
- `MapX` (`Map` extension)
- `Macro` (`Macro` extension)
- `ApplicationX` (`Application` extension)
- `CodeX` (`Code` extension)
- `EnumX` (`Enum` extension)
- `MapX` (`Map` extension)
- `Macro` (`Macro` extension)

## Changelog

### 2020-08-12 (v0.5.6)

- Fix project detection when installed inside a Elixir script with [`Mix.install/2`](https://hexdocs.pm/mix/Mix.html#install/2).

### 2020-11-08 (v0.5.5)

- Small fix detecting compile environment in custom commands and Elixir >= 1.11.
Expand Down
22 changes: 13 additions & 9 deletions lib/common_x/application_x.ex
Expand Up @@ -7,17 +7,21 @@ defmodule ApplicationX do
@ignore [:kernel, :stdlib, :elixir, :logger]
@load_error 'no such file or directory'

main_project =
task_module =
if p = Process.whereis(Mix.TasksServer) do
module =
p
|> Agent.get(&Map.keys/1)
|> Enum.find_value(false, fn
{:task, task, m} when task in ~W(app.start deps.loadpaths) -> m
_ -> false
end)
p
|> Agent.get(&Map.keys/1)
|> Enum.find_value(false, fn
{:task, task, m} when task in ~W(app.start deps.loadpaths) -> m
_ -> false
end)
end

if module, do: module.project()
main_project =
case task_module do
falsy when falsy in [nil, false] -> falsy
Mix.InstallProject -> []
module -> module.project()
end

main_app =
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -4,7 +4,7 @@ defmodule CommonX.MixProject do
def project do
[
app: :common_x,
version: "0.5.5",
version: "0.5.6",
description: "Extension of common Elixir modules.",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit bb2a086

Please sign in to comment.