@serwist/webpack-plugin 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,496 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var build = require('@serwist/build');
5
+ var stringify = require('fast-json-stable-stringify');
6
+ var prettyBytes = require('pretty-bytes');
7
+ var upath = require('upath');
8
+ var webpack = require('webpack');
9
+ var crypto = require('crypto');
10
+
11
+ /**
12
+ * @param asset
13
+ * @returns The MD5 hash of the asset's source.
14
+ *
15
+ * @private
16
+ */ function getAssetHash(asset) {
17
+ // If webpack has the asset marked as immutable, then we don't need to
18
+ // use an out-of-band revision for it.
19
+ // See https://github.com/webpack/webpack/issues/9038
20
+ if (asset.info && asset.info.immutable) {
21
+ return null;
22
+ }
23
+ return crypto.createHash("md5").update(Buffer.from(asset.source.source())).digest("hex");
24
+ }
25
+
26
+ /*
27
+ Copyright 2018 Google LLC
28
+
29
+ Use of this source code is governed by an MIT-style
30
+ license that can be found in the LICENSE file or at
31
+ https://opensource.org/licenses/MIT.
32
+ */ /**
33
+ * Resolves a url in the way that webpack would (with string concatenation)
34
+ *
35
+ * Use publicPath + filePath instead of url.resolve(publicPath, filePath) see:
36
+ * https://webpack.js.org/configuration/output/#output-publicpath
37
+ *
38
+ * @param publicPath The publicPath value from webpack's compilation.
39
+ * @param paths File paths to join
40
+ * @returns Joined file path
41
+ * @private
42
+ */ function resolveWebpackURL(publicPath, ...paths) {
43
+ // This is a change in webpack v5.
44
+ // See https://github.com/jantimon/html-webpack-plugin/pull/1516
45
+ if (publicPath === "auto") {
46
+ return paths.join("");
47
+ } else {
48
+ return [
49
+ publicPath,
50
+ ...paths
51
+ ].join("");
52
+ }
53
+ }
54
+
55
+ /**
56
+ * For a given asset, checks whether at least one of the conditions matches.
57
+ *
58
+ * @param asset The webpack asset in question. This will be passed
59
+ * to any functions that are listed as conditions.
60
+ * @param compilation The webpack compilation. This will be passed
61
+ * to any functions that are listed as conditions.
62
+ * @param conditions
63
+ * @returns Whether or not at least one condition matches.
64
+ * @private
65
+ */ function checkConditions(asset, compilation, conditions = []) {
66
+ for (const condition of conditions){
67
+ if (typeof condition === "function") {
68
+ return condition({
69
+ asset,
70
+ compilation
71
+ });
72
+ //return compilation !== null;
73
+ } else {
74
+ if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
75
+ return true;
76
+ }
77
+ }
78
+ }
79
+ // We'll only get here if none of the conditions applied.
80
+ return false;
81
+ }
82
+ /**
83
+ * Returns the names of all the assets in all the chunks in a chunk group,
84
+ * if provided a chunk group name.
85
+ * Otherwise, if provided a chunk name, return all the assets in that chunk.
86
+ * Otherwise, if there isn't a chunk group or chunk with that name, return null.
87
+ *
88
+ * @param compilation
89
+ * @param chunkOrGroup
90
+ * @returns
91
+ * @private
92
+ */ function getNamesOfAssetsInChunkOrGroup(compilation, chunkOrGroup) {
93
+ const chunkGroup = compilation.namedChunkGroups && compilation.namedChunkGroups.get(chunkOrGroup);
94
+ if (chunkGroup) {
95
+ const assetNames = [];
96
+ for (const chunk of chunkGroup.chunks){
97
+ assetNames.push(...getNamesOfAssetsInChunk(chunk));
98
+ }
99
+ return assetNames;
100
+ } else {
101
+ const chunk = compilation.namedChunks && compilation.namedChunks.get(chunkOrGroup);
102
+ if (chunk) {
103
+ return getNamesOfAssetsInChunk(chunk);
104
+ }
105
+ }
106
+ // If we get here, there's no chunkGroup or chunk with that name.
107
+ return null;
108
+ }
109
+ /**
110
+ * Returns the names of all the assets in a chunk.
111
+ *
112
+ * @param chunk
113
+ * @returns
114
+ * @private
115
+ */ function getNamesOfAssetsInChunk(chunk) {
116
+ const assetNames = [];
117
+ assetNames.push(...chunk.files);
118
+ // This only appears to be set in webpack v5.
119
+ if (chunk.auxiliaryFiles) {
120
+ assetNames.push(...chunk.auxiliaryFiles);
121
+ }
122
+ return assetNames;
123
+ }
124
+ /**
125
+ * Filters the set of assets out, based on the configuration options provided:
126
+ * - chunks and excludeChunks, for chunkName-based criteria.
127
+ * - include and exclude, for more general criteria.
128
+ *
129
+ * @param compilation The webpack compilation.
130
+ * @param config The validated configuration, obtained from the plugin.
131
+ * @returns The assets that should be included in the manifest,
132
+ * based on the criteria provided.
133
+ * @private
134
+ */ function filterAssets(compilation, config) {
135
+ const filteredAssets = new Set();
136
+ const assets = compilation.getAssets();
137
+ const allowedAssetNames = new Set();
138
+ // See https://github.com/GoogleChrome/workbox/issues/1287
139
+ if (Array.isArray(config.chunks)) {
140
+ for (const name of config.chunks){
141
+ // See https://github.com/GoogleChrome/workbox/issues/2717
142
+ const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);
143
+ if (assetsInChunkOrGroup) {
144
+ for (const assetName of assetsInChunkOrGroup){
145
+ allowedAssetNames.add(assetName);
146
+ }
147
+ } else {
148
+ compilation.warnings.push(new Error(`The chunk '${name}' was ` + `provided in your Serwist chunks config, but was not found in the ` + `compilation.`));
149
+ }
150
+ }
151
+ }
152
+ const deniedAssetNames = new Set();
153
+ if (Array.isArray(config.excludeChunks)) {
154
+ for (const name of config.excludeChunks){
155
+ // See https://github.com/GoogleChrome/workbox/issues/2717
156
+ const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);
157
+ if (assetsInChunkOrGroup) {
158
+ for (const assetName of assetsInChunkOrGroup){
159
+ deniedAssetNames.add(assetName);
160
+ }
161
+ } // Don't warn if the chunk group isn't found.
162
+ }
163
+ }
164
+ for (const asset of assets){
165
+ // chunk based filtering is funky because:
166
+ // - Each asset might belong to one or more chunks.
167
+ // - If *any* of those chunk names match our config.excludeChunks,
168
+ // then we skip that asset.
169
+ // - If the config.chunks is defined *and* there's no match
170
+ // between at least one of the chunkNames and one entry, then
171
+ // we skip that assets as well.
172
+ if (deniedAssetNames.has(asset.name)) {
173
+ continue;
174
+ }
175
+ if (Array.isArray(config.chunks) && !allowedAssetNames.has(asset.name)) {
176
+ continue;
177
+ }
178
+ // Next, check asset-level checks via includes/excludes:
179
+ const isExcluded = checkConditions(asset, compilation, config.exclude);
180
+ if (isExcluded) {
181
+ continue;
182
+ }
183
+ // Treat an empty config.includes as an implicit inclusion.
184
+ const isIncluded = !Array.isArray(config.include) || checkConditions(asset, compilation, config.include);
185
+ if (!isIncluded) {
186
+ continue;
187
+ }
188
+ // If we've gotten this far, then add the asset.
189
+ filteredAssets.add(asset);
190
+ }
191
+ return filteredAssets;
192
+ }
193
+ async function getManifestEntriesFromCompilation(compilation, config) {
194
+ const filteredAssets = filterAssets(compilation, config);
195
+ const { publicPath } = compilation.options.output;
196
+ const fileDetails = Array.from(filteredAssets).map((asset)=>{
197
+ return {
198
+ file: resolveWebpackURL(publicPath, asset.name),
199
+ hash: getAssetHash(asset),
200
+ size: asset.source.size() || 0
201
+ };
202
+ });
203
+ const { manifestEntries, size, warnings } = await build.transformManifest({
204
+ fileDetails,
205
+ additionalPrecacheEntries: config.additionalPrecacheEntries,
206
+ dontCacheBustURLsMatching: config.dontCacheBustURLsMatching,
207
+ manifestTransforms: config.manifestTransforms,
208
+ maximumFileSizeToCacheInBytes: config.maximumFileSizeToCacheInBytes,
209
+ modifyURLPrefix: config.modifyURLPrefix,
210
+ transformParam: compilation
211
+ });
212
+ // See https://github.com/GoogleChrome/workbox/issues/2790
213
+ for (const warning of warnings){
214
+ compilation.warnings.push(new Error(warning));
215
+ }
216
+ // Ensure that the entries are properly sorted by URL.
217
+ const sortedEntries = manifestEntries.sort((a, b)=>a.url === b.url ? 0 : a.url > b.url ? 1 : -1);
218
+ return {
219
+ size,
220
+ sortedEntries
221
+ };
222
+ }
223
+
224
+ /**
225
+ * If our bundled swDest file contains a sourcemap, we would invalidate that
226
+ * mapping if we just replaced injectionPoint with the stringified manifest.
227
+ * Instead, we need to update the swDest contents as well as the sourcemap
228
+ * at the same time.
229
+ *
230
+ * See https://github.com/GoogleChrome/workbox/issues/2235
231
+ *
232
+ * @param compilation The current webpack compilation.
233
+ * @param swContents The contents of the swSrc file, which may or
234
+ * may not include a valid sourcemap comment.
235
+ * @param swDest The configured swDest value.
236
+ * @returns If the swContents contains a valid sourcemap
237
+ * comment pointing to an asset present in the compilation, this will return the
238
+ * name of that asset. Otherwise, it will return undefined.
239
+ * @private
240
+ */ function getSourcemapAssetName(compilation, swContents, swDest) {
241
+ const url = build.getSourceMapURL(swContents);
242
+ if (url) {
243
+ // Translate the relative URL to what the presumed name for the webpack
244
+ // asset should be.
245
+ // This *might* not be a valid asset if the sourcemap URL that was found
246
+ // was added by another module incidentally.
247
+ // See https://github.com/GoogleChrome/workbox/issues/2250
248
+ const swAssetDirname = upath.dirname(swDest);
249
+ const sourcemapURLAssetName = upath.normalize(upath.join(swAssetDirname, url));
250
+ // Not sure if there's a better way to check for asset existence?
251
+ if (compilation.getAsset(sourcemapURLAssetName)) {
252
+ return sourcemapURLAssetName;
253
+ }
254
+ }
255
+ return undefined;
256
+ }
257
+
258
+ /**
259
+ * @param compilation The webpack compilation.
260
+ * @param swDest The original swDest value.
261
+ *
262
+ * @returns If swDest was not absolute, the returns swDest as-is.
263
+ * Otherwise, returns swDest relative to the compilation's output path.
264
+ *
265
+ * @private
266
+ */ function relativeToOutputPath(compilation, swDest) {
267
+ // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
268
+ if (upath.resolve(swDest) === upath.normalize(swDest)) {
269
+ return upath.relative(compilation.options.output.path, swDest);
270
+ }
271
+ // Otherwise, return swDest as-is.
272
+ return swDest;
273
+ }
274
+
275
+ // Used to keep track of swDest files written by *any* instance of this plugin.
276
+ // See https://github.com/GoogleChrome/workbox/issues/2181
277
+ const _generatedAssetNames = new Set();
278
+ /**
279
+ * This class supports compiling a service worker file provided via `swSrc`,
280
+ * and injecting into that service worker a list of URLs and revision
281
+ * information for precaching based on the webpack asset pipeline.
282
+ *
283
+ * Use an instance of `InjectManifest` in the
284
+ * [`plugins` array](https://webpack.js.org/concepts/plugins/#usage) of a
285
+ * webpack config.
286
+ *
287
+ * In addition to injecting the manifest, this plugin will perform a compilation
288
+ * of the `swSrc` file, using the options from the main webpack configuration.
289
+ *
290
+ * ```
291
+ * // The following lists some common options; see the rest of the documentation
292
+ * // for the full set of options and defaults.
293
+ * new InjectManifest({
294
+ * exclude: [/.../, '...'],
295
+ * maximumFileSizeToCacheInBytes: ...,
296
+ * swSrc: '...',
297
+ * });
298
+ * ```
299
+ */ class InjectManifest {
300
+ config;
301
+ alreadyCalled;
302
+ /**
303
+ * Creates an instance of InjectManifest.
304
+ */ constructor(config){
305
+ this.config = config;
306
+ this.alreadyCalled = false;
307
+ }
308
+ /**
309
+ * @param compiler default compiler object passed from webpack
310
+ *
311
+ * @private
312
+ */ propagateWebpackConfig(compiler) {
313
+ const parsedSwSrc = upath.parse(this.config.swSrc);
314
+ // Because this.config is listed last, properties that are already set
315
+ // there take precedence over derived properties from the compiler.
316
+ this.config = Object.assign({
317
+ mode: compiler.options.mode,
318
+ // Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.
319
+ swDest: path.join(parsedSwSrc.dir, parsedSwSrc.name + ".js")
320
+ }, this.config);
321
+ }
322
+ /**
323
+ * `getManifestEntriesFromCompilation` with a few additional checks.
324
+ *
325
+ * @private
326
+ */ async getManifestEntries(compilation, config) {
327
+ if (config.disablePrecacheManifest) {
328
+ return {
329
+ size: 0,
330
+ sortedEntries: [],
331
+ manifestString: "undefined"
332
+ };
333
+ }
334
+ // See https://github.com/GoogleChrome/workbox/issues/1790
335
+ if (this.alreadyCalled) {
336
+ 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.`;
337
+ if (!compilation.warnings.some((warning)=>warning instanceof Error && warning.message === warningMessage)) {
338
+ compilation.warnings.push(new Error(warningMessage));
339
+ }
340
+ } else {
341
+ this.alreadyCalled = true;
342
+ }
343
+ // Ensure that we don't precache any of the assets generated by *any*
344
+ // instance of this plugin.
345
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
346
+ config.exclude.push(({ asset })=>_generatedAssetNames.has(asset.name));
347
+ const { size, sortedEntries } = await getManifestEntriesFromCompilation(compilation, config);
348
+ let manifestString = stringify(sortedEntries);
349
+ if (this.config.compileSrc && // See https://github.com/GoogleChrome/workbox/issues/2729
350
+ !(compilation.options?.devtool === "eval-cheap-source-map" && compilation.options.optimization?.minimize)) {
351
+ // See https://github.com/GoogleChrome/workbox/issues/2263
352
+ manifestString = manifestString.replace(/"/g, `'`);
353
+ }
354
+ return {
355
+ size,
356
+ sortedEntries,
357
+ manifestString
358
+ };
359
+ }
360
+ /**
361
+ * @param compiler default compiler object passed from webpack
362
+ *
363
+ * @private
364
+ */ apply(compiler) {
365
+ this.propagateWebpackConfig(compiler);
366
+ compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.handleMake(compilation, compiler).catch((error)=>{
367
+ compilation.errors.push(error);
368
+ }));
369
+ const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation;
370
+ // Specifically hook into thisCompilation, as per
371
+ // https://github.com/webpack/webpack/issues/11425#issuecomment-690547848
372
+ compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation)=>{
373
+ compilation.hooks.processAssets.tapPromise({
374
+ name: this.constructor.name,
375
+ // TODO(jeffposnick): This may need to change eventually.
376
+ // See https://github.com/webpack/webpack/issues/11822#issuecomment-726184972
377
+ stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10
378
+ }, ()=>this.addAssets(compilation).catch((error)=>{
379
+ compilation.errors.push(error);
380
+ }));
381
+ });
382
+ }
383
+ /**
384
+ * @param compilation The webpack compilation.
385
+ * @param parentCompiler The webpack parent compiler.
386
+ *
387
+ * @private
388
+ */ async performChildCompilation(compilation, parentCompiler) {
389
+ const outputOptions = {
390
+ filename: this.config.swDest
391
+ };
392
+ const childCompiler = compilation.createChildCompiler(this.constructor.name, outputOptions, []);
393
+ childCompiler.context = parentCompiler.context;
394
+ childCompiler.inputFileSystem = parentCompiler.inputFileSystem;
395
+ childCompiler.outputFileSystem = parentCompiler.outputFileSystem;
396
+ if (Array.isArray(this.config.webpackCompilationPlugins)) {
397
+ for (const plugin of this.config.webpackCompilationPlugins){
398
+ plugin.apply(childCompiler);
399
+ }
400
+ }
401
+ new webpack.EntryPlugin(parentCompiler.context, this.config.swSrc, this.constructor.name).apply(childCompiler);
402
+ await new Promise((resolve, reject)=>{
403
+ childCompiler.runAsChild((error, _entries, childCompilation)=>{
404
+ if (error) {
405
+ reject(error);
406
+ } else {
407
+ compilation.warnings = compilation.warnings.concat(childCompilation?.warnings ?? []);
408
+ compilation.errors = compilation.errors.concat(childCompilation?.errors ?? []);
409
+ resolve();
410
+ }
411
+ });
412
+ });
413
+ }
414
+ /**
415
+ * @param compilation The webpack compilation.
416
+ * @param parentCompiler The webpack parent compiler.
417
+ *
418
+ * @private
419
+ */ addSrcToAssets(compilation, parentCompiler) {
420
+ // eslint-disable-next-line
421
+ const source = parentCompiler.inputFileSystem.readFileSync(this.config.swSrc);
422
+ compilation.emitAsset(this.config.swDest, new webpack.sources.RawSource(source));
423
+ }
424
+ /**
425
+ * @param compilation The webpack compilation.
426
+ * @param parentCompiler The webpack parent compiler.
427
+ *
428
+ * @private
429
+ */ async handleMake(compilation, parentCompiler) {
430
+ try {
431
+ this.config = build.validateWebpackInjectManifestOptions(this.config);
432
+ } catch (error) {
433
+ if (error instanceof Error) {
434
+ throw new Error(`Please check your ${this.constructor.name} plugin ` + `configuration:\n${error.message}`);
435
+ }
436
+ }
437
+ this.config.swDest = relativeToOutputPath(compilation, this.config.swDest);
438
+ _generatedAssetNames.add(this.config.swDest);
439
+ if (this.config.compileSrc) {
440
+ await this.performChildCompilation(compilation, parentCompiler);
441
+ } else {
442
+ this.addSrcToAssets(compilation, parentCompiler);
443
+ // This used to be a fatal error, but just warn at runtime because we
444
+ // can't validate it easily.
445
+ if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {
446
+ compilation.warnings.push(new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored."));
447
+ }
448
+ }
449
+ }
450
+ /**
451
+ * @param compilation The webpack compilation.
452
+ *
453
+ * @private
454
+ */ async addAssets(compilation) {
455
+ const config = Object.assign({}, this.config);
456
+ const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);
457
+ // See https://webpack.js.org/contribute/plugin-patterns/#monitoring-the-watch-graph
458
+ const absoluteSwSrc = upath.resolve(config.swSrc);
459
+ compilation.fileDependencies.add(absoluteSwSrc);
460
+ const swAsset = compilation.getAsset(config.swDest);
461
+ const swAssetString = swAsset.source.source().toString();
462
+ const globalRegexp = new RegExp(build.escapeRegExp(config.injectionPoint), "g");
463
+ const injectionResults = swAssetString.match(globalRegexp);
464
+ if (!injectionResults) {
465
+ throw new Error(`Can't find ${config.injectionPoint} in your SW source.`);
466
+ }
467
+ if (injectionResults.length !== 1) {
468
+ throw new Error(`Multiple instances of ${config.injectionPoint} were ` + "found in your SW source. Include it only once. For more info, see " + "https://github.com/GoogleChrome/workbox/issues/2681");
469
+ }
470
+ const sourcemapAssetName = getSourcemapAssetName(compilation, swAssetString, config.swDest);
471
+ if (sourcemapAssetName) {
472
+ _generatedAssetNames.add(sourcemapAssetName);
473
+ const sourcemapAsset = compilation.getAsset(sourcemapAssetName);
474
+ const { source, map } = await build.replaceAndUpdateSourceMap({
475
+ jsFilename: config.swDest,
476
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
477
+ originalMap: JSON.parse(sourcemapAsset.source.source().toString()),
478
+ originalSource: swAssetString,
479
+ replaceString: manifestString,
480
+ searchString: config.injectionPoint
481
+ });
482
+ compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
483
+ compilation.updateAsset(config.swDest, new webpack.sources.RawSource(source));
484
+ } else {
485
+ // If there's no sourcemap associated with swDest, a simple string
486
+ // replacement will suffice.
487
+ compilation.updateAsset(config.swDest, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
488
+ }
489
+ if (compilation.getLogger) {
490
+ const logger = compilation.getLogger(this.constructor.name);
491
+ logger.info(`The service worker at ${config.swDest ?? ""} will precache ${sortedEntries.length} URLs, totaling ${prettyBytes(size)}.`);
492
+ }
493
+ }
494
+ }
495
+
496
+ exports.InjectManifest = InjectManifest;
@@ -0,0 +1,83 @@
1
+ import type { WebpackInjectManifestOptions } from "@serwist/build";
2
+ import webpack from "webpack";
3
+ /**
4
+ * This class supports compiling a service worker file provided via `swSrc`,
5
+ * and injecting into that service worker a list of URLs and revision
6
+ * information for precaching based on the webpack asset pipeline.
7
+ *
8
+ * Use an instance of `InjectManifest` in the
9
+ * [`plugins` array](https://webpack.js.org/concepts/plugins/#usage) of a
10
+ * webpack config.
11
+ *
12
+ * In addition to injecting the manifest, this plugin will perform a compilation
13
+ * of the `swSrc` file, using the options from the main webpack configuration.
14
+ *
15
+ * ```
16
+ * // The following lists some common options; see the rest of the documentation
17
+ * // for the full set of options and defaults.
18
+ * new InjectManifest({
19
+ * exclude: [/.../, '...'],
20
+ * maximumFileSizeToCacheInBytes: ...,
21
+ * swSrc: '...',
22
+ * });
23
+ * ```
24
+ */
25
+ declare class InjectManifest {
26
+ protected config: WebpackInjectManifestOptions;
27
+ private alreadyCalled;
28
+ /**
29
+ * Creates an instance of InjectManifest.
30
+ */
31
+ constructor(config: WebpackInjectManifestOptions);
32
+ /**
33
+ * @param compiler default compiler object passed from webpack
34
+ *
35
+ * @private
36
+ */
37
+ propagateWebpackConfig(compiler: webpack.Compiler): void;
38
+ /**
39
+ * `getManifestEntriesFromCompilation` with a few additional checks.
40
+ *
41
+ * @private
42
+ */
43
+ getManifestEntries(compilation: webpack.Compilation, config: WebpackInjectManifestOptions): Promise<{
44
+ size: number;
45
+ sortedEntries: import("@serwist/build").ManifestEntry[];
46
+ manifestString: string;
47
+ }>;
48
+ /**
49
+ * @param compiler default compiler object passed from webpack
50
+ *
51
+ * @private
52
+ */
53
+ apply(compiler: webpack.Compiler): void;
54
+ /**
55
+ * @param compilation The webpack compilation.
56
+ * @param parentCompiler The webpack parent compiler.
57
+ *
58
+ * @private
59
+ */
60
+ performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
61
+ /**
62
+ * @param compilation The webpack compilation.
63
+ * @param parentCompiler The webpack parent compiler.
64
+ *
65
+ * @private
66
+ */
67
+ addSrcToAssets(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): void;
68
+ /**
69
+ * @param compilation The webpack compilation.
70
+ * @param parentCompiler The webpack parent compiler.
71
+ *
72
+ * @private
73
+ */
74
+ handleMake(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
75
+ /**
76
+ * @param compilation The webpack compilation.
77
+ *
78
+ * @private
79
+ */
80
+ addAssets(compilation: webpack.Compilation): Promise<void>;
81
+ }
82
+ export { InjectManifest };
83
+ //# sourceMappingURL=inject-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAMnE,OAAO,OAAO,MAAM,SAAS,CAAC;AAU9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,cAAM,cAAc;IAClB,SAAS,CAAC,MAAM,EAAE,4BAA4B,CAAC;IAC/C,OAAO,CAAC,aAAa,CAAU;IAE/B;;OAEG;gBACS,MAAM,EAAE,4BAA4B;IAKhD;;;;OAIG;IACH,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;IAcxD;;;;OAIG;IACG,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,4BAA4B;;;;;IA6C/F;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;IA4BvC;;;;;OAKG;IACG,uBAAuB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiChH;;;;;OAKG;IACH,cAAc,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;IAMxF;;;;;OAKG;IACG,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnG;;;;OAIG;IACG,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAqDjE;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { WebpackPluginInstance } from "webpack";
2
+ import webpack from "webpack";
3
+ export interface ChildCompilationPluginOptions {
4
+ src: string;
5
+ dest: string;
6
+ plugins?: WebpackPluginInstance[];
7
+ }
8
+ /**
9
+ * Compile a file by creating a child of the hooked compiler.
10
+ *
11
+ * @private
12
+ */
13
+ export declare class ChildCompilationPlugin implements WebpackPluginInstance {
14
+ src: string;
15
+ dest: string;
16
+ plugins: WebpackPluginInstance[] | undefined;
17
+ constructor({ src, dest, plugins }: ChildCompilationPluginOptions);
18
+ apply(compiler: webpack.Compiler): void;
19
+ performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=child-compilation-plugin.d.ts.map
@@ -0,0 +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,MAAM,SAAS,CAAC;AAClE,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,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;gBACjC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,6BAA6B;IAKjE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ;IAO1B,uBAAuB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,cAAc,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAiCjH"}
@@ -0,0 +1,9 @@
1
+ import type { Asset } from "webpack";
2
+ /**
3
+ * @param asset
4
+ * @returns The MD5 hash of the asset's source.
5
+ *
6
+ * @private
7
+ */
8
+ export declare function getAssetHash(asset: Asset): string | null;
9
+ //# sourceMappingURL=get-asset-hash.d.ts.map
@@ -0,0 +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,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CASxD"}
@@ -0,0 +1,7 @@
1
+ import type { ManifestEntry, WebpackInjectManifestOptions } from "@serwist/build";
2
+ import type { Compilation } from "webpack";
3
+ export declare function getManifestEntriesFromCompilation(compilation: Compilation, config: WebpackInjectManifestOptions): Promise<{
4
+ size: number;
5
+ sortedEntries: ManifestEntry[];
6
+ }>;
7
+ //# sourceMappingURL=get-manifest-entries-from-compilation.d.ts.map
@@ -0,0 +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,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAE/F,OAAO,KAAK,EAAgB,WAAW,EAAgB,MAAM,SAAS,CAAC;AA6KvE,wBAAsB,iCAAiC,CACrD,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC,CAgC3D"}
@@ -0,0 +1,3 @@
1
+ import type { Compilation } from "webpack";
2
+ export declare function getScriptFilesForChunks(compilation: Compilation, chunkNames: Array<string>): Array<string>;
3
+ //# sourceMappingURL=get-script-files-for-chunks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-script-files-for-chunks.d.ts","sourceRoot":"","sources":["../../src/lib/get-script-files-for-chunks.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,SAAS,CAAC;AAIzD,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CA0B1G"}
@@ -0,0 +1,20 @@
1
+ import type { Compilation } from "webpack";
2
+ /**
3
+ * If our bundled swDest file contains a sourcemap, we would invalidate that
4
+ * mapping if we just replaced injectionPoint with the stringified manifest.
5
+ * Instead, we need to update the swDest contents as well as the sourcemap
6
+ * at the same time.
7
+ *
8
+ * See https://github.com/GoogleChrome/workbox/issues/2235
9
+ *
10
+ * @param compilation The current webpack compilation.
11
+ * @param swContents The contents of the swSrc file, which may or
12
+ * may not include a valid sourcemap comment.
13
+ * @param swDest The configured swDest value.
14
+ * @returns If the swContents contains a valid sourcemap
15
+ * comment pointing to an asset present in the compilation, this will return the
16
+ * name of that asset. Otherwise, it will return undefined.
17
+ * @private
18
+ */
19
+ export declare function getSourcemapAssetName(compilation: Compilation, swContents: string, swDest: string): string | undefined;
20
+ //# sourceMappingURL=get-sourcemap-asset-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-sourcemap-asset-name.d.ts","sourceRoot":"","sources":["../../src/lib/get-sourcemap-asset-name.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiBtH"}