// src/lib/npmLatestVersion.ts
var REGISTRY_BASE = "https://registry.npmjs.org";
var cache = /* @__PURE__ */ new Map();
async function fetchUncached(packageName) {
  try {
    const url = `${REGISTRY_BASE}/${encodeURIComponent(packageName)}/latest`;
    const res = await fetch(url, { headers: { Accept: "application/vnd.npm.install-v1+json" } });
    if (!res.ok) return void 0;
    const data = await res.json();
    return data.version;
  } catch {
    return void 0;
  }
}
function fetchLatestPackageVersion(packageName) {
  const existing = cache.get(packageName);
  if (existing) return existing;
  const pending = fetchUncached(packageName);
  cache.set(packageName, pending);
  return pending;
}
function clearLatestPackageVersionCache() {
  cache.clear();
}
export {
  clearLatestPackageVersionCache,
  fetchLatestPackageVersion
};
//# sourceMappingURL=npmLatestVersion.mjs.map