-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { satisfies as satisfiesSemver } from 'semver'; | ||
|
||
/** | ||
* Checks if provided snaps are on the block list. | ||
* | ||
* @param snapsToCheck - An object containing snap ids and other information. | ||
* @param blocklist - An object containing snap ids, version or shasum of the blocked snaps. | ||
* @returns An object structure containing snaps block information. | ||
*/ | ||
const checkSnapsBlockList = async (snapsToCheck, blocklist) => | ||
Object.entries(snapsToCheck).reduce((acc, [snapId, snapInfo]) => { | ||
const blockInfo = blocklist.find( | ||
(blocked) => | ||
(blocked.id === snapId && | ||
satisfiesSemver(snapInfo.version, blocked.versionRange, { | ||
includePrerelease: true, | ||
})) || | ||
// Check for null/undefined for a case in which SnapController did not return | ||
// a valid message. This will avoid blocking all snaps in the given case. | ||
// Avoid having (undefined === undefined). | ||
(blocked.shasum ? blocked.shasum === snapInfo.shasum : false), | ||
); | ||
|
||
acc[snapId] = blockInfo | ||
? { | ||
blocked: true, | ||
reason: blockInfo.reason, | ||
infoUrl: blockInfo.infoUrl, | ||
} | ||
: { blocked: false }; | ||
return acc; | ||
}, {}); | ||
|
||
export default checkSnapsBlockList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,5 @@ | ||
import { satisfies as satisfiesSemver } from 'semver'; | ||
import { SNAP_BLOCKLIST } from './snap-blocklist'; | ||
import checkSnapsBlockList from './checkSnapsBlockList'; | ||
import { fetchNPMPackage } from './fetchNPMPackage'; | ||
|
||
/** | ||
* Checks if provided snaps are on the block list. | ||
* | ||
* @param snapsToCheck - An object containing snap ids and other information. | ||
* @param blocklist - An object containing snap ids, version or shasum of the blocked snaps. | ||
* @returns An object structure containing snaps block information. | ||
*/ | ||
const checkSnapsBlockList = async (snapsToCheck, blocklist) => | ||
Object.entries(snapsToCheck).reduce((acc, [snapId, snapInfo]) => { | ||
const blockInfo = blocklist.find( | ||
(blocked) => | ||
(blocked.id === snapId && | ||
satisfiesSemver(snapInfo.version, blocked.versionRange, { | ||
includePrerelease: true, | ||
})) || | ||
// Check for null/undefined for a case in which SnapController did not return | ||
// a valid message. This will avoid blocking all snaps in the given case. | ||
// Avoid having (undefined === undefined). | ||
(blocked.shasum ? blocked.shasum === snapInfo.shasum : false), | ||
); | ||
|
||
acc[snapId] = blockInfo | ||
? { | ||
blocked: true, | ||
reason: blockInfo.reason, | ||
infoUrl: blockInfo.infoUrl, | ||
} | ||
: { blocked: false }; | ||
return acc; | ||
}, {}); | ||
|
||
export { checkSnapsBlockList, SNAP_BLOCKLIST }; | ||
export { checkSnapsBlockList, SNAP_BLOCKLIST, fetchNPMPackage }; |