UNPKG

query-registry

Version:

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

44 lines (39 loc) 944 B
import { npmRegistry, npmRegistryMirrors } from '../data/registries.esm.js'; import { fetch } from './fetch.esm.js'; import { log } from './log.esm.js'; import urlJoin from 'url-join'; async function fetchFromRegistry({ endpoint, headers, query, registry = npmRegistry, mirrors = npmRegistryMirrors, cached }) { const urls = [registry, ...mirrors].map(base => urlJoin(base, endpoint, query ? `?${query}` : '')); 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