@@ -15,13 +15,20 @@ async function fetchCache(
1515 dest : string ,
1616 fetcher : Fetchers ,
1717 config : Config ,
18- integrity : ? string ,
18+ remote : PackageRemote ,
1919) : Promise < FetchedMetadata > {
2020 // $FlowFixMe: This error doesn't make sense
21- const { hash, package : pkg , remote} = await config . readPackageMetadata ( dest ) ;
21+ const { hash, package : pkg , remote : cacheRemote } = await config . readPackageMetadata ( dest ) ;
22+
23+ if ( remote . integrity ) {
24+ if ( ! cacheRemote . integrity || ! ssri . parse ( remote . integrity ) . match ( cacheRemote . integrity ) ) {
25+ // eslint-disable-next-line yarn-internal/warn-language
26+ throw new MessageError ( 'Incorrect integrity when fetching from the cache' ) ;
27+ }
28+ }
2229
23- if ( integrity ) {
24- if ( ! remote . integrity || ! ssri . parse ( integrity ) . match ( remote . integrity ) ) {
30+ if ( remote . hash ) {
31+ if ( ! cacheRemote . hash || cacheRemote . hash !== remote . hash ) {
2532 // eslint-disable-next-line yarn-internal/warn-language
2633 throw new MessageError ( 'Incorrect integrity when fetching from the cache' ) ;
2734 }
@@ -56,7 +63,7 @@ export async function fetchOneRemote(
5663
5764 const fetcher = new Fetcher ( dest , remote , config ) ;
5865 if ( await config . isValidModuleDest ( dest ) ) {
59- return fetchCache ( dest , fetcher , config , remote . integrity ) ;
66+ return fetchCache ( dest , fetcher , config , remote ) ;
6067 }
6168
6269 // remove as the module may be invalid
0 commit comments