@serwist/next 8.0.3 → 8.0.5

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.
@@ -0,0 +1,2 @@
1
+ import type { RuntimeCaching } from "@serwist/build";
2
+ export declare const defaultCache: RuntimeCaching[];
@@ -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,43 @@
1
+ 'use strict';
2
+
3
+ var window$1 = require('@serwist/window');
4
+
5
+ if (typeof window !== "undefined" && "serviceWorker" in navigator && typeof caches !== "undefined") {
6
+ let swEntryWorker;
7
+ if (self.__SERWIST_SW_ENTRY.swEntryWorker) {
8
+ swEntryWorker = new Worker(self.__SERWIST_SW_ENTRY.swEntryWorker);
9
+ }
10
+ window.serwist = new window$1.Serwist(window.location.origin + self.__SERWIST_SW_ENTRY.sw, {
11
+ scope: self.__SERWIST_SW_ENTRY.scope
12
+ });
13
+ if (self.__SERWIST_SW_ENTRY.register) {
14
+ window.serwist.register();
15
+ }
16
+ if (self.__SERWIST_SW_ENTRY.cacheOnFrontEndNav) {
17
+ const cacheOnFrontEndNav = async (url)=>{
18
+ if (!window.navigator.onLine || !url) {
19
+ return;
20
+ }
21
+ swEntryWorker?.postMessage({
22
+ type: "__FRONTEND_NAV_CACHE__",
23
+ url
24
+ });
25
+ };
26
+ const pushState = history.pushState;
27
+ history.pushState = (...args)=>{
28
+ pushState.apply(history, args);
29
+ cacheOnFrontEndNav(args[2]);
30
+ };
31
+ const replaceState = history.replaceState;
32
+ history.replaceState = (...args)=>{
33
+ replaceState.apply(history, args);
34
+ cacheOnFrontEndNav(args[2]);
35
+ };
36
+ window.addEventListener("online", ()=>{
37
+ cacheOnFrontEndNav(window.location.pathname);
38
+ });
39
+ }
40
+ if (self.__SERWIST_SW_ENTRY.reloadOnOnline) {
41
+ window.addEventListener("online", ()=>location.reload());
42
+ }
43
+ }
@@ -0,0 +1,6 @@
1
+ import { Serwist } from "@serwist/window";
2
+ declare global {
3
+ interface Window {
4
+ serwist: Serwist;
5
+ }
6
+ }
@@ -1,2 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  import type fs from "node:fs";
2
3
  export declare const getContentHash: (file: fs.PathOrFileDescriptor, isDev: boolean) => string;
@@ -1,2 +1,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  import fs from "node:fs";
2
3
  export declare const getFileHash: (file: fs.PathOrFileDescriptor) => string;
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  import fs from "node:fs";
2
3
  export declare const getFileHash: (file: fs.PathOrFileDescriptor) => string;
3
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.0.3",
3
+ "version": "8.0.5",
4
4
  "type": "module",
5
5
  "description": "A module that integrates Serwist into your Next.js application.",
6
6
  "files": [
@@ -25,18 +25,32 @@
25
25
  "types": "./dist/index.d.ts",
26
26
  "exports": {
27
27
  ".": {
28
- "import": "./dist/index.js",
29
- "require": "./dist/index.old.cjs",
30
- "types": "./dist/index.d.ts"
28
+ "import": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.old.d.cts",
34
+ "default": "./dist/index.old.cjs"
35
+ }
31
36
  },
32
37
  "./browser": {
33
- "import": "./dist/index.browser.js",
34
- "require": "./dist/index.browser.old.cjs",
35
- "types": "./dist/index.browser.d.ts"
38
+ "import": {
39
+ "types": "./dist/index.browser.d.ts",
40
+ "default": "./dist/index.browser.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/index.browser.old.d.cts",
44
+ "default": "./dist/index.browser.old.cjs"
45
+ }
36
46
  },
37
47
  "./typings": {
38
- "import": "./dist/sw-entry.d.ts",
39
- "require": "./dist/sw-entry.d.ts"
48
+ "import": {
49
+ "types": "./dist/sw-entry.d.ts"
50
+ },
51
+ "require": {
52
+ "types": "./dist/sw-entry.old.d.cts"
53
+ }
40
54
  },
41
55
  "./package.json": "./package.json"
42
56
  },
@@ -52,22 +66,22 @@
52
66
  },
53
67
  "dependencies": {
54
68
  "clean-webpack-plugin": "4.0.0",
55
- "fast-glob": "3.3.1",
56
- "@serwist/build": "8.0.3",
57
- "@serwist/webpack-plugin": "8.0.3",
58
- "@serwist/window": "8.0.3"
69
+ "fast-glob": "3.3.2",
70
+ "@serwist/build": "8.0.5",
71
+ "@serwist/webpack-plugin": "8.0.5",
72
+ "@serwist/window": "8.0.5"
59
73
  },
60
74
  "devDependencies": {
61
- "@types/node": "20.8.7",
75
+ "@types/node": "20.10.4",
62
76
  "chalk": "5.3.0",
63
- "next": "14.0.3",
77
+ "next": "14.0.4",
64
78
  "react": "18.2.0",
65
79
  "react-dom": "18.2.0",
66
80
  "rollup": "3.28.1",
67
- "type-fest": "4.5.0",
68
- "typescript": "5.3.0-dev.20231011",
81
+ "type-fest": "4.8.3",
82
+ "typescript": "5.4.0-dev.20231213",
69
83
  "webpack": "5.89.0",
70
- "@serwist/constants": "8.0.3"
84
+ "@serwist/constants": "8.0.5"
71
85
  },
72
86
  "peerDependencies": {
73
87
  "next": ">=14.0.0",