File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ defmodule Mix.Tasks.Deps.Unlock do
16
16
17
17
"""
18
18
19
- @ switches [ all: :boolean , unused: :boolean ]
19
+ @ switches [ all: :boolean , unused: :boolean , filter: :string ]
20
20
21
21
@ spec run ( OptionParser . argv ) :: :ok
22
22
def run ( args ) do
@@ -29,6 +29,27 @@ defmodule Mix.Tasks.Deps.Unlock do
29
29
opts [ :unused ] ->
30
30
apps = Mix.Dep . loaded ( [ ] ) |> Enum . map ( & & 1 . app )
31
31
Mix.Dep.Lock . read ( ) |> Map . take ( apps ) |> Mix.Dep.Lock . write ( )
32
+ filter = opts [ :filter ] ->
33
+ lock = Mix.Dep.Lock . read
34
+ apps = Map . keys ( lock )
35
+
36
+ unlock =
37
+ apps
38
+ |> Enum . filter ( & String . contains? ( "#{ & 1 } " , filter ) )
39
+
40
+ if unlock == [ ] do
41
+ Mix . shell . error "warning: no dependencies were matched"
42
+ else
43
+ lock =
44
+ Enum . reject ( lock , fn ( { app , _ } ) ->
45
+ app in unlock
46
+ end )
47
+ Mix.Dep.Lock . write ( lock )
48
+ Mix . shell . info """
49
+ Unlocked deps:
50
+ * #{ Enum . join ( unlock , "\n * " ) }
51
+ """
52
+ end
32
53
33
54
apps != [ ] ->
34
55
lock =
Original file line number Diff line number Diff line change @@ -238,6 +238,21 @@ defmodule Mix.Tasks.DepsTest do
238
238
end
239
239
end
240
240
241
+ test "unlocks filtered deps" , context do
242
+ Mix.Project . push DepsApp
243
+ in_tmp context . test , fn ->
244
+ Mix.Dep.Lock . write % { git_repo: "abcdef" , another: "hash" , another_one: "hash" }
245
+ Mix.Tasks.Deps.Unlock . run [ "--filter" , "another" ]
246
+ assert Mix.Dep.Lock . read == % { git_repo: "abcdef" }
247
+ output = """
248
+ Unlocked deps:
249
+ * another
250
+ * another_one
251
+ """
252
+ assert_received { :mix_shell , :info , [ ^ output ] }
253
+ end
254
+ end
255
+
241
256
## Deps environment
242
257
243
258
defmodule DepsEnvApp do
You can’t perform that action at this time.
0 commit comments