@wordpress/dependency-extraction-webpack-plugin 3.4.2 → 3.5.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,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.5.0 (2022-05-18)
6
+
7
+ ### Bug Fix
8
+
9
+ - Use OpenSSL provider supported in Node 17+ when calling `crypto.createHash` ([#40503](https://github.com/WordPress/gutenberg/pull/40503)).
10
+ - Add new line at the end of generated `*.asset.php` files ([#40753](https://github.com/WordPress/gutenberg/pull/40753)).
11
+ - Calculate version hashes based on output file contents rather than input files and other Webpack internal state ([#34969](https://github.com/WordPress/gutenberg/pull/34969)).
12
+
5
13
  ## 3.3.0 (2022-01-27)
6
14
 
7
15
  - Add the optional `externalizedReportFile` option ([#35106](https://github.com/WordPress/gutenberg/pull/35106)).
package/lib/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- const { createHash } = require( 'crypto' );
5
4
  const path = require( 'path' );
6
5
  const webpack = require( 'webpack' );
7
6
  // In webpack 5 there is a `webpack.sources` field but for webpack 4 we have to fallback to the `webpack-sources` package.
8
7
  const { RawSource } = webpack.sources || require( 'webpack-sources' );
9
8
  const json2php = require( 'json2php' );
10
9
  const isWebpack4 = webpack.version.startsWith( '4.' );
10
+ const { createHash } = webpack.util;
11
11
 
12
12
  /**
13
13
  * Internal dependencies
@@ -106,7 +106,7 @@ class DependencyExtractionWebpackPlugin {
106
106
  if ( this.options.outputFormat === 'php' ) {
107
107
  return `<?php return ${ json2php(
108
108
  JSON.parse( JSON.stringify( asset ) )
109
- ) };`;
109
+ ) };\n`;
110
110
  }
111
111
 
112
112
  return JSON.stringify( asset );
@@ -128,7 +128,7 @@ class DependencyExtractionWebpackPlugin {
128
128
  name: this.constructor.name,
129
129
  stage:
130
130
  compiler.webpack.Compilation
131
- .PROCESS_ASSETS_STAGE_ADDITIONAL,
131
+ .PROCESS_ASSETS_STAGE_ANALYSE,
132
132
  },
133
133
  () => this.addAssets( compilation, compiler )
134
134
  );
@@ -198,6 +198,27 @@ class DependencyExtractionWebpackPlugin {
198
198
  }
199
199
  }
200
200
 
201
+ const {
202
+ hashFunction,
203
+ hashDigest,
204
+ hashDigestLength,
205
+ } = compilation.outputOptions;
206
+
207
+ // Go through the assets and hash the sources. We can't just use
208
+ // `entrypointChunk.contentHash` because that's not updated when
209
+ // assets are minified. In practice the hash is updated by
210
+ // `RealContentHashPlugin` after minification, but it only modifies
211
+ // already-produced asset filenames and the updated hash is not
212
+ // available to plugins.
213
+ const hash = createHash( hashFunction );
214
+ for ( const filename of entrypoint.getFiles().sort() ) {
215
+ const asset = compilation.getAsset( filename );
216
+ hash.update( asset.source.buffer() );
217
+ }
218
+ const version = hash
219
+ .digest( hashDigest )
220
+ .slice( 0, hashDigestLength );
221
+
201
222
  const entrypointChunk = isWebpack4
202
223
  ? entrypoint.chunks.find( ( c ) => c.name === entrypointName )
203
224
  : entrypoint.getEntrypointChunk();
@@ -205,10 +226,14 @@ class DependencyExtractionWebpackPlugin {
205
226
  const assetData = {
206
227
  // Get a sorted array so we can produce a stable, stringified representation.
207
228
  dependencies: Array.from( entrypointExternalizedWpDeps ).sort(),
208
- version: entrypointChunk.hash,
229
+ version,
209
230
  };
210
231
 
211
232
  const assetString = this.stringify( assetData );
233
+ const contentHash = createHash( hashFunction )
234
+ .update( assetString )
235
+ .digest( hashDigest )
236
+ .slice( 0, hashDigestLength );
212
237
 
213
238
  // Determine a filename for the asset file.
214
239
  const [ filename, query ] = entrypointName.split( '?', 2 );
@@ -219,9 +244,7 @@ class DependencyExtractionWebpackPlugin {
219
244
  filename,
220
245
  query,
221
246
  basename: basename( filename ),
222
- contentHash: createHash( 'md4' )
223
- .update( assetString )
224
- .digest( 'hex' ),
247
+ contentHash,
225
248
  }
226
249
  );
227
250
 
@@ -238,9 +261,7 @@ class DependencyExtractionWebpackPlugin {
238
261
  filename,
239
262
  query,
240
263
  basename: basename( filename ),
241
- contentHash: createHash( 'md4' )
242
- .update( assetString )
243
- .digest( 'hex' ),
264
+ contentHash,
244
265
  } );
245
266
  } else {
246
267
  assetFilename = buildFilename.replace(
package/lib/types.d.ts CHANGED
@@ -11,7 +11,7 @@ declare interface DependencyExtractionWebpackPluginOptions {
11
11
  injectPolyfill?: boolean;
12
12
  useDefaults?: boolean;
13
13
  outputFormat?: 'php' | 'json';
14
- outputFilename?: string | Function,
14
+ outputFilename?: string | Function;
15
15
  requestToExternal?: ( request: string ) => string | string[] | undefined;
16
16
  requestToHandle?: ( request: string ) => string | undefined;
17
17
  combinedOutputFile?: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dependency-extraction-webpack-plugin",
3
- "version": "3.4.2",
3
+ "version": "3.5.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",
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "446565ecaa40370173c18926535e975ec5652b71"
41
+ "gitHead": "198fa129cf1af8dc615918987ea6795cd40ab7df"
42
42
  }