File tree 4 files changed +43
-2
lines changed
4 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ _Before_ submitting a pull request, please make sure the following is done…
64
64
8. Ensure the test suite passes via `yarn test`.
65
65
66
66
```sh-session
67
+ $ yarn test:prepare # build example and generate fixtures before running tests
67
68
$ yarn test
68
69
```
69
70
Original file line number Diff line number Diff line change @@ -233,9 +233,12 @@ class ChunkExtractor {
233
233
createChunkAsset ( { filename, chunk, type, linkType } ) {
234
234
const resolvedFilename =
235
235
typeof filename === 'object' && filename . name ? filename . name : filename
236
+ const resolvedIntegrity =
237
+ typeof filename === 'object' && filename . integrity ? filename . integrity : null
236
238
237
239
return {
238
240
filename : resolvedFilename ,
241
+ integrity : resolvedIntegrity ,
239
242
scriptType : getFileScriptType ( resolvedFilename ) ,
240
243
chunk,
241
244
url : this . resolvePublicUrl ( resolvedFilename ) ,
Original file line number Diff line number Diff line change @@ -102,6 +102,31 @@ describe('ChunkExtrator', () => {
102
102
` )
103
103
} )
104
104
105
+ it ( 'should add integrity if available in stats' , ( ) => {
106
+ const testExtractor = new ChunkExtractor ( {
107
+ stats : {
108
+ ...stats ,
109
+ namedChunkGroups : {
110
+ ...stats . namedChunkGroups ,
111
+ main : {
112
+ ...stats . namedChunkGroups . main ,
113
+ assets : stats . namedChunkGroups . main . assets . map ( name => ( {
114
+ name,
115
+ // pseudo hash - reversed name
116
+ integrity : name . split ( '' ) . reverse ( ) . join ( '' ) ,
117
+ } ) ) ,
118
+ } ,
119
+ } ,
120
+ } ,
121
+ outputPath : targetPath ,
122
+ } )
123
+ expect ( testExtractor . getScriptTags ( { crossorigin : 'anonymous' } ) )
124
+ . toMatchInlineSnapshot ( `
125
+ "<script id=\\"__LOADABLE_REQUIRED_CHUNKS__\\" type=\\"application/json\\" crossorigin=\\"anonymous\\">[]</script><script id=\\"__LOADABLE_REQUIRED_CHUNKS___ext\\" type=\\"application/json\\" crossorigin=\\"anonymous\\">{\\"namedChunks\\":[]}</script>
126
+ <script async data-chunk=\\"main\\" src=\\"/dist/node/main.js\\" integrity=\\"sj.niam\\" crossorigin=\\"anonymous\\"></script>"
127
+ ` )
128
+ } )
129
+
105
130
it ( 'should add extra props if specified - object argument' , ( ) => {
106
131
extractor . addChunk ( 'letters-A' )
107
132
expect ( extractor . getScriptTags ( { nonce : 'testnonce' } ) )
Original file line number Diff line number Diff line change @@ -39,8 +39,20 @@ class LoadablePlugin {
39
39
return {
40
40
id : chunk . id ,
41
41
files : [ ...chunk . files ] ,
42
- } ;
43
- } ) ;
42
+ }
43
+ } )
44
+
45
+ // update namedChunkGroups with integrity from webpack-subresource-integrity if available
46
+ Object . values ( stats . namedChunkGroups ) . forEach ( namedChunkGroup => {
47
+ namedChunkGroup . assets . forEach ( namedChunkGroupAsset => {
48
+ if ( ! namedChunkGroupAsset . integrity ) {
49
+ const asset = stats . assets . find ( a => a . name === namedChunkGroupAsset . name ) || { }
50
+ if ( asset . integrity ) {
51
+ namedChunkGroupAsset . integrity = asset . integrity
52
+ }
53
+ }
54
+ } )
55
+ } )
44
56
45
57
const result = JSON . stringify ( stats , null , 2 )
46
58
You can’t perform that action at this time.
0 commit comments