@@ -38,6 +38,22 @@ public function __construct(Filesystem $files, $workingPath = null)
38
38
$ this ->workingPath = $ workingPath ;
39
39
}
40
40
41
+ /**
42
+ * Determine if the given Composer package is installed.
43
+ *
44
+ * @param string $package
45
+ * @return bool
46
+ *
47
+ * @throw \RuntimeException
48
+ */
49
+ protected function hasPackage ($ package )
50
+ {
51
+ $ composer = json_decode (file_get_contents ($ this ->findComposerFile ()), true );
52
+
53
+ return array_key_exists ($ package , $ composer ['require ' ] ?? [])
54
+ || array_key_exists ($ package , $ composer ['require-dev ' ] ?? []);
55
+ }
56
+
41
57
/**
42
58
* Install the given Composer packages into the application.
43
59
*
@@ -104,11 +120,7 @@ public function removePackages(array $packages, bool $dev = false, Closure|Outpu
104
120
*/
105
121
public function modify (callable $ callback )
106
122
{
107
- $ composerFile = "{$ this ->workingPath }/composer.json " ;
108
-
109
- if (! file_exists ($ composerFile )) {
110
- throw new RuntimeException ("Unable to locate `composer.json` file at [ {$ this ->workingPath }]. " );
111
- }
123
+ $ composerFile = $ this ->findComposerFile ();
112
124
113
125
$ composer = json_decode (file_get_contents ($ composerFile ), true , 512 , JSON_THROW_ON_ERROR );
114
126
@@ -147,7 +159,7 @@ public function dumpOptimized()
147
159
}
148
160
149
161
/**
150
- * Get the composer command for the environment.
162
+ * Get the Composer binary / command for the environment.
151
163
*
152
164
* @return array
153
165
*/
@@ -160,6 +172,24 @@ public function findComposer()
160
172
return ['composer ' ];
161
173
}
162
174
175
+ /**
176
+ * Get the path to the "composer.json" file.
177
+ *
178
+ * @return string
179
+ *
180
+ * @throw \RuntimeException
181
+ */
182
+ protected function findComposerFile ()
183
+ {
184
+ $ composerFile = "{$ this ->workingPath }/composer.json " ;
185
+
186
+ if (! file_exists ($ composerFile )) {
187
+ throw new RuntimeException ("Unable to locate `composer.json` file at [ {$ this ->workingPath }]. " );
188
+ }
189
+
190
+ return $ composerFile ;
191
+ }
192
+
163
193
/**
164
194
* Get the PHP binary.
165
195
*
0 commit comments