import{__module as t}from"../../../_virtual/index31.mjs";import e from"../../../_virtual/_node_fs.mjs";import{__require as n}from"../../imurmurhash/imurmurhash.mjs";import*as r from"../../signal-exit/dist/mjs/index.mjs";import i from"../../../_virtual/_node_path.mjs";import o from"../../../_virtual/_node_util.mjs";var c;function a(){if(c)return t.exports;c=1,t.exports=async function(t,e,n,r){n instanceof Function&&(r=n,n={});const i=async function(t,e,n={}){"string"==typeof n&&(n={encoding:n});let r,i;const o=u(g(()=>i)),c=m.resolve(t);try{await function(t){return new Promise(e=>{l[t]||(l[t]=[]),l[t].push(e),1===l[t].length&&e()})}(c);const o=await f(a.realpath)(t).catch(()=>t);if(i=y(o),!n.mode||!n.chown){const t=await f(a.stat)(o).catch(()=>{});t&&(null==n.mode&&(n.mode=t.mode),null==n.chown&&process.getuid&&(n.chown={uid:t.uid,gid:t.gid}))}r=await f(a.open)(i,"w",n.mode),n.tmpfileCreated&&await n.tmpfileCreated(i),ArrayBuffer.isView(e)?await f(a.write)(r,e,0,e.length,0):null!=e&&await f(a.write)(r,String(e),0,String(n.encoding||"utf8")),!1!==n.fsync&&await f(a.fsync)(r),await f(a.close)(r),r=null,n.chown&&await f(a.chown)(i,n.chown.uid,n.chown.gid).catch(t=>{if(!S(t))throw t}),n.mode&&await f(a.chmod)(i,n.mode).catch(t=>{if(!S(t))throw t}),await f(a.rename)(i,o)}finally{r&&await f(a.close)(r).catch(()=>{}),o(),await f(a.unlink)(i).catch(()=>{}),l[c].shift(),l[c].length>0?l[c][0]():delete l[c]}}(t,e,n);if(r)try{return r(await i)}catch(t){return r(t)}return i},t.exports.sync=function(t,e,n){"string"==typeof n?n={encoding:n}:n||(n={});try{t=a.realpathSync(t)}catch(t){}const r=y(t);if(!n.mode||!n.chown)try{const e=a.statSync(t);(n=Object.assign({},n)).mode||(n.mode=e.mode),!n.chown&&process.getuid&&(n.chown={uid:e.uid,gid:e.gid})}catch(t){}let i;const o=g(r),c=u(o);let s=!0;try{if(i=a.openSync(r,"w",n.mode||438),n.tmpfileCreated&&n.tmpfileCreated(r),ArrayBuffer.isView(e)?a.writeSync(i,e,0,e.length,0):null!=e&&a.writeSync(i,String(e),0,String(n.encoding||"utf8")),!1!==n.fsync&&a.fsyncSync(i),a.closeSync(i),i=null,n.chown)try{a.chownSync(r,n.chown.uid,n.chown.gid)}catch(t){if(!S(t))throw t}if(n.mode)try{a.chmodSync(r,n.mode)}catch(t){if(!S(t))throw t}a.renameSync(r,t),s=!1}finally{if(i)try{a.closeSync(i)}catch(t){}c(),s&&o()}},t.exports._getTmpname=y,t.exports._cleanupOnExit=g;const a=e,s=n(),{onExit:u}=r,m=i,{promisify:f}=o,l={},w=function(){try{return h("worker_threads").threadId}catch(t){return 0}}();let p=0;function y(t){return t+"."+s(d).hash(String(process.pid)).hash(String(w)).hash(String(++p)).result()}function g(t){return()=>{try{a.unlinkSync("function"==typeof t?t():t)}catch{}}}function S(t){if("ENOSYS"===t.code)return!0;return!(process.getuid&&0===process.getuid()||"EINVAL"!==t.code&&"EPERM"!==t.code)}return t.exports}export{a as __require};import s from"node:url";import u from"node:path";import m from"node:module";const d=s.fileURLToPath(import.meta.url),h=(u.dirname(d),m.createRequire(import.meta.url));