const queues = new Map>(); export async function withVendorLock(lockPath: string, fn: () => Promise): Promise { const prev = queues.get(lockPath) ?? Promise.resolve(); const run = prev.then(fn, fn); const tracked = run.catch(() => undefined); queues.set(lockPath, tracked); try { return await run; } finally { if (queues.get(lockPath) === tracked) queues.delete(lockPath); } }