@wordpress/dependency-extraction-webpack-plugin 3.2.2-next.5df0cd52b7.0 → 3.2.3-next.33ec3857e2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.2.2-next.0 (2021-12-20)
6
+
7
+ - Add the optional `externalizedReportFile` option ([#35106](https://github.com/WordPress/gutenberg/pull/35106)).
8
+
5
9
  ## 3.0.0 (2021-01-21)
6
10
 
7
11
  ### Breaking Changes
package/README.md CHANGED
@@ -107,6 +107,13 @@ module.exports = {
107
107
 
108
108
  The output format for the generated asset file. There are two options available: 'php' or 'json'.
109
109
 
110
+ ##### `outputFilename`
111
+
112
+ - Type: string | function
113
+ - Default: null
114
+
115
+ The filename for the generated asset file. Accepts the same values as the Webpack `output.filename` option.
116
+
110
117
  ##### `combineAssets`
111
118
 
112
119
  - Type: boolean
@@ -135,6 +142,14 @@ Pass `useDefaults: false` to disable the default request handling.
135
142
 
136
143
  Force `wp-polyfill` to be included in each entry point's dependency list. This would be the same as adding `import '@wordpress/polyfill';` to each entry point.
137
144
 
145
+ ##### `externalizedReport`
146
+
147
+ - Type: boolean | string
148
+ - Default: `false`
149
+
150
+ Report all externalized dependencies as an array in JSON format. It could be used for further manual or automated inspection.
151
+ You can provide a filename, or set it to `true` to report to a default `externalized-dependencies.json`.
152
+
138
153
  ##### `requestToExternal`
139
154
 
140
155
  - Type: function
package/lib/index.js CHANGED
@@ -17,14 +17,18 @@ const {
17
17
  defaultRequestToHandle,
18
18
  } = require( './util' );
19
19
 
20
+ const defaultExternalizedReportFileName = 'externalized-dependencies.json';
21
+
20
22
  class DependencyExtractionWebpackPlugin {
21
23
  constructor( options ) {
22
24
  this.options = Object.assign(
23
25
  {
24
26
  combineAssets: false,
25
27
  combinedOutputFile: null,
28
+ externalizedReport: false,
26
29
  injectPolyfill: false,
27
30
  outputFormat: 'php',
31
+ outputFilename: null,
28
32
  useDefaults: true,
29
33
  },
30
34
  options
@@ -137,10 +141,26 @@ class DependencyExtractionWebpackPlugin {
137
141
  const {
138
142
  combineAssets,
139
143
  combinedOutputFile,
144
+ externalizedReport,
140
145
  injectPolyfill,
141
146
  outputFormat,
147
+ outputFilename,
142
148
  } = this.options;
143
149
 
150
+ // Dump actually externalized dependencies to a report file.
151
+ if ( externalizedReport ) {
152
+ const externalizedReportFile =
153
+ typeof externalizedReport === 'string'
154
+ ? externalizedReport
155
+ : defaultExternalizedReportFileName;
156
+ compilation.emitAsset(
157
+ externalizedReportFile,
158
+ new RawSource(
159
+ JSON.stringify( Array.from( this.externalizedDeps ).sort() )
160
+ )
161
+ );
162
+ }
163
+
144
164
  const combinedAssetsData = {};
145
165
 
146
166
  // Process each entry point independently.
@@ -178,12 +198,14 @@ class DependencyExtractionWebpackPlugin {
178
198
  }
179
199
  }
180
200
 
181
- const runtimeChunk = entrypoint.getRuntimeChunk();
201
+ const entrypointChunk = isWebpack4
202
+ ? entrypoint.chunks.find( ( c ) => c.name === entrypointName )
203
+ : entrypoint.getEntrypointChunk();
182
204
 
183
205
  const assetData = {
184
206
  // Get a sorted array so we can produce a stable, stringified representation.
185
207
  dependencies: Array.from( entrypointExternalizedWpDeps ).sort(),
186
- version: runtimeChunk.hash,
208
+ version: entrypointChunk.hash,
187
209
  };
188
210
 
189
211
  const assetString = this.stringify( assetData );
@@ -193,7 +215,7 @@ class DependencyExtractionWebpackPlugin {
193
215
  const buildFilename = compilation.getPath(
194
216
  compiler.options.output.filename,
195
217
  {
196
- chunk: runtimeChunk,
218
+ chunk: entrypointChunk,
197
219
  filename,
198
220
  query,
199
221
  basename: basename( filename ),
@@ -208,14 +230,30 @@ class DependencyExtractionWebpackPlugin {
208
230
  continue;
209
231
  }
210
232
 
211
- const assetFilename = buildFilename.replace(
212
- /\.js$/i,
213
- '.asset.' + ( outputFormat === 'php' ? 'php' : 'json' )
214
- );
233
+ let assetFilename;
234
+
235
+ if ( outputFilename ) {
236
+ assetFilename = compilation.getPath( outputFilename, {
237
+ chunk: entrypointChunk,
238
+ filename,
239
+ query,
240
+ basename: basename( filename ),
241
+ contentHash: createHash( 'md4' )
242
+ .update( assetString )
243
+ .digest( 'hex' ),
244
+ } );
245
+ } else {
246
+ assetFilename = buildFilename.replace(
247
+ /\.js$/i,
248
+ '.asset.' + ( outputFormat === 'php' ? 'php' : 'json' )
249
+ );
250
+ }
215
251
 
216
252
  // Add source and file into compilation for webpack to output.
217
253
  compilation.assets[ assetFilename ] = new RawSource( assetString );
218
- runtimeChunk.files[ isWebpack4 ? 'push' : 'add' ]( assetFilename );
254
+ entrypointChunk.files[ isWebpack4 ? 'push' : 'add' ](
255
+ assetFilename
256
+ );
219
257
  }
220
258
 
221
259
  if ( combineAssets ) {
package/lib/types.d.ts CHANGED
@@ -11,8 +11,10 @@ declare interface DependencyExtractionWebpackPluginOptions {
11
11
  injectPolyfill?: boolean;
12
12
  useDefaults?: boolean;
13
13
  outputFormat?: 'php' | 'json';
14
+ outputFilename?: string | Function,
14
15
  requestToExternal?: ( request: string ) => string | string[] | undefined;
15
16
  requestToHandle?: ( request: string ) => string | undefined;
16
17
  combinedOutputFile?: string | null;
17
18
  combineAssets?: boolean;
19
+ externalizedReportFile?: string | undefined;
18
20
  }
package/lib/util.js CHANGED
@@ -34,6 +34,10 @@ function defaultRequestToExternal( request ) {
34
34
  return 'ReactDOM';
35
35
  }
36
36
 
37
+ if ( request.includes( 'react-refresh/runtime' ) ) {
38
+ return 'ReactRefreshRuntime';
39
+ }
40
+
37
41
  if ( BUNDLED_PACKAGES.includes( request ) ) {
38
42
  return undefined;
39
43
  }
@@ -66,6 +70,10 @@ function defaultRequestToHandle( request ) {
66
70
  return 'lodash';
67
71
  }
68
72
 
73
+ if ( request.includes( 'react-refresh/runtime' ) ) {
74
+ return 'wp-react-refresh-runtime';
75
+ }
76
+
69
77
  if ( request.startsWith( WORDPRESS_NAMESPACE ) ) {
70
78
  return 'wp-' + request.substring( WORDPRESS_NAMESPACE.length );
71
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dependency-extraction-webpack-plugin",
3
- "version": "3.2.2-next.5df0cd52b7.0",
3
+ "version": "3.2.3-next.33ec3857e2.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",
@@ -30,7 +30,7 @@
30
30
  "types": "lib/types.d.ts",
31
31
  "dependencies": {
32
32
  "json2php": "^0.0.4",
33
- "webpack-sources": "^2.2.0"
33
+ "webpack-sources": "^3.2.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "webpack": "^4.8.3 || ^5.0.0"
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "558d577d12bec15f05e694eb49a094836d885cca"
41
+ "gitHead": "51c7917ea7fac72953702f24d6daac87d99e7617"
42
42
  }