@@ -65,30 +65,20 @@ defmodule Expert.Port do
65
65
# which contains path munging. This initial environment is present in the running
66
66
# VM, and needs to be undone so we can find the correct elixir executable in the project.
67
67
defp reset_env ( "asdf" , root_path ) do
68
- { env , _ } = System . cmd ( "asdf" , ~w( env elixir) , cd: root_path )
68
+ data_dir = System . get_env ( "ASDF_DATA_DIR" ) || Path . join ( System . user_home! ( ) , ".asdf" )
69
+ installs_dir = Path . join ( data_dir , "installs" )
69
70
70
- env =
71
- env
72
- |> String . trim ( )
73
- |> String . split ( "\n " )
74
- |> Enum . map ( fn key_and_value ->
75
- [ key , value ] =
76
- key_and_value
77
- |> String . split ( "=" , parts: 2 )
78
- |> Enum . map ( & String . trim / 1 )
71
+ { current , 0 } = System . cmd ( "asdf" , [ "list" ] , cd: root_path )
79
72
80
- { key , value }
81
- end )
82
- |> Enum . reject ( & is_nil / 1 )
73
+ versions = parse_asdf_installed_versions ( current , % { } )
83
74
84
- asdf_path =
85
- case List . keyfind ( env , "ASDF_INSTALL_PATH" , 0 ) do
86
- { _ , path } -> Path . join ( path , "../../../shims" )
87
- _ -> ""
88
- end
75
+ installed_bin_paths =
76
+ versions
77
+ |> Enum . map ( fn { tool , version } -> Path . join ( [ installs_dir , tool , version , "bin" ] ) end )
78
+ |> Enum . join ( ":" )
89
79
90
80
Enum . map ( System . get_env ( ) , fn
91
- { "PATH" , path } -> { "PATH" , "#{ asdf_path } :#{ path } " }
81
+ { "PATH" , path } -> { "PATH" , "#{ installed_bin_paths } :#{ path } " }
92
82
other -> other
93
83
end )
94
84
end
@@ -143,6 +133,39 @@ defmodule Expert.Port do
143
133
|> Enum . reject ( & is_nil / 1 )
144
134
end
145
135
136
+ defp parse_asdf_installed_versions ( output , acc ) when is_binary ( output ) do
137
+ output
138
+ |> String . split ( "\n " , trim: true )
139
+ |> parse_asdf_installed_versions ( acc )
140
+ end
141
+
142
+ defp parse_asdf_installed_versions ( [ ] , acc ) , do: acc
143
+
144
+ defp parse_asdf_installed_versions ( [ line | rest ] , acc ) do
145
+ tool_fn? = & ( not String . starts_with? ( & 1 , " " ) )
146
+
147
+ case tool_fn? . ( line ) do
148
+ true ->
149
+ { versions , rest } = Enum . split_while ( rest , & ( not tool_fn? . ( & 1 ) ) )
150
+ versions = Enum . map ( versions , & String . trim / 1 )
151
+ version = Enum . find ( versions , & String . starts_with? ( & 1 , "*" ) )
152
+
153
+ case version do
154
+ nil ->
155
+ parse_asdf_installed_versions ( rest , acc )
156
+
157
+ version when is_binary ( version ) ->
158
+ version = String . trim ( version , "*" )
159
+ acc = Map . put ( acc , line , version )
160
+
161
+ parse_asdf_installed_versions ( rest , acc )
162
+ end
163
+
164
+ false ->
165
+ parse_asdf_installed_versions ( rest , acc )
166
+ end
167
+ end
168
+
146
169
@ doc """
147
170
Launches an executable in the project context via a port.
148
171
"""
0 commit comments