@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.
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,20 @@
1
+ import { requiredSwDestPartial } from '@serwist/build/schema';
2
+ import { injectManifestOptions as injectManifestOptions$1 } from '@serwist/webpack-plugin/schema';
3
+ import { z } from 'zod';
4
+
5
+ const injectPartial = z.object({
6
+ cacheOnNavigation: z.boolean().default(false),
7
+ disable: z.boolean().default(false),
8
+ register: z.boolean().default(true),
9
+ reloadOnOnline: z.boolean().default(true),
10
+ scope: z.string().optional(),
11
+ swUrl: z.string().default("/sw.js"),
12
+ globPublicPatterns: z.array(z.string()).default([
13
+ "**/*"
14
+ ])
15
+ }).strict("Do not pass invalid properties to NextInjectManifestPartial!");
16
+ const injectManifestOptions = injectManifestOptions$1.merge(requiredSwDestPartial).merge(injectPartial).omit({
17
+ disablePrecacheManifest: true
18
+ }).strict("Do not pass invalid properties to NextInjectManifestOptions!");
19
+
20
+ export { injectManifestOptions as a, injectPartial as i };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
- import type { NextInjectManifestOptions } from "@serwist/build";
2
1
  import type { NextConfig } from "next";
3
- declare const withSerwistInit: (pluginOptions: NextInjectManifestOptions) => (nextConfig?: NextConfig) => NextConfig;
2
+ import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
3
+ import { validateInjectManifestOptions } from "./lib/validator.js";
4
+ /**
5
+ * Integrates Serwist into your Next.js app.
6
+ * @param userOptions
7
+ * @returns
8
+ */
9
+ declare const withSerwistInit: (userOptions: InjectManifestOptions) => (nextConfig?: NextConfig) => NextConfig;
4
10
  export default withSerwistInit;
5
- export type { NextInjectManifestOptions as PluginOptions };
11
+ export { validateInjectManifestOptions };
12
+ export type { InjectManifestOptions as PluginOptions, InjectManifestOptionsComplete as PluginOptionsComplete };
6
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAMhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAQvC,QAAA,MAAM,eAAe,kBAAmB,yBAAyB,mBAAkB,UAAU,KAAK,UA4NjG,CAAC;AAEF,eAAe,eAAe,CAAC;AAC/B,YAAY,EAAE,yBAAyB,IAAI,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAInE;;;;GAIG;AACH,QAAA,MAAM,eAAe,gBAAiB,qBAAqB,mBAAkB,UAAU,KAAK,UAwN3F,CAAC;AAEF,eAAe,eAAe,CAAC;AAC/B,OAAO,EAAE,6BAA6B,EAAE,CAAC;AACzC,YAAY,EAAE,qBAAqB,IAAI,aAAa,EAAE,6BAA6B,IAAI,qBAAqB,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,16 @@
1
+ import fs from 'node:fs';
1
2
  import path from 'node:path';
2
3
  import { fileURLToPath } from 'node:url';
3
- import { validateNextInjectManifestOptions } from '@serwist/build/next';
4
4
  import { InjectManifest } from '@serwist/webpack-plugin';
5
5
  import { ChildCompilationPlugin, relativeToOutputPath } from '@serwist/webpack-plugin/internal';
6
- import { CleanWebpackPlugin } from 'clean-webpack-plugin';
7
- import fg from 'fast-glob';
6
+ import { globSync } from 'glob';
8
7
  import crypto from 'node:crypto';
9
- import fs from 'node:fs';
10
8
  import { createRequire } from 'node:module';
11
9
  import chalk from 'chalk';
10
+ import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
11
+ import { a as injectManifestOptions } from './chunks/schema.js';
12
+ import '@serwist/webpack-plugin/schema';
13
+ import 'zod';
12
14
 
13
15
  const findFirstTruthy = (arr, fn)=>{
14
16
  for (const i of arr){
@@ -83,8 +85,21 @@ const event = (...message)=>{
83
85
  prefixedLog("event", ...message);
84
86
  };
85
87
 
88
+ const validateInjectManifestOptions = (input)=>{
89
+ const result = injectManifestOptions.safeParse(input, {
90
+ errorMap: validationErrorMap
91
+ });
92
+ if (!result.success) {
93
+ throw new SerwistConfigError({
94
+ moduleName: "@serwist/next",
95
+ message: JSON.stringify(result.error.format(), null, 2)
96
+ });
97
+ }
98
+ return result.data;
99
+ };
100
+
86
101
  const __dirname = fileURLToPath(new URL(".", import.meta.url));
87
- const withSerwistInit = (pluginOptions)=>{
102
+ const withSerwistInit = (userOptions)=>{
88
103
  return (nextConfig = {})=>({
89
104
  ...nextConfig,
90
105
  webpack (config, options) {
@@ -92,7 +107,7 @@ const withSerwistInit = (pluginOptions)=>{
92
107
  const { dev } = options;
93
108
  const basePath = options.config.basePath || "/";
94
109
  const tsConfigJson = loadTSConfig(options.dir, nextConfig?.typescript?.tsconfigPath);
95
- const { cacheOnNavigation, disable, scope = basePath, swUrl, register, reloadOnOnline, globPublicPatterns, ...buildOptions } = validateNextInjectManifestOptions(pluginOptions);
110
+ const { cacheOnNavigation, disable, scope = basePath, swUrl, register, reloadOnOnline, globPublicPatterns, ...buildOptions } = validateInjectManifestOptions(userOptions);
96
111
  if (typeof nextConfig.webpack === "function") {
97
112
  config = nextConfig.webpack(config, options);
98
113
  }
@@ -144,7 +159,7 @@ const withSerwistInit = (pluginOptions)=>{
144
159
  info("Service worker won't be automatically registered as per the config, please call the following code in componentDidMount or useEffect:");
145
160
  info(" window.serwist.register()");
146
161
  if (!tsConfigJson?.compilerOptions?.types?.includes("@serwist/next/typings")) {
147
- info("You may also want to add @serwist/next/typings to compilerOptions.types in your tsconfig.json/jsconfig.json.");
162
+ info("You may also want to add '@serwist/next/typings' to compilerOptions.types in your tsconfig.json/jsconfig.json.");
148
163
  }
149
164
  }
150
165
  const { swSrc: userSwSrc, swDest: userSwDest, additionalPrecacheEntries, exclude, manifestTransforms = [], ...otherBuildOptions } = buildOptions;
@@ -157,7 +172,24 @@ const withSerwistInit = (pluginOptions)=>{
157
172
  swDest = path.join(options.dir, swDest);
158
173
  }
159
174
  const publicDir = path.resolve(options.dir, "public");
160
- const destDir = path.dirname(swDest);
175
+ const { dir: destDir, base: destBase } = path.parse(swDest);
176
+ const cleanUpList = globSync([
177
+ "swe-worker-*.js",
178
+ "swe-worker-*.js.map",
179
+ destBase,
180
+ `${destBase}.map`
181
+ ], {
182
+ absolute: true,
183
+ nodir: true,
184
+ cwd: destDir
185
+ });
186
+ for (const file of cleanUpList){
187
+ fs.rm(file, {
188
+ force: true
189
+ }, (err)=>{
190
+ if (err) throw err;
191
+ });
192
+ }
161
193
  const shouldBuildSWEntryWorker = cacheOnNavigation;
162
194
  let swEntryPublicPath = undefined;
163
195
  let swEntryWorkerDest = undefined;
@@ -177,29 +209,16 @@ const withSerwistInit = (pluginOptions)=>{
177
209
  info(`Service worker: ${swDest}`);
178
210
  info(` URL: ${_sw}`);
179
211
  info(` Scope: ${_scope}`);
180
- config.plugins.push(new CleanWebpackPlugin({
181
- cleanOnceBeforeBuildPatterns: [
182
- path.join(destDir, "swe-worker-*.js"),
183
- path.join(destDir, "swe-worker-*.js.map"),
184
- swDest
185
- ]
186
- }));
187
212
  let resolvedManifestEntries = additionalPrecacheEntries;
188
213
  if (!resolvedManifestEntries) {
189
- const swDestFileName = path.basename(swDest);
190
- const userPublicGlob = typeof globPublicPatterns === "string" ? [
191
- globPublicPatterns
192
- ] : globPublicPatterns ?? [
193
- "**/*"
194
- ];
195
- const publicScan = fg.sync([
196
- ...userPublicGlob,
197
- "!swe-worker-*.js",
198
- "!swe-worker-*.js.map",
199
- `!${swDestFileName.replace(/^\/+/, "")}`,
200
- `!${swDestFileName.replace(/^\/+/, "")}.map`
201
- ], {
202
- cwd: publicDir
214
+ const publicScan = globSync(globPublicPatterns, {
215
+ nodir: true,
216
+ cwd: publicDir,
217
+ ignore: [
218
+ "swe-worker-*.js",
219
+ destBase,
220
+ `${destBase}.map`
221
+ ]
203
222
  });
204
223
  resolvedManifestEntries = publicScan.map((f)=>({
205
224
  url: path.posix.join(basePath, f),
@@ -247,4 +266,4 @@ const withSerwistInit = (pluginOptions)=>{
247
266
  });
248
267
  };
249
268
 
250
- export { withSerwistInit as default };
269
+ export { withSerwistInit as default, validateInjectManifestOptions };
@@ -0,0 +1,3 @@
1
+ import { injectManifestOptions, injectPartial } from "./lib/schema.js";
2
+ export { injectPartial, injectManifestOptions };
3
+ //# sourceMappingURL=index.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.schema.d.ts","sourceRoot":"","sources":["../src/index.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { a as injectManifestOptions, i as injectPartial } from './chunks/schema.js';
2
+ import '@serwist/build/schema';
3
+ import '@serwist/webpack-plugin/schema';
4
+ import 'zod';
@@ -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
- export { defaultCache, definePageRuntimeCaching };
4
- export type { DefinePageRuntimeCachingOptions, PageRuntimeCaching };
3
+ export { defaultCache, PAGES_CACHE_NAME };
5
4
  //# sourceMappingURL=index.worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,+BAA+B,EAAE,KAAK,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAE/I,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAClD,YAAY,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.worker.d.ts","sourceRoot":"","sources":["../src/index.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,163 +1,173 @@
1
- const nonNullable = (value)=>value !== null && value !== undefined;
1
+ import { ExpirationPlugin, RangeRequestsPlugin } from '@serwist/sw/plugins';
2
+ import { CacheFirst, StaleWhileRevalidate, NetworkFirst } from '@serwist/sw/strategies';
2
3
 
3
- const definePageRuntimeCaching = ({ rscPrefetch, rsc, html })=>{
4
- const pageRcs = [
5
- rscPrefetch,
6
- rsc,
7
- html
8
- ];
9
- if (pageRcs[0]) {
10
- if (!pageRcs[0].options) pageRcs[0].options = {};
11
- pageRcs[0].options.cacheName = "pages-rsc-prefetch";
12
- }
13
- if (pageRcs[1]) {
14
- if (!pageRcs[1].options) pageRcs[1].options = {};
15
- pageRcs[1].options.cacheName = "pages-rsc";
16
- }
17
- if (pageRcs[2]) {
18
- if (!pageRcs[2].options) pageRcs[2].options = {};
19
- pageRcs[2].options.cacheName = "pages";
20
- }
21
- return pageRcs.filter(nonNullable);
4
+ const PAGES_CACHE_NAME = {
5
+ rscPrefetch: "pages-rsc-prefetch",
6
+ rsc: "pages-rsc",
7
+ html: "pages"
22
8
  };
23
9
 
24
- const defaultCache = [
10
+ const defaultCache = process.env.NODE_ENV !== "production" ? [] : [
25
11
  {
26
- urlPattern: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
27
- handler: "CacheFirst",
28
- options: {
12
+ matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
13
+ handler: new CacheFirst({
29
14
  cacheName: "google-fonts-webfonts",
30
- expiration: {
31
- maxEntries: 4,
32
- maxAgeSeconds: 365 * 24 * 60 * 60
33
- }
34
- }
15
+ plugins: [
16
+ new ExpirationPlugin({
17
+ maxEntries: 4,
18
+ maxAgeSeconds: 365 * 24 * 60 * 60,
19
+ maxAgeFrom: "last-used"
20
+ })
21
+ ]
22
+ })
35
23
  },
36
24
  {
37
- urlPattern: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
38
- handler: "StaleWhileRevalidate",
39
- options: {
25
+ matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
26
+ handler: new StaleWhileRevalidate({
40
27
  cacheName: "google-fonts-stylesheets",
41
- expiration: {
42
- maxEntries: 4,
43
- maxAgeSeconds: 7 * 24 * 60 * 60
44
- }
45
- }
28
+ plugins: [
29
+ new ExpirationPlugin({
30
+ maxEntries: 4,
31
+ maxAgeSeconds: 7 * 24 * 60 * 60,
32
+ maxAgeFrom: "last-used"
33
+ })
34
+ ]
35
+ })
46
36
  },
47
37
  {
48
- urlPattern: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
49
- handler: "StaleWhileRevalidate",
50
- options: {
38
+ matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
39
+ handler: new StaleWhileRevalidate({
51
40
  cacheName: "static-font-assets",
52
- expiration: {
53
- maxEntries: 4,
54
- maxAgeSeconds: 7 * 24 * 60 * 60
55
- }
56
- }
41
+ plugins: [
42
+ new ExpirationPlugin({
43
+ maxEntries: 4,
44
+ maxAgeSeconds: 7 * 24 * 60 * 60,
45
+ maxAgeFrom: "last-used"
46
+ })
47
+ ]
48
+ })
57
49
  },
58
50
  {
59
- urlPattern: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
60
- handler: "StaleWhileRevalidate",
61
- options: {
51
+ matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
52
+ handler: new StaleWhileRevalidate({
62
53
  cacheName: "static-image-assets",
63
- expiration: {
64
- maxEntries: 64,
65
- maxAgeSeconds: 30 * 24 * 60 * 60
66
- }
67
- }
54
+ plugins: [
55
+ new ExpirationPlugin({
56
+ maxEntries: 64,
57
+ maxAgeSeconds: 30 * 24 * 60 * 60,
58
+ maxAgeFrom: "last-used"
59
+ })
60
+ ]
61
+ })
68
62
  },
69
63
  {
70
- urlPattern: /\/_next\/static.+\.js$/i,
71
- handler: "CacheFirst",
72
- options: {
64
+ matcher: /\/_next\/static.+\.js$/i,
65
+ handler: new CacheFirst({
73
66
  cacheName: "next-static-js-assets",
74
- expiration: {
75
- maxEntries: 64,
76
- maxAgeSeconds: 24 * 60 * 60
77
- }
78
- }
67
+ plugins: [
68
+ new ExpirationPlugin({
69
+ maxEntries: 64,
70
+ maxAgeSeconds: 24 * 60 * 60,
71
+ maxAgeFrom: "last-used"
72
+ })
73
+ ]
74
+ })
79
75
  },
80
76
  {
81
- urlPattern: /\/_next\/image\?url=.+$/i,
82
- handler: "StaleWhileRevalidate",
83
- options: {
77
+ matcher: /\/_next\/image\?url=.+$/i,
78
+ handler: new StaleWhileRevalidate({
84
79
  cacheName: "next-image",
85
- expiration: {
86
- maxEntries: 64,
87
- maxAgeSeconds: 24 * 60 * 60
88
- }
89
- }
80
+ plugins: [
81
+ new ExpirationPlugin({
82
+ maxEntries: 64,
83
+ maxAgeSeconds: 24 * 60 * 60,
84
+ maxAgeFrom: "last-used"
85
+ })
86
+ ]
87
+ })
90
88
  },
91
89
  {
92
- urlPattern: /\.(?:mp3|wav|ogg)$/i,
93
- handler: "CacheFirst",
94
- options: {
95
- rangeRequests: true,
90
+ matcher: /\.(?:mp3|wav|ogg)$/i,
91
+ handler: new CacheFirst({
96
92
  cacheName: "static-audio-assets",
97
- expiration: {
98
- maxEntries: 32,
99
- maxAgeSeconds: 24 * 60 * 60
100
- }
101
- }
93
+ plugins: [
94
+ new ExpirationPlugin({
95
+ maxEntries: 32,
96
+ maxAgeSeconds: 24 * 60 * 60,
97
+ maxAgeFrom: "last-used"
98
+ }),
99
+ new RangeRequestsPlugin()
100
+ ]
101
+ })
102
102
  },
103
103
  {
104
- urlPattern: /\.(?:mp4|webm)$/i,
105
- handler: "CacheFirst",
106
- options: {
107
- rangeRequests: true,
104
+ matcher: /\.(?:mp4|webm)$/i,
105
+ handler: new CacheFirst({
108
106
  cacheName: "static-video-assets",
109
- expiration: {
110
- maxEntries: 32,
111
- maxAgeSeconds: 24 * 60 * 60
112
- }
113
- }
107
+ plugins: [
108
+ new ExpirationPlugin({
109
+ maxEntries: 32,
110
+ maxAgeSeconds: 24 * 60 * 60,
111
+ maxAgeFrom: "last-used"
112
+ }),
113
+ new RangeRequestsPlugin()
114
+ ]
115
+ })
114
116
  },
115
117
  {
116
- urlPattern: /\.(?:js)$/i,
117
- handler: "StaleWhileRevalidate",
118
- options: {
118
+ matcher: /\.(?:js)$/i,
119
+ handler: new StaleWhileRevalidate({
119
120
  cacheName: "static-js-assets",
120
- expiration: {
121
- maxEntries: 48,
122
- maxAgeSeconds: 24 * 60 * 60
123
- }
124
- }
121
+ plugins: [
122
+ new ExpirationPlugin({
123
+ maxEntries: 48,
124
+ maxAgeSeconds: 24 * 60 * 60,
125
+ maxAgeFrom: "last-used"
126
+ })
127
+ ]
128
+ })
125
129
  },
126
130
  {
127
- urlPattern: /\.(?:css|less)$/i,
128
- handler: "StaleWhileRevalidate",
129
- options: {
131
+ matcher: /\.(?:css|less)$/i,
132
+ handler: new StaleWhileRevalidate({
130
133
  cacheName: "static-style-assets",
131
- expiration: {
132
- maxEntries: 32,
133
- maxAgeSeconds: 24 * 60 * 60
134
- }
135
- }
134
+ plugins: [
135
+ new ExpirationPlugin({
136
+ maxEntries: 32,
137
+ maxAgeSeconds: 24 * 60 * 60,
138
+ maxAgeFrom: "last-used"
139
+ })
140
+ ]
141
+ })
136
142
  },
137
143
  {
138
- urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
139
- handler: "StaleWhileRevalidate",
140
- options: {
144
+ matcher: /\/_next\/data\/.+\/.+\.json$/i,
145
+ handler: new NetworkFirst({
141
146
  cacheName: "next-data",
142
- expiration: {
143
- maxEntries: 32,
144
- maxAgeSeconds: 24 * 60 * 60
145
- }
146
- }
147
+ plugins: [
148
+ new ExpirationPlugin({
149
+ maxEntries: 32,
150
+ maxAgeSeconds: 24 * 60 * 60,
151
+ maxAgeFrom: "last-used"
152
+ })
153
+ ]
154
+ })
147
155
  },
148
156
  {
149
- urlPattern: /\.(?:json|xml|csv)$/i,
150
- handler: "NetworkFirst",
151
- options: {
157
+ matcher: /\.(?:json|xml|csv)$/i,
158
+ handler: new NetworkFirst({
152
159
  cacheName: "static-data-assets",
153
- expiration: {
154
- maxEntries: 32,
155
- maxAgeSeconds: 24 * 60 * 60
156
- }
157
- }
160
+ plugins: [
161
+ new ExpirationPlugin({
162
+ maxEntries: 32,
163
+ maxAgeSeconds: 24 * 60 * 60,
164
+ maxAgeFrom: "last-used"
165
+ })
166
+ ]
167
+ })
158
168
  },
159
169
  {
160
- urlPattern: ({ sameOrigin, url: { pathname } })=>{
170
+ matcher: ({ sameOrigin, url: { pathname } })=>{
161
171
  if (!sameOrigin || pathname.startsWith("/api/auth/callback")) {
162
172
  return false;
163
173
  }
@@ -166,72 +176,80 @@ const defaultCache = [
166
176
  }
167
177
  return false;
168
178
  },
169
- handler: "NetworkFirst",
170
179
  method: "GET",
171
- options: {
180
+ handler: new NetworkFirst({
172
181
  cacheName: "apis",
173
- expiration: {
174
- maxEntries: 16,
175
- maxAgeSeconds: 24 * 60 * 60
176
- },
182
+ plugins: [
183
+ new ExpirationPlugin({
184
+ maxEntries: 16,
185
+ maxAgeSeconds: 24 * 60 * 60,
186
+ maxAgeFrom: "last-used"
187
+ })
188
+ ],
177
189
  networkTimeoutSeconds: 10
178
- }
179
- },
180
- ...definePageRuntimeCaching({
181
- rscPrefetch: {
182
- urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
183
- handler: "NetworkFirst",
184
- options: {
185
- expiration: {
190
+ })
191
+ },
192
+ {
193
+ matcher: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
194
+ handler: new NetworkFirst({
195
+ cacheName: PAGES_CACHE_NAME.rscPrefetch,
196
+ plugins: [
197
+ new ExpirationPlugin({
186
198
  maxEntries: 32,
187
199
  maxAgeSeconds: 24 * 60 * 60
188
- }
189
- }
190
- },
191
- rsc: {
192
- urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
193
- handler: "NetworkFirst",
194
- options: {
195
- expiration: {
200
+ })
201
+ ]
202
+ })
203
+ },
204
+ {
205
+ matcher: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
206
+ handler: new NetworkFirst({
207
+ cacheName: PAGES_CACHE_NAME.rsc,
208
+ plugins: [
209
+ new ExpirationPlugin({
196
210
  maxEntries: 32,
197
211
  maxAgeSeconds: 24 * 60 * 60
198
- }
199
- }
200
- },
201
- html: {
202
- urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
203
- handler: "NetworkFirst",
204
- options: {
205
- expiration: {
212
+ })
213
+ ]
214
+ })
215
+ },
216
+ {
217
+ matcher: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
218
+ handler: new NetworkFirst({
219
+ cacheName: PAGES_CACHE_NAME.html,
220
+ plugins: [
221
+ new ExpirationPlugin({
206
222
  maxEntries: 32,
207
223
  maxAgeSeconds: 24 * 60 * 60
208
- }
209
- }
210
- }
211
- }),
224
+ })
225
+ ]
226
+ })
227
+ },
212
228
  {
213
- urlPattern: ({ url: { pathname }, sameOrigin })=>sameOrigin && !pathname.startsWith("/api/"),
214
- handler: "NetworkFirst",
215
- options: {
229
+ matcher: ({ url: { pathname }, sameOrigin })=>sameOrigin && !pathname.startsWith("/api/"),
230
+ handler: new NetworkFirst({
216
231
  cacheName: "others",
217
- expiration: {
218
- maxEntries: 32,
219
- maxAgeSeconds: 24 * 60 * 60
220
- }
221
- }
232
+ plugins: [
233
+ new ExpirationPlugin({
234
+ maxEntries: 32,
235
+ maxAgeSeconds: 24 * 60 * 60
236
+ })
237
+ ]
238
+ })
222
239
  },
223
240
  {
224
- urlPattern: ({ sameOrigin })=>!sameOrigin,
225
- handler: "NetworkFirst",
226
- options: {
241
+ matcher: ({ sameOrigin })=>!sameOrigin,
242
+ handler: new NetworkFirst({
227
243
  cacheName: "cross-origin",
228
- expiration: {
229
- maxEntries: 32,
230
- maxAgeSeconds: 60 * 60
231
- },
244
+ plugins: [
245
+ new ExpirationPlugin({
246
+ maxEntries: 32,
247
+ maxAgeSeconds: 60 * 60
248
+ })
249
+ ],
232
250
  networkTimeoutSeconds: 10
233
- }
251
+ })
234
252
  }
235
253
  ];
236
254
 
237
- export { defaultCache, definePageRuntimeCaching };
255
+ export { PAGES_CACHE_NAME, defaultCache };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-first-truthy.d.ts","sourceRoot":"","sources":["../../src/lib/find-first-truthy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,cAAe,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,+BAQhE,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-content-hash.d.ts","sourceRoot":"","sources":["../../src/lib/get-content-hash.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAI9B,eAAO,MAAM,cAAc,SAAU,GAAG,oBAAoB,SAAS,OAAO,WAK3E,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-file-hash.d.ts","sourceRoot":"","sources":["../../src/lib/get-file-hash.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,eAAO,MAAM,WAAW,SAAU,GAAG,oBAAoB,WAAyE,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-version.d.ts","sourceRoot":"","sources":["../../src/lib/get-package-version.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,gBAAiB,MAAM,KAAG,MAAM,GAAG,SAMhE,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/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"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-tsconfig.d.ts","sourceRoot":"","sources":["../../src/lib/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"}