@serwist/webpack-plugin 10.0.0-preview.1 → 10.0.0-preview.11
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/{perform-child-compilation.js → relative-to-output-path.js} +8 -7
- package/dist/chunks/schema.js +32 -21
- package/dist/index.internal.js +2 -1
- package/dist/index.js +22 -20
- package/dist/inject-manifest.d.ts.map +1 -1
- package/dist/lib/get-asset-hash.d.ts.map +1 -1
- package/dist/lib/get-manifest-entries-from-compilation.d.ts.map +1 -1
- package/dist/lib/get-script-files-for-chunks.d.ts.map +1 -1
- package/dist/lib/get-sourcemap-asset-name.d.ts.map +1 -1
- package/dist/lib/perform-child-compilation.d.ts.map +1 -1
- package/dist/lib/relative-to-output-path.d.ts.map +1 -1
- package/dist/lib/resolve-webpack-url.d.ts.map +1 -1
- package/dist/lib/schema.d.ts +21 -224
- package/dist/lib/schema.d.ts.map +1 -1
- package/dist/lib/types.d.ts +12 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/validator.d.ts.map +1 -1
- package/package.json +13 -11
- package/src/inject-manifest.ts +4 -4
- package/src/lib/child-compilation-plugin.ts +1 -1
- package/src/lib/get-asset-hash.ts +1 -1
- package/src/lib/get-manifest-entries-from-compilation.ts +8 -10
- package/src/lib/relative-to-output-path.ts +3 -1
- package/src/lib/schema.ts +41 -24
- package/src/lib/types.ts +15 -9
- package/src/lib/validator.ts +1 -1
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
const relativeToOutputPath = (compilation, originalPath)=>{
|
|
4
|
-
if (path.resolve(originalPath) === path.normalize(originalPath)) {
|
|
5
|
-
return path.relative(compilation.options.output.path, originalPath);
|
|
6
|
-
}
|
|
7
|
-
return originalPath;
|
|
8
|
-
};
|
|
2
|
+
import { toUnix } from '@serwist/utils';
|
|
9
3
|
|
|
10
4
|
const performChildCompilation = async (compiler, compilation, name, src, dest, plugins)=>{
|
|
11
5
|
const childCompiler = compilation.createChildCompiler(name, {
|
|
@@ -30,4 +24,11 @@ const performChildCompilation = async (compiler, compilation, name, src, dest, p
|
|
|
30
24
|
});
|
|
31
25
|
};
|
|
32
26
|
|
|
27
|
+
const relativeToOutputPath = (compilation, originalPath)=>{
|
|
28
|
+
if (path.resolve(originalPath) === path.normalize(originalPath)) {
|
|
29
|
+
return toUnix(path.relative(compilation.options.output.path, originalPath));
|
|
30
|
+
}
|
|
31
|
+
return originalPath;
|
|
32
|
+
};
|
|
33
|
+
|
|
33
34
|
export { performChildCompilation as p, relativeToOutputPath as r };
|
package/dist/chunks/schema.js
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fn, optionalSwDestPartial, injectPartial as injectPartial$1, basePartial, assertType } from '@serwist/build/schema';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
const
|
|
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(
|
|
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(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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({
|
|
25
|
+
...optionalSwDestPartial.shape,
|
|
26
26
|
compileSrc: z.boolean().default(true),
|
|
27
|
-
swDest: z.string().optional(),
|
|
28
27
|
webpackCompilationPlugins: z.array(z.any()).optional()
|
|
29
|
-
})
|
|
30
|
-
const injectManifestOptions =
|
|
28
|
+
});
|
|
29
|
+
const injectManifestOptions = z.strictObject({
|
|
30
|
+
...basePartial.shape,
|
|
31
|
+
...webpackPartial.shape,
|
|
32
|
+
...injectPartial$1.shape,
|
|
33
|
+
...optionalSwDestPartial.shape,
|
|
34
|
+
...injectPartial.shape
|
|
35
|
+
});
|
|
36
|
+
assertType();
|
|
37
|
+
assertType();
|
|
38
|
+
assertType();
|
|
39
|
+
assertType();
|
|
40
|
+
assertType();
|
|
41
|
+
assertType();
|
|
31
42
|
|
|
32
43
|
export { injectManifestOptions, injectPartial, webpackPartial };
|
package/dist/index.internal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { p as performChildCompilation, r as relativeToOutputPath } from './chunks/
|
|
1
|
+
import { p as performChildCompilation, r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
|
|
2
2
|
import 'node:path';
|
|
3
|
+
import '@serwist/utils';
|
|
3
4
|
|
|
4
5
|
class ChildCompilationPlugin {
|
|
5
6
|
src;
|
package/dist/index.js
CHANGED
|
@@ -2,28 +2,15 @@ import path from 'node:path';
|
|
|
2
2
|
import { transformManifest, getSourceMapURL, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build';
|
|
3
3
|
import { toUnix } from '@serwist/utils';
|
|
4
4
|
import prettyBytes from 'pretty-bytes';
|
|
5
|
-
import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
|
|
6
5
|
import crypto from 'node:crypto';
|
|
7
|
-
import { r as relativeToOutputPath, p as performChildCompilation } from './chunks/
|
|
8
|
-
|
|
9
|
-
const validateInjectManifestOptions = async (input)=>{
|
|
10
|
-
const result = await (await import('./chunks/schema.js')).injectManifestOptions.spa(input, {
|
|
11
|
-
errorMap: validationErrorMap
|
|
12
|
-
});
|
|
13
|
-
if (!result.success) {
|
|
14
|
-
throw new SerwistConfigError({
|
|
15
|
-
moduleName: "@serwist/webpack-plugin",
|
|
16
|
-
message: JSON.stringify(result.error.format(), null, 2)
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
return result.data;
|
|
20
|
-
};
|
|
6
|
+
import { r as relativeToOutputPath, p as performChildCompilation } from './chunks/relative-to-output-path.js';
|
|
7
|
+
import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
|
|
21
8
|
|
|
22
9
|
const getAssetHash = (asset)=>{
|
|
23
10
|
if (asset.info?.immutable) {
|
|
24
11
|
return null;
|
|
25
12
|
}
|
|
26
|
-
return crypto.createHash("md5").update(
|
|
13
|
+
return crypto.createHash("md5").update(asset.source.source()).digest("hex");
|
|
27
14
|
};
|
|
28
15
|
|
|
29
16
|
const resolveWebpackURL = (publicPath, ...paths)=>{
|
|
@@ -37,14 +24,16 @@ const resolveWebpackURL = (publicPath, ...paths)=>{
|
|
|
37
24
|
};
|
|
38
25
|
|
|
39
26
|
const checkConditions = (asset, compilation, conditions = [])=>{
|
|
27
|
+
const matchPart = compilation.compiler.webpack.ModuleFilenameHelpers.matchPart;
|
|
40
28
|
for (const condition of conditions){
|
|
41
29
|
if (typeof condition === "function") {
|
|
42
|
-
|
|
30
|
+
if (condition({
|
|
43
31
|
asset,
|
|
44
32
|
compilation
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
})) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
} else if (matchPart(asset.name, condition)) {
|
|
48
37
|
return true;
|
|
49
38
|
}
|
|
50
39
|
}
|
|
@@ -161,6 +150,19 @@ const getSourcemapAssetName = (compilation, swContents, swDest)=>{
|
|
|
161
150
|
return undefined;
|
|
162
151
|
};
|
|
163
152
|
|
|
153
|
+
const validateInjectManifestOptions = async (input)=>{
|
|
154
|
+
const result = await (await import('./chunks/schema.js')).injectManifestOptions.spa(input, {
|
|
155
|
+
error: validationErrorMap
|
|
156
|
+
});
|
|
157
|
+
if (!result.success) {
|
|
158
|
+
throw new SerwistConfigError({
|
|
159
|
+
moduleName: "@serwist/webpack-plugin",
|
|
160
|
+
message: JSON.stringify(result.error.format(), null, 2)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return result.data;
|
|
164
|
+
};
|
|
165
|
+
|
|
164
166
|
const _generatedAssetNames = new Set();
|
|
165
167
|
class InjectManifest {
|
|
166
168
|
config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,QAAQ,EAAoC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAe,QAAQ,EAAoC,MAAM,SAAS,CAAC;AAKvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAO3F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAc;IACzB,SAAS,CAAC,MAAM,EAAE,6BAA6B,CAAC;IAChD,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,OAAO,CAAiB;IAEhC;;OAEG;gBACS,MAAM,EAAE,qBAAqB;IAQzC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAa9B;;;;OAIG;YACW,kBAAkB;IAuChC;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IA6B/B;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAKtB;;;;;OAKG;YACW,UAAU;IAwBxB;;;;OAIG;YACW,SAAS;CAiDxB"}
|
|
@@ -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,
|
|
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,
|
|
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;AAGpD,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,
|
|
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,
|
|
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,
|
|
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":"
|
|
1
|
+
{"version":3,"file":"relative-to-output-path.d.ts","sourceRoot":"","sources":["../../src/lib/relative-to-output-path.ts"],"names":[],"mappings":"AAUA,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,
|
|
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"}
|
package/dist/lib/schema.d.ts
CHANGED
|
@@ -1,233 +1,30 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const webpackPartial: z.ZodObject<{
|
|
3
|
-
chunks: z.ZodOptional<z.ZodArray<z.ZodString
|
|
4
|
-
exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodString, z.
|
|
5
|
-
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString
|
|
6
|
-
include: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.
|
|
7
|
-
},
|
|
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.ZodType<(args_0: any) => boolean, (args_0: any) => boolean, z.core.$ZodTypeInternals<(args_0: any) => boolean, (args_0: any) => boolean>>]>>>;
|
|
5
|
+
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
6
|
+
include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodType<(args_0: any) => boolean, (args_0: any) => boolean, z.core.$ZodTypeInternals<(args_0: any) => boolean, (args_0: any) => boolean>>]>>>;
|
|
7
|
+
}, z.core.$strict>;
|
|
18
8
|
export declare const injectPartial: z.ZodObject<{
|
|
19
9
|
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
20
11
|
swDest: z.ZodOptional<z.ZodString>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
compileSrc:
|
|
24
|
-
webpackCompilationPlugins
|
|
25
|
-
swDest
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.
|
|
33
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
34
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
35
|
-
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">>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
export declare const injectManifestOptions: z.ZodObject<{
|
|
14
|
+
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
15
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
16
|
+
swDest: z.ZodOptional<z.ZodString>;
|
|
17
|
+
injectionPoint: z.ZodPrefault<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.ZodType<(args_0: any) => boolean, (args_0: any) => boolean, z.core.$ZodTypeInternals<(args_0: any) => boolean, (args_0: any) => boolean>>]>>>;
|
|
21
|
+
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
|
+
include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodType<(args_0: any) => boolean, (args_0: any) => boolean, z.core.$ZodTypeInternals<(args_0: any) => boolean, (args_0: any) => boolean>>]>>>;
|
|
23
|
+
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodType<import("@serwist/build").ManifestEntry, import("@serwist/build").ManifestEntry, z.core.$ZodTypeInternals<import("@serwist/build").ManifestEntry, import("@serwist/build").ManifestEntry>>]>>>;
|
|
45
24
|
disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
|
|
46
|
-
dontCacheBustURLsMatching: z.ZodOptional<z.
|
|
47
|
-
manifestTransforms: z.ZodOptional<z.ZodArray<z.
|
|
48
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
49
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
-
url: z.ZodString;
|
|
51
|
-
}, {
|
|
52
|
-
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<{
|
|
65
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
66
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
-
url: z.ZodString;
|
|
68
|
-
}, {
|
|
69
|
-
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
|
-
integrity: z.ZodOptional<z.ZodString>;
|
|
101
|
-
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
102
|
-
url: z.ZodString;
|
|
103
|
-
}, {
|
|
104
|
-
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">>;
|
|
25
|
+
dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
|
|
26
|
+
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodType<import("@serwist/build").ManifestTransform, import("@serwist/build").ManifestTransform, z.core.$ZodTypeInternals<import("@serwist/build").ManifestTransform, import("@serwist/build").ManifestTransform>>>>;
|
|
134
27
|
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
135
28
|
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
|
-
disablePrecacheManifest?: boolean | undefined;
|
|
200
|
-
maximumFileSizeToCacheInBytes?: number | undefined;
|
|
201
|
-
injectionPoint?: string | undefined;
|
|
202
|
-
additionalPrecacheEntries?: (string | {
|
|
203
|
-
url: string;
|
|
204
|
-
integrity?: string | undefined;
|
|
205
|
-
revision?: string | null | undefined;
|
|
206
|
-
})[] | undefined;
|
|
207
|
-
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
208
|
-
manifestTransforms?: ((args_0: {
|
|
209
|
-
url: string;
|
|
210
|
-
size: number;
|
|
211
|
-
integrity?: string | undefined;
|
|
212
|
-
revision?: string | null | undefined;
|
|
213
|
-
}[], args_1: unknown) => {
|
|
214
|
-
manifest: {
|
|
215
|
-
url: string;
|
|
216
|
-
size: number;
|
|
217
|
-
integrity?: string | undefined;
|
|
218
|
-
revision?: string | null | undefined;
|
|
219
|
-
}[];
|
|
220
|
-
warnings?: string[] | undefined;
|
|
221
|
-
} | Promise<{
|
|
222
|
-
manifest: {
|
|
223
|
-
url: string;
|
|
224
|
-
size: number;
|
|
225
|
-
integrity?: string | undefined;
|
|
226
|
-
revision?: string | null | undefined;
|
|
227
|
-
}[];
|
|
228
|
-
warnings?: string[] | undefined;
|
|
229
|
-
}>)[] | undefined;
|
|
230
|
-
modifyURLPrefix?: Record<string, string> | undefined;
|
|
231
|
-
swDest?: string | undefined;
|
|
232
|
-
}>;
|
|
29
|
+
}, z.core.$strict>;
|
|
233
30
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/lib/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBxB,eAAO,MAAM,cAAc;;;;;kBAKzB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;kBAIxB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;kBAMhC,CAAC"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InjectPartial as BaseInjectPartial, InjectResolved as BaseInjectResolved, BasePartial, BaseResolved, OptionalSwDestPartial } from "@serwist/build";
|
|
2
2
|
import type { Prettify, Require } from "@serwist/utils";
|
|
3
|
-
import type { WebpackPluginFunction, WebpackPluginInstance } from "webpack";
|
|
3
|
+
import type { Asset, Compilation, WebpackPluginFunction, WebpackPluginInstance } 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 |
|
|
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,10 +34,10 @@ 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 |
|
|
37
|
+
include?: (string | RegExp | ConditionCallback)[];
|
|
33
38
|
}
|
|
34
39
|
export type WebpackResolved = Prettify<Require<WebpackPartial, "exclude">>;
|
|
35
|
-
export interface InjectPartial {
|
|
40
|
+
export interface InjectPartial extends OptionalSwDestPartial {
|
|
36
41
|
/**
|
|
37
42
|
* When `true` (the default), the `swSrc` file will be compiled by webpack.
|
|
38
43
|
* When `false`, compilation will not occur (and `webpackCompilationPlugins`
|
|
@@ -48,7 +53,7 @@ export interface InjectPartial {
|
|
|
48
53
|
webpackCompilationPlugins?: WebpackPlugin[];
|
|
49
54
|
}
|
|
50
55
|
export type InjectResolved = Prettify<Require<InjectPartial, "compileSrc">>;
|
|
51
|
-
export type InjectManifestOptions = Prettify<BasePartial & WebpackPartial & BaseInjectPartial &
|
|
52
|
-
export type InjectManifestOptionsComplete = Prettify<BaseResolved & WebpackResolved & BaseInjectResolved &
|
|
56
|
+
export type InjectManifestOptions = Prettify<BasePartial & WebpackPartial & BaseInjectPartial & InjectPartial>;
|
|
57
|
+
export type InjectManifestOptionsComplete = Prettify<BaseResolved & WebpackResolved & BaseInjectResolved & InjectResolved>;
|
|
53
58
|
export type WebpackPlugin = WebpackPluginFunction | WebpackPluginInstance;
|
|
54
59
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,IAAI,iBAAiB,EAClC,cAAc,IAAI,kBAAkB,EACpC,WAAW,EACX,YAAY,EACZ,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,qBAAqB,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,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3E,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAIrB;;;OAGG;IACH,yBAAyB,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7C;AAED,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC;AAE5E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC,WAAW,GAAG,cAAc,GAAG,iBAAiB,GAAG,aAAa,CAAC,CAAC;AAE/G,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC,YAAY,GAAG,eAAe,GAAG,kBAAkB,GAAG,cAAc,CAAC,CAAC;AAE3H,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,
|
|
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,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/webpack-plugin",
|
|
3
|
-
"version": "10.0.0-preview.
|
|
3
|
+
"version": "10.0.0-preview.11",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
5
6
|
"description": "A plugin for your webpack build process, helping you generate a manifest of local files that should be precached.",
|
|
6
7
|
"files": [
|
|
7
8
|
"src",
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"file manifest"
|
|
21
22
|
],
|
|
22
23
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
24
|
+
"node": ">=20.0.0"
|
|
24
25
|
},
|
|
25
26
|
"author": "Google's Web DevRel Team",
|
|
26
27
|
"contributors": [
|
|
@@ -58,18 +59,18 @@
|
|
|
58
59
|
"./package.json": "./package.json"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"pretty-bytes": "
|
|
62
|
-
"zod": "
|
|
63
|
-
"@serwist/build": "10.0.0-preview.
|
|
64
|
-
"@serwist/utils": "10.0.0-preview.
|
|
62
|
+
"pretty-bytes": "7.0.0",
|
|
63
|
+
"zod": "4.0.5",
|
|
64
|
+
"@serwist/build": "10.0.0-preview.11",
|
|
65
|
+
"@serwist/utils": "10.0.0-preview.11"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
|
-
"@types/node": "
|
|
68
|
+
"@types/node": "24.0.14",
|
|
68
69
|
"@types/webpack": "5.28.5",
|
|
69
|
-
"rollup": "4.
|
|
70
|
-
"typescript": "5.
|
|
71
|
-
"webpack": "5.
|
|
72
|
-
"@serwist/configs": "10.0.0-preview.
|
|
70
|
+
"rollup": "4.45.1",
|
|
71
|
+
"typescript": "5.8.3",
|
|
72
|
+
"webpack": "5.100.2",
|
|
73
|
+
"@serwist/configs": "10.0.0-preview.11"
|
|
73
74
|
},
|
|
74
75
|
"peerDependencies": {
|
|
75
76
|
"typescript": ">=5.0.0",
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
"build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",
|
|
88
89
|
"dev": "rollup --config rollup.config.js --watch",
|
|
89
90
|
"lint": "biome lint ./src",
|
|
91
|
+
"qcheck": "biome check ./src",
|
|
90
92
|
"typecheck": "tsc"
|
|
91
93
|
}
|
|
92
94
|
}
|
package/src/inject-manifest.ts
CHANGED
|
@@ -2,13 +2,13 @@ import path from "node:path";
|
|
|
2
2
|
import { escapeRegExp, replaceAndUpdateSourceMap } from "@serwist/build";
|
|
3
3
|
import { toUnix } from "@serwist/utils";
|
|
4
4
|
import prettyBytes from "pretty-bytes";
|
|
5
|
-
import type { Compilation, Compiler,
|
|
6
|
-
import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
|
|
7
|
-
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
5
|
+
import type { Compilation, Compiler, default as Webpack, WebpackError } from "webpack";
|
|
8
6
|
import { getManifestEntriesFromCompilation } from "./lib/get-manifest-entries-from-compilation.js";
|
|
9
7
|
import { getSourcemapAssetName } from "./lib/get-sourcemap-asset-name.js";
|
|
10
|
-
import { relativeToOutputPath } from "./lib/relative-to-output-path.js";
|
|
11
8
|
import { performChildCompilation } from "./lib/perform-child-compilation.js";
|
|
9
|
+
import { relativeToOutputPath } from "./lib/relative-to-output-path.js";
|
|
10
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
|
|
11
|
+
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
12
12
|
|
|
13
13
|
// Used to keep track of swDest files written by *any* instance of this plugin.
|
|
14
14
|
// See https://github.com/GoogleChrome/workbox/issues/2181
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Compiler, WebpackError, WebpackPluginInstance } from "webpack";
|
|
2
2
|
|
|
3
|
-
import { relativeToOutputPath } from "./relative-to-output-path.js";
|
|
4
3
|
import { performChildCompilation } from "./perform-child-compilation.js";
|
|
4
|
+
import { relativeToOutputPath } from "./relative-to-output-path.js";
|
|
5
5
|
|
|
6
6
|
export interface ChildCompilationPluginOptions {
|
|
7
7
|
src: string;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { ManifestEntry } from "@serwist/build";
|
|
10
10
|
import { transformManifest } from "@serwist/build";
|
|
11
|
+
import type { FileDetails } from "@serwist/utils";
|
|
11
12
|
import type { Asset, Chunk, Compilation, WebpackError } from "webpack";
|
|
12
13
|
|
|
13
14
|
import { getAssetHash } from "./get-asset-hash.js";
|
|
@@ -25,18 +26,15 @@ import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./typ
|
|
|
25
26
|
* @returns Whether or not at least one condition matches.
|
|
26
27
|
* @private
|
|
27
28
|
*/
|
|
28
|
-
const checkConditions = (
|
|
29
|
-
|
|
30
|
-
compilation: Compilation,
|
|
29
|
+
const checkConditions = (asset: Asset, compilation: Compilation, conditions: Array<string | RegExp | ((arg0: any) => boolean)> = []): boolean => {
|
|
30
|
+
const matchPart = compilation.compiler.webpack.ModuleFilenameHelpers.matchPart;
|
|
31
31
|
|
|
32
|
-
conditions: Array<string | RegExp | ((arg0: any) => boolean)> = [],
|
|
33
|
-
): boolean => {
|
|
34
32
|
for (const condition of conditions) {
|
|
35
33
|
if (typeof condition === "function") {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (
|
|
34
|
+
if (condition({ asset, compilation })) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
} else if (matchPart(asset.name, condition)) {
|
|
40
38
|
return true;
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -5,7 +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
|
+
|
|
8
9
|
import path from "node:path";
|
|
10
|
+
import { toUnix } from "@serwist/utils";
|
|
9
11
|
import type { Compilation } from "webpack";
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -20,7 +22,7 @@ import type { Compilation } from "webpack";
|
|
|
20
22
|
export const relativeToOutputPath = (compilation: Compilation, originalPath: string): string => {
|
|
21
23
|
// See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
|
|
22
24
|
if (path.resolve(originalPath) === path.normalize(originalPath)) {
|
|
23
|
-
return path.relative(compilation.options.output.path!, originalPath);
|
|
25
|
+
return toUnix(path.relative(compilation.options.output.path!, originalPath));
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
// Otherwise, return swDest as-is.
|
package/src/lib/schema.ts
CHANGED
|
@@ -1,28 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertType, injectPartial as baseInjectPartial, basePartial, type Equals, fn, optionalSwDestPartial } from "@serwist/build/schema";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import type {
|
|
4
|
+
InjectManifestOptions,
|
|
5
|
+
InjectManifestOptionsComplete,
|
|
6
|
+
InjectPartial,
|
|
7
|
+
InjectResolved,
|
|
8
|
+
WebpackPartial,
|
|
9
|
+
WebpackResolved,
|
|
10
|
+
} from "./types.js";
|
|
3
11
|
|
|
4
|
-
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
|
|
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!");
|
|
12
|
+
const webpackConditionCallback = fn({
|
|
13
|
+
input: [z.any()],
|
|
14
|
+
output: z.boolean(),
|
|
15
|
+
});
|
|
14
16
|
|
|
15
|
-
|
|
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!");
|
|
17
|
+
const webpackCondition = z.union([z.string(), z.instanceof(RegExp), webpackConditionCallback]);
|
|
22
18
|
|
|
23
|
-
export const
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
|
|
19
|
+
export const webpackPartial = z.strictObject({
|
|
20
|
+
chunks: z.array(z.string()).optional(),
|
|
21
|
+
exclude: z.array(webpackCondition).default([/\.map$/, /^manifest.*\.js$/]),
|
|
22
|
+
excludeChunks: z.array(z.string()).optional(),
|
|
23
|
+
include: z.array(webpackCondition).optional(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const injectPartial = z.strictObject({
|
|
27
|
+
...optionalSwDestPartial.shape,
|
|
28
|
+
compileSrc: z.boolean().default(true),
|
|
29
|
+
webpackCompilationPlugins: z.array(z.any()).optional(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const injectManifestOptions = z.strictObject({
|
|
33
|
+
...basePartial.shape,
|
|
34
|
+
...webpackPartial.shape,
|
|
35
|
+
...baseInjectPartial.shape,
|
|
36
|
+
...optionalSwDestPartial.shape,
|
|
37
|
+
...injectPartial.shape,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
assertType<Equals<WebpackPartial, z.input<typeof webpackPartial>>>();
|
|
41
|
+
assertType<Equals<WebpackResolved, z.output<typeof webpackPartial>>>();
|
|
42
|
+
assertType<Equals<InjectPartial, z.input<typeof injectPartial>>>();
|
|
43
|
+
assertType<Equals<InjectResolved, z.output<typeof injectPartial>>>();
|
|
44
|
+
assertType<Equals<InjectManifestOptions, z.input<typeof injectManifestOptions>>>();
|
|
45
|
+
assertType<Equals<InjectManifestOptionsComplete, z.output<typeof injectManifestOptions>>>();
|
package/src/lib/types.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
BasePartial,
|
|
3
|
-
BaseResolved,
|
|
4
2
|
InjectPartial as BaseInjectPartial,
|
|
5
3
|
InjectResolved as BaseInjectResolved,
|
|
4
|
+
BasePartial,
|
|
5
|
+
BaseResolved,
|
|
6
6
|
OptionalSwDestPartial,
|
|
7
|
-
OptionalSwDestResolved,
|
|
8
7
|
} from "@serwist/build";
|
|
9
8
|
import type { Prettify, Require } from "@serwist/utils";
|
|
10
|
-
import type { WebpackPluginFunction, WebpackPluginInstance } from "webpack";
|
|
9
|
+
import type { Asset, Compilation, WebpackPluginFunction, WebpackPluginInstance } from "webpack";
|
|
10
|
+
|
|
11
|
+
export interface ConditionCallbackOptions {
|
|
12
|
+
asset: Asset;
|
|
13
|
+
compilation: Compilation;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type ConditionCallback = (options: ConditionCallbackOptions) => boolean;
|
|
11
17
|
|
|
12
18
|
export interface WebpackPartial {
|
|
13
19
|
/**
|
|
@@ -25,7 +31,7 @@ export interface WebpackPartial {
|
|
|
25
31
|
* [/\.map$/, /^manifest.*\.js$/]
|
|
26
32
|
* ```
|
|
27
33
|
*/
|
|
28
|
-
exclude?: (string | RegExp |
|
|
34
|
+
exclude?: (string | RegExp | ConditionCallback)[];
|
|
29
35
|
/**
|
|
30
36
|
* One or more chunk names whose corresponding output files should be excluded
|
|
31
37
|
* from the precache manifest.
|
|
@@ -37,12 +43,12 @@ export interface WebpackPartial {
|
|
|
37
43
|
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
38
44
|
* as webpack's standard `include` option.
|
|
39
45
|
*/
|
|
40
|
-
include?: (string | RegExp |
|
|
46
|
+
include?: (string | RegExp | ConditionCallback)[];
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
export type WebpackResolved = Prettify<Require<WebpackPartial, "exclude">>;
|
|
44
50
|
|
|
45
|
-
export interface InjectPartial {
|
|
51
|
+
export interface InjectPartial extends OptionalSwDestPartial {
|
|
46
52
|
/**
|
|
47
53
|
* When `true` (the default), the `swSrc` file will be compiled by webpack.
|
|
48
54
|
* When `false`, compilation will not occur (and `webpackCompilationPlugins`
|
|
@@ -63,8 +69,8 @@ export interface InjectPartial {
|
|
|
63
69
|
|
|
64
70
|
export type InjectResolved = Prettify<Require<InjectPartial, "compileSrc">>;
|
|
65
71
|
|
|
66
|
-
export type InjectManifestOptions = Prettify<BasePartial & WebpackPartial & BaseInjectPartial &
|
|
72
|
+
export type InjectManifestOptions = Prettify<BasePartial & WebpackPartial & BaseInjectPartial & InjectPartial>;
|
|
67
73
|
|
|
68
|
-
export type InjectManifestOptionsComplete = Prettify<BaseResolved & WebpackResolved & BaseInjectResolved &
|
|
74
|
+
export type InjectManifestOptionsComplete = Prettify<BaseResolved & WebpackResolved & BaseInjectResolved & InjectResolved>;
|
|
69
75
|
|
|
70
76
|
export type WebpackPlugin = WebpackPluginFunction | WebpackPluginInstance;
|
package/src/lib/validator.ts
CHANGED
|
@@ -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, {
|
|
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
|
}
|