@serwist/next 9.0.0-preview.12 → 9.0.0-preview.14
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 +20 -4
- 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/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/defaultCache.d.ts +2 -14
- package/dist/worker/defaultCache.d.ts.map +1 -1
- package/package.json +26 -18
- package/src/index.schema.ts +3 -0
- package/src/index.ts +12 -8
- package/src/lib/schema.ts +21 -0
- package/src/lib/types.ts +104 -0
- package/src/lib/validator.ts +13 -0
- package/src/worker/defaultCache.ts +2 -2
- 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/{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
|
@@ -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
|
-
|
|
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
|
|
11
|
+
export { validateInjectManifestOptions };
|
|
12
|
+
export type { InjectManifestOptions as PluginOptions, InjectManifestOptionsComplete as PluginOptionsComplete };
|
|
6
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,UAkO3F,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,13 +1,16 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { validateNextInjectManifestOptions } from '@serwist/build/next';
|
|
5
4
|
import { InjectManifest } from '@serwist/webpack-plugin';
|
|
6
5
|
import { ChildCompilationPlugin, relativeToOutputPath } from '@serwist/webpack-plugin/internal';
|
|
7
6
|
import { globSync } from 'glob';
|
|
8
7
|
import crypto from 'node:crypto';
|
|
9
8
|
import { createRequire } from 'node:module';
|
|
10
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';
|
|
11
14
|
|
|
12
15
|
const findFirstTruthy = (arr, fn)=>{
|
|
13
16
|
for (const i of arr){
|
|
@@ -82,8 +85,21 @@ const event = (...message)=>{
|
|
|
82
85
|
prefixedLog("event", ...message);
|
|
83
86
|
};
|
|
84
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
|
+
|
|
85
101
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
86
|
-
const withSerwistInit = (
|
|
102
|
+
const withSerwistInit = (userOptions)=>{
|
|
87
103
|
return (nextConfig = {})=>({
|
|
88
104
|
...nextConfig,
|
|
89
105
|
webpack (config, options) {
|
|
@@ -91,7 +107,7 @@ const withSerwistInit = (pluginOptions)=>{
|
|
|
91
107
|
const { dev } = options;
|
|
92
108
|
const basePath = options.config.basePath || "/";
|
|
93
109
|
const tsConfigJson = loadTSConfig(options.dir, nextConfig?.typescript?.tsconfigPath);
|
|
94
|
-
const { cacheOnNavigation, disable, scope = basePath, swUrl, register, reloadOnOnline, globPublicPatterns, ...buildOptions } =
|
|
110
|
+
const { cacheOnNavigation, disable, scope = basePath, swUrl, register, reloadOnOnline, globPublicPatterns, ...buildOptions } = validateInjectManifestOptions(userOptions);
|
|
95
111
|
if (typeof nextConfig.webpack === "function") {
|
|
96
112
|
config = nextConfig.webpack(config, options);
|
|
97
113
|
}
|
|
@@ -256,4 +272,4 @@ const withSerwistInit = (pluginOptions)=>{
|
|
|
256
272
|
});
|
|
257
273
|
};
|
|
258
274
|
|
|
259
|
-
export { withSerwistInit as default };
|
|
275
|
+
export { withSerwistInit as default, validateInjectManifestOptions };
|
|
@@ -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 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/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"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const injectPartial: z.ZodObject<{
|
|
3
|
+
cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
|
|
4
|
+
disable: z.ZodDefault<z.ZodBoolean>;
|
|
5
|
+
register: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
8
|
+
swUrl: z.ZodDefault<z.ZodString>;
|
|
9
|
+
globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
10
|
+
}, "strict", z.ZodTypeAny, {
|
|
11
|
+
cacheOnNavigation: boolean;
|
|
12
|
+
disable: boolean;
|
|
13
|
+
register: boolean;
|
|
14
|
+
reloadOnOnline: boolean;
|
|
15
|
+
swUrl: string;
|
|
16
|
+
globPublicPatterns: string[];
|
|
17
|
+
scope?: string | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
cacheOnNavigation?: boolean | undefined;
|
|
20
|
+
disable?: boolean | undefined;
|
|
21
|
+
register?: boolean | undefined;
|
|
22
|
+
reloadOnOnline?: boolean | undefined;
|
|
23
|
+
scope?: string | undefined;
|
|
24
|
+
swUrl?: string | undefined;
|
|
25
|
+
globPublicPatterns?: string[] | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const injectManifestOptions: z.ZodObject<Omit<{
|
|
28
|
+
chunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
29
|
+
exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
|
|
30
|
+
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
31
|
+
include: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
|
|
32
|
+
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
33
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
34
|
+
revision: z.ZodNullable<z.ZodString>;
|
|
35
|
+
url: z.ZodString;
|
|
36
|
+
}, "strict", z.ZodTypeAny, {
|
|
37
|
+
revision: string | null;
|
|
38
|
+
url: string;
|
|
39
|
+
integrity?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
revision: string | null;
|
|
42
|
+
url: string;
|
|
43
|
+
integrity?: string | undefined;
|
|
44
|
+
}>]>, "many">>;
|
|
45
|
+
disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
|
|
46
|
+
dontCacheBustURLsMatching: z.ZodOptional<z.ZodType<RegExp, z.ZodTypeDef, RegExp>>;
|
|
47
|
+
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
48
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
49
|
+
revision: z.ZodNullable<z.ZodString>;
|
|
50
|
+
url: z.ZodString;
|
|
51
|
+
size: z.ZodNumber;
|
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
|
53
|
+
revision: string | null;
|
|
54
|
+
url: string;
|
|
55
|
+
size: number;
|
|
56
|
+
integrity?: string | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
revision: string | null;
|
|
59
|
+
url: string;
|
|
60
|
+
size: number;
|
|
61
|
+
integrity?: string | undefined;
|
|
62
|
+
}>, "many">, z.ZodOptional<z.ZodUnknown>], null>, z.ZodUnion<[z.ZodPromise<z.ZodObject<{
|
|
63
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
64
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
65
|
+
revision: z.ZodNullable<z.ZodString>;
|
|
66
|
+
url: z.ZodString;
|
|
67
|
+
size: z.ZodNumber;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
revision: string | null;
|
|
70
|
+
url: string;
|
|
71
|
+
size: number;
|
|
72
|
+
integrity?: string | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
revision: string | null;
|
|
75
|
+
url: string;
|
|
76
|
+
size: number;
|
|
77
|
+
integrity?: string | undefined;
|
|
78
|
+
}>, "many">;
|
|
79
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
80
|
+
}, "strict", z.ZodTypeAny, {
|
|
81
|
+
manifest: {
|
|
82
|
+
revision: string | null;
|
|
83
|
+
url: string;
|
|
84
|
+
size: number;
|
|
85
|
+
integrity?: string | undefined;
|
|
86
|
+
}[];
|
|
87
|
+
warnings?: string[] | undefined;
|
|
88
|
+
}, {
|
|
89
|
+
manifest: {
|
|
90
|
+
revision: string | null;
|
|
91
|
+
url: string;
|
|
92
|
+
size: number;
|
|
93
|
+
integrity?: string | undefined;
|
|
94
|
+
}[];
|
|
95
|
+
warnings?: string[] | undefined;
|
|
96
|
+
}>>, z.ZodObject<{
|
|
97
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
98
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
99
|
+
revision: z.ZodNullable<z.ZodString>;
|
|
100
|
+
url: z.ZodString;
|
|
101
|
+
size: z.ZodNumber;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
revision: string | null;
|
|
104
|
+
url: string;
|
|
105
|
+
size: number;
|
|
106
|
+
integrity?: string | undefined;
|
|
107
|
+
}, {
|
|
108
|
+
revision: string | null;
|
|
109
|
+
url: string;
|
|
110
|
+
size: number;
|
|
111
|
+
integrity?: string | undefined;
|
|
112
|
+
}>, "many">;
|
|
113
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
114
|
+
}, "strict", z.ZodTypeAny, {
|
|
115
|
+
manifest: {
|
|
116
|
+
revision: string | null;
|
|
117
|
+
url: string;
|
|
118
|
+
size: number;
|
|
119
|
+
integrity?: string | undefined;
|
|
120
|
+
}[];
|
|
121
|
+
warnings?: string[] | undefined;
|
|
122
|
+
}, {
|
|
123
|
+
manifest: {
|
|
124
|
+
revision: string | null;
|
|
125
|
+
url: string;
|
|
126
|
+
size: number;
|
|
127
|
+
integrity?: string | undefined;
|
|
128
|
+
}[];
|
|
129
|
+
warnings?: string[] | undefined;
|
|
130
|
+
}>]>>, "many">>;
|
|
131
|
+
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
132
|
+
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
133
|
+
injectionPoint: z.ZodDefault<z.ZodString>;
|
|
134
|
+
swSrc: z.ZodString;
|
|
135
|
+
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
136
|
+
swDest: z.ZodString;
|
|
137
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
138
|
+
cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
|
|
139
|
+
disable: z.ZodDefault<z.ZodBoolean>;
|
|
140
|
+
register: z.ZodDefault<z.ZodBoolean>;
|
|
141
|
+
reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
|
|
142
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
143
|
+
swUrl: z.ZodDefault<z.ZodString>;
|
|
144
|
+
globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
145
|
+
}, "disablePrecacheManifest">, "strict", z.ZodTypeAny, {
|
|
146
|
+
cacheOnNavigation: boolean;
|
|
147
|
+
disable: boolean;
|
|
148
|
+
register: boolean;
|
|
149
|
+
reloadOnOnline: boolean;
|
|
150
|
+
swUrl: string;
|
|
151
|
+
globPublicPatterns: string[];
|
|
152
|
+
exclude: (string | RegExp | ((args_0: any) => boolean))[];
|
|
153
|
+
maximumFileSizeToCacheInBytes: number;
|
|
154
|
+
injectionPoint: string;
|
|
155
|
+
swSrc: string;
|
|
156
|
+
compileSrc: boolean;
|
|
157
|
+
swDest: string;
|
|
158
|
+
scope?: string | undefined;
|
|
159
|
+
chunks?: string[] | undefined;
|
|
160
|
+
excludeChunks?: string[] | undefined;
|
|
161
|
+
include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
162
|
+
additionalPrecacheEntries?: (string | {
|
|
163
|
+
revision: string | null;
|
|
164
|
+
url: string;
|
|
165
|
+
integrity?: string | undefined;
|
|
166
|
+
})[] | undefined;
|
|
167
|
+
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
168
|
+
manifestTransforms?: ((args_0: {
|
|
169
|
+
revision: string | null;
|
|
170
|
+
url: string;
|
|
171
|
+
size: number;
|
|
172
|
+
integrity?: string | undefined;
|
|
173
|
+
}[], args_1: unknown) => {
|
|
174
|
+
manifest: {
|
|
175
|
+
revision: string | null;
|
|
176
|
+
url: string;
|
|
177
|
+
size: number;
|
|
178
|
+
integrity?: string | undefined;
|
|
179
|
+
}[];
|
|
180
|
+
warnings?: string[] | undefined;
|
|
181
|
+
} | Promise<{
|
|
182
|
+
manifest: {
|
|
183
|
+
revision: string | null;
|
|
184
|
+
url: string;
|
|
185
|
+
size: number;
|
|
186
|
+
integrity?: string | undefined;
|
|
187
|
+
}[];
|
|
188
|
+
warnings?: string[] | undefined;
|
|
189
|
+
}>)[] | undefined;
|
|
190
|
+
modifyURLPrefix?: Record<string, string> | undefined;
|
|
191
|
+
webpackCompilationPlugins?: any[] | undefined;
|
|
192
|
+
}, {
|
|
193
|
+
swSrc: string;
|
|
194
|
+
swDest: string;
|
|
195
|
+
cacheOnNavigation?: boolean | undefined;
|
|
196
|
+
disable?: boolean | undefined;
|
|
197
|
+
register?: boolean | undefined;
|
|
198
|
+
reloadOnOnline?: boolean | undefined;
|
|
199
|
+
scope?: string | undefined;
|
|
200
|
+
swUrl?: string | undefined;
|
|
201
|
+
globPublicPatterns?: string[] | undefined;
|
|
202
|
+
chunks?: string[] | undefined;
|
|
203
|
+
exclude?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
204
|
+
excludeChunks?: string[] | undefined;
|
|
205
|
+
include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
206
|
+
additionalPrecacheEntries?: (string | {
|
|
207
|
+
revision: string | null;
|
|
208
|
+
url: string;
|
|
209
|
+
integrity?: string | undefined;
|
|
210
|
+
})[] | undefined;
|
|
211
|
+
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
212
|
+
manifestTransforms?: ((args_0: {
|
|
213
|
+
revision: string | null;
|
|
214
|
+
url: string;
|
|
215
|
+
size: number;
|
|
216
|
+
integrity?: string | undefined;
|
|
217
|
+
}[], args_1: unknown) => {
|
|
218
|
+
manifest: {
|
|
219
|
+
revision: string | null;
|
|
220
|
+
url: string;
|
|
221
|
+
size: number;
|
|
222
|
+
integrity?: string | undefined;
|
|
223
|
+
}[];
|
|
224
|
+
warnings?: string[] | undefined;
|
|
225
|
+
} | Promise<{
|
|
226
|
+
manifest: {
|
|
227
|
+
revision: string | null;
|
|
228
|
+
url: string;
|
|
229
|
+
size: number;
|
|
230
|
+
integrity?: string | undefined;
|
|
231
|
+
}[];
|
|
232
|
+
warnings?: string[] | undefined;
|
|
233
|
+
}>)[] | undefined;
|
|
234
|
+
maximumFileSizeToCacheInBytes?: number | undefined;
|
|
235
|
+
modifyURLPrefix?: Record<string, string> | undefined;
|
|
236
|
+
injectionPoint?: string | undefined;
|
|
237
|
+
compileSrc?: boolean | undefined;
|
|
238
|
+
webpackCompilationPlugins?: any[] | undefined;
|
|
239
|
+
}>;
|
|
240
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;EAU+C,CAAC;AAE1E,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIuC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { RequiredSwDestPartial, RequiredSwDestResolved } from "@serwist/build";
|
|
2
|
+
import type { Require } from "@serwist/utils";
|
|
3
|
+
import type { InjectManifestOptions as WebpackInjectManifestOptions, InjectManifestOptionsComplete as WebpackInjectManifestOptionsComplete } from "@serwist/webpack-plugin";
|
|
4
|
+
export interface InjectPartial {
|
|
5
|
+
/**
|
|
6
|
+
* Enables additional route caching when users navigate through pages with
|
|
7
|
+
* `next/link`. This improves the user experience in some cases but it
|
|
8
|
+
* also adds a bit of overhead due to additional network calls.
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
cacheOnNavigation?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether Serwist should be disabled.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
disable?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `@serwist/next` should automatically register the service worker for you. If
|
|
19
|
+
* you want to register the service worker yourself, set this to `false` and run
|
|
20
|
+
* `window.serwist.register()` in `componentDidMount` or `useEffect`.
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* // app/register-pwa.tsx
|
|
24
|
+
* "use client";
|
|
25
|
+
* import { useEffect } from "react";
|
|
26
|
+
* import type { Serwist } from "@serwist/window";
|
|
27
|
+
*
|
|
28
|
+
* declare global {
|
|
29
|
+
* interface Window {
|
|
30
|
+
* serwist: Serwist;
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* export default function RegisterPWA() {
|
|
35
|
+
* useEffect(() => {
|
|
36
|
+
* if ("serviceWorker" in navigator && window.serwist !== undefined) {
|
|
37
|
+
* window.serwist.register();
|
|
38
|
+
* }
|
|
39
|
+
* }, []);
|
|
40
|
+
* return <></>;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // app/layout.tsx
|
|
44
|
+
* import RegisterPWA from "./register-pwa";
|
|
45
|
+
*
|
|
46
|
+
* export default function RootLayout({
|
|
47
|
+
* children,
|
|
48
|
+
* }: {
|
|
49
|
+
* children: React.ReactNode;
|
|
50
|
+
* }) {
|
|
51
|
+
* return (
|
|
52
|
+
* <html lang="en">
|
|
53
|
+
* <head />
|
|
54
|
+
* <body>
|
|
55
|
+
* <RegisterPWA />
|
|
56
|
+
* {children}
|
|
57
|
+
* </body>
|
|
58
|
+
* </html>
|
|
59
|
+
* );
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
register?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether Serwist should reload the app when it goes online.
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
reloadOnOnline?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The service worker's URL scope. Set to `/foo/` so that paths under `/foo/` are under the service
|
|
72
|
+
* worker's control while others are not.
|
|
73
|
+
* @default nextConfig.basePath
|
|
74
|
+
*/
|
|
75
|
+
scope?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The URL to the service worker.
|
|
78
|
+
* @default "/sw.js"
|
|
79
|
+
*/
|
|
80
|
+
swUrl?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Files in the public directory matching any of these patterns
|
|
83
|
+
* will be included in the precache manifest. For more information,
|
|
84
|
+
* see [`node-glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
|
|
85
|
+
* @default
|
|
86
|
+
* ```
|
|
87
|
+
* ["**\/*"]
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
globPublicPatterns?: string[];
|
|
91
|
+
}
|
|
92
|
+
export type InjectResolved = Require<InjectPartial, "cacheOnNavigation" | "disable" | "register" | "reloadOnOnline" | "swUrl" | "globPublicPatterns">;
|
|
93
|
+
export type InjectManifestOptions = Omit<WebpackInjectManifestOptions & RequiredSwDestPartial & InjectPartial, "disablePrecacheManifest">;
|
|
94
|
+
export type InjectManifestOptionsComplete = Omit<WebpackInjectManifestOptionsComplete & RequiredSwDestResolved & InjectResolved, "disablePrecacheManifest">;
|
|
95
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EACV,qBAAqB,IAAI,4BAA4B,EACrD,6BAA6B,IAAI,oCAAoC,EACtE,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,mBAAmB,GAAG,SAAS,GAAG,UAAU,GAAG,gBAAgB,GAAG,OAAO,GAAG,oBAAoB,CAAC,CAAC;AAEtJ,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,4BAA4B,GAAG,qBAAqB,GAAG,aAAa,EAAE,yBAAyB,CAAC,CAAC;AAE1I,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,oCAAoC,GAAG,sBAAsB,GAAG,cAAc,EAC9E,yBAAyB,CAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,6BAA6B,UAAW,OAAO,KAAG,6BAQ9D,CAAC"}
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const defaultCache:
|
|
3
|
-
matcher: RegExp;
|
|
4
|
-
handler: CacheFirst;
|
|
5
|
-
method?: undefined;
|
|
6
|
-
} | {
|
|
7
|
-
matcher: ({ sameOrigin, url: { pathname } }: import("@serwist/core").RouteMatchCallbackOptions) => boolean;
|
|
8
|
-
method: "GET";
|
|
9
|
-
handler: NetworkFirst;
|
|
10
|
-
} | {
|
|
11
|
-
matcher: ({ request, url: { pathname }, sameOrigin }: import("@serwist/core").RouteMatchCallbackOptions) => boolean | undefined;
|
|
12
|
-
handler: NetworkFirst;
|
|
13
|
-
method?: undefined;
|
|
14
|
-
})[];
|
|
1
|
+
import type { RuntimeCaching } from "@serwist/sw";
|
|
2
|
+
export declare const defaultCache: RuntimeCaching[];
|
|
15
3
|
//# sourceMappingURL=defaultCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defaultCache.d.ts","sourceRoot":"","sources":["../../src/worker/defaultCache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAKlD,eAAO,MAAM,YAAY,EAAE,cAAc,EA6OxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/next",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that integrates Serwist into your Next.js application.",
|
|
6
6
|
"files": [
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
],
|
|
38
38
|
"typings": [
|
|
39
39
|
"./dist/sw-entry.d.ts"
|
|
40
|
+
],
|
|
41
|
+
"schema": [
|
|
42
|
+
"./dist/index.schema.d.ts"
|
|
40
43
|
]
|
|
41
44
|
}
|
|
42
45
|
},
|
|
@@ -52,36 +55,41 @@
|
|
|
52
55
|
"./typings": {
|
|
53
56
|
"types": "./dist/sw-entry.d.ts"
|
|
54
57
|
},
|
|
58
|
+
"./schema": {
|
|
59
|
+
"types": "./dist/index.schema.d.ts",
|
|
60
|
+
"default": "./dist/index.schema.js"
|
|
61
|
+
},
|
|
55
62
|
"./package.json": "./package.json"
|
|
56
63
|
},
|
|
57
64
|
"dependencies": {
|
|
58
65
|
"chalk": "5.3.0",
|
|
59
66
|
"glob": "10.3.10",
|
|
60
|
-
"
|
|
61
|
-
"@serwist/
|
|
62
|
-
"@serwist/
|
|
63
|
-
"@serwist/
|
|
64
|
-
"@serwist/
|
|
65
|
-
"@serwist/
|
|
66
|
-
"@serwist/
|
|
67
|
+
"zod": "3.22.4",
|
|
68
|
+
"@serwist/build": "9.0.0-preview.14",
|
|
69
|
+
"@serwist/core": "9.0.0-preview.14",
|
|
70
|
+
"@serwist/expiration": "9.0.0-preview.14",
|
|
71
|
+
"@serwist/range-requests": "9.0.0-preview.14",
|
|
72
|
+
"@serwist/strategies": "9.0.0-preview.14",
|
|
73
|
+
"@serwist/webpack-plugin": "9.0.0-preview.14",
|
|
74
|
+
"@serwist/window": "9.0.0-preview.14"
|
|
67
75
|
},
|
|
68
76
|
"devDependencies": {
|
|
69
|
-
"@types/node": "20.11.
|
|
70
|
-
"next": "14.1.
|
|
77
|
+
"@types/node": "20.11.26",
|
|
78
|
+
"next": "14.1.3",
|
|
71
79
|
"react": "18.2.0",
|
|
72
80
|
"react-dom": "18.2.0",
|
|
73
|
-
"rollup": "4.
|
|
74
|
-
"type-fest": "4.
|
|
75
|
-
"typescript": "5.
|
|
76
|
-
"webpack": "5.90.
|
|
77
|
-
"@serwist/constants": "9.0.0-preview.
|
|
78
|
-
"@serwist/sw": "9.0.0-preview.
|
|
79
|
-
"@serwist/utils": "9.0.0-preview.
|
|
81
|
+
"rollup": "4.13.0",
|
|
82
|
+
"type-fest": "4.12.0",
|
|
83
|
+
"typescript": "5.5.0-dev.20240312",
|
|
84
|
+
"webpack": "5.90.3",
|
|
85
|
+
"@serwist/constants": "9.0.0-preview.14",
|
|
86
|
+
"@serwist/sw": "9.0.0-preview.14",
|
|
87
|
+
"@serwist/utils": "9.0.0-preview.14"
|
|
80
88
|
},
|
|
81
89
|
"peerDependencies": {
|
|
82
90
|
"next": ">=14.0.0",
|
|
83
91
|
"typescript": ">=5.0.0",
|
|
84
|
-
"@serwist/sw": "9.0.0-preview.
|
|
92
|
+
"@serwist/sw": "9.0.0-preview.14"
|
|
85
93
|
},
|
|
86
94
|
"peerDependenciesMeta": {
|
|
87
95
|
"@serwist/sw": {
|
package/src/index.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
import type { NextInjectManifestOptions } from "@serwist/build";
|
|
6
|
-
import { validateNextInjectManifestOptions } from "@serwist/build/next";
|
|
7
4
|
import { InjectManifest } from "@serwist/webpack-plugin";
|
|
8
5
|
import { ChildCompilationPlugin, relativeToOutputPath } from "@serwist/webpack-plugin/internal";
|
|
9
6
|
import { globSync } from "glob";
|
|
10
7
|
import type { NextConfig } from "next";
|
|
11
8
|
import type { Compilation, Configuration, default as Webpack } from "webpack";
|
|
12
|
-
|
|
13
9
|
import type { ExcludeParams, SerwistNextOptions, SerwistNextOptionsKey } from "./internal-types.js";
|
|
14
|
-
import { getContentHash, getFileHash, loadTSConfig, logger } from "./
|
|
10
|
+
import { getContentHash, getFileHash, loadTSConfig, logger } from "./lib/index.js";
|
|
11
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
|
|
12
|
+
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
15
13
|
|
|
16
14
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Integrates Serwist into your Next.js app.
|
|
18
|
+
* @param userOptions
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
const withSerwistInit = (userOptions: InjectManifestOptions): ((nextConfig?: NextConfig) => NextConfig) => {
|
|
19
22
|
return (nextConfig = {}) => ({
|
|
20
23
|
...nextConfig,
|
|
21
24
|
webpack(config: Configuration, options) {
|
|
@@ -35,7 +38,7 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
35
38
|
reloadOnOnline,
|
|
36
39
|
globPublicPatterns,
|
|
37
40
|
...buildOptions
|
|
38
|
-
} =
|
|
41
|
+
} = validateInjectManifestOptions(userOptions);
|
|
39
42
|
|
|
40
43
|
if (typeof nextConfig.webpack === "function") {
|
|
41
44
|
config = nextConfig.webpack(config, options);
|
|
@@ -244,4 +247,5 @@ const withSerwistInit = (pluginOptions: NextInjectManifestOptions): ((nextConfig
|
|
|
244
247
|
};
|
|
245
248
|
|
|
246
249
|
export default withSerwistInit;
|
|
247
|
-
export
|
|
250
|
+
export { validateInjectManifestOptions };
|
|
251
|
+
export type { InjectManifestOptions as PluginOptions, InjectManifestOptionsComplete as PluginOptionsComplete };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { requiredSwDestPartial } from "@serwist/build/schema";
|
|
2
|
+
import { injectManifestOptions as webpackInjectManifestOptions } from "@serwist/webpack-plugin/schema";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
export const injectPartial = z
|
|
6
|
+
.object({
|
|
7
|
+
cacheOnNavigation: z.boolean().default(false),
|
|
8
|
+
disable: z.boolean().default(false),
|
|
9
|
+
register: z.boolean().default(true),
|
|
10
|
+
reloadOnOnline: z.boolean().default(true),
|
|
11
|
+
scope: z.string().optional(),
|
|
12
|
+
swUrl: z.string().default("/sw.js"),
|
|
13
|
+
globPublicPatterns: z.array(z.string()).default(["**/*"]),
|
|
14
|
+
})
|
|
15
|
+
.strict("Do not pass invalid properties to NextInjectManifestPartial!");
|
|
16
|
+
|
|
17
|
+
export const injectManifestOptions = webpackInjectManifestOptions
|
|
18
|
+
.merge(requiredSwDestPartial)
|
|
19
|
+
.merge(injectPartial)
|
|
20
|
+
.omit({ disablePrecacheManifest: true })
|
|
21
|
+
.strict("Do not pass invalid properties to NextInjectManifestOptions!");
|
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
|
+
};
|
|
@@ -6,7 +6,7 @@ import type { RuntimeCaching } from "@serwist/sw";
|
|
|
6
6
|
import { PAGES_CACHE_NAME } from "./constants.js";
|
|
7
7
|
|
|
8
8
|
// Serwist RuntimeCaching config: https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
9
|
-
export const defaultCache = [
|
|
9
|
+
export const defaultCache: RuntimeCaching[] = [
|
|
10
10
|
{
|
|
11
11
|
matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
12
12
|
handler: new CacheFirst({
|
|
@@ -243,4 +243,4 @@ export const defaultCache = [
|
|
|
243
243
|
networkTimeoutSeconds: 10,
|
|
244
244
|
}),
|
|
245
245
|
},
|
|
246
|
-
]
|
|
246
|
+
];
|
|
@@ -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"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|