@@ -298,49 +298,50 @@ export class SubresourceIntegrityPlugin {
298298 . forEach ( ( childChunk : Chunk ) => {
299299 const files = Array . from ( childChunk . files ) ;
300300
301- let sourcePath = files [ files . length - 1 ] ;
302- if ( ! sourcePath ) {
303- return ;
304- }
301+ files . forEach ( ( sourcePath ) => {
302+ if ( ! sourcePath ) {
303+ return ;
304+ }
305305
306- if ( assets [ sourcePath ] ) {
307- this . warnIfHotUpdate ( compilation , assets [ sourcePath ] . source ( ) ) ;
308- const newAsset = this . replaceAsset (
309- compilation . compiler ,
310- assets ,
311- hashByChunkId ,
312- sourcePath
313- ) ;
314- const integrity = computeIntegrity (
315- this . options . hashFuncNames ,
316- newAsset . source ( )
317- ) ;
318-
319- if ( childChunk . id !== null ) {
320- hashByChunkId . set ( childChunk . id , integrity ) ;
306+ if ( assets [ sourcePath ] ) {
307+ this . warnIfHotUpdate ( compilation , assets [ sourcePath ] . source ( ) ) ;
308+ const newAsset = this . replaceAsset (
309+ compilation . compiler ,
310+ assets ,
311+ hashByChunkId ,
312+ sourcePath
313+ ) ;
314+ const integrity = computeIntegrity (
315+ this . options . hashFuncNames ,
316+ newAsset . source ( )
317+ ) ;
318+
319+ if ( childChunk . id !== null ) {
320+ hashByChunkId . set ( childChunk . id , integrity ) ;
321+ }
322+ this . updateAssetIntegrity ( sourcePath , integrity ) ;
323+ compilation . updateAsset (
324+ sourcePath ,
325+ ( x ) => x ,
326+ ( assetInfo ) =>
327+ assetInfo && {
328+ ...assetInfo ,
329+ contenthash : Array . isArray ( assetInfo . contenthash )
330+ ? [ ...new Set ( [ ...assetInfo . contenthash , integrity ] ) ]
331+ : assetInfo . contenthash
332+ ? [ assetInfo . contenthash , integrity ]
333+ : integrity ,
334+ }
335+ ) ;
336+ } else {
337+ this . warnOnce (
338+ compilation ,
339+ `No asset found for source path '${ sourcePath } ', options are ${ Object . keys (
340+ assets
341+ ) . join ( ", " ) } `
342+ ) ;
321343 }
322- this . updateAssetIntegrity ( sourcePath , integrity ) ;
323- compilation . updateAsset (
324- sourcePath ,
325- ( x ) => x ,
326- ( assetInfo ) =>
327- assetInfo && {
328- ...assetInfo ,
329- contenthash : Array . isArray ( assetInfo . contenthash )
330- ? [ ...new Set ( [ ...assetInfo . contenthash , integrity ] ) ]
331- : assetInfo . contenthash
332- ? [ assetInfo . contenthash , integrity ]
333- : integrity ,
334- }
335- ) ;
336- } else {
337- this . warnOnce (
338- compilation ,
339- `No asset found for source path '${ sourcePath } ', options are ${ Object . keys (
340- assets
341- ) . join ( ", " ) } `
342- ) ;
343- }
344+ } ) ;
344345 } ) ;
345346 } ;
346347
@@ -746,16 +747,21 @@ export class SubresourceIntegrityPlugin {
746747 ) ;
747748
748749 compiler . hooks . compilation . tap (
749- "DefaultStatsFactoryPlugin" ,
750+ thisPluginName ,
750751 ( compilation : Compilation ) => {
751752 compilation . hooks . statsFactory . tap ( thisPluginName , ( statsFactory ) => {
752753 statsFactory . hooks . extract
753754 . for ( "asset" )
754755 . tap ( thisPluginName , ( object , asset ) => {
755- if ( this . assetIntegrity . has ( asset . name ) ) {
756- ( object as any ) . integrity = String (
757- this . assetIntegrity . get ( asset . name )
758- ) ;
756+ const contenthash = asset . info ?. contenthash ;
757+ if ( contenthash ) {
758+ const shaHashes = ( Array . isArray ( contenthash )
759+ ? contenthash
760+ : [ contenthash ]
761+ ) . filter ( ( hash : any ) => String ( hash ) . match ( / ^ s h a [ 0 - 9 ] + - / ) ) ;
762+ if ( shaHashes . length > 0 ) {
763+ ( object as any ) . integrity = shaHashes . join ( " " ) ;
764+ }
759765 }
760766 } ) ;
761767 } ) ;
0 commit comments