Skip to content

Commit

Permalink
Remove ImportMapConfigReader dependency from PwaRuntime (#152)
Browse files Browse the repository at this point in the history
* Remove ImportMapConfigReader dependency from PwaRuntime

The dependency on ImportMapConfigReader has been removed from PwaRuntime code to simplify Workbox URL generation. The URL is now directly derived from the `workboxPublicUrl` property of the serviceWorker's workbox object. This makes the code more maintainable and easy to read.

* Remove ImportMapConfigReader dependency from PwaRuntime

The ImportMapConfigReader dependency was removed from PwaRuntime.php, thus simplifying the Workbox URL generation process. The URL is now directly derived, resulting in a cleaner, more readable and easily maintainable codebase.
  • Loading branch information
Spomky authored Mar 31, 2024
1 parent 8756f3a commit 3713ae1
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/Twig/PwaRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SpomkyLabs\PwaBundle\Dto\Icon;
use SpomkyLabs\PwaBundle\Dto\Manifest;
use Symfony\Component\AssetMapper\AssetMapperInterface;
use Symfony\Component\AssetMapper\ImportMap\ImportMapConfigReader;
use Symfony\Component\AssetMapper\MappedAsset;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mime\MimeTypes;
Expand All @@ -25,8 +24,6 @@ public function __construct(
private bool $manifestEnabled,
#[Autowire('%spomky_labs_pwa.sw.enabled%')]
private bool $serviceWorkerEnabled,
#[Autowire('@asset_mapper.importmap.config_reader')]
private ImportMapConfigReader $importMapConfigReader,
private AssetMapperInterface $assetMapper,
private Manifest $manifest,
#[Autowire('%spomky_labs_pwa.manifest.public_url%')]
Expand Down Expand Up @@ -94,8 +91,7 @@ private function injectServiceWorker(string $output, bool $injectSW, array $swAt
$registerOptions = sprintf(', {%s}', mb_substr($registerOptions, 2));
}
if ($serviceWorker->workbox->enabled === true) {
$hasWorkboxWindow = $this->importMapConfigReader->findRootImportMapEntry('workbox-window') !== null;
$workboxUrl = $hasWorkboxWindow ? 'workbox-window' : 'https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-window.prod.mjs';
$workboxUrl = sprintf('%s%s', $serviceWorker->workbox->workboxPublicUrl, '/workbox-window.prod.mjs');
$declaration = <<<SERVICE_WORKER
<script type="module" {$scriptAttributes}>
import {Workbox} from '{$workboxUrl}';
Expand Down

0 comments on commit 3713ae1

Please sign in to comment.