@serwist/webpack-plugin 9.0.0-preview.0 → 9.0.0-preview.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,9 @@
1
1
  import upath from 'upath';
2
2
 
3
- /**
4
- * @param compilation The webpack compilation.
5
- * @param path The original path value.
6
- *
7
- * @returns If path was not absolute, the returns path as-is.
8
- * Otherwise, returns path relative to the compilation's output path.
9
- *
10
- * @private
11
- */ const relativeToOutputPath = (compilation, path)=>{
12
- // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
3
+ const relativeToOutputPath = (compilation, path)=>{
13
4
  if (upath.resolve(path) === upath.normalize(path)) {
14
5
  return upath.relative(compilation.options.output.path, path);
15
6
  }
16
- // Otherwise, return swDest as-is.
17
7
  return path;
18
8
  };
19
9
 
@@ -2,11 +2,7 @@ import webpack from 'webpack';
2
2
  import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
3
3
  import 'upath';
4
4
 
5
- /**
6
- * Compile a file by creating a child of the hooked compiler.
7
- *
8
- * @private
9
- */ class ChildCompilationPlugin {
5
+ class ChildCompilationPlugin {
10
6
  src;
11
7
  dest;
12
8
  plugins;
package/dist/index.js CHANGED
@@ -1,148 +1,19 @@
1
1
  import { transformManifest, getSourceMapURL, validateWebpackInjectManifestOptions, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build';
2
2
  import stringify from 'fast-json-stable-stringify';
3
+ import prettyBytes from 'pretty-bytes';
3
4
  import upath from 'upath';
4
5
  import webpack from 'webpack';
5
6
  import crypto from 'crypto';
6
7
  import { r as relativeToOutputPath } from './chunks/relative-to-output-path.js';
7
8
 
8
- const BYTE_UNITS = [
9
- 'B',
10
- 'kB',
11
- 'MB',
12
- 'GB',
13
- 'TB',
14
- 'PB',
15
- 'EB',
16
- 'ZB',
17
- 'YB'
18
- ];
19
- const BIBYTE_UNITS = [
20
- 'B',
21
- 'KiB',
22
- 'MiB',
23
- 'GiB',
24
- 'TiB',
25
- 'PiB',
26
- 'EiB',
27
- 'ZiB',
28
- 'YiB'
29
- ];
30
- const BIT_UNITS = [
31
- 'b',
32
- 'kbit',
33
- 'Mbit',
34
- 'Gbit',
35
- 'Tbit',
36
- 'Pbit',
37
- 'Ebit',
38
- 'Zbit',
39
- 'Ybit'
40
- ];
41
- const BIBIT_UNITS = [
42
- 'b',
43
- 'kibit',
44
- 'Mibit',
45
- 'Gibit',
46
- 'Tibit',
47
- 'Pibit',
48
- 'Eibit',
49
- 'Zibit',
50
- 'Yibit'
51
- ];
52
- /*
53
- Formats the given number using `Number#toLocaleString`.
54
- - If locale is a string, the value is expected to be a locale-key (for example: `de`).
55
- - If locale is true, the system default locale is used for translation.
56
- - If no value for locale is specified, the number is returned unmodified.
57
- */ const toLocaleString = (number, locale, options)=>{
58
- let result = number;
59
- if (typeof locale === 'string' || Array.isArray(locale)) {
60
- result = number.toLocaleString(locale, options);
61
- } else if (locale === true || options !== undefined) {
62
- result = number.toLocaleString(undefined, options);
63
- }
64
- return result;
65
- };
66
- function prettyBytes(number, options) {
67
- if (!Number.isFinite(number)) {
68
- throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
69
- }
70
- options = {
71
- bits: false,
72
- binary: false,
73
- space: true,
74
- ...options
75
- };
76
- const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
77
- const separator = options.space ? ' ' : '';
78
- if (options.signed && number === 0) {
79
- return ` 0${separator}${UNITS[0]}`;
80
- }
81
- const isNegative = number < 0;
82
- const prefix = isNegative ? '-' : options.signed ? '+' : '';
83
- if (isNegative) {
84
- number = -number;
85
- }
86
- let localeOptions;
87
- if (options.minimumFractionDigits !== undefined) {
88
- localeOptions = {
89
- minimumFractionDigits: options.minimumFractionDigits
90
- };
91
- }
92
- if (options.maximumFractionDigits !== undefined) {
93
- localeOptions = {
94
- maximumFractionDigits: options.maximumFractionDigits,
95
- ...localeOptions
96
- };
97
- }
98
- if (number < 1) {
99
- const numberString = toLocaleString(number, options.locale, localeOptions);
100
- return prefix + numberString + separator + UNITS[0];
101
- }
102
- const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
103
- number /= (options.binary ? 1024 : 1000) ** exponent;
104
- if (!localeOptions) {
105
- number = number.toPrecision(3);
106
- }
107
- const numberString = toLocaleString(Number(number), options.locale, localeOptions);
108
- const unit = UNITS[exponent];
109
- return prefix + numberString + separator + unit;
110
- }
111
-
112
- /**
113
- * @param asset
114
- * @returns The MD5 hash of the asset's source.
115
- *
116
- * @private
117
- */ const getAssetHash = (asset)=>{
118
- // If webpack has the asset marked as immutable, then we don't need to
119
- // use an out-of-band revision for it.
120
- // See https://github.com/webpack/webpack/issues/9038
9
+ const getAssetHash = (asset)=>{
121
10
  if (asset.info?.immutable) {
122
11
  return null;
123
12
  }
124
13
  return crypto.createHash("md5").update(Buffer.from(asset.source.source())).digest("hex");
125
14
  };
126
15
 
127
- /*
128
- Copyright 2018 Google LLC
129
-
130
- Use of this source code is governed by an MIT-style
131
- license that can be found in the LICENSE file or at
132
- https://opensource.org/licenses/MIT.
133
- */ /**
134
- * Resolves a url in the way that webpack would (with string concatenation)
135
- *
136
- * Use publicPath + filePath instead of url.resolve(publicPath, filePath) see:
137
- * https://webpack.js.org/configuration/output/#output-publicpath
138
- *
139
- * @param publicPath The publicPath value from webpack's compilation.
140
- * @param paths File paths to join
141
- * @returns Joined file path
142
- * @private
143
- */ const resolveWebpackURL = (publicPath, ...paths)=>{
144
- // This is a change in webpack v5.
145
- // See https://github.com/jantimon/html-webpack-plugin/pull/1516
16
+ const resolveWebpackURL = (publicPath, ...paths)=>{
146
17
  if (publicPath === "auto") {
147
18
  return paths.join("");
148
19
  }
@@ -152,43 +23,21 @@ function prettyBytes(number, options) {
152
23
  ].join("");
153
24
  };
154
25
 
155
- /**
156
- * For a given asset, checks whether at least one of the conditions matches.
157
- *
158
- * @param asset The webpack asset in question. This will be passed
159
- * to any functions that are listed as conditions.
160
- * @param compilation The webpack compilation. This will be passed
161
- * to any functions that are listed as conditions.
162
- * @param conditions
163
- * @returns Whether or not at least one condition matches.
164
- * @private
165
- */ const checkConditions = (asset, compilation, conditions = [])=>{
26
+ const checkConditions = (asset, compilation, conditions = [])=>{
166
27
  for (const condition of conditions){
167
28
  if (typeof condition === "function") {
168
29
  return condition({
169
30
  asset,
170
31
  compilation
171
32
  });
172
- //return compilation !== null;
173
33
  }
174
34
  if (webpack.ModuleFilenameHelpers.matchPart(asset.name, condition)) {
175
35
  return true;
176
36
  }
177
37
  }
178
- // We'll only get here if none of the conditions applied.
179
38
  return false;
180
39
  };
181
- /**
182
- * Returns the names of all the assets in all the chunks in a chunk group,
183
- * if provided a chunk group name.
184
- * Otherwise, if provided a chunk name, return all the assets in that chunk.
185
- * Otherwise, if there isn't a chunk group or chunk with that name, return null.
186
- *
187
- * @param compilation
188
- * @param chunkOrGroup
189
- * @returns
190
- * @private
191
- */ const getNamesOfAssetsInChunkOrGroup = (compilation, chunkOrGroup)=>{
40
+ const getNamesOfAssetsInChunkOrGroup = (compilation, chunkOrGroup)=>{
192
41
  const chunkGroup = compilation.namedChunkGroups?.get(chunkOrGroup);
193
42
  if (chunkGroup) {
194
43
  const assetNames = [];
@@ -201,42 +50,22 @@ function prettyBytes(number, options) {
201
50
  if (chunk) {
202
51
  return getNamesOfAssetsInChunk(chunk);
203
52
  }
204
- // If we get here, there's no chunkGroup or chunk with that name.
205
53
  return null;
206
54
  };
207
- /**
208
- * Returns the names of all the assets in a chunk.
209
- *
210
- * @param chunk
211
- * @returns
212
- * @private
213
- */ const getNamesOfAssetsInChunk = (chunk)=>{
55
+ const getNamesOfAssetsInChunk = (chunk)=>{
214
56
  const assetNames = [];
215
57
  assetNames.push(...chunk.files);
216
- // This only appears to be set in webpack v5.
217
58
  if (chunk.auxiliaryFiles) {
218
59
  assetNames.push(...chunk.auxiliaryFiles);
219
60
  }
220
61
  return assetNames;
221
62
  };
222
- /**
223
- * Filters the set of assets out, based on the configuration options provided:
224
- * - chunks and excludeChunks, for chunkName-based criteria.
225
- * - include and exclude, for more general criteria.
226
- *
227
- * @param compilation The webpack compilation.
228
- * @param config The validated configuration, obtained from the plugin.
229
- * @returns The assets that should be included in the manifest,
230
- * based on the criteria provided.
231
- * @private
232
- */ const filterAssets = (compilation, config)=>{
63
+ const filterAssets = (compilation, config)=>{
233
64
  const filteredAssets = new Set();
234
65
  const assets = compilation.getAssets();
235
66
  const allowedAssetNames = new Set();
236
- // See https://github.com/GoogleChrome/workbox/issues/1287
237
67
  if (Array.isArray(config.chunks)) {
238
68
  for (const name of config.chunks){
239
- // See https://github.com/GoogleChrome/workbox/issues/2717
240
69
  const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);
241
70
  if (assetsInChunkOrGroup) {
242
71
  for (const assetName of assetsInChunkOrGroup){
@@ -250,40 +79,29 @@ function prettyBytes(number, options) {
250
79
  const deniedAssetNames = new Set();
251
80
  if (Array.isArray(config.excludeChunks)) {
252
81
  for (const name of config.excludeChunks){
253
- // See https://github.com/GoogleChrome/workbox/issues/2717
254
82
  const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);
255
83
  if (assetsInChunkOrGroup) {
256
84
  for (const assetName of assetsInChunkOrGroup){
257
85
  deniedAssetNames.add(assetName);
258
86
  }
259
- } // Don't warn if the chunk group isn't found.
87
+ }
260
88
  }
261
89
  }
262
90
  for (const asset of assets){
263
- // chunk based filtering is funky because:
264
- // - Each asset might belong to one or more chunks.
265
- // - If *any* of those chunk names match our config.excludeChunks,
266
- // then we skip that asset.
267
- // - If the config.chunks is defined *and* there's no match
268
- // between at least one of the chunkNames and one entry, then
269
- // we skip that assets as well.
270
91
  if (deniedAssetNames.has(asset.name)) {
271
92
  continue;
272
93
  }
273
94
  if (Array.isArray(config.chunks) && !allowedAssetNames.has(asset.name)) {
274
95
  continue;
275
96
  }
276
- // Next, check asset-level checks via includes/excludes:
277
97
  const isExcluded = checkConditions(asset, compilation, config.exclude);
278
98
  if (isExcluded) {
279
99
  continue;
280
100
  }
281
- // Treat an empty config.includes as an implicit inclusion.
282
101
  const isIncluded = !Array.isArray(config.include) || checkConditions(asset, compilation, config.include);
283
102
  if (!isIncluded) {
284
103
  continue;
285
104
  }
286
- // If we've gotten this far, then add the asset.
287
105
  filteredAssets.add(asset);
288
106
  }
289
107
  return filteredAssets;
@@ -307,11 +125,9 @@ const getManifestEntriesFromCompilation = async (compilation, config)=>{
307
125
  modifyURLPrefix: config.modifyURLPrefix,
308
126
  transformParam: compilation
309
127
  });
310
- // See https://github.com/GoogleChrome/workbox/issues/2790
311
128
  for (const warning of warnings){
312
129
  compilation.warnings.push(new Error(warning));
313
130
  }
314
- // Ensure that the entries are properly sorted by URL.
315
131
  const sortedEntries = manifestEntries?.sort((a, b)=>a.url === b.url ? 0 : a.url > b.url ? 1 : -1);
316
132
  return {
317
133
  size,
@@ -319,33 +135,11 @@ const getManifestEntriesFromCompilation = async (compilation, config)=>{
319
135
  };
320
136
  };
321
137
 
322
- /**
323
- * If our bundled swDest file contains a sourcemap, we would invalidate that
324
- * mapping if we just replaced injectionPoint with the stringified manifest.
325
- * Instead, we need to update the swDest contents as well as the sourcemap
326
- * at the same time.
327
- *
328
- * See https://github.com/GoogleChrome/workbox/issues/2235
329
- *
330
- * @param compilation The current webpack compilation.
331
- * @param swContents The contents of the swSrc file, which may or
332
- * may not include a valid sourcemap comment.
333
- * @param swDest The configured swDest value.
334
- * @returns If the swContents contains a valid sourcemap
335
- * comment pointing to an asset present in the compilation, this will return the
336
- * name of that asset. Otherwise, it will return undefined.
337
- * @private
338
- */ const getSourcemapAssetName = (compilation, swContents, swDest)=>{
138
+ const getSourcemapAssetName = (compilation, swContents, swDest)=>{
339
139
  const url = getSourceMapURL(swContents);
340
140
  if (url) {
341
- // Translate the relative URL to what the presumed name for the webpack
342
- // asset should be.
343
- // This *might* not be a valid asset if the sourcemap URL that was found
344
- // was added by another module incidentally.
345
- // See https://github.com/GoogleChrome/workbox/issues/2250
346
141
  const swAssetDirname = upath.dirname(swDest);
347
142
  const sourcemapURLAssetName = upath.normalize(upath.join(swAssetDirname, url));
348
- // Not sure if there's a better way to check for asset existence?
349
143
  if (compilation.getAsset(sourcemapURLAssetName)) {
350
144
  return sourcemapURLAssetName;
351
145
  }
@@ -353,58 +147,21 @@ const getManifestEntriesFromCompilation = async (compilation, config)=>{
353
147
  return undefined;
354
148
  };
355
149
 
356
- // Used to keep track of swDest files written by *any* instance of this plugin.
357
- // See https://github.com/GoogleChrome/workbox/issues/2181
358
150
  const _generatedAssetNames = new Set();
359
- /**
360
- * This class supports compiling a service worker file provided via `swSrc`,
361
- * and injecting into that service worker a list of URLs and revision
362
- * information for precaching based on the webpack asset pipeline.
363
- *
364
- * Use an instance of `InjectManifest` in the
365
- * [`plugins` array](https://webpack.js.org/concepts/plugins/#usage) of a
366
- * webpack config.
367
- *
368
- * In addition to injecting the manifest, this plugin will perform a compilation
369
- * of the `swSrc` file, using the options from the main webpack configuration.
370
- *
371
- * ```
372
- * // The following lists some common options; see the rest of the documentation
373
- * // for the full set of options and defaults.
374
- * new InjectManifest({
375
- * exclude: [/.../, '...'],
376
- * maximumFileSizeToCacheInBytes: ...,
377
- * swSrc: '...',
378
- * });
379
- * ```
380
- */ class InjectManifest {
151
+ class InjectManifest {
381
152
  config;
382
153
  alreadyCalled;
383
- /**
384
- * Creates an instance of InjectManifest.
385
- */ constructor(config){
154
+ constructor(config){
386
155
  this.config = config;
387
156
  this.alreadyCalled = false;
388
157
  }
389
- /**
390
- * @param compiler default compiler object passed from webpack
391
- *
392
- * @private
393
- */ propagateWebpackConfig(compiler) {
158
+ propagateWebpackConfig() {
394
159
  const parsedSwSrc = upath.parse(this.config.swSrc);
395
- // Because this.config is listed last, properties that are already set
396
- // there take precedence over derived properties from the compiler.
397
160
  this.config = Object.assign({
398
- mode: compiler.options.mode,
399
- // Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.
400
161
  swDest: `${parsedSwSrc.name}.js`
401
162
  }, this.config);
402
163
  }
403
- /**
404
- * `getManifestEntriesFromCompilation` with a few additional checks.
405
- *
406
- * @private
407
- */ async getManifestEntries(compilation, config) {
164
+ async getManifestEntries(compilation, config) {
408
165
  if (config.disablePrecacheManifest) {
409
166
  return {
410
167
  size: 0,
@@ -412,7 +169,6 @@ const _generatedAssetNames = new Set();
412
169
  manifestString: "undefined"
413
170
  };
414
171
  }
415
- // See https://github.com/GoogleChrome/workbox/issues/1790
416
172
  if (this.alreadyCalled) {
417
173
  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.`;
418
174
  if (!compilation.warnings.some((warning)=>warning instanceof Error && warning.message === warningMessage)) {
@@ -421,15 +177,10 @@ const _generatedAssetNames = new Set();
421
177
  } else {
422
178
  this.alreadyCalled = true;
423
179
  }
424
- // Ensure that we don't precache any of the assets generated by *any*
425
- // instance of this plugin.
426
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
427
180
  config.exclude.push(({ asset })=>_generatedAssetNames.has(asset.name));
428
181
  const { size, sortedEntries } = await getManifestEntriesFromCompilation(compilation, config);
429
182
  let manifestString = stringify(sortedEntries);
430
- if (this.config.compileSrc && // See https://github.com/GoogleChrome/workbox/issues/2729
431
- !(compilation.options?.devtool === "eval-cheap-source-map" && compilation.options.optimization?.minimize)) {
432
- // See https://github.com/GoogleChrome/workbox/issues/2263
183
+ if (this.config.compileSrc && !(compilation.options?.devtool === "eval-cheap-source-map" && compilation.options.optimization?.minimize)) {
433
184
  manifestString = manifestString.replace(/"/g, `'`);
434
185
  }
435
186
  return {
@@ -438,35 +189,22 @@ const _generatedAssetNames = new Set();
438
189
  manifestString
439
190
  };
440
191
  }
441
- /**
442
- * @param compiler default compiler object passed from webpack
443
- *
444
- * @private
445
- */ apply(compiler) {
446
- this.propagateWebpackConfig(compiler);
192
+ apply(compiler) {
193
+ this.propagateWebpackConfig();
447
194
  compiler.hooks.make.tapPromise(this.constructor.name, (compilation)=>this.handleMake(compilation, compiler).catch((error)=>{
448
195
  compilation.errors.push(error);
449
196
  }));
450
197
  const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = webpack.Compilation;
451
- // Specifically hook into thisCompilation, as per
452
- // https://github.com/webpack/webpack/issues/11425#issuecomment-690547848
453
198
  compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation)=>{
454
199
  compilation.hooks.processAssets.tapPromise({
455
200
  name: this.constructor.name,
456
- // TODO(jeffposnick): This may need to change eventually.
457
- // See https://github.com/webpack/webpack/issues/11822#issuecomment-726184972
458
201
  stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10
459
202
  }, ()=>this.addAssets(compilation).catch((error)=>{
460
203
  compilation.errors.push(error);
461
204
  }));
462
205
  });
463
206
  }
464
- /**
465
- * @param compilation The webpack compilation.
466
- * @param parentCompiler The webpack parent compiler.
467
- *
468
- * @private
469
- */ async performChildCompilation(compilation, parentCompiler) {
207
+ async performChildCompilation(compilation, parentCompiler) {
470
208
  const outputOptions = {
471
209
  filename: this.config.swDest
472
210
  };
@@ -492,22 +230,11 @@ const _generatedAssetNames = new Set();
492
230
  });
493
231
  });
494
232
  }
495
- /**
496
- * @param compilation The webpack compilation.
497
- * @param parentCompiler The webpack parent compiler.
498
- *
499
- * @private
500
- */ addSrcToAssets(compilation, parentCompiler) {
501
- // eslint-disable-next-line
233
+ addSrcToAssets(compilation, parentCompiler) {
502
234
  const source = parentCompiler.inputFileSystem.readFileSync(this.config.swSrc);
503
235
  compilation.emitAsset(this.config.swDest, new webpack.sources.RawSource(source));
504
236
  }
505
- /**
506
- * @param compilation The webpack compilation.
507
- * @param parentCompiler The webpack parent compiler.
508
- *
509
- * @private
510
- */ async handleMake(compilation, parentCompiler) {
237
+ async handleMake(compilation, parentCompiler) {
511
238
  this.config = await validateWebpackInjectManifestOptions(this.config);
512
239
  this.config.swDest = relativeToOutputPath(compilation, this.config.swDest);
513
240
  _generatedAssetNames.add(this.config.swDest);
@@ -515,21 +242,14 @@ const _generatedAssetNames = new Set();
515
242
  await this.performChildCompilation(compilation, parentCompiler);
516
243
  } else {
517
244
  this.addSrcToAssets(compilation, parentCompiler);
518
- // This used to be a fatal error, but just warn at runtime because we
519
- // can't validate it easily.
520
245
  if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {
521
246
  compilation.warnings.push(new Error("compileSrc is false, so the " + "webpackCompilationPlugins option will be ignored."));
522
247
  }
523
248
  }
524
249
  }
525
- /**
526
- * @param compilation The webpack compilation.
527
- *
528
- * @private
529
- */ async addAssets(compilation) {
250
+ async addAssets(compilation) {
530
251
  const config = Object.assign({}, this.config);
531
252
  const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);
532
- // See https://webpack.js.org/contribute/plugin-patterns/#monitoring-the-watch-graph
533
253
  const absoluteSwSrc = upath.resolve(config.swSrc);
534
254
  compilation.fileDependencies.add(absoluteSwSrc);
535
255
  const swAsset = compilation.getAsset(config.swDest);
@@ -548,7 +268,6 @@ const _generatedAssetNames = new Set();
548
268
  const sourcemapAsset = compilation.getAsset(sourcemapAssetName);
549
269
  const { source, map } = await replaceAndUpdateSourceMap({
550
270
  jsFilename: config.swDest,
551
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
552
271
  originalMap: JSON.parse(sourcemapAsset.source.source().toString()),
553
272
  originalSource: swAssetString,
554
273
  replaceString: manifestString,
@@ -557,8 +276,6 @@ const _generatedAssetNames = new Set();
557
276
  compilation.updateAsset(sourcemapAssetName, new webpack.sources.RawSource(map));
558
277
  compilation.updateAsset(config.swDest, new webpack.sources.RawSource(source));
559
278
  } else {
560
- // If there's no sourcemap associated with swDest, a simple string
561
- // replacement will suffice.
562
279
  compilation.updateAsset(config.swDest, new webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
563
280
  }
564
281
  if (compilation.getLogger) {
@@ -34,7 +34,7 @@ export declare class InjectManifest {
34
34
  *
35
35
  * @private
36
36
  */
37
- propagateWebpackConfig(compiler: webpack.Compiler): void;
37
+ propagateWebpackConfig(): void;
38
38
  /**
39
39
  * `getManifestEntriesFromCompilation` with a few additional checks.
40
40
  *
@@ -1 +1 @@
1
- {"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAMnE,OAAO,OAAO,MAAM,SAAS,CAAC;AAU9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAc;IACzB,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;;;;;;;;;IAwC/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;IAmBnG;;;;OAIG;IACG,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAmDjE"}
1
+ {"version":3,"file":"inject-manifest.d.ts","sourceRoot":"","sources":["../src/inject-manifest.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAMnE,OAAO,OAAO,MAAM,SAAS,CAAC;AAU9B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,cAAc;IACzB,SAAS,CAAC,MAAM,EAAE,4BAA4B,CAAC;IAC/C,OAAO,CAAC,aAAa,CAAU;IAE/B;;OAEG;gBACS,MAAM,EAAE,4BAA4B;IAKhD;;;;OAIG;IACH,sBAAsB,IAAI,IAAI;IAa9B;;;;OAIG;IACG,kBAAkB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,4BAA4B;;;;;;;;;IAwC/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;IAmBnG;;;;OAIG;IACG,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAmDjE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/webpack-plugin",
3
- "version": "9.0.0-preview.0",
3
+ "version": "9.0.0-preview.10",
4
4
  "type": "module",
5
5
  "description": "A plugin for your Webpack build process, helping you generate a manifest of local files that should be precached.",
6
6
  "files": [
@@ -47,17 +47,17 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "fast-json-stable-stringify": "2.1.0",
50
+ "pretty-bytes": "6.1.1",
50
51
  "upath": "2.0.1",
51
- "@serwist/build": "9.0.0-preview.0"
52
+ "@serwist/build": "9.0.0-preview.10"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@types/node": "20.11.16",
55
56
  "@types/webpack": "5.28.5",
56
- "pretty-bytes": "6.1.1",
57
57
  "rollup": "4.9.6",
58
- "typescript": "5.4.0-dev.20240203",
58
+ "typescript": "5.4.0-dev.20240206",
59
59
  "webpack": "5.90.1",
60
- "@serwist/constants": "9.0.0-preview.0"
60
+ "@serwist/constants": "9.0.0-preview.10"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "typescript": ">=5.0.0",
@@ -60,13 +60,12 @@ export class InjectManifest {
60
60
  *
61
61
  * @private
62
62
  */
63
- propagateWebpackConfig(compiler: webpack.Compiler): void {
63
+ propagateWebpackConfig(): void {
64
64
  const parsedSwSrc = upath.parse(this.config.swSrc);
65
65
  // Because this.config is listed last, properties that are already set
66
66
  // there take precedence over derived properties from the compiler.
67
67
  this.config = Object.assign(
68
68
  {
69
- mode: compiler.options.mode,
70
69
  // Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.
71
70
  swDest: `${parsedSwSrc.name}.js`,
72
71
  },
@@ -125,7 +124,7 @@ export class InjectManifest {
125
124
  * @private
126
125
  */
127
126
  apply(compiler: webpack.Compiler): void {
128
- this.propagateWebpackConfig(compiler);
127
+ this.propagateWebpackConfig();
129
128
 
130
129
  compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>
131
130
  this.handleMake(compilation, compiler).catch((error: webpack.WebpackError) => {