@@ -81,6 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
81
81
$ requirements = $ this ->determineRequirements ($ input , $ output , $ input ->getArgument ('packages ' ));
82
82
83
83
$ requireKey = $ input ->getOption ('dev ' ) ? 'require-dev ' : 'require ' ;
84
+ $ removeKey = $ input ->getOption ('dev ' ) ? 'require ' : 'require-dev ' ;
84
85
$ baseRequirements = array_key_exists ($ requireKey , $ composer ) ? $ composer [$ requireKey ] : array ();
85
86
$ requirements = $ this ->formatRequirements ($ requirements );
86
87
@@ -90,9 +91,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
90
91
$ versionParser ->parseConstraints ($ constraint );
91
92
}
92
93
93
- if (!$ this ->updateFileCleanly ($ json , $ baseRequirements , $ requirements , $ requireKey )) {
94
+ if (!$ this ->updateFileCleanly ($ json , $ baseRequirements , $ requirements , $ requireKey, $ removeKey )) {
94
95
foreach ($ requirements as $ package => $ version ) {
95
96
$ baseRequirements [$ package ] = $ version ;
97
+
98
+ if (isset ($ composer [$ removeKey ][$ package ])) {
99
+ unset($ composer [$ removeKey ][$ package ]);
100
+ }
96
101
}
97
102
98
103
$ composer [$ requireKey ] = $ baseRequirements ;
@@ -134,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
134
139
return $ status ;
135
140
}
136
141
137
- private function updateFileCleanly ($ json , array $ base , array $ new , $ requireKey )
142
+ private function updateFileCleanly ($ json , array $ base , array $ new , $ requireKey, $ removeKey )
138
143
{
139
144
$ contents = file_get_contents ($ json ->getPath ());
140
145
@@ -144,6 +149,9 @@ private function updateFileCleanly($json, array $base, array $new, $requireKey)
144
149
if (!$ manipulator ->addLink ($ requireKey , $ package , $ constraint )) {
145
150
return false ;
146
151
}
152
+ if (!$ manipulator ->removeSubNode ($ removeKey , $ package )) {
153
+ return false ;
154
+ }
147
155
}
148
156
149
157
file_put_contents ($ json ->getPath (), $ manipulator ->getContents ());
0 commit comments