openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
4 lines • 1.3 kB
JavaScript
import{i as resolveRuntimeWorkerThreadExecArgv}from"../runtime-worker-url-Dqf-I1cs.mjs";import{o as resolveRuntimeProcessEntrypointUrl}from"../runtime-process-url-DJ272Tuo.mjs";import fs from"node:fs";import{Worker}from"node:worker_threads";
//!src/infra/directory-watch-host.worker.ts
const parentMonitor=resolveRuntimeProcessEntrypointUrl(`directoryWatchParent`);new Worker(parentMonitor,{execArgv:resolveRuntimeWorkerThreadExecArgv(parentMonitor),workerData:{caller:Number(process.argv[2])}}).on(`error`,()=>{}).unref();const live=/* @__PURE__ */ new Map;const send=e=>process.stdout.write(`${JSON.stringify(e)}\n`);let buffered=``;process.stdin.setEncoding(`utf8`).on(`data`,e=>{const t=(buffered+e).split(`
`);buffered=t.pop()??``;for(const e of t){const{id:t,path:n,recursive:r}=JSON.parse(e);if(n===void 0){if(process.platform!==`darwin`)live.get(t)?.close();live.delete(t);continue}try{if(r)fs.accessSync(n,fs.constants.R_OK);const e=process.platform===`win32`&&n.includes(`~`)?fs.realpathSync.native(n):n;const i=fs.watch(e,{persistent:false,recursive:r},(e,n)=>{if(live.has(t))send({id:t,event:e,filename:n})}).on(`error`,()=>live.delete(t)&&send({id:t}));live.set(t,i);send({id:t,event:`change`})}catch{send({id:t})}}});process.stdin.on(`end`,()=>process.kill(process.pid,`SIGKILL`));export{};