@wordpress/dependency-extraction-webpack-plugin 6.7.1-next.5368f64a9.0 → 6.8.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.
Files changed (2) hide show
  1. package/lib/index.js +27 -7
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -269,7 +269,7 @@ class DependencyExtractionWebpackPlugin {
269
269
  }
270
270
  }
271
271
 
272
- // Go through the assets and hash the sources. We can't just use
272
+ // Prepare to hash the sources. We can't just use
273
273
  // `chunk.contentHash` because that's not updated when
274
274
  // assets are minified. In practice the hash is updated by
275
275
  // `RealContentHashPlugin` after minification, but it only modifies
@@ -278,12 +278,32 @@ class DependencyExtractionWebpackPlugin {
278
278
  const { hashFunction, hashDigest, hashDigestLength } =
279
279
  compilation.outputOptions;
280
280
 
281
- const contentHash = chunkFiles
282
- .sort()
283
- .reduce( ( hash, filename ) => {
284
- const asset = compilation.getAsset( filename );
285
- return hash.update( asset.source.buffer() );
286
- }, createHash( hashFunction ) )
281
+ const hashBuilder = createHash( hashFunction );
282
+
283
+ const processContentsForHash = ( content ) => {
284
+ hashBuilder.update( content );
285
+ };
286
+
287
+ // Prepare to look for magic comments, in order to decide whether
288
+ // `wp-polyfill` is needed.
289
+ const processContentsForMagicComments = ( content ) => {
290
+ if ( content.includes( '/* wp:polyfill */' ) ) {
291
+ chunkStaticDeps.add( 'wp-polyfill' );
292
+ }
293
+ };
294
+
295
+ // Go through the assets to process the sources.
296
+ // This allows us to generate hashes, as well as look for magic comments.
297
+ chunkFiles.sort().forEach( ( filename ) => {
298
+ const asset = compilation.getAsset( filename );
299
+ const content = asset.source.buffer();
300
+
301
+ processContentsForHash( content );
302
+ processContentsForMagicComments( content );
303
+ } );
304
+
305
+ // Finalise hash.
306
+ const contentHash = hashBuilder
287
307
  .digest( hashDigest )
288
308
  .slice( 0, hashDigestLength );
289
309
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dependency-extraction-webpack-plugin",
3
- "version": "6.7.1-next.5368f64a9.0",
3
+ "version": "6.8.1",
4
4
  "description": "Extract WordPress script dependencies from webpack bundles.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "24934a1f5251bbee15045d1fd953d9c5650317cd"
41
+ "gitHead": "cf707c1f25a2716e310cc8f9afcc8554405c79ac"
42
42
  }