@serwist/build
Version:
A module that integrates into your build process, helping you generate a manifest of local files that should be precached.
77 lines (70 loc) • 2.37 kB
JavaScript
import { z } from 'zod';
const manifestEntry = z.strictObject({
integrity: z.string().optional(),
revision: z.string().nullable().optional(),
url: z.string()
});
const fn = ({ input, output })=>{
const schema = z.function({
input: z.tuple(input),
output
});
return z.custom((arg)=>typeof arg === "function").transform((arg)=>schema.implement(arg));
};
const asyncFn = ({ input, output })=>{
const schema = z.function({
input: z.tuple(input),
output
});
return z.custom((arg)=>typeof arg === "function").transform((arg)=>schema.implementAsync(arg));
};
const sizeObject = z.object({
size: z.number()
});
const manifestEntryWithSize = z.object({
...manifestEntry.shape,
...sizeObject.shape
});
const manifestTransformResult = z.strictObject({
manifest: z.array(manifestEntryWithSize),
warnings: z.array(z.string()).optional()
});
const manifestTransform = asyncFn({
input: [
z.array(manifestEntryWithSize),
z.unknown().optional()
],
output: manifestTransformResult
});
const basePartial = z.strictObject({
additionalPrecacheEntries: z.array(z.union([
z.string(),
manifestEntry
])).optional(),
disablePrecacheManifest: z.boolean().default(false),
dontCacheBustURLsMatching: z.instanceof(RegExp).optional(),
manifestTransforms: z.array(manifestTransform).optional(),
maximumFileSizeToCacheInBytes: z.number().default(2097152),
modifyURLPrefix: z.record(z.string(), z.string()).optional()
});
const globPartial = z.strictObject({
globFollow: z.boolean().default(true),
globIgnores: z.array(z.string()).default([
"**/node_modules/**/*"
]),
globPatterns: z.array(z.string()).default([
"**/*.{js,css,html}"
]),
globStrict: z.boolean().default(true),
templatedURLs: z.record(z.string(), z.union([
z.string(),
z.array(z.string())
])).optional()
});
const optionalGlobDirectoryPartial = z.strictObject({
globDirectory: z.string().optional()
});
const requiredGlobDirectoryPartial = z.strictObject({
globDirectory: z.string()
});
export { asyncFn as a, basePartial as b, manifestTransform as c, manifestTransformResult as d, fn as f, globPartial as g, manifestEntry as m, optionalGlobDirectoryPartial as o, requiredGlobDirectoryPartial as r };