How to use the npm-registry-fetch function in npm-registry-fetch

To help you get started, we’ve selected a few npm-registry-fetch 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 callstack / haul / packages / haul-cli / src / commands / init.ts View on Github external
async function getAvailableHaulPreset(
  progress: Ora,
  targetHaulPreset: string
): Promise {
  // Stop searching on 0.59 - there's no preset below 0.59.
  if (targetHaulPreset.includes('0.59')) {
    return targetHaulPreset;
  }

  try {
    await npmFetch(targetHaulPreset);
    return targetHaulPreset;
  } catch (error) {
    if (error.statusCode === 404) {
      progress.info(
        `${targetHaulPreset} not available. Trying older version...`
      );
      const previousHaulPreset = targetHaulPreset.replace(/-0\.\d+$/, match => {
        const [major, minor] = match.slice(1).split('.');
        return `-${major}.${parseInt(minor, 10) - 1}`;
      });
      return await getAvailableHaulPreset(progress, previousHaulPreset);
    }

    return targetHaulPreset;
  }
}

npm-registry-fetch

Fetch-based http client for use with npm registry APIs

ISC
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis