import{s as e}from"./DrKWWDpL.js";import{t}from"./DYP3EJMY.js";import"./CX8DOZuw2.js";import{t as n}from"./BYJC6_MM.js";var r=e(t(),1),i=e(n(),1),a=10;function o(e,t){let n=(0,r.dirname)(e),i=(0,r.basename)(e),o=(0,r.join)(n,`.backups`),c=typeof t==`number`?s(t):void 0;(0,r.existsSync)(o)||(0,r.mkdirSync)(o,{recursive:!0,mode:c});for(let e=a;e>=1;e--){let t=(0,r.join)(o,`${i}.${e}`);if(e===a)try{(0,r.unlinkSync)(t)}catch{}else{let n=(0,r.join)(o,`${i}.${e+1}`);try{(0,r.existsSync)(t)&&(0,r.renameSync)(t,n)}catch{}}}try{let n=(0,r.readFileSync)(e,`utf-8`),a=(0,r.join)(o,`${i}.1`);typeof t==`number`?(0,r.writeFileSync)(a,n,{encoding:`utf-8`,mode:t}):(0,r.writeFileSync)(a,n,`utf-8`)}catch{}}function s(e){let t=e&511;return t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1),t}function c(e,t,n=2){let i=typeof n==`number`?{indent:n}:n,a=i.indent??2,s=i.mode,c=(0,r.join)((0,r.dirname)(e),`.${(0,r.basename)(e)}.${(0,r.randomBytes)(6).toString(`hex`)}.tmp`),l=JSON.stringify(t,null,a)+`
`;typeof s==`number`?(0,r.writeFileSync)(c,l,{encoding:`utf-8`,mode:s}):(0,r.writeFileSync)(c,l,`utf-8`);try{(0,r.existsSync)(e)&&o(e,s),(0,r.renameSync)(c,e)}catch(e){try{(0,r.unlinkSync)(c)}catch{}throw e}}function l(e){try{let t=(0,r.readFileSync)(e,`utf-8`);return JSON.parse(t)}catch(e){if(e.code===`ENOENT`)return null;throw e}}var u={retries:{retries:5,factor:2,minTimeout:100,maxTimeout:5e3},stale:3e4};async function d(e,t,n={}){let a=(0,r.dirname)(e),o=typeof n.mode==`number`?s(n.mode):void 0;(0,r.existsSync)(a)||(0,r.mkdirSync)(a,{recursive:!0,mode:o}),(0,r.existsSync)(e)||(typeof n.mode==`number`?(0,r.writeFileSync)(e,``,{encoding:`utf-8`,mode:n.mode}):(0,r.writeFileSync)(e,``,`utf-8`));let d;try{d=await i.lock(e,u);let r=t(l(e));return c(e,r,{mode:n.mode}),r}finally{d&&await d()}}async function f(e,t){let n=(0,r.dirname)(e);(0,r.existsSync)(n)||(0,r.mkdirSync)(n,{recursive:!0}),(0,r.existsSync)(e)||(0,r.writeFileSync)(e,``,`utf-8`);let a;try{return a=await i.lock(e,u),await t()}finally{a&&await a()}}export{c as i,f as n,d as r,l as t};