@serwist/sw 9.0.0-preview.8 → 9.0.0
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 +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -107
- package/package.json +7 -19
- package/src/index.ts +15 -10
- package/README.md +0 -1
- package/dist/disableDevLogs.d.ts +0 -7
- package/dist/disableDevLogs.d.ts.map +0 -1
- package/dist/fallbacks.d.ts +0 -39
- package/dist/fallbacks.d.ts.map +0 -1
- package/dist/handlePrecaching.d.ts +0 -43
- package/dist/handlePrecaching.d.ts.map +0 -1
- package/dist/installSerwist.d.ts +0 -68
- package/dist/installSerwist.d.ts.map +0 -1
- package/dist/registerRuntimeCaching.d.ts +0 -11
- package/dist/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/types.d.ts +0 -29
- package/dist/types.d.ts.map +0 -1
- package/src/disableDevLogs.ts +0 -10
- package/src/fallbacks.ts +0 -65
- package/src/handlePrecaching.ts +0 -67
- package/src/installSerwist.ts +0 -150
- package/src/registerRuntimeCaching.ts +0 -28
- package/src/types.ts +0 -29
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { type InstallSerwistOptions, installSerwist } from "./installSerwist.js";
|
|
6
|
-
import { registerRuntimeCaching } from "./registerRuntimeCaching.js";
|
|
7
|
-
import type { RuntimeCaching } from "./types.js";
|
|
8
|
-
export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };
|
|
9
|
-
export type { FallbackEntry, FallbackMatcher, FallbacksOptions, HandlePrecachingOptions, InstallSerwistOptions as SerwistOptions, RuntimeCaching };
|
|
1
|
+
export { disableDevLogs } from "serwist";
|
|
2
|
+
export { fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching, } from "serwist/legacy";
|
|
3
|
+
export type { RuntimeCaching } from "serwist";
|
|
4
|
+
export type { FallbackEntry, FallbacksOptions, HandlePrecachingOptions, InstallSerwistOptions, InstallSerwistOptions as SerwistOptions, } from "serwist/legacy";
|
|
10
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,IAAI,cAAc,GACxC,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,107 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { registerRoute, NavigationRoute } from '@serwist/routing';
|
|
4
|
-
import { setCacheNameDetails, clientsClaim } from '@serwist/core';
|
|
5
|
-
import { initialize } from '@serwist/google-analytics/initialize';
|
|
6
|
-
import { enable } from '@serwist/navigation-preload';
|
|
7
|
-
import { logger } from '@serwist/core/internal';
|
|
8
|
-
|
|
9
|
-
const disableDevLogs = ()=>{
|
|
10
|
-
self.__WB_DISABLE_DEV_LOGS = true;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const fallbacks = ({ runtimeCaching, entries, precacheOptions })=>{
|
|
14
|
-
precacheAndRoute(entries, precacheOptions);
|
|
15
|
-
const fallbackPlugin = new PrecacheFallbackPlugin({
|
|
16
|
-
fallbackUrls: entries
|
|
17
|
-
});
|
|
18
|
-
runtimeCaching.forEach((cacheEntry)=>{
|
|
19
|
-
if (cacheEntry.handler instanceof Strategy && !cacheEntry.handler.plugins.some((plugin)=>"handlerDidError" in plugin)) {
|
|
20
|
-
cacheEntry.handler.plugins.push(fallbackPlugin);
|
|
21
|
-
}
|
|
22
|
-
return cacheEntry;
|
|
23
|
-
});
|
|
24
|
-
return runtimeCaching;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches: cleanupOutdatedCaches$1 = false, ...options })=>{
|
|
28
|
-
if (!!precacheEntries && precacheEntries.length > 0) {
|
|
29
|
-
precacheAndRoute(precacheEntries, precacheOptions);
|
|
30
|
-
}
|
|
31
|
-
if (cleanupOutdatedCaches$1) cleanupOutdatedCaches();
|
|
32
|
-
if (options.navigateFallback) {
|
|
33
|
-
registerRoute(new NavigationRoute(createHandlerBoundToURL(options.navigateFallback), {
|
|
34
|
-
allowlist: options.navigateFallbackAllowlist,
|
|
35
|
-
denylist: options.navigateFallbackDenylist
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const registerRuntimeCaching = (...runtimeCachingList)=>{
|
|
41
|
-
if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
|
|
42
|
-
self.__WB_FORCE_RUNTIME_CACHING = false;
|
|
43
|
-
}
|
|
44
|
-
if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
|
|
45
|
-
logger.log("registerRuntimeCaching is disabled in development mode.");
|
|
46
|
-
} else {
|
|
47
|
-
for (const entry of runtimeCachingList){
|
|
48
|
-
registerRoute(entry.matcher, entry.handler, entry.method);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const installSerwist = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, skipWaiting = false, importScripts, navigationPreload = false, cacheId, clientsClaim: clientsClaim$1 = false, runtimeCaching, offlineAnalyticsConfig, disableDevLogs: disableDevLogs$1 = false, fallbacks: fallbacks$1, ...options })=>{
|
|
54
|
-
if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
|
|
55
|
-
if (navigationPreload) enable();
|
|
56
|
-
if (cacheId !== undefined) {
|
|
57
|
-
setCacheNameDetails({
|
|
58
|
-
prefix: cacheId
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (skipWaiting) {
|
|
62
|
-
self.skipWaiting();
|
|
63
|
-
} else {
|
|
64
|
-
self.addEventListener("message", (event)=>{
|
|
65
|
-
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
66
|
-
self.skipWaiting();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
if (clientsClaim$1) clientsClaim();
|
|
71
|
-
handlePrecaching({
|
|
72
|
-
precacheEntries,
|
|
73
|
-
precacheOptions,
|
|
74
|
-
cleanupOutdatedCaches,
|
|
75
|
-
...options.navigateFallback && {
|
|
76
|
-
navigateFallback: options.navigateFallback,
|
|
77
|
-
navigateFallbackAllowlist: options.navigateFallbackAllowlist,
|
|
78
|
-
navigateFallbackDenylist: options.navigateFallbackDenylist
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
if (runtimeCaching !== undefined) {
|
|
82
|
-
if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
|
|
83
|
-
self.__WB_FORCE_RUNTIME_CACHING = false;
|
|
84
|
-
}
|
|
85
|
-
if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
|
|
86
|
-
logger.log("runtimeCaching and fallbacks are disabled in development mode.");
|
|
87
|
-
} else {
|
|
88
|
-
if (fallbacks$1 !== undefined) {
|
|
89
|
-
fallbacks({
|
|
90
|
-
...fallbacks$1,
|
|
91
|
-
runtimeCaching
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
registerRuntimeCaching(...runtimeCaching);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (offlineAnalyticsConfig !== undefined) {
|
|
98
|
-
if (typeof offlineAnalyticsConfig === "boolean") {
|
|
99
|
-
offlineAnalyticsConfig && initialize();
|
|
100
|
-
} else {
|
|
101
|
-
initialize(offlineAnalyticsConfig);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (disableDevLogs$1) disableDevLogs();
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export { disableDevLogs, fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching };
|
|
1
|
+
export { disableDevLogs } from 'serwist';
|
|
2
|
+
export { fallbacks, handlePrecaching, installSerwist, registerRuntimeCaching } from 'serwist/legacy';
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/sw",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "A service worker helper module.",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
8
|
"dist"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"repository": "serwist/serwist",
|
|
18
|
+
"repository": "https://github.com/serwist/serwist",
|
|
19
19
|
"bugs": "https://github.com/serwist/serwist/issues",
|
|
20
20
|
"homepage": "https://serwist.pages.dev",
|
|
21
21
|
"main": "./dist/index.js",
|
|
@@ -28,23 +28,12 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"
|
|
32
|
-
"@serwist/broadcast-update": "9.0.0-preview.8",
|
|
33
|
-
"@serwist/cacheable-response": "9.0.0-preview.8",
|
|
34
|
-
"@serwist/core": "9.0.0-preview.8",
|
|
35
|
-
"@serwist/expiration": "9.0.0-preview.8",
|
|
36
|
-
"@serwist/google-analytics": "9.0.0-preview.8",
|
|
37
|
-
"@serwist/navigation-preload": "9.0.0-preview.8",
|
|
38
|
-
"@serwist/precaching": "9.0.0-preview.8",
|
|
39
|
-
"@serwist/range-requests": "9.0.0-preview.8",
|
|
40
|
-
"@serwist/routing": "9.0.0-preview.8",
|
|
41
|
-
"@serwist/strategies": "9.0.0-preview.8"
|
|
31
|
+
"serwist": "9.0.0"
|
|
42
32
|
},
|
|
43
33
|
"devDependencies": {
|
|
44
|
-
"rollup": "4.
|
|
45
|
-
"typescript": "5.
|
|
46
|
-
"@serwist/
|
|
47
|
-
"@serwist/utils": "9.0.0-preview.8"
|
|
34
|
+
"rollup": "4.14.3",
|
|
35
|
+
"typescript": "5.5.0-dev.20240415",
|
|
36
|
+
"@serwist/configs": "9.0.0"
|
|
48
37
|
},
|
|
49
38
|
"peerDependencies": {
|
|
50
39
|
"typescript": ">=5.0.0"
|
|
@@ -56,7 +45,6 @@
|
|
|
56
45
|
},
|
|
57
46
|
"scripts": {
|
|
58
47
|
"build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
|
|
59
|
-
"dev": "rollup --config rollup.config.js --watch",
|
|
60
48
|
"lint": "biome lint ./src",
|
|
61
49
|
"typecheck": "tsc"
|
|
62
50
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
|
|
1
|
+
export { disableDevLogs } from "serwist";
|
|
2
|
+
export {
|
|
3
|
+
fallbacks,
|
|
4
|
+
handlePrecaching,
|
|
5
|
+
installSerwist,
|
|
6
|
+
registerRuntimeCaching,
|
|
7
|
+
} from "serwist/legacy";
|
|
8
|
+
export type { RuntimeCaching } from "serwist";
|
|
9
|
+
export type {
|
|
10
|
+
FallbackEntry,
|
|
11
|
+
FallbacksOptions,
|
|
12
|
+
HandlePrecachingOptions,
|
|
13
|
+
InstallSerwistOptions,
|
|
14
|
+
InstallSerwistOptions as SerwistOptions,
|
|
15
|
+
} from "serwist/legacy";
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
This module's documentation can be found at https://serwist.pages.dev/docs/sw
|
package/dist/disableDevLogs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"disableDevLogs.d.ts","sourceRoot":"","sources":["../src/disableDevLogs.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO,IAEjC,CAAC"}
|
package/dist/fallbacks.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { HandlerDidErrorCallbackParam } from "@serwist/core";
|
|
2
|
-
import type { PrecacheRouteOptions } from "@serwist/precaching";
|
|
3
|
-
import type { PrecacheFallbackEntry } from "@serwist/precaching";
|
|
4
|
-
import type { RuntimeCaching } from "./types.js";
|
|
5
|
-
export type FallbackMatcher = (_: HandlerDidErrorCallbackParam) => boolean;
|
|
6
|
-
export interface FallbackEntry extends PrecacheFallbackEntry {
|
|
7
|
-
/**
|
|
8
|
-
* The revision used for precaching.
|
|
9
|
-
*/
|
|
10
|
-
revision: string;
|
|
11
|
-
}
|
|
12
|
-
export interface FallbacksOptions {
|
|
13
|
-
/**
|
|
14
|
-
* Your previous `RuntimeCaching` array.
|
|
15
|
-
*/
|
|
16
|
-
runtimeCaching: RuntimeCaching[];
|
|
17
|
-
/**
|
|
18
|
-
* A list of fallback entries.
|
|
19
|
-
*/
|
|
20
|
-
entries: FallbackEntry[];
|
|
21
|
-
/**
|
|
22
|
-
* Precache options that will be used for your
|
|
23
|
-
* fallback entries.
|
|
24
|
-
*/
|
|
25
|
-
precacheOptions?: PrecacheRouteOptions;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Precaches routes so that they can be used as a fallback when
|
|
29
|
-
* a Strategy fails to generate a response.
|
|
30
|
-
*
|
|
31
|
-
* Note: This function mutates `runtimeCaching`!
|
|
32
|
-
*
|
|
33
|
-
* @see https://serwist.pages.dev/docs/sw/fallbacks
|
|
34
|
-
* @param options
|
|
35
|
-
* @returns The modified `RuntimeCaching` array. Using this value
|
|
36
|
-
* is not needed, as it is simply the array in `options`.
|
|
37
|
-
*/
|
|
38
|
-
export declare const fallbacks: ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions) => RuntimeCaching[];
|
|
39
|
-
//# sourceMappingURL=fallbacks.d.ts.map
|
package/dist/fallbacks.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../src/fallbacks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,4BAA4B,KAAK,OAAO,CAAC;AAE3E,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,iDAAkD,gBAAgB,KAAG,cAAc,EAoBxG,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";
|
|
2
|
-
export type HandlePrecachingOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* A list of fallback entries.
|
|
5
|
-
*/
|
|
6
|
-
precacheEntries?: (PrecacheEntry | string)[];
|
|
7
|
-
/**
|
|
8
|
-
* Precache options for the provided entries.
|
|
9
|
-
*/
|
|
10
|
-
precacheOptions?: PrecacheRouteOptions;
|
|
11
|
-
/**
|
|
12
|
-
* Whether outdated caches should be removed.
|
|
13
|
-
*
|
|
14
|
-
* @default false
|
|
15
|
-
*/
|
|
16
|
-
cleanupOutdatedCaches?: boolean;
|
|
17
|
-
} & ({
|
|
18
|
-
/**
|
|
19
|
-
* An URL that should point to a HTML
|
|
20
|
-
* file with which navigation requests for URLs that aren't precached will be fulfilled.
|
|
21
|
-
* For more complex cases, consider `@serwist/sw.fallbacks`instead.
|
|
22
|
-
*/
|
|
23
|
-
navigateFallback: string;
|
|
24
|
-
/**
|
|
25
|
-
* URLs that should be allowed to use the `navigateFallback` handler.
|
|
26
|
-
*/
|
|
27
|
-
navigateFallbackAllowlist?: RegExp[];
|
|
28
|
-
/**
|
|
29
|
-
* URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
|
|
30
|
-
* over `navigateFallbackAllowlist`.
|
|
31
|
-
*/
|
|
32
|
-
navigateFallbackDenylist?: RegExp[];
|
|
33
|
-
} | {
|
|
34
|
-
navigateFallback?: never;
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Handles a list of precache entries and cleans up outdated caches.
|
|
38
|
-
*
|
|
39
|
-
* @see https://serwist.pages.dev/docs/sw/handlePrecaching
|
|
40
|
-
* @param options
|
|
41
|
-
*/
|
|
42
|
-
export declare const handlePrecaching: ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, ...options }: HandlePrecachingOptions) => void;
|
|
43
|
-
//# sourceMappingURL=handlePrecaching.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handlePrecaching.d.ts","sourceRoot":"","sources":["../src/handlePrecaching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI/E,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IAC7C;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,GAAG,CACA;IACE;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,GACD;IAAE,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,CAC/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,4EAAqF,uBAAuB,KAAG,IAoB3I,CAAC"}
|
package/dist/installSerwist.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { type GoogleAnalyticsInitializeOptions } from "@serwist/google-analytics/initialize";
|
|
2
|
-
import type { FallbacksOptions } from "./fallbacks.js";
|
|
3
|
-
import { type HandlePrecachingOptions } from "./handlePrecaching.js";
|
|
4
|
-
import type { RuntimeCaching } from "./types.js";
|
|
5
|
-
export type InstallSerwistOptions = HandlePrecachingOptions & {
|
|
6
|
-
/**
|
|
7
|
-
* Forces the waiting service worker to become the active one.
|
|
8
|
-
*
|
|
9
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
|
|
10
|
-
*/
|
|
11
|
-
skipWaiting?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Imports external scripts. They are executed in the order they
|
|
14
|
-
* are passed.
|
|
15
|
-
*
|
|
16
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
|
|
17
|
-
*/
|
|
18
|
-
importScripts?: string[];
|
|
19
|
-
/**
|
|
20
|
-
* Enables Navigation Preload if it is supported.
|
|
21
|
-
*
|
|
22
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
|
|
23
|
-
*/
|
|
24
|
-
navigationPreload?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Modifies the prefix of the default cache names used by Serwist packages.
|
|
27
|
-
*/
|
|
28
|
-
cacheId?: string | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Claims any currently available clients once the service worker
|
|
31
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
32
|
-
*
|
|
33
|
-
* @default false
|
|
34
|
-
*/
|
|
35
|
-
clientsClaim?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* A list of caching strategies.
|
|
38
|
-
*
|
|
39
|
-
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
40
|
-
*/
|
|
41
|
-
runtimeCaching?: RuntimeCaching[];
|
|
42
|
-
/**
|
|
43
|
-
* Your configuration for `@serwist/google-analytics`. This plugin is
|
|
44
|
-
* only initialized when this option is not `undefined` or `false`.
|
|
45
|
-
*/
|
|
46
|
-
offlineAnalyticsConfig?: GoogleAnalyticsInitializeOptions | boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Disables Serwist's logging in development mode.
|
|
49
|
-
*
|
|
50
|
-
* @default false
|
|
51
|
-
* @see https://serwist.pages.dev/docs/sw/disable-dev-logs
|
|
52
|
-
*/
|
|
53
|
-
disableDevLogs?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Precaches routes so that they can be used as a fallback when
|
|
56
|
-
* a Strategy fails to generate a response.
|
|
57
|
-
* Note: This option mutates `runtimeCaching`!
|
|
58
|
-
*
|
|
59
|
-
* @see https://serwist.pages.dev/docs/sw/fallbacks
|
|
60
|
-
*/
|
|
61
|
-
fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* A function that abstracts away the core APIs of Serwist.
|
|
65
|
-
* @param options - `installSerwist` options.
|
|
66
|
-
*/
|
|
67
|
-
export declare const installSerwist: ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, skipWaiting, importScripts, navigationPreload, cacheId, clientsClaim, runtimeCaching, offlineAnalyticsConfig, disableDevLogs, fallbacks, ...options }: InstallSerwistOptions) => void;
|
|
68
|
-
//# sourceMappingURL=installSerwist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"installSerwist.d.ts","sourceRoot":"","sources":["../src/installSerwist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gCAAgC,EAAc,MAAM,sCAAsC,CAAC;AAMzG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,KAAK,uBAAuB,EAAoB,MAAM,uBAAuB,CAAC;AAEvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG;IAC5D;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC;IACpE;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;CACtD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,qNAexB,qBAAqB,KAAG,IAyD1B,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCaching } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Registers caching strategies to a singleton Router instance. It is a simple
|
|
4
|
-
* syntatic sugar for `@serwist/routing.registerRoute`.
|
|
5
|
-
*
|
|
6
|
-
* @see https://serwist.pages.dev/docs/sw/registerRuntimeCaching
|
|
7
|
-
* @param runtimeCachingList
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export declare const registerRuntimeCaching: (...runtimeCachingList: RuntimeCaching[]) => void;
|
|
11
|
-
//# sourceMappingURL=registerRuntimeCaching.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registerRuntimeCaching.d.ts","sourceRoot":"","sources":["../src/registerRuntimeCaching.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,0BAA2B,cAAc,EAAE,KAAG,IAYhF,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
-
import type { HTTPMethod } from "@serwist/routing";
|
|
3
|
-
export interface RuntimeCaching {
|
|
4
|
-
/**
|
|
5
|
-
* The HTTP method to match against. The default value of `'GET'` is normally
|
|
6
|
-
* sufficient, unless you explicitly need to match `'POST'`, `'PUT'`, or
|
|
7
|
-
* another type of request.
|
|
8
|
-
* @default "GET"
|
|
9
|
-
*/
|
|
10
|
-
method?: HTTPMethod;
|
|
11
|
-
/**
|
|
12
|
-
* This match criteria determines whether the configured handler will
|
|
13
|
-
* generate a response for any requests that don't match one of the precached
|
|
14
|
-
* URLs. If multiple `RuntimeCaching` routes are defined, then the first one
|
|
15
|
-
* whose `matcher` matches will be the one that responds.
|
|
16
|
-
*
|
|
17
|
-
* This value directly maps to the first parameter passed to
|
|
18
|
-
* `@serwist/routing.registerRoute`. It's recommended to use a
|
|
19
|
-
* `@serwist/core.RouteMatchCallback` function for greatest flexibility.
|
|
20
|
-
*/
|
|
21
|
-
matcher: RegExp | string | RouteMatchCallback;
|
|
22
|
-
/**
|
|
23
|
-
* This determines how the runtime route will generate a response. It
|
|
24
|
-
* can be a `@serwist/core.RouteHandler` callback function with custom
|
|
25
|
-
* response logic.
|
|
26
|
-
*/
|
|
27
|
-
handler: RouteHandler;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC;IAC9C;;;;OAIG;IACH,OAAO,EAAE,YAAY,CAAC;CACvB"}
|
package/src/disableDevLogs.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Disables Serwist's logging in development mode.
|
|
5
|
-
*
|
|
6
|
-
* @see https://serwist.pages.dev/docs/sw/disable-dev-logs
|
|
7
|
-
*/
|
|
8
|
-
export const disableDevLogs = (): void => {
|
|
9
|
-
self.__WB_DISABLE_DEV_LOGS = true;
|
|
10
|
-
};
|
package/src/fallbacks.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { HandlerDidErrorCallbackParam } from "@serwist/core";
|
|
2
|
-
import type { PrecacheRouteOptions } from "@serwist/precaching";
|
|
3
|
-
import { PrecacheFallbackPlugin, precacheAndRoute } from "@serwist/precaching";
|
|
4
|
-
import type { PrecacheFallbackEntry } from "@serwist/precaching";
|
|
5
|
-
|
|
6
|
-
import { Strategy } from "@serwist/strategies";
|
|
7
|
-
import type { RuntimeCaching } from "./types.js";
|
|
8
|
-
|
|
9
|
-
export type FallbackMatcher = (_: HandlerDidErrorCallbackParam) => boolean;
|
|
10
|
-
|
|
11
|
-
export interface FallbackEntry extends PrecacheFallbackEntry {
|
|
12
|
-
/**
|
|
13
|
-
* The revision used for precaching.
|
|
14
|
-
*/
|
|
15
|
-
revision: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface FallbacksOptions {
|
|
19
|
-
/**
|
|
20
|
-
* Your previous `RuntimeCaching` array.
|
|
21
|
-
*/
|
|
22
|
-
runtimeCaching: RuntimeCaching[];
|
|
23
|
-
/**
|
|
24
|
-
* A list of fallback entries.
|
|
25
|
-
*/
|
|
26
|
-
entries: FallbackEntry[];
|
|
27
|
-
/**
|
|
28
|
-
* Precache options that will be used for your
|
|
29
|
-
* fallback entries.
|
|
30
|
-
*/
|
|
31
|
-
precacheOptions?: PrecacheRouteOptions;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Precaches routes so that they can be used as a fallback when
|
|
36
|
-
* a Strategy fails to generate a response.
|
|
37
|
-
*
|
|
38
|
-
* Note: This function mutates `runtimeCaching`!
|
|
39
|
-
*
|
|
40
|
-
* @see https://serwist.pages.dev/docs/sw/fallbacks
|
|
41
|
-
* @param options
|
|
42
|
-
* @returns The modified `RuntimeCaching` array. Using this value
|
|
43
|
-
* is not needed, as it is simply the array in `options`.
|
|
44
|
-
*/
|
|
45
|
-
export const fallbacks = ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions): RuntimeCaching[] => {
|
|
46
|
-
precacheAndRoute(entries, precacheOptions);
|
|
47
|
-
|
|
48
|
-
const fallbackPlugin = new PrecacheFallbackPlugin({
|
|
49
|
-
fallbackUrls: entries,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
runtimeCaching.forEach((cacheEntry) => {
|
|
53
|
-
if (
|
|
54
|
-
cacheEntry.handler instanceof Strategy &&
|
|
55
|
-
// PrecacheFallbackPlugin also has `handlerDidError`, so we don't need to check for its instances.
|
|
56
|
-
!cacheEntry.handler.plugins.some((plugin) => "handlerDidError" in plugin)
|
|
57
|
-
) {
|
|
58
|
-
cacheEntry.handler.plugins.push(fallbackPlugin);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return cacheEntry;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return runtimeCaching;
|
|
65
|
-
};
|
package/src/handlePrecaching.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";
|
|
2
|
-
import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl, createHandlerBoundToURL, precacheAndRoute } from "@serwist/precaching";
|
|
3
|
-
import { NavigationRoute, registerRoute } from "@serwist/routing";
|
|
4
|
-
|
|
5
|
-
export type HandlePrecachingOptions = {
|
|
6
|
-
/**
|
|
7
|
-
* A list of fallback entries.
|
|
8
|
-
*/
|
|
9
|
-
precacheEntries?: (PrecacheEntry | string)[];
|
|
10
|
-
/**
|
|
11
|
-
* Precache options for the provided entries.
|
|
12
|
-
*/
|
|
13
|
-
precacheOptions?: PrecacheRouteOptions;
|
|
14
|
-
/**
|
|
15
|
-
* Whether outdated caches should be removed.
|
|
16
|
-
*
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
cleanupOutdatedCaches?: boolean;
|
|
20
|
-
} & (
|
|
21
|
-
| {
|
|
22
|
-
/**
|
|
23
|
-
* An URL that should point to a HTML
|
|
24
|
-
* file with which navigation requests for URLs that aren't precached will be fulfilled.
|
|
25
|
-
* For more complex cases, consider `@serwist/sw.fallbacks`instead.
|
|
26
|
-
*/
|
|
27
|
-
navigateFallback: string;
|
|
28
|
-
/**
|
|
29
|
-
* URLs that should be allowed to use the `navigateFallback` handler.
|
|
30
|
-
*/
|
|
31
|
-
navigateFallbackAllowlist?: RegExp[];
|
|
32
|
-
/**
|
|
33
|
-
* URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
|
|
34
|
-
* over `navigateFallbackAllowlist`.
|
|
35
|
-
*/
|
|
36
|
-
navigateFallbackDenylist?: RegExp[];
|
|
37
|
-
}
|
|
38
|
-
| { navigateFallback?: never }
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Handles a list of precache entries and cleans up outdated caches.
|
|
43
|
-
*
|
|
44
|
-
* @see https://serwist.pages.dev/docs/sw/handlePrecaching
|
|
45
|
-
* @param options
|
|
46
|
-
*/
|
|
47
|
-
export const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches = false, ...options }: HandlePrecachingOptions): void => {
|
|
48
|
-
if (!!precacheEntries && precacheEntries.length > 0) {
|
|
49
|
-
/**
|
|
50
|
-
* The precacheAndRoute() method efficiently caches and responds to
|
|
51
|
-
* requests for URLs in the manifest.
|
|
52
|
-
* See https://goo.gl/S9QRab
|
|
53
|
-
*/
|
|
54
|
-
precacheAndRoute(precacheEntries, precacheOptions);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (cleanupOutdatedCaches) cleanupOutdatedCachesImpl();
|
|
58
|
-
|
|
59
|
-
if (options.navigateFallback) {
|
|
60
|
-
registerRoute(
|
|
61
|
-
new NavigationRoute(createHandlerBoundToURL(options.navigateFallback), {
|
|
62
|
-
allowlist: options.navigateFallbackAllowlist,
|
|
63
|
-
denylist: options.navigateFallbackDenylist,
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
};
|
package/src/installSerwist.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { clientsClaim as clientsClaimImpl, setCacheNameDetails } from "@serwist/core";
|
|
2
|
-
import { type GoogleAnalyticsInitializeOptions, initialize } from "@serwist/google-analytics/initialize";
|
|
3
|
-
import { enable } from "@serwist/navigation-preload";
|
|
4
|
-
|
|
5
|
-
import { logger } from "@serwist/core/internal";
|
|
6
|
-
import { disableDevLogs as disableDevLogsImpl } from "./disableDevLogs.js";
|
|
7
|
-
import { fallbacks as fallbacksImpl } from "./fallbacks.js";
|
|
8
|
-
import type { FallbacksOptions } from "./fallbacks.js";
|
|
9
|
-
import { type HandlePrecachingOptions, handlePrecaching } from "./handlePrecaching.js";
|
|
10
|
-
import { registerRuntimeCaching } from "./registerRuntimeCaching.js";
|
|
11
|
-
import type { RuntimeCaching } from "./types.js";
|
|
12
|
-
|
|
13
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
14
|
-
|
|
15
|
-
export type InstallSerwistOptions = HandlePrecachingOptions & {
|
|
16
|
-
/**
|
|
17
|
-
* Forces the waiting service worker to become the active one.
|
|
18
|
-
*
|
|
19
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
|
|
20
|
-
*/
|
|
21
|
-
skipWaiting?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Imports external scripts. They are executed in the order they
|
|
24
|
-
* are passed.
|
|
25
|
-
*
|
|
26
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
|
|
27
|
-
*/
|
|
28
|
-
importScripts?: string[];
|
|
29
|
-
/**
|
|
30
|
-
* Enables Navigation Preload if it is supported.
|
|
31
|
-
*
|
|
32
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
|
|
33
|
-
*/
|
|
34
|
-
navigationPreload?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Modifies the prefix of the default cache names used by Serwist packages.
|
|
37
|
-
*/
|
|
38
|
-
cacheId?: string | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* Claims any currently available clients once the service worker
|
|
41
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
42
|
-
*
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
clientsClaim?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* A list of caching strategies.
|
|
48
|
-
*
|
|
49
|
-
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
50
|
-
*/
|
|
51
|
-
runtimeCaching?: RuntimeCaching[];
|
|
52
|
-
/**
|
|
53
|
-
* Your configuration for `@serwist/google-analytics`. This plugin is
|
|
54
|
-
* only initialized when this option is not `undefined` or `false`.
|
|
55
|
-
*/
|
|
56
|
-
offlineAnalyticsConfig?: GoogleAnalyticsInitializeOptions | boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Disables Serwist's logging in development mode.
|
|
59
|
-
*
|
|
60
|
-
* @default false
|
|
61
|
-
* @see https://serwist.pages.dev/docs/sw/disable-dev-logs
|
|
62
|
-
*/
|
|
63
|
-
disableDevLogs?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Precaches routes so that they can be used as a fallback when
|
|
66
|
-
* a Strategy fails to generate a response.
|
|
67
|
-
* Note: This option mutates `runtimeCaching`!
|
|
68
|
-
*
|
|
69
|
-
* @see https://serwist.pages.dev/docs/sw/fallbacks
|
|
70
|
-
*/
|
|
71
|
-
fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* A function that abstracts away the core APIs of Serwist.
|
|
76
|
-
* @param options - `installSerwist` options.
|
|
77
|
-
*/
|
|
78
|
-
export const installSerwist = ({
|
|
79
|
-
precacheEntries,
|
|
80
|
-
precacheOptions,
|
|
81
|
-
cleanupOutdatedCaches,
|
|
82
|
-
|
|
83
|
-
skipWaiting = false,
|
|
84
|
-
importScripts,
|
|
85
|
-
navigationPreload = false,
|
|
86
|
-
cacheId,
|
|
87
|
-
clientsClaim = false,
|
|
88
|
-
runtimeCaching,
|
|
89
|
-
offlineAnalyticsConfig,
|
|
90
|
-
disableDevLogs = false,
|
|
91
|
-
fallbacks,
|
|
92
|
-
...options
|
|
93
|
-
}: InstallSerwistOptions): void => {
|
|
94
|
-
if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
|
|
95
|
-
|
|
96
|
-
if (navigationPreload) enable();
|
|
97
|
-
|
|
98
|
-
if (cacheId !== undefined) {
|
|
99
|
-
setCacheNameDetails({
|
|
100
|
-
prefix: cacheId,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (skipWaiting) {
|
|
105
|
-
self.skipWaiting();
|
|
106
|
-
} else {
|
|
107
|
-
self.addEventListener("message", (event) => {
|
|
108
|
-
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
109
|
-
self.skipWaiting();
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (clientsClaim) clientsClaimImpl();
|
|
115
|
-
|
|
116
|
-
handlePrecaching({
|
|
117
|
-
precacheEntries,
|
|
118
|
-
precacheOptions,
|
|
119
|
-
cleanupOutdatedCaches,
|
|
120
|
-
...(options.navigateFallback && {
|
|
121
|
-
navigateFallback: options.navigateFallback,
|
|
122
|
-
navigateFallbackAllowlist: options.navigateFallbackAllowlist,
|
|
123
|
-
navigateFallbackDenylist: options.navigateFallbackDenylist,
|
|
124
|
-
}),
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
if (runtimeCaching !== undefined) {
|
|
128
|
-
if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
|
|
129
|
-
self.__WB_FORCE_RUNTIME_CACHING = false;
|
|
130
|
-
}
|
|
131
|
-
if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
|
|
132
|
-
logger.log("runtimeCaching and fallbacks are disabled in development mode.");
|
|
133
|
-
} else {
|
|
134
|
-
if (fallbacks !== undefined) {
|
|
135
|
-
fallbacksImpl({ ...fallbacks, runtimeCaching });
|
|
136
|
-
}
|
|
137
|
-
registerRuntimeCaching(...runtimeCaching);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (offlineAnalyticsConfig !== undefined) {
|
|
142
|
-
if (typeof offlineAnalyticsConfig === "boolean") {
|
|
143
|
-
offlineAnalyticsConfig && initialize();
|
|
144
|
-
} else {
|
|
145
|
-
initialize(offlineAnalyticsConfig);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (disableDevLogs) disableDevLogsImpl();
|
|
150
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { logger } from "@serwist/core/internal";
|
|
2
|
-
import { registerRoute } from "@serwist/routing";
|
|
3
|
-
|
|
4
|
-
import type { RuntimeCaching } from "./types.js";
|
|
5
|
-
|
|
6
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Registers caching strategies to a singleton Router instance. It is a simple
|
|
10
|
-
* syntatic sugar for `@serwist/routing.registerRoute`.
|
|
11
|
-
*
|
|
12
|
-
* @see https://serwist.pages.dev/docs/sw/registerRuntimeCaching
|
|
13
|
-
* @param runtimeCachingList
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export const registerRuntimeCaching = (...runtimeCachingList: RuntimeCaching[]): void => {
|
|
17
|
-
if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
|
|
18
|
-
self.__WB_FORCE_RUNTIME_CACHING = false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
|
|
22
|
-
logger.log("registerRuntimeCaching is disabled in development mode.");
|
|
23
|
-
} else {
|
|
24
|
-
for (const entry of runtimeCachingList) {
|
|
25
|
-
registerRoute(entry.matcher, entry.handler, entry.method);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
-
import type { HTTPMethod } from "@serwist/routing";
|
|
3
|
-
|
|
4
|
-
export interface RuntimeCaching {
|
|
5
|
-
/**
|
|
6
|
-
* The HTTP method to match against. The default value of `'GET'` is normally
|
|
7
|
-
* sufficient, unless you explicitly need to match `'POST'`, `'PUT'`, or
|
|
8
|
-
* another type of request.
|
|
9
|
-
* @default "GET"
|
|
10
|
-
*/
|
|
11
|
-
method?: HTTPMethod;
|
|
12
|
-
/**
|
|
13
|
-
* This match criteria determines whether the configured handler will
|
|
14
|
-
* generate a response for any requests that don't match one of the precached
|
|
15
|
-
* URLs. If multiple `RuntimeCaching` routes are defined, then the first one
|
|
16
|
-
* whose `matcher` matches will be the one that responds.
|
|
17
|
-
*
|
|
18
|
-
* This value directly maps to the first parameter passed to
|
|
19
|
-
* `@serwist/routing.registerRoute`. It's recommended to use a
|
|
20
|
-
* `@serwist/core.RouteMatchCallback` function for greatest flexibility.
|
|
21
|
-
*/
|
|
22
|
-
matcher: RegExp | string | RouteMatchCallback;
|
|
23
|
-
/**
|
|
24
|
-
* This determines how the runtime route will generate a response. It
|
|
25
|
-
* can be a `@serwist/core.RouteHandler` callback function with custom
|
|
26
|
-
* response logic.
|
|
27
|
-
*/
|
|
28
|
-
handler: RouteHandler;
|
|
29
|
-
}
|