@serwist/precaching 9.0.0-preview.17 → 9.0.0-preview.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -155
- package/package.json +3 -17
- package/src/index.ts +5 -39
- package/dist/PrecacheController.d.ts +0 -146
- package/dist/PrecacheController.d.ts.map +0 -1
- package/dist/PrecacheFallbackPlugin.d.ts +0 -54
- package/dist/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/PrecacheRoute.d.ts +0 -20
- package/dist/PrecacheRoute.d.ts.map +0 -1
- package/dist/PrecacheStrategy.d.ts +0 -67
- package/dist/PrecacheStrategy.d.ts.map +0 -1
- package/dist/_types.d.ts +0 -37
- package/dist/_types.d.ts.map +0 -1
- package/dist/addPlugins.d.ts +0 -9
- package/dist/addPlugins.d.ts.map +0 -1
- package/dist/addRoute.d.ts +0 -15
- package/dist/addRoute.d.ts.map +0 -1
- package/dist/chunks/getOrCreatePrecacheController.js +0 -436
- package/dist/cleanupOutdatedCaches.d.ts +0 -6
- package/dist/cleanupOutdatedCaches.d.ts.map +0 -1
- package/dist/createHandlerBoundToURL.d.ts +0 -17
- package/dist/createHandlerBoundToURL.d.ts.map +0 -1
- package/dist/getCacheKeyForURL.d.ts +0 -20
- package/dist/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/index.internal.d.ts +0 -3
- package/dist/index.internal.d.ts.map +0 -1
- package/dist/index.internal.js +0 -4
- package/dist/matchPrecache.d.ts +0 -15
- package/dist/matchPrecache.d.ts.map +0 -1
- package/dist/precache.d.ts +0 -19
- package/dist/precache.d.ts.map +0 -1
- package/dist/precacheAndRoute.d.ts +0 -14
- package/dist/precacheAndRoute.d.ts.map +0 -1
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts +0 -17
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/utils/PrecacheInstallReportPlugin.d.ts +0 -15
- package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
- package/dist/utils/createCacheKey.d.ts +0 -16
- package/dist/utils/createCacheKey.d.ts.map +0 -1
- package/dist/utils/deleteOutdatedCaches.d.ts +0 -18
- package/dist/utils/deleteOutdatedCaches.d.ts.map +0 -1
- package/dist/utils/generateURLVariations.d.ts +0 -12
- package/dist/utils/generateURLVariations.d.ts.map +0 -1
- package/dist/utils/getCacheKeyForURL.d.ts +0 -14
- package/dist/utils/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/utils/getOrCreatePrecacheController.d.ts +0 -7
- package/dist/utils/getOrCreatePrecacheController.d.ts.map +0 -1
- package/dist/utils/printCleanupDetails.d.ts +0 -6
- package/dist/utils/printCleanupDetails.d.ts.map +0 -1
- package/dist/utils/printInstallDetails.d.ts +0 -7
- package/dist/utils/printInstallDetails.d.ts.map +0 -1
- package/dist/utils/removeIgnoredSearchParams.d.ts +0 -12
- package/dist/utils/removeIgnoredSearchParams.d.ts.map +0 -1
- package/src/PrecacheController.ts +0 -344
- package/src/PrecacheFallbackPlugin.ts +0 -86
- package/src/PrecacheRoute.ts +0 -50
- package/src/PrecacheStrategy.ts +0 -239
- package/src/_types.ts +0 -46
- package/src/addPlugins.ts +0 -23
- package/src/addRoute.ts +0 -31
- package/src/cleanupOutdatedCaches.ts +0 -33
- package/src/createHandlerBoundToURL.ts +0 -30
- package/src/getCacheKeyForURL.ts +0 -33
- package/src/index.internal.ts +0 -3
- package/src/matchPrecache.ts +0 -28
- package/src/precache.ts +0 -31
- package/src/precacheAndRoute.ts +0 -27
- package/src/utils/PrecacheCacheKeyPlugin.ts +0 -36
- package/src/utils/PrecacheInstallReportPlugin.ts +0 -49
- package/src/utils/createCacheKey.ts +0 -68
- package/src/utils/deleteOutdatedCaches.ts +0 -40
- package/src/utils/generateURLVariations.ts +0 -55
- package/src/utils/getCacheKeyForURL.ts +0 -36
- package/src/utils/getOrCreatePrecacheController.ts +0 -22
- package/src/utils/printCleanupDetails.ts +0 -38
- package/src/utils/printInstallDetails.ts +0 -53
- package/src/utils/removeIgnoredSearchParams.ts +0 -29
package/dist/addRoute.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PrecacheRouteOptions } from "./_types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Add a `fetch` listener to the service worker that will
|
|
4
|
-
* respond to
|
|
5
|
-
* [network requests](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests)
|
|
6
|
-
* with precached assets.
|
|
7
|
-
*
|
|
8
|
-
* Requests for assets that aren't precached, the `FetchEvent` will not be
|
|
9
|
-
* responded to, allowing the event to fall through to other `fetch` event
|
|
10
|
-
* listeners.
|
|
11
|
-
*
|
|
12
|
-
* @param options See the `@serwist/precaching.PrecacheRoute` options.
|
|
13
|
-
*/
|
|
14
|
-
export declare const addRoute: (options?: PrecacheRouteOptions) => void;
|
|
15
|
-
//# sourceMappingURL=addRoute.d.ts.map
|
package/dist/addRoute.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addRoute.d.ts","sourceRoot":"","sources":["../src/addRoute.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,aAAc,oBAAoB,KAAG,IAKzD,CAAC"}
|
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
import { privateCacheNames, logger, getFriendlyURL, SerwistError, assert, waitUntil } from '@serwist/core/internal';
|
|
2
|
-
import { copyResponse } from '@serwist/core';
|
|
3
|
-
import { Strategy } from '@serwist/strategies';
|
|
4
|
-
|
|
5
|
-
const parallel = async (limit, array, func)=>{
|
|
6
|
-
const work = array.map((item, index)=>({
|
|
7
|
-
index,
|
|
8
|
-
item
|
|
9
|
-
}));
|
|
10
|
-
const processor = async (res)=>{
|
|
11
|
-
const results = [];
|
|
12
|
-
while(true){
|
|
13
|
-
const next = work.pop();
|
|
14
|
-
if (!next) {
|
|
15
|
-
return res(results);
|
|
16
|
-
}
|
|
17
|
-
const result = await func(next.item);
|
|
18
|
-
results.push({
|
|
19
|
-
result: result,
|
|
20
|
-
index: next.index
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const queues = Array.from({
|
|
25
|
-
length: limit
|
|
26
|
-
}, ()=>new Promise(processor));
|
|
27
|
-
const results = (await Promise.all(queues)).flat().sort((a, b)=>a.index < b.index ? -1 : 1).map((res)=>res.result);
|
|
28
|
-
return results;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
class PrecacheStrategy extends Strategy {
|
|
32
|
-
_fallbackToNetwork;
|
|
33
|
-
static defaultPrecacheCacheabilityPlugin = {
|
|
34
|
-
async cacheWillUpdate ({ response }) {
|
|
35
|
-
if (!response || response.status >= 400) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return response;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
static copyRedirectedCacheableResponsesPlugin = {
|
|
42
|
-
async cacheWillUpdate ({ response }) {
|
|
43
|
-
return response.redirected ? await copyResponse(response) : response;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
constructor(options = {}){
|
|
47
|
-
options.cacheName = privateCacheNames.getPrecacheName(options.cacheName);
|
|
48
|
-
super(options);
|
|
49
|
-
this._fallbackToNetwork = options.fallbackToNetwork === false ? false : true;
|
|
50
|
-
this.plugins.push(PrecacheStrategy.copyRedirectedCacheableResponsesPlugin);
|
|
51
|
-
}
|
|
52
|
-
async _handle(request, handler) {
|
|
53
|
-
const response = await handler.cacheMatch(request);
|
|
54
|
-
if (response) {
|
|
55
|
-
return response;
|
|
56
|
-
}
|
|
57
|
-
if (handler.event && handler.event.type === "install") {
|
|
58
|
-
return await this._handleInstall(request, handler);
|
|
59
|
-
}
|
|
60
|
-
return await this._handleFetch(request, handler);
|
|
61
|
-
}
|
|
62
|
-
async _handleFetch(request, handler) {
|
|
63
|
-
let response = undefined;
|
|
64
|
-
const params = handler.params || {};
|
|
65
|
-
if (this._fallbackToNetwork) {
|
|
66
|
-
if (process.env.NODE_ENV !== "production") {
|
|
67
|
-
logger.warn(`The precached response for ${getFriendlyURL(request.url)} in ${this.cacheName} was not found. Falling back to the network.`);
|
|
68
|
-
}
|
|
69
|
-
const integrityInManifest = params.integrity;
|
|
70
|
-
const integrityInRequest = request.integrity;
|
|
71
|
-
const noIntegrityConflict = !integrityInRequest || integrityInRequest === integrityInManifest;
|
|
72
|
-
response = await handler.fetch(new Request(request, {
|
|
73
|
-
integrity: request.mode !== "no-cors" ? integrityInRequest || integrityInManifest : undefined
|
|
74
|
-
}));
|
|
75
|
-
if (integrityInManifest && noIntegrityConflict && request.mode !== "no-cors") {
|
|
76
|
-
this._useDefaultCacheabilityPluginIfNeeded();
|
|
77
|
-
const wasCached = await handler.cachePut(request, response.clone());
|
|
78
|
-
if (process.env.NODE_ENV !== "production") {
|
|
79
|
-
if (wasCached) {
|
|
80
|
-
logger.log(`A response for ${getFriendlyURL(request.url)} was used to "repair" the precache.`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
throw new SerwistError("missing-precache-entry", {
|
|
86
|
-
cacheName: this.cacheName,
|
|
87
|
-
url: request.url
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (process.env.NODE_ENV !== "production") {
|
|
91
|
-
const cacheKey = params.cacheKey || await handler.getCacheKey(request, "read");
|
|
92
|
-
logger.groupCollapsed(`Precaching is responding to: ${getFriendlyURL(request.url)}`);
|
|
93
|
-
logger.log(`Serving the precached url: ${getFriendlyURL(cacheKey instanceof Request ? cacheKey.url : cacheKey)}`);
|
|
94
|
-
logger.groupCollapsed("View request details here.");
|
|
95
|
-
logger.log(request);
|
|
96
|
-
logger.groupEnd();
|
|
97
|
-
logger.groupCollapsed("View response details here.");
|
|
98
|
-
logger.log(response);
|
|
99
|
-
logger.groupEnd();
|
|
100
|
-
logger.groupEnd();
|
|
101
|
-
}
|
|
102
|
-
return response;
|
|
103
|
-
}
|
|
104
|
-
async _handleInstall(request, handler) {
|
|
105
|
-
this._useDefaultCacheabilityPluginIfNeeded();
|
|
106
|
-
const response = await handler.fetch(request);
|
|
107
|
-
const wasCached = await handler.cachePut(request, response.clone());
|
|
108
|
-
if (!wasCached) {
|
|
109
|
-
throw new SerwistError("bad-precaching-response", {
|
|
110
|
-
url: request.url,
|
|
111
|
-
status: response.status
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return response;
|
|
115
|
-
}
|
|
116
|
-
_useDefaultCacheabilityPluginIfNeeded() {
|
|
117
|
-
let defaultPluginIndex = null;
|
|
118
|
-
let cacheWillUpdatePluginCount = 0;
|
|
119
|
-
for (const [index, plugin] of this.plugins.entries()){
|
|
120
|
-
if (plugin === PrecacheStrategy.copyRedirectedCacheableResponsesPlugin) {
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (plugin === PrecacheStrategy.defaultPrecacheCacheabilityPlugin) {
|
|
124
|
-
defaultPluginIndex = index;
|
|
125
|
-
}
|
|
126
|
-
if (plugin.cacheWillUpdate) {
|
|
127
|
-
cacheWillUpdatePluginCount++;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (cacheWillUpdatePluginCount === 0) {
|
|
131
|
-
this.plugins.push(PrecacheStrategy.defaultPrecacheCacheabilityPlugin);
|
|
132
|
-
} else if (cacheWillUpdatePluginCount > 1 && defaultPluginIndex !== null) {
|
|
133
|
-
this.plugins.splice(defaultPluginIndex, 1);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class PrecacheCacheKeyPlugin {
|
|
139
|
-
_precacheController;
|
|
140
|
-
constructor({ precacheController }){
|
|
141
|
-
this._precacheController = precacheController;
|
|
142
|
-
}
|
|
143
|
-
cacheKeyWillBeUsed = async ({ request, params })=>{
|
|
144
|
-
const cacheKey = params?.cacheKey || this._precacheController.getCacheKeyForURL(request.url);
|
|
145
|
-
return cacheKey ? new Request(cacheKey, {
|
|
146
|
-
headers: request.headers
|
|
147
|
-
}) : request;
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
class PrecacheInstallReportPlugin {
|
|
152
|
-
updatedURLs = [];
|
|
153
|
-
notUpdatedURLs = [];
|
|
154
|
-
handlerWillStart = async ({ request, state })=>{
|
|
155
|
-
if (state) {
|
|
156
|
-
state.originalRequest = request;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
cachedResponseWillBeUsed = async ({ event, state, cachedResponse })=>{
|
|
160
|
-
if (event.type === "install") {
|
|
161
|
-
if (state?.originalRequest && state.originalRequest instanceof Request) {
|
|
162
|
-
const url = state.originalRequest.url;
|
|
163
|
-
if (cachedResponse) {
|
|
164
|
-
this.notUpdatedURLs.push(url);
|
|
165
|
-
} else {
|
|
166
|
-
this.updatedURLs.push(url);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return cachedResponse;
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const REVISION_SEARCH_PARAM = "__WB_REVISION__";
|
|
175
|
-
function createCacheKey(entry) {
|
|
176
|
-
if (!entry) {
|
|
177
|
-
throw new SerwistError("add-to-cache-list-unexpected-type", {
|
|
178
|
-
entry
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
if (typeof entry === "string") {
|
|
182
|
-
const urlObject = new URL(entry, location.href);
|
|
183
|
-
return {
|
|
184
|
-
cacheKey: urlObject.href,
|
|
185
|
-
url: urlObject.href
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
const { revision, url } = entry;
|
|
189
|
-
if (!url) {
|
|
190
|
-
throw new SerwistError("add-to-cache-list-unexpected-type", {
|
|
191
|
-
entry
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
if (!revision) {
|
|
195
|
-
const urlObject = new URL(url, location.href);
|
|
196
|
-
return {
|
|
197
|
-
cacheKey: urlObject.href,
|
|
198
|
-
url: urlObject.href
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
const cacheKeyURL = new URL(url, location.href);
|
|
202
|
-
const originalURL = new URL(url, location.href);
|
|
203
|
-
cacheKeyURL.searchParams.set(REVISION_SEARCH_PARAM, revision);
|
|
204
|
-
return {
|
|
205
|
-
cacheKey: cacheKeyURL.href,
|
|
206
|
-
url: originalURL.href
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const logGroup = (groupTitle, deletedURLs)=>{
|
|
211
|
-
logger.groupCollapsed(groupTitle);
|
|
212
|
-
for (const url of deletedURLs){
|
|
213
|
-
logger.log(url);
|
|
214
|
-
}
|
|
215
|
-
logger.groupEnd();
|
|
216
|
-
};
|
|
217
|
-
function printCleanupDetails(deletedURLs) {
|
|
218
|
-
const deletionCount = deletedURLs.length;
|
|
219
|
-
if (deletionCount > 0) {
|
|
220
|
-
logger.groupCollapsed(`During precaching cleanup, ${deletionCount} cached request${deletionCount === 1 ? " was" : "s were"} deleted.`);
|
|
221
|
-
logGroup("Deleted Cache Requests", deletedURLs);
|
|
222
|
-
logger.groupEnd();
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function _nestedGroup(groupTitle, urls) {
|
|
227
|
-
if (urls.length === 0) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
logger.groupCollapsed(groupTitle);
|
|
231
|
-
for (const url of urls){
|
|
232
|
-
logger.log(url);
|
|
233
|
-
}
|
|
234
|
-
logger.groupEnd();
|
|
235
|
-
}
|
|
236
|
-
function printInstallDetails(urlsToPrecache, urlsAlreadyPrecached) {
|
|
237
|
-
const precachedCount = urlsToPrecache.length;
|
|
238
|
-
const alreadyPrecachedCount = urlsAlreadyPrecached.length;
|
|
239
|
-
if (precachedCount || alreadyPrecachedCount) {
|
|
240
|
-
let message = `Precaching ${precachedCount} file${precachedCount === 1 ? "" : "s"}.`;
|
|
241
|
-
if (alreadyPrecachedCount > 0) {
|
|
242
|
-
message += ` ${alreadyPrecachedCount} ` + `file${alreadyPrecachedCount === 1 ? " is" : "s are"} already cached.`;
|
|
243
|
-
}
|
|
244
|
-
logger.groupCollapsed(message);
|
|
245
|
-
_nestedGroup("View newly precached URLs.", urlsToPrecache);
|
|
246
|
-
_nestedGroup("View previously precached URLs.", urlsAlreadyPrecached);
|
|
247
|
-
logger.groupEnd();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
class PrecacheController {
|
|
252
|
-
_installAndActiveListenersAdded;
|
|
253
|
-
_concurrentPrecaching;
|
|
254
|
-
_strategy;
|
|
255
|
-
_urlsToCacheKeys = new Map();
|
|
256
|
-
_urlsToCacheModes = new Map();
|
|
257
|
-
_cacheKeysToIntegrities = new Map();
|
|
258
|
-
constructor({ cacheName, plugins = [], fallbackToNetwork = true, concurrentPrecaching } = {}){
|
|
259
|
-
this._strategy = new PrecacheStrategy({
|
|
260
|
-
cacheName: privateCacheNames.getPrecacheName(cacheName),
|
|
261
|
-
plugins: [
|
|
262
|
-
...plugins,
|
|
263
|
-
new PrecacheCacheKeyPlugin({
|
|
264
|
-
precacheController: this
|
|
265
|
-
})
|
|
266
|
-
],
|
|
267
|
-
fallbackToNetwork
|
|
268
|
-
});
|
|
269
|
-
this._concurrentPrecaching = concurrentPrecaching;
|
|
270
|
-
this.install = this.install.bind(this);
|
|
271
|
-
this.activate = this.activate.bind(this);
|
|
272
|
-
}
|
|
273
|
-
get strategy() {
|
|
274
|
-
return this._strategy;
|
|
275
|
-
}
|
|
276
|
-
precache(entries) {
|
|
277
|
-
this.addToCacheList(entries);
|
|
278
|
-
if (!this._installAndActiveListenersAdded) {
|
|
279
|
-
self.addEventListener("install", this.install);
|
|
280
|
-
self.addEventListener("activate", this.activate);
|
|
281
|
-
this._installAndActiveListenersAdded = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
addToCacheList(entries) {
|
|
285
|
-
if (process.env.NODE_ENV !== "production") {
|
|
286
|
-
assert.isArray(entries, {
|
|
287
|
-
moduleName: "@serwist/precaching",
|
|
288
|
-
className: "PrecacheController",
|
|
289
|
-
funcName: "addToCacheList",
|
|
290
|
-
paramName: "entries"
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
const urlsToWarnAbout = [];
|
|
294
|
-
for (const entry of entries){
|
|
295
|
-
if (typeof entry === "string") {
|
|
296
|
-
urlsToWarnAbout.push(entry);
|
|
297
|
-
} else if (entry && !entry.integrity && entry.revision === undefined) {
|
|
298
|
-
urlsToWarnAbout.push(entry.url);
|
|
299
|
-
}
|
|
300
|
-
const { cacheKey, url } = createCacheKey(entry);
|
|
301
|
-
const cacheMode = typeof entry !== "string" && entry.revision ? "reload" : "default";
|
|
302
|
-
if (this._urlsToCacheKeys.has(url) && this._urlsToCacheKeys.get(url) !== cacheKey) {
|
|
303
|
-
throw new SerwistError("add-to-cache-list-conflicting-entries", {
|
|
304
|
-
firstEntry: this._urlsToCacheKeys.get(url),
|
|
305
|
-
secondEntry: cacheKey
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
if (typeof entry !== "string" && entry.integrity) {
|
|
309
|
-
if (this._cacheKeysToIntegrities.has(cacheKey) && this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) {
|
|
310
|
-
throw new SerwistError("add-to-cache-list-conflicting-integrities", {
|
|
311
|
-
url
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
this._cacheKeysToIntegrities.set(cacheKey, entry.integrity);
|
|
315
|
-
}
|
|
316
|
-
this._urlsToCacheKeys.set(url, cacheKey);
|
|
317
|
-
this._urlsToCacheModes.set(url, cacheMode);
|
|
318
|
-
if (urlsToWarnAbout.length > 0) {
|
|
319
|
-
const warningMessage = `Serwist is precaching URLs without revision info: ${urlsToWarnAbout.join(", ")}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;
|
|
320
|
-
if (process.env.NODE_ENV === "production") {
|
|
321
|
-
console.warn(warningMessage);
|
|
322
|
-
} else {
|
|
323
|
-
logger.warn(warningMessage);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
install(event) {
|
|
329
|
-
return waitUntil(event, async ()=>{
|
|
330
|
-
const installReportPlugin = new PrecacheInstallReportPlugin();
|
|
331
|
-
this.strategy.plugins.push(installReportPlugin);
|
|
332
|
-
let concurrents = this._concurrentPrecaching;
|
|
333
|
-
if (concurrents === undefined) {
|
|
334
|
-
if (!("__WB_CONCURRENT_PRECACHING" in globalThis)) {
|
|
335
|
-
self.__WB_CONCURRENT_PRECACHING = 1;
|
|
336
|
-
}
|
|
337
|
-
concurrents = self.__WB_CONCURRENT_PRECACHING;
|
|
338
|
-
}
|
|
339
|
-
await parallel(concurrents, Array.from(this._urlsToCacheKeys.entries()), async ([url, cacheKey])=>{
|
|
340
|
-
const integrity = this._cacheKeysToIntegrities.get(cacheKey);
|
|
341
|
-
const cacheMode = this._urlsToCacheModes.get(url);
|
|
342
|
-
const request = new Request(url, {
|
|
343
|
-
integrity,
|
|
344
|
-
cache: cacheMode,
|
|
345
|
-
credentials: "same-origin"
|
|
346
|
-
});
|
|
347
|
-
await Promise.all(this.strategy.handleAll({
|
|
348
|
-
event,
|
|
349
|
-
request,
|
|
350
|
-
url: new URL(request.url),
|
|
351
|
-
params: {
|
|
352
|
-
cacheKey
|
|
353
|
-
}
|
|
354
|
-
}));
|
|
355
|
-
});
|
|
356
|
-
const { updatedURLs, notUpdatedURLs } = installReportPlugin;
|
|
357
|
-
if (process.env.NODE_ENV !== "production") {
|
|
358
|
-
printInstallDetails(updatedURLs, notUpdatedURLs);
|
|
359
|
-
}
|
|
360
|
-
return {
|
|
361
|
-
updatedURLs,
|
|
362
|
-
notUpdatedURLs
|
|
363
|
-
};
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
activate(event) {
|
|
367
|
-
return waitUntil(event, async ()=>{
|
|
368
|
-
const cache = await self.caches.open(this.strategy.cacheName);
|
|
369
|
-
const currentlyCachedRequests = await cache.keys();
|
|
370
|
-
const expectedCacheKeys = new Set(this._urlsToCacheKeys.values());
|
|
371
|
-
const deletedCacheRequests = [];
|
|
372
|
-
for (const request of currentlyCachedRequests){
|
|
373
|
-
if (!expectedCacheKeys.has(request.url)) {
|
|
374
|
-
await cache.delete(request);
|
|
375
|
-
deletedCacheRequests.push(request.url);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (process.env.NODE_ENV !== "production") {
|
|
379
|
-
printCleanupDetails(deletedCacheRequests);
|
|
380
|
-
}
|
|
381
|
-
return {
|
|
382
|
-
deletedCacheRequests
|
|
383
|
-
};
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
getURLsToCacheKeys() {
|
|
387
|
-
return this._urlsToCacheKeys;
|
|
388
|
-
}
|
|
389
|
-
getCachedURLs() {
|
|
390
|
-
return [
|
|
391
|
-
...this._urlsToCacheKeys.keys()
|
|
392
|
-
];
|
|
393
|
-
}
|
|
394
|
-
getCacheKeyForURL(url) {
|
|
395
|
-
const urlObject = new URL(url, location.href);
|
|
396
|
-
return this._urlsToCacheKeys.get(urlObject.href);
|
|
397
|
-
}
|
|
398
|
-
getIntegrityForCacheKey(cacheKey) {
|
|
399
|
-
return this._cacheKeysToIntegrities.get(cacheKey);
|
|
400
|
-
}
|
|
401
|
-
async matchPrecache(request) {
|
|
402
|
-
const url = request instanceof Request ? request.url : request;
|
|
403
|
-
const cacheKey = this.getCacheKeyForURL(url);
|
|
404
|
-
if (cacheKey) {
|
|
405
|
-
const cache = await self.caches.open(this.strategy.cacheName);
|
|
406
|
-
return cache.match(cacheKey);
|
|
407
|
-
}
|
|
408
|
-
return undefined;
|
|
409
|
-
}
|
|
410
|
-
createHandlerBoundToURL(url) {
|
|
411
|
-
const cacheKey = this.getCacheKeyForURL(url);
|
|
412
|
-
if (!cacheKey) {
|
|
413
|
-
throw new SerwistError("non-precached-url", {
|
|
414
|
-
url
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
return (options)=>{
|
|
418
|
-
options.request = new Request(url);
|
|
419
|
-
options.params = {
|
|
420
|
-
cacheKey,
|
|
421
|
-
...options.params
|
|
422
|
-
};
|
|
423
|
-
return this.strategy.handle(options);
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
let precacheController;
|
|
429
|
-
const getOrCreatePrecacheController = ()=>{
|
|
430
|
-
if (!precacheController) {
|
|
431
|
-
precacheController = new PrecacheController();
|
|
432
|
-
}
|
|
433
|
-
return precacheController;
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
export { PrecacheController as P, PrecacheStrategy as a, getOrCreatePrecacheController as g };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cleanupOutdatedCaches.d.ts","sourceRoot":"","sources":["../src/cleanupOutdatedCaches.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAO,IAcxC,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { RouteHandlerCallback } from "@serwist/core";
|
|
2
|
-
/**
|
|
3
|
-
* Helper function that calls `PrecacheController#createHandlerBoundToURL`
|
|
4
|
-
* on the default `PrecacheController` instance.
|
|
5
|
-
*
|
|
6
|
-
* If you are creating your own `PrecacheController`, then call the
|
|
7
|
-
* `PrecacheController#createHandlerBoundToURL` on that instance,
|
|
8
|
-
* instead of using this function.
|
|
9
|
-
*
|
|
10
|
-
* @param url The precached URL which will be used to lookup the
|
|
11
|
-
* `Response`.
|
|
12
|
-
* @param fallbackToNetwork Whether to attempt to get the
|
|
13
|
-
* response from the network if there's a precache miss.
|
|
14
|
-
* @return
|
|
15
|
-
*/
|
|
16
|
-
export declare const createHandlerBoundToURL: (url: string) => RouteHandlerCallback;
|
|
17
|
-
//# sourceMappingURL=createHandlerBoundToURL.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createHandlerBoundToURL.d.ts","sourceRoot":"","sources":["../src/createHandlerBoundToURL.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAI1D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,QAAS,MAAM,KAAG,oBAGrD,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Takes in a URL, and returns the corresponding URL that could be used to
|
|
3
|
-
* lookup the entry in the precache.
|
|
4
|
-
*
|
|
5
|
-
* If a relative URL is provided, the location of the service worker file will
|
|
6
|
-
* be used as the base.
|
|
7
|
-
*
|
|
8
|
-
* For precached entries without revision information, the cache key will be the
|
|
9
|
-
* same as the original URL.
|
|
10
|
-
*
|
|
11
|
-
* For precached entries with revision information, the cache key will be the
|
|
12
|
-
* original URL with the addition of a query parameter used for keeping track of
|
|
13
|
-
* the revision info.
|
|
14
|
-
*
|
|
15
|
-
* @param url The URL whose cache key to look up.
|
|
16
|
-
* @returns The cache key that corresponds to that URL.
|
|
17
|
-
*/
|
|
18
|
-
declare function getCacheKeyForURL(url: string): string | undefined;
|
|
19
|
-
export { getCacheKeyForURL };
|
|
20
|
-
//# sourceMappingURL=getCacheKeyForURL.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheKeyForURL.d.ts","sourceRoot":"","sources":["../src/getCacheKeyForURL.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG1D;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/index.internal.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.internal.d.ts","sourceRoot":"","sources":["../src/index.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
|
package/dist/index.internal.js
DELETED
package/dist/matchPrecache.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper function that calls `PrecacheController#matchPrecache`
|
|
3
|
-
* on the default `PrecacheController` instance.
|
|
4
|
-
*
|
|
5
|
-
* If you are creating your own `PrecacheController`, then call
|
|
6
|
-
* `PrecacheController#matchPrecache` on that instance,
|
|
7
|
-
* instead of using this function.
|
|
8
|
-
*
|
|
9
|
-
* @param request The key (without revisioning parameters)
|
|
10
|
-
* to look up in the precache.
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
declare function matchPrecache(request: string | Request): Promise<Response | undefined>;
|
|
14
|
-
export { matchPrecache };
|
|
15
|
-
//# sourceMappingURL=matchPrecache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"matchPrecache.d.ts","sourceRoot":"","sources":["../src/matchPrecache.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAG/E;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/precache.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { PrecacheEntry } from "./_types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Adds items to the precache list, removing any duplicates and
|
|
4
|
-
* stores the files in the precache cache when the service
|
|
5
|
-
* worker installs.
|
|
6
|
-
*
|
|
7
|
-
* This method can be called multiple times.
|
|
8
|
-
*
|
|
9
|
-
* Please note: This method **will not** serve any of the cached files for you.
|
|
10
|
-
* It only precaches files. To respond to a network request you call
|
|
11
|
-
* `@serwist/precaching.addRoute`.
|
|
12
|
-
*
|
|
13
|
-
* If you have a single array of files to precache, you can just call
|
|
14
|
-
* `@serwist/precaching.precacheAndRoute`.
|
|
15
|
-
*
|
|
16
|
-
* @param entries Array of entries to precache.
|
|
17
|
-
*/
|
|
18
|
-
export declare const precache: (entries: (PrecacheEntry | string)[]) => void;
|
|
19
|
-
//# sourceMappingURL=precache.d.ts.map
|
package/dist/precache.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"precache.d.ts","sourceRoot":"","sources":["../src/precache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,YAAa,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,KAAG,IAG9D,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { PrecacheEntry, PrecacheRouteOptions } from "./_types.js";
|
|
2
|
-
/**
|
|
3
|
-
* This method will add entries to the precache list and add a route to
|
|
4
|
-
* respond to fetch events.
|
|
5
|
-
*
|
|
6
|
-
* This is a convenience method that will call
|
|
7
|
-
* `@serwist/precaching.precache` and
|
|
8
|
-
* `@serwist/precaching.addRoute` in a single call.
|
|
9
|
-
*
|
|
10
|
-
* @param entries Array of entries to precache.
|
|
11
|
-
* @param options See the `@serwist/precaching.PrecacheRoute` options.
|
|
12
|
-
*/
|
|
13
|
-
export declare const precacheAndRoute: (entries: (PrecacheEntry | string)[], options?: PrecacheRouteOptions) => void;
|
|
14
|
-
//# sourceMappingURL=precacheAndRoute.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"precacheAndRoute.d.ts","sourceRoot":"","sources":["../src/precacheAndRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAIvE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,YAAa,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,YAAY,oBAAoB,KAAG,IAGtG,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { SerwistPlugin } from "@serwist/core";
|
|
2
|
-
import type { PrecacheController } from "../PrecacheController.js";
|
|
3
|
-
/**
|
|
4
|
-
* A plugin, designed to be used with PrecacheController, to translate URLs into
|
|
5
|
-
* the corresponding cache key, based on the current revision info.
|
|
6
|
-
*
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
declare class PrecacheCacheKeyPlugin implements SerwistPlugin {
|
|
10
|
-
private readonly _precacheController;
|
|
11
|
-
constructor({ precacheController }: {
|
|
12
|
-
precacheController: PrecacheController;
|
|
13
|
-
});
|
|
14
|
-
cacheKeyWillBeUsed: SerwistPlugin["cacheKeyWillBeUsed"];
|
|
15
|
-
}
|
|
16
|
-
export { PrecacheCacheKeyPlugin };
|
|
17
|
-
//# sourceMappingURL=PrecacheCacheKeyPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrecacheCacheKeyPlugin.d.ts","sourceRoot":"","sources":["../../src/utils/PrecacheCacheKeyPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,eAAe,CAAC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;;GAKG;AACH,cAAM,sBAAuB,YAAW,aAAa;IACnD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;gBAE7C,EAAE,kBAAkB,EAAE,EAAE;QAAE,kBAAkB,EAAE,kBAAkB,CAAA;KAAE;IAI9E,kBAAkB,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAOrD;CACH;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { SerwistPlugin } from "@serwist/core";
|
|
2
|
-
/**
|
|
3
|
-
* A plugin, designed to be used with PrecacheController, to determine the
|
|
4
|
-
* of assets that were updated (or not updated) during the install event.
|
|
5
|
-
*
|
|
6
|
-
* @private
|
|
7
|
-
*/
|
|
8
|
-
declare class PrecacheInstallReportPlugin implements SerwistPlugin {
|
|
9
|
-
updatedURLs: string[];
|
|
10
|
-
notUpdatedURLs: string[];
|
|
11
|
-
handlerWillStart: SerwistPlugin["handlerWillStart"];
|
|
12
|
-
cachedResponseWillBeUsed: SerwistPlugin["cachedResponseWillBeUsed"];
|
|
13
|
-
}
|
|
14
|
-
export { PrecacheInstallReportPlugin };
|
|
15
|
-
//# sourceMappingURL=PrecacheInstallReportPlugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrecacheInstallReportPlugin.d.ts","sourceRoot":"","sources":["../../src/utils/PrecacheInstallReportPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,eAAe,CAAC;AAE/E;;;;;GAKG;AACH,cAAM,2BAA4B,YAAW,aAAa;IACxD,WAAW,EAAE,MAAM,EAAE,CAAM;IAC3B,cAAc,EAAE,MAAM,EAAE,CAAM;IAE9B,gBAAgB,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAKjD;IAEF,wBAAwB,EAAE,aAAa,CAAC,0BAA0B,CAAC,CAkBjE;CACH;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { PrecacheEntry } from "../_types.js";
|
|
2
|
-
interface CacheKey {
|
|
3
|
-
cacheKey: string;
|
|
4
|
-
url: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Converts a manifest entry into a versioned URL suitable for precaching.
|
|
8
|
-
*
|
|
9
|
-
* @param entry
|
|
10
|
-
* @returns A URL with versioning info.
|
|
11
|
-
*
|
|
12
|
-
* @private
|
|
13
|
-
*/
|
|
14
|
-
export declare function createCacheKey(entry: PrecacheEntry | string): CacheKey;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=createCacheKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createCacheKey.d.ts","sourceRoot":"","sources":["../../src/utils/createCacheKey.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,UAAU,QAAQ;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAKD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,QAAQ,CAuCtE"}
|