workbox-precaching
Advanced tools
Comparing version 6.3.0 to 6.4.0
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:precaching:6.2.4'] && _(); | ||
self['workbox:precaching:6.3.0'] && _(); | ||
} | ||
catch (e) { } |
@@ -6,3 +6,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self['workbox:precaching:6.2.4'] && _(); | ||
self['workbox:precaching:6.3.0'] && _(); | ||
} catch (e) {} | ||
@@ -9,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.precaching=function(t,e,s,n,i,c,r,o){"use strict";try{self["workbox:precaching:6.2.4"]&&_()}catch(t){}function a(t){if(!t)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if("string"==typeof t){const e=new URL(t,location.href);return{cacheKey:e.href,url:e.href}}const{revision:e,url:n}=t;if(!n)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if(!e){const t=new URL(n,location.href);return{cacheKey:t.href,url:t.href}}const i=new URL(n,location.href),c=new URL(n,location.href);return i.searchParams.set("__WB_REVISION__",e),{cacheKey:i.href,url:c.href}}class h{constructor(){this.updatedURLs=[],this.notUpdatedURLs=[],this.handlerWillStart=async({request:t,state:e})=>{e&&(e.originalRequest=t)},this.cachedResponseWillBeUsed=async({event:t,state:e,cachedResponse:s})=>{if("install"===t.type&&e&&e.originalRequest&&e.originalRequest instanceof Request){const t=e.originalRequest.url;s?this.notUpdatedURLs.push(t):this.updatedURLs.push(t)}return s}}}class l{constructor({precacheController:t}){this.cacheKeyWillBeUsed=async({request:t,params:e})=>{const s=(null==e?void 0:e.cacheKey)||this.Z.getCacheKeyForURL(t.url);return s?new Request(s,{headers:t.headers}):t},this.Z=t}}class u extends c.Strategy{constructor(t={}){t.cacheName=e.cacheNames.getPrecacheName(t.cacheName),super(t),this.tt=!1!==t.fallbackToNetwork,this.plugins.push(u.copyRedirectedCacheableResponsesPlugin)}async _handle(t,e){const s=await e.cacheMatch(t);return s||(e.event&&"install"===e.event.type?await this.et(t,e):await this.st(t,e))}async st(t,e){let n;const i=e.params||{};if(!this.tt)throw new s.WorkboxError("missing-precache-entry",{cacheName:this.cacheName,url:t.url});{const s=i.integrity,c=t.integrity,r=!c||c===s;n=await e.fetch(new Request(t,{integrity:c||s})),s&&r&&(this.nt(),await e.cachePut(t,n.clone()))}return n}async et(t,e){this.nt();const n=await e.fetch(t);if(!await e.cachePut(t,n.clone()))throw new s.WorkboxError("bad-precaching-response",{url:t.url,status:n.status});return n}nt(){let t=null,e=0;for(const[s,n]of this.plugins.entries())n!==u.copyRedirectedCacheableResponsesPlugin&&(n===u.defaultPrecacheCacheabilityPlugin&&(t=s),n.cacheWillUpdate&&e++);0===e?this.plugins.push(u.defaultPrecacheCacheabilityPlugin):e>1&&null!==t&&this.plugins.splice(t,1)}}u.defaultPrecacheCacheabilityPlugin={cacheWillUpdate:async({response:t})=>!t||t.status>=400?null:t},u.copyRedirectedCacheableResponsesPlugin={cacheWillUpdate:async({response:t})=>t.redirected?await i.copyResponse(t):t};class f{constructor({cacheName:t,plugins:s=[],fallbackToNetwork:n=!0}={}){this.it=new Map,this.ct=new Map,this.rt=new Map,this.ot=new u({cacheName:e.cacheNames.getPrecacheName(t),plugins:[...s,new l({precacheController:this})],fallbackToNetwork:n}),this.install=this.install.bind(this),this.activate=this.activate.bind(this)}get strategy(){return this.ot}precache(t){this.addToCacheList(t),this.at||(self.addEventListener("install",this.install),self.addEventListener("activate",this.activate),this.at=!0)}addToCacheList(t){const e=[];for(const n of t){"string"==typeof n?e.push(n):n&&void 0===n.revision&&e.push(n.url);const{cacheKey:t,url:i}=a(n),c="string"!=typeof n&&n.revision?"reload":"default";if(this.it.has(i)&&this.it.get(i)!==t)throw new s.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:this.it.get(i),secondEntry:t});if("string"!=typeof n&&n.integrity){if(this.rt.has(t)&&this.rt.get(t)!==n.integrity)throw new s.WorkboxError("add-to-cache-list-conflicting-integrities",{url:i});this.rt.set(t,n.integrity)}if(this.it.set(i,t),this.ct.set(i,c),e.length>0){const t=`Workbox is precaching URLs without revision info: ${e.join(", ")}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(t)}}}install(t){return n.waitUntil(t,(async()=>{const e=new h;this.strategy.plugins.push(e);for(const[e,s]of this.it){const n=this.rt.get(s),i=this.ct.get(e),c=new Request(e,{integrity:n,cache:i,credentials:"same-origin"});await Promise.all(this.strategy.handleAll({params:{cacheKey:s},request:c,event:t}))}const{updatedURLs:s,notUpdatedURLs:n}=e;return{updatedURLs:s,notUpdatedURLs:n}}))}activate(t){return n.waitUntil(t,(async()=>{const t=await self.caches.open(this.strategy.cacheName),e=await t.keys(),s=new Set(this.it.values()),n=[];for(const i of e)s.has(i.url)||(await t.delete(i),n.push(i.url));return{deletedURLs:n}}))}getURLsToCacheKeys(){return this.it}getCachedURLs(){return[...this.it.keys()]}getCacheKeyForURL(t){const e=new URL(t,location.href);return this.it.get(e.href)}getIntegrityForCacheKey(t){return this.rt.get(t)}async matchPrecache(t){const e=t instanceof Request?t.url:t,s=this.getCacheKeyForURL(e);if(s){return(await self.caches.open(this.strategy.cacheName)).match(s)}}createHandlerBoundToURL(t){const e=this.getCacheKeyForURL(t);if(!e)throw new s.WorkboxError("non-precached-url",{url:t});return s=>(s.request=new Request(t),s.params=Object.assign({cacheKey:e},s.params),this.strategy.handle(s))}}let w;const d=()=>(w||(w=new f),w);class y extends o.Route{constructor(t,e){super((({request:s})=>{const n=t.getURLsToCacheKeys();for(const i of function*(t,{ignoreURLParametersMatching:e=[/^utm_/,/^fbclid$/],directoryIndex:s="index.html",cleanURLs:n=!0,urlManipulation:i}={}){const c=new URL(t,location.href);c.hash="",yield c.href;const r=function(t,e=[]){for(const s of[...t.searchParams.keys()])e.some((t=>t.test(s)))&&t.searchParams.delete(s);return t}(c,e);if(yield r.href,s&&r.pathname.endsWith("/")){const t=new URL(r.href);t.pathname+=s,yield t.href}if(n){const t=new URL(r.href);t.pathname+=".html",yield t.href}if(i){const t=i({url:c});for(const e of t)yield e.href}}(s.url,e)){const e=n.get(i);if(e){return{cacheKey:e,integrity:t.getIntegrityForCacheKey(e)}}}}),t.strategy)}}function p(t){const e=d(),s=new y(e,t);r.registerRoute(s)}function R(t){d().precache(t)}return t.PrecacheController=f,t.PrecacheFallbackPlugin=class{constructor({fallbackURL:t,precacheController:e}){this.handlerDidError=()=>this.Z.matchPrecache(this.ht),this.ht=t,this.Z=e||d()}},t.PrecacheRoute=y,t.PrecacheStrategy=u,t.addPlugins=function(t){d().strategy.plugins.push(...t)},t.addRoute=p,t.cleanupOutdatedCaches=function(){self.addEventListener("activate",(t=>{const s=e.cacheNames.getPrecacheName();t.waitUntil((async(t,e="-precache-")=>{const s=(await self.caches.keys()).filter((s=>s.includes(e)&&s.includes(self.registration.scope)&&s!==t));return await Promise.all(s.map((t=>self.caches.delete(t)))),s})(s).then((t=>{})))}))},t.createHandlerBoundToURL=function(t){return d().createHandlerBoundToURL(t)},t.getCacheKeyForURL=function(t){return d().getCacheKeyForURL(t)},t.matchPrecache=function(t){return d().matchPrecache(t)},t.precache=R,t.precacheAndRoute=function(t,e){R(t),p(e)},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core,workbox.strategies,workbox.routing,workbox.routing); | ||
this.workbox=this.workbox||{},this.workbox.precaching=function(t,e,s,n,i,c,r,o){"use strict";try{self["workbox:precaching:6.3.0"]&&_()}catch(t){}function a(t){if(!t)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if("string"==typeof t){const e=new URL(t,location.href);return{cacheKey:e.href,url:e.href}}const{revision:e,url:n}=t;if(!n)throw new s.WorkboxError("add-to-cache-list-unexpected-type",{entry:t});if(!e){const t=new URL(n,location.href);return{cacheKey:t.href,url:t.href}}const i=new URL(n,location.href),c=new URL(n,location.href);return i.searchParams.set("__WB_REVISION__",e),{cacheKey:i.href,url:c.href}}class h{constructor(){this.updatedURLs=[],this.notUpdatedURLs=[],this.handlerWillStart=async({request:t,state:e})=>{e&&(e.originalRequest=t)},this.cachedResponseWillBeUsed=async({event:t,state:e,cachedResponse:s})=>{if("install"===t.type&&e&&e.originalRequest&&e.originalRequest instanceof Request){const t=e.originalRequest.url;s?this.notUpdatedURLs.push(t):this.updatedURLs.push(t)}return s}}}class l{constructor({precacheController:t}){this.cacheKeyWillBeUsed=async({request:t,params:e})=>{const s=(null==e?void 0:e.cacheKey)||this.Z.getCacheKeyForURL(t.url);return s?new Request(s,{headers:t.headers}):t},this.Z=t}}class u extends c.Strategy{constructor(t={}){t.cacheName=e.cacheNames.getPrecacheName(t.cacheName),super(t),this.tt=!1!==t.fallbackToNetwork,this.plugins.push(u.copyRedirectedCacheableResponsesPlugin)}async _handle(t,e){const s=await e.cacheMatch(t);return s||(e.event&&"install"===e.event.type?await this.et(t,e):await this.st(t,e))}async st(t,e){let n;const i=e.params||{};if(!this.tt)throw new s.WorkboxError("missing-precache-entry",{cacheName:this.cacheName,url:t.url});{const s=i.integrity,c=t.integrity,r=!c||c===s;n=await e.fetch(new Request(t,{integrity:c||s})),s&&r&&(this.nt(),await e.cachePut(t,n.clone()))}return n}async et(t,e){this.nt();const n=await e.fetch(t);if(!await e.cachePut(t,n.clone()))throw new s.WorkboxError("bad-precaching-response",{url:t.url,status:n.status});return n}nt(){let t=null,e=0;for(const[s,n]of this.plugins.entries())n!==u.copyRedirectedCacheableResponsesPlugin&&(n===u.defaultPrecacheCacheabilityPlugin&&(t=s),n.cacheWillUpdate&&e++);0===e?this.plugins.push(u.defaultPrecacheCacheabilityPlugin):e>1&&null!==t&&this.plugins.splice(t,1)}}u.defaultPrecacheCacheabilityPlugin={cacheWillUpdate:async({response:t})=>!t||t.status>=400?null:t},u.copyRedirectedCacheableResponsesPlugin={cacheWillUpdate:async({response:t})=>t.redirected?await i.copyResponse(t):t};class f{constructor({cacheName:t,plugins:s=[],fallbackToNetwork:n=!0}={}){this.it=new Map,this.ct=new Map,this.rt=new Map,this.ot=new u({cacheName:e.cacheNames.getPrecacheName(t),plugins:[...s,new l({precacheController:this})],fallbackToNetwork:n}),this.install=this.install.bind(this),this.activate=this.activate.bind(this)}get strategy(){return this.ot}precache(t){this.addToCacheList(t),this.at||(self.addEventListener("install",this.install),self.addEventListener("activate",this.activate),this.at=!0)}addToCacheList(t){const e=[];for(const n of t){"string"==typeof n?e.push(n):n&&void 0===n.revision&&e.push(n.url);const{cacheKey:t,url:i}=a(n),c="string"!=typeof n&&n.revision?"reload":"default";if(this.it.has(i)&&this.it.get(i)!==t)throw new s.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:this.it.get(i),secondEntry:t});if("string"!=typeof n&&n.integrity){if(this.rt.has(t)&&this.rt.get(t)!==n.integrity)throw new s.WorkboxError("add-to-cache-list-conflicting-integrities",{url:i});this.rt.set(t,n.integrity)}if(this.it.set(i,t),this.ct.set(i,c),e.length>0){const t=`Workbox is precaching URLs without revision info: ${e.join(", ")}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;console.warn(t)}}}install(t){return n.waitUntil(t,(async()=>{const e=new h;this.strategy.plugins.push(e);for(const[e,s]of this.it){const n=this.rt.get(s),i=this.ct.get(e),c=new Request(e,{integrity:n,cache:i,credentials:"same-origin"});await Promise.all(this.strategy.handleAll({params:{cacheKey:s},request:c,event:t}))}const{updatedURLs:s,notUpdatedURLs:n}=e;return{updatedURLs:s,notUpdatedURLs:n}}))}activate(t){return n.waitUntil(t,(async()=>{const t=await self.caches.open(this.strategy.cacheName),e=await t.keys(),s=new Set(this.it.values()),n=[];for(const i of e)s.has(i.url)||(await t.delete(i),n.push(i.url));return{deletedURLs:n}}))}getURLsToCacheKeys(){return this.it}getCachedURLs(){return[...this.it.keys()]}getCacheKeyForURL(t){const e=new URL(t,location.href);return this.it.get(e.href)}getIntegrityForCacheKey(t){return this.rt.get(t)}async matchPrecache(t){const e=t instanceof Request?t.url:t,s=this.getCacheKeyForURL(e);if(s){return(await self.caches.open(this.strategy.cacheName)).match(s)}}createHandlerBoundToURL(t){const e=this.getCacheKeyForURL(t);if(!e)throw new s.WorkboxError("non-precached-url",{url:t});return s=>(s.request=new Request(t),s.params=Object.assign({cacheKey:e},s.params),this.strategy.handle(s))}}let w;const d=()=>(w||(w=new f),w);class y extends o.Route{constructor(t,e){super((({request:s})=>{const n=t.getURLsToCacheKeys();for(const i of function*(t,{ignoreURLParametersMatching:e=[/^utm_/,/^fbclid$/],directoryIndex:s="index.html",cleanURLs:n=!0,urlManipulation:i}={}){const c=new URL(t,location.href);c.hash="",yield c.href;const r=function(t,e=[]){for(const s of[...t.searchParams.keys()])e.some((t=>t.test(s)))&&t.searchParams.delete(s);return t}(c,e);if(yield r.href,s&&r.pathname.endsWith("/")){const t=new URL(r.href);t.pathname+=s,yield t.href}if(n){const t=new URL(r.href);t.pathname+=".html",yield t.href}if(i){const t=i({url:c});for(const e of t)yield e.href}}(s.url,e)){const e=n.get(i);if(e){return{cacheKey:e,integrity:t.getIntegrityForCacheKey(e)}}}}),t.strategy)}}function p(t){const e=d(),s=new y(e,t);r.registerRoute(s)}function R(t){d().precache(t)}return t.PrecacheController=f,t.PrecacheFallbackPlugin=class{constructor({fallbackURL:t,precacheController:e}){this.handlerDidError=()=>this.Z.matchPrecache(this.ht),this.ht=t,this.Z=e||d()}},t.PrecacheRoute=y,t.PrecacheStrategy=u,t.addPlugins=function(t){d().strategy.plugins.push(...t)},t.addRoute=p,t.cleanupOutdatedCaches=function(){self.addEventListener("activate",(t=>{const s=e.cacheNames.getPrecacheName();t.waitUntil((async(t,e="-precache-")=>{const s=(await self.caches.keys()).filter((s=>s.includes(e)&&s.includes(self.registration.scope)&&s!==t));return await Promise.all(s.map((t=>self.caches.delete(t)))),s})(s).then((t=>{})))}))},t.createHandlerBoundToURL=function(t){return d().createHandlerBoundToURL(t)},t.getCacheKeyForURL=function(t){return d().getCacheKeyForURL(t)},t.matchPrecache=function(t){return d().matchPrecache(t)},t.precache=R,t.precacheAndRoute=function(t,e){R(t),p(e)},t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core,workbox.strategies,workbox.routing,workbox.routing); | ||
//# sourceMappingURL=workbox-precaching.prod.js.map |
@@ -27,1 +27,2 @@ import { addPlugins } from './addPlugins.js'; | ||
export { addPlugins, addRoute, cleanupOutdatedCaches, createHandlerBoundToURL, getCacheKeyForURL, matchPrecache, precache, precacheAndRoute, PrecacheController, PrecacheRoute, PrecacheStrategy, PrecacheFallbackPlugin, }; | ||
export * from './_types.js'; |
@@ -34,1 +34,2 @@ /* | ||
export { addPlugins, addRoute, cleanupOutdatedCaches, createHandlerBoundToURL, getCacheKeyForURL, matchPrecache, precache, precacheAndRoute, PrecacheController, PrecacheRoute, PrecacheStrategy, PrecacheFallbackPlugin, }; | ||
export * from './_types.js'; |
{ | ||
"name": "workbox-precaching", | ||
"version": "6.3.0", | ||
"version": "6.4.0", | ||
"license": "MIT", | ||
@@ -24,7 +24,7 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "6.3.0", | ||
"workbox-routing": "6.3.0", | ||
"workbox-strategies": "6.3.0" | ||
"workbox-core": "6.4.0", | ||
"workbox-routing": "6.4.0", | ||
"workbox-strategies": "6.4.0" | ||
}, | ||
"gitHead": "03055e64014a46f6cc977a3a50ad814c6409d36a" | ||
"gitHead": "cdad230c678a3626c217615d5792eb0f1c77194c" | ||
} |
@@ -36,3 +36,3 @@ import { Strategy } from 'workbox-strategies/Strategy.js'; | ||
*/ | ||
constructor({ cacheName, plugins, fallbackToNetwork }?: PrecacheControllerOptions); | ||
constructor({ cacheName, plugins, fallbackToNetwork, }?: PrecacheControllerOptions); | ||
/** | ||
@@ -39,0 +39,0 @@ * @type {module:workbox-precaching.PrecacheStrategy} The strategy created by this controller and |
@@ -36,3 +36,3 @@ /* | ||
*/ | ||
constructor({ cacheName, plugins = [], fallbackToNetwork = true } = {}) { | ||
constructor({ cacheName, plugins = [], fallbackToNetwork = true, } = {}) { | ||
this._urlsToCacheKeys = new Map(); | ||
@@ -104,4 +104,3 @@ this._urlsToCacheModes = new Map(); | ||
const { cacheKey, url } = createCacheKey(entry); | ||
const cacheMode = (typeof entry !== 'string' && entry.revision) ? | ||
'reload' : 'default'; | ||
const cacheMode = typeof entry !== 'string' && entry.revision ? 'reload' : 'default'; | ||
if (this._urlsToCacheKeys.has(url) && | ||
@@ -108,0 +107,0 @@ this._urlsToCacheKeys.get(url) !== cacheKey) { |
@@ -31,3 +31,3 @@ import { WorkboxPlugin } from 'workbox-core/types.js'; | ||
*/ | ||
constructor({ fallbackURL, precacheController }: { | ||
constructor({ fallbackURL, precacheController, }: { | ||
fallbackURL: string; | ||
@@ -34,0 +34,0 @@ precacheController?: PrecacheController; |
@@ -35,3 +35,3 @@ /* | ||
*/ | ||
constructor({ fallbackURL, precacheController }) { | ||
constructor({ fallbackURL, precacheController, }) { | ||
/** | ||
@@ -44,6 +44,6 @@ * @return {Promise<Response>} The precache response for the fallback URL. | ||
this._fallbackURL = fallbackURL; | ||
this._precacheController = precacheController || | ||
getOrCreatePrecacheController(); | ||
this._precacheController = | ||
precacheController || getOrCreatePrecacheController(); | ||
} | ||
} | ||
export { PrecacheFallbackPlugin }; |
@@ -40,3 +40,3 @@ /* | ||
constructor(precacheController, options) { | ||
const match = ({ request }) => { | ||
const match = ({ request, }) => { | ||
const urlsToCacheKeys = precacheController.getURLsToCacheKeys(); | ||
@@ -51,4 +51,3 @@ for (const possibleURL of generateURLVariations(request.url, options)) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.debug(`Precaching did not find a match for ` + | ||
getFriendlyURL(request.url)); | ||
logger.debug(`Precaching did not find a match for ` + getFriendlyURL(request.url)); | ||
} | ||
@@ -55,0 +54,0 @@ return; |
@@ -25,2 +25,3 @@ /* | ||
} | ||
export interface PrecacheRouteOptions { | ||
@@ -27,0 +28,0 @@ directoryIndex?: string; |
// @ts-ignore | ||
try{self['workbox:precaching:6.3.0']&&_()}catch(e){} | ||
try{self['workbox:precaching:6.4.0']&&_()}catch(e){} |
@@ -13,3 +13,2 @@ /* | ||
/** | ||
@@ -16,0 +15,0 @@ * Adds plugins to the precaching strategy. |
@@ -1,2 +0,1 @@ | ||
/* | ||
@@ -17,3 +16,2 @@ Copyright 2019 Google LLC | ||
/** | ||
@@ -41,2 +39,2 @@ * Add a `fetch` listener to the service worker that will | ||
export {addRoute} | ||
export {addRoute}; |
@@ -14,3 +14,2 @@ /* | ||
/** | ||
@@ -27,13 +26,18 @@ * Adds an `activate` event listener which will clean up incompatible | ||
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); | ||
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} | ||
export {cleanupOutdatedCaches}; |
@@ -35,2 +35,2 @@ /* | ||
export {createHandlerBoundToURL} | ||
export {createHandlerBoundToURL}; |
@@ -12,3 +12,2 @@ /* | ||
/** | ||
@@ -38,2 +37,2 @@ * Takes in a URL, and returns the corresponding URL that could be used to | ||
export {getCacheKeyForURL} | ||
export {getCacheKeyForURL}; |
@@ -51,1 +51,3 @@ /* | ||
}; | ||
export * from './_types.js'; |
@@ -28,3 +28,5 @@ /* | ||
*/ | ||
function matchPrecache(request: string | Request): Promise<Response | undefined> { | ||
function matchPrecache( | ||
request: string | Request, | ||
): Promise<Response | undefined> { | ||
const precacheController = getOrCreatePrecacheController(); | ||
@@ -34,2 +36,2 @@ return precacheController.matchPrecache(request); | ||
export {matchPrecache} | ||
export {matchPrecache}; |
@@ -13,3 +13,2 @@ /* | ||
/** | ||
@@ -39,2 +38,2 @@ * Adds items to the precache list, removing any duplicates and | ||
export {precache} | ||
export {precache}; |
@@ -14,3 +14,2 @@ /* | ||
/** | ||
@@ -30,3 +29,6 @@ * This method will add entries to the precache list and add a route to | ||
*/ | ||
function precacheAndRoute(entries: Array<PrecacheEntry | string>, options?: PrecacheRouteOptions): void { | ||
function precacheAndRoute( | ||
entries: Array<PrecacheEntry | string>, | ||
options?: PrecacheRouteOptions, | ||
): void { | ||
precache(entries); | ||
@@ -36,2 +38,2 @@ addRoute(options); | ||
export {precacheAndRoute} | ||
export {precacheAndRoute}; |
@@ -26,3 +26,2 @@ /* | ||
// Give TypeScript the correct global. | ||
@@ -33,3 +32,3 @@ declare let self: ServiceWorkerGlobalScope; | ||
interface ServiceWorkerGlobalScope { | ||
__WB_MANIFEST: Array<PrecacheEntry|string>; | ||
__WB_MANIFEST: Array<PrecacheEntry | string>; | ||
} | ||
@@ -53,3 +52,11 @@ } | ||
private readonly _urlsToCacheKeys: Map<string, string> = new Map(); | ||
private readonly _urlsToCacheModes: Map<string, "reload" | "default" | "no-store" | "no-cache" | "force-cache" | "only-if-cached"> = new Map(); | ||
private readonly _urlsToCacheModes: Map< | ||
string, | ||
| 'reload' | ||
| 'default' | ||
| 'no-store' | ||
| 'no-cache' | ||
| 'force-cache' | ||
| 'only-if-cached' | ||
> = new Map(); | ||
private readonly _cacheKeysToIntegrities: Map<string, string> = new Map(); | ||
@@ -67,3 +74,7 @@ | ||
*/ | ||
constructor({cacheName, plugins = [], fallbackToNetwork = true}: PrecacheControllerOptions = {}) { | ||
constructor({ | ||
cacheName, | ||
plugins = [], | ||
fallbackToNetwork = true, | ||
}: PrecacheControllerOptions = {}) { | ||
this._strategy = new PrecacheStrategy({ | ||
@@ -138,7 +149,9 @@ cacheName: cacheNames.getPrecacheName(cacheName), | ||
const {cacheKey, url} = createCacheKey(entry); | ||
const cacheMode = (typeof entry !== 'string' && entry.revision) ? | ||
'reload' : 'default'; | ||
const cacheMode = | ||
typeof entry !== 'string' && entry.revision ? 'reload' : 'default'; | ||
if (this._urlsToCacheKeys.has(url) && | ||
this._urlsToCacheKeys.get(url) !== cacheKey) { | ||
if ( | ||
this._urlsToCacheKeys.has(url) && | ||
this._urlsToCacheKeys.get(url) !== cacheKey | ||
) { | ||
throw new WorkboxError('add-to-cache-list-conflicting-entries', { | ||
@@ -151,4 +164,6 @@ firstEntry: this._urlsToCacheKeys.get(url), | ||
if (typeof entry !== 'string' && entry.integrity) { | ||
if (this._cacheKeysToIntegrities.has(cacheKey) && | ||
this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) { | ||
if ( | ||
this._cacheKeysToIntegrities.has(cacheKey) && | ||
this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity | ||
) { | ||
throw new WorkboxError('add-to-cache-list-conflicting-integrities', { | ||
@@ -165,3 +180,4 @@ url, | ||
if (urlsToWarnAbout.length > 0) { | ||
const warningMessage = `Workbox is precaching URLs without revision ` + | ||
const warningMessage = | ||
`Workbox is precaching URLs without revision ` + | ||
`info: ${urlsToWarnAbout.join(', ')}\nThis is generally NOT safe. ` + | ||
@@ -209,7 +225,9 @@ `Learn more at https://bit.ly/wb-precache`; | ||
await Promise.all(this.strategy.handleAll({ | ||
params: {cacheKey}, | ||
request, | ||
event, | ||
})); | ||
await Promise.all( | ||
this.strategy.handleAll({ | ||
params: {cacheKey}, | ||
request, | ||
event, | ||
}), | ||
); | ||
} | ||
@@ -322,3 +340,5 @@ | ||
*/ | ||
async matchPrecache(request: string|Request): Promise<Response|undefined> { | ||
async matchPrecache( | ||
request: string | Request, | ||
): Promise<Response | undefined> { | ||
const url = request instanceof Request ? request.url : request; | ||
@@ -325,0 +345,0 @@ const cacheKey = this.getCacheKeyForURL(url); |
@@ -11,4 +11,3 @@ /* | ||
import {getOrCreatePrecacheController} from | ||
'./utils/getOrCreatePrecacheController.js'; | ||
import {getOrCreatePrecacheController} from './utils/getOrCreatePrecacheController.js'; | ||
import {PrecacheController} from './PrecacheController.js'; | ||
@@ -18,3 +17,2 @@ | ||
/** | ||
@@ -27,3 +25,3 @@ * `PrecacheFallbackPlugin` allows you to specify an "offline fallback" | ||
* into account automatically. | ||
* | ||
* | ||
* Unless you explicitly pass in a `PrecacheController` instance to the | ||
@@ -49,3 +47,6 @@ * constructor, the default instance will be used. Generally speaking, most | ||
*/ | ||
constructor({fallbackURL, precacheController}: { | ||
constructor({ | ||
fallbackURL, | ||
precacheController, | ||
}: { | ||
fallbackURL: string; | ||
@@ -55,4 +56,4 @@ precacheController?: PrecacheController; | ||
this._fallbackURL = fallbackURL; | ||
this._precacheController = precacheController || | ||
getOrCreatePrecacheController(); | ||
this._precacheController = | ||
precacheController || getOrCreatePrecacheController(); | ||
} | ||
@@ -65,6 +66,6 @@ | ||
*/ | ||
handlerDidError: WorkboxPlugin['handlerDidError'] = | ||
() => this._precacheController.matchPrecache(this._fallbackURL); | ||
handlerDidError: WorkboxPlugin['handlerDidError'] = () => | ||
this._precacheController.matchPrecache(this._fallbackURL); | ||
} | ||
export {PrecacheFallbackPlugin}; |
@@ -11,3 +11,6 @@ /* | ||
import {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.js'; | ||
import {RouteMatchCallback, RouteMatchCallbackOptions} from 'workbox-core/types.js'; | ||
import { | ||
RouteMatchCallback, | ||
RouteMatchCallbackOptions, | ||
} from 'workbox-core/types.js'; | ||
import {Route} from 'workbox-routing/Route.js'; | ||
@@ -21,3 +24,2 @@ | ||
/** | ||
@@ -49,4 +51,9 @@ * A subclass of [Route]{@link module:workbox-routing.Route} that takes a | ||
*/ | ||
constructor(precacheController: PrecacheController, options?: PrecacheRouteOptions) { | ||
const match: RouteMatchCallback = ({request}: RouteMatchCallbackOptions) => { | ||
constructor( | ||
precacheController: PrecacheController, | ||
options?: PrecacheRouteOptions, | ||
) { | ||
const match: RouteMatchCallback = ({ | ||
request, | ||
}: RouteMatchCallbackOptions) => { | ||
const urlsToCacheKeys = precacheController.getURLsToCacheKeys(); | ||
@@ -56,3 +63,4 @@ for (const possibleURL of generateURLVariations(request.url, options)) { | ||
if (cacheKey) { | ||
const integrity = precacheController.getIntegrityForCacheKey(cacheKey); | ||
const integrity = | ||
precacheController.getIntegrityForCacheKey(cacheKey); | ||
return {cacheKey, integrity}; | ||
@@ -62,7 +70,8 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.debug(`Precaching did not find a match for ` + | ||
getFriendlyURL(request.url)); | ||
logger.debug( | ||
`Precaching did not find a match for ` + getFriendlyURL(request.url), | ||
); | ||
} | ||
return; | ||
} | ||
}; | ||
@@ -69,0 +78,0 @@ super(match, precacheController.strategy); |
@@ -13,3 +13,2 @@ /* | ||
interface CacheKey { | ||
@@ -32,3 +31,3 @@ cacheKey: string; | ||
*/ | ||
export function createCacheKey(entry: PrecacheEntry | string): CacheKey { | ||
export function createCacheKey(entry: PrecacheEntry | string): CacheKey { | ||
if (!entry) { | ||
@@ -35,0 +34,0 @@ throw new WorkboxError('add-to-cache-list-unexpected-type', {entry}); |
@@ -11,3 +11,2 @@ /* | ||
// Give TypeScript the correct global. | ||
@@ -37,14 +36,18 @@ declare let self: ServiceWorkerGlobalScope; | ||
const deleteOutdatedCaches = async ( | ||
currentPrecacheName: string, | ||
substringToFind: string = SUBSTRING_TO_FIND): Promise<string[]> => { | ||
currentPrecacheName: string, | ||
substringToFind: string = SUBSTRING_TO_FIND, | ||
): Promise<string[]> => { | ||
const cacheNames = await self.caches.keys(); | ||
const cacheNamesToDelete = cacheNames.filter((cacheName) => { | ||
return cacheName.includes(substringToFind) && | ||
cacheName.includes(self.registration.scope) && | ||
cacheName !== currentPrecacheName; | ||
return ( | ||
cacheName.includes(substringToFind) && | ||
cacheName.includes(self.registration.scope) && | ||
cacheName !== currentPrecacheName | ||
); | ||
}); | ||
await Promise.all( | ||
cacheNamesToDelete.map((cacheName) => self.caches.delete(cacheName))); | ||
cacheNamesToDelete.map((cacheName) => self.caches.delete(cacheName)), | ||
); | ||
@@ -55,2 +58,1 @@ return cacheNamesToDelete; | ||
export {deleteOutdatedCaches}; | ||
@@ -13,3 +13,2 @@ /* | ||
/** | ||
@@ -25,8 +24,11 @@ * Generator function that yields possible variations on the original URL to | ||
*/ | ||
export function* generateURLVariations(url: string, { | ||
ignoreURLParametersMatching = [/^utm_/, /^fbclid$/], | ||
directoryIndex = 'index.html', | ||
cleanURLs = true, | ||
urlManipulation, | ||
}: PrecacheRouteOptions = {}): Generator<string, void, unknown> { | ||
export function* generateURLVariations( | ||
url: string, | ||
{ | ||
ignoreURLParametersMatching = [/^utm_/, /^fbclid$/], | ||
directoryIndex = 'index.html', | ||
cleanURLs = true, | ||
urlManipulation, | ||
}: PrecacheRouteOptions = {}, | ||
): Generator<string, void, unknown> { | ||
const urlObject = new URL(url, location.href); | ||
@@ -36,4 +38,6 @@ urlObject.hash = ''; | ||
const urlWithoutIgnoredParams = | ||
removeIgnoredSearchParams(urlObject, ignoreURLParametersMatching); | ||
const urlWithoutIgnoredParams = removeIgnoredSearchParams( | ||
urlObject, | ||
ignoreURLParametersMatching, | ||
); | ||
yield urlWithoutIgnoredParams.href; | ||
@@ -40,0 +44,0 @@ |
@@ -14,3 +14,2 @@ /* | ||
/** | ||
@@ -27,4 +26,6 @@ * This function will take the request URL and manipulate it based on the | ||
*/ | ||
export const getCacheKeyForURL = | ||
(url: string, options: PrecacheRouteOptions): string | void => { | ||
export const getCacheKeyForURL = ( | ||
url: string, | ||
options: PrecacheRouteOptions, | ||
): string | void => { | ||
const precacheController = getOrCreatePrecacheController(); | ||
@@ -31,0 +32,0 @@ |
@@ -12,3 +12,2 @@ /* | ||
let precacheController: PrecacheController | undefined; | ||
@@ -15,0 +14,0 @@ |
@@ -13,3 +13,2 @@ /* | ||
/** | ||
@@ -33,3 +32,3 @@ * A plugin, designed to be used with PrecacheController, to determine the | ||
} | ||
} | ||
}; | ||
@@ -42,5 +41,8 @@ cachedResponseWillBeUsed: WorkboxPlugin['cachedResponseWillBeUsed'] = async ({ | ||
if (event.type === 'install') { | ||
if (state && state.originalRequest | ||
&& state.originalRequest instanceof Request) { | ||
// TODO: `state` should never be undefined... | ||
if ( | ||
state && | ||
state.originalRequest && | ||
state.originalRequest instanceof Request | ||
) { | ||
// TODO: `state` should never be undefined... | ||
const url = state.originalRequest.url; | ||
@@ -56,5 +58,5 @@ | ||
return cachedResponse; | ||
} | ||
}; | ||
} | ||
export {PrecacheInstallReportPlugin}; |
@@ -12,3 +12,2 @@ /* | ||
/** | ||
@@ -39,5 +38,7 @@ * @param {string} groupTitle | ||
if (deletionCount > 0) { | ||
logger.groupCollapsed(`During precaching cleanup, ` + | ||
logger.groupCollapsed( | ||
`During precaching cleanup, ` + | ||
`${deletionCount} cached ` + | ||
`request${deletionCount === 1 ? ' was' : 's were'} deleted.`); | ||
`request${deletionCount === 1 ? ' was' : 's were'} deleted.`, | ||
); | ||
logGroup('Deleted Cache Requests', deletedURLs); | ||
@@ -44,0 +45,0 @@ logger.groupEnd(); |
@@ -12,3 +12,2 @@ /* | ||
/** | ||
@@ -41,3 +40,6 @@ * @param {string} groupTitle | ||
*/ | ||
export function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void { | ||
export function printInstallDetails( | ||
urlsToPrecache: string[], | ||
urlsAlreadyPrecached: string[], | ||
): void { | ||
const precachedCount = urlsToPrecache.length; | ||
@@ -47,7 +49,9 @@ const alreadyPrecachedCount = urlsAlreadyPrecached.length; | ||
if (precachedCount || alreadyPrecachedCount) { | ||
let message = | ||
`Precaching ${precachedCount} file${precachedCount === 1 ? '' : 's'}.`; | ||
let message = `Precaching ${precachedCount} file${ | ||
precachedCount === 1 ? '' : 's' | ||
}.`; | ||
if (alreadyPrecachedCount > 0) { | ||
message += ` ${alreadyPrecachedCount} ` + | ||
message += | ||
` ${alreadyPrecachedCount} ` + | ||
`file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`; | ||
@@ -54,0 +58,0 @@ } |
@@ -24,3 +24,5 @@ /* | ||
export function removeIgnoredSearchParams( | ||
urlObject: URL, ignoreURLParametersMatching: RegExp[] = []): URL { | ||
urlObject: URL, | ||
ignoreURLParametersMatching: RegExp[] = [], | ||
): URL { | ||
// Convert the iterable into an array at the start of the loop to make sure | ||
@@ -27,0 +29,0 @@ // deletion doesn't mess up iteration. |
@@ -8,10 +8,8 @@ { | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"include": ["src/**/*.ts"], | ||
"references": [ | ||
{ "path": "../workbox-core/" }, | ||
{ "path": "../workbox-routing/" }, | ||
{ "path": "../workbox-strategies/" } | ||
{"path": "../workbox-core/"}, | ||
{"path": "../workbox-routing/"}, | ||
{"path": "../workbox-strategies/"} | ||
] | ||
} |
@@ -31,5 +31,5 @@ /* | ||
const cacheNamesToDelete = cacheNames.filter((cacheName) => { | ||
return cacheName.includes(substringToFind) && | ||
return (cacheName.includes(substringToFind) && | ||
cacheName.includes(self.registration.scope) && | ||
cacheName !== currentPrecacheName; | ||
cacheName !== currentPrecacheName); | ||
}); | ||
@@ -36,0 +36,0 @@ await Promise.all(cacheNamesToDelete.map((cacheName) => self.caches.delete(cacheName))); |
@@ -27,4 +27,5 @@ /* | ||
if (event.type === 'install') { | ||
if (state && state.originalRequest | ||
&& state.originalRequest instanceof Request) { | ||
if (state && | ||
state.originalRequest && | ||
state.originalRequest instanceof Request) { | ||
// TODO: `state` should never be undefined... | ||
@@ -31,0 +32,0 @@ const url = state.originalRequest.url; |
@@ -39,4 +39,5 @@ /* | ||
if (alreadyPrecachedCount > 0) { | ||
message += ` ${alreadyPrecachedCount} ` + | ||
`file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`; | ||
message += | ||
` ${alreadyPrecachedCount} ` + | ||
`file${alreadyPrecachedCount === 1 ? ' is' : 's are'} already cached.`; | ||
} | ||
@@ -43,0 +44,0 @@ logger.groupCollapsed(message); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 3 instances in 1 package
4625
343701
+ Addedworkbox-core@6.4.0(transitive)
+ Addedworkbox-routing@6.4.0(transitive)
+ Addedworkbox-strategies@6.4.0(transitive)
- Removedworkbox-core@6.3.0(transitive)
- Removedworkbox-routing@6.3.0(transitive)
- Removedworkbox-strategies@6.3.0(transitive)
Updatedworkbox-core@6.4.0
Updatedworkbox-routing@6.4.0
Updatedworkbox-strategies@6.4.0