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
1616
1717 """
1818
19- @ switches [ all: :boolean , unused: :boolean ]
19+ @ switches [ all: :boolean , unused: :boolean , filter: :string ]
2020
2121 @ spec run ( OptionParser . argv ) :: :ok
2222 def run ( args ) do
@@ -29,6 +29,27 @@ defmodule Mix.Tasks.Deps.Unlock do
2929 opts [ :unused ] ->
3030 apps = Mix.Dep . loaded ( [ ] ) |> Enum . map ( & & 1 . app )
3131 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
3253
3354 apps != [ ] ->
3455 lock =
Original file line number Diff line number Diff line change @@ -238,6 +238,21 @@ defmodule Mix.Tasks.DepsTest do
238238 end
239239 end
240240
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+
241256 ## Deps environment
242257
243258 defmodule DepsEnvApp do
You can’t perform that action at this time.
0 commit comments