@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.
Files changed (78) hide show
  1. package/dist/chunks/glob.js +3 -3
  2. package/dist/chunks/injectManifest.js +5 -5
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +26 -58
  6. package/dist/index.schema.d.ts +13 -0
  7. package/dist/index.schema.d.ts.map +1 -0
  8. package/dist/index.schema.js +9 -0
  9. package/dist/lib/additional-precache-entries-transform.d.ts +6 -8
  10. package/dist/lib/additional-precache-entries-transform.d.ts.map +1 -1
  11. package/dist/lib/errors.d.ts +0 -3
  12. package/dist/lib/errors.d.ts.map +1 -1
  13. package/dist/lib/get-file-details.d.ts +3 -9
  14. package/dist/lib/get-file-details.d.ts.map +1 -1
  15. package/dist/lib/get-file-hash.d.ts +1 -1
  16. package/dist/lib/get-file-hash.d.ts.map +1 -1
  17. package/dist/lib/get-file-manifest-entries.d.ts +2 -2
  18. package/dist/lib/get-file-manifest-entries.d.ts.map +1 -1
  19. package/dist/lib/get-string-details.d.ts +1 -1
  20. package/dist/lib/get-string-details.d.ts.map +1 -1
  21. package/dist/lib/get-string-hash.d.ts +1 -1
  22. package/dist/lib/get-string-hash.d.ts.map +1 -1
  23. package/dist/lib/transform-manifest.d.ts +4 -3
  24. package/dist/lib/transform-manifest.d.ts.map +1 -1
  25. package/dist/lib/validate-options.d.ts +1 -3
  26. package/dist/lib/validate-options.d.ts.map +1 -1
  27. package/dist/schema/assertType.d.ts +1 -0
  28. package/dist/schema/assertType.d.ts.map +1 -1
  29. package/dist/schema/base.d.ts +24 -24
  30. package/dist/schema/getManifest.d.ts +24 -24
  31. package/dist/schema/injectManifest.d.ts +27 -27
  32. package/dist/schema/injectManifest.d.ts.map +1 -1
  33. package/dist/schema/manifestEntry.d.ts +3 -3
  34. package/dist/schema/manifestTransform.d.ts +18 -18
  35. package/dist/{lib/serwist-config-error.d.ts → schema/serwistConfigError.d.ts} +1 -1
  36. package/dist/schema/serwistConfigError.d.ts.map +1 -0
  37. package/dist/types.d.ts +6 -156
  38. package/dist/types.d.ts.map +1 -1
  39. package/package.json +15 -23
  40. package/src/index.schema.ts +29 -0
  41. package/src/index.ts +2 -3
  42. package/src/inject-manifest.ts +1 -1
  43. package/src/lib/additional-precache-entries-transform.ts +4 -8
  44. package/src/lib/errors.ts +0 -6
  45. package/src/lib/get-composite-details.ts +2 -2
  46. package/src/lib/get-file-details.ts +9 -17
  47. package/src/lib/get-file-hash.ts +4 -4
  48. package/src/lib/get-file-manifest-entries.ts +9 -9
  49. package/src/lib/get-string-details.ts +5 -7
  50. package/src/lib/get-string-hash.ts +1 -1
  51. package/src/lib/transform-manifest.ts +28 -16
  52. package/src/lib/validate-options.ts +2 -23
  53. package/src/schema/assertType.ts +2 -0
  54. package/src/schema/injectManifest.ts +4 -4
  55. package/src/schema/manifestEntry.ts +1 -1
  56. package/src/types.ts +6 -188
  57. package/dist/chunks/vite.js +0 -7
  58. package/dist/chunks/webpack.js +0 -34
  59. package/dist/index.next.d.ts +0 -3
  60. package/dist/index.next.d.ts.map +0 -1
  61. package/dist/index.next.js +0 -38
  62. package/dist/lib/serwist-config-error.d.ts.map +0 -1
  63. package/dist/lib/validate-next-options.d.ts +0 -3
  64. package/dist/lib/validate-next-options.d.ts.map +0 -1
  65. package/dist/schema/next.d.ts +0 -243
  66. package/dist/schema/next.d.ts.map +0 -1
  67. package/dist/schema/vite.d.ts +0 -196
  68. package/dist/schema/vite.d.ts.map +0 -1
  69. package/dist/schema/webpack.d.ts +0 -231
  70. package/dist/schema/webpack.d.ts.map +0 -1
  71. package/src/_types.js +0 -112
  72. package/src/index.next.ts +0 -3
  73. package/src/lib/validate-next-options.ts +0 -14
  74. package/src/schema/next.ts +0 -33
  75. package/src/schema/vite.ts +0 -18
  76. package/src/schema/webpack.ts +0 -47
  77. package/dist/chunks/{serwist-config-error.js → validationErrorMap.js} +7 -7
  78. /package/src/{lib/serwist-config-error.ts → schema/serwistConfigError.ts} +0 -0
package/src/_types.js DELETED
@@ -1,112 +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
- /**
10
- * @typedef {Object} ManifestEntry
11
- * @property {string} url The URL to the asset in the manifest.
12
- * @property {string} revision The revision details for the file. This should be
13
- * either a hash generated based on the file contents, or `null` if there is
14
- * versioning already included in the URL.
15
- * @property {string} [integrity] Integrity metadata that will be used when
16
- * making the network request for the URL.
17
- */
18
-
19
- /**
20
- * @typedef {Object} ManifestTransformResult
21
- * @property {Array<module:workbox-build.ManifestEntry>} manifest
22
- * @property {Array<string>|undefined} warnings
23
- */
24
-
25
- /**
26
- * @typedef {Object} RuntimeCachingEntry
27
- *
28
- * @property {string|module:workbox-routing~handlerCallback} handler
29
- * Either the name of one of the [built-in strategy classes]{@link module:workbox-strategies},
30
- * or custom handler callback to use when the generated route matches.
31
- *
32
- * @property {string|RegExp|module:workbox-routing~matchCallback} urlPattern
33
- * The value that will be passed to [`registerRoute()`]{@link module:workbox-routing.registerRoute},
34
- * used to determine whether the generated route will match a given request.
35
- *
36
- * @property {string} [method='GET'] The
37
- * [HTTP method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) that
38
- * will match the generated route.
39
- *
40
- * @property {Object} [options]
41
- *
42
- * @property {Object} [options.backgroundSync]
43
- *
44
- * @property {string} [options.backgroundSync.name] The `name` property to use
45
- * when creating the
46
- * [`BackgroundSyncPlugin`]{@link module:workbox-background-sync.BackgroundSyncPlugin}.
47
- *
48
- * @property {Object} [options.backgroundSync.options] The `options` property
49
- * to use when creating the
50
- * [`BackgroundSyncPlugin`]{@link module:workbox-background-sync.BackgroundSyncPlugin}.
51
- *
52
- * @property {Object} [options.broadcastUpdate]
53
- *
54
- * @property {string} [options.broadcastUpdate.channelName] The `channelName`
55
- * property to use when creating the
56
- * [`BroadcastCacheUpdatePlugin`]{@link module:workbox-broadcast-update.BroadcastUpdatePlugin}.
57
- *
58
- * @property {Object} [options.broadcastUpdate.options] The `options` property
59
- * to use when creating the
60
- * [`BroadcastCacheUpdatePlugin`]{@link module:workbox-broadcast-update.BroadcastUpdatePlugin}.
61
- *
62
- * @property {Object} [options.cacheableResponse]
63
- *
64
- * @property {Object} [options.cacheableResponse.headers] The `headers` property
65
- * to use when creating the
66
- * [`CacheableResponsePlugin`]{@link module:workbox-cacheable-response.CacheableResponsePlugin}.
67
- *
68
- * @property {Array<number>} [options.cacheableResponse.statuses] `statuses`
69
- * property to use when creating the
70
- * [`CacheableResponsePlugin`]{@link module:workbox-cacheable-response.CacheableResponsePlugin}.
71
- *
72
- * @property {string} [options.cacheName] The `cacheName` to use when
73
- * constructing one of the
74
- * [Workbox strategy classes]{@link module:workbox-strategies}.
75
- *
76
- * @property {Object} [options.fetchOptions] The `fetchOptions` property value
77
- * to use when constructing one of the
78
- * [Workbox strategy classes]{@link module:workbox-strategies}.
79
- *
80
- * @property {Object} [options.expiration]
81
- *
82
- * @property {number} [options.expiration.maxAgeSeconds] The `maxAgeSeconds`
83
- * property to use when creating the
84
- * [`ExpirationPlugin`]{@link module:workbox-expiration.ExpirationPlugin}.
85
- *
86
- * @property {number} [options.expiration.maxEntries] The `maxEntries`
87
- * property to use when creating the
88
- * [`ExpirationPlugin`]{@link module:workbox-expiration.ExpirationPlugin}.
89
- *
90
- * @property {Object} [options.precacheFallback]
91
- *
92
- * @property {string} [options.precacheFallback.fallbackURL] The `fallbackURL`
93
- * property to use when creating the
94
- * [`PrecacheFallbackPlugin`]{@link module:workbox-precaching.PrecacheFallbackPlugin}.
95
- *
96
- * @property {boolean} [options.rangeRequests] Set to `true` to add the
97
- * [`RangeRequestsPlugin`]{@link module:workbox-range-requests.RangeRequestsPlugin}
98
- * for the strategy being configured.
99
- *
100
- * @property {Object} [options.matchOptions] The `matchOptions` property value
101
- * to use when constructing one of the
102
- * [Workbox strategy classes]{@link module:workbox-strategies}.
103
- *
104
- * @property {number} [options.networkTimeoutSeconds] The
105
- * `networkTimeoutSeconds` property value to use when creating a
106
- * [`NetworkFirst`]{@link module:workbox-strategies.NetworkFirst} strategy.
107
- *
108
- * @property {Array<Object>} [options.plugins]
109
- * One or more [additional plugins](https://developers.google.com/web/tools/workbox/guides/using-plugins#custom_plugins)
110
- * to apply to the handler. Useful when you want a plugin that doesn't have a
111
- * "shortcut" configuration.
112
- */
package/src/index.next.ts DELETED
@@ -1,3 +0,0 @@
1
- import { validateNextInjectManifestOptions } from "./lib/validate-next-options.js";
2
-
3
- export { validateNextInjectManifestOptions };
@@ -1,14 +0,0 @@
1
- import { nextInjectManifestOptions } from "../schema/next.js";
2
- import { validationErrorMap } from "../schema/validationErrorMap.js";
3
- import type { NextInjectManifestOptionsComplete } from "../types.js";
4
- import { SerwistConfigError } from "./serwist-config-error.js";
5
-
6
- export const validateNextInjectManifestOptions = (input: unknown): NextInjectManifestOptionsComplete => {
7
- const result = nextInjectManifestOptions.safeParse(input, {
8
- errorMap: validationErrorMap,
9
- });
10
- if (!result.success) {
11
- throw new SerwistConfigError({ moduleName: "@serwist/next", message: JSON.stringify(result.error.format(), null, 2) });
12
- }
13
- return result.data;
14
- };
@@ -1,33 +0,0 @@
1
- import { z } from "zod";
2
- import type {
3
- NextInjectManifestOptions,
4
- NextInjectManifestOptionsComplete,
5
- NextInjectManifestPartial,
6
- NextInjectManifestResolved,
7
- } from "../types.js";
8
- import { type Equals, assertType } from "./assertType.js";
9
- import { requiredSwDestPartial } from "./swDest.js";
10
- import { webpackInjectManifestOptions } from "./webpack.js";
11
-
12
- export const nextInjectManifestPartial = z
13
- .object({
14
- cacheOnNavigation: z.boolean().default(false),
15
- disable: z.boolean().default(false),
16
- register: z.boolean().default(true),
17
- reloadOnOnline: z.boolean().default(true),
18
- scope: z.string().optional(),
19
- swUrl: z.string().default("/sw.js"),
20
- globPublicPatterns: z.union([z.string(), z.array(z.string())]).default(["**/*"]),
21
- })
22
- .strict("Do not pass invalid properties to NextInjectManifestPartial!");
23
-
24
- export const nextInjectManifestOptions = webpackInjectManifestOptions
25
- .merge(requiredSwDestPartial)
26
- .merge(nextInjectManifestPartial)
27
- .omit({ disablePrecacheManifest: true })
28
- .strict("Do not pass invalid properties to NextInjectManifestOptions!");
29
-
30
- assertType<Equals<NextInjectManifestPartial, z.input<typeof nextInjectManifestPartial>>>();
31
- assertType<Equals<NextInjectManifestResolved, z.output<typeof nextInjectManifestPartial>>>();
32
- assertType<Equals<NextInjectManifestOptions, z.input<typeof nextInjectManifestOptions>>>();
33
- assertType<Equals<NextInjectManifestOptionsComplete, z.output<typeof nextInjectManifestOptions>>>();
@@ -1,18 +0,0 @@
1
- import type { z } from "zod";
2
- import type { ViteInjectManifestOptions, ViteInjectManifestOptionsComplete } from "../types.js";
3
- import { type Equals, assertType } from "./assertType.js";
4
- import { basePartial } from "./base.js";
5
- import { globPartial } from "./glob.js";
6
- import { requiredGlobDirectoryPartial } from "./glob.js";
7
- import { injectPartial } from "./injectManifest.js";
8
- import { requiredSwDestPartial } from "./swDest.js";
9
-
10
- export const viteInjectManifestOptions = basePartial
11
- .merge(globPartial)
12
- .merge(injectPartial)
13
- .merge(requiredSwDestPartial)
14
- .merge(requiredGlobDirectoryPartial)
15
- .strict("Do not pass invalid properties to ViteInjectManifestPartial!");
16
-
17
- assertType<Equals<ViteInjectManifestOptions, z.input<typeof viteInjectManifestOptions>>>();
18
- assertType<Equals<ViteInjectManifestOptionsComplete, z.output<typeof viteInjectManifestOptions>>>();
@@ -1,47 +0,0 @@
1
- import { z } from "zod";
2
- import type {
3
- WebpackInjectManifestOptions,
4
- WebpackInjectManifestOptionsComplete,
5
- WebpackInjectManifestPartial,
6
- WebpackInjectManifestResolved,
7
- WebpackPartial,
8
- WebpackResolved,
9
- } from "../types.js";
10
- import { type Equals, assertType } from "./assertType.js";
11
- import { basePartial } from "./base.js";
12
- import { injectPartial } from "./injectManifest.js";
13
- import { optionalSwDestPartial } from "./swDest.js";
14
-
15
- export const webpackPartial = z
16
- .object({
17
- chunks: z.array(z.string()).optional(),
18
- exclude: z
19
- .array(z.union([z.string(), z.instanceof(RegExp), z.function(z.tuple([z.any()]), z.boolean())]))
20
- .default([/\.map$/, /^manifest.*\.js$/]),
21
- excludeChunks: z.array(z.string()).optional(),
22
- include: z.array(z.union([z.string(), z.instanceof(RegExp), z.function(z.tuple([z.any()]), z.boolean())])).optional(),
23
- mode: z.string().nullable().optional(),
24
- })
25
- .strict("Do not pass invalid properties to WebpackPartial!");
26
-
27
- export const webpackInjectManifestPartial = z
28
- .object({
29
- compileSrc: z.boolean().default(true),
30
- swDest: z.string().optional(),
31
- webpackCompilationPlugins: z.array(z.any()).optional(),
32
- })
33
- .strict("Do not pass invalid properties to WebpackInjectManifestPartial!");
34
-
35
- export const webpackInjectManifestOptions = basePartial
36
- .merge(webpackPartial)
37
- .merge(injectPartial)
38
- .merge(optionalSwDestPartial)
39
- .merge(webpackInjectManifestPartial)
40
- .strict("Do not pass invalid properties to WebpackInjectManifestOptions!");
41
-
42
- assertType<Equals<WebpackPartial, z.input<typeof webpackPartial>>>();
43
- assertType<Equals<WebpackResolved, z.output<typeof webpackPartial>>>();
44
- assertType<Equals<WebpackInjectManifestPartial, z.input<typeof webpackInjectManifestPartial>>>();
45
- assertType<Equals<WebpackInjectManifestResolved, z.output<typeof webpackInjectManifestPartial>>>();
46
- assertType<Equals<WebpackInjectManifestOptions, z.input<typeof webpackInjectManifestOptions>>>();
47
- assertType<Equals<WebpackInjectManifestOptionsComplete, z.output<typeof webpackInjectManifestOptions>>>();
@@ -1,5 +1,12 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ class SerwistConfigError extends Error {
4
+ constructor({ moduleName, message }){
5
+ super(`Received an invalid ${moduleName ?? "Serwist"} configuration: ${message}`);
6
+ Object.setPrototypeOf(this, new.target.prototype);
7
+ }
8
+ }
9
+
3
10
  const validationErrorMap = (error, ctx)=>{
4
11
  switch(error.code){
5
12
  case z.ZodIssueCode.invalid_type:
@@ -44,11 +51,4 @@ const validationErrorMap = (error, ctx)=>{
44
51
  };
45
52
  };
46
53
 
47
- class SerwistConfigError extends Error {
48
- constructor({ moduleName, message }){
49
- super(`Received an invalid ${moduleName ?? "Serwist"} configuration: ${message}`);
50
- Object.setPrototypeOf(this, new.target.prototype);
51
- }
52
- }
53
-
54
54
  export { SerwistConfigError as S, validationErrorMap as v };