@@ -39,17 +39,17 @@ public function __construct(
3939 $ this ->distributionStoragePath = "$ storagePath/distribution " ;
4040 }
4141
42- public function exists (string $ packageName , string $ versionName , string $ reference , string $ type ): bool
42+ public function exists (string $ packageName , string $ versionName , ? string $ reference , ? string $ type ): bool
4343 {
44- return $ this ->filesystem ->exists ($ this ->path ($ packageName , $ versionName , $ reference , $ type ));
44+ return null !== $ reference && null !== $ type && $ this ->filesystem ->exists ($ this ->path ($ packageName , $ versionName , $ reference , $ type ));
4545 }
4646
4747 public function path (string $ packageName , string $ versionName , string $ reference , string $ type ): string
4848 {
4949 return "$ this ->distributionStoragePath / $ packageName/ $ versionName- $ reference. $ type " ;
5050 }
5151
52- public function resolve (Version $ version , string $ reference , string $ type , bool $ async ): bool
52+ public function resolve (Version $ version , ? string $ reference , ? string $ type , bool $ async ): bool
5353 {
5454 $ package = $ version ->getPackage ();
5555 $ packageName = $ package ->getName ();
@@ -73,16 +73,30 @@ public function resolve(Version $version, string $reference, string $type, bool
7373 return false ;
7474 }
7575
76- $ hasDistribution = null !== $ version -> getDist () ;
76+ $ result = false ;
7777
78- return match (true ) {
79- $ this ->buildDistributions && !$ hasDistribution => $ this ->build ($ version , $ reference , $ type ),
80- $ this ->mirrorDistributions && $ hasDistribution => $ this ->mirror ($ version , $ reference , $ type ),
81- default => false ,
82- };
78+ // Build the distribution from source
79+ if (
80+ $ this ->buildDistributions
81+ && $ version ->getPackage ()->getFetchStrategy ()->isVcs ()
82+ ) {
83+ $ result = $ this ->build ($ version , $ reference ?? $ version ->getSourceReference (), $ type ?? $ version ->getSourceType ());
84+ }
85+
86+ // Mirror the distribution from a remote source if it can't be built from source
87+ $ distributionAvailable = null !== $ version ->getDist ();
88+ if (
89+ !$ result
90+ && $ this ->mirrorDistributions
91+ && $ distributionAvailable
92+ ) {
93+ $ result = $ this ->mirror ($ version , $ reference ?? $ version ->getDistReference (), $ type ?? $ version ->getDistType ());
94+ }
95+
96+ return $ result ;
8397 }
8498
85- private function build (Version $ version , string $ reference , string $ type ): bool
99+ private function build (Version $ version , ? string $ reference , ? string $ type ): bool
86100 {
87101 // Skip building of outdated references for now
88102 if ($ reference !== $ version ->getSourceReference ()) {
@@ -119,7 +133,7 @@ private function build(Version $version, string $reference, string $type): bool
119133 return true ;
120134 }
121135
122- private function mirror (Version $ version , string $ reference , string $ type ): bool
136+ private function mirror (Version $ version , ? string $ reference , ? string $ type ): bool
123137 {
124138 // Skip mirroring of outdated references for now
125139 if ($ reference !== $ version ->getDistReference ()) {
0 commit comments