Skip to content

Commit

Permalink
Remove ImportMapConfigReader dependency from PwaRuntime
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Spomky committed Mar 31, 2024
1 parent 8756f3a commit ce9722d
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/Twig/PwaRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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 +92,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 ce9722d

Please sign in to comment.