waysact / webpack-subresource-integrity

Webpack plugin for enabling Subresource Integrity.
MIT License
357 stars 46 forks source link

integrity missing from namedChunkGroups assets #163

Closed jarrett-confrey closed 3 years ago

jarrett-confrey commented 3 years ago

integrity is in stats.toJson().assets but not stats.toJson().namedChunkGroups.assets. i noticed this when working with loadable-components. i have https://github.com/gregberge/loadable-components/pull/803 (packages/webpack-plugin/src/index.js) to add integrity to namedChunkGroups but im curious if it might be better to do so in this library instead or as well

jscheid commented 3 years ago

Thanks for the suggestion, it did sound reasonable at first. But on closer inspection it turns out that in terms of the official typings, elements of stats.toJson().assets are explicitly designed to receive custom properties (via & Record<string, any>): https://github.com/webpack/webpack/blob/60d8968cd48cf1677df5f50ed878c6a912e9d692/types.d.ts#L10597

... whereas elements of stats.toJson().namedChunkGroups.assets are not: https://github.com/webpack/webpack/blob/60d8968cd48cf1677df5f50ed878c6a912e9d692/types.d.ts#L5466

This means implementing your suggestion would require casting the type, which I'd like to avoid.

Also, the records in namedChunkGroups being typed differently, I think it's clear they are not meant to be treated as copies of the records at the top level. Perhaps you should also consider designing this differently in your lib, or asking the Webpack devs for clarification, if you want to be sure this is going to continue to work in future Webpack versions?