@@ -259,49 +259,49 @@ export class DocViewerComponent implements OnDestroy {
259259 * issues with failing to find resources in the cache.
260260 * (See https://github.com/angular/angular/issues/28114.)
261261 */
262- async function printSwDebugInfo ( ) : Promise < void > {
263- console . log ( `\nServiceWorker: ${ navigator . serviceWorker ?. controller ?. state ?? 'N/A' } ` ) ;
264-
265- if ( typeof caches === 'undefined' ) {
266- console . log ( '\nCaches: N/A' ) ;
267- } else {
268- const allCacheNames = await caches . keys ( ) ;
269- const swCacheNames = allCacheNames . filter ( name => name . startsWith ( 'ngsw:/:' ) ) ;
270-
271- await findCachesAndPrintEntries ( swCacheNames , 'db:control' , true , [ 'manifests' ] ) ;
272- await findCachesAndPrintEntries ( swCacheNames , 'assets:app-shell:cache' , false ) ;
273- await findCachesAndPrintEntries ( swCacheNames , 'assets:app-shell:meta' , true ) ;
274- }
262+ function printSwDebugInfo ( ) : Promise < void > {
263+ return Promise . resolve ( )
264+ . then ( ( ) => console . log ( `\nServiceWorker: ${ navigator . serviceWorker ?. controller ?. state ?? 'N/A' } ` ) )
265+ . then ( ( ) => {
266+ if ( typeof caches === 'undefined' ) {
267+ return console . log ( '\nCaches: N/A' ) ;
268+ } else {
269+ return caches . keys ( ) . then ( allCacheNames => {
270+ const swCacheNames = allCacheNames . filter ( name => name . startsWith ( 'ngsw:/:' ) ) ;
271+ return findCachesAndPrintEntries ( swCacheNames , 'db:control' , true , [ 'manifests' ] )
272+ . then ( ( ) => findCachesAndPrintEntries ( swCacheNames , 'assets:app-shell:cache' , false ) )
273+ . then ( ( ) => findCachesAndPrintEntries ( swCacheNames , 'assets:app-shell:meta' , true ) ) ;
274+ } ) ;
275+ }
276+ } )
277+ . then ( ( ) => {
278+ console . warn (
279+ '\nIf you see this error, please report an issue at ' +
280+ 'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.' ) ;
281+ } ) ;
275282
276- console . warn (
277- '\nIf you see this error, please report an issue at ' +
278- 'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.' ) ;
279283
280284 // Internal helpers
281- async function findCachesAndPrintEntries (
285+ function findCachesAndPrintEntries (
282286 swCacheNames : string [ ] , nameSuffix : string , includeValues = false ,
283287 ignoredKeys : string [ ] = [ ] ) : Promise < void > {
284288 const cacheNames = swCacheNames . filter ( name => name . endsWith ( nameSuffix ) ) ;
285289
286- for ( const cacheName of cacheNames ) {
287- const cacheEntries = await getCacheEntries ( cacheName , includeValues , ignoredKeys ) ;
288- await printCacheEntries ( cacheName , cacheEntries ) ;
289- }
290+ return cacheNames . reduce ( ( prev , cacheName ) => prev
291+ . then ( ( ) => getCacheEntries ( cacheName , includeValues , ignoredKeys ) )
292+ . then ( cacheEntries => printCacheEntries ( cacheName , cacheEntries ) ) , Promise . resolve ( ) ) ;
290293 }
291294
292- async function getCacheEntries (
295+ function getCacheEntries (
293296 name : string , includeValues = false ,
294297 ignoredKeys : string [ ] = [ ] ) : Promise < { key : string , value ?: object } [ ] > {
295298 const ignoredUrls = new Set ( ignoredKeys . map ( key => new Request ( key ) . url ) ) ;
296299
297- const cache = await caches . open ( name ) ;
298- const keys = ( await cache . keys ( ) ) . map ( req => req . url ) . filter ( url => ! ignoredUrls . has ( url ) ) ;
299- const entries = await Promise . all ( keys . map ( async key => ( {
300- key,
301- value : ! includeValues ? undefined : await ( await cache . match ( key ) ) ?. json ( ) ,
302- } ) ) ) ;
303-
304- return entries ;
300+ return caches . open ( name ) . then ( cache => cache . keys ( )
301+ . then ( keys => keys . map ( req => req . url ) . filter ( url => ! ignoredUrls . has ( url ) ) )
302+ . then ( keys => Promise . all ( keys . map ( key => ! includeValues ?
303+ { key} :
304+ cache . match ( key ) . then ( res => res ?. json ( ) ) . then ( value => ( { key, value} ) ) ) ) ) ) ;
305305 }
306306
307307 function printCacheEntries ( name : string , entries : { key : string , value ?: object } [ ] ) : void {
0 commit comments