@serwist/svelte 9.0.0-preview.12 → 9.0.0-preview.14

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.
@@ -1,11 +1,15 @@
1
1
  /// <reference types="@sveltejs/kit" />
2
2
  import type { PrecacheEntry } from "@serwist/precaching";
3
3
  import type { RuntimeCaching } from "@serwist/sw";
4
- import { build as immutableAssets, files as staticAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion } from "$service-worker";
5
- export { immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
6
- export type StaticRevisions = {
4
+ import { base as basePath, build as immutableAssets, files as staticAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion } from "$service-worker";
5
+ export { basePath, immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
6
+ export type StaticRevisions = string | {
7
7
  [url: string]: string | null;
8
8
  };
9
+ export type ManifestTransform = (manifest: PrecacheEntry[]) => {
10
+ manifest: PrecacheEntry[];
11
+ warnings?: string[] | undefined;
12
+ };
9
13
  export interface GetPrecacheManifestOptions {
10
14
  /**
11
15
  * Whether immutable assets, as in assets that are generated by
@@ -28,25 +32,32 @@ export interface GetPrecacheManifestOptions {
28
32
  */
29
33
  precachePrerendered?: boolean;
30
34
  /**
31
- * An object that maps URLs of static assets to custom `revision`'s.
32
- * If an URL doesn't exist in the object, `$service-worker.version`
35
+ * A string revision used for all static assets or an object that maps
36
+ * URLs of static assets to custom revisions.
37
+ * If an URL doesn't exist in the object, `serviceWorkerVersion`
33
38
  * will be used instead.
34
39
  *
35
40
  * This helps prevent such assets, which are unlikely to change, from
36
- * being invalidated every time the service worker is installed.
41
+ * being invalidated every time the service worker is rebuilt and updated.
37
42
  *
38
- * Note: you should prefix these URLs with `$service-worker.base`.
43
+ * Note: you should prefix these URLs with `basePath`.
39
44
  */
40
45
  staticRevisions?: StaticRevisions;
46
+ /**
47
+ * One or more functions which will be applied sequentially against the
48
+ * generated manifest.
49
+ */
50
+ manifestTransforms?: ManifestTransform[];
41
51
  }
42
52
  /**
43
- * Retrieves the precache manifest generated by SvelteKit. If further
44
- * modifications are needed, simply mutate the resulting array.
53
+ * Retrieves the precache manifest generated by SvelteKit. A simple
54
+ * wrapper around SvelteKit's built-in service worker support. For more
55
+ * complex use cases, seek [the `@serwist/vite` recipe for SvelteKit](https://serwist.pages.dev/docs/vite/recipes/svelte-kit).
45
56
  *
46
57
  * @param options
47
58
  * @returns
48
59
  */
49
- export declare const getPrecacheManifest: ({ precacheImmutable, precacheStatic, precachePrerendered, staticRevisions, }?: GetPrecacheManifestOptions) => PrecacheEntry[];
60
+ export declare const getPrecacheManifest: ({ precacheImmutable, precacheStatic, precachePrerendered, staticRevisions, manifestTransforms, }?: GetPrecacheManifestOptions) => PrecacheEntry[] | undefined;
50
61
  export declare const defaultIgnoreUrlParameters: RegExp[];
51
62
  export declare const defaultCache: RuntimeCaching[];
52
63
  //# sourceMappingURL=index.worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,KAAK,IAAI,YAAY,EAAE,WAAW,IAAI,iBAAiB,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAErJ,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;AAElF,MAAM,MAAM,eAAe,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE/D,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,cAAc,C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C;IAC9B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,sGAM7B,0BAA0B,KAAQ,aAAa,EAAE,GAAG,SA2CtD,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAAgC,CAAC;AAExE,eAAO,MAAM,YAAY,EAAE,cAAc,EAoGxC,CAAC"}
@@ -1,17 +1,15 @@
1
+ import { logger } from '@serwist/core/internal';
1
2
  import { ExpirationPlugin } from '@serwist/expiration';
2
3
  import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from '@serwist/strategies';
3
4
  import { build, files, prerendered, version } from '$service-worker';
4
- export { build as immutableAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion, files as staticAssets } from '$service-worker';
5
+ export { base as basePath, build as immutableAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion, files as staticAssets } from '$service-worker';
5
6
 
6
- const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true, precachePrerendered = true, staticRevisions } = {})=>{
7
- const staticMapper = (url)=>{
8
- const revision = staticRevisions !== undefined && url in staticRevisions ? staticRevisions[url] : version;
9
- return {
7
+ const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true, precachePrerendered = true, staticRevisions, manifestTransforms } = {})=>{
8
+ const staticMapper = (url)=>({
10
9
  url,
11
- revision
12
- };
13
- };
14
- return [
10
+ revision: typeof staticRevisions === "string" ? staticRevisions : typeof staticRevisions === "object" ? url in staticRevisions ? staticRevisions[url] : version : version
11
+ });
12
+ let precacheManifest = [
15
13
  ...precacheImmutable ? build.map((url)=>({
16
14
  url,
17
15
  revision: null
@@ -22,6 +20,29 @@ const getPrecacheManifest = ({ precacheImmutable = true, precacheStatic = true,
22
20
  revision: version
23
21
  })) : []
24
22
  ];
23
+ if (manifestTransforms) {
24
+ const allWarnings = [];
25
+ for (const transform of manifestTransforms){
26
+ const result = transform(precacheManifest);
27
+ if (!("manifest" in result)) {
28
+ if (process.env.NODE_ENV !== "production") {
29
+ logger.error("The return value from a manifestTransform should be an object with 'manifest' and optionally 'warnings' properties.");
30
+ }
31
+ return undefined;
32
+ }
33
+ precacheManifest = result.manifest;
34
+ allWarnings.push(...result.warnings || []);
35
+ }
36
+ if (process.env.NODE_ENV !== "production" && allWarnings.length > 0) {
37
+ logger.warn("Received warnings while transforming the precache manifest.");
38
+ logger.groupCollapsed("View details here.");
39
+ for (const warning of allWarnings){
40
+ logger.warn(warning);
41
+ }
42
+ logger.groupEnd();
43
+ }
44
+ }
45
+ return precacheManifest;
25
46
  };
26
47
  const defaultIgnoreUrlParameters = [
27
48
  /^x-sveltekit-invalidated$/
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@serwist/svelte",
3
- "version": "9.0.0-preview.12",
3
+ "version": "9.0.0-preview.14",
4
4
  "type": "module",
5
- "description": "A module that integrates Serwist into your Svelte application.",
5
+ "description": "A module that complements SvelteKit's built-in service worker support.",
6
6
  "files": [
7
7
  "src",
8
8
  "dist"
@@ -40,20 +40,21 @@
40
40
  "./package.json": "./package.json"
41
41
  },
42
42
  "dependencies": {
43
- "@serwist/expiration": "9.0.0-preview.12",
44
- "@serwist/strategies": "9.0.0-preview.12"
43
+ "@serwist/core": "9.0.0-preview.14",
44
+ "@serwist/expiration": "9.0.0-preview.14",
45
+ "@serwist/strategies": "9.0.0-preview.14"
45
46
  },
46
47
  "devDependencies": {
47
- "@sveltejs/kit": "2.5.0",
48
- "rollup": "4.9.6",
49
- "@serwist/constants": "9.0.0-preview.12",
50
- "@serwist/precaching": "9.0.0-preview.12",
51
- "@serwist/sw": "9.0.0-preview.12"
48
+ "@sveltejs/kit": "2.5.3",
49
+ "rollup": "4.13.0",
50
+ "@serwist/constants": "9.0.0-preview.14",
51
+ "@serwist/precaching": "9.0.0-preview.14",
52
+ "@serwist/sw": "9.0.0-preview.14"
52
53
  },
53
54
  "peerDependencies": {
54
55
  "@sveltejs/kit": ">=2.0.0",
55
56
  "typescript": ">=5.0.0",
56
- "@serwist/sw": "9.0.0-preview.12"
57
+ "@serwist/sw": "9.0.0-preview.14"
57
58
  },
58
59
  "peerDependenciesMeta": {
59
60
  "@serwist/sw": {
@@ -1,13 +1,25 @@
1
+ import { logger } from "@serwist/core/internal";
1
2
  import { ExpirationPlugin } from "@serwist/expiration";
2
3
  import type { PrecacheEntry } from "@serwist/precaching";
3
4
  import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/strategies";
4
5
  import type { RuntimeCaching } from "@serwist/sw";
5
6
 
6
- import { build as immutableAssets, files as staticAssets, prerendered as prerenderedRoutes, version as serviceWorkerVersion } from "$service-worker";
7
+ import {
8
+ base as basePath,
9
+ build as immutableAssets,
10
+ files as staticAssets,
11
+ prerendered as prerenderedRoutes,
12
+ version as serviceWorkerVersion,
13
+ } from "$service-worker";
7
14
 
8
- export { immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
15
+ export { basePath, immutableAssets, staticAssets, prerenderedRoutes, serviceWorkerVersion };
9
16
 
10
- export type StaticRevisions = { [url: string]: string | null };
17
+ export type StaticRevisions = string | { [url: string]: string | null };
18
+
19
+ export type ManifestTransform = (manifest: PrecacheEntry[]) => {
20
+ manifest: PrecacheEntry[];
21
+ warnings?: string[] | undefined;
22
+ };
11
23
 
12
24
  export interface GetPrecacheManifestOptions {
13
25
  /**
@@ -31,21 +43,28 @@ export interface GetPrecacheManifestOptions {
31
43
  */
32
44
  precachePrerendered?: boolean;
33
45
  /**
34
- * An object that maps URLs of static assets to custom `revision`'s.
35
- * If an URL doesn't exist in the object, `$service-worker.version`
46
+ * A string revision used for all static assets or an object that maps
47
+ * URLs of static assets to custom revisions.
48
+ * If an URL doesn't exist in the object, `serviceWorkerVersion`
36
49
  * will be used instead.
37
50
  *
38
51
  * This helps prevent such assets, which are unlikely to change, from
39
- * being invalidated every time the service worker is installed.
52
+ * being invalidated every time the service worker is rebuilt and updated.
40
53
  *
41
- * Note: you should prefix these URLs with `$service-worker.base`.
54
+ * Note: you should prefix these URLs with `basePath`.
42
55
  */
43
56
  staticRevisions?: StaticRevisions;
57
+ /**
58
+ * One or more functions which will be applied sequentially against the
59
+ * generated manifest.
60
+ */
61
+ manifestTransforms?: ManifestTransform[];
44
62
  }
45
63
 
46
64
  /**
47
- * Retrieves the precache manifest generated by SvelteKit. If further
48
- * modifications are needed, simply mutate the resulting array.
65
+ * Retrieves the precache manifest generated by SvelteKit. A simple
66
+ * wrapper around SvelteKit's built-in service worker support. For more
67
+ * complex use cases, seek [the `@serwist/vite` recipe for SvelteKit](https://serwist.pages.dev/docs/vite/recipes/svelte-kit).
49
68
  *
50
69
  * @param options
51
70
  * @returns
@@ -55,19 +74,50 @@ export const getPrecacheManifest = ({
55
74
  precacheStatic = true,
56
75
  precachePrerendered = true,
57
76
  staticRevisions,
58
- }: GetPrecacheManifestOptions = {}): PrecacheEntry[] => {
59
- const staticMapper = (url: string): PrecacheEntry => {
60
- const revision = staticRevisions !== undefined && url in staticRevisions ? staticRevisions[url] : serviceWorkerVersion;
61
- return { url, revision };
62
- };
63
- return [
77
+ manifestTransforms,
78
+ }: GetPrecacheManifestOptions = {}): PrecacheEntry[] | undefined => {
79
+ const staticMapper = (url: string): PrecacheEntry => ({
80
+ url,
81
+ revision:
82
+ typeof staticRevisions === "string"
83
+ ? staticRevisions
84
+ : typeof staticRevisions === "object"
85
+ ? url in staticRevisions
86
+ ? staticRevisions[url]
87
+ : serviceWorkerVersion
88
+ : serviceWorkerVersion,
89
+ });
90
+ let precacheManifest: PrecacheEntry[] = [
64
91
  // Immutable files generated by Vite.
65
- ...(precacheImmutable ? immutableAssets.map((url) => ({ url, revision: null }) satisfies PrecacheEntry) : []),
92
+ ...(precacheImmutable ? immutableAssets.map((url) => <PrecacheEntry>{ url, revision: null }) : []),
66
93
  // Files in the static directory.
67
94
  ...(precacheStatic ? staticAssets.map(staticMapper) : []),
68
95
  // Prerendered routes.
69
- ...(precachePrerendered ? prerenderedRoutes.map((url) => ({ url, revision: serviceWorkerVersion }) satisfies PrecacheEntry) : []),
96
+ ...(precachePrerendered ? prerenderedRoutes.map((url) => <PrecacheEntry>{ url, revision: serviceWorkerVersion }) : []),
70
97
  ];
98
+ if (manifestTransforms) {
99
+ const allWarnings: string[] = [];
100
+ for (const transform of manifestTransforms) {
101
+ const result = transform(precacheManifest);
102
+ if (!("manifest" in result)) {
103
+ if (process.env.NODE_ENV !== "production") {
104
+ logger.error("The return value from a manifestTransform should be an object with 'manifest' and optionally 'warnings' properties.");
105
+ }
106
+ return undefined;
107
+ }
108
+ precacheManifest = result.manifest;
109
+ allWarnings.push(...(result.warnings || []));
110
+ }
111
+ if (process.env.NODE_ENV !== "production" && allWarnings.length > 0) {
112
+ logger.warn("Received warnings while transforming the precache manifest.");
113
+ logger.groupCollapsed("View details here.");
114
+ for (const warning of allWarnings) {
115
+ logger.warn(warning);
116
+ }
117
+ logger.groupEnd();
118
+ }
119
+ }
120
+ return precacheManifest;
71
121
  };
72
122
 
73
123
  export const defaultIgnoreUrlParameters = [/^x-sveltekit-invalidated$/];