@@ -76,6 +76,7 @@ class Flex implements PluginInterface, EventSubscriberInterface
7676 private $ lock ;
7777 private $ displayThanksReminder = 0 ;
7878 private $ dryRun = false ;
79+ private $ reinstall ;
7980 private static $ activated = true ;
8081 private static $ aliasResolveCommands = [
8182 'require ' => true ,
@@ -117,8 +118,12 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
117118 $ this ->filter = new PackageFilter ($ io , $ symfonyRequire , $ this ->downloader );
118119 }
119120
121+ $ composerFile = Factory::getComposerFile ();
122+ $ composerLock = 'json ' === pathinfo ($ composerFile , \PATHINFO_EXTENSION ) ? substr ($ composerFile , 0 , -4 ).'lock ' : $ composerFile .'.lock ' ;
123+ $ symfonyLock = str_replace ('composer ' , 'symfony ' , basename ($ composerLock ));
124+
120125 $ this ->configurator = new Configurator ($ composer , $ io , $ this ->options );
121- $ this ->lock = new Lock (getenv ('SYMFONY_LOCKFILE ' ) ?: str_replace ( ' composer.json ' , 'symfony.lock ' , Factory:: getComposerFile () ));
126+ $ this ->lock = new Lock (getenv ('SYMFONY_LOCKFILE ' ) ?: \dirname ( $ composerLock ). ' / ' .( basename ( $ composerLock ) !== $ symfonyLock ? $ symfonyLock : 'symfony.lock ' ));
122127
123128 $ disable = true ;
124129 foreach (array_merge ($ composer ->getPackage ()->getRequires () ?? [], $ composer ->getPackage ()->getDevRequires () ?? []) as $ link ) {
@@ -244,6 +249,13 @@ public function configureProject(Event $event)
244249 $ this ->updateComposerLock ();
245250 }
246251
252+ public function recordFlexInstall (PackageEvent $ event )
253+ {
254+ if (null === $ this ->reinstall && 'symfony/flex ' === $ event ->getOperation ()->getPackage ()->getName ()) {
255+ $ this ->reinstall = true ;
256+ }
257+ }
258+
247259 public function record (PackageEvent $ event )
248260 {
249261 if ($ this ->shouldRecordOperation ($ event ->getOperation (), $ event ->isDevMode (), $ event ->getComposer ())) {
@@ -286,7 +298,7 @@ public function update(Event $event, $operations = [])
286298 $ contents = file_get_contents ($ file );
287299 $ json = JsonFile::parseJson ($ contents );
288300
289- if (!isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
301+ if (!$ this -> reinstall && ! isset ($ json ['flex-require ' ]) && !isset ($ json ['flex-require-dev ' ])) {
290302 $ this ->unpack ($ event );
291303
292304 return ;
@@ -298,17 +310,18 @@ public function update(Event $event, $operations = [])
298310 $ symfonyVersion = $ json ['extra ' ]['symfony ' ]['require ' ] ?? null ;
299311 $ versions = $ symfonyVersion ? $ this ->downloader ->getVersions () : null ;
300312 foreach (['require ' , 'require-dev ' ] as $ type ) {
301- if (isset ($ json ['flex- ' .$ type ])) {
302- foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
303- if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
304- // replace unbounded constraints for symfony/* packages by extra.symfony.require
305- $ constraint = $ symfonyVersion ;
306- }
307- $ manipulator -> addLink ( $ type , $ package , $ constraint , $ sortPackages ) ;
313+ if (! isset ($ json ['flex- ' .$ type ])) {
314+ continue ;
315+ }
316+ foreach ( $ json [ ' flex- ' . $ type ] as $ package => $ constraint ) {
317+ if ( $ symfonyVersion && ' * ' === $ constraint && isset ( $ versions [ ' splits ' ][ $ package ])) {
318+ // replace unbounded constraints for symfony/* packages by extra.symfony.require
319+ $ constraint = $ symfonyVersion ;
308320 }
309-
310- $ manipulator ->removeMainKey ('flex- ' .$ type );
321+ $ manipulator ->addLink ($ type , $ package , $ constraint , $ sortPackages );
311322 }
323+
324+ $ manipulator ->removeMainKey ('flex- ' .$ type );
312325 }
313326
314327 file_put_contents ($ file , $ manipulator ->getContents ());
@@ -671,7 +684,7 @@ private function formatOrigin(Recipe $recipe): string
671684
672685 private function shouldRecordOperation (OperationInterface $ operation , bool $ isDevMode , Composer $ composer = null ): bool
673686 {
674- if ($ this ->dryRun ) {
687+ if ($ this ->dryRun || $ this -> reinstall ) {
675688 return false ;
676689 }
677690
@@ -746,6 +759,7 @@ private function unpack(Event $event)
746759
747760 private function reinstall (Event $ event , bool $ update )
748761 {
762+ $ this ->reinstall = false ;
749763 $ event ->stopPropagation ();
750764
751765 $ ed = $ this ->composer ->getEventDispatcher ();
@@ -783,6 +797,7 @@ public static function getSubscribedEvents(): array
783797
784798 $ events = [
785799 PackageEvents::POST_PACKAGE_UPDATE => 'enableThanksReminder ' ,
800+ PackageEvents::POST_PACKAGE_INSTALL => 'recordFlexInstall ' ,
786801 InstallerEvents::PRE_OPERATIONS_EXEC => 'recordOperations ' ,
787802 PluginEvents::PRE_POOL_CREATE => 'truncatePackages ' ,
788803 ScriptEvents::POST_CREATE_PROJECT_CMD => 'configureProject ' ,
0 commit comments