@serwist/next 9.0.0-preview.2 → 9.0.0-preview.21
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/chunks/schema.js +20 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -30
- package/dist/index.schema.d.ts +3 -0
- package/dist/index.schema.d.ts.map +1 -0
- package/dist/index.schema.js +4 -0
- package/dist/index.worker.d.ts +2 -3
- package/dist/index.worker.d.ts.map +1 -1
- package/dist/index.worker.js +189 -171
- package/dist/lib/find-first-truthy.d.ts.map +1 -0
- package/dist/lib/get-content-hash.d.ts.map +1 -0
- package/dist/lib/get-file-hash.d.ts.map +1 -0
- package/dist/lib/get-package-version.d.ts.map +1 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/load-tsconfig.d.ts.map +1 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/schema.d.ts +240 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/types.d.ts +95 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/validator.d.ts +3 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/worker/constants.d.ts +6 -0
- package/dist/worker/constants.d.ts.map +1 -0
- package/dist/worker/defaultCache.d.ts +6 -0
- package/dist/worker/defaultCache.d.ts.map +1 -1
- package/package.json +32 -25
- package/src/index.schema.ts +3 -0
- package/src/index.ts +33 -33
- package/src/index.worker.ts +2 -3
- package/src/lib/schema.ts +21 -0
- package/src/lib/types.ts +104 -0
- package/src/lib/validator.ts +13 -0
- package/src/worker/constants.ts +5 -0
- package/src/worker/defaultCache.ts +266 -219
- package/dist/utils/find-first-truthy.d.ts.map +0 -1
- package/dist/utils/get-content-hash.d.ts.map +0 -1
- package/dist/utils/get-file-hash.d.ts.map +0 -1
- package/dist/utils/get-package-version.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/load-tsconfig.d.ts.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/worker/definePageRuntimeCaching.d.ts +0 -16
- package/dist/worker/definePageRuntimeCaching.d.ts.map +0 -1
- package/src/worker/definePageRuntimeCaching.ts +0 -36
- /package/dist/{utils → lib}/find-first-truthy.d.ts +0 -0
- /package/dist/{utils → lib}/get-content-hash.d.ts +0 -0
- /package/dist/{utils → lib}/get-file-hash.d.ts +0 -0
- /package/dist/{utils → lib}/get-package-version.d.ts +0 -0
- /package/dist/{utils → lib}/index.d.ts +0 -0
- /package/dist/{utils → lib}/load-tsconfig.d.ts +0 -0
- /package/dist/{utils → lib}/logger.d.ts +0 -0
- /package/src/{utils → lib}/find-first-truthy.ts +0 -0
- /package/src/{utils → lib}/get-content-hash.ts +0 -0
- /package/src/{utils → lib}/get-file-hash.ts +0 -0
- /package/src/{utils → lib}/get-package-version.ts +0 -0
- /package/src/{utils → lib}/index.ts +0 -0
- /package/src/{utils → lib}/load-tsconfig.ts +0 -0
- /package/src/{utils → lib}/logger.ts +0 -0
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { RequiredSwDestPartial, RequiredSwDestResolved } from "@serwist/build";
|
|
2
|
+
import type { Require } from "@serwist/utils";
|
|
3
|
+
import type {
|
|
4
|
+
InjectManifestOptions as WebpackInjectManifestOptions,
|
|
5
|
+
InjectManifestOptionsComplete as WebpackInjectManifestOptionsComplete,
|
|
6
|
+
} from "@serwist/webpack-plugin";
|
|
7
|
+
|
|
8
|
+
export interface InjectPartial {
|
|
9
|
+
/**
|
|
10
|
+
* Enables additional route caching when users navigate through pages with
|
|
11
|
+
* `next/link`. This improves the user experience in some cases but it
|
|
12
|
+
* also adds a bit of overhead due to additional network calls.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
cacheOnNavigation?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether Serwist should be disabled.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
disable?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether `@serwist/next` should automatically register the service worker for you. If
|
|
23
|
+
* you want to register the service worker yourself, set this to `false` and run
|
|
24
|
+
* `window.serwist.register()` in `componentDidMount` or `useEffect`.
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* // app/register-pwa.tsx
|
|
28
|
+
* "use client";
|
|
29
|
+
* import { useEffect } from "react";
|
|
30
|
+
* import type { Serwist } from "@serwist/window";
|
|
31
|
+
*
|
|
32
|
+
* declare global {
|
|
33
|
+
* interface Window {
|
|
34
|
+
* serwist: Serwist;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* export default function RegisterPWA() {
|
|
39
|
+
* useEffect(() => {
|
|
40
|
+
* if ("serviceWorker" in navigator && window.serwist !== undefined) {
|
|
41
|
+
* window.serwist.register();
|
|
42
|
+
* }
|
|
43
|
+
* }, []);
|
|
44
|
+
* return <></>;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* // app/layout.tsx
|
|
48
|
+
* import RegisterPWA from "./register-pwa";
|
|
49
|
+
*
|
|
50
|
+
* export default function RootLayout({
|
|
51
|
+
* children,
|
|
52
|
+
* }: {
|
|
53
|
+
* children: React.ReactNode;
|
|
54
|
+
* }) {
|
|
55
|
+
* return (
|
|
56
|
+
* <html lang="en">
|
|
57
|
+
* <head />
|
|
58
|
+
* <body>
|
|
59
|
+
* <RegisterPWA />
|
|
60
|
+
* {children}
|
|
61
|
+
* </body>
|
|
62
|
+
* </html>
|
|
63
|
+
* );
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
* @default true
|
|
67
|
+
*/
|
|
68
|
+
register?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether Serwist should reload the app when it goes online.
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
reloadOnOnline?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The service worker's URL scope. Set to `/foo/` so that paths under `/foo/` are under the service
|
|
76
|
+
* worker's control while others are not.
|
|
77
|
+
* @default nextConfig.basePath
|
|
78
|
+
*/
|
|
79
|
+
scope?: string;
|
|
80
|
+
/**
|
|
81
|
+
* The URL to the service worker.
|
|
82
|
+
* @default "/sw.js"
|
|
83
|
+
*/
|
|
84
|
+
swUrl?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Files in the public directory matching any of these patterns
|
|
87
|
+
* will be included in the precache manifest. For more information,
|
|
88
|
+
* see [`node-glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
|
|
89
|
+
* @default
|
|
90
|
+
* ```
|
|
91
|
+
* ["**\/*"]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
globPublicPatterns?: string[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type InjectResolved = Require<InjectPartial, "cacheOnNavigation" | "disable" | "register" | "reloadOnOnline" | "swUrl" | "globPublicPatterns">;
|
|
98
|
+
|
|
99
|
+
export type InjectManifestOptions = Omit<WebpackInjectManifestOptions & RequiredSwDestPartial & InjectPartial, "disablePrecacheManifest">;
|
|
100
|
+
|
|
101
|
+
export type InjectManifestOptionsComplete = Omit<
|
|
102
|
+
WebpackInjectManifestOptionsComplete & RequiredSwDestResolved & InjectResolved,
|
|
103
|
+
"disablePrecacheManifest"
|
|
104
|
+
>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
|
|
2
|
+
import { injectManifestOptions } from "./schema.js";
|
|
3
|
+
import type { InjectManifestOptionsComplete } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export const validateInjectManifestOptions = (input: unknown): InjectManifestOptionsComplete => {
|
|
6
|
+
const result = injectManifestOptions.safeParse(input, {
|
|
7
|
+
errorMap: validationErrorMap,
|
|
8
|
+
});
|
|
9
|
+
if (!result.success) {
|
|
10
|
+
throw new SerwistConfigError({ moduleName: "@serwist/next", message: JSON.stringify(result.error.format(), null, 2) });
|
|
11
|
+
}
|
|
12
|
+
return result.data;
|
|
13
|
+
};
|
|
@@ -1,223 +1,270 @@
|
|
|
1
1
|
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
import {
|
|
2
|
+
import { ExpirationPlugin, RangeRequestsPlugin } from "@serwist/sw/plugins";
|
|
3
|
+
import { CacheFirst, NetworkFirst, StaleWhileRevalidate } from "@serwist/sw/strategies";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
export const defaultCache = [
|
|
6
|
-
{
|
|
7
|
-
urlPattern: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
8
|
-
handler: "CacheFirst",
|
|
9
|
-
options: {
|
|
10
|
-
cacheName: "google-fonts-webfonts",
|
|
11
|
-
expiration: {
|
|
12
|
-
maxEntries: 4,
|
|
13
|
-
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
urlPattern: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
19
|
-
handler: "StaleWhileRevalidate",
|
|
20
|
-
options: {
|
|
21
|
-
cacheName: "google-fonts-stylesheets",
|
|
22
|
-
expiration: {
|
|
23
|
-
maxEntries: 4,
|
|
24
|
-
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
30
|
-
handler: "StaleWhileRevalidate",
|
|
31
|
-
options: {
|
|
32
|
-
cacheName: "static-font-assets",
|
|
33
|
-
expiration: {
|
|
34
|
-
maxEntries: 4,
|
|
35
|
-
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
41
|
-
handler: "StaleWhileRevalidate",
|
|
42
|
-
options: {
|
|
43
|
-
cacheName: "static-image-assets",
|
|
44
|
-
expiration: {
|
|
45
|
-
maxEntries: 64,
|
|
46
|
-
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
urlPattern: /\/_next\/static.+\.js$/i,
|
|
52
|
-
handler: "CacheFirst",
|
|
53
|
-
options: {
|
|
54
|
-
cacheName: "next-static-js-assets",
|
|
55
|
-
expiration: {
|
|
56
|
-
maxEntries: 64,
|
|
57
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
urlPattern: /\/_next\/image\?url=.+$/i,
|
|
63
|
-
handler: "StaleWhileRevalidate",
|
|
64
|
-
options: {
|
|
65
|
-
cacheName: "next-image",
|
|
66
|
-
expiration: {
|
|
67
|
-
maxEntries: 64,
|
|
68
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
urlPattern: /\.(?:mp3|wav|ogg)$/i,
|
|
74
|
-
handler: "CacheFirst",
|
|
75
|
-
options: {
|
|
76
|
-
rangeRequests: true,
|
|
77
|
-
cacheName: "static-audio-assets",
|
|
78
|
-
expiration: {
|
|
79
|
-
maxEntries: 32,
|
|
80
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
urlPattern: /\.(?:mp4|webm)$/i,
|
|
86
|
-
handler: "CacheFirst",
|
|
87
|
-
options: {
|
|
88
|
-
rangeRequests: true,
|
|
89
|
-
cacheName: "static-video-assets",
|
|
90
|
-
expiration: {
|
|
91
|
-
maxEntries: 32,
|
|
92
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
urlPattern: /\.(?:js)$/i,
|
|
98
|
-
handler: "StaleWhileRevalidate",
|
|
99
|
-
options: {
|
|
100
|
-
cacheName: "static-js-assets",
|
|
101
|
-
expiration: {
|
|
102
|
-
maxEntries: 48,
|
|
103
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
urlPattern: /\.(?:css|less)$/i,
|
|
109
|
-
handler: "StaleWhileRevalidate",
|
|
110
|
-
options: {
|
|
111
|
-
cacheName: "static-style-assets",
|
|
112
|
-
expiration: {
|
|
113
|
-
maxEntries: 32,
|
|
114
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
|
|
120
|
-
handler: "StaleWhileRevalidate",
|
|
121
|
-
options: {
|
|
122
|
-
cacheName: "next-data",
|
|
123
|
-
expiration: {
|
|
124
|
-
maxEntries: 32,
|
|
125
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
urlPattern: /\.(?:json|xml|csv)$/i,
|
|
131
|
-
handler: "NetworkFirst",
|
|
132
|
-
options: {
|
|
133
|
-
cacheName: "static-data-assets",
|
|
134
|
-
expiration: {
|
|
135
|
-
maxEntries: 32,
|
|
136
|
-
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
urlPattern: ({ sameOrigin, url: { pathname } }) => {
|
|
142
|
-
// Exclude /api/auth/callback/* to fix OAuth workflow in Safari without having an impact on other environments
|
|
143
|
-
// The above route is the default for next-auth, you may need to change it if your OAuth workflow has a different callback route
|
|
144
|
-
// Issue: https://github.com/shadowwalker/next-pwa/issues/131#issuecomment-821894809
|
|
145
|
-
if (!sameOrigin || pathname.startsWith("/api/auth/callback")) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
5
|
+
import { PAGES_CACHE_NAME } from "./constants.js";
|
|
148
6
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The default, recommended list of caching strategies for applications
|
|
9
|
+
* built with Next.js.
|
|
10
|
+
*
|
|
11
|
+
* @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
|
|
12
|
+
*/
|
|
13
|
+
export const defaultCache: RuntimeCaching[] =
|
|
14
|
+
process.env.NODE_ENV !== "production"
|
|
15
|
+
? []
|
|
16
|
+
: [
|
|
17
|
+
{
|
|
18
|
+
matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
19
|
+
handler: new CacheFirst({
|
|
20
|
+
cacheName: "google-fonts-webfonts",
|
|
21
|
+
plugins: [
|
|
22
|
+
new ExpirationPlugin({
|
|
23
|
+
maxEntries: 4,
|
|
24
|
+
maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days
|
|
25
|
+
maxAgeFrom: "last-used",
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
32
|
+
handler: new StaleWhileRevalidate({
|
|
33
|
+
cacheName: "google-fonts-stylesheets",
|
|
34
|
+
plugins: [
|
|
35
|
+
new ExpirationPlugin({
|
|
36
|
+
maxEntries: 4,
|
|
37
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
38
|
+
maxAgeFrom: "last-used",
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
45
|
+
handler: new StaleWhileRevalidate({
|
|
46
|
+
cacheName: "static-font-assets",
|
|
47
|
+
plugins: [
|
|
48
|
+
new ExpirationPlugin({
|
|
49
|
+
maxEntries: 4,
|
|
50
|
+
maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days
|
|
51
|
+
maxAgeFrom: "last-used",
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
58
|
+
handler: new StaleWhileRevalidate({
|
|
59
|
+
cacheName: "static-image-assets",
|
|
60
|
+
plugins: [
|
|
61
|
+
new ExpirationPlugin({
|
|
62
|
+
maxEntries: 64,
|
|
63
|
+
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
|
|
64
|
+
maxAgeFrom: "last-used",
|
|
65
|
+
}),
|
|
66
|
+
],
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
matcher: /\/_next\/static.+\.js$/i,
|
|
71
|
+
handler: new CacheFirst({
|
|
72
|
+
cacheName: "next-static-js-assets",
|
|
73
|
+
plugins: [
|
|
74
|
+
new ExpirationPlugin({
|
|
75
|
+
maxEntries: 64,
|
|
76
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
77
|
+
maxAgeFrom: "last-used",
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
matcher: /\/_next\/image\?url=.+$/i,
|
|
84
|
+
handler: new StaleWhileRevalidate({
|
|
85
|
+
cacheName: "next-image",
|
|
86
|
+
plugins: [
|
|
87
|
+
new ExpirationPlugin({
|
|
88
|
+
maxEntries: 64,
|
|
89
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
90
|
+
maxAgeFrom: "last-used",
|
|
91
|
+
}),
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
matcher: /\.(?:mp3|wav|ogg)$/i,
|
|
97
|
+
handler: new CacheFirst({
|
|
98
|
+
cacheName: "static-audio-assets",
|
|
99
|
+
plugins: [
|
|
100
|
+
new ExpirationPlugin({
|
|
101
|
+
maxEntries: 32,
|
|
102
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
103
|
+
maxAgeFrom: "last-used",
|
|
104
|
+
}),
|
|
105
|
+
new RangeRequestsPlugin(),
|
|
106
|
+
],
|
|
107
|
+
}),
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
matcher: /\.(?:mp4|webm)$/i,
|
|
111
|
+
handler: new CacheFirst({
|
|
112
|
+
cacheName: "static-video-assets",
|
|
113
|
+
plugins: [
|
|
114
|
+
new ExpirationPlugin({
|
|
115
|
+
maxEntries: 32,
|
|
116
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
117
|
+
maxAgeFrom: "last-used",
|
|
118
|
+
}),
|
|
119
|
+
new RangeRequestsPlugin(),
|
|
120
|
+
],
|
|
121
|
+
}),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
matcher: /\.(?:js)$/i,
|
|
125
|
+
handler: new StaleWhileRevalidate({
|
|
126
|
+
cacheName: "static-js-assets",
|
|
127
|
+
plugins: [
|
|
128
|
+
new ExpirationPlugin({
|
|
129
|
+
maxEntries: 48,
|
|
130
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
131
|
+
maxAgeFrom: "last-used",
|
|
132
|
+
}),
|
|
133
|
+
],
|
|
134
|
+
}),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
matcher: /\.(?:css|less)$/i,
|
|
138
|
+
handler: new StaleWhileRevalidate({
|
|
139
|
+
cacheName: "static-style-assets",
|
|
140
|
+
plugins: [
|
|
141
|
+
new ExpirationPlugin({
|
|
142
|
+
maxEntries: 32,
|
|
143
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
144
|
+
maxAgeFrom: "last-used",
|
|
145
|
+
}),
|
|
146
|
+
],
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
matcher: /\/_next\/data\/.+\/.+\.json$/i,
|
|
151
|
+
handler: new NetworkFirst({
|
|
152
|
+
cacheName: "next-data",
|
|
153
|
+
plugins: [
|
|
154
|
+
new ExpirationPlugin({
|
|
155
|
+
maxEntries: 32,
|
|
156
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
157
|
+
maxAgeFrom: "last-used",
|
|
158
|
+
}),
|
|
159
|
+
],
|
|
160
|
+
}),
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
matcher: /\.(?:json|xml|csv)$/i,
|
|
164
|
+
handler: new NetworkFirst({
|
|
165
|
+
cacheName: "static-data-assets",
|
|
166
|
+
plugins: [
|
|
167
|
+
new ExpirationPlugin({
|
|
168
|
+
maxEntries: 32,
|
|
169
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
170
|
+
maxAgeFrom: "last-used",
|
|
171
|
+
}),
|
|
172
|
+
],
|
|
173
|
+
}),
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
matcher: ({ sameOrigin, url: { pathname } }) => {
|
|
177
|
+
// Exclude /api/auth/callback/* to fix OAuth workflow in Safari without having
|
|
178
|
+
// an impact on other environments
|
|
179
|
+
// The above route is the default for next-auth, you may need to change it if
|
|
180
|
+
// your OAuth workflow has a different callback route.
|
|
181
|
+
// Issue: https://github.com/shadowwalker/next-pwa/issues/131#issuecomment-821894809
|
|
182
|
+
// TODO(ducanhgh): Investigate Auth.js's "/api/auth/*" failing when we allow them
|
|
183
|
+
// to be cached (the current behaviour).
|
|
184
|
+
if (!sameOrigin || pathname.startsWith("/api/auth/callback")) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (pathname.startsWith("/api/")) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
152
191
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
192
|
+
return false;
|
|
193
|
+
},
|
|
194
|
+
method: "GET",
|
|
195
|
+
handler: new NetworkFirst({
|
|
196
|
+
cacheName: "apis",
|
|
197
|
+
plugins: [
|
|
198
|
+
new ExpirationPlugin({
|
|
199
|
+
maxEntries: 16,
|
|
200
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
201
|
+
maxAgeFrom: "last-used",
|
|
202
|
+
}),
|
|
203
|
+
],
|
|
204
|
+
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) =>
|
|
209
|
+
request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
210
|
+
handler: new NetworkFirst({
|
|
211
|
+
cacheName: PAGES_CACHE_NAME.rscPrefetch,
|
|
212
|
+
plugins: [
|
|
213
|
+
new ExpirationPlugin({
|
|
214
|
+
maxEntries: 32,
|
|
215
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
216
|
+
}),
|
|
217
|
+
],
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
222
|
+
handler: new NetworkFirst({
|
|
223
|
+
cacheName: PAGES_CACHE_NAME.rsc,
|
|
224
|
+
plugins: [
|
|
225
|
+
new ExpirationPlugin({
|
|
226
|
+
maxEntries: 32,
|
|
227
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
228
|
+
}),
|
|
229
|
+
],
|
|
230
|
+
}),
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) =>
|
|
234
|
+
request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
|
|
235
|
+
handler: new NetworkFirst({
|
|
236
|
+
cacheName: PAGES_CACHE_NAME.html,
|
|
237
|
+
plugins: [
|
|
238
|
+
new ExpirationPlugin({
|
|
239
|
+
maxEntries: 32,
|
|
240
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
241
|
+
}),
|
|
242
|
+
],
|
|
243
|
+
}),
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
|
|
247
|
+
handler: new NetworkFirst({
|
|
248
|
+
cacheName: "others",
|
|
249
|
+
plugins: [
|
|
250
|
+
new ExpirationPlugin({
|
|
251
|
+
maxEntries: 32,
|
|
252
|
+
maxAgeSeconds: 24 * 60 * 60, // 24 hours
|
|
253
|
+
}),
|
|
254
|
+
],
|
|
255
|
+
}),
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
matcher: ({ sameOrigin }) => !sameOrigin,
|
|
259
|
+
handler: new NetworkFirst({
|
|
260
|
+
cacheName: "cross-origin",
|
|
261
|
+
plugins: [
|
|
262
|
+
new ExpirationPlugin({
|
|
263
|
+
maxEntries: 32,
|
|
264
|
+
maxAgeSeconds: 60 * 60, // 1 hour
|
|
265
|
+
}),
|
|
266
|
+
],
|
|
267
|
+
networkTimeoutSeconds: 10,
|
|
268
|
+
}),
|
|
269
|
+
},
|
|
270
|
+
];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find-first-truthy.d.ts","sourceRoot":"","sources":["../../src/utils/find-first-truthy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,mEAQ3B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-content-hash.d.ts","sourceRoot":"","sources":["../../src/utils/get-content-hash.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAI9B,eAAO,MAAM,cAAc,SAAU,GAAG,oBAAoB,SAAS,OAAO,WAK3E,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-file-hash.d.ts","sourceRoot":"","sources":["../../src/utils/get-file-hash.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,eAAO,MAAM,WAAW,SAAU,GAAG,oBAAoB,WAAyE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-package-version.d.ts","sourceRoot":"","sources":["../../src/utils/get-package-version.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,gBAAiB,MAAM,KAAG,MAAM,GAAG,SAMhE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-tsconfig.d.ts","sourceRoot":"","sources":["../../src/utils/load-tsconfig.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AAI9D,eAAO,MAAM,YAAY,YAAa,MAAM,wBAAwB,MAAM,GAAG,SAAS,KAAG,YAAY,GAAG,SAmBvG,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/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"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
-
export interface PageRuntimeCaching extends Omit<RuntimeCaching, "options"> {
|
|
3
|
-
options?: Omit<NonNullable<RuntimeCaching["options"]>, "cacheName">;
|
|
4
|
-
}
|
|
5
|
-
export interface DefinePageRuntimeCachingOptions {
|
|
6
|
-
rscPrefetch?: PageRuntimeCaching;
|
|
7
|
-
rsc?: PageRuntimeCaching;
|
|
8
|
-
html?: PageRuntimeCaching;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Conveniently define three `runtimeCaching` entries for Next.js pages.
|
|
12
|
-
* @param options
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const definePageRuntimeCaching: ({ rscPrefetch, rsc, html }: DefinePageRuntimeCachingOptions) => RuntimeCaching[];
|
|
16
|
-
//# sourceMappingURL=definePageRuntimeCaching.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"definePageRuntimeCaching.d.ts","sourceRoot":"","sources":["../../src/worker/definePageRuntimeCaching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGlD,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IACzE,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,+BAA+B;IAC9C,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAC;CAC3B;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,+BAAgC,+BAA+B,KAAG,cAAc,EAiBpH,CAAC"}
|