File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ This is a new major version that contains several backwards-compatibility breaks
88
99* #1344 Add options configuration callback to ` Encore.enableReactPreset() ` (@Kocal )
1010
11+ * #1345 Add support for integrity hashes when asset names contain a query string (@Kocal )
12+
1113### BC Breaks
1214
1315* #1321 Drop support of Node.js 19 and 21 (@Kocal )
Original file line number Diff line number Diff line change @@ -95,13 +95,16 @@ class EntryPointsPlugin {
9595 for ( const entryName in manifest . entrypoints ) {
9696 for ( const fileType in manifest . entrypoints [ entryName ] ) {
9797 for ( const asset of manifest . entrypoints [ entryName ] [ fileType ] ) {
98- if ( asset in manifest . integrity ) {
98+ // Drop query string if any
99+ const assetNormalized = asset . includes ( '?' ) ? asset . split ( '?' ) [ 0 ] : asset ;
100+
101+ if ( assetNormalized in manifest . integrity ) {
99102 continue ;
100103 }
101104
102105 const filePath = path . resolve (
103106 this . outputPath ,
104- asset . replace ( this . publicPath , '' ) ,
107+ assetNormalized . replace ( this . publicPath , '' ) ,
105108 ) ;
106109
107110 if ( fs . existsSync ( filePath ) ) {
@@ -115,7 +118,7 @@ class EntryPointsPlugin {
115118 fileHashes . push ( `${ algorithm } -${ hash . digest ( 'base64' ) } ` ) ;
116119 }
117120
118- manifest . integrity [ asset ] = fileHashes . join ( ' ' ) ;
121+ manifest . integrity [ assetNormalized ] = fileHashes . join ( ' ' ) ;
119122 }
120123 }
121124 }
Original file line number Diff line number Diff line change @@ -3123,6 +3123,35 @@ module.exports = {
31233123 done ( ) ;
31243124 } ) ;
31253125 } ) ;
3126+
3127+ it ( 'With query string versioning' , ( done ) => {
3128+ const config = createWebpackConfig ( 'web/build' , 'dev' ) ;
3129+ config . addEntry ( 'main' , './js/no_require' ) ;
3130+ config . setPublicPath ( '/build' ) ;
3131+ config . addStyleEntry ( 'styles' , './css/h1_style.css' ) ;
3132+ config . enableVersioning ( true ) ;
3133+ config . configureFilenames ( {
3134+ js : '[name].js?v=[contenthash:16]' ,
3135+ css : '[name].css?v=[contenthash:16]'
3136+ } ) ;
3137+ config . enableIntegrityHashes ( ) ;
3138+
3139+ testSetup . runWebpack ( config , ( webpackAssert ) => {
3140+ const integrityData = getIntegrityData ( config ) ;
3141+ const expectedFilesWithHashes = [
3142+ '/build/runtime.js' ,
3143+ '/build/main.js' ,
3144+ '/build/styles.css' ,
3145+ ] ;
3146+
3147+ expectedFilesWithHashes . forEach ( ( file ) => {
3148+ expect ( integrityData [ file ] ) . to . contain ( 'sha384-' ) ;
3149+ expect ( integrityData [ file ] ) . to . have . length ( 71 ) ;
3150+ } ) ;
3151+
3152+ done ( ) ;
3153+ } ) ;
3154+ } ) ;
31263155 } ) ;
31273156 } ) ;
31283157} ) ;
You can’t perform that action at this time.
0 commit comments