UNPKG

commitsmile

Version:
3 lines 21.7 kB
import {createRequire}from'node:module';import {b as b$1,k}from'./chunk-G5RJVSXQ.mjs';import {stat,realpath,readdir,lstat,open}from'fs/promises';import {Readable}from'stream';import*as d from'path';import {resolve,join,relative,sep}from'path';import {stat as stat$1,unwatchFile,watchFile,watch}from'fs';import {type}from'os';import {EventEmitter}from'events';createRequire(import.meta.url); function xt(){return {root:".",fileFilter:r=>!0,directoryFilter:r=>!0,type:L,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096}}var tt,At,L,st,v,x,q,It,Tt,St,Ft,J,Q,C,et,it=b$1(()=>{k();tt="READDIRP_RECURSIVE_ERROR",At=new Set(["ENOENT","EPERM","EACCES","ELOOP",tt]),L="files",st="directories",v="files_directories",x="all",q=[L,st,v,x],It=new Set([st,v,x]),Tt=new Set([L,v,x]),St=r=>At.has(r.code),Ft=process.platform==="win32",J=r=>!0,Q=r=>{if(r===void 0)return J;if(typeof r=="function")return r;if(typeof r=="string"){let t=r.trim();return s=>s.basename===t}if(Array.isArray(r)){let t=r.map(s=>s.trim());return s=>t.some(i=>s.basename===i)}return J},C=class extends Readable{constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let s={...xt(),...t},{root:i,type:e}=s;this._fileFilter=Q(s.fileFilter),this._directoryFilter=Q(s.directoryFilter);let n=s.lstat?lstat:stat;Ft?this._stat=h=>n(h,{bigint:!0}):this._stat=n,this._maxDepth=s.depth,this._wantsDir=It.has(e),this._wantsFile=Tt.has(e),this._wantsEverything=e===x,this._root=resolve(i),this._isDirent=!s.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0;}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let s=this.parent,i=s&&s.files;if(i&&i.length>0){let{path:e,depth:n}=s,h=i.splice(0,t).map(a=>this._formatEntry(a,e)),o=await Promise.all(h);for(let a of o){if(!a){t--;return}if(this.destroyed)return;let l=await this._getEntryType(a);l==="directory"&&this._directoryFilter(a)?(n<=this._maxDepth&&this.parents.push(this._exploreDir(a.fullPath,n+1)),this._wantsDir&&(this.push(a),t--)):(l==="file"||this._includeAsFile(a))&&this._fileFilter(a)&&this._wantsFile&&(this.push(a),t--);}}else {let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(s){this.destroy(s);}finally{this.reading=!1;}}}async _exploreDir(t,s){let i;try{i=await readdir(t,this._rdOptions);}catch(e){this._onError(e);}return {files:i,depth:s,path:t}}async _formatEntry(t,s){let i,e=this._isDirent?t.name:t;try{let n=resolve(join(s,e));i={path:relative(this._root,n),fullPath:n,basename:e},i[this._statsProp]=this._isDirent?t:await this._stat(n);}catch(n){this._onError(n);return}return i}_onError(t){St(t)&&!this.destroyed?this.emit("warn",t):this.destroy(t);}async _getEntryType(t){if(!t&&this._statsProp in t)return "";let s=t[this._statsProp];if(s.isFile())return "file";if(s.isDirectory())return "directory";if(s&&s.isSymbolicLink()){let i=t.fullPath;try{let e=await realpath(i),n=await lstat(e);if(n.isFile())return "file";if(n.isDirectory()){let h=e.length;if(i.startsWith(e)&&i.substr(h,1)===sep){let o=new Error(`Circular symlink detected: "${i}" points to "${e}"`);return o.code=tt,this._onError(o)}return "directory"}}catch(e){return this._onError(e),""}}}_includeAsFile(t){let s=t&&t[this._statsProp];return s&&this._wantsEverything&&!s.isDirectory()}},et=(r,t={})=>{let s=t.entryType||t.type;if(s==="both"&&(s=v),s&&(t.type=s),r){if(typeof r!="string")throw new TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");if(s&&!q.includes(s))throw new Error(`readdirp: Invalid type passed. Use one of ${q.join(", ")}`)}else throw new Error("readdirp: root argument is required. Usage: readdirp(root, options)");return t.root=r,new C(t)};});function nt(r,t,s,i,e){let n=(h,o)=>{s(r),e(h,o,{watchedPath:r}),o&&r!==o&&T(d.resolve(r,o),g,d.join(r,o));};try{return watch(r,{persistent:t.persistent},n)}catch(h){i(h);return}}var Ot,j,at,F,H,U,Mt,zt,ht,_,y,jt,Ht,g,A,E,Ut,Yt,Gt,z,b,Kt,D,ct,I,T,Bt,M,Vt,S,lt=b$1(()=>{k();Ot="data",j="end",at="close",F=()=>{},H=process.platform,U=H==="win32",Mt=H==="darwin",zt=H==="linux",ht=type()==="OS400",_={ALL:"all",READY:"ready",ADD:"add",CHANGE:"change",ADD_DIR:"addDir",UNLINK:"unlink",UNLINK_DIR:"unlinkDir",RAW:"raw",ERROR:"error"},y=_,jt="watch",Ht={lstat:lstat,stat:stat},g="listeners",A="errHandlers",E="rawEmitters",Ut=[g,A,E],Yt=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),Gt=r=>Yt.has(d.extname(r).slice(1).toLowerCase()),z=(r,t)=>{r instanceof Set?r.forEach(t):t(r);},b=(r,t,s)=>{let i=r[t];i instanceof Set||(r[t]=i=new Set([i])),i.add(s);},Kt=r=>t=>{let s=r[t];s instanceof Set?s.clear():delete r[t];},D=(r,t,s)=>{let i=r[t];i instanceof Set?i.delete(s):i===s&&delete r[t];},ct=r=>r instanceof Set?r.size===0:!r,I=new Map;T=(r,t,s,i,e)=>{let n=I.get(r);n&&z(n[t],h=>{h(s,i,e);});},Bt=(r,t,s,i)=>{let{listener:e,errHandler:n,rawEmitter:h}=i,o=I.get(t),a;if(!s.persistent)return a=nt(r,s,e,n,h),a?a.close.bind(a):void 0;if(o)b(o,g,e),b(o,A,n),b(o,E,h);else {if(a=nt(r,s,T.bind(null,t,g),n,T.bind(null,t,E)),!a)return;a.on(y.ERROR,async l=>{let c=T.bind(null,t,A);if(o&&(o.watcherUnusable=!0),U&&l.code==="EPERM")try{await(await open(r,"r")).close(),c(l);}catch{}else c(l);}),o={listeners:e,errHandlers:n,rawEmitters:h,watcher:a},I.set(t,o);}return ()=>{D(o,g,e),D(o,A,n),D(o,E,h),ct(o.listeners)&&(o.watcher.close(),I.delete(t),Ut.forEach(Kt(o)),o.watcher=void 0,Object.freeze(o));}},M=new Map,Vt=(r,t,s,i)=>{let{listener:e,rawEmitter:n}=i,h=M.get(t),o=h&&h.options;return o&&(o.persistent<s.persistent||o.interval>s.interval)&&(unwatchFile(t),h=void 0),h?(b(h,g,e),b(h,E,n)):(h={listeners:e,rawEmitters:n,options:s,watcher:watchFile(t,s,(a,l)=>{z(h.rawEmitters,f=>{f(y.CHANGE,t,{curr:a,prev:l});});let c=a.mtimeMs;(a.size!==l.size||c>l.mtimeMs||c===0)&&z(h.listeners,f=>f(r,a));})},M.set(t,h)),()=>{D(h,g,e),D(h,E,n),ct(h.listeners)&&(M.delete(t),unwatchFile(t),h.options=h.watcher=void 0,Object.freeze(h));}},S=class{constructor(t){this.fsw=t,this._boundHandleError=s=>t._handleError(s);}_watchWithNodeFs(t,s){let i=this.fsw.options,e=d.dirname(t),n=d.basename(t);this.fsw._getWatchedDir(e).add(n);let o=d.resolve(t),a={persistent:i.persistent};s||(s=F);let l;if(i.usePolling){let c=i.interval!==i.binaryInterval;a.interval=c&&Gt(n)?i.binaryInterval:i.interval,l=Vt(t,o,a,{listener:s,rawEmitter:this.fsw._emitRaw});}else l=Bt(t,o,a,{listener:s,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(t,s,i){if(this.fsw.closed)return;let e=d.dirname(t),n=d.basename(t),h=this.fsw._getWatchedDir(e),o=s;if(h.has(n))return;let a=async(c,f)=>{if(this.fsw._throttle(jt,t,5)){if(!f||f.mtimeMs===0)try{let u=await stat(t);if(this.fsw.closed)return;let w=u.atimeMs,p=u.mtimeMs;if((!w||w<=p||p!==o.mtimeMs)&&this.fsw._emit(y.CHANGE,t,u),(Mt||zt)&&o.ino!==u.ino){this.fsw._closeFile(c),o=u;let R=this._watchWithNodeFs(t,a);R&&this.fsw._addPathCloser(c,R);}else o=u;}catch{this.fsw._remove(e,n);}else if(h.has(n)){let u=f.atimeMs,w=f.mtimeMs;(!u||u<=w||w!==o.mtimeMs)&&this.fsw._emit(y.CHANGE,t,f),o=f;}}},l=this._watchWithNodeFs(t,a);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(y.ADD,t,0))return;this.fsw._emit(y.ADD,t,s);}return l}async _handleSymlink(t,s,i,e){if(this.fsw.closed)return;let n=t.fullPath,h=this.fsw._getWatchedDir(s);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let o;try{o=await realpath(i);}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(h.has(e)?this.fsw._symlinkPaths.get(n)!==o&&(this.fsw._symlinkPaths.set(n,o),this.fsw._emit(y.CHANGE,i,t.stats)):(h.add(e),this.fsw._symlinkPaths.set(n,o),this.fsw._emit(y.ADD,i,t.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(n))return !0;this.fsw._symlinkPaths.set(n,!0);}_handleRead(t,s,i,e,n,h,o){if(t=d.join(t,""),o=this.fsw._throttle("readdir",t,1e3),!o)return;let a=this.fsw._getWatchedDir(i.path),l=new Set,c=this.fsw._readdirp(t,{fileFilter:f=>i.filterPath(f),directoryFilter:f=>i.filterDir(f)});if(c)return c.on(Ot,async f=>{if(this.fsw.closed){c=void 0;return}let u=f.path,w=d.join(t,u);if(l.add(u),!(f.stats.isSymbolicLink()&&await this._handleSymlink(f,t,w,u))){if(this.fsw.closed){c=void 0;return}(u===e||!e&&!a.has(u))&&(this.fsw._incrReadyCount(),w=d.join(n,d.relative(n,w)),this._addToNodeFs(w,s,i,h+1));}}).on(y.ERROR,this._boundHandleError),new Promise((f,u)=>{if(!c)return u();c.once(j,()=>{if(this.fsw.closed){c=void 0;return}let w=o?o.clear():!1;f(void 0),a.getChildren().filter(p=>p!==t&&!l.has(p)).forEach(p=>{this.fsw._remove(t,p);}),c=void 0,w&&this._handleRead(t,!1,i,e,n,h,o);});})}async _handleDir(t,s,i,e,n,h,o){let a=this.fsw._getWatchedDir(d.dirname(t)),l=a.has(d.basename(t));!(i&&this.fsw.options.ignoreInitial)&&!n&&!l&&this.fsw._emit(y.ADD_DIR,t,s),a.add(d.basename(t)),this.fsw._getWatchedDir(t);let c,f,u=this.fsw.options.depth;if((u==null||e<=u)&&!this.fsw._symlinkPaths.has(o)){if(!n&&(await this._handleRead(t,i,h,n,t,e,c),this.fsw.closed))return;f=this._watchWithNodeFs(t,(w,p)=>{p&&p.mtimeMs===0||this._handleRead(w,!1,h,n,t,e,c);});}return f}async _addToNodeFs(t,s,i,e,n){let h=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return h(),!1;let o=this.fsw._getWatchHelpers(t);i&&(o.filterPath=a=>i.filterPath(a),o.filterDir=a=>i.filterDir(a));try{let a=await Ht[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,a))return h(),!1;let l=this.fsw.options.followSymlinks,c;if(a.isDirectory()){let f=d.resolve(t),u=l?await realpath(t):t;if(this.fsw.closed||(c=await this._handleDir(o.watchPath,a,s,e,n,o,u),this.fsw.closed))return;f!==u&&u!==void 0&&this.fsw._symlinkPaths.set(f,u);}else if(a.isSymbolicLink()){let f=l?await realpath(t):t;if(this.fsw.closed)return;let u=d.dirname(o.watchPath);if(this.fsw._getWatchedDir(u).add(o.watchPath),this.fsw._emit(y.ADD,o.watchPath,a),c=await this._handleDir(u,a,s,e,t,o,f),this.fsw.closed)return;f!==void 0&&this.fsw._symlinkPaths.set(d.resolve(t),f);}else c=this._handleFile(o.watchPath,a,s);return h(),c&&this.fsw._addPathCloser(t,c),!1}catch(a){if(this.fsw._handleError(a))return h(),t}}};});function W(r){return Array.isArray(r)?r:[r]}function rs(r){return typeof r=="function"?r:typeof r=="string"?t=>r===t:r instanceof RegExp?t=>r.test(t):typeof r=="object"&&r!==null?t=>{if(r.path===t)return !0;if(r.recursive){let s=d.relative(r.path,t);return s?!s.startsWith("..")&&!d.isAbsolute(s):!1}return !1}:()=>!1}function ns(r){if(typeof r!="string")throw new Error("string expected");r=d.normalize(r),r=r.replace(/\\/g,"/");let t=!1;r.startsWith("//")&&(t=!0);let s=/\/\//;for(;r.match(s);)r=r.replace(s,"/");return t&&(r="/"+r),r}function dt(r,t,s){let i=ns(t);for(let e=0;e<r.length;e++){let n=r[e];if(n(i,s))return !0}return !1}function os(r,t){if(r==null)throw new TypeError("anymatch: specify first argument");let i=W(r).map(e=>rs(e));return t==null?(e,n)=>dt(i,e,n):dt(i,t)}function fs(r,t={}){let s=new N(t);return s.add(r),s}var Y,Xt,wt,Zt,ts,ss,ft,es,is,G,ut,mt,pt,_t,as,hs,K,cs,ls,B,N,Ts,ds=b$1(()=>{k();it();lt();Y="/",Xt="//",wt=".",Zt="..",ts="string",ss=/\\/g,ft=/\/\//,es=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,is=/^\.[/\\]/;G=r=>typeof r=="object"&&r!==null&&!(r instanceof RegExp);ut=r=>{let t=W(r).flat();if(!t.every(s=>typeof s===ts))throw new TypeError(`Non-string provided as watch path: ${t}`);return t.map(pt)},mt=r=>{let t=r.replace(ss,Y),s=!1;for(t.startsWith(Xt)&&(s=!0);t.match(ft);)t=t.replace(ft,Y);return s&&(t=Y+t),t},pt=r=>mt(d.normalize(mt(r))),_t=(r="")=>t=>typeof t=="string"?pt(d.isAbsolute(t)?t:d.join(r,t)):t,as=(r,t)=>d.isAbsolute(r)?r:d.join(t,r),hs=Object.freeze(new Set),K=class{constructor(t,s){this.path=t,this._removeWatcher=s,this.items=new Set;}add(t){let{items:s}=this;s&&t!==wt&&t!==Zt&&s.add(t);}async remove(t){let{items:s}=this;if(!s||(s.delete(t),s.size>0))return;let i=this.path;try{await readdir(i);}catch{this._removeWatcher&&this._removeWatcher(d.dirname(i),d.basename(i));}}has(t){let{items:s}=this;if(s)return s.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=F,this.items=hs,Object.freeze(this);}},cs="stat",ls="lstat",B=class{constructor(t,s,i){this.fsw=i;let e=t;this.path=t=t.replace(is,""),this.watchPath=e,this.fullWatchPath=d.resolve(e),this.dirParts=[],this.dirParts.forEach(n=>{n.length>1&&n.pop();}),this.followSymlinks=s,this.statMethod=s?cs:ls;}entryPath(t){return d.join(this.watchPath,d.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:s}=t;if(s&&s.isSymbolicLink())return this.filterDir(t);let i=this.entryPath(t);return this.fsw._isntIgnored(i,s)&&this.fsw._hasReadPermissions(s)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}},N=class extends EventEmitter{constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let s=t.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},e={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?W(t.ignored):W([]),awaitWriteFinish:s===!0?i:typeof s=="object"?{...i,...s}:!1};ht&&(e.usePolling=!0),e.atomic===void 0&&(e.atomic=!e.usePolling);let n=process.env.CHOKIDAR_USEPOLLING;if(n!==void 0){let a=n.toLowerCase();a==="false"||a==="0"?e.usePolling=!1:a==="true"||a==="1"?e.usePolling=!0:e.usePolling=!!a;}let h=process.env.CHOKIDAR_INTERVAL;h&&(e.interval=Number.parseInt(h,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=F,this._readyEmitted=!0,process.nextTick(()=>this.emit(_.READY)));},this._emitRaw=(...a)=>this.emit(_.RAW,...a),this._boundRemove=this._remove.bind(this),this.options=e,this._nodeFsHandler=new S(this),Object.freeze(e);}_addIgnoredPath(t){if(G(t)){for(let s of this._ignoredPaths)if(G(s)&&s.path===t.path&&s.recursive===t.recursive)return}this._ignoredPaths.add(t);}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),typeof t=="string")for(let s of this._ignoredPaths)G(s)&&s.path===t&&this._ignoredPaths.delete(s);}add(t,s,i){let{cwd:e}=this.options;this.closed=!1,this._closePromise=void 0;let n=ut(t);return e&&(n=n.map(h=>as(h,e))),n.forEach(h=>{this._removeIgnoredPath(h);}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=n.length,Promise.all(n.map(async h=>{let o=await this._nodeFsHandler._addToNodeFs(h,!i,void 0,0,s);return o&&this._emitReady(),o})).then(h=>{this.closed||h.forEach(o=>{o&&this.add(d.dirname(o),d.basename(s||o));});}),this}unwatch(t){if(this.closed)return this;let s=ut(t),{cwd:i}=this.options;return s.forEach(e=>{!d.isAbsolute(e)&&!this._closers.has(e)&&(i&&(e=d.join(i,e)),e=d.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0;}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(s=>s.forEach(i=>{let e=i();e instanceof Promise&&t.push(e);})),this._streams.forEach(s=>s.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(s=>s.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>{}):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((s,i)=>{let n=(this.options.cwd?d.relative(this.options.cwd,i):i)||wt;t[n]=s.getChildren().sort();}),t}emitWithAll(t,s){this.emit(...s),t!==_.ERROR&&this.emit(_.ALL,...s);}async _emit(t,s,i){if(this.closed)return;let e=this.options;U&&(s=d.normalize(s)),e.cwd&&(s=d.relative(e.cwd,s));let n=[t,s];i!=null&&n.push(i);let h=e.awaitWriteFinish,o;if(h&&(o=this._pendingWrites.get(s)))return o.lastChange=new Date,this;if(e.atomic){if(t===_.UNLINK)return this._pendingUnlinks.set(s,n),setTimeout(()=>{this._pendingUnlinks.forEach((a,l)=>{this.emit(...a),this.emit(_.ALL,...a),this._pendingUnlinks.delete(l);});},typeof e.atomic=="number"?e.atomic:100),this;t===_.ADD&&this._pendingUnlinks.has(s)&&(t=n[0]=_.CHANGE,this._pendingUnlinks.delete(s));}if(h&&(t===_.ADD||t===_.CHANGE)&&this._readyEmitted){let a=(l,c)=>{l?(t=n[0]=_.ERROR,n[1]=l,this.emitWithAll(t,n)):c&&(n.length>2?n[2]=c:n.push(c),this.emitWithAll(t,n));};return this._awaitWriteFinish(s,h.stabilityThreshold,t,a),this}if(t===_.CHANGE&&!this._throttle(_.CHANGE,s,50))return this;if(e.alwaysStat&&i===void 0&&(t===_.ADD||t===_.ADD_DIR||t===_.CHANGE)){let a=e.cwd?d.join(e.cwd,s):s,l;try{l=await stat(a);}catch{}if(!l||this.closed)return;n.push(l);}return this.emitWithAll(t,n),this}_handleError(t){let s=t&&t.code;return t&&s!=="ENOENT"&&s!=="ENOTDIR"&&(!this.options.ignorePermissionErrors||s!=="EPERM"&&s!=="EACCES")&&this.emit(_.ERROR,t),t||this.closed}_throttle(t,s,i){this._throttled.has(t)||this._throttled.set(t,new Map);let e=this._throttled.get(t);if(!e)throw new Error("invalid throttle");let n=e.get(s);if(n)return n.count++,!1;let h,o=()=>{let l=e.get(s),c=l?l.count:0;return e.delete(s),clearTimeout(h),l&&clearTimeout(l.timeoutObject),c};h=setTimeout(o,i);let a={timeoutObject:h,clear:o,count:0};return e.set(s,a),a}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,s,i,e){let n=this.options.awaitWriteFinish;if(typeof n!="object")return;let h=n.pollInterval,o,a=t;this.options.cwd&&!d.isAbsolute(t)&&(a=d.join(this.options.cwd,t));let l=new Date,c=this._pendingWrites;function f(u){stat$1(a,(w,p)=>{if(w||!c.has(t)){w&&w.code!=="ENOENT"&&e(w);return}let R=Number(new Date);u&&p.size!==u.size&&(c.get(t).lastChange=R);let yt=c.get(t);R-yt.lastChange>=s?(c.delete(t),e(void 0,p)):o=setTimeout(f,h,p);});}c.has(t)||(c.set(t,{lastChange:l,cancelWait:()=>(c.delete(t),clearTimeout(o),i)}),o=setTimeout(f,h));}_isIgnored(t,s){if(this.options.atomic&&es.test(t))return !0;if(!this._userIgnored){let{cwd:i}=this.options,n=(this.options.ignored||[]).map(_t(i)),o=[...[...this._ignoredPaths].map(_t(i)),...n];this._userIgnored=os(o,void 0);}return this._userIgnored(t,s)}_isntIgnored(t,s){return !this._isIgnored(t,s)}_getWatchHelpers(t){return new B(t,this.options.followSymlinks,this)}_getWatchedDir(t){let s=d.resolve(t);return this._watched.has(s)||this._watched.set(s,new K(s,this._boundRemove)),this._watched.get(s)}_hasReadPermissions(t){return this.options.ignorePermissionErrors?!0:!!(Number(t.mode)&256)}_remove(t,s,i){let e=d.join(t,s),n=d.resolve(e);if(i=i??(this._watched.has(e)||this._watched.has(n)),!this._throttle("remove",e,100))return;!i&&this._watched.size===1&&this.add(t,s,!0),this._getWatchedDir(e).getChildren().forEach(u=>this._remove(e,u));let a=this._getWatchedDir(t),l=a.has(s);a.remove(s),this._symlinkPaths.has(n)&&this._symlinkPaths.delete(n);let c=e;if(this.options.cwd&&(c=d.relative(this.options.cwd,e)),this.options.awaitWriteFinish&&this._pendingWrites.has(c)&&this._pendingWrites.get(c).cancelWait()===_.ADD)return;this._watched.delete(e),this._watched.delete(n);let f=i?_.UNLINK_DIR:_.UNLINK;l&&!this._isIgnored(e)&&this._emit(f,e),this._closePath(e);}_closePath(t){this._closeFile(t);let s=d.dirname(t);this._getWatchedDir(s).remove(d.basename(t));}_closeFile(t){let s=this._closers.get(t);s&&(s.forEach(i=>i()),this._closers.delete(t));}_addPathCloser(t,s){if(!s)return;let i=this._closers.get(t);i||(i=[],this._closers.set(t,i)),i.push(s);}_readdirp(t,s){if(this.closed)return;let i={type:_.ALL,alwaysStat:!0,lstat:!0,...s,depth:0},e=et(t,i);return this._streams.add(e),e.once(at,()=>{e=void 0;}),e.once(j,()=>{e&&(this._streams.delete(e),e=void 0);}),e}};Ts={watch:fs,FSWatcher:N};});ds(); export{N as FSWatcher,B as WatchHelper,Ts as default,fs as watch};