@serwist/build 9.0.0-preview.9 → 9.0.1
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 +24 -50
- 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/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 +9 -152
- package/dist/types.d.ts.map +1 -1
- package/package.json +15 -24
- 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/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 +5 -5
- 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 +9 -184
- package/dist/chunks/vite.js +0 -7
- package/dist/chunks/webpack.js +0 -33
- 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 -240
- 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 -225
- package/dist/schema/webpack.d.ts.map +0 -1
- 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 -46
- package/dist/chunks/{serwist-config-error.js → validationErrorMap.js} +7 -7
- /package/src/{lib/serwist-config-error.ts → schema/serwistConfigError.ts} +0 -0
package/dist/types.d.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";
|
|
@@ -35,9 +34,9 @@ export interface BasePartial {
|
|
|
35
34
|
*/
|
|
36
35
|
manifestTransforms?: ManifestTransform[];
|
|
37
36
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
37
|
+
* Determines the maximum size of files that will be precached. This prevents
|
|
38
|
+
* you from inadvertently precaching very large files that might have accidentally
|
|
39
|
+
* matched one of your patterns.
|
|
41
40
|
* @default 2097152
|
|
42
41
|
*/
|
|
43
42
|
maximumFileSizeToCacheInBytes?: number;
|
|
@@ -85,14 +84,14 @@ export interface GlobPartial {
|
|
|
85
84
|
/**
|
|
86
85
|
* Determines whether or not symlinks are followed when generating the
|
|
87
86
|
* precache manifest. For more information, see the definition of `follow` in
|
|
88
|
-
* [`glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
87
|
+
* [`node-glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
89
88
|
* @default true
|
|
90
89
|
*/
|
|
91
90
|
globFollow?: boolean;
|
|
92
91
|
/**
|
|
93
92
|
* A set of patterns matching files to always exclude when generating the
|
|
94
93
|
* precache manifest. For more information, see the definition of `ignore` in
|
|
95
|
-
* [`glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
94
|
+
* [`node-glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
96
95
|
* @default
|
|
97
96
|
* ```
|
|
98
97
|
* ["**\/node_modules\/**\/*"]
|
|
@@ -102,7 +101,7 @@ export interface GlobPartial {
|
|
|
102
101
|
/**
|
|
103
102
|
* Files matching any of these patterns will be included in the precache
|
|
104
103
|
* manifest. For more information, see
|
|
105
|
-
* [`glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
|
|
104
|
+
* [`node-glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
|
|
106
105
|
* @default
|
|
107
106
|
* ```
|
|
108
107
|
* ["**\/*.{js,css,html}"]
|
|
@@ -113,7 +112,7 @@ export interface GlobPartial {
|
|
|
113
112
|
* If true, an error reading a directory when generating a precache manifest
|
|
114
113
|
* will cause the build to fail. If false, the problematic directory will be
|
|
115
114
|
* skipped. For more information, see the definition of `strict` in
|
|
116
|
-
* [`glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
115
|
+
* [`node-glob`'s documentation](https://github.com/isaacs/node-glob#options).
|
|
117
116
|
* @default true
|
|
118
117
|
*/
|
|
119
118
|
globStrict?: boolean;
|
|
@@ -121,7 +120,7 @@ export interface GlobPartial {
|
|
|
121
120
|
* If a URL is rendered based on some server-side logic, its contents may
|
|
122
121
|
* depend on multiple files or on some other unique string value. The keys in
|
|
123
122
|
* this object are server-rendered URLs. If the values are an array of
|
|
124
|
-
* strings, they will be interpreted as
|
|
123
|
+
* strings, they will be interpreted as glob patterns, and the contents of
|
|
125
124
|
* any files matching the patterns will be used to uniquely version the URL.
|
|
126
125
|
* If used with a single string, it will be interpreted as unique versioning
|
|
127
126
|
* information that you've generated for a given URL.
|
|
@@ -145,37 +144,6 @@ export interface InjectPartial {
|
|
|
145
144
|
swSrc: string;
|
|
146
145
|
}
|
|
147
146
|
export type InjectResolved = Require<InjectPartial, "injectionPoint">;
|
|
148
|
-
export interface WebpackPartial {
|
|
149
|
-
/**
|
|
150
|
-
* One or more chunk names whose corresponding output files should be included
|
|
151
|
-
* in the precache manifest.
|
|
152
|
-
*/
|
|
153
|
-
chunks?: string[];
|
|
154
|
-
/**
|
|
155
|
-
* One or more specifiers used to exclude assets from the precache manifest.
|
|
156
|
-
* This is interpreted following
|
|
157
|
-
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
158
|
-
* as `webpack`'s standard `exclude` option.
|
|
159
|
-
* @default
|
|
160
|
-
* ```
|
|
161
|
-
* [/\.map$/, /^manifest.*\.js$]
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
exclude?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
165
|
-
/**
|
|
166
|
-
* One or more chunk names whose corresponding output files should be excluded
|
|
167
|
-
* from the precache manifest.
|
|
168
|
-
*/
|
|
169
|
-
excludeChunks?: string[];
|
|
170
|
-
/**
|
|
171
|
-
* One or more specifiers used to include assets in the precache manifest.
|
|
172
|
-
* This is interpreted following
|
|
173
|
-
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
174
|
-
* as `webpack`'s standard `include` option.
|
|
175
|
-
*/
|
|
176
|
-
include?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
177
|
-
}
|
|
178
|
-
export type WebpackResolved = Require<WebpackPartial, "exclude">;
|
|
179
147
|
export interface RequiredSwDestPartial {
|
|
180
148
|
/**
|
|
181
149
|
* The path and filename of the service worker file that will be created by
|
|
@@ -193,121 +161,10 @@ export interface OptionalSwDestPartial {
|
|
|
193
161
|
swDest?: string;
|
|
194
162
|
}
|
|
195
163
|
export type OptionalSwDestResolved = OptionalSwDestPartial;
|
|
196
|
-
export interface WebpackInjectManifestPartial {
|
|
197
|
-
/**
|
|
198
|
-
* When `true` (the default), the `swSrc` file will be compiled by `webpack`.
|
|
199
|
-
* When `false`, compilation will not occur (and `webpackCompilationPlugins`
|
|
200
|
-
* can't be used.) Set to `false` if you want to inject the manifest into,
|
|
201
|
-
* e.g., a JSON file.
|
|
202
|
-
* @default true
|
|
203
|
-
*/
|
|
204
|
-
compileSrc?: boolean;
|
|
205
|
-
/**
|
|
206
|
-
* Optional `webpack` plugins that will be used when compiling the `swSrc`
|
|
207
|
-
* input file. Only valid if `compileSrc` is `true`.
|
|
208
|
-
*/
|
|
209
|
-
webpackCompilationPlugins?: any[];
|
|
210
|
-
}
|
|
211
|
-
export type WebpackInjectManifestResolved = Require<WebpackInjectManifestPartial, "compileSrc">;
|
|
212
|
-
export interface NextInjectManifestPartial {
|
|
213
|
-
/**
|
|
214
|
-
* Enables additional route caching when users navigate through pages with
|
|
215
|
-
* `next/link`. This improves the user experience in some cases but it
|
|
216
|
-
* also adds a bit of overhead due to additional network calls.
|
|
217
|
-
* @default false
|
|
218
|
-
*/
|
|
219
|
-
cacheOnNavigation?: boolean;
|
|
220
|
-
/**
|
|
221
|
-
* Whether Serwist should be disabled.
|
|
222
|
-
* @default false
|
|
223
|
-
*/
|
|
224
|
-
disable?: boolean;
|
|
225
|
-
/**
|
|
226
|
-
* Whether `@serwist/next` should automatically register the service worker for you. If
|
|
227
|
-
* you want to register the service worker yourself, set this to `false` and run
|
|
228
|
-
* `window.serwist.register()` in `componentDidMount` or `useEffect`.
|
|
229
|
-
* @example
|
|
230
|
-
* ```tsx
|
|
231
|
-
* // app/register-pwa.tsx
|
|
232
|
-
* "use client";
|
|
233
|
-
* import { useEffect } from "react";
|
|
234
|
-
* import type { Serwist } from "@serwist/window";
|
|
235
|
-
*
|
|
236
|
-
* declare global {
|
|
237
|
-
* interface Window {
|
|
238
|
-
* serwist: Serwist;
|
|
239
|
-
* }
|
|
240
|
-
* }
|
|
241
|
-
*
|
|
242
|
-
* export default function RegisterPWA() {
|
|
243
|
-
* useEffect(() => {
|
|
244
|
-
* if ("serviceWorker" in navigator && window.serwist !== undefined) {
|
|
245
|
-
* window.serwist.register();
|
|
246
|
-
* }
|
|
247
|
-
* }, []);
|
|
248
|
-
* return <></>;
|
|
249
|
-
* }
|
|
250
|
-
*
|
|
251
|
-
* // app/layout.tsx
|
|
252
|
-
* import RegisterPWA from "./register-pwa";
|
|
253
|
-
*
|
|
254
|
-
* export default function RootLayout({
|
|
255
|
-
* children,
|
|
256
|
-
* }: {
|
|
257
|
-
* children: React.ReactNode;
|
|
258
|
-
* }) {
|
|
259
|
-
* return (
|
|
260
|
-
* <html lang="en">
|
|
261
|
-
* <head />
|
|
262
|
-
* <body>
|
|
263
|
-
* <RegisterPWA />
|
|
264
|
-
* {children}
|
|
265
|
-
* </body>
|
|
266
|
-
* </html>
|
|
267
|
-
* );
|
|
268
|
-
* }
|
|
269
|
-
* ```
|
|
270
|
-
* @default true
|
|
271
|
-
*/
|
|
272
|
-
register?: boolean;
|
|
273
|
-
/**
|
|
274
|
-
* Whether Serwist should reload the app when it goes online.
|
|
275
|
-
* @default true
|
|
276
|
-
*/
|
|
277
|
-
reloadOnOnline?: boolean;
|
|
278
|
-
/**
|
|
279
|
-
* The service worker's URL scope. Set to `/foo/` so that paths under `/foo/` are under the service
|
|
280
|
-
* worker's control while others are not.
|
|
281
|
-
* @default nextConfig.basePath
|
|
282
|
-
*/
|
|
283
|
-
scope?: string;
|
|
284
|
-
/**
|
|
285
|
-
* The URL to the service worker.
|
|
286
|
-
* @default "/sw.js"
|
|
287
|
-
*/
|
|
288
|
-
swUrl?: string;
|
|
289
|
-
/**
|
|
290
|
-
* Files in the public directory matching any of these patterns
|
|
291
|
-
* will be included in the precache manifest. For more information,
|
|
292
|
-
* see [`fast-glob`'s documentation](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax).
|
|
293
|
-
* @default
|
|
294
|
-
* ```
|
|
295
|
-
* ["**\/*"]
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
globPublicPatterns?: GlobPattern | GlobPattern[];
|
|
299
|
-
}
|
|
300
|
-
export type NextInjectManifestResolved = Require<NextInjectManifestPartial, "cacheOnNavigation" | "disable" | "register" | "reloadOnOnline" | "swUrl" | "globPublicPatterns">;
|
|
301
164
|
export type GetManifestOptions = BasePartial & GlobPartial & RequiredGlobDirectoryPartial;
|
|
302
165
|
export type GetManifestOptionsComplete = BaseResolved & GlobResolved & RequiredGlobDirectoryResolved;
|
|
303
166
|
export type InjectManifestOptions = BasePartial & GlobPartial & InjectPartial & RequiredSwDestPartial & RequiredGlobDirectoryPartial;
|
|
304
167
|
export type InjectManifestOptionsComplete = BaseResolved & GlobResolved & InjectResolved & RequiredSwDestResolved & RequiredGlobDirectoryResolved;
|
|
305
|
-
export type WebpackInjectManifestOptions = BasePartial & WebpackPartial & InjectPartial & OptionalSwDestPartial & WebpackInjectManifestPartial;
|
|
306
|
-
export type WebpackInjectManifestOptionsComplete = BaseResolved & WebpackResolved & InjectResolved & OptionalSwDestResolved & WebpackInjectManifestResolved;
|
|
307
|
-
export type ViteInjectManifestOptions = BasePartial & GlobPartial & InjectPartial & RequiredSwDestPartial & RequiredGlobDirectoryPartial;
|
|
308
|
-
export type ViteInjectManifestOptionsComplete = BaseResolved & GlobResolved & InjectResolved & RequiredSwDestResolved & RequiredGlobDirectoryResolved;
|
|
309
|
-
export type NextInjectManifestOptions = Omit<WebpackInjectManifestOptions & RequiredSwDestPartial & NextInjectManifestPartial, "disablePrecacheManifest">;
|
|
310
|
-
export type NextInjectManifestOptionsComplete = Omit<WebpackInjectManifestOptionsComplete & RequiredSwDestResolved & NextInjectManifestResolved, "disablePrecacheManifest">;
|
|
311
168
|
export interface GetManifestResult {
|
|
312
169
|
count: number;
|
|
313
170
|
manifestEntries: ManifestEntry[] | undefined;
|
|
@@ -322,7 +179,7 @@ export type BuildResult = Omit<GetManifestResult, "manifestEntries"> & {
|
|
|
322
179
|
*/
|
|
323
180
|
export interface FileDetails {
|
|
324
181
|
file: string;
|
|
325
|
-
hash: string;
|
|
182
|
+
hash: string | null;
|
|
326
183
|
size: number;
|
|
327
184
|
}
|
|
328
185
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,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MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,GAAG;IACrE,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,gBAAgB,GAAG,uBAAuB,GAAG,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/build",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A module that integrates into your build process, helping you generate a manifest of local files that should be precached.",
|
|
6
6
|
"files": [
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
},
|
|
22
22
|
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"repository": "serwist/serwist",
|
|
24
|
+
"repository": "https://github.com/serwist/serwist",
|
|
25
25
|
"bugs": "https://github.com/serwist/serwist/issues",
|
|
26
26
|
"homepage": "https://serwist.pages.dev",
|
|
27
27
|
"main": "./dist/index.js",
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"typesVersions": {
|
|
30
30
|
"*": {
|
|
31
|
-
"
|
|
32
|
-
"./dist/index.
|
|
31
|
+
"schema": [
|
|
32
|
+
"./dist/index.schema.d.ts"
|
|
33
33
|
]
|
|
34
34
|
}
|
|
35
35
|
},
|
|
@@ -38,41 +38,32 @@
|
|
|
38
38
|
"types": "./dist/index.d.ts",
|
|
39
39
|
"default": "./dist/index.js"
|
|
40
40
|
},
|
|
41
|
-
"./
|
|
42
|
-
"types": "./dist/index.
|
|
43
|
-
"default": "./dist/index.
|
|
41
|
+
"./schema": {
|
|
42
|
+
"types": "./dist/index.schema.d.ts",
|
|
43
|
+
"default": "./dist/index.schema.js"
|
|
44
44
|
},
|
|
45
45
|
"./package.json": "./package.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"common-tags": "1.8.2",
|
|
49
|
-
"fast-glob": "3.3.2",
|
|
50
49
|
"fast-json-stable-stringify": "2.1.0",
|
|
51
50
|
"fs-extra": "11.2.0",
|
|
52
|
-
"glob": "10.3.
|
|
51
|
+
"glob": "10.3.12",
|
|
53
52
|
"pretty-bytes": "6.1.1",
|
|
54
|
-
"rollup": "4.
|
|
53
|
+
"rollup": "4.14.3",
|
|
55
54
|
"source-map": "0.8.0-beta.0",
|
|
56
55
|
"upath": "2.0.1",
|
|
57
|
-
"zod": "3.22.4"
|
|
58
|
-
"@serwist/background-sync": "9.0.0-preview.9",
|
|
59
|
-
"@serwist/broadcast-update": "9.0.0-preview.9",
|
|
60
|
-
"@serwist/cacheable-response": "9.0.0-preview.9",
|
|
61
|
-
"@serwist/core": "9.0.0-preview.9",
|
|
62
|
-
"@serwist/expiration": "9.0.0-preview.9",
|
|
63
|
-
"@serwist/google-analytics": "9.0.0-preview.9",
|
|
64
|
-
"@serwist/precaching": "9.0.0-preview.9",
|
|
65
|
-
"@serwist/routing": "9.0.0-preview.9"
|
|
56
|
+
"zod": "3.22.4"
|
|
66
57
|
},
|
|
67
58
|
"devDependencies": {
|
|
68
59
|
"@types/common-tags": "1.8.4",
|
|
69
60
|
"@types/fs-extra": "11.0.4",
|
|
70
|
-
"@types/node": "20.
|
|
61
|
+
"@types/node": "20.12.7",
|
|
71
62
|
"@types/stringify-object": "4.0.5",
|
|
72
|
-
"type-fest": "4.
|
|
73
|
-
"typescript": "5.
|
|
74
|
-
"@serwist/
|
|
75
|
-
"@serwist/utils": "9.0.
|
|
63
|
+
"type-fest": "4.15.0",
|
|
64
|
+
"typescript": "5.5.0-dev.20240415",
|
|
65
|
+
"@serwist/configs": "9.0.1",
|
|
66
|
+
"@serwist/utils": "9.0.1"
|
|
76
67
|
},
|
|
77
68
|
"peerDependencies": {
|
|
78
69
|
"typescript": ">=5.0.0"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Assignable, type Equals, assertType } from "./schema/assertType.js";
|
|
2
|
+
import { basePartial } from "./schema/base.js";
|
|
3
|
+
import { getManifestOptions } from "./schema/getManifest.js";
|
|
4
|
+
import { globPartial, optionalGlobDirectoryPartial, requiredGlobDirectoryPartial } from "./schema/glob.js";
|
|
5
|
+
import { baseInjectPartial, injectManifestOptions } from "./schema/injectManifest.js";
|
|
6
|
+
import { manifestEntry } from "./schema/manifestEntry.js";
|
|
7
|
+
import { manifestTransform, manifestTransformResult } from "./schema/manifestTransform.js";
|
|
8
|
+
import { SerwistConfigError } from "./schema/serwistConfigError.js";
|
|
9
|
+
import { optionalSwDestPartial, requiredSwDestPartial } from "./schema/swDest.js";
|
|
10
|
+
import { validationErrorMap } from "./schema/validationErrorMap.js";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
assertType,
|
|
14
|
+
basePartial,
|
|
15
|
+
globPartial,
|
|
16
|
+
baseInjectPartial as injectPartial,
|
|
17
|
+
injectManifestOptions,
|
|
18
|
+
getManifestOptions,
|
|
19
|
+
manifestEntry,
|
|
20
|
+
manifestTransform,
|
|
21
|
+
manifestTransformResult,
|
|
22
|
+
optionalGlobDirectoryPartial,
|
|
23
|
+
requiredGlobDirectoryPartial,
|
|
24
|
+
optionalSwDestPartial,
|
|
25
|
+
requiredSwDestPartial,
|
|
26
|
+
validationErrorMap,
|
|
27
|
+
SerwistConfigError,
|
|
28
|
+
};
|
|
29
|
+
export type { Assignable, Equals };
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { rebasePath } from "./lib/rebase-path.js";
|
|
|
17
17
|
import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.js";
|
|
18
18
|
import { transformManifest } from "./lib/transform-manifest.js";
|
|
19
19
|
import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
|
|
20
|
-
import {
|
|
20
|
+
import { validateGetManifestOptions, validateInjectManifestOptions } from "./lib/validate-options.js";
|
|
21
21
|
|
|
22
22
|
export {
|
|
23
23
|
errors,
|
|
@@ -31,9 +31,8 @@ export {
|
|
|
31
31
|
stringify,
|
|
32
32
|
transformManifest,
|
|
33
33
|
translateURLToSourcemapPaths,
|
|
34
|
+
validateGetManifestOptions,
|
|
34
35
|
validateInjectManifestOptions,
|
|
35
|
-
validateViteInjectManifestOptions,
|
|
36
|
-
validateWebpackInjectManifestOptions,
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
export type * from "./types.js";
|
package/src/inject-manifest.ts
CHANGED
|
@@ -9,13 +9,9 @@
|
|
|
9
9
|
import type { ManifestEntry } from "../types.js";
|
|
10
10
|
import { errors } from "./errors.js";
|
|
11
11
|
|
|
12
|
-
type AdditionalManifestEntriesTransform = {
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
): {
|
|
16
|
-
manifest: (ManifestEntry & { size: number })[];
|
|
17
|
-
warnings: string[];
|
|
18
|
-
};
|
|
12
|
+
type AdditionalManifestEntriesTransform = (manifest: (ManifestEntry & { size: number })[]) => {
|
|
13
|
+
manifest: (ManifestEntry & { size: number })[];
|
|
14
|
+
warnings: string[];
|
|
19
15
|
};
|
|
20
16
|
|
|
21
17
|
export const additionalPrecacheEntriesTransform = (additionalPrecacheEntries: (ManifestEntry | string)[]): AdditionalManifestEntriesTransform => {
|
|
@@ -34,7 +30,7 @@ export const additionalPrecacheEntriesTransform = (additionalPrecacheEntries: (M
|
|
|
34
30
|
url: additionalEntry,
|
|
35
31
|
});
|
|
36
32
|
} else {
|
|
37
|
-
if (additionalEntry && additionalEntry.revision === undefined) {
|
|
33
|
+
if (additionalEntry && !additionalEntry.integrity && additionalEntry.revision === undefined) {
|
|
38
34
|
stringEntries.add(additionalEntry.url);
|
|
39
35
|
}
|
|
40
36
|
manifest.push(Object.assign({ size: 0 }, additionalEntry));
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import crypto from "crypto";
|
|
9
|
+
import crypto from "node:crypto";
|
|
10
10
|
|
|
11
11
|
import type { FileDetails } from "../types.js";
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ export const getCompositeDetails = (compositeURL: string, dependencyDetails: Fil
|
|
|
16
16
|
|
|
17
17
|
for (const fileDetails of dependencyDetails) {
|
|
18
18
|
totalSize += fileDetails.size;
|
|
19
|
-
compositeHash += fileDetails.hash;
|
|
19
|
+
compositeHash += fileDetails.hash === null ? "" : fileDetails.hash;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const md5 = crypto.createHash("md5");
|
|
@@ -5,22 +5,14 @@
|
|
|
5
5
|
license that can be found in the LICENSE file or at
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import type { GlobPartial } from "../types.js";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { globSync } from "glob";
|
|
10
|
+
import type { FileDetails, GlobPartial } from "../types.js";
|
|
13
11
|
import { errors } from "./errors.js";
|
|
14
12
|
import { getFileHash } from "./get-file-hash.js";
|
|
15
13
|
import { getFileSize } from "./get-file-size.js";
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
file: string;
|
|
19
|
-
hash: string;
|
|
20
|
-
size: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function getFileDetails({
|
|
15
|
+
export const getFileDetails = ({
|
|
24
16
|
globDirectory,
|
|
25
17
|
globFollow,
|
|
26
18
|
globIgnores,
|
|
@@ -32,12 +24,12 @@ export function getFileDetails({
|
|
|
32
24
|
}): {
|
|
33
25
|
globbedFileDetails: FileDetails[];
|
|
34
26
|
warning: string;
|
|
35
|
-
} {
|
|
27
|
+
} => {
|
|
36
28
|
let globbedFiles: string[];
|
|
37
29
|
let warning = "";
|
|
38
30
|
|
|
39
31
|
try {
|
|
40
|
-
globbedFiles =
|
|
32
|
+
globbedFiles = globSync(globPattern, {
|
|
41
33
|
cwd: globDirectory,
|
|
42
34
|
follow: globFollow,
|
|
43
35
|
ignore: globIgnores,
|
|
@@ -52,12 +44,12 @@ export function getFileDetails({
|
|
|
52
44
|
|
|
53
45
|
const globbedFileDetails: FileDetails[] = [];
|
|
54
46
|
for (const file of globbedFiles) {
|
|
55
|
-
const fullPath =
|
|
47
|
+
const fullPath = path.join(globDirectory, file);
|
|
56
48
|
const fileSize = getFileSize(fullPath);
|
|
57
49
|
if (fileSize !== null) {
|
|
58
50
|
const fileHash = getFileHash(fullPath);
|
|
59
51
|
globbedFileDetails.push({
|
|
60
|
-
file:
|
|
52
|
+
file: path.relative(globDirectory, fullPath),
|
|
61
53
|
hash: fileHash,
|
|
62
54
|
size: fileSize,
|
|
63
55
|
});
|
|
@@ -65,4 +57,4 @@ export function getFileDetails({
|
|
|
65
57
|
}
|
|
66
58
|
|
|
67
59
|
return { globbedFileDetails, warning };
|
|
68
|
-
}
|
|
60
|
+
};
|
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,
|
|
@@ -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
|
|