From 07248f4323934859a66a50d84f018c82d6f5347e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 18 Sep 2024 09:16:31 +0200 Subject: [PATCH] Fix require command skipping new stability-flags from the lock file, fixes #11698 (#12112) --- src/Composer/Command/RequireCommand.php | 6 ++++++ src/Composer/Package/Locker.php | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 1b6f5e7b8..6f1b9ea7c 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -561,10 +561,16 @@ EOT } $lockFile = Factory::getLockFile($this->json->getPath()); if (file_exists($lockFile)) { + $stabilityFlags = RootPackageLoader::extractStabilityFlags($requirements, $composer->getPackage()->getMinimumStability(), []); + $lockMtime = filemtime($lockFile); $lock = new JsonFile($lockFile); $lockData = $lock->read(); $lockData['content-hash'] = Locker::getContentHash($contents); + foreach ($stabilityFlags as $packageName => $flag) { + $lockData['stability-flags'][$packageName] = $flag; + } + ksort($lockData['stability-flags']); $lock->write($lockData); if (is_int($lockMtime)) { @touch($lockFile, $lockMtime); diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 87971cc03..366af3f3f 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -373,6 +373,8 @@ class Locker 'prefer-lowest' => $preferLowest, ]; + ksort($lock['stability-flags']); + $lock['packages'] = $this->lockPackages($packages); if (null !== $devPackages) { $lock['packages-dev'] = $this->lockPackages($devPackages);