UNPKG

jsr

Version:

jsr.io package manager for node

38 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNpmPackageInfo = exports.getLatestPackageVersion = exports.getPackageMeta = exports.JSR_URL = void 0; 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()); } exports.getPackageMeta = getPackageMeta; 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; } exports.getLatestPackageVersion = getLatestPackageVersion; 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; } exports.getNpmPackageInfo = getNpmPackageInfo; //# sourceMappingURL=api.js.map