@wordpress/dependency-extraction-webpack-plugin 3.6.0 → 3.7.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 +6 -0
- package/lib/index.js +57 -86
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -117,7 +117,7 @@ class DependencyExtractionWebpackPlugin {
|
|
|
117
117
|
|
|
118
118
|
if ( isWebpack4 ) {
|
|
119
119
|
compiler.hooks.emit.tap( this.constructor.name, ( compilation ) =>
|
|
120
|
-
this.addAssets( compilation
|
|
120
|
+
this.addAssets( compilation )
|
|
121
121
|
);
|
|
122
122
|
} else {
|
|
123
123
|
compiler.hooks.thisCompilation.tap(
|
|
@@ -129,14 +129,14 @@ class DependencyExtractionWebpackPlugin {
|
|
|
129
129
|
stage: compiler.webpack.Compilation
|
|
130
130
|
.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
131
131
|
},
|
|
132
|
-
() => this.addAssets( compilation
|
|
132
|
+
() => this.addAssets( compilation )
|
|
133
133
|
);
|
|
134
134
|
}
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
addAssets( compilation
|
|
139
|
+
addAssets( compilation ) {
|
|
140
140
|
const {
|
|
141
141
|
combineAssets,
|
|
142
142
|
combinedOutputFile,
|
|
@@ -162,124 +162,102 @@ class DependencyExtractionWebpackPlugin {
|
|
|
162
162
|
|
|
163
163
|
const combinedAssetsData = {};
|
|
164
164
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
entrypoint
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
// Accumulate all entrypoint chunks, some of them shared
|
|
166
|
+
const entrypointChunks = new Set();
|
|
167
|
+
for ( const entrypoint of compilation.entrypoints.values() ) {
|
|
168
|
+
for ( const chunk of entrypoint.chunks ) {
|
|
169
|
+
entrypointChunks.add( chunk );
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Process each entrypoint chunk independently
|
|
174
|
+
for ( const chunk of entrypointChunks ) {
|
|
175
|
+
const chunkFiles = Array.from( chunk.files );
|
|
176
|
+
|
|
177
|
+
const chunkJSFile = chunkFiles.find( ( f ) => /\.js$/i.test( f ) );
|
|
178
|
+
if ( ! chunkJSFile ) {
|
|
179
|
+
// There's no JS file in this chunk, no work for us. Typically a `style.css` from cache group.
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const chunkDeps = new Set();
|
|
171
184
|
if ( injectPolyfill ) {
|
|
172
|
-
|
|
185
|
+
chunkDeps.add( 'wp-polyfill' );
|
|
173
186
|
}
|
|
174
187
|
|
|
175
188
|
const processModule = ( { userRequest } ) => {
|
|
176
189
|
if ( this.externalizedDeps.has( userRequest ) ) {
|
|
177
|
-
|
|
178
|
-
this.mapRequestToDependency( userRequest );
|
|
179
|
-
entrypointExternalizedWpDeps.add( scriptDependency );
|
|
190
|
+
chunkDeps.add( this.mapRequestToDependency( userRequest ) );
|
|
180
191
|
}
|
|
181
192
|
};
|
|
182
193
|
|
|
183
194
|
// Search for externalized modules in all chunks.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
processModule( concatModule );
|
|
194
|
-
}
|
|
195
|
+
const modulesIterable = isWebpack4
|
|
196
|
+
? chunk.modulesIterable
|
|
197
|
+
: compilation.chunkGraph.getChunkModules( chunk );
|
|
198
|
+
for ( const chunkModule of modulesIterable ) {
|
|
199
|
+
processModule( chunkModule );
|
|
200
|
+
// Loop through submodules of ConcatenatedModule.
|
|
201
|
+
if ( chunkModule.modules ) {
|
|
202
|
+
for ( const concatModule of chunkModule.modules ) {
|
|
203
|
+
processModule( concatModule );
|
|
195
204
|
}
|
|
196
205
|
}
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
const { hashFunction, hashDigest, hashDigestLength } =
|
|
200
|
-
compilation.outputOptions;
|
|
201
|
-
|
|
202
208
|
// Go through the assets and hash the sources. We can't just use
|
|
203
|
-
// `
|
|
209
|
+
// `chunk.contentHash` because that's not updated when
|
|
204
210
|
// assets are minified. In practice the hash is updated by
|
|
205
211
|
// `RealContentHashPlugin` after minification, but it only modifies
|
|
206
212
|
// already-produced asset filenames and the updated hash is not
|
|
207
213
|
// available to plugins.
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
const { hashFunction, hashDigest, hashDigestLength } =
|
|
215
|
+
compilation.outputOptions;
|
|
216
|
+
|
|
217
|
+
const contentHash = chunkFiles
|
|
218
|
+
.sort()
|
|
219
|
+
.reduce( ( hash, filename ) => {
|
|
220
|
+
const asset = compilation.getAsset( filename );
|
|
221
|
+
return hash.update( asset.source.buffer() );
|
|
222
|
+
}, createHash( hashFunction ) )
|
|
214
223
|
.digest( hashDigest )
|
|
215
224
|
.slice( 0, hashDigestLength );
|
|
216
225
|
|
|
217
|
-
const entrypointChunk = isWebpack4
|
|
218
|
-
? entrypoint.chunks.find( ( c ) => c.name === entrypointName )
|
|
219
|
-
: entrypoint.getEntrypointChunk();
|
|
220
|
-
|
|
221
226
|
const assetData = {
|
|
222
227
|
// Get a sorted array so we can produce a stable, stringified representation.
|
|
223
|
-
dependencies: Array.from(
|
|
224
|
-
version,
|
|
228
|
+
dependencies: Array.from( chunkDeps ).sort(),
|
|
229
|
+
version: contentHash,
|
|
225
230
|
};
|
|
226
231
|
|
|
227
|
-
const assetString = this.stringify( assetData );
|
|
228
|
-
const contentHash = createHash( hashFunction )
|
|
229
|
-
.update( assetString )
|
|
230
|
-
.digest( hashDigest )
|
|
231
|
-
.slice( 0, hashDigestLength );
|
|
232
|
-
|
|
233
|
-
// Determine a filename for the asset file.
|
|
234
|
-
const [ filename, query ] = entrypointName.split( '?', 2 );
|
|
235
|
-
const buildFilename = compilation.getPath(
|
|
236
|
-
compiler.options.output.filename,
|
|
237
|
-
{
|
|
238
|
-
chunk: entrypointChunk,
|
|
239
|
-
filename,
|
|
240
|
-
query,
|
|
241
|
-
basename: basename( filename ),
|
|
242
|
-
contentHash,
|
|
243
|
-
}
|
|
244
|
-
);
|
|
245
|
-
|
|
246
232
|
if ( combineAssets ) {
|
|
247
|
-
combinedAssetsData[
|
|
233
|
+
combinedAssetsData[ chunkJSFile ] = assetData;
|
|
248
234
|
continue;
|
|
249
235
|
}
|
|
250
236
|
|
|
251
237
|
let assetFilename;
|
|
252
|
-
|
|
253
238
|
if ( outputFilename ) {
|
|
254
239
|
assetFilename = compilation.getPath( outputFilename, {
|
|
255
|
-
chunk
|
|
256
|
-
filename,
|
|
257
|
-
query,
|
|
258
|
-
basename: basename( filename ),
|
|
240
|
+
chunk,
|
|
241
|
+
filename: chunkJSFile,
|
|
259
242
|
contentHash,
|
|
260
243
|
} );
|
|
261
244
|
} else {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
245
|
+
const suffix =
|
|
246
|
+
'.asset.' + ( outputFormat === 'php' ? 'php' : 'json' );
|
|
247
|
+
assetFilename = compilation
|
|
248
|
+
.getPath( '[file]', { filename: chunkJSFile } )
|
|
249
|
+
.replace( /\.js$/i, suffix );
|
|
266
250
|
}
|
|
267
251
|
|
|
268
252
|
// Add source and file into compilation for webpack to output.
|
|
269
|
-
compilation.assets[ assetFilename ] = new RawSource(
|
|
270
|
-
|
|
271
|
-
assetFilename
|
|
253
|
+
compilation.assets[ assetFilename ] = new RawSource(
|
|
254
|
+
this.stringify( assetData )
|
|
272
255
|
);
|
|
256
|
+
chunk.files[ isWebpack4 ? 'push' : 'add' ]( assetFilename );
|
|
273
257
|
}
|
|
274
258
|
|
|
275
259
|
if ( combineAssets ) {
|
|
276
|
-
|
|
277
|
-
// The type indicates the option may be `undefined`.
|
|
278
|
-
// However, at this point in compilation, webpack has filled the options in if
|
|
279
|
-
// they were not provided.
|
|
280
|
-
const outputFolder = /** @type {{path:string}} */ (
|
|
281
|
-
compiler.options.output
|
|
282
|
-
).path;
|
|
260
|
+
const outputFolder = compilation.outputOptions.path;
|
|
283
261
|
|
|
284
262
|
const assetsFilePath = path.resolve(
|
|
285
263
|
outputFolder,
|
|
@@ -299,11 +277,4 @@ class DependencyExtractionWebpackPlugin {
|
|
|
299
277
|
}
|
|
300
278
|
}
|
|
301
279
|
|
|
302
|
-
function basename( name ) {
|
|
303
|
-
if ( ! name.includes( '/' ) ) {
|
|
304
|
-
return name;
|
|
305
|
-
}
|
|
306
|
-
return name.substr( name.lastIndexOf( '/' ) + 1 );
|
|
307
|
-
}
|
|
308
|
-
|
|
309
280
|
module.exports = DependencyExtractionWebpackPlugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/dependency-extraction-webpack-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.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": "9d9d33bbdf317a4381b8ca1713e43bb50df653b3"
|
|
42
42
|
}
|