var T=Object.defineProperty;var v=(s,r)=>T(s,"name",{value:r,configurable:!0});import{createRequire as W}from"node:module";import{C as _,K as k,z as F}from"./readFileSync-DseCu8sg-DEq4Fn3a.js";import{p as u}from"../packem_chunks/bin.js";const j=W(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=v(s=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[r,a]=p.versions.node.split(".").map(Number);if(r>22||r===22&&a>=3||r===20&&a>=16)return p.getBuiltinModule(s)}return j(s)},"__cjs_getBuiltinModule"),{watch:S}=g("node:fs"),{execFileSync:q}=g("node:child_process"),{createRequire:A}=g("node:module");var C=Object.defineProperty,b=v((s,r)=>C(s,"name",{value:r,configurable:!0}),"r");const $=A(import.meta.url);let w;const P=b(()=>{if(w!==void 0)return w;try{$.resolve("fb-watchman")}catch{return w=!1,!1}try{q("watchman",["--version"],{stdio:"ignore",timeout:2e3})}catch{return w=!1,!1}return w=!0,!0},"isWatchmanAvailable"),x=b((s,r)=>{if(!P())return;let a;try{a=$("fb-watchman")}catch(o){u.warn(`[vis watch] fb-watchman failed to load, using native watcher: ${o.message}`);return}const n=new a.Client;n.on("error",o=>{u.warn(`[vis watch] watchman error: ${o.message}`)}),n.on("subscription",o=>{const t=o;if(!t.is_fresh_instance)for(const e of t.files??[])r(e)});for(const[o,t]of s.entries()){const e=_(t),i=`vis-watch-${o}-${process.pid}`;n.command(["watch-project",e],(l,h)=>{if(l){u.warn(`[vis watch] watchman could not watch ${t}: ${l.message}`);return}const d={expression:["allof",["type","f"]],fields:["name"]};h.relative_path&&(d.relative_root=h.relative_path),n.command(["subscribe",h.watch,i,d],c=>{c&&u.warn(`[vis watch] watchman subscribe failed for ${t}: ${c.message}`)})})}return{close:b(()=>{try{n.end()}catch{}},"close")}},"startWatchmanWatcher");var M=Object.defineProperty,f=v((s,r)=>M(s,"name",{value:r,configurable:!0}),"c");const O=[/node_modules(?:\/|$)/,/\.git(?:\/|$)/,/\.vis(?:\/|$)/],N=f((s,r)=>{const a=new Set,n=new Set;for(const[,e]of s){const i=e.task.hashDetails?.nodes;if(i)for(const l of Object.keys(i))a.add(l),n.add(k(_(r,l)))}const o=[...n].sort(),t=[];for(const e of o)t.some(i=>e===i||e.startsWith(`${i}/`))||t.push(e);return{directories:t,files:a}},"collectTrackedWatchTargets"),E=f((s,r,a)=>{const n=new Set;for(const o of s){const t=_(r,o);for(const e of a)if(t===e||t.startsWith(`${e}/`)){const i=F(e,t);i.length>0&&n.add(i)}}return o=>{const t=o.replaceAll("\\","/");return n.has(t)}},"createTrackedFileFilter"),R=f(s=>{const r=s.replaceAll("\\","/");return O.some(a=>a.test(r))},"shouldIgnore"),G=f(s=>{const{debounceMs:r=150,filter:a,onChange:n,paths:o}=s;let t=new Set,e;const i=f(()=>{e=void 0;const c=[...t];t=new Set,c.length!==0&&Promise.resolve(n(c)).catch(m=>{u.error("[vis watch] onChange handler failed:",m)})},"flush"),l=f(c=>{R(c)||a&&!a(c)||(t.add(c),e&&clearTimeout(e),e=setTimeout(i,r))},"emit"),h=x(o,l);if(h)return{close:f(()=>{e&&clearTimeout(e),h.close()},"close")};const d=[];for(const c of o)try{const m=S(c,{recursive:!0},(z,y)=>{y&&l(y)});d.push(m)}catch(m){u.warn(`[vis watch] unable to watch ${c}: ${m.message}`)}return{close:f(()=>{e&&clearTimeout(e);for(const c of d)try{c.close()}catch{}},"close")}},"startWatcher");export{E as a,N as c,G as s};
