UNPKG

query-registry

Version:

Query the npm registry for packuments, manifests, packages and download counts

47 lines (42 loc) 975 B
import { npmRegistry, npmRegistryMirrors } from '../data/registries.esm.js'; import { fetch } from './fetch.esm.js'; import { log } from './log.esm.js'; async function fetchFromRegistry({ endpoint, headers, query, registry = npmRegistry, mirrors = npmRegistryMirrors, cached }) { const urls = [registry, ...mirrors].map(host => { const url = new URL(endpoint, host); url.search = query != null ? query : ''; return url.href; }); let lastError; for (const url of urls) { try { const json = await fetch({ url, headers, cached }); return json; } catch (err) { // Keep last fetch error lastError = err; } } log('fetchFromRegistry: cannot retrieve data from registry or mirrors: %O', { endpoint, headers, query, registry, mirrors, lastError }); throw lastError; } export { fetchFromRegistry }; //# sourceMappingURL=fetch-from-registry.esm.js.map