@serwist/build 8.4.4 → 9.0.0-preview.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/getManifest.js +6 -0
- package/dist/chunks/glob.js +58 -0
- package/dist/chunks/injectManifest.js +23 -0
- package/dist/chunks/serwist-config-error.js +54 -0
- package/dist/chunks/vite.js +7 -0
- package/dist/chunks/webpack.js +34 -0
- package/dist/get-manifest.d.ts +2 -1
- package/dist/get-manifest.d.ts.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -1014
- package/dist/index.next.d.ts +3 -0
- package/dist/index.next.d.ts.map +1 -0
- package/dist/index.next.js +38 -0
- package/dist/inject-manifest.d.ts +2 -1
- package/dist/inject-manifest.d.ts.map +1 -0
- package/dist/lib/additional-precache-entries-transform.d.ts +6 -5
- package/dist/lib/additional-precache-entries-transform.d.ts.map +1 -0
- package/dist/lib/errors.d.ts +1 -2
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/escape-regexp.d.ts +2 -1
- package/dist/lib/escape-regexp.d.ts.map +1 -0
- package/dist/lib/get-composite-details.d.ts +2 -1
- package/dist/lib/get-composite-details.d.ts.map +1 -0
- package/dist/lib/get-file-details.d.ts +2 -1
- package/dist/lib/get-file-details.d.ts.map +1 -0
- package/dist/lib/get-file-hash.d.ts +1 -0
- package/dist/lib/get-file-hash.d.ts.map +1 -0
- package/dist/lib/get-file-manifest-entries.d.ts +1 -0
- package/dist/lib/get-file-manifest-entries.d.ts.map +1 -0
- package/dist/lib/get-file-size.d.ts +1 -0
- package/dist/lib/get-file-size.d.ts.map +1 -0
- package/dist/lib/get-source-map-url.d.ts +1 -0
- package/dist/lib/get-source-map-url.d.ts.map +1 -0
- package/dist/lib/get-string-details.d.ts +1 -0
- package/dist/lib/get-string-details.d.ts.map +1 -0
- package/dist/lib/get-string-hash.d.ts +1 -0
- package/dist/lib/get-string-hash.d.ts.map +1 -0
- package/dist/lib/maximum-size-transform.d.ts +1 -0
- package/dist/lib/maximum-size-transform.d.ts.map +1 -0
- package/dist/lib/modify-url-prefix-transform.d.ts +1 -0
- package/dist/lib/modify-url-prefix-transform.d.ts.map +1 -0
- package/dist/lib/no-revision-for-urls-matching-transform.d.ts +1 -0
- package/dist/lib/no-revision-for-urls-matching-transform.d.ts.map +1 -0
- package/dist/lib/rebase-path.d.ts +1 -0
- package/dist/lib/rebase-path.d.ts.map +1 -0
- package/dist/lib/replace-and-update-source-map.d.ts +1 -0
- package/dist/lib/replace-and-update-source-map.d.ts.map +1 -0
- package/dist/lib/serwist-config-error.d.ts +7 -0
- package/dist/lib/serwist-config-error.d.ts.map +1 -0
- package/dist/lib/transform-manifest.d.ts +2 -1
- package/dist/lib/transform-manifest.d.ts.map +1 -0
- package/dist/lib/translate-url-to-sourcemap-paths.d.ts +1 -0
- package/dist/lib/translate-url-to-sourcemap-paths.d.ts.map +1 -0
- package/dist/lib/validate-next-options.d.ts +3 -0
- package/dist/lib/validate-next-options.d.ts.map +1 -0
- package/dist/lib/validate-options.d.ts +6 -8
- package/dist/lib/validate-options.d.ts.map +1 -0
- package/dist/schema/assertType.d.ts +3 -0
- package/dist/schema/assertType.d.ts.map +1 -0
- package/dist/schema/base.d.ts +169 -0
- package/dist/schema/base.d.ts.map +1 -0
- package/dist/schema/getManifest.d.ts +187 -0
- package/dist/schema/getManifest.d.ts.map +1 -0
- package/dist/schema/glob.d.ts +35 -0
- package/dist/schema/glob.d.ts.map +1 -0
- package/dist/schema/injectManifest.d.ts +206 -0
- package/dist/schema/injectManifest.d.ts.map +1 -0
- package/dist/schema/manifestEntry.d.ts +15 -0
- package/dist/schema/manifestEntry.d.ts.map +1 -0
- package/dist/schema/manifestTransform.d.ts +121 -0
- package/dist/schema/manifestTransform.d.ts.map +1 -0
- package/dist/schema/next.d.ts +243 -0
- package/dist/schema/next.d.ts.map +1 -0
- package/dist/schema/swDest.d.ts +16 -0
- package/dist/schema/swDest.d.ts.map +1 -0
- package/dist/schema/validationErrorMap.d.ts +3 -0
- package/dist/schema/validationErrorMap.d.ts.map +1 -0
- package/dist/schema/vite.d.ts +196 -0
- package/dist/schema/vite.d.ts.map +1 -0
- package/dist/schema/webpack.d.ts +231 -0
- package/dist/schema/webpack.d.ts.map +1 -0
- package/dist/types.d.ts +147 -175
- package/dist/types.d.ts.map +1 -0
- package/package.json +43 -29
- package/src/_types.js +112 -0
- package/src/get-manifest.ts +33 -0
- package/src/index.next.ts +3 -0
- package/{dist/index.d.cts → src/index.ts} +27 -2
- package/src/inject-manifest.ts +140 -0
- package/src/lib/additional-precache-entries-transform.ts +58 -0
- package/src/lib/errors.ts +99 -0
- package/src/lib/escape-regexp.ts +12 -0
- package/src/lib/get-composite-details.ts +31 -0
- package/src/lib/get-file-details.ts +68 -0
- package/src/lib/get-file-hash.ts +21 -0
- package/src/lib/get-file-manifest-entries.ts +126 -0
- package/src/lib/get-file-size.ts +23 -0
- package/src/lib/get-source-map-url.ts +17 -0
- package/src/lib/get-string-details.ts +18 -0
- package/src/lib/get-string-hash.ts +15 -0
- package/src/lib/maximum-size-transform.ts +29 -0
- package/src/lib/modify-url-prefix-transform.ts +55 -0
- package/src/lib/no-revision-for-urls-matching-transform.ts +32 -0
- package/src/lib/rebase-path.ts +22 -0
- package/src/lib/replace-and-update-source-map.ts +122 -0
- package/src/lib/serwist-config-error.ts +6 -0
- package/src/lib/transform-manifest.ts +158 -0
- package/src/lib/translate-url-to-sourcemap-paths.ts +38 -0
- package/src/lib/validate-next-options.ts +14 -0
- package/src/lib/validate-options.ts +47 -0
- package/src/schema/assertType.ts +5 -0
- package/src/schema/base.ts +20 -0
- package/src/schema/getManifest.ts +13 -0
- package/src/schema/glob.ts +41 -0
- package/src/schema/injectManifest.ts +25 -0
- package/src/schema/manifestEntry.ts +9 -0
- package/src/schema/manifestTransform.ts +15 -0
- package/src/schema/next.ts +33 -0
- package/src/schema/swDest.ts +20 -0
- package/src/schema/validationErrorMap.ts +36 -0
- package/src/schema/vite.ts +18 -0
- package/src/schema/webpack.ts +47 -0
- package/src/types.ts +407 -0
- package/dist/index.cjs +0 -1632
- package/dist/lib/cdn-utils.d.ts +0 -1
- package/dist/lib/copy-serwist-libraries.d.ts +0 -16
- package/dist/schema/index.d.ts +0 -605
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2021 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
|
+
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";
|
|
16
|
+
|
|
17
|
+
export const validateGetManifestOptions = async (input: unknown): Promise<GetManifestOptionsComplete> => {
|
|
18
|
+
const result = await (await import("../schema/getManifest.js")).getManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
19
|
+
if (!result.success) {
|
|
20
|
+
throw new SerwistConfigError({ moduleName: "@serwist/build", message: JSON.stringify(result.error.format(), null, 2) });
|
|
21
|
+
}
|
|
22
|
+
return result.data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const validateInjectManifestOptions = async (input: unknown): Promise<InjectManifestOptionsComplete> => {
|
|
26
|
+
const result = await (await import("../schema/injectManifest.js")).injectManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
27
|
+
if (!result.success) {
|
|
28
|
+
throw new SerwistConfigError({ moduleName: "@serwist/build", message: JSON.stringify(result.error.format(), null, 2) });
|
|
29
|
+
}
|
|
30
|
+
return result.data;
|
|
31
|
+
};
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import type { BasePartial, BaseResolved } from "../types.js";
|
|
4
|
+
import { type Equals, assertType } from "./assertType.js";
|
|
5
|
+
import { manifestEntry } from "./manifestEntry.js";
|
|
6
|
+
import { manifestTransform } from "./manifestTransform.js";
|
|
7
|
+
|
|
8
|
+
export const basePartial = z
|
|
9
|
+
.object({
|
|
10
|
+
additionalPrecacheEntries: z.array(z.union([z.string(), manifestEntry])).optional(),
|
|
11
|
+
disablePrecacheManifest: z.boolean().default(false),
|
|
12
|
+
dontCacheBustURLsMatching: z.instanceof(RegExp).optional(),
|
|
13
|
+
manifestTransforms: z.array(manifestTransform).optional(),
|
|
14
|
+
maximumFileSizeToCacheInBytes: z.number().default(2097152),
|
|
15
|
+
modifyURLPrefix: z.record(z.string(), z.string()).optional(),
|
|
16
|
+
})
|
|
17
|
+
.strict("Do not pass invalid properties to BasePartial!");
|
|
18
|
+
|
|
19
|
+
assertType<Equals<BasePartial, z.input<typeof basePartial>>>();
|
|
20
|
+
assertType<Equals<BaseResolved, z.output<typeof basePartial>>>();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { GetManifestOptions, GetManifestOptionsComplete } from "../types.js";
|
|
3
|
+
import { type Equals, assertType } from "./assertType.js";
|
|
4
|
+
import { basePartial } from "./base.js";
|
|
5
|
+
import { globPartial, requiredGlobDirectoryPartial } from "./glob.js";
|
|
6
|
+
|
|
7
|
+
export const getManifestOptions = basePartial
|
|
8
|
+
.merge(globPartial)
|
|
9
|
+
.merge(requiredGlobDirectoryPartial)
|
|
10
|
+
.strict("Do not pass invalid properties to GetManifestOptions!");
|
|
11
|
+
|
|
12
|
+
assertType<Equals<GetManifestOptions, z.input<typeof getManifestOptions>>>();
|
|
13
|
+
assertType<Equals<GetManifestOptionsComplete, z.output<typeof getManifestOptions>>>();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type {
|
|
3
|
+
GlobPartial,
|
|
4
|
+
GlobResolved,
|
|
5
|
+
OptionalGlobDirectoryPartial,
|
|
6
|
+
OptionalGlobDirectoryResolved,
|
|
7
|
+
RequiredGlobDirectoryPartial,
|
|
8
|
+
RequiredGlobDirectoryResolved,
|
|
9
|
+
} from "../types.js";
|
|
10
|
+
import { type Equals, assertType } from "./assertType.js";
|
|
11
|
+
|
|
12
|
+
export const globPartial = z
|
|
13
|
+
.object({
|
|
14
|
+
globFollow: z.boolean().default(true),
|
|
15
|
+
globIgnores: z.array(z.string()).default(["**/node_modules/**/*"]),
|
|
16
|
+
globPatterns: z.array(z.string()).default(["**/*.{js,css,html}"]),
|
|
17
|
+
globStrict: z.boolean().default(true),
|
|
18
|
+
templatedURLs: z.record(z.string(), z.union([z.string(), z.array(z.string())])).optional(),
|
|
19
|
+
})
|
|
20
|
+
.strict("Do not pass invalid properties to GlobPartial!");
|
|
21
|
+
|
|
22
|
+
export const optionalGlobDirectoryPartial = z
|
|
23
|
+
.object({
|
|
24
|
+
globDirectory: z.string().optional(),
|
|
25
|
+
})
|
|
26
|
+
.strict("Do not pass invalid properties to OptionalGlobDirectoryPartial!");
|
|
27
|
+
|
|
28
|
+
// This needs to be set when using GetManifest or InjectManifest. This is
|
|
29
|
+
// enforced via runtime validation, and needs to be documented.
|
|
30
|
+
export const requiredGlobDirectoryPartial = z
|
|
31
|
+
.object({
|
|
32
|
+
globDirectory: z.string(),
|
|
33
|
+
})
|
|
34
|
+
.strict("Do not pass invalid properties to RequiredGlobDirectoryPartial!");
|
|
35
|
+
|
|
36
|
+
assertType<Equals<GlobPartial, z.input<typeof globPartial>>>();
|
|
37
|
+
assertType<Equals<GlobResolved, z.output<typeof globPartial>>>();
|
|
38
|
+
assertType<Equals<OptionalGlobDirectoryPartial, z.input<typeof optionalGlobDirectoryPartial>>>();
|
|
39
|
+
assertType<Equals<OptionalGlobDirectoryResolved, z.output<typeof optionalGlobDirectoryPartial>>>();
|
|
40
|
+
assertType<Equals<RequiredGlobDirectoryPartial, z.input<typeof requiredGlobDirectoryPartial>>>();
|
|
41
|
+
assertType<Equals<RequiredGlobDirectoryResolved, z.output<typeof requiredGlobDirectoryPartial>>>();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete, InjectPartial, InjectResolved } from "../types.js";
|
|
3
|
+
import { type Equals, assertType } from "./assertType.js";
|
|
4
|
+
import { basePartial } from "./base.js";
|
|
5
|
+
import { globPartial, requiredGlobDirectoryPartial } from "./glob.js";
|
|
6
|
+
import { requiredSwDestPartial } from "./swDest.js";
|
|
7
|
+
|
|
8
|
+
export const injectPartial = z
|
|
9
|
+
.object({
|
|
10
|
+
injectionPoint: z.string().default("self.__SW_MANIFEST"),
|
|
11
|
+
swSrc: z.string(),
|
|
12
|
+
})
|
|
13
|
+
.strict("Do not pass invalid properties to InjectPartial!");
|
|
14
|
+
|
|
15
|
+
export const injectManifestOptions = basePartial
|
|
16
|
+
.merge(globPartial)
|
|
17
|
+
.merge(injectPartial)
|
|
18
|
+
.merge(requiredSwDestPartial)
|
|
19
|
+
.merge(requiredGlobDirectoryPartial)
|
|
20
|
+
.strict("Do not pass invalid properties to InjectManifestOptions!");
|
|
21
|
+
|
|
22
|
+
assertType<Equals<InjectPartial, z.input<typeof injectPartial>>>();
|
|
23
|
+
assertType<Equals<InjectResolved, z.output<typeof injectPartial>>>();
|
|
24
|
+
assertType<Equals<InjectManifestOptions, z.input<typeof injectManifestOptions>>>();
|
|
25
|
+
assertType<Equals<InjectManifestOptionsComplete, z.output<typeof injectManifestOptions>>>();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { manifestEntry } from "./manifestEntry.js";
|
|
4
|
+
|
|
5
|
+
export const manifestTransformResult = z
|
|
6
|
+
.object({
|
|
7
|
+
manifest: z.array(manifestEntry.merge(z.object({ size: z.number() }))),
|
|
8
|
+
warnings: z.array(z.string()).optional(),
|
|
9
|
+
})
|
|
10
|
+
.strict("Do not pass invalid properties to ManifestTransformResult!");
|
|
11
|
+
|
|
12
|
+
export const manifestTransform = z.function(
|
|
13
|
+
z.tuple([z.array(manifestEntry.merge(z.object({ size: z.number() }))), z.unknown().optional()]),
|
|
14
|
+
z.union([z.promise(manifestTransformResult), manifestTransformResult]),
|
|
15
|
+
);
|
|
@@ -0,0 +1,33 @@
|
|
|
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>>>();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { OptionalSwDestPartial, OptionalSwDestResolved, RequiredSwDestPartial, RequiredSwDestResolved } from "../types.js";
|
|
3
|
+
import { type Equals, assertType } from "./assertType.js";
|
|
4
|
+
|
|
5
|
+
export const optionalSwDestPartial = z
|
|
6
|
+
.object({
|
|
7
|
+
swDest: z.string().optional(),
|
|
8
|
+
})
|
|
9
|
+
.strict("Do not pass invalid properties to OptionalSwDest!");
|
|
10
|
+
|
|
11
|
+
export const requiredSwDestPartial = z
|
|
12
|
+
.object({
|
|
13
|
+
swDest: z.string(),
|
|
14
|
+
})
|
|
15
|
+
.strict("Do not pass invalid properties to RequiredSwDest!");
|
|
16
|
+
|
|
17
|
+
assertType<Equals<OptionalSwDestPartial, z.input<typeof optionalSwDestPartial>>>();
|
|
18
|
+
assertType<Equals<OptionalSwDestResolved, z.output<typeof optionalSwDestPartial>>>();
|
|
19
|
+
assertType<Equals<RequiredSwDestPartial, z.input<typeof requiredSwDestPartial>>>();
|
|
20
|
+
assertType<Equals<RequiredSwDestResolved, z.output<typeof requiredSwDestPartial>>>();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const validationErrorMap: z.ZodErrorMap = (error, ctx) => {
|
|
4
|
+
/*
|
|
5
|
+
This is where you override the various error codes
|
|
6
|
+
*/
|
|
7
|
+
switch (error.code) {
|
|
8
|
+
case z.ZodIssueCode.invalid_type: {
|
|
9
|
+
return { message: `${error.message ?? "Received invalid type"}: expected ${error.expected}, received ${error.received}.` };
|
|
10
|
+
}
|
|
11
|
+
case z.ZodIssueCode.invalid_literal: {
|
|
12
|
+
return { message: `${error.message ?? "Received invalid literal"}: expected ${error.expected}, received ${error.received}.` };
|
|
13
|
+
}
|
|
14
|
+
case z.ZodIssueCode.unrecognized_keys: {
|
|
15
|
+
return { message: `${error.message ?? "Received unrecognized keys"}: ${error.keys.join(",")}` };
|
|
16
|
+
}
|
|
17
|
+
case z.ZodIssueCode.invalid_arguments: {
|
|
18
|
+
return {
|
|
19
|
+
message: `${error.message ?? "Received invalid arguments"}: ${error.argumentsError.errors.map((e) => validationErrorMap(e, ctx)).join(",")}.`,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
case z.ZodIssueCode.invalid_return_type: {
|
|
23
|
+
return {
|
|
24
|
+
message: `${error.message ?? "Received invalid return type"}: ${error.returnTypeError.errors
|
|
25
|
+
.map((e) => validationErrorMap(e, ctx))
|
|
26
|
+
.join(",")}.`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
case z.ZodIssueCode.custom: {
|
|
30
|
+
return { message: error.message ?? ctx.defaultError };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Fallback to the default message.
|
|
35
|
+
return { message: ctx.defaultError };
|
|
36
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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>>>();
|
|
@@ -0,0 +1,47 @@
|
|
|
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>>>();
|