@wordpress/dependency-extraction-webpack-plugin 3.4.1 → 3.6.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 +8 -0
- package/lib/index.js +34 -17
- package/lib/types.d.ts +1 -1
- package/package.json +2 -2
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 );
|
|
@@ -126,9 +126,8 @@ class DependencyExtractionWebpackPlugin {
|
|
|
126
126
|
compilation.hooks.processAssets.tap(
|
|
127
127
|
{
|
|
128
128
|
name: this.constructor.name,
|
|
129
|
-
stage:
|
|
130
|
-
|
|
131
|
-
.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
|
129
|
+
stage: compiler.webpack.Compilation
|
|
130
|
+
.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
132
131
|
},
|
|
133
132
|
() => this.addAssets( compilation, compiler )
|
|
134
133
|
);
|
|
@@ -175,9 +174,8 @@ class DependencyExtractionWebpackPlugin {
|
|
|
175
174
|
|
|
176
175
|
const processModule = ( { userRequest } ) => {
|
|
177
176
|
if ( this.externalizedDeps.has( userRequest ) ) {
|
|
178
|
-
const scriptDependency =
|
|
179
|
-
userRequest
|
|
180
|
-
);
|
|
177
|
+
const scriptDependency =
|
|
178
|
+
this.mapRequestToDependency( userRequest );
|
|
181
179
|
entrypointExternalizedWpDeps.add( scriptDependency );
|
|
182
180
|
}
|
|
183
181
|
};
|
|
@@ -198,6 +196,24 @@ class DependencyExtractionWebpackPlugin {
|
|
|
198
196
|
}
|
|
199
197
|
}
|
|
200
198
|
|
|
199
|
+
const { hashFunction, hashDigest, hashDigestLength } =
|
|
200
|
+
compilation.outputOptions;
|
|
201
|
+
|
|
202
|
+
// Go through the assets and hash the sources. We can't just use
|
|
203
|
+
// `entrypointChunk.contentHash` because that's not updated when
|
|
204
|
+
// assets are minified. In practice the hash is updated by
|
|
205
|
+
// `RealContentHashPlugin` after minification, but it only modifies
|
|
206
|
+
// already-produced asset filenames and the updated hash is not
|
|
207
|
+
// available to plugins.
|
|
208
|
+
const hash = createHash( hashFunction );
|
|
209
|
+
for ( const filename of entrypoint.getFiles().sort() ) {
|
|
210
|
+
const asset = compilation.getAsset( filename );
|
|
211
|
+
hash.update( asset.source.buffer() );
|
|
212
|
+
}
|
|
213
|
+
const version = hash
|
|
214
|
+
.digest( hashDigest )
|
|
215
|
+
.slice( 0, hashDigestLength );
|
|
216
|
+
|
|
201
217
|
const entrypointChunk = isWebpack4
|
|
202
218
|
? entrypoint.chunks.find( ( c ) => c.name === entrypointName )
|
|
203
219
|
: entrypoint.getEntrypointChunk();
|
|
@@ -205,10 +221,14 @@ class DependencyExtractionWebpackPlugin {
|
|
|
205
221
|
const assetData = {
|
|
206
222
|
// Get a sorted array so we can produce a stable, stringified representation.
|
|
207
223
|
dependencies: Array.from( entrypointExternalizedWpDeps ).sort(),
|
|
208
|
-
version
|
|
224
|
+
version,
|
|
209
225
|
};
|
|
210
226
|
|
|
211
227
|
const assetString = this.stringify( assetData );
|
|
228
|
+
const contentHash = createHash( hashFunction )
|
|
229
|
+
.update( assetString )
|
|
230
|
+
.digest( hashDigest )
|
|
231
|
+
.slice( 0, hashDigestLength );
|
|
212
232
|
|
|
213
233
|
// Determine a filename for the asset file.
|
|
214
234
|
const [ filename, query ] = entrypointName.split( '?', 2 );
|
|
@@ -219,9 +239,7 @@ class DependencyExtractionWebpackPlugin {
|
|
|
219
239
|
filename,
|
|
220
240
|
query,
|
|
221
241
|
basename: basename( filename ),
|
|
222
|
-
contentHash
|
|
223
|
-
.update( assetString )
|
|
224
|
-
.digest( 'hex' ),
|
|
242
|
+
contentHash,
|
|
225
243
|
}
|
|
226
244
|
);
|
|
227
245
|
|
|
@@ -238,9 +256,7 @@ class DependencyExtractionWebpackPlugin {
|
|
|
238
256
|
filename,
|
|
239
257
|
query,
|
|
240
258
|
basename: basename( filename ),
|
|
241
|
-
contentHash
|
|
242
|
-
.update( assetString )
|
|
243
|
-
.digest( 'hex' ),
|
|
259
|
+
contentHash,
|
|
244
260
|
} );
|
|
245
261
|
} else {
|
|
246
262
|
assetFilename = buildFilename.replace(
|
|
@@ -261,8 +277,9 @@ class DependencyExtractionWebpackPlugin {
|
|
|
261
277
|
// The type indicates the option may be `undefined`.
|
|
262
278
|
// However, at this point in compilation, webpack has filled the options in if
|
|
263
279
|
// they were not provided.
|
|
264
|
-
const outputFolder = /** @type {{path:string}} */ (
|
|
265
|
-
.output
|
|
280
|
+
const outputFolder = /** @type {{path:string}} */ (
|
|
281
|
+
compiler.options.output
|
|
282
|
+
).path;
|
|
266
283
|
|
|
267
284
|
const assetsFilePath = path.resolve(
|
|
268
285
|
outputFolder,
|
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.
|
|
3
|
+
"version": "3.6.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": "
|
|
41
|
+
"gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
|
|
42
42
|
}
|