@serwist/next 8.2.0 → 8.4.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.
package/README.md CHANGED
@@ -1 +1 @@
1
- This module's documentation can be found at https://serwist.vercel.app/docs/next
1
+ This module's documentation can be found at https://serwist.pages.dev/docs/next
@@ -0,0 +1,2 @@
1
+ import type { RuntimeCaching } from "@serwist/build";
2
+ export declare const defaultCache: RuntimeCaching[];
package/dist/index.d.cts CHANGED
@@ -0,0 +1,5 @@
1
+ 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";
@@ -0,0 +1,9 @@
1
+ export type SerwistNextOptionsKey = "self.__SERWIST_SW_ENTRY";
2
+ export interface SerwistNextOptions {
3
+ sw: string;
4
+ scope: string;
5
+ cacheOnFrontEndNav: boolean;
6
+ register: boolean;
7
+ reloadOnOnline: boolean;
8
+ swEntryWorker: string | undefined;
9
+ }
@@ -0,0 +1,7 @@
1
+ export type MessageType = {
2
+ type: "__FRONTEND_NAV_CACHE__";
3
+ url: URL | string;
4
+ } | {
5
+ type: "__START_URL_CACHE__";
6
+ url: URL | string;
7
+ };
@@ -0,0 +1,6 @@
1
+ import { Serwist } from "@serwist/window";
2
+ declare global {
3
+ interface Window {
4
+ serwist: Serwist;
5
+ }
6
+ }
package/dist/types.d.cts CHANGED
@@ -0,0 +1,81 @@
1
+ import type { WebpackInjectManifestOptions } from "@serwist/build";
2
+ type Require<T, U extends keyof T> = T & Required<Pick<T, U>>;
3
+ export interface PluginOptions extends Require<WebpackInjectManifestOptions, "swDest"> {
4
+ /**
5
+ * Enable additional route caching when users navigate through pages with
6
+ * `next/link`. This improves the user experience in some cases but it
7
+ * also adds a bit of overhead due to additional network calls.
8
+ * @default false
9
+ */
10
+ cacheOnFrontEndNav?: boolean;
11
+ /**
12
+ * Whether Serwist should be disabled.
13
+ * @default false
14
+ */
15
+ disable?: boolean;
16
+ /**
17
+ * Whether `@serwist/next` should automatically register the service worker for you. If
18
+ * you want to register the service worker yourself, set this to `false` and run
19
+ * `window.serwist.register()` in `componentDidMount` or `useEffect`.
20
+ * @example
21
+ * ```tsx
22
+ * // app/register-pwa.tsx
23
+ * "use client";
24
+ * import { useEffect } from "react";
25
+ * import type { Serwist } from "@serwist/window";
26
+ *
27
+ * declare global {
28
+ * interface Window {
29
+ * serwist: Serwist;
30
+ * }
31
+ * }
32
+ *
33
+ * export default function RegisterPWA() {
34
+ * useEffect(() => {
35
+ * if ("serviceWorker" in navigator && window.serwist !== undefined) {
36
+ * window.serwist.register();
37
+ * }
38
+ * }, []);
39
+ * return <></>;
40
+ * }
41
+ *
42
+ * // app/layout.tsx
43
+ * import RegisterPWA from "./register-pwa";
44
+ *
45
+ * export default function RootLayout({
46
+ * children,
47
+ * }: {
48
+ * children: React.ReactNode;
49
+ * }) {
50
+ * return (
51
+ * <html lang="en">
52
+ * <head />
53
+ * <body>
54
+ * <RegisterPWA />
55
+ * {children}
56
+ * </body>
57
+ * </html>
58
+ * );
59
+ * }
60
+ * ```
61
+ * @default true
62
+ */
63
+ register?: boolean;
64
+ /**
65
+ * Whether Serwist should reload the app when it goes online.
66
+ * @default true
67
+ */
68
+ reloadOnOnline?: boolean;
69
+ /**
70
+ * The service worker's URL scope. Set to `/foo/` so that paths under `/foo/` are under the service
71
+ * worker's control while others are not.
72
+ * @default nextConfig.basePath
73
+ */
74
+ scope?: string;
75
+ /**
76
+ * The URL to the service worker.
77
+ * @default "/sw.js"
78
+ */
79
+ swUrl?: string;
80
+ }
81
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Find the first truthy value in an array.
3
+ * @param arr
4
+ * @param fn
5
+ * @returns
6
+ */
7
+ export declare const findFirstTruthy: <T, U>(arr: T[], fn: (elm: T) => U) => NonNullable<U> | undefined;
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type fs from "node:fs";
3
+ export declare const getContentHash: (file: fs.PathOrFileDescriptor, isDev: boolean) => string;
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import fs from "node:fs";
3
+ export declare const getFileHash: (file: fs.PathOrFileDescriptor) => string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get a package's version
3
+ * @param packageName
4
+ * @returns
5
+ */
6
+ export declare const getPackageVersion: (packageName: string) => string | undefined;
@@ -0,0 +1,6 @@
1
+ export { findFirstTruthy } from "./find-first-truthy.js";
2
+ export { getContentHash } from "./get-content-hash.js";
3
+ export { getFileHash } from "./get-file-hash.js";
4
+ export { getPackageVersion } from "./get-package-version.js";
5
+ export { loadTSConfig } from "./load-tsconfig.js";
6
+ export * as logger from "./logger.js";
@@ -0,0 +1,2 @@
1
+ import type { TsConfigJson as TSConfigJSON } from "type-fest";
2
+ export declare const loadTSConfig: (baseDir: string, relativeTSConfigPath: string | undefined) => TSConfigJSON | undefined;
@@ -0,0 +1,5 @@
1
+ export declare const wait: (...message: any[]) => void;
2
+ export declare const error: (...message: any[]) => void;
3
+ export declare const warn: (...message: any[]) => void;
4
+ export declare const info: (...message: any[]) => void;
5
+ export declare const event: (...message: any[]) => void;
package/dist/utils.d.cts CHANGED
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import fs from "node:fs";
3
+ export declare const getFileHash: (file: fs.PathOrFileDescriptor) => string;
4
+ export declare const getContentHash: (file: fs.PathOrFileDescriptor, isDev: boolean) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/next",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "repository": "serwist/serwist",
21
21
  "bugs": "https://github.com/serwist/serwist/issues",
22
- "homepage": "https://serwist.vercel.app",
22
+ "homepage": "https://serwist.pages.dev",
23
23
  "module": "./dist/index.js",
24
24
  "main": "./dist/index.cjs",
25
25
  "types": "./dist/index.d.ts",
@@ -67,9 +67,9 @@
67
67
  "dependencies": {
68
68
  "clean-webpack-plugin": "4.0.0",
69
69
  "fast-glob": "3.3.2",
70
- "@serwist/build": "8.2.0",
71
- "@serwist/webpack-plugin": "8.2.0",
72
- "@serwist/window": "8.2.0"
70
+ "@serwist/build": "8.4.0",
71
+ "@serwist/webpack-plugin": "8.4.0",
72
+ "@serwist/window": "8.4.0"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@types/node": "20.10.5",
@@ -81,7 +81,7 @@
81
81
  "type-fest": "4.8.3",
82
82
  "typescript": "5.4.0-dev.20231226",
83
83
  "webpack": "5.89.0",
84
- "@serwist/constants": "8.2.0"
84
+ "@serwist/constants": "8.4.0"
85
85
  },
86
86
  "peerDependencies": {
87
87
  "next": ">=14.0.0",
@@ -89,6 +89,7 @@
89
89
  },
90
90
  "scripts": {
91
91
  "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
92
+ "dev": "rollup --config rollup.config.js --watch",
92
93
  "lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs",
93
94
  "typecheck": "tsc"
94
95
  }