@serwist/build 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.
- package/dist/chunks/glob.js +3 -3
- package/dist/chunks/injectManifest.js +5 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -58
- package/dist/index.schema.d.ts +13 -0
- package/dist/index.schema.d.ts.map +1 -0
- package/dist/index.schema.js +9 -0
- package/dist/lib/additional-precache-entries-transform.d.ts +6 -8
- package/dist/lib/additional-precache-entries-transform.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -3
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/get-file-details.d.ts +3 -9
- package/dist/lib/get-file-details.d.ts.map +1 -1
- package/dist/lib/get-file-hash.d.ts +1 -1
- package/dist/lib/get-file-hash.d.ts.map +1 -1
- package/dist/lib/get-file-manifest-entries.d.ts +2 -2
- package/dist/lib/get-file-manifest-entries.d.ts.map +1 -1
- package/dist/lib/get-string-details.d.ts +1 -1
- package/dist/lib/get-string-details.d.ts.map +1 -1
- package/dist/lib/get-string-hash.d.ts +1 -1
- package/dist/lib/get-string-hash.d.ts.map +1 -1
- package/dist/lib/transform-manifest.d.ts +4 -3
- package/dist/lib/transform-manifest.d.ts.map +1 -1
- package/dist/lib/validate-options.d.ts +1 -3
- package/dist/lib/validate-options.d.ts.map +1 -1
- package/dist/schema/assertType.d.ts +1 -0
- package/dist/schema/assertType.d.ts.map +1 -1
- package/dist/schema/base.d.ts +24 -24
- package/dist/schema/getManifest.d.ts +24 -24
- package/dist/schema/injectManifest.d.ts +27 -27
- package/dist/schema/injectManifest.d.ts.map +1 -1
- package/dist/schema/manifestEntry.d.ts +3 -3
- package/dist/schema/manifestTransform.d.ts +18 -18
- package/dist/{lib/serwist-config-error.d.ts → schema/serwistConfigError.d.ts} +1 -1
- package/dist/schema/serwistConfigError.d.ts.map +1 -0
- package/dist/types.d.ts +6 -156
- package/dist/types.d.ts.map +1 -1
- package/package.json +15 -23
- package/src/index.schema.ts +29 -0
- package/src/index.ts +2 -3
- package/src/inject-manifest.ts +1 -1
- package/src/lib/additional-precache-entries-transform.ts +4 -8
- package/src/lib/errors.ts +0 -6
- package/src/lib/get-composite-details.ts +2 -2
- package/src/lib/get-file-details.ts +9 -17
- package/src/lib/get-file-hash.ts +4 -4
- package/src/lib/get-file-manifest-entries.ts +9 -9
- package/src/lib/get-string-details.ts +5 -7
- package/src/lib/get-string-hash.ts +1 -1
- package/src/lib/transform-manifest.ts +28 -16
- package/src/lib/validate-options.ts +2 -23
- package/src/schema/assertType.ts +2 -0
- package/src/schema/injectManifest.ts +4 -4
- package/src/schema/manifestEntry.ts +1 -1
- package/src/types.ts +6 -188
- package/dist/chunks/vite.js +0 -7
- package/dist/chunks/webpack.js +0 -34
- package/dist/index.next.d.ts +0 -3
- package/dist/index.next.d.ts.map +0 -1
- package/dist/index.next.js +0 -38
- package/dist/lib/serwist-config-error.d.ts.map +0 -1
- package/dist/lib/validate-next-options.d.ts +0 -3
- package/dist/lib/validate-next-options.d.ts.map +0 -1
- package/dist/schema/next.d.ts +0 -243
- package/dist/schema/next.d.ts.map +0 -1
- package/dist/schema/vite.d.ts +0 -196
- package/dist/schema/vite.d.ts.map +0 -1
- package/dist/schema/webpack.d.ts +0 -231
- package/dist/schema/webpack.d.ts.map +0 -1
- package/src/_types.js +0 -112
- package/src/index.next.ts +0 -3
- package/src/lib/validate-next-options.ts +0 -14
- package/src/schema/next.ts +0 -33
- package/src/schema/vite.ts +0 -18
- package/src/schema/webpack.ts +0 -47
- package/dist/chunks/{serwist-config-error.js → validationErrorMap.js} +7 -7
- /package/src/{lib/serwist-config-error.ts → schema/serwistConfigError.ts} +0 -0
package/src/lib/get-file-hash.ts
CHANGED
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import { readFileSync } from "node:fs";
|
|
10
10
|
|
|
11
11
|
import { errors } from "./errors.js";
|
|
12
12
|
import { getStringHash } from "./get-string-hash.js";
|
|
13
13
|
|
|
14
|
-
export
|
|
14
|
+
export const getFileHash = (file: string): string => {
|
|
15
15
|
try {
|
|
16
|
-
const buffer =
|
|
16
|
+
const buffer = readFileSync(file);
|
|
17
17
|
return getStringHash(buffer);
|
|
18
18
|
} catch (err) {
|
|
19
19
|
throw new Error(`${errors["unable-to-get-file-hash"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
};
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import assert from "assert";
|
|
9
|
+
import assert from "node:assert";
|
|
10
10
|
|
|
11
|
-
import type { FileDetails,
|
|
11
|
+
import type { FileDetails, GetManifestOptionsComplete, GetManifestResult } from "../types.js";
|
|
12
12
|
import { errors } from "./errors.js";
|
|
13
13
|
import { getCompositeDetails } from "./get-composite-details.js";
|
|
14
14
|
import { getFileDetails } from "./get-file-details.js";
|
|
15
15
|
import { getStringDetails } from "./get-string-details.js";
|
|
16
16
|
import { transformManifest } from "./transform-manifest.js";
|
|
17
17
|
|
|
18
|
-
export async
|
|
18
|
+
export const getFileManifestEntries = async ({
|
|
19
19
|
additionalPrecacheEntries,
|
|
20
20
|
dontCacheBustURLsMatching,
|
|
21
21
|
globDirectory,
|
|
@@ -28,7 +28,7 @@ export async function getFileManifestEntries({
|
|
|
28
28
|
modifyURLPrefix,
|
|
29
29
|
templatedURLs,
|
|
30
30
|
disablePrecacheManifest,
|
|
31
|
-
}:
|
|
31
|
+
}: GetManifestOptionsComplete): Promise<GetManifestResult> => {
|
|
32
32
|
if (disablePrecacheManifest) {
|
|
33
33
|
return {
|
|
34
34
|
count: 0,
|
|
@@ -94,14 +94,14 @@ export async function getFileManifestEntries({
|
|
|
94
94
|
const debugObj: { [key: string]: string[] } = {};
|
|
95
95
|
debugObj[url] = dependencies;
|
|
96
96
|
throw new Error(
|
|
97
|
-
`${errors["bad-template-urls-asset"]}
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
`${errors["bad-template-urls-asset"]} '${globPattern}' from '${JSON.stringify(debugObj)}':\n${
|
|
98
|
+
error instanceof Error ? error.toString() : ""
|
|
99
|
+
}`,
|
|
100
100
|
);
|
|
101
101
|
}
|
|
102
102
|
}, []);
|
|
103
103
|
if (details.length === 0) {
|
|
104
|
-
throw new Error(`${errors["bad-template-urls-asset"]} The glob
|
|
104
|
+
throw new Error(`${errors["bad-template-urls-asset"]} The glob pattern '${dependencies.toString()}' did not match anything.`);
|
|
105
105
|
}
|
|
106
106
|
allFileDetails.set(url, getCompositeDetails(url, details));
|
|
107
107
|
} else if (typeof dependencies === "string") {
|
|
@@ -123,4 +123,4 @@ export async function getFileManifestEntries({
|
|
|
123
123
|
transformedManifest.warnings.push(...warnings);
|
|
124
124
|
|
|
125
125
|
return transformedManifest;
|
|
126
|
-
}
|
|
126
|
+
};
|
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
import type { FileDetails } from "../types.js";
|
|
10
10
|
import { getStringHash } from "./get-string-hash.js";
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
}
|
|
12
|
+
export const getStringDetails = (url: string, str: string): FileDetails => ({
|
|
13
|
+
file: url,
|
|
14
|
+
hash: getStringHash(str),
|
|
15
|
+
size: str.length,
|
|
16
|
+
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { BaseResolved, FileDetails, ManifestEntry, ManifestTransform } from "../types.js";
|
|
10
10
|
import { additionalPrecacheEntriesTransform } from "./additional-precache-entries-transform.js";
|
|
11
11
|
import { errors } from "./errors.js";
|
|
12
12
|
import { maximumSizeTransform } from "./maximum-size-transform.js";
|
|
@@ -68,6 +68,25 @@ interface ManifestTransformResultWithWarnings {
|
|
|
68
68
|
manifestEntries: ManifestEntry[] | undefined;
|
|
69
69
|
warnings: string[];
|
|
70
70
|
}
|
|
71
|
+
interface ManifestEntryWithSize extends ManifestEntry {
|
|
72
|
+
size: number;
|
|
73
|
+
}
|
|
74
|
+
interface TransformManifestOptions
|
|
75
|
+
extends Pick<
|
|
76
|
+
BaseResolved,
|
|
77
|
+
| "additionalPrecacheEntries"
|
|
78
|
+
| "dontCacheBustURLsMatching"
|
|
79
|
+
| "manifestTransforms"
|
|
80
|
+
| "maximumFileSizeToCacheInBytes"
|
|
81
|
+
| "modifyURLPrefix"
|
|
82
|
+
| "disablePrecacheManifest"
|
|
83
|
+
> {
|
|
84
|
+
fileDetails: FileDetails[];
|
|
85
|
+
// When this is called by the webpack plugin, transformParam will be the
|
|
86
|
+
// current webpack compilation.
|
|
87
|
+
transformParam?: unknown;
|
|
88
|
+
}
|
|
89
|
+
|
|
71
90
|
export async function transformManifest({
|
|
72
91
|
additionalPrecacheEntries,
|
|
73
92
|
dontCacheBustURLsMatching,
|
|
@@ -77,12 +96,7 @@ export async function transformManifest({
|
|
|
77
96
|
modifyURLPrefix,
|
|
78
97
|
transformParam,
|
|
79
98
|
disablePrecacheManifest,
|
|
80
|
-
}:
|
|
81
|
-
fileDetails: FileDetails[];
|
|
82
|
-
// When this is called by the webpack plugin, transformParam will be the
|
|
83
|
-
// current webpack compilation.
|
|
84
|
-
transformParam?: unknown;
|
|
85
|
-
}): Promise<ManifestTransformResultWithWarnings> {
|
|
99
|
+
}: TransformManifestOptions): Promise<ManifestTransformResultWithWarnings> {
|
|
86
100
|
if (disablePrecacheManifest) {
|
|
87
101
|
return {
|
|
88
102
|
count: 0,
|
|
@@ -96,13 +110,11 @@ export async function transformManifest({
|
|
|
96
110
|
|
|
97
111
|
// Take the array of fileDetail objects and convert it into an array of
|
|
98
112
|
// {url, revision, size} objects, with \ replaced with /.
|
|
99
|
-
const normalizedManifest = fileDetails.map((fileDetails) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
});
|
|
113
|
+
const normalizedManifest: ManifestEntryWithSize[] = fileDetails.map((fileDetails) => ({
|
|
114
|
+
url: fileDetails.file.replace(/\\/g, "/"),
|
|
115
|
+
revision: fileDetails.hash,
|
|
116
|
+
size: fileDetails.size,
|
|
117
|
+
}));
|
|
106
118
|
|
|
107
119
|
const transformsToApply: ManifestTransform[] = [];
|
|
108
120
|
|
|
@@ -128,7 +140,7 @@ export async function transformManifest({
|
|
|
128
140
|
transformsToApply.push(additionalPrecacheEntriesTransform(additionalPrecacheEntries));
|
|
129
141
|
}
|
|
130
142
|
|
|
131
|
-
let transformedManifest:
|
|
143
|
+
let transformedManifest: ManifestEntryWithSize[] = normalizedManifest;
|
|
132
144
|
for (const transform of transformsToApply) {
|
|
133
145
|
const result = await transform(transformedManifest, transformParam);
|
|
134
146
|
if (!("manifest" in result)) {
|
|
@@ -145,7 +157,7 @@ export async function transformManifest({
|
|
|
145
157
|
let size = 0;
|
|
146
158
|
for (const manifestEntry of transformedManifest as (ManifestEntry & { size?: number })[]) {
|
|
147
159
|
size += manifestEntry.size || 0;
|
|
148
|
-
// biome-ignore lint/performance/noDelete:
|
|
160
|
+
// biome-ignore lint/performance/noDelete: These values are no longer necessary.
|
|
149
161
|
delete manifestEntry.size;
|
|
150
162
|
}
|
|
151
163
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SerwistConfigError } from "../schema/serwistConfigError.js";
|
|
1
2
|
/*
|
|
2
3
|
Copyright 2021 Google LLC
|
|
3
4
|
|
|
@@ -6,13 +7,7 @@
|
|
|
6
7
|
https://opensource.org/licenses/MIT.
|
|
7
8
|
*/
|
|
8
9
|
import { validationErrorMap } from "../schema/validationErrorMap.js";
|
|
9
|
-
import type {
|
|
10
|
-
GetManifestOptionsComplete,
|
|
11
|
-
InjectManifestOptionsComplete,
|
|
12
|
-
ViteInjectManifestOptionsComplete,
|
|
13
|
-
WebpackInjectManifestOptionsComplete,
|
|
14
|
-
} from "../types.js";
|
|
15
|
-
import { SerwistConfigError } from "./serwist-config-error.js";
|
|
10
|
+
import type { GetManifestOptionsComplete, InjectManifestOptionsComplete } from "../types.js";
|
|
16
11
|
|
|
17
12
|
export const validateGetManifestOptions = async (input: unknown): Promise<GetManifestOptionsComplete> => {
|
|
18
13
|
const result = await (await import("../schema/getManifest.js")).getManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
@@ -29,19 +24,3 @@ export const validateInjectManifestOptions = async (input: unknown): Promise<Inj
|
|
|
29
24
|
}
|
|
30
25
|
return result.data;
|
|
31
26
|
};
|
|
32
|
-
|
|
33
|
-
export const validateWebpackInjectManifestOptions = async (input: unknown): Promise<WebpackInjectManifestOptionsComplete> => {
|
|
34
|
-
const result = await (await import("../schema/webpack.js")).webpackInjectManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
35
|
-
if (!result.success) {
|
|
36
|
-
throw new SerwistConfigError({ moduleName: "@serwist/webpack-plugin", message: JSON.stringify(result.error.format(), null, 2) });
|
|
37
|
-
}
|
|
38
|
-
return result.data;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const validateViteInjectManifestOptions = async (input: unknown): Promise<ViteInjectManifestOptionsComplete> => {
|
|
42
|
-
const result = await (await import("../schema/vite.js")).viteInjectManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
43
|
-
if (!result.success) {
|
|
44
|
-
throw new SerwistConfigError({ moduleName: "@serwist/vite", message: JSON.stringify(result.error.format(), null, 2) });
|
|
45
|
-
}
|
|
46
|
-
return result.data;
|
|
47
|
-
};
|
package/src/schema/assertType.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { basePartial } from "./base.js";
|
|
|
5
5
|
import { globPartial, requiredGlobDirectoryPartial } from "./glob.js";
|
|
6
6
|
import { requiredSwDestPartial } from "./swDest.js";
|
|
7
7
|
|
|
8
|
-
export const
|
|
8
|
+
export const baseInjectPartial = z
|
|
9
9
|
.object({
|
|
10
10
|
injectionPoint: z.string().default("self.__SW_MANIFEST"),
|
|
11
11
|
swSrc: z.string(),
|
|
@@ -14,12 +14,12 @@ export const injectPartial = z
|
|
|
14
14
|
|
|
15
15
|
export const injectManifestOptions = basePartial
|
|
16
16
|
.merge(globPartial)
|
|
17
|
-
.merge(
|
|
17
|
+
.merge(baseInjectPartial)
|
|
18
18
|
.merge(requiredSwDestPartial)
|
|
19
19
|
.merge(requiredGlobDirectoryPartial)
|
|
20
20
|
.strict("Do not pass invalid properties to InjectManifestOptions!");
|
|
21
21
|
|
|
22
|
-
assertType<Equals<InjectPartial, z.input<typeof
|
|
23
|
-
assertType<Equals<InjectResolved, z.output<typeof
|
|
22
|
+
assertType<Equals<InjectPartial, z.input<typeof baseInjectPartial>>>();
|
|
23
|
+
assertType<Equals<InjectResolved, z.output<typeof baseInjectPartial>>>();
|
|
24
24
|
assertType<Equals<InjectManifestOptions, z.input<typeof injectManifestOptions>>>();
|
|
25
25
|
assertType<Equals<InjectManifestOptionsComplete, z.output<typeof injectManifestOptions>>>();
|
|
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
export const manifestEntry = z
|
|
4
4
|
.object({
|
|
5
5
|
integrity: z.string().optional(),
|
|
6
|
-
revision: z.string().nullable(),
|
|
6
|
+
revision: z.string().nullable().optional(),
|
|
7
7
|
url: z.string(),
|
|
8
8
|
})
|
|
9
9
|
.strict("Do not pass invalid properties to ManifestEntry!");
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Require } from "@serwist/utils";
|
|
2
|
-
import type { Pattern as GlobPattern } from "fast-glob";
|
|
3
2
|
import type { PackageJson } from "type-fest";
|
|
4
3
|
import type { z } from "zod";
|
|
5
4
|
import type { manifestEntry } from "./schema/manifestEntry.js";
|
|
@@ -97,14 +96,14 @@ export interface GlobPartial {
|
|
|
97
96
|
/**
|
|
98
97
|
* Determines whether or not symlinks are followed when generating the
|
|
99
98
|
* precache manifest. For more information, see the definition of `follow` in
|
|
100
|
-
* [`glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
99
|
+
* [`node-glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
101
100
|
* @default true
|
|
102
101
|
*/
|
|
103
102
|
globFollow?: boolean;
|
|
104
103
|
/**
|
|
105
104
|
* A set of patterns matching files to always exclude when generating the
|
|
106
105
|
* precache manifest. For more information, see the definition of `ignore` in
|
|
107
|
-
* [`glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
106
|
+
* [`node-glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
108
107
|
* @default
|
|
109
108
|
* ```
|
|
110
109
|
* ["**\/node_modules\/**\/*"]
|
|
@@ -114,7 +113,7 @@ export interface GlobPartial {
|
|
|
114
113
|
/**
|
|
115
114
|
* Files matching any of these patterns will be included in the precache
|
|
116
115
|
* manifest. For more information, see
|
|
117
|
-
* [`glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
|
|
116
|
+
* [`node-glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
|
|
118
117
|
* @default
|
|
119
118
|
* ```
|
|
120
119
|
* ["**\/*.{js,css,html}"]
|
|
@@ -125,7 +124,7 @@ export interface GlobPartial {
|
|
|
125
124
|
* If true, an error reading a directory when generating a precache manifest
|
|
126
125
|
* will cause the build to fail. If false, the problematic directory will be
|
|
127
126
|
* skipped. For more information, see the definition of `strict` in
|
|
128
|
-
* [`glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
127
|
+
* [`node-glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
129
128
|
* @default true
|
|
130
129
|
*/
|
|
131
130
|
globStrict?: boolean;
|
|
@@ -133,7 +132,7 @@ export interface GlobPartial {
|
|
|
133
132
|
* If a URL is rendered based on some server-side logic, its contents may
|
|
134
133
|
* depend on multiple files or on some other unique string value. The keys in
|
|
135
134
|
* this object are server-rendered URLs. If the values are an array of
|
|
136
|
-
* strings, they will be interpreted as
|
|
135
|
+
* strings, they will be interpreted as glob patterns, and the contents of
|
|
137
136
|
* any files matching the patterns will be used to uniquely version the URL.
|
|
138
137
|
* If used with a single string, it will be interpreted as unique versioning
|
|
139
138
|
* information that you've generated for a given URL.
|
|
@@ -161,50 +160,6 @@ export interface InjectPartial {
|
|
|
161
160
|
|
|
162
161
|
export type InjectResolved = Require<InjectPartial, "injectionPoint">;
|
|
163
162
|
|
|
164
|
-
export interface WebpackPartial {
|
|
165
|
-
/**
|
|
166
|
-
* One or more chunk names whose corresponding output files should be included
|
|
167
|
-
* in the precache manifest.
|
|
168
|
-
*/
|
|
169
|
-
chunks?: string[];
|
|
170
|
-
// We can't use the @default annotation here to assign the value via AJV, as
|
|
171
|
-
// an (RegExp)[] can't be serialized into JSON.
|
|
172
|
-
// The default value of [/\.map$/, /^manifest.*\.js$/] will be assigned by
|
|
173
|
-
// the validation function, and we need to reflect that in the docs.
|
|
174
|
-
/**
|
|
175
|
-
* One or more specifiers used to exclude assets from the precache manifest.
|
|
176
|
-
* This is interpreted following
|
|
177
|
-
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
178
|
-
* as `webpack`'s standard `exclude` option.
|
|
179
|
-
* @default
|
|
180
|
-
* ```
|
|
181
|
-
* [/\.map$/, /^manifest.*\.js$]
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
exclude?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
185
|
-
/**
|
|
186
|
-
* One or more chunk names whose corresponding output files should be excluded
|
|
187
|
-
* from the precache manifest.
|
|
188
|
-
*/
|
|
189
|
-
excludeChunks?: string[];
|
|
190
|
-
/**
|
|
191
|
-
* One or more specifiers used to include assets in the precache manifest.
|
|
192
|
-
* This is interpreted following
|
|
193
|
-
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
194
|
-
* as `webpack`'s standard `include` option.
|
|
195
|
-
*/
|
|
196
|
-
include?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
197
|
-
/**
|
|
198
|
-
* If set to 'production', then an optimized service worker bundle that
|
|
199
|
-
* excludes debugging info will be produced. If not explicitly configured
|
|
200
|
-
* here, the `mode` value configured in the current `webpack` compilation
|
|
201
|
-
* will be used.
|
|
202
|
-
*/
|
|
203
|
-
mode?: string | null;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export type WebpackResolved = Require<WebpackPartial, "exclude">;
|
|
207
|
-
|
|
208
163
|
export interface RequiredSwDestPartial {
|
|
209
164
|
/**
|
|
210
165
|
* The path and filename of the service worker file that will be created by
|
|
@@ -226,121 +181,6 @@ export interface OptionalSwDestPartial {
|
|
|
226
181
|
|
|
227
182
|
export type OptionalSwDestResolved = OptionalSwDestPartial;
|
|
228
183
|
|
|
229
|
-
export interface WebpackInjectManifestPartial {
|
|
230
|
-
/**
|
|
231
|
-
* When `true` (the default), the `swSrc` file will be compiled by `webpack`.
|
|
232
|
-
* When `false`, compilation will not occur (and `webpackCompilationPlugins`
|
|
233
|
-
* can't be used.) Set to `false` if you want to inject the manifest into,
|
|
234
|
-
* e.g., a JSON file.
|
|
235
|
-
* @default true
|
|
236
|
-
*/
|
|
237
|
-
compileSrc?: boolean;
|
|
238
|
-
// This can only be set if `compileSrc` is true, but that restriction can't be
|
|
239
|
-
// represented in TypeScript. It's enforced via custom runtime validation
|
|
240
|
-
// logic and needs to be documented.
|
|
241
|
-
/**
|
|
242
|
-
* Optional `webpack` plugins that will be used when compiling the `swSrc`
|
|
243
|
-
* input file. Only valid if `compileSrc` is `true`.
|
|
244
|
-
*/
|
|
245
|
-
webpackCompilationPlugins?: any[];
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export type WebpackInjectManifestResolved = Require<WebpackInjectManifestPartial, "compileSrc">;
|
|
249
|
-
|
|
250
|
-
export interface NextInjectManifestPartial {
|
|
251
|
-
/**
|
|
252
|
-
* Enables additional route caching when users navigate through pages with
|
|
253
|
-
* `next/link`. This improves the user experience in some cases but it
|
|
254
|
-
* also adds a bit of overhead due to additional network calls.
|
|
255
|
-
* @default false
|
|
256
|
-
*/
|
|
257
|
-
cacheOnNavigation?: boolean;
|
|
258
|
-
/**
|
|
259
|
-
* Whether Serwist should be disabled.
|
|
260
|
-
* @default false
|
|
261
|
-
*/
|
|
262
|
-
disable?: boolean;
|
|
263
|
-
/**
|
|
264
|
-
* Whether `@serwist/next` should automatically register the service worker for you. If
|
|
265
|
-
* you want to register the service worker yourself, set this to `false` and run
|
|
266
|
-
* `window.serwist.register()` in `componentDidMount` or `useEffect`.
|
|
267
|
-
* @example
|
|
268
|
-
* ```tsx
|
|
269
|
-
* // app/register-pwa.tsx
|
|
270
|
-
* "use client";
|
|
271
|
-
* import { useEffect } from "react";
|
|
272
|
-
* import type { Serwist } from "@serwist/window";
|
|
273
|
-
*
|
|
274
|
-
* declare global {
|
|
275
|
-
* interface Window {
|
|
276
|
-
* serwist: Serwist;
|
|
277
|
-
* }
|
|
278
|
-
* }
|
|
279
|
-
*
|
|
280
|
-
* export default function RegisterPWA() {
|
|
281
|
-
* useEffect(() => {
|
|
282
|
-
* if ("serviceWorker" in navigator && window.serwist !== undefined) {
|
|
283
|
-
* window.serwist.register();
|
|
284
|
-
* }
|
|
285
|
-
* }, []);
|
|
286
|
-
* return <></>;
|
|
287
|
-
* }
|
|
288
|
-
*
|
|
289
|
-
* // app/layout.tsx
|
|
290
|
-
* import RegisterPWA from "./register-pwa";
|
|
291
|
-
*
|
|
292
|
-
* export default function RootLayout({
|
|
293
|
-
* children,
|
|
294
|
-
* }: {
|
|
295
|
-
* children: React.ReactNode;
|
|
296
|
-
* }) {
|
|
297
|
-
* return (
|
|
298
|
-
* <html lang="en">
|
|
299
|
-
* <head />
|
|
300
|
-
* <body>
|
|
301
|
-
* <RegisterPWA />
|
|
302
|
-
* {children}
|
|
303
|
-
* </body>
|
|
304
|
-
* </html>
|
|
305
|
-
* );
|
|
306
|
-
* }
|
|
307
|
-
* ```
|
|
308
|
-
* @default true
|
|
309
|
-
*/
|
|
310
|
-
register?: boolean;
|
|
311
|
-
/**
|
|
312
|
-
* Whether Serwist should reload the app when it goes online.
|
|
313
|
-
* @default true
|
|
314
|
-
*/
|
|
315
|
-
reloadOnOnline?: boolean;
|
|
316
|
-
/**
|
|
317
|
-
* The service worker's URL scope. Set to `/foo/` so that paths under `/foo/` are under the service
|
|
318
|
-
* worker's control while others are not.
|
|
319
|
-
* @default nextConfig.basePath
|
|
320
|
-
*/
|
|
321
|
-
scope?: string;
|
|
322
|
-
/**
|
|
323
|
-
* The URL to the service worker.
|
|
324
|
-
* @default "/sw.js"
|
|
325
|
-
*/
|
|
326
|
-
swUrl?: string;
|
|
327
|
-
/**
|
|
328
|
-
* Files in the public directory matching any of these patterns
|
|
329
|
-
* will be included in the precache manifest. For more information,
|
|
330
|
-
* see [`fast-glob`'s documentation](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax).
|
|
331
|
-
* @default
|
|
332
|
-
* ```
|
|
333
|
-
* ["**\/*"]
|
|
334
|
-
* ```
|
|
335
|
-
*/
|
|
336
|
-
globPublicPatterns?: GlobPattern | GlobPattern[];
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
export type NextInjectManifestResolved = Require<
|
|
340
|
-
NextInjectManifestPartial,
|
|
341
|
-
"cacheOnNavigation" | "disable" | "register" | "reloadOnOnline" | "swUrl" | "globPublicPatterns"
|
|
342
|
-
>;
|
|
343
|
-
|
|
344
184
|
export type GetManifestOptions = BasePartial & GlobPartial & RequiredGlobDirectoryPartial;
|
|
345
185
|
|
|
346
186
|
export type GetManifestOptionsComplete = BaseResolved & GlobResolved & RequiredGlobDirectoryResolved;
|
|
@@ -349,28 +189,6 @@ export type InjectManifestOptions = BasePartial & GlobPartial & InjectPartial &
|
|
|
349
189
|
|
|
350
190
|
export type InjectManifestOptionsComplete = BaseResolved & GlobResolved & InjectResolved & RequiredSwDestResolved & RequiredGlobDirectoryResolved;
|
|
351
191
|
|
|
352
|
-
export type WebpackInjectManifestOptions = BasePartial & WebpackPartial & InjectPartial & OptionalSwDestPartial & WebpackInjectManifestPartial;
|
|
353
|
-
|
|
354
|
-
export type WebpackInjectManifestOptionsComplete = BaseResolved &
|
|
355
|
-
WebpackResolved &
|
|
356
|
-
InjectResolved &
|
|
357
|
-
OptionalSwDestResolved &
|
|
358
|
-
WebpackInjectManifestResolved;
|
|
359
|
-
|
|
360
|
-
export type ViteInjectManifestOptions = BasePartial & GlobPartial & InjectPartial & RequiredSwDestPartial & RequiredGlobDirectoryPartial;
|
|
361
|
-
|
|
362
|
-
export type ViteInjectManifestOptionsComplete = BaseResolved & GlobResolved & InjectResolved & RequiredSwDestResolved & RequiredGlobDirectoryResolved;
|
|
363
|
-
|
|
364
|
-
export type NextInjectManifestOptions = Omit<
|
|
365
|
-
WebpackInjectManifestOptions & RequiredSwDestPartial & NextInjectManifestPartial,
|
|
366
|
-
"disablePrecacheManifest"
|
|
367
|
-
>;
|
|
368
|
-
|
|
369
|
-
export type NextInjectManifestOptionsComplete = Omit<
|
|
370
|
-
WebpackInjectManifestOptionsComplete & RequiredSwDestResolved & NextInjectManifestResolved,
|
|
371
|
-
"disablePrecacheManifest"
|
|
372
|
-
>;
|
|
373
|
-
|
|
374
192
|
export interface GetManifestResult {
|
|
375
193
|
count: number;
|
|
376
194
|
manifestEntries: ManifestEntry[] | undefined;
|
|
@@ -387,7 +205,7 @@ export type BuildResult = Omit<GetManifestResult, "manifestEntries"> & {
|
|
|
387
205
|
*/
|
|
388
206
|
export interface FileDetails {
|
|
389
207
|
file: string;
|
|
390
|
-
hash: string;
|
|
208
|
+
hash: string | null;
|
|
391
209
|
size: number;
|
|
392
210
|
}
|
|
393
211
|
|
package/dist/chunks/vite.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { b as basePartial, g as globPartial, r as requiredGlobDirectoryPartial } from './glob.js';
|
|
2
|
-
import { i as injectPartial, r as requiredSwDestPartial } from './injectManifest.js';
|
|
3
|
-
import 'zod';
|
|
4
|
-
|
|
5
|
-
const viteInjectManifestOptions = basePartial.merge(globPartial).merge(injectPartial).merge(requiredSwDestPartial).merge(requiredGlobDirectoryPartial).strict("Do not pass invalid properties to ViteInjectManifestPartial!");
|
|
6
|
-
|
|
7
|
-
export { viteInjectManifestOptions };
|
package/dist/chunks/webpack.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { b as basePartial } from './glob.js';
|
|
3
|
-
import { i as injectPartial, o as optionalSwDestPartial } from './injectManifest.js';
|
|
4
|
-
|
|
5
|
-
const webpackPartial = z.object({
|
|
6
|
-
chunks: z.array(z.string()).optional(),
|
|
7
|
-
exclude: z.array(z.union([
|
|
8
|
-
z.string(),
|
|
9
|
-
z.instanceof(RegExp),
|
|
10
|
-
z.function(z.tuple([
|
|
11
|
-
z.any()
|
|
12
|
-
]), z.boolean())
|
|
13
|
-
])).default([
|
|
14
|
-
/\.map$/,
|
|
15
|
-
/^manifest.*\.js$/
|
|
16
|
-
]),
|
|
17
|
-
excludeChunks: z.array(z.string()).optional(),
|
|
18
|
-
include: z.array(z.union([
|
|
19
|
-
z.string(),
|
|
20
|
-
z.instanceof(RegExp),
|
|
21
|
-
z.function(z.tuple([
|
|
22
|
-
z.any()
|
|
23
|
-
]), z.boolean())
|
|
24
|
-
])).optional(),
|
|
25
|
-
mode: z.string().nullable().optional()
|
|
26
|
-
}).strict("Do not pass invalid properties to WebpackPartial!");
|
|
27
|
-
const webpackInjectManifestPartial = z.object({
|
|
28
|
-
compileSrc: z.boolean().default(true),
|
|
29
|
-
swDest: z.string().optional(),
|
|
30
|
-
webpackCompilationPlugins: z.array(z.any()).optional()
|
|
31
|
-
}).strict("Do not pass invalid properties to WebpackInjectManifestPartial!");
|
|
32
|
-
const webpackInjectManifestOptions = basePartial.merge(webpackPartial).merge(injectPartial).merge(optionalSwDestPartial).merge(webpackInjectManifestPartial).strict("Do not pass invalid properties to WebpackInjectManifestOptions!");
|
|
33
|
-
|
|
34
|
-
export { webpackInjectManifestOptions, webpackInjectManifestPartial, webpackPartial };
|
package/dist/index.next.d.ts
DELETED
package/dist/index.next.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.next.d.ts","sourceRoot":"","sources":["../src/index.next.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AAEnF,OAAO,EAAE,iCAAiC,EAAE,CAAC"}
|
package/dist/index.next.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { r as requiredSwDestPartial } from './chunks/injectManifest.js';
|
|
3
|
-
import { webpackInjectManifestOptions } from './chunks/webpack.js';
|
|
4
|
-
import { v as validationErrorMap, S as SerwistConfigError } from './chunks/serwist-config-error.js';
|
|
5
|
-
import './chunks/glob.js';
|
|
6
|
-
|
|
7
|
-
const nextInjectManifestPartial = z.object({
|
|
8
|
-
cacheOnNavigation: z.boolean().default(false),
|
|
9
|
-
disable: z.boolean().default(false),
|
|
10
|
-
register: z.boolean().default(true),
|
|
11
|
-
reloadOnOnline: z.boolean().default(true),
|
|
12
|
-
scope: z.string().optional(),
|
|
13
|
-
swUrl: z.string().default("/sw.js"),
|
|
14
|
-
globPublicPatterns: z.union([
|
|
15
|
-
z.string(),
|
|
16
|
-
z.array(z.string())
|
|
17
|
-
]).default([
|
|
18
|
-
"**/*"
|
|
19
|
-
])
|
|
20
|
-
}).strict("Do not pass invalid properties to NextInjectManifestPartial!");
|
|
21
|
-
const nextInjectManifestOptions = webpackInjectManifestOptions.merge(requiredSwDestPartial).merge(nextInjectManifestPartial).omit({
|
|
22
|
-
disablePrecacheManifest: true
|
|
23
|
-
}).strict("Do not pass invalid properties to NextInjectManifestOptions!");
|
|
24
|
-
|
|
25
|
-
const validateNextInjectManifestOptions = (input)=>{
|
|
26
|
-
const result = nextInjectManifestOptions.safeParse(input, {
|
|
27
|
-
errorMap: validationErrorMap
|
|
28
|
-
});
|
|
29
|
-
if (!result.success) {
|
|
30
|
-
throw new SerwistConfigError({
|
|
31
|
-
moduleName: "@serwist/next",
|
|
32
|
-
message: JSON.stringify(result.error.format(), null, 2)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return result.data;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export { validateNextInjectManifestOptions };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serwist-config-error.d.ts","sourceRoot":"","sources":["../../src/lib/serwist-config-error.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;CAI/E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-next-options.d.ts","sourceRoot":"","sources":["../../src/lib/validate-next-options.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAGrE,eAAO,MAAM,iCAAiC,UAAW,OAAO,KAAG,iCAQlE,CAAC"}
|