import{a as e,n as t,t as n}from"./errors-pXKbCKbL.js";import*as r from"node:path";import*as i from"node:fs";import*as a from"node:os";import*as o from"smol-toml";function s(e){return e.startsWith(`~/`)||e===`~`?r.join(a.homedir(),e.slice(1)):e}function c(e){let t=s(e);i.existsSync(t)||i.mkdirSync(t,{recursive:!0})}function l(e){let r=s(e);if(!i.existsSync(r))throw new n(r);try{let e=i.readFileSync(r,`utf-8`);return JSON.parse(e)}catch(e){throw new t(r,e.message)}}function u(t,n,a=!0){let o=s(t);if(c(r.dirname(o)),a&&i.existsSync(o)){let e=`${o}.bak`;i.copyFileSync(o,e)}try{let e=`${o}.tmp`;i.writeFileSync(e,JSON.stringify(n,null,2),`utf-8`),i.renameSync(e,o)}catch(t){throw new e(o,t.message)}}function d(e){let r=s(e);if(!i.existsSync(r))throw new n(r);try{let e=i.readFileSync(r,`utf-8`);return o.parse(e)}catch(e){throw new t(r,e.message)}}function f(t,n,a=!0){let l=s(t);if(c(r.dirname(l)),a&&i.existsSync(l)){let e=`${l}.bak`;i.copyFileSync(l,e)}try{let e=`${l}.tmp`;i.writeFileSync(e,o.stringify(n),`utf-8`),i.renameSync(e,l)}catch(t){throw new e(l,t.message)}}const p=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Date);function m(e,t){let n={...e};for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e)){let r=t[e],i=n[e];p(r)&&p(i)?n[e]=m(i,r):n[e]=r}return n}function h(e){let t=s(e);return i.existsSync(t)}function g(e){let t=s(e);if(!i.existsSync(t))return null;let n=i.statSync(t);return{size:n.size,lastModified:n.mtime}}export{l as a,u as c,g as i,f as l,c as n,d as o,h as r,s,m as t};