@serwist/webpack-plugin 9.1.0-preview.0 → 9.1.0

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.
@@ -1,8 +1,12 @@
1
1
  import path from 'node:path';
2
2
 
3
+ const toUnix = (p)=>{
4
+ return p.replace(/\\/g, "/").replace(/(?<!^)\/+/g, "/");
5
+ };
6
+
3
7
  const relativeToOutputPath = (compilation, originalPath)=>{
4
8
  if (path.resolve(originalPath) === path.normalize(originalPath)) {
5
- return path.relative(compilation.options.output.path, originalPath);
9
+ return toUnix(path.relative(compilation.options.output.path, originalPath));
6
10
  }
7
11
  return originalPath;
8
12
  };
@@ -30,4 +34,4 @@ const performChildCompilation = async (compiler, compilation, name, src, dest, p
30
34
  });
31
35
  };
32
36
 
33
- export { performChildCompilation as p, relativeToOutputPath as r };
37
+ export { performChildCompilation as p, relativeToOutputPath as r, toUnix as t };
@@ -1,32 +1,37 @@
1
- import { basePartial, injectPartial as injectPartial$1, optionalSwDestPartial } from '@serwist/build/schema';
1
+ import { fn, optionalSwDestPartial, injectPartial as injectPartial$1, basePartial } from '@serwist/build/schema';
2
2
  import { z } from 'zod';
3
3
 
4
- const webpackPartial = z.object({
4
+ const webpackConditionCallback = fn({
5
+ input: [
6
+ z.any()
7
+ ],
8
+ output: z.boolean()
9
+ });
10
+ const webpackCondition = z.union([
11
+ z.string(),
12
+ z.instanceof(RegExp),
13
+ webpackConditionCallback
14
+ ]);
15
+ const webpackPartial = z.strictObject({
5
16
  chunks: z.array(z.string()).optional(),
6
- exclude: z.array(z.union([
7
- z.string(),
8
- z.instanceof(RegExp),
9
- z.function(z.tuple([
10
- z.any()
11
- ]), z.boolean())
12
- ])).default([
17
+ exclude: z.array(webpackCondition).default([
13
18
  /\.map$/,
14
19
  /^manifest.*\.js$/
15
20
  ]),
16
21
  excludeChunks: z.array(z.string()).optional(),
17
- include: z.array(z.union([
18
- z.string(),
19
- z.instanceof(RegExp),
20
- z.function(z.tuple([
21
- z.any()
22
- ]), z.boolean())
23
- ])).optional()
24
- }).strict("Do not pass invalid properties to WebpackPartial!");
25
- const injectPartial = z.object({
22
+ include: z.array(webpackCondition).optional()
23
+ });
24
+ const injectPartial = z.strictObject({
26
25
  compileSrc: z.boolean().default(true),
27
26
  swDest: z.string().optional(),
28
27
  webpackCompilationPlugins: z.array(z.any()).optional()
29
- }).strict("Do not pass invalid properties to WebpackInjectManifestPartial!");
30
- const injectManifestOptions = basePartial.merge(webpackPartial).merge(injectPartial$1).merge(optionalSwDestPartial).merge(injectPartial).strict("Do not pass invalid properties to WebpackInjectManifestOptions!");
28
+ });
29
+ const injectManifestOptions = z.strictObject({
30
+ ...basePartial.shape,
31
+ ...webpackPartial.shape,
32
+ ...injectPartial$1.shape,
33
+ ...optionalSwDestPartial.shape,
34
+ ...injectPartial.shape
35
+ });
31
36
 
32
37
  export { injectManifestOptions, injectPartial, webpackPartial };
package/dist/index.js CHANGED
@@ -1,17 +1,13 @@
1
1
  import path from 'node:path';
2
- import { transformManifest, getSourceMapURL, stringify, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build';
2
+ import { transformManifest, getSourceMapURL, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build';
3
+ import { r as relativeToOutputPath, p as performChildCompilation, t as toUnix } from './chunks/perform-child-compilation.js';
3
4
  import prettyBytes from 'pretty-bytes';
4
5
  import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
5
6
  import crypto from 'node:crypto';
6
- import { r as relativeToOutputPath, p as performChildCompilation } from './chunks/perform-child-compilation.js';
7
-
8
- const toUnix = (p)=>{
9
- return p.replace(/\\/g, "/").replace(/(?<!^)\/+/g, "/");
10
- };
11
7
 
12
8
  const validateInjectManifestOptions = async (input)=>{
13
9
  const result = await (await import('./chunks/schema.js')).injectManifestOptions.spa(input, {
14
- errorMap: validationErrorMap
10
+ error: validationErrorMap
15
11
  });
16
12
  if (!result.success) {
17
13
  throw new SerwistConfigError({
@@ -26,7 +22,7 @@ const getAssetHash = (asset)=>{
26
22
  if (asset.info?.immutable) {
27
23
  return null;
28
24
  }
29
- return crypto.createHash("md5").update(Buffer.from(asset.source.source())).digest("hex");
25
+ return crypto.createHash("md5").update(asset.source.source()).digest("hex");
30
26
  };
31
27
 
32
28
  const resolveWebpackURL = (publicPath, ...paths)=>{
@@ -40,14 +36,16 @@ const resolveWebpackURL = (publicPath, ...paths)=>{
40
36
  };
41
37
 
42
38
  const checkConditions = (asset, compilation, conditions = [])=>{
39
+ const matchPart = compilation.compiler.webpack.ModuleFilenameHelpers.matchPart;
43
40
  for (const condition of conditions){
44
41
  if (typeof condition === "function") {
45
- return condition({
42
+ if (condition({
46
43
  asset,
47
44
  compilation
48
- });
49
- }
50
- if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
45
+ })) {
46
+ return true;
47
+ }
48
+ } else if (matchPart(asset.name, condition)) {
51
49
  return true;
52
50
  }
53
51
  }
@@ -200,7 +198,7 @@ class InjectManifest {
200
198
  }
201
199
  config.exclude.push(({ asset })=>_generatedAssetNames.has(asset.name));
202
200
  const { size, sortedEntries } = await getManifestEntriesFromCompilation(compilation, config);
203
- let manifestString = stringify(sortedEntries);
201
+ let manifestString = JSON.stringify(sortedEntries);
204
202
  if (this.config.compileSrc && !(compilation.options?.devtool === "eval-cheap-source-map" && compilation.options.optimization?.minimize)) {
205
203
  manifestString = manifestString.replace(/"/g, `'`);
206
204
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-asset-hash.d.ts","sourceRoot":"","sources":["../../src/lib/get-asset-hash.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,UAAW,KAAK,KAAG,MAAM,GAAG,IASpD,CAAC"}
1
+ {"version":3,"file":"get-asset-hash.d.ts","sourceRoot":"","sources":["../../src/lib/get-asset-hash.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,KAAK,KAAG,MAAM,GAAG,IASpD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-manifest-entries-from-compilation.d.ts","sourceRoot":"","sources":["../../src/lib/get-manifest-entries-from-compilation.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,EAAgB,WAAW,EAAgB,MAAM,SAAS,CAAC;AAIvE,OAAO,KAAK,EAAyB,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAoKvF,eAAO,MAAM,iCAAiC,gBAC/B,WAAW,UAChB,6BAA6B,KACpC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;CAAE,CAiCtE,CAAC"}
1
+ {"version":3,"file":"get-manifest-entries-from-compilation.d.ts","sourceRoot":"","sources":["../../src/lib/get-manifest-entries-from-compilation.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,KAAK,EAAgB,WAAW,EAAgB,MAAM,SAAS,CAAC;AAIvE,OAAO,KAAK,EAAyB,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAiKvF,eAAO,MAAM,iCAAiC,GAC5C,aAAa,WAAW,EACxB,QAAQ,6BAA6B,KACpC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;CAAE,CAiCtE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-script-files-for-chunks.d.ts","sourceRoot":"","sources":["../../src/lib/get-script-files-for-chunks.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,SAAS,CAAC;AAIzD,eAAO,MAAM,uBAAuB,gBAAiB,WAAW,cAAc,MAAM,EAAE,KAAG,MAAM,EAwB9F,CAAC"}
1
+ {"version":3,"file":"get-script-files-for-chunks.d.ts","sourceRoot":"","sources":["../../src/lib/get-script-files-for-chunks.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,SAAS,CAAC;AAIzD,eAAO,MAAM,uBAAuB,GAAI,aAAa,WAAW,EAAE,YAAY,MAAM,EAAE,KAAG,MAAM,EAwB9F,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-sourcemap-asset-name.d.ts","sourceRoot":"","sources":["../../src/lib/get-sourcemap-asset-name.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,gBAAiB,WAAW,cAAc,MAAM,UAAU,MAAM,KAAG,MAAM,GAAG,SAgB7G,CAAC"}
1
+ {"version":3,"file":"get-sourcemap-asset-name.d.ts","sourceRoot":"","sources":["../../src/lib/get-sourcemap-asset-name.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAa,WAAW,EAAE,YAAY,MAAM,EAAE,QAAQ,MAAM,KAAG,MAAM,GAAG,SAgB7G,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"perform-child-compilation.d.ts","sourceRoot":"","sources":["../../src/lib/perform-child-compilation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,aACxB,QAAQ,eACL,WAAW,QAClB,MAAM,OACP,MAAM,QACL,MAAM,WACH,aAAa,EAAE,GAAG,SAAS,kBAuBrC,CAAC"}
1
+ {"version":3,"file":"perform-child-compilation.d.ts","sourceRoot":"","sources":["../../src/lib/perform-child-compilation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAU,QAAQ,EAClB,aAAa,WAAW,EACxB,MAAM,MAAM,EACZ,KAAK,MAAM,EACX,MAAM,MAAM,EACZ,SAAS,aAAa,EAAE,GAAG,SAAS,kBAuBrC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"relative-to-output-path.d.ts","sourceRoot":"","sources":["../../src/lib/relative-to-output-path.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,gBAAiB,WAAW,gBAAgB,MAAM,KAAG,MAQrF,CAAC"}
1
+ {"version":3,"file":"relative-to-output-path.d.ts","sourceRoot":"","sources":["../../src/lib/relative-to-output-path.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,GAAI,aAAa,WAAW,EAAE,cAAc,MAAM,KAAG,MAQrF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-webpack-url.d.ts","sourceRoot":"","sources":["../../src/lib/resolve-webpack-url.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,YAAY,MAAM,EAAE,KAAG,MAO1E,CAAC"}
1
+ {"version":3,"file":"resolve-webpack-url.d.ts","sourceRoot":"","sources":["../../src/lib/resolve-webpack-url.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,EAAE,GAAG,OAAO,MAAM,EAAE,KAAG,MAO1E,CAAC"}
@@ -1,233 +1,86 @@
1
1
  import { z } from "zod";
2
2
  export declare const webpackPartial: z.ZodObject<{
3
- chunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
4
- exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
5
- excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
6
- include: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
7
- }, "strict", z.ZodTypeAny, {
8
- exclude: (string | RegExp | ((args_0: any) => boolean))[];
9
- chunks?: string[] | undefined;
10
- excludeChunks?: string[] | undefined;
11
- include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
12
- }, {
13
- exclude?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
14
- chunks?: string[] | undefined;
15
- excludeChunks?: string[] | undefined;
16
- include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
17
- }>;
3
+ chunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
4
+ exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
5
+ excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
6
+ include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
7
+ }, z.core.$strict>;
18
8
  export declare const injectPartial: z.ZodObject<{
19
9
  compileSrc: z.ZodDefault<z.ZodBoolean>;
20
10
  swDest: z.ZodOptional<z.ZodString>;
21
- webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
22
- }, "strict", z.ZodTypeAny, {
23
- compileSrc: boolean;
24
- webpackCompilationPlugins?: any[] | undefined;
25
- swDest?: string | undefined;
26
- }, {
27
- compileSrc?: boolean | undefined;
28
- webpackCompilationPlugins?: any[] | undefined;
29
- swDest?: string | undefined;
30
- }>;
31
- export declare const injectManifestOptions: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<z.objectUtil.extendShape<z.objectUtil.extendShape<{
32
- additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
11
+ webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
12
+ }, z.core.$strict>;
13
+ export declare const injectManifestOptions: z.ZodObject<{
14
+ compileSrc: z.ZodDefault<z.ZodBoolean>;
15
+ swDest: z.ZodOptional<z.ZodString>;
16
+ webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
17
+ injectionPoint: z.ZodDefault<z.ZodString>;
18
+ swSrc: z.ZodString;
19
+ chunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
20
+ exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
21
+ excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
23
+ additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
33
24
  integrity: z.ZodOptional<z.ZodString>;
34
25
  revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
35
26
  url: z.ZodString;
36
- }, "strict", z.ZodTypeAny, {
37
- url: string;
38
- integrity?: string | undefined;
39
- revision?: string | null | undefined;
40
- }, {
41
- url: string;
42
- integrity?: string | undefined;
43
- revision?: string | null | undefined;
44
- }>]>, "many">>;
27
+ }, z.core.$strict>]>>>;
45
28
  disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
46
- dontCacheBustURLsMatching: z.ZodOptional<z.ZodType<RegExp, z.ZodTypeDef, RegExp>>;
47
- manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodObject<z.objectUtil.extendShape<{
29
+ dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
30
+ manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
31
+ size: z.ZodNumber;
48
32
  integrity: z.ZodOptional<z.ZodString>;
49
33
  revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
34
  url: z.ZodString;
51
- }, {
35
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
36
+ manifest: z.ZodArray<z.ZodObject<{
37
+ size: z.ZodNumber;
38
+ integrity: z.ZodOptional<z.ZodString>;
39
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
40
+ url: z.ZodString;
41
+ }, z.core.$strip>>;
42
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
43
+ }, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
52
44
  size: z.ZodNumber;
53
- }>, "strip", z.ZodTypeAny, {
54
- url: string;
55
- size: number;
56
- integrity?: string | undefined;
57
- revision?: string | null | undefined;
58
- }, {
59
- url: string;
60
- size: number;
61
- integrity?: string | undefined;
62
- revision?: string | null | undefined;
63
- }>, "many">, z.ZodOptional<z.ZodUnknown>], null>, z.ZodUnion<[z.ZodPromise<z.ZodObject<{
64
- manifest: z.ZodArray<z.ZodObject<z.objectUtil.extendShape<{
45
+ integrity: z.ZodOptional<z.ZodString>;
46
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
47
+ url: z.ZodString;
48
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
49
+ manifest: z.ZodArray<z.ZodObject<{
50
+ size: z.ZodNumber;
65
51
  integrity: z.ZodOptional<z.ZodString>;
66
52
  revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
67
53
  url: z.ZodString;
68
- }, {
54
+ }, z.core.$strip>>;
55
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
+ }, z.core.$strict>>>, z.ZodTransform<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
57
+ size: z.ZodNumber;
58
+ integrity: z.ZodOptional<z.ZodString>;
59
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
60
+ url: z.ZodString;
61
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
62
+ manifest: z.ZodArray<z.ZodObject<{
69
63
  size: z.ZodNumber;
70
- }>, "strip", z.ZodTypeAny, {
71
- url: string;
72
- size: number;
73
- integrity?: string | undefined;
74
- revision?: string | null | undefined;
75
- }, {
76
- url: string;
77
- size: number;
78
- integrity?: string | undefined;
79
- revision?: string | null | undefined;
80
- }>, "many">;
81
- warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
82
- }, "strict", z.ZodTypeAny, {
83
- manifest: {
84
- url: string;
85
- size: number;
86
- integrity?: string | undefined;
87
- revision?: string | null | undefined;
88
- }[];
89
- warnings?: string[] | undefined;
90
- }, {
91
- manifest: {
92
- url: string;
93
- size: number;
94
- integrity?: string | undefined;
95
- revision?: string | null | undefined;
96
- }[];
97
- warnings?: string[] | undefined;
98
- }>>, z.ZodObject<{
99
- manifest: z.ZodArray<z.ZodObject<z.objectUtil.extendShape<{
100
64
  integrity: z.ZodOptional<z.ZodString>;
101
65
  revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
66
  url: z.ZodString;
103
- }, {
67
+ }, z.core.$strip>>;
68
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ }, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
70
+ size: z.ZodNumber;
71
+ integrity: z.ZodOptional<z.ZodString>;
72
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
73
+ url: z.ZodString;
74
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
75
+ manifest: z.ZodArray<z.ZodObject<{
104
76
  size: z.ZodNumber;
105
- }>, "strip", z.ZodTypeAny, {
106
- url: string;
107
- size: number;
108
- integrity?: string | undefined;
109
- revision?: string | null | undefined;
110
- }, {
111
- url: string;
112
- size: number;
113
- integrity?: string | undefined;
114
- revision?: string | null | undefined;
115
- }>, "many">;
116
- warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
117
- }, "strict", z.ZodTypeAny, {
118
- manifest: {
119
- url: string;
120
- size: number;
121
- integrity?: string | undefined;
122
- revision?: string | null | undefined;
123
- }[];
124
- warnings?: string[] | undefined;
125
- }, {
126
- manifest: {
127
- url: string;
128
- size: number;
129
- integrity?: string | undefined;
130
- revision?: string | null | undefined;
131
- }[];
132
- warnings?: string[] | undefined;
133
- }>]>>, "many">>;
77
+ integrity: z.ZodOptional<z.ZodString>;
78
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ url: z.ZodString;
80
+ }, z.core.$strip>>;
81
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
82
+ }, z.core.$strict>>>>>>;
134
83
  maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
135
84
  modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
136
- }, {
137
- chunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
138
- exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
139
- excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
140
- include: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodType<RegExp, z.ZodTypeDef, RegExp>, z.ZodFunction<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>]>, "many">>;
141
- }>, {
142
- injectionPoint: z.ZodDefault<z.ZodString>;
143
- swSrc: z.ZodString;
144
- }>, {
145
- swDest: z.ZodOptional<z.ZodString>;
146
- }>, {
147
- compileSrc: z.ZodDefault<z.ZodBoolean>;
148
- swDest: z.ZodOptional<z.ZodString>;
149
- webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
150
- }>, "strict", z.ZodTypeAny, {
151
- exclude: (string | RegExp | ((args_0: any) => boolean))[];
152
- compileSrc: boolean;
153
- disablePrecacheManifest: boolean;
154
- maximumFileSizeToCacheInBytes: number;
155
- injectionPoint: string;
156
- swSrc: string;
157
- chunks?: string[] | undefined;
158
- excludeChunks?: string[] | undefined;
159
- include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
160
- webpackCompilationPlugins?: any[] | undefined;
161
- additionalPrecacheEntries?: (string | {
162
- url: string;
163
- integrity?: string | undefined;
164
- revision?: string | null | undefined;
165
- })[] | undefined;
166
- dontCacheBustURLsMatching?: RegExp | undefined;
167
- manifestTransforms?: ((args_0: {
168
- url: string;
169
- size: number;
170
- integrity?: string | undefined;
171
- revision?: string | null | undefined;
172
- }[], args_1: unknown) => {
173
- manifest: {
174
- url: string;
175
- size: number;
176
- integrity?: string | undefined;
177
- revision?: string | null | undefined;
178
- }[];
179
- warnings?: string[] | undefined;
180
- } | Promise<{
181
- manifest: {
182
- url: string;
183
- size: number;
184
- integrity?: string | undefined;
185
- revision?: string | null | undefined;
186
- }[];
187
- warnings?: string[] | undefined;
188
- }>)[] | undefined;
189
- modifyURLPrefix?: Record<string, string> | undefined;
190
- swDest?: string | undefined;
191
- }, {
192
- swSrc: string;
193
- exclude?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
194
- chunks?: string[] | undefined;
195
- excludeChunks?: string[] | undefined;
196
- include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
197
- compileSrc?: boolean | undefined;
198
- webpackCompilationPlugins?: any[] | undefined;
199
- additionalPrecacheEntries?: (string | {
200
- url: string;
201
- integrity?: string | undefined;
202
- revision?: string | null | undefined;
203
- })[] | undefined;
204
- disablePrecacheManifest?: boolean | undefined;
205
- dontCacheBustURLsMatching?: RegExp | undefined;
206
- manifestTransforms?: ((args_0: {
207
- url: string;
208
- size: number;
209
- integrity?: string | undefined;
210
- revision?: string | null | undefined;
211
- }[], args_1: unknown) => {
212
- manifest: {
213
- url: string;
214
- size: number;
215
- integrity?: string | undefined;
216
- revision?: string | null | undefined;
217
- }[];
218
- warnings?: string[] | undefined;
219
- } | Promise<{
220
- manifest: {
221
- url: string;
222
- size: number;
223
- integrity?: string | undefined;
224
- revision?: string | null | undefined;
225
- }[];
226
- warnings?: string[] | undefined;
227
- }>)[] | undefined;
228
- maximumFileSizeToCacheInBytes?: number | undefined;
229
- modifyURLPrefix?: Record<string, string> | undefined;
230
- injectionPoint?: string | undefined;
231
- swDest?: string | undefined;
232
- }>;
85
+ }, z.core.$strict>;
233
86
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,cAAc;;;;;kBAKzB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;kBAIxB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAMhC,CAAC"}
@@ -1,6 +1,11 @@
1
1
  import type { BasePartial, BaseResolved, InjectPartial as BaseInjectPartial, InjectResolved as BaseInjectResolved, OptionalSwDestPartial, OptionalSwDestResolved } from "@serwist/build";
2
2
  import type { Require } from "@serwist/utils";
3
- import type { WebpackPluginFunction, WebpackPluginInstance } from "webpack";
3
+ import type { WebpackPluginFunction, WebpackPluginInstance, Asset, Compilation } from "webpack";
4
+ export interface ConditionCallbackOptions {
5
+ asset: Asset;
6
+ compilation: Compilation;
7
+ }
8
+ export type ConditionCallback = (options: ConditionCallbackOptions) => boolean;
4
9
  export interface WebpackPartial {
5
10
  /**
6
11
  * One or more chunk names whose corresponding output files should be included
@@ -17,7 +22,7 @@ export interface WebpackPartial {
17
22
  * [/\.map$/, /^manifest.*\.js$/]
18
23
  * ```
19
24
  */
20
- exclude?: (string | RegExp | ((arg0: any) => boolean))[];
25
+ exclude?: (string | RegExp | ConditionCallback)[];
21
26
  /**
22
27
  * One or more chunk names whose corresponding output files should be excluded
23
28
  * from the precache manifest.
@@ -29,7 +34,7 @@ export interface WebpackPartial {
29
34
  * [the same rules](https://webpack.js.org/configuration/module/#condition)
30
35
  * as webpack's standard `include` option.
31
36
  */
32
- include?: (string | RegExp | ((arg0: any) => boolean))[];
37
+ include?: (string | RegExp | ConditionCallback)[];
33
38
  }
34
39
  export type WebpackResolved = Require<WebpackPartial, "exclude">;
35
40
  export interface InjectPartial {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,aAAa,IAAI,iBAAiB,EAClC,cAAc,IAAI,kBAAkB,EACpC,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC;IACzD;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC;CAC1D;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAEjE,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAIrB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7C;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;AAElE,MAAM,WAAW,qBAAsB,SAAQ,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,aAAa;CAAG;AAEtI,MAAM,WAAW,6BAA8B,SAAQ,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,cAAc;CAAG;AAEnJ,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,qBAAqB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,aAAa,IAAI,iBAAiB,EAClC,cAAc,IAAI,kBAAkB,EACpC,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEhG,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,wBAAwB,KAAK,OAAO,CAAC;AAE/E,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAC,EAAE,CAAC;IAClD;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAAC,EAAE,CAAC;CACnD;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AAEjE,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAIrB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7C;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;AAElE,MAAM,WAAW,qBAAsB,SAAQ,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,aAAa;CAAG;AAEtI,MAAM,WAAW,6BAA8B,SAAQ,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,cAAc;CAAG;AAEnJ,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,6BAA6B,UAAiB,OAAO,KAAG,OAAO,CAAC,6BAA6B,CAMzG,CAAC"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/lib/validator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,6BAA6B,GAAU,OAAO,OAAO,KAAG,OAAO,CAAC,6BAA6B,CAMzG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/webpack-plugin",
3
- "version": "9.1.0-preview.0",
3
+ "version": "9.1.0",
4
4
  "type": "module",
5
5
  "description": "A plugin for your webpack build process, helping you generate a manifest of local files that should be precached.",
6
6
  "files": [
@@ -59,17 +59,17 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "pretty-bytes": "6.1.1",
62
- "zod": "3.23.8",
63
- "@serwist/build": "9.1.0-preview.0"
62
+ "zod": "4.0.5",
63
+ "@serwist/build": "9.1.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@types/node": "22.8.6",
66
+ "@types/node": "24.0.14",
67
67
  "@types/webpack": "5.28.5",
68
- "rollup": "4.24.3",
69
- "typescript": "5.6.3",
70
- "webpack": "5.96.1",
71
- "@serwist/configs": "9.1.0-preview.0",
72
- "@serwist/utils": "9.1.0-preview.0"
68
+ "rollup": "4.45.1",
69
+ "typescript": "5.8.3",
70
+ "webpack": "5.100.2",
71
+ "@serwist/configs": "9.1.0",
72
+ "@serwist/utils": "9.1.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "typescript": ">=5.0.0",
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { escapeRegExp, replaceAndUpdateSourceMap, stringify } from "@serwist/build";
2
+ import { escapeRegExp, replaceAndUpdateSourceMap } from "@serwist/build";
3
3
  import { toUnix } from "@serwist/utils";
4
4
  import prettyBytes from "pretty-bytes";
5
5
  import type { Compilation, Compiler, WebpackError, default as Webpack } from "webpack";
@@ -101,7 +101,7 @@ export class InjectManifest {
101
101
 
102
102
  const { size, sortedEntries } = await getManifestEntriesFromCompilation(compilation, config);
103
103
 
104
- let manifestString = stringify(sortedEntries);
104
+ let manifestString = JSON.stringify(sortedEntries);
105
105
  if (
106
106
  this.config.compileSrc &&
107
107
  // See https://github.com/GoogleChrome/workbox/issues/2729
@@ -23,5 +23,5 @@ export const getAssetHash = (asset: Asset): string | null => {
23
23
  return null;
24
24
  }
25
25
 
26
- return crypto.createHash("md5").update(Buffer.from(asset.source.source())).digest("hex");
26
+ return crypto.createHash("md5").update(asset.source.source()).digest("hex");
27
27
  };
@@ -25,18 +25,15 @@ import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./typ
25
25
  * @returns Whether or not at least one condition matches.
26
26
  * @private
27
27
  */
28
- const checkConditions = (
29
- asset: Asset,
30
- compilation: Compilation,
28
+ const checkConditions = (asset: Asset, compilation: Compilation, conditions: Array<string | RegExp | ((arg0: any) => boolean)> = []): boolean => {
29
+ const matchPart = compilation.compiler.webpack.ModuleFilenameHelpers.matchPart;
31
30
 
32
- conditions: Array<string | RegExp | ((arg0: any) => boolean)> = [],
33
- ): boolean => {
34
31
  for (const condition of conditions) {
35
32
  if (typeof condition === "function") {
36
- return condition({ asset, compilation });
37
- //return compilation !== null;
38
- }
39
- if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
33
+ if (condition({ asset, compilation })) {
34
+ return true;
35
+ }
36
+ } else if (matchPart(asset.name, condition)) {
40
37
  return true;
41
38
  }
42
39
  }
@@ -5,6 +5,7 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
+ import { toUnix } from "@serwist/utils";
8
9
  import path from "node:path";
9
10
  import type { Compilation } from "webpack";
10
11
 
@@ -20,7 +21,7 @@ import type { Compilation } from "webpack";
20
21
  export const relativeToOutputPath = (compilation: Compilation, originalPath: string): string => {
21
22
  // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
22
23
  if (path.resolve(originalPath) === path.normalize(originalPath)) {
23
- return path.relative(compilation.options.output.path!, originalPath);
24
+ return toUnix(path.relative(compilation.options.output.path!, originalPath));
24
25
  }
25
26
 
26
27
  // Otherwise, return swDest as-is.
package/src/lib/schema.ts CHANGED
@@ -1,28 +1,30 @@
1
- import { basePartial, injectPartial as baseInjectPartial, optionalSwDestPartial } from "@serwist/build/schema";
1
+ import { fn, basePartial, injectPartial as baseInjectPartial, optionalSwDestPartial } from "@serwist/build/schema";
2
2
  import { z } from "zod";
3
3
 
4
- export const webpackPartial = z
5
- .object({
6
- chunks: z.array(z.string()).optional(),
7
- exclude: z
8
- .array(z.union([z.string(), z.instanceof(RegExp), z.function(z.tuple([z.any()]), z.boolean())]))
9
- .default([/\.map$/, /^manifest.*\.js$/]),
10
- excludeChunks: z.array(z.string()).optional(),
11
- include: z.array(z.union([z.string(), z.instanceof(RegExp), z.function(z.tuple([z.any()]), z.boolean())])).optional(),
12
- })
13
- .strict("Do not pass invalid properties to WebpackPartial!");
4
+ const webpackConditionCallback = fn({
5
+ input: [z.any()],
6
+ output: z.boolean(),
7
+ });
14
8
 
15
- export const injectPartial = z
16
- .object({
17
- compileSrc: z.boolean().default(true),
18
- swDest: z.string().optional(),
19
- webpackCompilationPlugins: z.array(z.any()).optional(),
20
- })
21
- .strict("Do not pass invalid properties to WebpackInjectManifestPartial!");
9
+ const webpackCondition = z.union([z.string(), z.instanceof(RegExp), webpackConditionCallback]);
22
10
 
23
- export const injectManifestOptions = basePartial
24
- .merge(webpackPartial)
25
- .merge(baseInjectPartial)
26
- .merge(optionalSwDestPartial)
27
- .merge(injectPartial)
28
- .strict("Do not pass invalid properties to WebpackInjectManifestOptions!");
11
+ export const webpackPartial = z.strictObject({
12
+ chunks: z.array(z.string()).optional(),
13
+ exclude: z.array(webpackCondition).default([/\.map$/, /^manifest.*\.js$/]),
14
+ excludeChunks: z.array(z.string()).optional(),
15
+ include: z.array(webpackCondition).optional(),
16
+ });
17
+
18
+ export const injectPartial = z.strictObject({
19
+ compileSrc: z.boolean().default(true),
20
+ swDest: z.string().optional(),
21
+ webpackCompilationPlugins: z.array(z.any()).optional(),
22
+ });
23
+
24
+ export const injectManifestOptions = z.strictObject({
25
+ ...basePartial.shape,
26
+ ...webpackPartial.shape,
27
+ ...baseInjectPartial.shape,
28
+ ...optionalSwDestPartial.shape,
29
+ ...injectPartial.shape,
30
+ });
package/src/lib/types.ts CHANGED
@@ -7,7 +7,14 @@ import type {
7
7
  OptionalSwDestResolved,
8
8
  } from "@serwist/build";
9
9
  import type { Require } from "@serwist/utils";
10
- import type { WebpackPluginFunction, WebpackPluginInstance } from "webpack";
10
+ import type { WebpackPluginFunction, WebpackPluginInstance, Asset, Compilation } from "webpack";
11
+
12
+ export interface ConditionCallbackOptions {
13
+ asset: Asset;
14
+ compilation: Compilation;
15
+ }
16
+
17
+ export type ConditionCallback = (options: ConditionCallbackOptions) => boolean;
11
18
 
12
19
  export interface WebpackPartial {
13
20
  /**
@@ -25,7 +32,7 @@ export interface WebpackPartial {
25
32
  * [/\.map$/, /^manifest.*\.js$/]
26
33
  * ```
27
34
  */
28
- exclude?: (string | RegExp | ((arg0: any) => boolean))[];
35
+ exclude?: (string | RegExp | ConditionCallback)[];
29
36
  /**
30
37
  * One or more chunk names whose corresponding output files should be excluded
31
38
  * from the precache manifest.
@@ -37,7 +44,7 @@ export interface WebpackPartial {
37
44
  * [the same rules](https://webpack.js.org/configuration/module/#condition)
38
45
  * as webpack's standard `include` option.
39
46
  */
40
- include?: (string | RegExp | ((arg0: any) => boolean))[];
47
+ include?: (string | RegExp | ConditionCallback)[];
41
48
  }
42
49
 
43
50
  export type WebpackResolved = Require<WebpackPartial, "exclude">;
@@ -2,7 +2,7 @@ import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
2
2
  import type { InjectManifestOptionsComplete } from "./types.js";
3
3
 
4
4
  export const validateInjectManifestOptions = async (input: unknown): Promise<InjectManifestOptionsComplete> => {
5
- const result = await (await import("./schema.js")).injectManifestOptions.spa(input, { errorMap: validationErrorMap });
5
+ const result = await (await import("./schema.js")).injectManifestOptions.spa(input, { error: validationErrorMap });
6
6
  if (!result.success) {
7
7
  throw new SerwistConfigError({ moduleName: "@serwist/webpack-plugin", message: JSON.stringify(result.error.format(), null, 2) });
8
8
  }