// src/lib/concurrency.ts
import { AsyncLocalStorage } from "async_hooks";
var outputStorage = new AsyncLocalStorage();
async function runWithConcurrency(items, concurrency, fn) {
  let next = 0;
  async function worker() {
    while (next < items.length) {
      const i = next++;
      await fn(items[i]);
    }
  }
  await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => worker()));
}

// src/actions/deplint/fetchPackageManifest.ts
var REGISTRY_BASE = "https://registry.npmjs.org";
var cache = /* @__PURE__ */ new Map();
async function fetchUncached(packageName) {
  try {
    const url = `${REGISTRY_BASE}/${encodeURIComponent(packageName)}`;
    const res = await fetch(url, { headers: { Accept: "application/vnd.npm.install-v1+json" } });
    if (!res.ok) return void 0;
    const data = await res.json();
    const versionsMap = data.versions ?? {};
    const versions = Object.entries(versionsMap).map(
      ([version, manifest]) => ({ peerDependencies: manifest.peerDependencies ?? {}, version })
    );
    return { distTags: data["dist-tags"] ?? {}, versions };
  } catch {
    return void 0;
  }
}
function fetchPackageManifest(packageName) {
  const existing = cache.get(packageName);
  if (existing) return existing;
  const pending = fetchUncached(packageName);
  cache.set(packageName, pending);
  return pending;
}
async function fetchPackageManifests(packageNames, concurrency = 16) {
  const unique = [...new Set(packageNames)];
  const results = /* @__PURE__ */ new Map();
  await runWithConcurrency(unique, concurrency, async (name) => {
    results.set(name, await fetchPackageManifest(name));
  });
  return results;
}
function clearPackageManifestCache() {
  cache.clear();
}
export {
  clearPackageManifestCache,
  fetchPackageManifest,
  fetchPackageManifests
};
//# sourceMappingURL=fetchPackageManifest.mjs.map