@serwist/webpack-plugin 9.0.0-preview.9 → 9.0.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/schema.js +32 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.js +7 -2
- package/dist/index.js +37 -20
- package/dist/index.schema.d.ts +3 -0
- package/dist/index.schema.d.ts.map +1 -0
- package/dist/index.schema.js +3 -0
- package/dist/inject-manifest.d.ts +12 -19
- package/dist/inject-manifest.d.ts.map +1 -1
- package/dist/lib/child-compilation-plugin.d.ts +21 -4
- package/dist/lib/child-compilation-plugin.d.ts.map +1 -1
- package/dist/lib/get-manifest-entries-from-compilation.d.ts +3 -2
- package/dist/lib/get-manifest-entries-from-compilation.d.ts.map +1 -1
- package/dist/lib/schema.d.ts +225 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/types.d.ts +54 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/validator.d.ts +3 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/package.json +21 -10
- package/src/index.schema.ts +3 -0
- package/src/index.ts +4 -1
- package/src/inject-manifest.ts +38 -45
- package/src/lib/child-compilation-plugin.ts +28 -6
- package/src/lib/get-asset-hash.ts +1 -1
- package/src/lib/get-manifest-entries-from-compilation.ts +7 -6
- package/src/lib/schema.ts +28 -0
- package/src/lib/types.ts +67 -0
- package/src/lib/validator.ts +10 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { basePartial, injectPartial as injectPartial$1, optionalSwDestPartial } from '@serwist/build/schema';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
const webpackPartial = z.object({
|
|
5
|
+
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([
|
|
13
|
+
/\.map$/,
|
|
14
|
+
/^manifest.*\.js$/
|
|
15
|
+
]),
|
|
16
|
+
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({
|
|
26
|
+
compileSrc: z.boolean().default(true),
|
|
27
|
+
swDest: z.string().optional(),
|
|
28
|
+
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!");
|
|
31
|
+
|
|
32
|
+
export { injectManifestOptions, injectPartial, webpackPartial };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { InjectManifest } from "./inject-manifest.js";
|
|
2
|
-
|
|
2
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete, WebpackPartial, WebpackResolved } from "./lib/types.js";
|
|
3
|
+
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
4
|
+
export { InjectManifest, validateInjectManifestOptions };
|
|
5
|
+
export type { InjectManifestOptions, InjectManifestOptionsComplete, WebpackPartial, WebpackResolved };
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5H,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,6BAA6B,EAAE,CAAC;AACzD,YAAY,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/index.internal.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import webpack from 'webpack';
|
|
2
1
|
import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
|
|
3
2
|
import 'upath';
|
|
4
3
|
|
|
@@ -6,12 +5,18 @@ class ChildCompilationPlugin {
|
|
|
6
5
|
src;
|
|
7
6
|
dest;
|
|
8
7
|
plugins;
|
|
8
|
+
webpack;
|
|
9
9
|
constructor({ src, dest, plugins }){
|
|
10
10
|
this.src = src;
|
|
11
11
|
this.dest = dest;
|
|
12
12
|
this.plugins = plugins;
|
|
13
|
+
this.webpack = null;
|
|
14
|
+
}
|
|
15
|
+
propagateWebpackConfig(compiler) {
|
|
16
|
+
this.webpack = compiler.webpack;
|
|
13
17
|
}
|
|
14
18
|
apply(compiler) {
|
|
19
|
+
this.propagateWebpackConfig(compiler);
|
|
15
20
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.performChildCompilation(compilation, compiler).catch((error)=>{
|
|
16
21
|
compilation.errors.push(error);
|
|
17
22
|
}));
|
|
@@ -30,7 +35,7 @@ class ChildCompilationPlugin {
|
|
|
30
35
|
plugin?.apply(childCompiler);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
|
-
new webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
38
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
34
39
|
await new Promise((resolve, reject)=>{
|
|
35
40
|
childCompiler.runAsChild((error, _entries, childCompilation)=>{
|
|
36
41
|
if (error) {
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import { transformManifest, getSourceMapURL,
|
|
2
|
-
import stringify from 'fast-json-stable-stringify';
|
|
1
|
+
import { transformManifest, getSourceMapURL, stringify, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build';
|
|
3
2
|
import prettyBytes from 'pretty-bytes';
|
|
4
3
|
import upath from 'upath';
|
|
5
|
-
import
|
|
6
|
-
import crypto from 'crypto';
|
|
4
|
+
import { validationErrorMap, SerwistConfigError } from '@serwist/build/schema';
|
|
5
|
+
import crypto from 'node:crypto';
|
|
7
6
|
import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
|
|
8
7
|
|
|
8
|
+
const validateInjectManifestOptions = async (input)=>{
|
|
9
|
+
const result = await (await import('./chunks/schema.js')).injectManifestOptions.spa(input, {
|
|
10
|
+
errorMap: validationErrorMap
|
|
11
|
+
});
|
|
12
|
+
if (!result.success) {
|
|
13
|
+
throw new SerwistConfigError({
|
|
14
|
+
moduleName: "@serwist/webpack-plugin",
|
|
15
|
+
message: JSON.stringify(result.error.format(), null, 2)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return result.data;
|
|
19
|
+
};
|
|
20
|
+
|
|
9
21
|
const getAssetHash = (asset)=>{
|
|
10
22
|
if (asset.info?.immutable) {
|
|
11
23
|
return null;
|
|
@@ -31,7 +43,7 @@ const checkConditions = (asset, compilation, conditions = [])=>{
|
|
|
31
43
|
compilation
|
|
32
44
|
});
|
|
33
45
|
}
|
|
34
|
-
if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
46
|
+
if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
35
47
|
return true;
|
|
36
48
|
}
|
|
37
49
|
}
|
|
@@ -123,7 +135,8 @@ const getManifestEntriesFromCompilation = async (compilation, config)=>{
|
|
|
123
135
|
manifestTransforms: config.manifestTransforms,
|
|
124
136
|
maximumFileSizeToCacheInBytes: config.maximumFileSizeToCacheInBytes,
|
|
125
137
|
modifyURLPrefix: config.modifyURLPrefix,
|
|
126
|
-
transformParam: compilation
|
|
138
|
+
transformParam: compilation,
|
|
139
|
+
disablePrecacheManifest: config.disablePrecacheManifest
|
|
127
140
|
});
|
|
128
141
|
for (const warning of warnings){
|
|
129
142
|
compilation.warnings.push(new Error(warning));
|
|
@@ -151,15 +164,19 @@ const _generatedAssetNames = new Set();
|
|
|
151
164
|
class InjectManifest {
|
|
152
165
|
config;
|
|
153
166
|
alreadyCalled;
|
|
167
|
+
webpack;
|
|
154
168
|
constructor(config){
|
|
155
169
|
this.config = config;
|
|
156
170
|
this.alreadyCalled = false;
|
|
171
|
+
this.webpack = null;
|
|
157
172
|
}
|
|
158
|
-
propagateWebpackConfig() {
|
|
173
|
+
propagateWebpackConfig(compiler) {
|
|
174
|
+
this.webpack = compiler.webpack;
|
|
159
175
|
const parsedSwSrc = upath.parse(this.config.swSrc);
|
|
160
|
-
this.config =
|
|
161
|
-
swDest: `${parsedSwSrc.name}.js
|
|
162
|
-
|
|
176
|
+
this.config = {
|
|
177
|
+
swDest: `${parsedSwSrc.name}.js`,
|
|
178
|
+
...this.config
|
|
179
|
+
};
|
|
163
180
|
}
|
|
164
181
|
async getManifestEntries(compilation, config) {
|
|
165
182
|
if (config.disablePrecacheManifest) {
|
|
@@ -190,11 +207,11 @@ class InjectManifest {
|
|
|
190
207
|
};
|
|
191
208
|
}
|
|
192
209
|
apply(compiler) {
|
|
193
|
-
this.propagateWebpackConfig();
|
|
210
|
+
this.propagateWebpackConfig(compiler);
|
|
194
211
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.handleMake(compilation, compiler).catch((error)=>{
|
|
195
212
|
compilation.errors.push(error);
|
|
196
213
|
}));
|
|
197
|
-
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation;
|
|
214
|
+
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
|
|
198
215
|
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation)=>{
|
|
199
216
|
compilation.hooks.processAssets.tapPromise({
|
|
200
217
|
name: this.constructor.name,
|
|
@@ -217,7 +234,7 @@ class InjectManifest {
|
|
|
217
234
|
plugin.apply(childCompiler);
|
|
218
235
|
}
|
|
219
236
|
}
|
|
220
|
-
new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
237
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
221
238
|
await new Promise((resolve, reject)=>{
|
|
222
239
|
childCompiler.runAsChild((error, _entries, childCompilation)=>{
|
|
223
240
|
if (error) {
|
|
@@ -232,10 +249,10 @@ class InjectManifest {
|
|
|
232
249
|
}
|
|
233
250
|
addSrcToAssets(compilation, parentCompiler) {
|
|
234
251
|
const source = parentCompiler.inputFileSystem.readFileSync(this.config.swSrc);
|
|
235
|
-
compilation.emitAsset(this.config.swDest, new webpack.sources.RawSource(source));
|
|
252
|
+
compilation.emitAsset(this.config.swDest, new this.webpack.sources.RawSource(source));
|
|
236
253
|
}
|
|
237
254
|
async handleMake(compilation, parentCompiler) {
|
|
238
|
-
this.config = await
|
|
255
|
+
this.config = await validateInjectManifestOptions(this.config);
|
|
239
256
|
this.config.swDest = relativeToOutputPath(compilation, this.config.swDest);
|
|
240
257
|
_generatedAssetNames.add(this.config.swDest);
|
|
241
258
|
if (this.config.compileSrc) {
|
|
@@ -243,7 +260,7 @@ class InjectManifest {
|
|
|
243
260
|
} else {
|
|
244
261
|
this.addSrcToAssets(compilation, parentCompiler);
|
|
245
262
|
if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {
|
|
246
|
-
compilation.warnings.push(new Error("compileSrc is false, so the
|
|
263
|
+
compilation.warnings.push(new Error("'compileSrc' is 'false', so the 'webpackCompilationPlugins' option will be ignored."));
|
|
247
264
|
}
|
|
248
265
|
}
|
|
249
266
|
}
|
|
@@ -273,10 +290,10 @@ class InjectManifest {
|
|
|
273
290
|
replaceString: manifestString,
|
|
274
291
|
searchString: config.injectionPoint
|
|
275
292
|
});
|
|
276
|
-
compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
|
|
277
|
-
compilation.updateAsset(config.swDest, new webpack.sources.RawSource(source));
|
|
293
|
+
compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map));
|
|
294
|
+
compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(source));
|
|
278
295
|
} else {
|
|
279
|
-
compilation.updateAsset(config.swDest, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
|
|
296
|
+
compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
|
|
280
297
|
}
|
|
281
298
|
if (compilation.getLogger) {
|
|
282
299
|
const logger = compilation.getLogger(this.constructor.name);
|
|
@@ -285,4 +302,4 @@ class InjectManifest {
|
|
|
285
302
|
}
|
|
286
303
|
}
|
|
287
304
|
|
|
288
|
-
export { InjectManifest };
|
|
305
|
+
export { InjectManifest, validateInjectManifestOptions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.schema.d.ts","sourceRoot":"","sources":["../src/index.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEvF,OAAO,EAAE,cAAc,EAAE,aAAa,IAAI,qBAAqB,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { Compiler } from "webpack";
|
|
2
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* This class supports compiling a service worker file provided via `swSrc`,
|
|
5
5
|
* and injecting into that service worker a list of URLs and revision
|
|
@@ -23,64 +23,57 @@ import webpack from "webpack";
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
export declare class InjectManifest {
|
|
26
|
-
protected config:
|
|
26
|
+
protected config: InjectManifestOptionsComplete;
|
|
27
27
|
private alreadyCalled;
|
|
28
|
+
private webpack;
|
|
28
29
|
/**
|
|
29
30
|
* Creates an instance of InjectManifest.
|
|
30
31
|
*/
|
|
31
|
-
constructor(config:
|
|
32
|
+
constructor(config: InjectManifestOptions);
|
|
32
33
|
/**
|
|
33
34
|
* @param compiler default compiler object passed from webpack
|
|
34
35
|
*
|
|
35
36
|
* @private
|
|
36
37
|
*/
|
|
37
|
-
propagateWebpackConfig
|
|
38
|
+
private propagateWebpackConfig;
|
|
38
39
|
/**
|
|
39
40
|
* `getManifestEntriesFromCompilation` with a few additional checks.
|
|
40
41
|
*
|
|
41
42
|
* @private
|
|
42
43
|
*/
|
|
43
|
-
getManifestEntries
|
|
44
|
-
size: number;
|
|
45
|
-
sortedEntries: {
|
|
46
|
-
revision: string | null;
|
|
47
|
-
url: string;
|
|
48
|
-
integrity?: string | undefined;
|
|
49
|
-
}[] | undefined;
|
|
50
|
-
manifestString: string;
|
|
51
|
-
}>;
|
|
44
|
+
private getManifestEntries;
|
|
52
45
|
/**
|
|
53
46
|
* @param compiler default compiler object passed from webpack
|
|
54
47
|
*
|
|
55
48
|
* @private
|
|
56
49
|
*/
|
|
57
|
-
apply(compiler:
|
|
50
|
+
apply(compiler: Compiler): void;
|
|
58
51
|
/**
|
|
59
52
|
* @param compilation The webpack compilation.
|
|
60
53
|
* @param parentCompiler The webpack parent compiler.
|
|
61
54
|
*
|
|
62
55
|
* @private
|
|
63
56
|
*/
|
|
64
|
-
performChildCompilation
|
|
57
|
+
private performChildCompilation;
|
|
65
58
|
/**
|
|
66
59
|
* @param compilation The webpack compilation.
|
|
67
60
|
* @param parentCompiler The webpack parent compiler.
|
|
68
61
|
*
|
|
69
62
|
* @private
|
|
70
63
|
*/
|
|
71
|
-
addSrcToAssets
|
|
64
|
+
private addSrcToAssets;
|
|
72
65
|
/**
|
|
73
66
|
* @param compilation The webpack compilation.
|
|
74
67
|
* @param parentCompiler The webpack parent compiler.
|
|
75
68
|
*
|
|
76
69
|
* @private
|
|
77
70
|
*/
|
|
78
|
-
handleMake
|
|
71
|
+
private handleMake;
|
|
79
72
|
/**
|
|
80
73
|
* @param compilation The webpack compilation.
|
|
81
74
|
*
|
|
82
75
|
* @private
|
|
83
76
|
*/
|
|
84
|
-
addAssets
|
|
77
|
+
private addAssets;
|
|
85
78
|
}
|
|
86
79
|
//# sourceMappingURL=inject-manifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,QAAQ,EAAoC,MAAM,SAAS,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAW3F;;;;;;;;;;;;;;;;;;;;;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;IAOzC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAa9B;;;;OAIG;YACW,kBAAkB;IAwChC;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IA6B/B;;;;;OAKG;YACW,uBAAuB;IAiCrC;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAKtB;;;;;OAKG;YACW,UAAU;IAiBxB;;;;OAIG;YACW,SAAS;CAmDxB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { WebpackPluginInstance } from "webpack";
|
|
2
|
-
import webpack from "webpack";
|
|
1
|
+
import type { Compiler, WebpackPluginInstance, default as Webpack } from "webpack";
|
|
3
2
|
export interface ChildCompilationPluginOptions {
|
|
4
3
|
src: string;
|
|
5
4
|
dest: string;
|
|
@@ -14,8 +13,26 @@ export declare class ChildCompilationPlugin implements WebpackPluginInstance {
|
|
|
14
13
|
src: string;
|
|
15
14
|
dest: string;
|
|
16
15
|
plugins: WebpackPluginInstance[] | undefined;
|
|
16
|
+
webpack: typeof Webpack;
|
|
17
17
|
constructor({ src, dest, plugins }: ChildCompilationPluginOptions);
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param compiler default compiler object passed from webpack
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private propagateWebpackConfig;
|
|
24
|
+
/**
|
|
25
|
+
* @param compiler default compiler object passed from webpack
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
apply(compiler: Compiler): void;
|
|
30
|
+
/**
|
|
31
|
+
* @param compilation The webpack compilation.
|
|
32
|
+
* @param parentCompiler The webpack parent compiler.
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
private performChildCompilation;
|
|
20
37
|
}
|
|
21
38
|
//# sourceMappingURL=child-compilation-plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child-compilation-plugin.d.ts","sourceRoot":"","sources":["../../src/lib/child-compilation-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"child-compilation-plugin.d.ts","sourceRoot":"","sources":["../../src/lib/child-compilation-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,QAAQ,EAAgB,qBAAqB,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,SAAS,CAAC;AAI9G,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACnC;AAED;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,qBAAqB,EAAE,GAAG,SAAS,CAAC;IAC7C,OAAO,EAAE,OAAO,OAAO,CAAC;gBACZ,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,6BAA6B;IAMjE;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IAG9B;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;IASxB;;;;;OAKG;YACW,uBAAuB;CAiCtC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ManifestEntry
|
|
1
|
+
import type { ManifestEntry } from "@serwist/build";
|
|
2
2
|
import type { Compilation } from "webpack";
|
|
3
|
-
|
|
3
|
+
import type { InjectManifestOptionsComplete } from "./types.js";
|
|
4
|
+
export declare const getManifestEntriesFromCompilation: (compilation: Compilation, config: InjectManifestOptionsComplete) => Promise<{
|
|
4
5
|
size: number;
|
|
5
6
|
sortedEntries: ManifestEntry[] | undefined;
|
|
6
7
|
}>;
|
|
@@ -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,
|
|
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,QAAQ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,EAAE,GAAG,SAAS,CAAA;CAAE,CAiCtE,CAAC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
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
|
+
chunks?: string[] | undefined;
|
|
14
|
+
exclude?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
15
|
+
excludeChunks?: string[] | undefined;
|
|
16
|
+
include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const injectPartial: z.ZodObject<{
|
|
19
|
+
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
+
swDest: z.ZodOptional<z.ZodString>;
|
|
21
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
22
|
+
}, "strict", z.ZodTypeAny, {
|
|
23
|
+
compileSrc: boolean;
|
|
24
|
+
swDest?: string | undefined;
|
|
25
|
+
webpackCompilationPlugins?: any[] | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
compileSrc?: boolean | undefined;
|
|
28
|
+
swDest?: string | undefined;
|
|
29
|
+
webpackCompilationPlugins?: any[] | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const injectManifestOptions: z.ZodObject<{
|
|
32
|
+
chunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
33
|
+
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">>;
|
|
34
|
+
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
35
|
+
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">>;
|
|
36
|
+
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
37
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
38
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
+
url: z.ZodString;
|
|
40
|
+
}, "strict", z.ZodTypeAny, {
|
|
41
|
+
url: string;
|
|
42
|
+
integrity?: string | undefined;
|
|
43
|
+
revision?: string | null | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
url: string;
|
|
46
|
+
integrity?: string | undefined;
|
|
47
|
+
revision?: string | null | undefined;
|
|
48
|
+
}>]>, "many">>;
|
|
49
|
+
disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
|
|
50
|
+
dontCacheBustURLsMatching: z.ZodOptional<z.ZodType<RegExp, z.ZodTypeDef, RegExp>>;
|
|
51
|
+
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodFunction<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
52
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
53
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
|
+
url: z.ZodString;
|
|
55
|
+
size: z.ZodNumber;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
url: string;
|
|
58
|
+
size: number;
|
|
59
|
+
integrity?: string | undefined;
|
|
60
|
+
revision?: string | null | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
url: string;
|
|
63
|
+
size: number;
|
|
64
|
+
integrity?: string | undefined;
|
|
65
|
+
revision?: string | null | undefined;
|
|
66
|
+
}>, "many">, z.ZodOptional<z.ZodUnknown>], null>, z.ZodUnion<[z.ZodPromise<z.ZodObject<{
|
|
67
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
68
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
69
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
70
|
+
url: z.ZodString;
|
|
71
|
+
size: z.ZodNumber;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
url: string;
|
|
74
|
+
size: number;
|
|
75
|
+
integrity?: string | undefined;
|
|
76
|
+
revision?: string | null | undefined;
|
|
77
|
+
}, {
|
|
78
|
+
url: string;
|
|
79
|
+
size: number;
|
|
80
|
+
integrity?: string | undefined;
|
|
81
|
+
revision?: string | null | undefined;
|
|
82
|
+
}>, "many">;
|
|
83
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
84
|
+
}, "strict", z.ZodTypeAny, {
|
|
85
|
+
manifest: {
|
|
86
|
+
url: string;
|
|
87
|
+
size: number;
|
|
88
|
+
integrity?: string | undefined;
|
|
89
|
+
revision?: string | null | undefined;
|
|
90
|
+
}[];
|
|
91
|
+
warnings?: string[] | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
manifest: {
|
|
94
|
+
url: string;
|
|
95
|
+
size: number;
|
|
96
|
+
integrity?: string | undefined;
|
|
97
|
+
revision?: string | null | undefined;
|
|
98
|
+
}[];
|
|
99
|
+
warnings?: string[] | undefined;
|
|
100
|
+
}>>, z.ZodObject<{
|
|
101
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
102
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
103
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
url: z.ZodString;
|
|
105
|
+
size: z.ZodNumber;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
url: string;
|
|
108
|
+
size: number;
|
|
109
|
+
integrity?: string | undefined;
|
|
110
|
+
revision?: string | null | undefined;
|
|
111
|
+
}, {
|
|
112
|
+
url: string;
|
|
113
|
+
size: number;
|
|
114
|
+
integrity?: string | undefined;
|
|
115
|
+
revision?: string | null | undefined;
|
|
116
|
+
}>, "many">;
|
|
117
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
118
|
+
}, "strict", z.ZodTypeAny, {
|
|
119
|
+
manifest: {
|
|
120
|
+
url: string;
|
|
121
|
+
size: number;
|
|
122
|
+
integrity?: string | undefined;
|
|
123
|
+
revision?: string | null | undefined;
|
|
124
|
+
}[];
|
|
125
|
+
warnings?: string[] | undefined;
|
|
126
|
+
}, {
|
|
127
|
+
manifest: {
|
|
128
|
+
url: string;
|
|
129
|
+
size: number;
|
|
130
|
+
integrity?: string | undefined;
|
|
131
|
+
revision?: string | null | undefined;
|
|
132
|
+
}[];
|
|
133
|
+
warnings?: string[] | undefined;
|
|
134
|
+
}>]>>, "many">>;
|
|
135
|
+
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
136
|
+
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
137
|
+
injectionPoint: z.ZodDefault<z.ZodString>;
|
|
138
|
+
swSrc: z.ZodString;
|
|
139
|
+
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
140
|
+
swDest: z.ZodOptional<z.ZodString>;
|
|
141
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
142
|
+
}, "strict", z.ZodTypeAny, {
|
|
143
|
+
exclude: (string | RegExp | ((args_0: any) => boolean))[];
|
|
144
|
+
compileSrc: boolean;
|
|
145
|
+
disablePrecacheManifest: boolean;
|
|
146
|
+
maximumFileSizeToCacheInBytes: number;
|
|
147
|
+
injectionPoint: string;
|
|
148
|
+
swSrc: string;
|
|
149
|
+
chunks?: string[] | undefined;
|
|
150
|
+
excludeChunks?: string[] | undefined;
|
|
151
|
+
include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
152
|
+
additionalPrecacheEntries?: (string | {
|
|
153
|
+
url: string;
|
|
154
|
+
integrity?: string | undefined;
|
|
155
|
+
revision?: string | null | undefined;
|
|
156
|
+
})[] | undefined;
|
|
157
|
+
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
158
|
+
manifestTransforms?: ((args_0: {
|
|
159
|
+
url: string;
|
|
160
|
+
size: number;
|
|
161
|
+
integrity?: string | undefined;
|
|
162
|
+
revision?: string | null | undefined;
|
|
163
|
+
}[], args_1: unknown) => {
|
|
164
|
+
manifest: {
|
|
165
|
+
url: string;
|
|
166
|
+
size: number;
|
|
167
|
+
integrity?: string | undefined;
|
|
168
|
+
revision?: string | null | undefined;
|
|
169
|
+
}[];
|
|
170
|
+
warnings?: string[] | undefined;
|
|
171
|
+
} | Promise<{
|
|
172
|
+
manifest: {
|
|
173
|
+
url: string;
|
|
174
|
+
size: number;
|
|
175
|
+
integrity?: string | undefined;
|
|
176
|
+
revision?: string | null | undefined;
|
|
177
|
+
}[];
|
|
178
|
+
warnings?: string[] | undefined;
|
|
179
|
+
}>)[] | undefined;
|
|
180
|
+
modifyURLPrefix?: Record<string, string> | undefined;
|
|
181
|
+
swDest?: string | undefined;
|
|
182
|
+
webpackCompilationPlugins?: any[] | undefined;
|
|
183
|
+
}, {
|
|
184
|
+
swSrc: string;
|
|
185
|
+
chunks?: string[] | undefined;
|
|
186
|
+
exclude?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
187
|
+
excludeChunks?: string[] | undefined;
|
|
188
|
+
include?: (string | RegExp | ((args_0: any) => boolean))[] | undefined;
|
|
189
|
+
additionalPrecacheEntries?: (string | {
|
|
190
|
+
url: string;
|
|
191
|
+
integrity?: string | undefined;
|
|
192
|
+
revision?: string | null | undefined;
|
|
193
|
+
})[] | undefined;
|
|
194
|
+
disablePrecacheManifest?: boolean | undefined;
|
|
195
|
+
dontCacheBustURLsMatching?: RegExp | undefined;
|
|
196
|
+
manifestTransforms?: ((args_0: {
|
|
197
|
+
url: string;
|
|
198
|
+
size: number;
|
|
199
|
+
integrity?: string | undefined;
|
|
200
|
+
revision?: string | null | undefined;
|
|
201
|
+
}[], args_1: unknown) => {
|
|
202
|
+
manifest: {
|
|
203
|
+
url: string;
|
|
204
|
+
size: number;
|
|
205
|
+
integrity?: string | undefined;
|
|
206
|
+
revision?: string | null | undefined;
|
|
207
|
+
}[];
|
|
208
|
+
warnings?: string[] | undefined;
|
|
209
|
+
} | Promise<{
|
|
210
|
+
manifest: {
|
|
211
|
+
url: string;
|
|
212
|
+
size: number;
|
|
213
|
+
integrity?: string | undefined;
|
|
214
|
+
revision?: string | null | undefined;
|
|
215
|
+
}[];
|
|
216
|
+
warnings?: string[] | undefined;
|
|
217
|
+
}>)[] | undefined;
|
|
218
|
+
maximumFileSizeToCacheInBytes?: number | undefined;
|
|
219
|
+
modifyURLPrefix?: Record<string, string> | undefined;
|
|
220
|
+
injectionPoint?: string | undefined;
|
|
221
|
+
compileSrc?: boolean | undefined;
|
|
222
|
+
swDest?: string | undefined;
|
|
223
|
+
webpackCompilationPlugins?: any[] | undefined;
|
|
224
|
+
}>;
|
|
225
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;EASmC,CAAC;AAE/D,eAAO,MAAM,aAAa;;;;;;;;;;;;EAMkD,CAAC;AAE7E,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAK0C,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { BasePartial, BaseResolved, InjectPartial as BaseInjectPartial, InjectResolved as BaseInjectResolved, OptionalSwDestPartial, OptionalSwDestResolved } from "@serwist/build";
|
|
2
|
+
import type { Require } from "@serwist/utils";
|
|
3
|
+
export interface WebpackPartial {
|
|
4
|
+
/**
|
|
5
|
+
* One or more chunk names whose corresponding output files should be included
|
|
6
|
+
* in the precache manifest.
|
|
7
|
+
*/
|
|
8
|
+
chunks?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* One or more specifiers used to exclude assets from the precache manifest.
|
|
11
|
+
* This is interpreted following
|
|
12
|
+
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
13
|
+
* as webpack's standard `exclude` option.
|
|
14
|
+
* @default
|
|
15
|
+
* ```
|
|
16
|
+
* [/\.map$/, /^manifest.*\.js$/]
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
exclude?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
20
|
+
/**
|
|
21
|
+
* One or more chunk names whose corresponding output files should be excluded
|
|
22
|
+
* from the precache manifest.
|
|
23
|
+
*/
|
|
24
|
+
excludeChunks?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* One or more specifiers used to include assets in the precache manifest.
|
|
27
|
+
* This is interpreted following
|
|
28
|
+
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
29
|
+
* as webpack's standard `include` option.
|
|
30
|
+
*/
|
|
31
|
+
include?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
32
|
+
}
|
|
33
|
+
export type WebpackResolved = Require<WebpackPartial, "exclude">;
|
|
34
|
+
export interface InjectPartial {
|
|
35
|
+
/**
|
|
36
|
+
* When `true` (the default), the `swSrc` file will be compiled by webpack.
|
|
37
|
+
* When `false`, compilation will not occur (and `webpackCompilationPlugins`
|
|
38
|
+
* can't be used.) Set to `false` if you want to inject the manifest into,
|
|
39
|
+
* e.g., a JSON file.
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
compileSrc?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Optional webpack plugins that will be used when compiling the `swSrc`
|
|
45
|
+
* file. Only valid if `compileSrc` is `true`.
|
|
46
|
+
*/
|
|
47
|
+
webpackCompilationPlugins?: any[];
|
|
48
|
+
}
|
|
49
|
+
export type InjectResolved = Require<InjectPartial, "compileSrc">;
|
|
50
|
+
export interface InjectManifestOptions extends BasePartial, WebpackPartial, BaseInjectPartial, OptionalSwDestPartial, InjectPartial {
|
|
51
|
+
}
|
|
52
|
+
export interface InjectManifestOptionsComplete extends BaseResolved, WebpackResolved, BaseInjectResolved, OptionalSwDestResolved, InjectResolved {
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;AAE9C,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,GAAG,EAAE,CAAC;CACnC;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"}
|
|
@@ -0,0 +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,QAAQ,6BAA6B,CAMzG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/webpack-plugin",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "A plugin for your
|
|
5
|
+
"description": "A plugin for your webpack build process, helping you generate a manifest of local files that should be precached.",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
8
|
"dist"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
24
24
|
"license": "MIT",
|
|
25
|
-
"repository": "serwist/serwist",
|
|
25
|
+
"repository": "https://github.com/serwist/serwist",
|
|
26
26
|
"bugs": "https://github.com/serwist/serwist/issues",
|
|
27
27
|
"homepage": "https://serwist.pages.dev",
|
|
28
28
|
"main": "./dist/index.js",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"*": {
|
|
32
32
|
"internal": [
|
|
33
33
|
"./dist/index.internal.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"schema": [
|
|
36
|
+
"./dist/index.schema.d.ts"
|
|
34
37
|
]
|
|
35
38
|
}
|
|
36
39
|
},
|
|
@@ -43,21 +46,26 @@
|
|
|
43
46
|
"types": "./dist/index.internal.d.ts",
|
|
44
47
|
"default": "./dist/index.internal.js"
|
|
45
48
|
},
|
|
49
|
+
"./schema": {
|
|
50
|
+
"types": "./dist/index.schema.d.ts",
|
|
51
|
+
"default": "./dist/index.schema.js"
|
|
52
|
+
},
|
|
46
53
|
"./package.json": "./package.json"
|
|
47
54
|
},
|
|
48
55
|
"dependencies": {
|
|
49
|
-
"fast-json-stable-stringify": "2.1.0",
|
|
50
56
|
"pretty-bytes": "6.1.1",
|
|
51
57
|
"upath": "2.0.1",
|
|
52
|
-
"
|
|
58
|
+
"zod": "3.22.4",
|
|
59
|
+
"@serwist/build": "9.0.1"
|
|
53
60
|
},
|
|
54
61
|
"devDependencies": {
|
|
55
|
-
"@types/node": "20.
|
|
62
|
+
"@types/node": "20.12.7",
|
|
56
63
|
"@types/webpack": "5.28.5",
|
|
57
|
-
"rollup": "4.
|
|
58
|
-
"typescript": "5.
|
|
59
|
-
"webpack": "5.
|
|
60
|
-
"@serwist/
|
|
64
|
+
"rollup": "4.14.3",
|
|
65
|
+
"typescript": "5.5.0-dev.20240415",
|
|
66
|
+
"webpack": "5.91.0",
|
|
67
|
+
"@serwist/configs": "9.0.1",
|
|
68
|
+
"@serwist/utils": "9.0.1"
|
|
61
69
|
},
|
|
62
70
|
"peerDependencies": {
|
|
63
71
|
"typescript": ">=5.0.0",
|
|
@@ -66,6 +74,9 @@
|
|
|
66
74
|
"peerDependenciesMeta": {
|
|
67
75
|
"typescript": {
|
|
68
76
|
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"webpack": {
|
|
79
|
+
"optional": true
|
|
69
80
|
}
|
|
70
81
|
},
|
|
71
82
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { InjectManifest } from "./inject-manifest.js";
|
|
10
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete, WebpackPartial, WebpackResolved } from "./lib/types.js";
|
|
11
|
+
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
10
12
|
|
|
11
|
-
export { InjectManifest };
|
|
13
|
+
export { InjectManifest, validateInjectManifestOptions };
|
|
14
|
+
export type { InjectManifestOptions, InjectManifestOptionsComplete, WebpackPartial, WebpackResolved };
|
package/src/inject-manifest.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright 2018 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
import type { WebpackInjectManifestOptions } from "@serwist/build";
|
|
9
|
-
import { escapeRegExp, replaceAndUpdateSourceMap, validateWebpackInjectManifestOptions } from "@serwist/build";
|
|
10
|
-
import stringify from "fast-json-stable-stringify";
|
|
1
|
+
import { escapeRegExp, replaceAndUpdateSourceMap, stringify } from "@serwist/build";
|
|
11
2
|
import prettyBytes from "pretty-bytes";
|
|
12
3
|
import upath from "upath";
|
|
13
|
-
import type { Compilation } from "webpack";
|
|
14
|
-
import
|
|
4
|
+
import type { Compilation, Compiler, WebpackError, default as Webpack } from "webpack";
|
|
5
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./lib/types.js";
|
|
6
|
+
import { validateInjectManifestOptions } from "./lib/validator.js";
|
|
15
7
|
|
|
16
8
|
import { getManifestEntriesFromCompilation } from "./lib/get-manifest-entries-from-compilation.js";
|
|
17
9
|
import { getSourcemapAssetName } from "./lib/get-sourcemap-asset-name.js";
|
|
@@ -44,15 +36,18 @@ const _generatedAssetNames = new Set<string>();
|
|
|
44
36
|
* ```
|
|
45
37
|
*/
|
|
46
38
|
export class InjectManifest {
|
|
47
|
-
protected config:
|
|
39
|
+
protected config: InjectManifestOptionsComplete;
|
|
48
40
|
private alreadyCalled: boolean;
|
|
41
|
+
private webpack: typeof Webpack;
|
|
49
42
|
|
|
50
43
|
/**
|
|
51
44
|
* Creates an instance of InjectManifest.
|
|
52
45
|
*/
|
|
53
|
-
constructor(config:
|
|
54
|
-
|
|
46
|
+
constructor(config: InjectManifestOptions) {
|
|
47
|
+
// We are essentially lying to TypeScript.
|
|
48
|
+
this.config = config as InjectManifestOptionsComplete;
|
|
55
49
|
this.alreadyCalled = false;
|
|
50
|
+
this.webpack = null!;
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
/**
|
|
@@ -60,17 +55,17 @@ export class InjectManifest {
|
|
|
60
55
|
*
|
|
61
56
|
* @private
|
|
62
57
|
*/
|
|
63
|
-
propagateWebpackConfig(): void {
|
|
58
|
+
private propagateWebpackConfig(compiler: Compiler): void {
|
|
59
|
+
this.webpack = compiler.webpack;
|
|
60
|
+
|
|
64
61
|
const parsedSwSrc = upath.parse(this.config.swSrc);
|
|
65
62
|
// Because this.config is listed last, properties that are already set
|
|
66
63
|
// there take precedence over derived properties from the compiler.
|
|
67
|
-
this.config =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.config,
|
|
73
|
-
);
|
|
64
|
+
this.config = {
|
|
65
|
+
// Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.
|
|
66
|
+
swDest: `${parsedSwSrc.name}.js`,
|
|
67
|
+
...this.config,
|
|
68
|
+
};
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
/**
|
|
@@ -78,7 +73,7 @@ export class InjectManifest {
|
|
|
78
73
|
*
|
|
79
74
|
* @private
|
|
80
75
|
*/
|
|
81
|
-
async getManifestEntries(compilation:
|
|
76
|
+
private async getManifestEntries(compilation: Compilation, config: InjectManifestOptionsComplete) {
|
|
82
77
|
if (config.disablePrecacheManifest) {
|
|
83
78
|
return {
|
|
84
79
|
size: 0,
|
|
@@ -92,7 +87,7 @@ export class InjectManifest {
|
|
|
92
87
|
const warningMessage = `${this.constructor.name} has been called multiple times, perhaps due to running webpack in --watch mode. The precache manifest generated after the first call may be inaccurate! Please see https://github.com/GoogleChrome/workbox/issues/1790 for more information.`;
|
|
93
88
|
|
|
94
89
|
if (!compilation.warnings.some((warning) => warning instanceof Error && warning.message === warningMessage)) {
|
|
95
|
-
compilation.warnings.push(new Error(warningMessage) as
|
|
90
|
+
compilation.warnings.push(new Error(warningMessage) as WebpackError);
|
|
96
91
|
}
|
|
97
92
|
} else {
|
|
98
93
|
this.alreadyCalled = true;
|
|
@@ -123,16 +118,17 @@ export class InjectManifest {
|
|
|
123
118
|
*
|
|
124
119
|
* @private
|
|
125
120
|
*/
|
|
126
|
-
apply(compiler:
|
|
127
|
-
this.propagateWebpackConfig();
|
|
121
|
+
apply(compiler: Compiler): void {
|
|
122
|
+
this.propagateWebpackConfig(compiler);
|
|
128
123
|
|
|
129
124
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
|
|
130
|
-
this.handleMake(compilation, compiler).catch((error:
|
|
125
|
+
this.handleMake(compilation, compiler).catch((error: WebpackError) => {
|
|
131
126
|
compilation.errors.push(error);
|
|
132
127
|
}),
|
|
133
128
|
);
|
|
134
129
|
|
|
135
|
-
|
|
130
|
+
// webpack should not be null at this point.
|
|
131
|
+
const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
|
|
136
132
|
// Specifically hook into thisCompilation, as per
|
|
137
133
|
// https://github.com/webpack/webpack/issues/11425#issuecomment-690547848
|
|
138
134
|
compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
|
|
@@ -144,7 +140,7 @@ export class InjectManifest {
|
|
|
144
140
|
stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10,
|
|
145
141
|
},
|
|
146
142
|
() =>
|
|
147
|
-
this.addAssets(compilation).catch((error:
|
|
143
|
+
this.addAssets(compilation).catch((error: WebpackError) => {
|
|
148
144
|
compilation.errors.push(error);
|
|
149
145
|
}),
|
|
150
146
|
);
|
|
@@ -157,7 +153,7 @@ export class InjectManifest {
|
|
|
157
153
|
*
|
|
158
154
|
* @private
|
|
159
155
|
*/
|
|
160
|
-
async performChildCompilation(compilation:
|
|
156
|
+
private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
|
|
161
157
|
const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = {
|
|
162
158
|
filename: this.config.swDest,
|
|
163
159
|
};
|
|
@@ -174,7 +170,7 @@ export class InjectManifest {
|
|
|
174
170
|
}
|
|
175
171
|
}
|
|
176
172
|
|
|
177
|
-
new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
173
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
|
|
178
174
|
|
|
179
175
|
await new Promise<void>((resolve, reject) => {
|
|
180
176
|
childCompiler.runAsChild((error, _entries, childCompilation) => {
|
|
@@ -196,10 +192,9 @@ export class InjectManifest {
|
|
|
196
192
|
*
|
|
197
193
|
* @private
|
|
198
194
|
*/
|
|
199
|
-
addSrcToAssets(compilation:
|
|
200
|
-
// eslint-disable-next-line
|
|
195
|
+
private addSrcToAssets(compilation: Compilation, parentCompiler: Compiler): void {
|
|
201
196
|
const source = (parentCompiler.inputFileSystem as any).readFileSync(this.config.swSrc);
|
|
202
|
-
compilation.emitAsset(this.config.swDest!, new webpack.sources.RawSource(source));
|
|
197
|
+
compilation.emitAsset(this.config.swDest!, new this.webpack.sources.RawSource(source));
|
|
203
198
|
}
|
|
204
199
|
|
|
205
200
|
/**
|
|
@@ -208,8 +203,8 @@ export class InjectManifest {
|
|
|
208
203
|
*
|
|
209
204
|
* @private
|
|
210
205
|
*/
|
|
211
|
-
async handleMake(compilation:
|
|
212
|
-
this.config = await
|
|
206
|
+
private async handleMake(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
|
|
207
|
+
this.config = await validateInjectManifestOptions(this.config);
|
|
213
208
|
this.config.swDest = relativeToOutputPath(compilation, this.config.swDest!);
|
|
214
209
|
_generatedAssetNames.add(this.config.swDest);
|
|
215
210
|
|
|
@@ -220,9 +215,7 @@ export class InjectManifest {
|
|
|
220
215
|
// This used to be a fatal error, but just warn at runtime because we
|
|
221
216
|
// can't validate it easily.
|
|
222
217
|
if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {
|
|
223
|
-
compilation.warnings.push(
|
|
224
|
-
new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored.") as webpack.WebpackError,
|
|
225
|
-
);
|
|
218
|
+
compilation.warnings.push(new Error("'compileSrc' is 'false', so the 'webpackCompilationPlugins' option will be ignored.") as WebpackError);
|
|
226
219
|
}
|
|
227
220
|
}
|
|
228
221
|
}
|
|
@@ -232,7 +225,7 @@ export class InjectManifest {
|
|
|
232
225
|
*
|
|
233
226
|
* @private
|
|
234
227
|
*/
|
|
235
|
-
async addAssets(compilation:
|
|
228
|
+
private async addAssets(compilation: Compilation): Promise<void> {
|
|
236
229
|
const config = Object.assign({}, this.config);
|
|
237
230
|
|
|
238
231
|
const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);
|
|
@@ -244,7 +237,7 @@ export class InjectManifest {
|
|
|
244
237
|
const swAsset = compilation.getAsset(config.swDest!);
|
|
245
238
|
const swAssetString = swAsset!.source.source().toString();
|
|
246
239
|
|
|
247
|
-
const globalRegexp = new RegExp(escapeRegExp(config.injectionPoint
|
|
240
|
+
const globalRegexp = new RegExp(escapeRegExp(config.injectionPoint), "g");
|
|
248
241
|
const injectionResults = swAssetString.match(globalRegexp);
|
|
249
242
|
|
|
250
243
|
if (!injectionResults) {
|
|
@@ -270,12 +263,12 @@ export class InjectManifest {
|
|
|
270
263
|
searchString: config.injectionPoint!,
|
|
271
264
|
});
|
|
272
265
|
|
|
273
|
-
compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
|
|
274
|
-
compilation.updateAsset(config.swDest!, new webpack.sources.RawSource(source));
|
|
266
|
+
compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map));
|
|
267
|
+
compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(source));
|
|
275
268
|
} else {
|
|
276
269
|
// If there's no sourcemap associated with swDest, a simple string
|
|
277
270
|
// replacement will suffice.
|
|
278
|
-
compilation.updateAsset(config.swDest!, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint!, manifestString)));
|
|
271
|
+
compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint!, manifestString)));
|
|
279
272
|
}
|
|
280
273
|
|
|
281
274
|
if (compilation.getLogger) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Compilation, WebpackPluginInstance } from "webpack";
|
|
2
|
-
import webpack from "webpack";
|
|
1
|
+
import type { Compilation, Compiler, WebpackError, WebpackPluginInstance, default as Webpack } from "webpack";
|
|
3
2
|
|
|
4
3
|
import { relativeToOutputPath } from "./relative-to-output-path.js";
|
|
5
4
|
|
|
@@ -18,19 +17,42 @@ export class ChildCompilationPlugin implements WebpackPluginInstance {
|
|
|
18
17
|
src: string;
|
|
19
18
|
dest: string;
|
|
20
19
|
plugins: WebpackPluginInstance[] | undefined;
|
|
20
|
+
webpack: typeof Webpack;
|
|
21
21
|
constructor({ src, dest, plugins }: ChildCompilationPluginOptions) {
|
|
22
22
|
this.src = src;
|
|
23
23
|
this.dest = dest;
|
|
24
24
|
this.plugins = plugins;
|
|
25
|
+
this.webpack = null!;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @param compiler default compiler object passed from webpack
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
private propagateWebpackConfig(compiler: Compiler): void {
|
|
33
|
+
this.webpack = compiler.webpack;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @param compiler default compiler object passed from webpack
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
apply(compiler: Compiler) {
|
|
41
|
+
this.propagateWebpackConfig(compiler);
|
|
42
|
+
|
|
27
43
|
compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
|
|
28
|
-
this.performChildCompilation(compilation, compiler).catch((error:
|
|
44
|
+
this.performChildCompilation(compilation, compiler).catch((error: WebpackError) => {
|
|
29
45
|
compilation.errors.push(error);
|
|
30
46
|
}),
|
|
31
47
|
);
|
|
32
48
|
}
|
|
33
|
-
|
|
49
|
+
/**
|
|
50
|
+
* @param compilation The webpack compilation.
|
|
51
|
+
* @param parentCompiler The webpack parent compiler.
|
|
52
|
+
*
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private async performChildCompilation(compilation: Compilation, parentCompiler: Compiler): Promise<void> {
|
|
34
56
|
const resolvedDest = relativeToOutputPath(compilation, this.dest);
|
|
35
57
|
const outputOptions: Parameters<Compilation["createChildCompiler"]>["1"] = {
|
|
36
58
|
filename: resolvedDest,
|
|
@@ -48,7 +70,7 @@ export class ChildCompilationPlugin implements WebpackPluginInstance {
|
|
|
48
70
|
}
|
|
49
71
|
}
|
|
50
72
|
|
|
51
|
-
new webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
73
|
+
new this.webpack.EntryPlugin(parentCompiler.context, this.src, this.constructor.name).apply(childCompiler);
|
|
52
74
|
|
|
53
75
|
await new Promise<void>((resolve, reject) => {
|
|
54
76
|
childCompiler.runAsChild((error, _entries, childCompilation) => {
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { FileDetails, ManifestEntry
|
|
9
|
+
import type { FileDetails, ManifestEntry } from "@serwist/build";
|
|
10
10
|
import { transformManifest } from "@serwist/build";
|
|
11
11
|
import type { Asset, Chunk, Compilation, WebpackError } from "webpack";
|
|
12
|
-
import webpack from "webpack";
|
|
13
12
|
|
|
14
13
|
import { getAssetHash } from "./get-asset-hash.js";
|
|
15
14
|
import { resolveWebpackURL } from "./resolve-webpack-url.js";
|
|
15
|
+
import type { InjectManifestOptions, InjectManifestOptionsComplete } from "./types.js";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* For a given asset, checks whether at least one of the conditions matches.
|
|
@@ -36,7 +36,7 @@ const checkConditions = (
|
|
|
36
36
|
return condition({ asset, compilation });
|
|
37
37
|
//return compilation !== null;
|
|
38
38
|
}
|
|
39
|
-
if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
39
|
+
if (compilation.compiler.webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -105,7 +105,7 @@ const getNamesOfAssetsInChunk = (chunk: Chunk): string[] => {
|
|
|
105
105
|
* based on the criteria provided.
|
|
106
106
|
* @private
|
|
107
107
|
*/
|
|
108
|
-
const filterAssets = (compilation: Compilation, config:
|
|
108
|
+
const filterAssets = (compilation: Compilation, config: InjectManifestOptions): Set<Asset> => {
|
|
109
109
|
const filteredAssets = new Set<Asset>();
|
|
110
110
|
const assets = compilation.getAssets();
|
|
111
111
|
|
|
@@ -178,7 +178,7 @@ const filterAssets = (compilation: Compilation, config: WebpackInjectManifestOpt
|
|
|
178
178
|
|
|
179
179
|
export const getManifestEntriesFromCompilation = async (
|
|
180
180
|
compilation: Compilation,
|
|
181
|
-
config:
|
|
181
|
+
config: InjectManifestOptionsComplete,
|
|
182
182
|
): Promise<{ size: number; sortedEntries: ManifestEntry[] | undefined }> => {
|
|
183
183
|
const filteredAssets = filterAssets(compilation, config);
|
|
184
184
|
|
|
@@ -189,7 +189,7 @@ export const getManifestEntriesFromCompilation = async (
|
|
|
189
189
|
file: resolveWebpackURL(publicPath as string, asset.name),
|
|
190
190
|
hash: getAssetHash(asset),
|
|
191
191
|
size: asset.source.size() || 0,
|
|
192
|
-
}
|
|
192
|
+
} satisfies FileDetails;
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
const { manifestEntries, size, warnings } = await transformManifest({
|
|
@@ -200,6 +200,7 @@ export const getManifestEntriesFromCompilation = async (
|
|
|
200
200
|
maximumFileSizeToCacheInBytes: config.maximumFileSizeToCacheInBytes,
|
|
201
201
|
modifyURLPrefix: config.modifyURLPrefix,
|
|
202
202
|
transformParam: compilation,
|
|
203
|
+
disablePrecacheManifest: config.disablePrecacheManifest,
|
|
203
204
|
});
|
|
204
205
|
|
|
205
206
|
// See https://github.com/GoogleChrome/workbox/issues/2790
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { basePartial, injectPartial as baseInjectPartial, optionalSwDestPartial } from "@serwist/build/schema";
|
|
2
|
+
import { z } from "zod";
|
|
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!");
|
|
14
|
+
|
|
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!");
|
|
22
|
+
|
|
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!");
|
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BasePartial,
|
|
3
|
+
BaseResolved,
|
|
4
|
+
InjectPartial as BaseInjectPartial,
|
|
5
|
+
InjectResolved as BaseInjectResolved,
|
|
6
|
+
OptionalSwDestPartial,
|
|
7
|
+
OptionalSwDestResolved,
|
|
8
|
+
} from "@serwist/build";
|
|
9
|
+
import type { Require } from "@serwist/utils";
|
|
10
|
+
|
|
11
|
+
export interface WebpackPartial {
|
|
12
|
+
/**
|
|
13
|
+
* One or more chunk names whose corresponding output files should be included
|
|
14
|
+
* in the precache manifest.
|
|
15
|
+
*/
|
|
16
|
+
chunks?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* One or more specifiers used to exclude assets from the precache manifest.
|
|
19
|
+
* This is interpreted following
|
|
20
|
+
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
21
|
+
* as webpack's standard `exclude` option.
|
|
22
|
+
* @default
|
|
23
|
+
* ```
|
|
24
|
+
* [/\.map$/, /^manifest.*\.js$/]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
exclude?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
28
|
+
/**
|
|
29
|
+
* One or more chunk names whose corresponding output files should be excluded
|
|
30
|
+
* from the precache manifest.
|
|
31
|
+
*/
|
|
32
|
+
excludeChunks?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* One or more specifiers used to include assets in the precache manifest.
|
|
35
|
+
* This is interpreted following
|
|
36
|
+
* [the same rules](https://webpack.js.org/configuration/module/#condition)
|
|
37
|
+
* as webpack's standard `include` option.
|
|
38
|
+
*/
|
|
39
|
+
include?: (string | RegExp | ((arg0: any) => boolean))[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type WebpackResolved = Require<WebpackPartial, "exclude">;
|
|
43
|
+
|
|
44
|
+
export interface InjectPartial {
|
|
45
|
+
/**
|
|
46
|
+
* When `true` (the default), the `swSrc` file will be compiled by webpack.
|
|
47
|
+
* When `false`, compilation will not occur (and `webpackCompilationPlugins`
|
|
48
|
+
* can't be used.) Set to `false` if you want to inject the manifest into,
|
|
49
|
+
* e.g., a JSON file.
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
compileSrc?: boolean;
|
|
53
|
+
// This can only be set if `compileSrc` is true, but that restriction can't be
|
|
54
|
+
// represented in TypeScript. It's enforced via custom runtime validation
|
|
55
|
+
// logic and needs to be documented.
|
|
56
|
+
/**
|
|
57
|
+
* Optional webpack plugins that will be used when compiling the `swSrc`
|
|
58
|
+
* file. Only valid if `compileSrc` is `true`.
|
|
59
|
+
*/
|
|
60
|
+
webpackCompilationPlugins?: any[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type InjectResolved = Require<InjectPartial, "compileSrc">;
|
|
64
|
+
|
|
65
|
+
export interface InjectManifestOptions extends BasePartial, WebpackPartial, BaseInjectPartial, OptionalSwDestPartial, InjectPartial {}
|
|
66
|
+
|
|
67
|
+
export interface InjectManifestOptionsComplete extends BaseResolved, WebpackResolved, BaseInjectResolved, OptionalSwDestResolved, InjectResolved {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
|
|
2
|
+
import type { InjectManifestOptionsComplete } from "./types.js";
|
|
3
|
+
|
|
4
|
+
export const validateInjectManifestOptions = async (input: unknown): Promise<InjectManifestOptionsComplete> => {
|
|
5
|
+
const result = await (await import("./schema.js")).injectManifestOptions.spa(input, { errorMap: validationErrorMap });
|
|
6
|
+
if (!result.success) {
|
|
7
|
+
throw new SerwistConfigError({ moduleName: "@serwist/webpack-plugin", message: JSON.stringify(result.error.format(), null, 2) });
|
|
8
|
+
}
|
|
9
|
+
return result.data;
|
|
10
|
+
};
|