Urara-Blog/node_modules/.pnpm-store/v3/files/6f/a7186d72ac53c77f65d94fd04ac9017cf4624968ccf8394ece1eed46cd697c0cd0bf19a2973c431842f4b1722d3a9f0e439e656dfc7383a237b98baba74f13
2022-08-14 01:14:53 +08:00

41 lines
1.2 KiB
Text

/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
import {cacheNames} from 'workbox-core/_private/cacheNames.js';
import {logger} from 'workbox-core/_private/logger.js';
import {deleteOutdatedCaches} from './utils/deleteOutdatedCaches.js';
import './_version.js';
/**
* Adds an `activate` event listener which will clean up incompatible
* precaches that were created by older versions of Workbox.
*
* @memberof workbox-precaching
*/
function cleanupOutdatedCaches(): void {
// See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
self.addEventListener('activate', ((event: ExtendableEvent) => {
const cacheName = cacheNames.getPrecacheName();
event.waitUntil(
deleteOutdatedCaches(cacheName).then((cachesDeleted) => {
if (process.env.NODE_ENV !== 'production') {
if (cachesDeleted.length > 0) {
logger.log(
`The following out-of-date precaches were cleaned up ` +
`automatically:`,
cachesDeleted,
);
}
}
}),
);
}) as EventListener);
}
export {cleanupOutdatedCaches};