@typespec/compiler
Version:
TypeSpec compiler and standard library
20 lines • 860 B
JavaScript
// Browser-safe helpers to access the npm registry api
// https://github.com/npm/registry/blob/main/docs/REGISTRY-API.md#package-endpoints
const defaultRegistry = `https://registry.npmjs.org`;
/**
* Returns the npm registry URL to use for fetching packages.
* Uses the `TYPESPEC_NPM_REGISTRY` environment variable if set,
* otherwise falls back to the default npm registry.
*/
export function getNpmRegistry() {
return (process.env["TYPESPEC_NPM_REGISTRY"] ?? defaultRegistry).replace(/\/$/, "");
}
export async function fetchPackageManifest(packageName, version) {
const url = `${getNpmRegistry()}/${packageName}/${version}`;
const res = await fetch(url);
return await res.json();
}
export function fetchLatestPackageManifest(packageName) {
return fetchPackageManifest(packageName, "latest");
}
//# sourceMappingURL=npm-registry.js.map