@serwist/next 9.0.0-preview.2 → 9.0.0-preview.20

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.
Files changed (60) hide show
  1. package/dist/chunks/schema.js +20 -0
  2. package/dist/index.d.ts +10 -3
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +49 -30
  5. package/dist/index.schema.d.ts +3 -0
  6. package/dist/index.schema.d.ts.map +1 -0
  7. package/dist/index.schema.js +4 -0
  8. package/dist/index.worker.d.ts +2 -3
  9. package/dist/index.worker.d.ts.map +1 -1
  10. package/dist/index.worker.js +189 -171
  11. package/dist/lib/find-first-truthy.d.ts.map +1 -0
  12. package/dist/lib/get-content-hash.d.ts.map +1 -0
  13. package/dist/lib/get-file-hash.d.ts.map +1 -0
  14. package/dist/lib/get-package-version.d.ts.map +1 -0
  15. package/dist/lib/index.d.ts.map +1 -0
  16. package/dist/lib/load-tsconfig.d.ts.map +1 -0
  17. package/dist/lib/logger.d.ts.map +1 -0
  18. package/dist/lib/schema.d.ts +240 -0
  19. package/dist/lib/schema.d.ts.map +1 -0
  20. package/dist/lib/types.d.ts +95 -0
  21. package/dist/lib/types.d.ts.map +1 -0
  22. package/dist/lib/validator.d.ts +3 -0
  23. package/dist/lib/validator.d.ts.map +1 -0
  24. package/dist/worker/constants.d.ts +6 -0
  25. package/dist/worker/constants.d.ts.map +1 -0
  26. package/dist/worker/defaultCache.d.ts +6 -0
  27. package/dist/worker/defaultCache.d.ts.map +1 -1
  28. package/package.json +32 -25
  29. package/src/index.schema.ts +3 -0
  30. package/src/index.ts +33 -33
  31. package/src/index.worker.ts +2 -3
  32. package/src/lib/schema.ts +21 -0
  33. package/src/lib/types.ts +104 -0
  34. package/src/lib/validator.ts +13 -0
  35. package/src/worker/constants.ts +5 -0
  36. package/src/worker/defaultCache.ts +266 -219
  37. package/dist/utils/find-first-truthy.d.ts.map +0 -1
  38. package/dist/utils/get-content-hash.d.ts.map +0 -1
  39. package/dist/utils/get-file-hash.d.ts.map +0 -1
  40. package/dist/utils/get-package-version.d.ts.map +0 -1
  41. package/dist/utils/index.d.ts.map +0 -1
  42. package/dist/utils/load-tsconfig.d.ts.map +0 -1
  43. package/dist/utils/logger.d.ts.map +0 -1
  44. package/dist/worker/definePageRuntimeCaching.d.ts +0 -16
  45. package/dist/worker/definePageRuntimeCaching.d.ts.map +0 -1
  46. package/src/worker/definePageRuntimeCaching.ts +0 -36
  47. /package/dist/{utils → lib}/find-first-truthy.d.ts +0 -0
  48. /package/dist/{utils → lib}/get-content-hash.d.ts +0 -0
  49. /package/dist/{utils → lib}/get-file-hash.d.ts +0 -0
  50. /package/dist/{utils → lib}/get-package-version.d.ts +0 -0
  51. /package/dist/{utils → lib}/index.d.ts +0 -0
  52. /package/dist/{utils → lib}/load-tsconfig.d.ts +0 -0
  53. /package/dist/{utils → lib}/logger.d.ts +0 -0
  54. /package/src/{utils → lib}/find-first-truthy.ts +0 -0
  55. /package/src/{utils → lib}/get-content-hash.ts +0 -0
  56. /package/src/{utils → lib}/get-file-hash.ts +0 -0
  57. /package/src/{utils → lib}/get-package-version.ts +0 -0
  58. /package/src/{utils → lib}/index.ts +0 -0
  59. /package/src/{utils → lib}/load-tsconfig.ts +0 -0
  60. /package/src/{utils → lib}/logger.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAsCA,eAAO,MAAM,IAAI,eAAgB,GAAG,EAAE,SAErC,CAAC;AAEF,eAAO,MAAM,KAAK,eAAgB,GAAG,EAAE,SAEtC,CAAC;AAEF,eAAO,MAAM,IAAI,eAAgB,GAAG,EAAE,SAErC,CAAC;AAEF,eAAO,MAAM,IAAI,eAAgB,GAAG,EAAE,SAErC,CAAC;AAEF,eAAO,MAAM,KAAK,eAAgB,GAAG,EAAE,SAEtC,CAAC"}
@@ -0,0 +1,240 @@
1
+ import { z } from "zod";
2
+ export declare const injectPartial: z.ZodObject<{
3
+ cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
4
+ disable: z.ZodDefault<z.ZodBoolean>;
5
+ register: z.ZodDefault<z.ZodBoolean>;
6
+ reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
7
+ scope: z.ZodOptional<z.ZodString>;
8
+ swUrl: z.ZodDefault<z.ZodString>;
9
+ globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
10
+ }, "strict", z.ZodTypeAny, {
11
+ cacheOnNavigation: boolean;
12
+ disable: boolean;
13
+ register: boolean;
14
+ reloadOnOnline: boolean;
15
+ swUrl: string;
16
+ globPublicPatterns: string[];
17
+ scope?: string | undefined;
18
+ }, {
19
+ cacheOnNavigation?: boolean | undefined;
20
+ disable?: boolean | undefined;
21
+ register?: boolean | undefined;
22
+ reloadOnOnline?: boolean | undefined;
23
+ scope?: string | undefined;
24
+ swUrl?: string | undefined;
25
+ globPublicPatterns?: string[] | undefined;
26
+ }>;
27
+ export declare const injectManifestOptions: z.ZodObject<Omit<{
28
+ chunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
29
+ exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
30
+ excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
31
+ include: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
32
+ additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
33
+ integrity: z.ZodOptional<z.ZodString>;
34
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
+ url: z.ZodString;
36
+ }, "strict", z.ZodTypeAny, {
37
+ url: string;
38
+ integrity?: string | undefined;
39
+ revision?: string | null | undefined;
40
+ }, {
41
+ url: string;
42
+ integrity?: string | undefined;
43
+ revision?: string | null | undefined;
44
+ }>]>, "many">>;
45
+ disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
46
+ dontCacheBustURLsMatching: z.ZodOptional<z.ZodType<RegExp, z.ZodTypeDef, RegExp>>;
47
+ manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodObject<{
48
+ integrity: z.ZodOptional<z.ZodString>;
49
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
+ url: z.ZodString;
51
+ size: z.ZodNumber;
52
+ }, "strip", z.ZodTypeAny, {
53
+ url: string;
54
+ size: number;
55
+ integrity?: string | undefined;
56
+ revision?: string | null | undefined;
57
+ }, {
58
+ url: string;
59
+ size: number;
60
+ integrity?: string | undefined;
61
+ revision?: string | null | undefined;
62
+ }>, "many">, z.ZodOptional<z.ZodUnknown>], null>, z.ZodUnion<[z.ZodPromise<z.ZodObject<{
63
+ manifest: z.ZodArray<z.ZodObject<{
64
+ integrity: z.ZodOptional<z.ZodString>;
65
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
66
+ url: z.ZodString;
67
+ size: z.ZodNumber;
68
+ }, "strip", z.ZodTypeAny, {
69
+ url: string;
70
+ size: number;
71
+ integrity?: string | undefined;
72
+ revision?: string | null | undefined;
73
+ }, {
74
+ url: string;
75
+ size: number;
76
+ integrity?: string | undefined;
77
+ revision?: string | null | undefined;
78
+ }>, "many">;
79
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
80
+ }, "strict", z.ZodTypeAny, {
81
+ manifest: {
82
+ url: string;
83
+ size: number;
84
+ integrity?: string | undefined;
85
+ revision?: string | null | undefined;
86
+ }[];
87
+ warnings?: string[] | undefined;
88
+ }, {
89
+ manifest: {
90
+ url: string;
91
+ size: number;
92
+ integrity?: string | undefined;
93
+ revision?: string | null | undefined;
94
+ }[];
95
+ warnings?: string[] | undefined;
96
+ }>>, z.ZodObject<{
97
+ manifest: z.ZodArray<z.ZodObject<{
98
+ integrity: z.ZodOptional<z.ZodString>;
99
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
100
+ url: z.ZodString;
101
+ size: z.ZodNumber;
102
+ }, "strip", z.ZodTypeAny, {
103
+ url: string;
104
+ size: number;
105
+ integrity?: string | undefined;
106
+ revision?: string | null | undefined;
107
+ }, {
108
+ url: string;
109
+ size: number;
110
+ integrity?: string | undefined;
111
+ revision?: string | null | undefined;
112
+ }>, "many">;
113
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
114
+ }, "strict", z.ZodTypeAny, {
115
+ manifest: {
116
+ url: string;
117
+ size: number;
118
+ integrity?: string | undefined;
119
+ revision?: string | null | undefined;
120
+ }[];
121
+ warnings?: string[] | undefined;
122
+ }, {
123
+ manifest: {
124
+ url: string;
125
+ size: number;
126
+ integrity?: string | undefined;
127
+ revision?: string | null | undefined;
128
+ }[];
129
+ warnings?: string[] | undefined;
130
+ }>]>>, "many">>;
131
+ maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
132
+ modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
133
+ injectionPoint: z.ZodDefault<z.ZodString>;
134
+ swSrc: z.ZodString;
135
+ compileSrc: z.ZodDefault<z.ZodBoolean>;
136
+ swDest: z.ZodString;
137
+ webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
138
+ cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
139
+ disable: z.ZodDefault<z.ZodBoolean>;
140
+ register: z.ZodDefault<z.ZodBoolean>;
141
+ reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
142
+ scope: z.ZodOptional<z.ZodString>;
143
+ swUrl: z.ZodDefault<z.ZodString>;
144
+ globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
145
+ }, "disablePrecacheManifest">, "strict", z.ZodTypeAny, {
146
+ cacheOnNavigation: boolean;
147
+ disable: boolean;
148
+ register: boolean;
149
+ reloadOnOnline: boolean;
150
+ swUrl: string;
151
+ globPublicPatterns: string[];
152
+ exclude: (string | RegExp | ((args_0: any) => boolean))[];
153
+ maximumFileSizeToCacheInBytes: number;
154
+ injectionPoint: string;
155
+ swSrc: string;
156
+ compileSrc: boolean;
157
+ swDest: string;
158
+ scope?: string | undefined;
159
+ chunks?: string[] | undefined;
160
+ excludeChunks?: string[] | undefined;
161
+ include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
162
+ additionalPrecacheEntries?: (string | {
163
+ url: string;
164
+ integrity?: string | undefined;
165
+ revision?: string | null | undefined;
166
+ })[] | undefined;
167
+ dontCacheBustURLsMatching?: RegExp | undefined;
168
+ manifestTransforms?: ((args_0: {
169
+ url: string;
170
+ size: number;
171
+ integrity?: string | undefined;
172
+ revision?: string | null | undefined;
173
+ }[], args_1: unknown) => {
174
+ manifest: {
175
+ url: string;
176
+ size: number;
177
+ integrity?: string | undefined;
178
+ revision?: string | null | undefined;
179
+ }[];
180
+ warnings?: string[] | undefined;
181
+ } | Promise<{
182
+ manifest: {
183
+ url: string;
184
+ size: number;
185
+ integrity?: string | undefined;
186
+ revision?: string | null | undefined;
187
+ }[];
188
+ warnings?: string[] | undefined;
189
+ }>)[] | undefined;
190
+ modifyURLPrefix?: Record<string, string> | undefined;
191
+ webpackCompilationPlugins?: any[] | undefined;
192
+ }, {
193
+ swSrc: string;
194
+ swDest: string;
195
+ cacheOnNavigation?: boolean | undefined;
196
+ disable?: boolean | undefined;
197
+ register?: boolean | undefined;
198
+ reloadOnOnline?: boolean | undefined;
199
+ scope?: string | undefined;
200
+ swUrl?: string | undefined;
201
+ globPublicPatterns?: string[] | undefined;
202
+ chunks?: string[] | undefined;
203
+ exclude?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
204
+ excludeChunks?: string[] | undefined;
205
+ include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
206
+ additionalPrecacheEntries?: (string | {
207
+ url: string;
208
+ integrity?: string | undefined;
209
+ revision?: string | null | undefined;
210
+ })[] | undefined;
211
+ dontCacheBustURLsMatching?: RegExp | undefined;
212
+ manifestTransforms?: ((args_0: {
213
+ url: string;
214
+ size: number;
215
+ integrity?: string | undefined;
216
+ revision?: string | null | undefined;
217
+ }[], args_1: unknown) => {
218
+ manifest: {
219
+ url: string;
220
+ size: number;
221
+ integrity?: string | undefined;
222
+ revision?: string | null | undefined;
223
+ }[];
224
+ warnings?: string[] | undefined;
225
+ } | Promise<{
226
+ manifest: {
227
+ url: string;
228
+ size: number;
229
+ integrity?: string | undefined;
230
+ revision?: string | null | undefined;
231
+ }[];
232
+ warnings?: string[] | undefined;
233
+ }>)[] | undefined;
234
+ maximumFileSizeToCacheInBytes?: number | undefined;
235
+ modifyURLPrefix?: Record<string, string> | undefined;
236
+ injectionPoint?: string | undefined;
237
+ compileSrc?: boolean | undefined;
238
+ webpackCompilationPlugins?: any[] | undefined;
239
+ }>;
240
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;EAU+C,CAAC;AAE1E,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIuC,CAAC"}
@@ -0,0 +1,95 @@
1
+ import type { RequiredSwDestPartial, RequiredSwDestResolved } from "@serwist/build";
2
+ import type { Require } from "@serwist/utils";
3
+ import type { InjectManifestOptions as WebpackInjectManifestOptions, InjectManifestOptionsComplete as WebpackInjectManifestOptionsComplete } from "@serwist/webpack-plugin";
4
+ export interface InjectPartial {
5
+ /**
6
+ * Enables additional route caching when users navigate through pages with
7
+ * `next/link`. This improves the user experience in some cases but it
8
+ * also adds a bit of overhead due to additional network calls.
9
+ * @default false
10
+ */
11
+ cacheOnNavigation?: boolean;
12
+ /**
13
+ * Whether Serwist should be disabled.
14
+ * @default false
15
+ */
16
+ disable?: boolean;
17
+ /**
18
+ * Whether `@serwist/next` should automatically register the service worker for you. If
19
+ * you want to register the service worker yourself, set this to `false` and run
20
+ * `window.serwist.register()` in `componentDidMount` or `useEffect`.
21
+ * @example
22
+ * ```tsx
23
+ * // app/register-pwa.tsx
24
+ * "use client";
25
+ * import { useEffect } from "react";
26
+ * import type { Serwist } from "@serwist/window";
27
+ *
28
+ * declare global {
29
+ * interface Window {
30
+ * serwist: Serwist;
31
+ * }
32
+ * }
33
+ *
34
+ * export default function RegisterPWA() {
35
+ * useEffect(() => {
36
+ * if ("serviceWorker" in navigator && window.serwist !== undefined) {
37
+ * window.serwist.register();
38
+ * }
39
+ * }, []);
40
+ * return <></>;
41
+ * }
42
+ *
43
+ * // app/layout.tsx
44
+ * import RegisterPWA from "./register-pwa";
45
+ *
46
+ * export default function RootLayout({
47
+ * children,
48
+ * }: {
49
+ * children: React.ReactNode;
50
+ * }) {
51
+ * return (
52
+ * <html lang="en">
53
+ * <head />
54
+ * <body>
55
+ * <RegisterPWA />
56
+ * {children}
57
+ * </body>
58
+ * </html>
59
+ * );
60
+ * }
61
+ * ```
62
+ * @default true
63
+ */
64
+ register?: boolean;
65
+ /**
66
+ * Whether Serwist should reload the app when it goes online.
67
+ * @default true
68
+ */
69
+ reloadOnOnline?: boolean;
70
+ /**
71
+ * The service worker's URL scope. Set to `/foo/` so that paths under `/foo/` are under the service
72
+ * worker's control while others are not.
73
+ * @default nextConfig.basePath
74
+ */
75
+ scope?: string;
76
+ /**
77
+ * The URL to the service worker.
78
+ * @default "/sw.js"
79
+ */
80
+ swUrl?: string;
81
+ /**
82
+ * Files in the public directory matching any of these patterns
83
+ * will be included in the precache manifest. For more information,
84
+ * see [`node-glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
85
+ * @default
86
+ * ```
87
+ * ["**\/*"]
88
+ * ```
89
+ */
90
+ globPublicPatterns?: string[];
91
+ }
92
+ export type InjectResolved = Require<InjectPartial, "cacheOnNavigation" | "disable" | "register" | "reloadOnOnline" | "swUrl" | "globPublicPatterns">;
93
+ export type InjectManifestOptions = Omit<WebpackInjectManifestOptions & RequiredSwDestPartial & InjectPartial, "disablePrecacheManifest">;
94
+ export type InjectManifestOptionsComplete = Omit<WebpackInjectManifestOptionsComplete & RequiredSwDestResolved & InjectResolved, "disablePrecacheManifest">;
95
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EACV,qBAAqB,IAAI,4BAA4B,EACrD,6BAA6B,IAAI,oCAAoC,EACtE,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,mBAAmB,GAAG,SAAS,GAAG,UAAU,GAAG,gBAAgB,GAAG,OAAO,GAAG,oBAAoB,CAAC,CAAC;AAEtJ,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,4BAA4B,GAAG,qBAAqB,GAAG,aAAa,EAAE,yBAAyB,CAAC,CAAC;AAE1I,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,oCAAoC,GAAG,sBAAsB,GAAG,cAAc,EAC9E,yBAAyB,CAC1B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { InjectManifestOptionsComplete } from "./types.js";
2
+ export declare const validateInjectManifestOptions: (input: unknown) => InjectManifestOptionsComplete;
3
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,6BAA6B,UAAW,OAAO,KAAG,6BAQ9D,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const PAGES_CACHE_NAME: {
2
+ readonly rscPrefetch: "pages-rsc-prefetch";
3
+ readonly rsc: "pages-rsc";
4
+ readonly html: "pages";
5
+ };
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/worker/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC"}
@@ -1,3 +1,9 @@
1
1
  import type { RuntimeCaching } from "@serwist/sw";
2
+ /**
3
+ * The default, recommended list of caching strategies for applications
4
+ * built with Next.js.
5
+ *
6
+ * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
7
+ */
2
8
  export declare const defaultCache: RuntimeCaching[];
3
9
  //# sourceMappingURL=defaultCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIlD,eAAO,MAAM,YAAY,kBA0NG,CAAC"}
1
+ {"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMlD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,EAAE,cAAc,EAiQlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "9.0.0-preview.2",
3
+ "version": "9.0.0-preview.20",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -12,16 +12,21 @@
12
12
  "serwistjs",
13
13
  "sw",
14
14
  "service worker",
15
+ "progressive web apps",
15
16
  "web",
16
- "service-worker"
17
+ "service-worker",
18
+ "progressive-web-apps",
19
+ "next",
20
+ "next.js",
21
+ "pwa"
17
22
  ],
18
23
  "engines": {
19
24
  "node": ">=18.0.0"
20
25
  },
21
26
  "author": "Serwist's Team",
22
27
  "license": "MIT",
23
- "repository": "serwist/serwist",
24
- "bugs": "https://github.com/serwist/serwist/issues",
28
+ "repository": "https://gitlab.com/serwist/serwist",
29
+ "bugs": "https://gitlab.com/serwist/serwist/issues",
25
30
  "homepage": "https://serwist.pages.dev",
26
31
  "main": "./dist/index.js",
27
32
  "types": "./dist/index.d.ts",
@@ -32,6 +37,9 @@
32
37
  ],
33
38
  "typings": [
34
39
  "./dist/sw-entry.d.ts"
40
+ ],
41
+ "schema": [
42
+ "./dist/index.schema.d.ts"
35
43
  ]
36
44
  }
37
45
  },
@@ -47,40 +55,39 @@
47
55
  "./typings": {
48
56
  "types": "./dist/sw-entry.d.ts"
49
57
  },
58
+ "./schema": {
59
+ "types": "./dist/index.schema.d.ts",
60
+ "default": "./dist/index.schema.js"
61
+ },
50
62
  "./package.json": "./package.json"
51
63
  },
52
64
  "dependencies": {
53
65
  "chalk": "5.3.0",
54
- "clean-webpack-plugin": "4.0.0",
55
- "fast-glob": "3.3.2",
56
- "@serwist/build": "9.0.0-preview.2",
57
- "@serwist/core": "9.0.0-preview.2",
58
- "@serwist/webpack-plugin": "9.0.0-preview.2",
59
- "@serwist/window": "9.0.0-preview.2"
66
+ "glob": "10.3.10",
67
+ "zod": "3.22.4",
68
+ "@serwist/build": "9.0.0-preview.20",
69
+ "@serwist/core": "9.0.0-preview.20",
70
+ "@serwist/sw": "9.0.0-preview.20",
71
+ "@serwist/webpack-plugin": "9.0.0-preview.20",
72
+ "@serwist/window": "9.0.0-preview.20"
60
73
  },
61
74
  "devDependencies": {
62
- "@types/node": "20.11.16",
63
- "next": "14.1.0",
75
+ "@types/node": "20.11.30",
76
+ "next": "14.1.4",
64
77
  "react": "18.2.0",
65
78
  "react-dom": "18.2.0",
66
- "rollup": "4.9.6",
67
- "type-fest": "4.10.2",
68
- "typescript": "5.4.0-dev.20240206",
69
- "webpack": "5.90.1",
70
- "@serwist/constants": "9.0.0-preview.2",
71
- "@serwist/sw": "9.0.0-preview.2",
72
- "@serwist/utils": "9.0.0-preview.2"
79
+ "rollup": "4.13.0",
80
+ "type-fest": "4.13.1",
81
+ "typescript": "5.5.0-dev.20240323",
82
+ "webpack": "5.91.0",
83
+ "@serwist/constants": "9.0.0-preview.20",
84
+ "@serwist/utils": "9.0.0-preview.20"
73
85
  },
74
86
  "peerDependencies": {
75
87
  "next": ">=14.0.0",
76
- "typescript": ">=5.0.0",
77
- "webpack": ">=5.9.0",
78
- "@serwist/sw": "9.0.0-preview.2"
88
+ "typescript": ">=5.0.0"
79
89
  },
80
90
  "peerDependenciesMeta": {
81
- "@serwist/sw": {
82
- "optional": true
83
- },
84
91
  "typescript": {
85
92
  "optional": true
86
93
  }
@@ -0,0 +1,3 @@
1
+ import { injectManifestOptions, injectPartial } from "./lib/schema.js";
2
+
3
+ export { injectPartial, injectManifestOptions };
package/src/index.ts CHANGED
@@ -1,21 +1,24 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
2
3
  import { fileURLToPath } from "node:url";
3
-
4
- import type { NextInjectManifestOptions } from "@serwist/build";
5
- import { validateNextInjectManifestOptions } from "@serwist/build/next";
6
4
  import { InjectManifest } from "@serwist/webpack-plugin";
7
5
  import { ChildCompilationPlugin, relativeToOutputPath } from "@serwist/webpack-plugin/internal";
8
- import { CleanWebpackPlugin } from "clean-webpack-plugin";
9
- import fg from "fast-glob";
6
+ import { globSync } from "glob";
10
7
  import type { NextConfig } from "next";
11
8
  import type { Compilation, Configuration, default as Webpack } from "webpack";
12
-
13
9
  import type { ExcludeParams, SerwistNextOptions, SerwistNextOptionsKey } from "./internal-types.js";
14
- import { getContentHash, getFileHash, loadTSConfig, logger } from "./utils/index.js";
10
+ import { getContentHash, getFileHash, loadTSConfig, logger } from "./lib/index.js";
11
+ import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
12
+ import { validateInjectManifestOptions } from "./lib/validator.js";
15
13
 
16
14
  const __dirname = fileURLToPath(new URL(".", import.meta.url));
17
15
 
18
- const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig?: NextConfig) => NextConfig) => {
16
+ /**
17
+ * Integrates Serwist into your Next.js app.
18
+ * @param userOptions
19
+ * @returns
20
+ */
21
+ const withSerwistInit = (userOptions: InjectManifestOptions): ((nextConfig?: NextConfig) => NextConfig) => {
19
22
  return (nextConfig = {}) => ({
20
23
  ...nextConfig,
21
24
  webpack(config: Configuration, options) {
@@ -35,7 +38,7 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
35
38
  reloadOnOnline,
36
39
  globPublicPatterns,
37
40
  ...buildOptions
38
- } = validateNextInjectManifestOptions(pluginOptions);
41
+ } = validateInjectManifestOptions(userOptions);
39
42
 
40
43
  if (typeof nextConfig.webpack === "function") {
41
44
  config = nextConfig.webpack(config, options);
@@ -95,7 +98,7 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
95
98
  logger.info(" window.serwist.register()");
96
99
 
97
100
  if (!tsConfigJson?.compilerOptions?.types?.includes("@serwist/next/typings")) {
98
- logger.info("You may also want to add @serwist/next/typings to compilerOptions.types in your tsconfig.json/jsconfig.json.");
101
+ logger.info("You may also want to add '@serwist/next/typings' to compilerOptions.types in your tsconfig.json/jsconfig.json.");
99
102
  }
100
103
  }
101
104
 
@@ -122,7 +125,19 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
122
125
  }
123
126
 
124
127
  const publicDir = path.resolve(options.dir, "public");
125
- const destDir = path.dirname(swDest);
128
+ const { dir: destDir, base: destBase } = path.parse(swDest);
129
+
130
+ const cleanUpList = globSync(["swe-worker-*.js", "swe-worker-*.js.map", destBase, `${destBase}.map`], {
131
+ absolute: true,
132
+ nodir: true,
133
+ cwd: destDir,
134
+ });
135
+
136
+ for (const file of cleanUpList) {
137
+ fs.rm(file, { force: true }, (err) => {
138
+ if (err) throw err;
139
+ });
140
+ }
126
141
 
127
142
  const shouldBuildSWEntryWorker = cacheOnNavigation;
128
143
  let swEntryPublicPath: string | undefined = undefined;
@@ -150,31 +165,15 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
150
165
  logger.info(` URL: ${_sw}`);
151
166
  logger.info(` Scope: ${_scope}`);
152
167
 
153
- config.plugins.push(
154
- new CleanWebpackPlugin({
155
- cleanOnceBeforeBuildPatterns: [path.join(destDir, "swe-worker-*.js"), path.join(destDir, "swe-worker-*.js.map"), swDest],
156
- }),
157
- );
158
-
159
168
  // Precache files in public folder
160
169
  let resolvedManifestEntries = additionalPrecacheEntries;
161
170
 
162
171
  if (!resolvedManifestEntries) {
163
- const swDestFileName = path.basename(swDest);
164
- const userPublicGlob = typeof globPublicPatterns === "string" ? [globPublicPatterns] : globPublicPatterns ?? ["**/*"];
165
- const publicScan = fg.sync(
166
- [
167
- ...userPublicGlob,
168
- // Forcibly include these in case the user outputs these files to `public`.
169
- "!swe-worker-*.js",
170
- "!swe-worker-*.js.map",
171
- `!${swDestFileName.replace(/^\/+/, "")}`,
172
- `!${swDestFileName.replace(/^\/+/, "")}.map`,
173
- ],
174
- {
175
- cwd: publicDir,
176
- },
177
- );
172
+ const publicScan = globSync(globPublicPatterns, {
173
+ nodir: true,
174
+ cwd: publicDir,
175
+ ignore: ["swe-worker-*.js", destBase, `${destBase}.map`],
176
+ });
178
177
  resolvedManifestEntries = publicScan.map((f) => ({
179
178
  url: path.posix.join(basePath, f),
180
179
  revision: getFileHash(path.join(publicDir, f)),
@@ -238,4 +237,5 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
238
237
  };
239
238
 
240
239
  export default withSerwistInit;
241
- export type { NextInjectManifestOptions as PluginOptions };
240
+ export { validateInjectManifestOptions };
241
+ export type { InjectManifestOptions as PluginOptions, InjectManifestOptionsComplete as PluginOptionsComplete };
@@ -1,5 +1,4 @@
1
+ import { PAGES_CACHE_NAME } from "./worker/constants.js";
1
2
  import { defaultCache } from "./worker/defaultCache.js";
2
- import { type DefinePageRuntimeCachingOptions, type PageRuntimeCaching, definePageRuntimeCaching } from "./worker/definePageRuntimeCaching.js";
3
3
 
4
- export { defaultCache, definePageRuntimeCaching };
5
- export type { DefinePageRuntimeCachingOptions, PageRuntimeCaching };
4
+ export { defaultCache, PAGES_CACHE_NAME };
@@ -0,0 +1,21 @@
1
+ import { requiredSwDestPartial } from "@serwist/build/schema";
2
+ import { injectManifestOptions as webpackInjectManifestOptions } from "@serwist/webpack-plugin/schema";
3
+ import { z } from "zod";
4
+
5
+ export const injectPartial = z
6
+ .object({
7
+ cacheOnNavigation: z.boolean().default(false),
8
+ disable: z.boolean().default(false),
9
+ register: z.boolean().default(true),
10
+ reloadOnOnline: z.boolean().default(true),
11
+ scope: z.string().optional(),
12
+ swUrl: z.string().default("/sw.js"),
13
+ globPublicPatterns: z.array(z.string()).default(["**/*"]),
14
+ })
15
+ .strict("Do not pass invalid properties to NextInjectManifestPartial!");
16
+
17
+ export const injectManifestOptions = webpackInjectManifestOptions
18
+ .merge(requiredSwDestPartial)
19
+ .merge(injectPartial)
20
+ .omit({ disablePrecacheManifest: true })
21
+ .strict("Do not pass invalid properties to NextInjectManifestOptions!");