@@ -227,12 +227,23 @@ protected function process(array $answers): void {
227227 protected function cleanup (): void {
228228 $ json = $ this ->readComposerJson ();
229229
230+ $ is_dependency = (
231+ !empty ($ json ['require ' ])
232+ && is_array ($ json ['require ' ])
233+ && isset ($ json ['require ' ]['alexskrypnyk/customizer ' ])
234+ ) || (
235+ !empty ($ json ['require-dev ' ])
236+ && is_array ($ json ['require-dev ' ])
237+ && isset ($ json ['require-dev ' ]['alexskrypnyk/customizer ' ])
238+ );
239+
230240 static ::arrayUnsetDeep ($ json , ['autoload ' , 'classmap ' ], basename (__FILE__ ), FALSE );
231241 static ::arrayUnsetDeep ($ json , ['scripts ' , 'customize ' ]);
232242 static ::arrayUnsetDeep ($ json , ['scripts ' , 'post-create-project-cmd ' ], '@customize ' );
233243
234244 static ::arrayUnsetDeep ($ json , ['require-dev ' , 'alexskrypnyk/customizer ' ]);
235245 static ::arrayUnsetDeep ($ json , ['autoload-dev ' , 'psr-4 ' , 'AlexSkrypnyk \\Customizer \\Tests \\' ]);
246+ static ::arrayUnsetDeep ($ json , ['config ' , 'allow-plugins ' , 'alexskrypnyk/customizer ' ]);
236247
237248 if (!empty ($ this ->cleanupCallback )) {
238249 call_user_func_array ($ this ->cleanupCallback , [&$ json , $ this ]);
@@ -242,17 +253,16 @@ protected function cleanup(): void {
242253 if (strcmp (serialize ($ this ->packageData ), serialize ($ json )) !== 0 ) {
243254 $ this ->writeComposerJson ($ json );
244255
245- if ($ this ->isComposerDependenciesInstalled ) {
256+ // We can only update the composer.lock file if the Customizer was not run
257+ // after the Composer dependencies were installed and the Customizer
258+ // was not installed as a dependency because the files will be removed
259+ // and this process will no longer have required dependencies.
260+ // For a Customizer installed as a dependency, the user should run
261+ // `composer update` manually (or through a plugin) after the Customizer
262+ // is finished.
263+ if ($ this ->isComposerDependenciesInstalled && !$ is_dependency ) {
246264 $ this ->io ->writeLn ('Updating composer.lock file after customization. ' );
247265 static ::passthru ('composer update --quiet --no-interaction --no-progress ' );
248- // Composer checks for plugins within installed packages, even if the
249- // packages are no longer is `composer.json`. So we need to remove the
250- // plugin from the `composer.json` and update the dependencies again.
251- if (isset ($ json ['config ' ]['allow-plugins ' ]['alexskrypnyk/customizer ' ])) {
252- static ::arrayUnsetDeep ($ json , ['config ' , 'allow-plugins ' , 'alexskrypnyk/customizer ' ]);
253- $ this ->writeComposerJson ($ json );
254- passthru ('composer update --quiet --no-interaction --no-progress ' );
255- }
256266 }
257267 }
258268
0 commit comments