@@ -115,23 +115,6 @@ private function prepare()
115115 $ this ->addIrremovablePackageConstraint ($ package ->getName (), new Constraint ('== ' , $ package ->getVersion ()));
116116 $ this ->addIrremovablePackageConstraint ($ package ->getAliasOf ()->getName (), new Constraint ('== ' , $ package ->getAliasOf ()->getVersion ()));
117117 }
118-
119- // This is the lazy approach. We simply do not remove any packages that are replaced or replace others here.
120- // (maybe this can be improved?)
121- if ($ package ->getReplaces ()) {
122- $ this ->addIrremovablePackageConstraint ($ package ->getName (), new Constraint ('== ' , $ package ->getVersion ()));
123-
124- foreach ($ package ->getReplaces () as $ link ) {
125- // Make sure we do not replace ourselves (if someone made a mistake and tagged it)
126- // See e.g. https://github.com/BabDev/Pagerfanta/commit/fd00eb74632fecc0265327e9fe0eddc08c72b238#diff-b5d0ee8c97c7abd7e3fa29b9a27d1780
127- // TODO: should that go into package itself?
128- if ($ package ->getName () === $ link ->getTarget ()) {
129- continue ;
130- }
131-
132- $ this ->addIrremovablePackageConstraint ($ link ->getTarget (), $ link ->getConstraint ());
133- }
134- }
135118 }
136119
137120 // Mark the packages as irremovable based on the constraints
@@ -207,6 +190,22 @@ private function optimizeByIdenticalDependencies()
207190 $ groupHashParts [] = 'require: ' . (string ) $ requireConstraint ;
208191 }
209192
193+ if ($ package ->getReplaces ()) {
194+ foreach ($ package ->getReplaces () as $ link ) {
195+ // Make sure we do not replace ourselves (if someone made a mistake and tagged it)
196+ // See e.g. https://github.com/BabDev/Pagerfanta/commit/fd00eb74632fecc0265327e9fe0eddc08c72b238#diff-b5d0ee8c97c7abd7e3fa29b9a27d1780
197+ // TODO: should that go into package itself?
198+ if ($ package ->getName () === $ link ->getTarget ()) {
199+ continue ;
200+ }
201+
202+ if (CompilingMatcher::match ($ link ->getConstraint (), Constraint::OP_EQ , $ package ->getVersion ())) {
203+ // Use the same hash part as the regular require hash because that's what the replacement does
204+ $ groupHashParts [] = 'require: ' . (string ) $ link ->getConstraint ();
205+ }
206+ }
207+ }
208+
210209 if (isset ($ this ->conflictConstraintsPerPackage [$ packageName ])) {
211210 foreach ($ this ->conflictConstraintsPerPackage [$ packageName ] as $ conflictConstraint ) {
212211 if (CompilingMatcher::match ($ conflictConstraint , Constraint::OP_EQ , $ package ->getVersion ())) {
0 commit comments