let e;Object.defineProperty(exports,"__esModule",{value:!0});var t=require("node:fs"),r=require("node:fs/promises"),o=require("node:path"),n=require("@jsdevtools/ez-spawn"),i=require("node:process"),a=require("node:os"),l=require("gensync"),s=require("which"),d=require("picocolors");function u(e){return e&&e.__esModule?e:{default:e}}var c=/*#__PURE__*/u(o),y=/*#__PURE__*/u(l),f=/*#__PURE__*/u(s),p=/*#__PURE__*/u(d);const m=f.default.sync,$=y.default({sync:m,async:f.default}),h=y.default(function*(t){return(void 0===e&&(e=yield*$("sudo",{nothrow:!0})),null===e)?t:e+" "+t}),k=e=>"darwin"===i.platform?`/Volumes/${e}`:`/mnt/${e}`,w=e=>{let t="";return"object"==typeof e&&e&&("name"in e&&"string"==typeof e.name&&(t+=e.name),"code"in e&&"string"==typeof e.code&&(t+=" "+e.code),"message"in e&&"string"==typeof e.message&&(t+=" "+e.message)),t},{yellow:b,red:R,blue:g}=p.default,A=()=>{},M=(e=!1)=>({warn:e?A:(...e)=>console.warn(b("WARN")+" ",...e),error:e?A:(...e)=>console.error(R("ERROR")+" ",...e),info:e?A:(...e)=>console.info(g("INFO")+" ",...e)}),x=y.default({sync:n.sync,async:n.async}),q=y.default({sync:t.mkdirSync,async:r.mkdir}),v=y.default({sync:t.rmSync,async:r.rm}),S="Initializing RAM disk. You may be prompted for credentials",j="Mouting RAM disk. You may be prompted for credentials",F=e=>`Unmouting RAM disk at ${e}. You may be prompted for credentials`,_=e=>"darwin"===e||"linux"===e,z=Symbol("not supported"),E=e=>({darwin:{create:y.default(function*(t,r,o,n){e.info(S);let i=(yield*x(`hdiutil attach -nomount ram://${o/512}`)).stdout.trim();e.info(j),yield*x(`diskutil eraseVolume ${n?"HFS+":"APFS"} ${t} ${i}`)}),destroy:y.default(function*(t,r){e.info(F(t));let o=`hdiutil detach ${t}`;r&&(o+=" -force"),yield*x(o)})},linux:{create:y.default(function*(t,r,o,n){e.info(S),yield*x((yield*h(`mkdir -p ${r}`))),e.info(j),yield*x((yield*h(`mount -t tmpfs -o size=${o} tmpfs ${r}`)))}),destroy:y.default(function*(t,r){e.info(F(t));let o=r?`umount --force ${t}`:`umount ${t}`;yield*x((yield*h(o)))})},[z]:{create:y.default(function*(t,r,o,n){e.warn(`The current platform "${i.platform}" does not support RAM disks. A temporary directory (which may or may not exists in the RAM) is created at "${r}".`),yield*q(r,{recursive:!0})}),destroy:y.default(function*(t,r){let o=`Current platform "${i.platform}" does not support RAM disks, attempted to remove the directory "${t}"`;try{yield*v(t,{recursive:!0,force:!0}),e.warn(`${o} and successed.`)}catch(t){e.warn(`${o} but failed`+w(t))}})}}),O=e=>{if(e)throw Error(`Unsupported platform "${i.platform}"`)},P=y.default(function*(e,{quiet:t=!0,throwOnNotSupportedPlatform:r=!1,force:o=!0}={}){let n=M(t);if(_(i.platform)){yield*E(n)[i.platform].destroy(e,o);return}O(r),yield*E(n)[z].destroy(e,o)}),Y=y.default(function*(e,r,{quiet:o=!0,throwOnNotSupportedPlatform:n=!1,darwinUseHFSPlus:l=!1}={}){let s=M(o),d=k(e);try{if(_(i.platform)){if(t.existsSync(d))return s.warn(`The path "${d}" already exists, skipping creation`),d;return yield*E(s)[i.platform].create(e,d,r,l),s.info(`RAM disk is avaliable at ${d}`),d}return O(n),d=c.default.join(a.tmpdir(),".mocked-memdisk",e),yield*E(s)[z].create(e,d,r,l),d}catch{let e=`Failed to create RAM disk at ${d}`;throw t.existsSync(d)&&(s.error(`${e}, clean it up`),yield*P(d,{quiet:o,throwOnNotSupportedPlatform:n})),Error(e)}});exports.create={sync:(...e)=>Y.sync.apply(null,e),async:(...e)=>Y.async.apply(null,e),errback:(...e)=>Y.errback.apply(null,e)},exports.destroy={sync:(...e)=>P.sync.apply(null,e),async:(...e)=>P.async.apply(null,e),errback:(...e)=>P.errback.apply(null,e)},exports.isSupportedPlatform=_;