How to use the @react-native-community/cli-tools.fetch function in @react-native-community/cli-tools

To help you get started, we’ve selected a few @react-native-community/cli-tools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-native-community / cli / packages / cli / src / tools / releaseChecker / getLatestRelease.ts View on Github external
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);
    }