Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getLatestRnDiffPurgeVersion(
name: string,
eTag?: string,
): Promise {
const options = {
// https://developer.github.com/v3/#user-agent-required
headers: {'User-Agent': 'React-Native-CLI'} as Headers,
};
if (eTag) {
options.headers['If-None-Match'] = eTag;
}
const {data, status, headers} = await fetch(
'https://api.github.com/repos/react-native-community/rn-diff-purge/tags',
options,
);
// Remote is newer.
if (status === 200) {
const body: Array = data;
const latestVersion = body[0].name.substring(8);
const eTagHeader = headers.get('eTag');
// Update cache only if newer release is stable.
if (!semver.prerelease(latestVersion) && eTagHeader) {
logger.debug(`Saving ${eTagHeader} to cache`);
cacheManager.set(name, 'eTag', eTagHeader);
cacheManager.set(name, 'latestVersion', latestVersion);
}