Urara-Blog/node_modules/.pnpm-store/v3/files/1d/5a75f3994ed2df3be223c570537e01474e6105aceb2c1c84a4b5b91a2a41b74b559a6a83c6facba900a62924f46306cace11b27f890941bc3a13f7d56bc47f
2022-08-14 01:14:53 +08:00

58 lines
1.5 KiB
Text

/*
Copyright 2020 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 {WorkboxPlugin, WorkboxPluginCallbackParam} from 'workbox-core/types.js';
import '../_version.js';
/**
* A plugin, designed to be used with PrecacheController, to determine the
* of assets that were updated (or not updated) during the install event.
*
* @private
*/
class PrecacheInstallReportPlugin implements WorkboxPlugin {
updatedURLs: string[] = [];
notUpdatedURLs: string[] = [];
handlerWillStart: WorkboxPlugin['handlerWillStart'] = async ({
request,
state,
}: WorkboxPluginCallbackParam['handlerWillStart']) => {
// TODO: `state` should never be undefined...
if (state) {
state.originalRequest = request;
}
};
cachedResponseWillBeUsed: WorkboxPlugin['cachedResponseWillBeUsed'] = async ({
event,
state,
cachedResponse,
}: WorkboxPluginCallbackParam['cachedResponseWillBeUsed']) => {
if (event.type === 'install') {
if (
state &&
state.originalRequest &&
state.originalRequest instanceof Request
) {
// TODO: `state` should never be undefined...
const url = state.originalRequest.url;
if (cachedResponse) {
this.notUpdatedURLs.push(url);
} else {
this.updatedURLs.push(url);
}
}
}
return cachedResponse;
};
}
export {PrecacheInstallReportPlugin};