@wordpress/dependency-extraction-webpack-plugin 6.50.0 → 6.51.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.
Files changed (2) hide show
  1. package/lib/index.js +55 -10
  2. package/package.json +5 -3
package/lib/index.js CHANGED
@@ -296,12 +296,24 @@ class DependencyExtractionWebpackPlugin {
296
296
 
297
297
  /**
298
298
  * @param {webpack.Module} m
299
+ * @param {boolean} [fromAsyncChunk] Module was found in an
300
+ * async chunk of the entry.
299
301
  */
300
- const processModule = ( m ) => {
302
+ const processModule = ( m, fromAsyncChunk ) => {
301
303
  const { userRequest } = m;
302
304
  if ( this.externalizedDeps.has( userRequest ) ) {
303
305
  if ( this.useModules ) {
306
+ // A static occurrence (in the entry chunk) wins.
307
+ if (
308
+ fromAsyncChunk &&
309
+ chunkStaticDeps.has( m.request )
310
+ ) {
311
+ return;
312
+ }
313
+ // Externals in an async chunk are reached via a dynamic
314
+ // import by definition.
304
315
  const isStatic =
316
+ ! fromAsyncChunk &&
305
317
  DependencyExtractionWebpackPlugin.hasStaticDependencyPathToRoot(
306
318
  compilation,
307
319
  m
@@ -318,16 +330,49 @@ class DependencyExtractionWebpackPlugin {
318
330
  }
319
331
  };
320
332
 
321
- // Search for externalized modules in all chunks.
322
- for ( const chunkModule of compilation.chunkGraph.getChunkModulesIterable(
323
- chunk
324
- ) ) {
325
- processModule( chunkModule );
326
- // Loop through submodules of ConcatenatedModule.
327
- if ( chunkModule.modules ) {
328
- for ( const concatModule of chunkModule.modules ) {
329
- processModule( concatModule );
333
+ /**
334
+ * @param {webpack.Chunk} searchChunk
335
+ * @param {boolean} [fromAsyncChunk]
336
+ */
337
+ const processChunkModules = ( searchChunk, fromAsyncChunk ) => {
338
+ for ( const chunkModule of compilation.chunkGraph.getChunkModulesIterable(
339
+ searchChunk
340
+ ) ) {
341
+ processModule( chunkModule, fromAsyncChunk );
342
+ // Loop through submodules of ConcatenatedModule.
343
+ if ( chunkModule.modules ) {
344
+ for ( const concatModule of chunkModule.modules ) {
345
+ processModule( concatModule, fromAsyncChunk );
346
+ }
347
+ }
348
+ }
349
+ };
350
+
351
+ processChunkModules( chunk );
352
+
353
+ /*
354
+ * Also search the entry's async chunks: webpack can code-split a
355
+ * dynamically imported external into its own chunk.
356
+ */
357
+ for ( const group of chunk.groupsIterable ) {
358
+ if (
359
+ typeof group.getEntrypointChunk !== 'function' ||
360
+ group.getEntrypointChunk() !== chunk
361
+ ) {
362
+ continue;
363
+ }
364
+ const seenGroups = new Set();
365
+ const groupQueue = [ ...group.getChildren() ];
366
+ while ( groupQueue.length ) {
367
+ const childGroup = groupQueue.pop();
368
+ if ( seenGroups.has( childGroup ) ) {
369
+ continue;
370
+ }
371
+ seenGroups.add( childGroup );
372
+ for ( const asyncChunk of childGroup.chunks ) {
373
+ processChunkModules( asyncChunk, true );
330
374
  }
375
+ groupQueue.push( ...childGroup.getChildren() );
331
376
  }
332
377
  }
333
378
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dependency-extraction-webpack-plugin",
3
- "version": "6.50.0",
3
+ "version": "6.51.0",
4
4
  "description": "Extract WordPress script dependencies from webpack bundles.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -46,7 +46,9 @@
46
46
  "glob": "^7.1.2",
47
47
  "lodash": "^4.17.21",
48
48
  "mini-css-extract-plugin": "^2.9.2",
49
- "mkdirp": "^3.0.1"
49
+ "mkdirp": "^3.0.1",
50
+ "rimraf": "^5.0.10",
51
+ "webpack": "^5.108.1"
50
52
  },
51
53
  "peerDependencies": {
52
54
  "webpack": "^5.0.0"
@@ -54,5 +56,5 @@
54
56
  "publishConfig": {
55
57
  "access": "public"
56
58
  },
57
- "gitHead": "fee6e24e8e63d36f6bbcf487c193461e9bd79753"
59
+ "gitHead": "e9a74f9c14095a34398ecd4d1f7a908e55051205"
58
60
  }