import { inDebugger , UserError } from "@adpt/utils" ; import plf from "proper-lockfile" ; export const lockDefaults = { retries : 2 , stale : inDebugger ( ) ? 24 * 60 * 60 * 1000 : 10 * 1000 , } ; export async function lock ( filename , lockDescr , options = { } ) { try { return await plf . lock ( filename , { ... lockDefaults , onCompromised : ( err ) => { throw new UserError ( `${ lockDescr } error: ${ err . message } (${ filename })` ) ; } , ... options , } ) ; } catch ( err ) { err . message = `${ err . message } (${ filename })` ; throw err ; } }