@serwist/next 8.4.4 → 9.0.0-preview.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/index.d.ts +5 -4
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +50 -37
  4. package/dist/index.worker.d.ts +5 -0
  5. package/dist/index.worker.d.ts.map +1 -0
  6. package/dist/{index.browser.cjs → index.worker.js} +57 -22
  7. package/dist/internal-types.d.ts +6 -0
  8. package/dist/internal-types.d.ts.map +1 -0
  9. package/dist/sw-entry-worker.d.ts +1 -0
  10. package/dist/sw-entry-worker.d.ts.map +1 -0
  11. package/dist/sw-entry.d.ts +1 -0
  12. package/dist/sw-entry.d.ts.map +1 -0
  13. package/dist/utils/find-first-truthy.d.ts +1 -0
  14. package/dist/utils/find-first-truthy.d.ts.map +1 -0
  15. package/dist/utils/get-content-hash.d.ts +1 -0
  16. package/dist/utils/get-content-hash.d.ts.map +1 -0
  17. package/dist/utils/get-file-hash.d.ts +1 -0
  18. package/dist/utils/get-file-hash.d.ts.map +1 -0
  19. package/dist/utils/get-package-version.d.ts +1 -0
  20. package/dist/utils/get-package-version.d.ts.map +1 -0
  21. package/dist/utils/index.d.ts +1 -0
  22. package/dist/utils/index.d.ts.map +1 -0
  23. package/dist/utils/load-tsconfig.d.ts +1 -0
  24. package/dist/utils/load-tsconfig.d.ts.map +1 -0
  25. package/dist/utils/logger.d.ts +1 -0
  26. package/dist/utils/logger.d.ts.map +1 -0
  27. package/dist/utils.d.ts +1 -0
  28. package/dist/utils.d.ts.map +1 -0
  29. package/dist/worker/defaultCache.d.ts +3 -0
  30. package/dist/worker/defaultCache.d.ts.map +1 -0
  31. package/dist/worker/definePageRuntimeCaching.d.ts +16 -0
  32. package/dist/worker/definePageRuntimeCaching.d.ts.map +1 -0
  33. package/package.json +47 -49
  34. package/src/index.ts +241 -0
  35. package/src/index.worker.ts +5 -0
  36. package/src/internal-types.ts +17 -0
  37. package/src/sw-entry-worker.ts +46 -0
  38. package/src/sw-entry.ts +64 -0
  39. package/src/utils/find-first-truthy.ts +15 -0
  40. package/src/utils/get-content-hash.ts +10 -0
  41. package/src/utils/get-file-hash.ts +4 -0
  42. package/src/utils/get-package-version.ts +16 -0
  43. package/src/utils/load-tsconfig.ts +27 -0
  44. package/src/utils/logger.ts +57 -0
  45. package/src/utils.ts +11 -0
  46. package/src/worker/defaultCache.ts +223 -0
  47. package/src/worker/definePageRuntimeCaching.ts +36 -0
  48. package/dist/index.browser.d.cts +0 -2
  49. package/dist/index.browser.d.ts +0 -2
  50. package/dist/index.browser.js +0 -208
  51. package/dist/index.cjs +0 -928
  52. package/dist/index.d.cts +0 -5
  53. package/dist/internal-types.d.cts +0 -9
  54. package/dist/sw-entry-worker.cjs +0 -35
  55. package/dist/sw-entry-worker.d.cts +0 -7
  56. package/dist/sw-entry.cjs +0 -43
  57. package/dist/sw-entry.d.cts +0 -6
  58. package/dist/types.d.cts +0 -81
  59. package/dist/types.d.ts +0 -81
  60. package/dist/utils/find-first-truthy.d.cts +0 -7
  61. package/dist/utils/get-content-hash.d.cts +0 -3
  62. package/dist/utils/get-file-hash.d.cts +0 -3
  63. package/dist/utils/get-package-version.d.cts +0 -6
  64. package/dist/utils/load-tsconfig.d.cts +0 -2
  65. package/dist/utils/logger.d.cts +0 -5
  66. package/dist/utils.d.cts +0 -4
  67. /package/{dist/utils/index.d.cts → src/utils/index.ts} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type { NextInjectManifestOptions } from "@serwist/build";
1
2
  import type { NextConfig } from "next";
2
- import type { PluginOptions } from "./types.js";
3
- declare const withPWAInit: (pluginOptions: PluginOptions) => (nextConfig?: NextConfig) => NextConfig;
4
- export default withPWAInit;
5
- export * from "./types.js";
3
+ declare const withSerwistInit: (pluginOptions: NextInjectManifestOptions) => (nextConfig?: NextConfig) => NextConfig;
4
+ export default withSerwistInit;
5
+ export type { NextInjectManifestOptions as PluginOptions };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import path from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
+ import { validateNextInjectManifestOptions } from '@serwist/build/next';
3
4
  import { InjectManifest } from '@serwist/webpack-plugin';
4
- import { ChildCompilationPlugin } from '@serwist/webpack-plugin/internal';
5
+ import { ChildCompilationPlugin, relativeToOutputPath } from '@serwist/webpack-plugin/internal';
5
6
  import { CleanWebpackPlugin } from 'clean-webpack-plugin';
6
7
  import fg from 'fast-glob';
7
8
  import crypto from 'node:crypto';
@@ -719,7 +720,6 @@ const chalk = createChalk();
719
720
  createChalk({
720
721
  level: stderrColor ? stderrColor.level : 0
721
722
  });
722
- var chalk$1 = chalk;
723
723
 
724
724
  const mapLoggingMethodToConsole = {
725
725
  wait: "log",
@@ -729,11 +729,11 @@ const mapLoggingMethodToConsole = {
729
729
  event: "log"
730
730
  };
731
731
  const prefixes = {
732
- wait: `${chalk$1.white(chalk$1.bold("○"))} (serwist)`,
733
- error: `${chalk$1.red(chalk$1.bold("X"))} (serwist)`,
734
- warn: `${chalk$1.yellow(chalk$1.bold("⚠"))} (serwist)`,
735
- info: `${chalk$1.white(chalk$1.bold("○"))} (serwist)`,
736
- event: `${chalk$1.green(chalk$1.bold("✓"))} (serwist)`
732
+ wait: `${chalk.white(chalk.bold("○"))} (serwist)`,
733
+ error: `${chalk.red(chalk.bold("X"))} (serwist)`,
734
+ warn: `${chalk.yellow(chalk.bold("⚠"))} (serwist)`,
735
+ info: `${chalk.white(chalk.bold("○"))} (serwist)`,
736
+ event: `${chalk.green(chalk.bold("✓"))} (serwist)`
737
737
  };
738
738
  const prefixedLog = (prefixType, ...message)=>{
739
739
  const consoleMethod = mapLoggingMethodToConsole[prefixType];
@@ -756,15 +756,15 @@ const event = (...message)=>{
756
756
  };
757
757
 
758
758
  const __dirname = fileURLToPath(new URL(".", import.meta.url));
759
- const withPWAInit = (pluginOptions)=>{
759
+ const withSerwistInit = (pluginOptions)=>{
760
760
  return (nextConfig = {})=>({
761
761
  ...nextConfig,
762
762
  webpack (config, options) {
763
763
  const webpack = options.webpack;
764
- const { buildId, dev } = options;
764
+ const { dev } = options;
765
765
  const basePath = options.config.basePath || "/";
766
766
  const tsConfigJson = loadTSConfig(options.dir, nextConfig?.typescript?.tsconfigPath);
767
- const { cacheOnFrontEndNav = false, disable = false, scope = basePath, swUrl = "sw.js", register = true, reloadOnOnline = true, ...buildOptions } = pluginOptions;
767
+ const { cacheOnFrontEndNav, disable, scope = basePath, swUrl, register, reloadOnOnline, globPublicPatterns, ...buildOptions } = validateNextInjectManifestOptions(pluginOptions);
768
768
  if (typeof nextConfig.webpack === "function") {
769
769
  config = nextConfig.webpack(config, options);
770
770
  }
@@ -781,9 +781,9 @@ const withPWAInit = (pluginOptions)=>{
781
781
  config.plugins.push(new webpack.DefinePlugin({
782
782
  "self.__SERWIST_SW_ENTRY.sw": `'${_sw}'`,
783
783
  "self.__SERWIST_SW_ENTRY.scope": `'${_scope}'`,
784
- "self.__SERWIST_SW_ENTRY.cacheOnFrontEndNav": `${Boolean(cacheOnFrontEndNav)}`,
785
- "self.__SERWIST_SW_ENTRY.register": `${Boolean(register)}`,
786
- "self.__SERWIST_SW_ENTRY.reloadOnOnline": `${Boolean(reloadOnOnline)}`
784
+ "self.__SERWIST_SW_ENTRY.cacheOnFrontEndNav": `${cacheOnFrontEndNav}`,
785
+ "self.__SERWIST_SW_ENTRY.register": `${register}`,
786
+ "self.__SERWIST_SW_ENTRY.reloadOnOnline": `${reloadOnOnline}`
787
787
  }));
788
788
  const swEntryJs = path.join(__dirname, "sw-entry.js");
789
789
  const entry = config.entry;
@@ -822,20 +822,25 @@ const withPWAInit = (pluginOptions)=>{
822
822
  const { swSrc: providedSwSrc, swDest: providedSwDest, additionalPrecacheEntries, exclude = [], manifestTransforms = [], ...otherBuildOptions } = buildOptions;
823
823
  let swSrc = providedSwSrc;
824
824
  let swDest = providedSwDest;
825
+ // If these two paths are not absolute, they will be resolved from `compilation.options.output.path`,
826
+ // which is `${options.dir}/${nextConfig.destDir}` for Next.js apps, rather than `${options.dir}`
827
+ // as an user would expect.
825
828
  if (!path.isAbsolute(swSrc)) {
826
829
  swSrc = path.join(options.dir, swSrc);
827
830
  }
828
831
  if (!path.isAbsolute(swDest)) {
829
832
  swDest = path.join(options.dir, swDest);
830
833
  }
834
+ const publicDir = path.resolve(options.dir, "public");
831
835
  const destDir = path.dirname(swDest);
832
836
  const shouldBuildSWEntryWorker = cacheOnFrontEndNav;
833
837
  let swEntryPublicPath = undefined;
838
+ let swEntryWorkerDest = undefined;
834
839
  if (shouldBuildSWEntryWorker) {
835
840
  const swEntryWorkerSrc = path.join(__dirname, "sw-entry-worker.js");
836
841
  const swEntryName = `swe-worker-${getContentHash(swEntryWorkerSrc, dev)}.js`;
837
842
  swEntryPublicPath = path.posix.join(basePath, swEntryName);
838
- const swEntryWorkerDest = path.join(destDir, swEntryName);
843
+ swEntryWorkerDest = path.join(destDir, swEntryName);
839
844
  config.plugins.push(new ChildCompilationPlugin({
840
845
  src: swEntryWorkerSrc,
841
846
  dest: swEntryWorkerDest
@@ -858,18 +863,24 @@ const withPWAInit = (pluginOptions)=>{
858
863
  let resolvedManifestEntries = additionalPrecacheEntries;
859
864
  if (!resolvedManifestEntries) {
860
865
  const swDestFileName = path.basename(swDest);
861
- resolvedManifestEntries = fg.sync([
862
- "**/*",
863
- // Include these in case the user outputs these files to `public`.
866
+ const userPublicGlob = typeof globPublicPatterns === "string" ? [
867
+ globPublicPatterns
868
+ ] : globPublicPatterns ?? [
869
+ "**/*"
870
+ ];
871
+ const publicScan = fg.sync([
872
+ ...userPublicGlob,
873
+ // Forcibly include these in case the user outputs these files to `public`.
864
874
  "!swe-worker-*.js",
865
875
  "!swe-worker-*.js.map",
866
876
  `!${swDestFileName.replace(/^\/+/, "")}`,
867
877
  `!${swDestFileName.replace(/^\/+/, "")}.map`
868
878
  ], {
869
- cwd: "public"
870
- }).map((f)=>({
879
+ cwd: publicDir
880
+ });
881
+ resolvedManifestEntries = publicScan.map((f)=>({
871
882
  url: path.posix.join(basePath, f),
872
- revision: getFileHash(`public/${f}`)
883
+ revision: getFileHash(path.join(publicDir, f))
873
884
  }));
874
885
  }
875
886
  const publicPath = config.output?.publicPath;
@@ -880,28 +891,30 @@ const withPWAInit = (pluginOptions)=>{
880
891
  additionalPrecacheEntries: dev ? [] : resolvedManifestEntries,
881
892
  exclude: [
882
893
  ...exclude,
883
- ({ asset })=>{
884
- if (asset.name.startsWith("server/") || asset.name.match(/^((app-|^)build-manifest\.json|react-loadable-manifest\.json)$/)) {
885
- return true;
886
- }
887
- if (dev && !asset.name.startsWith("static/runtime/")) {
888
- return true;
889
- }
890
- return false;
894
+ ({ asset, compilation })=>{
895
+ // Same as how `@serwist/webpack-plugin` does it. It is always
896
+ // `relativeToOutputPath(compilation, originalSwDest)`.
897
+ const swDestRelativeOutput = relativeToOutputPath(compilation, swDest);
898
+ const swAsset = compilation.getAsset(swDestRelativeOutput);
899
+ return(// We don't need the service worker to be cached.
900
+ asset.name === swAsset?.name || asset.name.startsWith("server/") || /^((app-|^)build-manifest\.json|react-loadable-manifest\.json)$/.test(asset.name) || dev && !asset.name.startsWith("static/runtime/"));
891
901
  }
892
902
  ],
893
903
  manifestTransforms: [
894
904
  ...manifestTransforms,
895
905
  async (manifestEntries, compilation)=>{
906
+ // This path always uses forward slashes, so it is safe to use it in the following string replace.
907
+ const publicDirRelativeOutput = relativeToOutputPath(compilation, publicDir);
908
+ // `publicPath` is always `${assetPrefix}/_next/` for Next.js apps.
909
+ const publicFilesPrefix = `${publicPath}${publicDirRelativeOutput}`;
896
910
  const manifest = manifestEntries.map((m)=>{
897
- m.url = m.url.replace("/_next//static/image", "/_next/static/image").replace("/_next//static/media", "/_next/static/media").replace("/_next/../public", "");
898
- if (m.revision === null) {
899
- let key = m.url;
900
- if (typeof publicPath === "string" && key.startsWith(publicPath)) {
901
- key = m.url.substring(publicPath.length);
902
- }
903
- const asset = compilation.assetsInfo.get(key);
904
- m.revision = asset ? asset.contenthash || buildId : buildId;
911
+ m.url = m.url.replace("/_next//static/image", "/_next/static/image").replace("/_next//static/media", "/_next/static/media");
912
+ // We remove `${publicPath}/${publicDirRelativeOutput}` because `assetPrefix`
913
+ // is not intended for files that are in the public directory and we also want
914
+ // to remove `/_next/${publicDirRelativeOutput}` from the URL, since that is not how
915
+ // we resolve files in the public directory.
916
+ if (m.url.startsWith(publicFilesPrefix)) {
917
+ m.url = path.posix.join(basePath, m.url.replace(publicFilesPrefix, ""));
905
918
  }
906
919
  m.url = m.url.replace(/\[/g, "%5B").replace(/\]/g, "%5D");
907
920
  return m;
@@ -920,4 +933,4 @@ const withPWAInit = (pluginOptions)=>{
920
933
  });
921
934
  };
922
935
 
923
- export { withPWAInit as default };
936
+ export { withSerwistInit as default };
@@ -0,0 +1,5 @@
1
+ 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 };
5
+ //# sourceMappingURL=index.worker.d.ts.map
@@ -0,0 +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,4 +1,29 @@
1
- 'use strict';
1
+ const nonNullable = (value)=>value !== null && value !== undefined;
2
+
3
+ /**
4
+ * Conveniently define three `runtimeCaching` entries for Next.js pages.
5
+ * @param options
6
+ * @returns
7
+ */ const definePageRuntimeCaching = ({ rscPrefetch, rsc, html })=>{
8
+ const pageRcs = [
9
+ rscPrefetch,
10
+ rsc,
11
+ html
12
+ ];
13
+ if (pageRcs[0]) {
14
+ if (!pageRcs[0].options) pageRcs[0].options = {};
15
+ pageRcs[0].options.cacheName = "pages-rsc-prefetch";
16
+ }
17
+ if (pageRcs[1]) {
18
+ if (!pageRcs[1].options) pageRcs[1].options = {};
19
+ pageRcs[1].options.cacheName = "pages-rsc";
20
+ }
21
+ if (pageRcs[2]) {
22
+ if (!pageRcs[2].options) pageRcs[2].options = {};
23
+ pageRcs[2].options.cacheName = "pages";
24
+ }
25
+ return pageRcs.filter(nonNullable);
26
+ };
2
27
 
3
28
  // Serwist RuntimeCaching config: https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.RuntimeCachingEntry
4
29
  const defaultCache = [
@@ -160,33 +185,43 @@ const defaultCache = [
160
185
  networkTimeoutSeconds: 10
161
186
  }
162
187
  },
163
- {
164
- urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
165
- handler: "NetworkFirst",
166
- options: {
167
- cacheName: "pages-rsc-prefetch",
168
- expiration: {
169
- maxEntries: 32,
170
- maxAgeSeconds: 24 * 60 * 60
188
+ ...definePageRuntimeCaching({
189
+ rscPrefetch: {
190
+ urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
191
+ handler: "NetworkFirst",
192
+ options: {
193
+ expiration: {
194
+ maxEntries: 32,
195
+ maxAgeSeconds: 24 * 60 * 60
196
+ }
171
197
  }
172
- }
173
- },
174
- {
175
- urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
176
- handler: "NetworkFirst",
177
- options: {
178
- cacheName: "pages-rsc",
179
- expiration: {
180
- maxEntries: 32,
181
- maxAgeSeconds: 24 * 60 * 60
198
+ },
199
+ rsc: {
200
+ urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
201
+ handler: "NetworkFirst",
202
+ options: {
203
+ expiration: {
204
+ maxEntries: 32,
205
+ maxAgeSeconds: 24 * 60 * 60
206
+ }
207
+ }
208
+ },
209
+ html: {
210
+ urlPattern: ({ request, url: { pathname }, sameOrigin })=>request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
211
+ handler: "NetworkFirst",
212
+ options: {
213
+ expiration: {
214
+ maxEntries: 32,
215
+ maxAgeSeconds: 24 * 60 * 60
216
+ }
182
217
  }
183
218
  }
184
- },
219
+ }),
185
220
  {
186
221
  urlPattern: ({ url: { pathname }, sameOrigin })=>sameOrigin && !pathname.startsWith("/api/"),
187
222
  handler: "NetworkFirst",
188
223
  options: {
189
- cacheName: "pages",
224
+ cacheName: "others",
190
225
  expiration: {
191
226
  maxEntries: 32,
192
227
  maxAgeSeconds: 24 * 60 * 60
@@ -207,4 +242,4 @@ const defaultCache = [
207
242
  }
208
243
  ];
209
244
 
210
- exports.defaultCache = defaultCache;
245
+ export { defaultCache, definePageRuntimeCaching };
@@ -1,3 +1,4 @@
1
+ import type { Asset, Compilation } from "webpack";
1
2
  export type SerwistNextOptionsKey = "self.__SERWIST_SW_ENTRY";
2
3
  export interface SerwistNextOptions {
3
4
  sw: string;
@@ -7,3 +8,8 @@ export interface SerwistNextOptions {
7
8
  reloadOnOnline: boolean;
8
9
  swEntryWorker: string | undefined;
9
10
  }
11
+ export interface ExcludeParams {
12
+ asset: Asset;
13
+ compilation: Compilation;
14
+ }
15
+ //# sourceMappingURL=internal-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-types.d.ts","sourceRoot":"","sources":["../src/internal-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;CAC1B"}
@@ -5,3 +5,4 @@ export type MessageType = {
5
5
  type: "__START_URL_CACHE__";
6
6
  url: URL | string;
7
7
  };
8
+ //# sourceMappingURL=sw-entry-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sw-entry-worker.d.ts","sourceRoot":"","sources":["../src/sw-entry-worker.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GACnB;IACE,IAAI,EAAE,wBAAwB,CAAC;IAC/B,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC;CACnB,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC;CACnB,CAAC"}
@@ -4,3 +4,4 @@ declare global {
4
4
  serwist: Serwist;
5
5
  }
6
6
  }
7
+ //# sourceMappingURL=sw-entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sw-entry.d.ts","sourceRoot":"","sources":["../src/sw-entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,CAAC;KAClB;CACF"}
@@ -5,3 +5,4 @@
5
5
  * @returns
6
6
  */
7
7
  export declare const findFirstTruthy: <T, U>(arr: T[], fn: (elm: T) => U) => NonNullable<U> | undefined;
8
+ //# sourceMappingURL=find-first-truthy.d.ts.map
@@ -0,0 +1 @@
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,3 +1,4 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type fs from "node:fs";
3
3
  export declare const getContentHash: (file: fs.PathOrFileDescriptor, isDev: boolean) => string;
4
+ //# sourceMappingURL=get-content-hash.d.ts.map
@@ -0,0 +1 @@
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,3 +1,4 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import fs from "node:fs";
3
3
  export declare const getFileHash: (file: fs.PathOrFileDescriptor) => string;
4
+ //# sourceMappingURL=get-file-hash.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -4,3 +4,4 @@
4
4
  * @returns
5
5
  */
6
6
  export declare const getPackageVersion: (packageName: string) => string | undefined;
7
+ //# sourceMappingURL=get-package-version.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -4,3 +4,4 @@ export { getFileHash } from "./get-file-hash.js";
4
4
  export { getPackageVersion } from "./get-package-version.js";
5
5
  export { loadTSConfig } from "./load-tsconfig.js";
6
6
  export * as logger from "./logger.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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,2 +1,3 @@
1
1
  import type { TsConfigJson as TSConfigJSON } from "type-fest";
2
2
  export declare const loadTSConfig: (baseDir: string, relativeTSConfigPath: string | undefined) => TSConfigJSON | undefined;
3
+ //# sourceMappingURL=load-tsconfig.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -3,3 +3,4 @@ export declare const error: (...message: any[]) => void;
3
3
  export declare const warn: (...message: any[]) => void;
4
4
  export declare const info: (...message: any[]) => void;
5
5
  export declare const event: (...message: any[]) => void;
6
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
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"}
package/dist/utils.d.ts CHANGED
@@ -2,3 +2,4 @@
2
2
  import fs from "node:fs";
3
3
  export declare const getFileHash: (file: fs.PathOrFileDescriptor) => string;
4
4
  export declare const getContentHash: (file: fs.PathOrFileDescriptor, isDev: boolean) => string;
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,eAAO,MAAM,WAAW,SAAU,GAAG,oBAAoB,WAAyE,CAAC;AAEnI,eAAO,MAAM,cAAc,SAAU,GAAG,oBAAoB,SAAS,OAAO,WAK3E,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RuntimeCaching } from "@serwist/sw";
2
+ export declare const defaultCache: RuntimeCaching[];
3
+ //# sourceMappingURL=defaultCache.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "8.4.4",
3
+ "version": "9.0.0-preview.0",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
7
- "dist",
8
- "!dist/dts"
7
+ "src",
8
+ "dist"
9
9
  ],
10
10
  "keywords": [
11
11
  "serwist",
@@ -15,77 +15,75 @@
15
15
  "web",
16
16
  "service-worker"
17
17
  ],
18
+ "engines": {
19
+ "node": ">=18.0.0"
20
+ },
18
21
  "author": "Serwist's Team",
19
22
  "license": "MIT",
20
23
  "repository": "serwist/serwist",
21
24
  "bugs": "https://github.com/serwist/serwist/issues",
22
25
  "homepage": "https://serwist.pages.dev",
23
- "module": "./dist/index.js",
24
- "main": "./dist/index.cjs",
26
+ "main": "./dist/index.js",
25
27
  "types": "./dist/index.d.ts",
26
- "exports": {
27
- ".": {
28
- "import": {
29
- "types": "./dist/index.d.ts",
30
- "default": "./dist/index.js"
31
- },
32
- "require": {
33
- "types": "./dist/index.d.cts",
34
- "default": "./dist/index.cjs"
35
- }
36
- },
37
- "./browser": {
38
- "import": {
39
- "types": "./dist/index.browser.d.ts",
40
- "default": "./dist/index.browser.js"
41
- },
42
- "require": {
43
- "types": "./dist/index.browser.d.cts",
44
- "default": "./dist/index.browser.cjs"
45
- }
46
- },
47
- "./typings": {
48
- "import": {
49
- "types": "./dist/sw-entry.d.ts"
50
- },
51
- "require": {
52
- "types": "./dist/sw-entry.d.cts"
53
- }
54
- },
55
- "./package.json": "./package.json"
56
- },
57
28
  "typesVersions": {
58
29
  "*": {
59
- "browser": [
60
- "./dist/index.browser.d.ts"
30
+ "worker": [
31
+ "./dist/index.worker.d.ts"
61
32
  ],
62
33
  "typings": [
63
34
  "./dist/sw-entry.d.ts"
64
35
  ]
65
36
  }
66
37
  },
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "default": "./dist/index.js"
42
+ },
43
+ "./worker": {
44
+ "types": "./dist/index.worker.d.ts",
45
+ "default": "./dist/index.worker.js"
46
+ },
47
+ "./typings": {
48
+ "types": "./dist/sw-entry.d.ts"
49
+ },
50
+ "./package.json": "./package.json"
51
+ },
67
52
  "dependencies": {
68
53
  "clean-webpack-plugin": "4.0.0",
69
54
  "fast-glob": "3.3.2",
70
- "@serwist/build": "8.4.4",
71
- "@serwist/webpack-plugin": "8.4.4",
72
- "@serwist/window": "8.4.4"
55
+ "@serwist/build": "9.0.0-preview.0",
56
+ "@serwist/core": "9.0.0-preview.0",
57
+ "@serwist/webpack-plugin": "9.0.0-preview.0",
58
+ "@serwist/window": "9.0.0-preview.0"
73
59
  },
74
60
  "devDependencies": {
75
- "@types/node": "20.10.5",
61
+ "@types/node": "20.11.16",
76
62
  "chalk": "5.3.0",
77
- "next": "14.0.4",
63
+ "next": "14.1.0",
78
64
  "react": "18.2.0",
79
65
  "react-dom": "18.2.0",
80
- "rollup": "4.9.1",
81
- "type-fest": "4.8.3",
82
- "typescript": "5.4.0-dev.20231226",
83
- "webpack": "5.89.0",
84
- "@serwist/constants": "8.4.4"
66
+ "rollup": "4.9.6",
67
+ "type-fest": "4.10.2",
68
+ "typescript": "5.4.0-dev.20240203",
69
+ "webpack": "5.90.1",
70
+ "@serwist/constants": "9.0.0-preview.0",
71
+ "@serwist/sw": "9.0.0-preview.0",
72
+ "@serwist/utils": "9.0.0-preview.0"
85
73
  },
86
74
  "peerDependencies": {
87
75
  "next": ">=14.0.0",
88
- "webpack": ">=5.9.0"
76
+ "typescript": ">=5.0.0",
77
+ "webpack": ">=5.9.0",
78
+ "@serwist/sw": "9.0.0-preview.0"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "@serwist/sw": {
82
+ "optional": true
83
+ },
84
+ "typescript": {
85
+ "optional": true
86
+ }
89
87
  },
90
88
  "scripts": {
91
89
  "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",