UNPKG

jsr

Version:

jsr.io package manager for npm, yarn, pnpm and bun

39 lines 1.45 kB
"use strict"; // Copyright the JSR authors. MIT license. Object.defineProperty(exports, "__esModule", { value: true }); exports.JSR_URL = void 0; exports.getPackageMeta = getPackageMeta; exports.getLatestPackageVersion = getLatestPackageVersion; exports.getNpmPackageInfo = getNpmPackageInfo; exports.JSR_URL = process.env.JSR_URL ?? "https://jsr.io"; async function getPackageMeta(pkg) { const url = `${exports.JSR_URL}/@${pkg.scope}/${pkg.name}/meta.json`; const res = await fetch(url); if (!res.ok) { // cancel unconsumed body to avoid memory leak await res.body?.cancel(); throw new Error(`Received ${res.status} from ${url}`); } return (await res.json()); } async function getLatestPackageVersion(pkg) { const info = await getPackageMeta(pkg); const { latest } = info; if (latest === undefined) { throw new Error(`Unable to find latest version of ${pkg}`); } return latest; } async function getNpmPackageInfo(pkg) { const tmpUrl = new URL(`${exports.JSR_URL}/@jsr/${pkg.scope}__${pkg.name}`); const url = `${tmpUrl.protocol}//npm.${tmpUrl.host}${tmpUrl.pathname}`; const res = await fetch(url); if (!res.ok) { // Cancel unconsumed body to avoid memory leak await res.body?.cancel(); throw new Error(`Received ${res.status} from ${tmpUrl}`); } const json = await res.json(); return json; } //# sourceMappingURL=api.js.map