@serwist/build 9.1.1 → 10.0.0-preview.10

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.
Files changed (64) hide show
  1. package/dist/chunks/{error.js → constants.js} +5 -1
  2. package/dist/chunks/get-manifest.js +1 -0
  3. package/dist/chunks/glob.js +2 -3
  4. package/dist/chunks/inject-manifest.js +1 -1
  5. package/dist/index.d.ts +3 -11
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +7 -145
  8. package/dist/index.schema.d.ts +3 -3
  9. package/dist/index.schema.d.ts.map +1 -1
  10. package/dist/index.schema.js +1 -1
  11. package/dist/inject-manifest.d.ts.map +1 -1
  12. package/dist/lib/additional-precache-entries-transform.d.ts.map +1 -1
  13. package/dist/lib/constants.d.ts +2 -0
  14. package/dist/lib/constants.d.ts.map +1 -0
  15. package/dist/lib/get-file-details.d.ts +2 -1
  16. package/dist/lib/get-file-details.d.ts.map +1 -1
  17. package/dist/lib/get-file-manifest-entries.d.ts.map +1 -1
  18. package/dist/lib/modify-url-prefix-transform.d.ts.map +1 -1
  19. package/dist/lib/no-revision-for-urls-matching-transform.d.ts.map +1 -1
  20. package/dist/lib/transform-manifest.d.ts +2 -1
  21. package/dist/lib/transform-manifest.d.ts.map +1 -1
  22. package/dist/lib/validate-options.d.ts.map +1 -1
  23. package/dist/schema/glob.d.ts.map +1 -1
  24. package/dist/schema/inject-manifest.d.ts +2 -2
  25. package/dist/types.d.ts +14 -22
  26. package/dist/types.d.ts.map +1 -1
  27. package/package.json +10 -8
  28. package/src/index.schema.ts +3 -3
  29. package/src/index.ts +5 -11
  30. package/src/inject-manifest.ts +2 -1
  31. package/src/lib/additional-precache-entries-transform.ts +1 -2
  32. package/src/lib/constants.ts +1 -0
  33. package/src/lib/get-file-details.ts +3 -4
  34. package/src/lib/get-file-manifest-entries.ts +3 -4
  35. package/src/lib/modify-url-prefix-transform.ts +1 -1
  36. package/src/lib/no-revision-for-urls-matching-transform.ts +1 -1
  37. package/src/lib/rebase-path.ts +1 -1
  38. package/src/lib/transform-manifest.ts +3 -2
  39. package/src/lib/translate-url-to-sourcemap-paths.ts +1 -1
  40. package/src/lib/validate-options.ts +1 -2
  41. package/src/schema/base.ts +1 -1
  42. package/src/schema/get-manifest.ts +1 -1
  43. package/src/schema/glob.ts +3 -2
  44. package/src/schema/inject-manifest.ts +2 -2
  45. package/src/schema/sw-dest.ts +1 -1
  46. package/src/types.ts +16 -23
  47. package/dist/lib/errors.d.ts +0 -47
  48. package/dist/lib/errors.d.ts.map +0 -1
  49. package/dist/lib/get-composite-details.d.ts +0 -3
  50. package/dist/lib/get-composite-details.d.ts.map +0 -1
  51. package/dist/lib/get-file-hash.d.ts +0 -2
  52. package/dist/lib/get-file-hash.d.ts.map +0 -1
  53. package/dist/lib/get-file-size.d.ts +0 -2
  54. package/dist/lib/get-file-size.d.ts.map +0 -1
  55. package/dist/lib/get-string-details.d.ts +0 -3
  56. package/dist/lib/get-string-details.d.ts.map +0 -1
  57. package/dist/lib/get-string-hash.d.ts +0 -3
  58. package/dist/lib/get-string-hash.d.ts.map +0 -1
  59. package/src/lib/errors.ts +0 -93
  60. package/src/lib/get-composite-details.ts +0 -31
  61. package/src/lib/get-file-hash.ts +0 -21
  62. package/src/lib/get-file-size.ts +0 -22
  63. package/src/lib/get-string-details.ts +0 -16
  64. package/src/lib/get-string-hash.ts +0 -15
@@ -9,8 +9,9 @@ import assert from "node:assert";
9
9
  import fsp from "node:fs/promises";
10
10
  import path from "node:path";
11
11
  import { toUnix } from "@serwist/utils";
12
+ import { errors } from "@serwist/utils/node";
12
13
  import type { RawSourceMap } from "source-map";
13
- import { errors } from "./lib/errors.js";
14
+
14
15
  import { escapeRegExp } from "./lib/escape-regexp.js";
15
16
  import { getFileManifestEntries } from "./lib/get-file-manifest-entries.js";
16
17
  import { getSourceMapURL } from "./lib/get-source-map-url.js";
@@ -5,9 +5,8 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
-
8
+ import { errors } from "@serwist/utils/node";
9
9
  import type { ManifestEntry } from "../types.js";
10
- import { errors } from "./errors.js";
11
10
 
12
11
  type AdditionalManifestEntriesTransform = (manifest: (ManifestEntry & { size: number })[]) => {
13
12
  manifest: (ManifestEntry & { size: number })[];
@@ -0,0 +1 @@
1
+ export const DEFAULT_GLOB_PATTERNS = ["**/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}"];
@@ -6,11 +6,10 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
  import path from "node:path";
9
+ import type { FileDetails } from "@serwist/utils";
10
+ import { errors, getFileHash, getFileSize } from "@serwist/utils/node";
9
11
  import { globSync } from "glob";
10
- import type { FileDetails, GlobPartial } from "../types.js";
11
- import { errors } from "./errors.js";
12
- import { getFileHash } from "./get-file-hash.js";
13
- import { getFileSize } from "./get-file-size.js";
12
+ import type { GlobPartial } from "../types.js";
14
13
 
15
14
  export const getFileDetails = ({
16
15
  globDirectory,
@@ -7,12 +7,11 @@
7
7
  */
8
8
 
9
9
  import assert from "node:assert";
10
+ import type { FileDetails } from "@serwist/utils";
11
+ import { errors, getCompositeDetails, getStringDetails } from "@serwist/utils/node";
10
12
 
11
- import type { FileDetails, GetManifestOptionsComplete, GetManifestResult } from "../types.js";
12
- import { errors } from "./errors.js";
13
- import { getCompositeDetails } from "./get-composite-details.js";
13
+ import type { GetManifestOptionsComplete, GetManifestResult } from "../types.js";
14
14
  import { getFileDetails } from "./get-file-details.js";
15
- import { getStringDetails } from "./get-string-details.js";
16
15
  import { transformManifest } from "./transform-manifest.js";
17
16
 
18
17
  export const getFileManifestEntries = async ({
@@ -5,9 +5,9 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
+ import { errors } from "@serwist/utils/node";
8
9
 
9
10
  import type { ManifestTransform } from "../types.js";
10
- import { errors } from "./errors.js";
11
11
  import { escapeRegExp } from "./escape-regexp.js";
12
12
 
13
13
  export function modifyURLPrefixTransform(modifyURLPrefix: { [key: string]: string }): ManifestTransform {
@@ -5,9 +5,9 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
+ import { errors } from "@serwist/utils/node";
8
9
 
9
10
  import type { ManifestTransform } from "../types.js";
10
- import { errors } from "./errors.js";
11
11
 
12
12
  export function noRevisionForURLsMatchingTransform(regexp: RegExp): ManifestTransform {
13
13
  if (!(regexp instanceof RegExp)) {
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { toUnix } from "@serwist/utils";
10
9
  import path from "node:path";
10
+ import { toUnix } from "@serwist/utils";
11
11
 
12
12
  export function rebasePath({ baseDirectory, file }: { baseDirectory: string; file: string }): string {
13
13
  // The initial path is relative to the current directory, so make it absolute.
@@ -5,10 +5,11 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
+ import type { FileDetails } from "@serwist/utils";
9
+ import { errors } from "@serwist/utils/node";
8
10
 
9
- import type { BaseResolved, FileDetails, ManifestEntry, ManifestTransform } from "../types.js";
11
+ import type { BaseResolved, ManifestEntry, ManifestTransform } from "../types.js";
10
12
  import { additionalPrecacheEntriesTransform } from "./additional-precache-entries-transform.js";
11
- import { errors } from "./errors.js";
12
13
  import { maximumSizeTransform } from "./maximum-size-transform.js";
13
14
  import { modifyURLPrefixTransform } from "./modify-url-prefix-transform.js";
14
15
  import { noRevisionForURLsMatchingTransform } from "./no-revision-for-urls-matching-transform.js";
@@ -8,7 +8,7 @@
8
8
  import fs from "node:fs";
9
9
  import path from "node:path";
10
10
  import { toUnix } from "@serwist/utils";
11
- import { errors } from "./errors.js";
11
+ import { errors } from "@serwist/utils/node";
12
12
 
13
13
  export function translateURLToSourcemapPaths(
14
14
  url: string | null,
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- import { SerwistConfigError } from "../schema/error.js";
3
2
  /*
4
3
  Copyright 2021 Google LLC
5
4
 
@@ -7,7 +6,7 @@ import { SerwistConfigError } from "../schema/error.js";
7
6
  license that can be found in the LICENSE file or at
8
7
  https://opensource.org/licenses/MIT.
9
8
  */
10
- import { validationErrorMap } from "../schema/error.js";
9
+ import { SerwistConfigError, validationErrorMap } from "../schema/error.js";
11
10
  import type { GetManifestOptionsComplete, InjectManifestOptionsComplete } from "../types.js";
12
11
 
13
12
  export const validateGetManifestOptions = async (input: unknown): Promise<GetManifestOptionsComplete> => {
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
 
3
3
  import type { BasePartial, BaseResolved } from "../types.js";
4
- import { type Equals, assertType } from "./assert-type.js";
4
+ import { assertType, type Equals } from "./assert-type.js";
5
5
  import { manifestEntry } from "./manifest-entry.js";
6
6
  import { manifestTransform } from "./manifest-transform.js";
7
7
 
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import type { GetManifestOptions, GetManifestOptionsComplete } from "../types.js";
3
- import { type Equals, assertType } from "./assert-type.js";
3
+ import { assertType, type Equals } from "./assert-type.js";
4
4
  import { basePartial } from "./base.js";
5
5
  import { globPartial, requiredGlobDirectoryPartial } from "./glob.js";
6
6
 
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { DEFAULT_GLOB_PATTERNS } from "../lib/constants.js";
2
3
  import type {
3
4
  GlobPartial,
4
5
  GlobResolved,
@@ -7,12 +8,12 @@ import type {
7
8
  RequiredGlobDirectoryPartial,
8
9
  RequiredGlobDirectoryResolved,
9
10
  } from "../types.js";
10
- import { type Equals, assertType } from "./assert-type.js";
11
+ import { assertType, type Equals } from "./assert-type.js";
11
12
 
12
13
  export const globPartial = z.strictObject({
13
14
  globFollow: z.boolean().default(true),
14
15
  globIgnores: z.array(z.string()).default(["**/node_modules/**/*"]),
15
- globPatterns: z.array(z.string()).default(["**/*.{js,css,html}"]),
16
+ globPatterns: z.array(z.string()).default(DEFAULT_GLOB_PATTERNS),
16
17
  globStrict: z.boolean().default(true),
17
18
  templatedURLs: z.record(z.string(), z.union([z.string(), z.array(z.string())])).optional(),
18
19
  });
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import type { InjectManifestOptions, InjectManifestOptionsComplete, InjectPartial, InjectResolved } from "../types.js";
3
- import { type Equals, assertType } from "./assert-type.js";
3
+ import { assertType, type Equals } from "./assert-type.js";
4
4
  import { basePartial } from "./base.js";
5
5
  import { globPartial, requiredGlobDirectoryPartial } from "./glob.js";
6
6
  import { requiredSwDestPartial } from "./sw-dest.js";
7
7
 
8
8
  export const baseInjectPartial = z.strictObject({
9
- injectionPoint: z.string().default("self.__SW_MANIFEST"),
9
+ injectionPoint: z.string().prefault("self.__SW_MANIFEST"),
10
10
  swSrc: z.string(),
11
11
  });
12
12
 
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import type { OptionalSwDestPartial, OptionalSwDestResolved, RequiredSwDestPartial, RequiredSwDestResolved } from "../types.js";
3
- import { type Equals, assertType } from "./assert-type.js";
3
+ import { assertType, type Equals } from "./assert-type.js";
4
4
 
5
5
  export const optionalSwDestPartial = z.strictObject({
6
6
  swDest: z.string().optional(),
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MaybePromise, Require } from "@serwist/utils";
1
+ import type { MaybePromise, Prettify, Require } from "@serwist/utils";
2
2
  import type { PackageJson } from "type-fest";
3
3
  import type { z } from "zod";
4
4
  import type { manifestEntry } from "./schema/manifest-entry.js";
@@ -74,7 +74,7 @@ export interface BasePartial {
74
74
  };
75
75
  }
76
76
 
77
- export type BaseResolved = Require<BasePartial, "disablePrecacheManifest" | "maximumFileSizeToCacheInBytes">;
77
+ export type BaseResolved = Prettify<Require<BasePartial, "disablePrecacheManifest" | "maximumFileSizeToCacheInBytes">>;
78
78
 
79
79
  // This needs to be set when using GetManifest or InjectManifest. This is
80
80
  // enforced via runtime validation, and needs to be documented.
@@ -86,7 +86,7 @@ export interface RequiredGlobDirectoryPartial {
86
86
  globDirectory: string;
87
87
  }
88
88
 
89
- export type RequiredGlobDirectoryResolved = RequiredGlobDirectoryPartial;
89
+ export type RequiredGlobDirectoryResolved = Prettify<RequiredGlobDirectoryPartial>;
90
90
 
91
91
  export interface OptionalGlobDirectoryPartial {
92
92
  /**
@@ -96,7 +96,7 @@ export interface OptionalGlobDirectoryPartial {
96
96
  globDirectory?: string;
97
97
  }
98
98
 
99
- export type OptionalGlobDirectoryResolved = OptionalGlobDirectoryPartial;
99
+ export type OptionalGlobDirectoryResolved = Prettify<OptionalGlobDirectoryPartial>;
100
100
 
101
101
  export interface GlobPartial {
102
102
  /**
@@ -122,7 +122,7 @@ export interface GlobPartial {
122
122
  * [`node-glob`'s Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
123
123
  * @default
124
124
  * ```
125
- * ["**\/*.{js,css,html}"]
125
+ * ["**\/*.{js,css,html,ico,apng,png,avif,jpg,jpeg,jfif,pjpeg,pjp,gif,svg,webp,json,webmanifest}"]
126
126
  * ```
127
127
  */
128
128
  globPatterns?: string[];
@@ -148,7 +148,7 @@ export interface GlobPartial {
148
148
  };
149
149
  }
150
150
 
151
- export type GlobResolved = Require<GlobPartial, "globFollow" | "globIgnores" | "globPatterns" | "globStrict">;
151
+ export type GlobResolved = Prettify<Require<GlobPartial, "globFollow" | "globIgnores" | "globPatterns" | "globStrict">>;
152
152
 
153
153
  export interface InjectPartial {
154
154
  /**
@@ -164,7 +164,7 @@ export interface InjectPartial {
164
164
  swSrc: string;
165
165
  }
166
166
 
167
- export type InjectResolved = Require<InjectPartial, "injectionPoint">;
167
+ export type InjectResolved = Prettify<Require<InjectPartial, "injectionPoint">>;
168
168
 
169
169
  export interface RequiredSwDestPartial {
170
170
  /**
@@ -174,7 +174,7 @@ export interface RequiredSwDestPartial {
174
174
  swDest: string;
175
175
  }
176
176
 
177
- export type RequiredSwDestResolved = RequiredSwDestPartial;
177
+ export type RequiredSwDestResolved = Prettify<RequiredSwDestPartial>;
178
178
 
179
179
  export interface OptionalSwDestPartial {
180
180
  /**
@@ -185,15 +185,17 @@ export interface OptionalSwDestPartial {
185
185
  swDest?: string;
186
186
  }
187
187
 
188
- export type OptionalSwDestResolved = OptionalSwDestPartial;
188
+ export type OptionalSwDestResolved = Prettify<OptionalSwDestPartial>;
189
189
 
190
- export type GetManifestOptions = BasePartial & GlobPartial & RequiredGlobDirectoryPartial;
190
+ export type GetManifestOptions = Prettify<BasePartial & GlobPartial & RequiredGlobDirectoryPartial>;
191
191
 
192
- export type GetManifestOptionsComplete = BaseResolved & GlobResolved & RequiredGlobDirectoryResolved;
192
+ export type GetManifestOptionsComplete = Prettify<BaseResolved & GlobResolved & RequiredGlobDirectoryResolved>;
193
193
 
194
- export type InjectManifestOptions = BasePartial & GlobPartial & InjectPartial & RequiredSwDestPartial & RequiredGlobDirectoryPartial;
194
+ export type InjectManifestOptions = Prettify<BasePartial & GlobPartial & InjectPartial & RequiredSwDestPartial & RequiredGlobDirectoryPartial>;
195
195
 
196
- export type InjectManifestOptionsComplete = BaseResolved & GlobResolved & InjectResolved & RequiredSwDestResolved & RequiredGlobDirectoryResolved;
196
+ export type InjectManifestOptionsComplete = Prettify<
197
+ BaseResolved & GlobResolved & InjectResolved & RequiredSwDestResolved & RequiredGlobDirectoryResolved
198
+ >;
197
199
 
198
200
  export interface GetManifestResult {
199
201
  count: number;
@@ -206,15 +208,6 @@ export type BuildResult = Omit<GetManifestResult, "manifestEntries"> & {
206
208
  filePaths: string[];
207
209
  };
208
210
 
209
- /**
210
- * @private
211
- */
212
- export interface FileDetails {
213
- file: string;
214
- hash: string | null;
215
- size: number;
216
- }
217
-
218
211
  /**
219
212
  * @private
220
213
  */
@@ -223,7 +216,7 @@ export type BuildType = "dev" | "prod";
223
216
  /**
224
217
  * @private
225
218
  */
226
- export type SerwistPackageJSON = PackageJson;
219
+ export type SerwistPackageJSON = Prettify<PackageJson>;
227
220
 
228
221
  /**
229
222
  * @private
@@ -1,47 +0,0 @@
1
- export declare const errors: {
2
- "unable-to-get-rootdir": string;
3
- "no-extension": string;
4
- "invalid-file-manifest-name": string;
5
- "unable-to-get-file-manifest-name": string;
6
- "invalid-sw-dest": string;
7
- "unable-to-get-sw-name": string;
8
- "unable-to-get-save-config": string;
9
- "unable-to-get-file-hash": string;
10
- "unable-to-get-file-size": string;
11
- "unable-to-glob-files": string;
12
- "unable-to-make-manifest-directory": string;
13
- "read-manifest-template-failure": string;
14
- "populating-manifest-tmpl-failed": string;
15
- "manifest-file-write-failure": string;
16
- "unable-to-make-sw-directory": string;
17
- "sw-write-failure": string;
18
- "sw-write-failure-directory": string;
19
- "unable-to-copy-serwist-libraries": string;
20
- "invalid-glob-directory": string;
21
- "invalid-dont-cache-bust": string;
22
- "invalid-exclude-files": string;
23
- "invalid-get-manifest-entries-input": string;
24
- "invalid-manifest-path": string;
25
- "invalid-manifest-entries": string;
26
- "invalid-manifest-format": string;
27
- "invalid-static-file-globs": string;
28
- "invalid-templated-urls": string;
29
- "templated-url-matches-glob": string;
30
- "invalid-glob-ignores": string;
31
- "manifest-entry-bad-url": string;
32
- "modify-url-prefix-bad-prefixes": string;
33
- "invalid-inject-manifest-arg": string;
34
- "injection-point-not-found": string;
35
- "multiple-injection-points": string;
36
- "useless-glob-pattern": string;
37
- "bad-template-urls-asset": string;
38
- "invalid-generate-file-manifest-arg": string;
39
- "invalid-sw-src": string;
40
- "same-src-and-dest": string;
41
- "no-module-name": string;
42
- "bad-manifest-transforms-return-value": string;
43
- "string-entry-warning": string;
44
- "cant-find-sourcemap": string;
45
- "manifest-transforms": string;
46
- };
47
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFlB,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { FileDetails } from "../types.js";
2
- export declare const getCompositeDetails: (compositeURL: string, dependencyDetails: FileDetails[]) => FileDetails;
3
- //# sourceMappingURL=get-composite-details.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-composite-details.d.ts","sourceRoot":"","sources":["../../src/lib/get-composite-details.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,eAAO,MAAM,mBAAmB,GAAI,cAAc,MAAM,EAAE,mBAAmB,WAAW,EAAE,KAAG,WAkB5F,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const getFileHash: (file: string) => string;
2
- //# sourceMappingURL=get-file-hash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-file-hash.d.ts","sourceRoot":"","sources":["../../src/lib/get-file-hash.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MAO1C,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const getFileSize: (file: string) => number | null;
2
- //# sourceMappingURL=get-file-size.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-file-size.d.ts","sourceRoot":"","sources":["../../src/lib/get-file-size.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAUnD,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { FileDetails } from "../types.js";
2
- export declare const getStringDetails: (url: string, str: string) => FileDetails;
3
- //# sourceMappingURL=get-string-details.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-string-details.d.ts","sourceRoot":"","sources":["../../src/lib/get-string-details.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,WAI1D,CAAC"}
@@ -1,3 +0,0 @@
1
- import crypto from "node:crypto";
2
- export declare function getStringHash(input: crypto.BinaryLike): string;
3
- //# sourceMappingURL=get-string-hash.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-string-hash.d.ts","sourceRoot":"","sources":["../../src/lib/get-string-hash.ts"],"names":[],"mappings":"AAQA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAI9D"}
package/src/lib/errors.ts DELETED
@@ -1,93 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import { oneLine as ol } from "common-tags";
10
-
11
- export const errors = {
12
- "unable-to-get-rootdir": "Unable to get the root directory of your web app.",
13
- "no-extension": ol`Unable to detect a usable extension for a file in your web
14
- app directory.`,
15
- "invalid-file-manifest-name": ol`The File Manifest Name must have at least one
16
- character.`,
17
- "unable-to-get-file-manifest-name": "Unable to get a file manifest name.",
18
- "invalid-sw-dest": `The 'swDest' value must be a valid path.`,
19
- "unable-to-get-sw-name": "Unable to get a service worker file name.",
20
- "unable-to-get-save-config": ol`An error occurred when asking to save details
21
- in a config file.`,
22
- "unable-to-get-file-hash": ol`An error occurred when attempting to create a
23
- file hash.`,
24
- "unable-to-get-file-size": ol`An error occurred when attempting to get a file
25
- size.`,
26
- "unable-to-glob-files": "An error occurred when globbing for files.",
27
- "unable-to-make-manifest-directory": ol`Unable to make output directory for
28
- file manifest.`,
29
- "read-manifest-template-failure": "Unable to read template for file manifest",
30
- "populating-manifest-tmpl-failed": ol`An error occurred when populating the
31
- file manifest template.`,
32
- "manifest-file-write-failure": "Unable to write the file manifest.",
33
- "unable-to-make-sw-directory": ol`Unable to make the directories to output
34
- the service worker path.`,
35
- "sw-write-failure": "Unable to write the service worker file.",
36
- "sw-write-failure-directory": ol`Unable to write the service worker file;
37
- 'swDest' should be a full path to the file, not a path to a directory.`,
38
- "unable-to-copy-serwist-libraries": ol`One or more of the Serwist libraries
39
- could not be copied over to the destination directory: `,
40
- "invalid-glob-directory": ol`The supplied globDirectory must be a path as a
41
- string.`,
42
- "invalid-dont-cache-bust": ol`The supplied 'dontCacheBustURLsMatching'
43
- parameter must be a RegExp.`,
44
- "invalid-exclude-files": "The excluded files should be an array of strings.",
45
- "invalid-get-manifest-entries-input": ol`The input to
46
- 'getFileManifestEntries()' must be an object.`,
47
- "invalid-manifest-path": ol`The supplied manifest path is not a string with
48
- at least one character.`,
49
- "invalid-manifest-entries": ol`The manifest entries must be an array of
50
- strings or JavaScript objects containing a url parameter.`,
51
- "invalid-manifest-format": ol`The value of the 'format' option passed to
52
- generateFileManifest() must be either 'iife' (the default) or 'es'.`,
53
- "invalid-static-file-globs": ol`The 'globPatterns' value must be an array
54
- of strings.`,
55
- "invalid-templated-urls": ol`The 'templatedURLs' value should be an object
56
- that maps URLs to either a string, or to an array of glob patterns.`,
57
- "templated-url-matches-glob": ol`One of the 'templatedURLs' URLs is already
58
- being tracked via 'globPatterns': `,
59
- "invalid-glob-ignores": ol`The 'globIgnores' parameter must be an array of
60
- glob pattern strings.`,
61
- "manifest-entry-bad-url": ol`The generated manifest contains an entry without
62
- a URL string. This is likely an error with @serwist/build.`,
63
- "modify-url-prefix-bad-prefixes": ol`The 'modifyURLPrefix' parameter must be
64
- an object with string key value pairs.`,
65
- "invalid-inject-manifest-arg": ol`The input to 'injectManifest()' must be an
66
- object.`,
67
- "injection-point-not-found": ol`Unable to find a place to inject the manifest.
68
- Please ensure that your service worker file contains the following: `,
69
- "multiple-injection-points": ol`Please ensure that your 'swSrc' file contains
70
- only one match for the following: `,
71
- "useless-glob-pattern": ol`One of the glob patterns doesn't match any files.
72
- Please remove or fix the following: `,
73
- "bad-template-urls-asset": ol`There was an issue using one of the provided
74
- 'templatedURLs'.`,
75
- "invalid-generate-file-manifest-arg": ol`The input to generateFileManifest()
76
- must be an Object.`,
77
- "invalid-sw-src": `The 'swSrc' file can't be read.`,
78
- "same-src-and-dest": ol`Unable to find a place to inject the manifest. This is
79
- likely because swSrc and swDest are configured to the same file.
80
- Please ensure that your swSrc file contains the following:`,
81
- "no-module-name": ol`You must provide a moduleName parameter when calling
82
- getModuleURL().`,
83
- "bad-manifest-transforms-return-value": ol`The return value from a
84
- manifestTransform should be an object with 'manifest' and optionally
85
- 'warnings' properties.`,
86
- "string-entry-warning": ol`Some items were passed to additionalPrecacheEntries
87
- without revisioning info. This is generally NOT safe. Learn more at
88
- https://bit.ly/wb-precache.`,
89
- "cant-find-sourcemap": ol`The swSrc file refers to a sourcemap that can't be
90
- opened:`,
91
- "manifest-transforms": ol`When using manifestTransforms, you must provide
92
- an array of functions.`,
93
- };
@@ -1,31 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import crypto from "node:crypto";
10
-
11
- import type { FileDetails } from "../types.js";
12
-
13
- export const getCompositeDetails = (compositeURL: string, dependencyDetails: FileDetails[]): FileDetails => {
14
- let totalSize = 0;
15
- let compositeHash = "";
16
-
17
- for (const fileDetails of dependencyDetails) {
18
- totalSize += fileDetails.size;
19
- compositeHash += fileDetails.hash === null ? "" : fileDetails.hash;
20
- }
21
-
22
- const md5 = crypto.createHash("md5");
23
- md5.update(compositeHash);
24
- const hashOfHashes = md5.digest("hex");
25
-
26
- return {
27
- file: compositeURL,
28
- hash: hashOfHashes,
29
- size: totalSize,
30
- };
31
- };
@@ -1,21 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import { readFileSync } from "node:fs";
10
-
11
- import { errors } from "./errors.js";
12
- import { getStringHash } from "./get-string-hash.js";
13
-
14
- export const getFileHash = (file: string): string => {
15
- try {
16
- const buffer = readFileSync(file);
17
- return getStringHash(buffer);
18
- } catch (err) {
19
- throw new Error(`${errors["unable-to-get-file-hash"]} '${err instanceof Error && err.message ? err.message : ""}'`);
20
- }
21
- };
@@ -1,22 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import fs from "node:fs";
10
- import { errors } from "./errors.js";
11
-
12
- export const getFileSize = (file: string): number | null => {
13
- try {
14
- const stat = fs.statSync(file);
15
- if (!stat.isFile()) {
16
- return null;
17
- }
18
- return stat.size;
19
- } catch (err) {
20
- throw new Error(`${errors["unable-to-get-file-size"]} '${err instanceof Error && err.message ? err.message : ""}'`);
21
- }
22
- };
@@ -1,16 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import type { FileDetails } from "../types.js";
10
- import { getStringHash } from "./get-string-hash.js";
11
-
12
- export const getStringDetails = (url: string, str: string): FileDetails => ({
13
- file: url,
14
- hash: getStringHash(str),
15
- size: str.length,
16
- });
@@ -1,15 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import crypto from "node:crypto";
10
-
11
- export function getStringHash(input: crypto.BinaryLike): string {
12
- const md5 = crypto.createHash("md5");
13
- md5.update(input);
14
- return md5.digest("hex");
15
- }