Skip to content

Commit

Permalink
Add a static method to support removing unused services only in dev e…
Browse files Browse the repository at this point in the history
…nviroment
  • Loading branch information
kayw-geek committed Mar 20, 2023
1 parent 121638b commit c2e5220
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/Script/Composer/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@

class Composer
{
public static function removeUnusedServices(
Event $event,
Filesystem $filesystem = null
)

public static function removeUnusedServicesInDevOnly(Event $event, Filesystem $filesystem = null)
{
self::removeUnusedServicesByExtraConfig($event, $filesystem, true);
}

public static function removeUnusedServices(Event $event, Filesystem $filesystem = null)
{
self::removeUnusedServicesByExtraConfig($event, $filesystem, false);
}

private static function removeUnusedServicesByExtraConfig(Event $event, Filesystem $filesystem = null, $onlyRunInDev = false)
{
if ($onlyRunInDev && !$event->isDevMode()){
return;
}

$composer = $event->getComposer();
$extra = $composer->getPackage()->getExtra();
$listedServices = isset($extra['aws/aws-sdk-php'])
Expand Down
2 changes: 1 addition & 1 deletion src/Script/Composer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ you have feedback on the implementation, please visit the [open discussion](http
we have on the topic.

To avoid shipping unused services, specify which services you would like to keep in your `composer.json` file and
use the `Aws\\Script\\Composer::removeUnusedServices` script:
use the `Aws\\Script\\Composer::removeUnusedServices` or `Aws\\Script\\Composer::removeUnusedServicesInDevOnly` script:

```
{
Expand Down

0 comments on commit c2e5220

Please sign in to comment.