serve-sim 0.1.42-beta.87.1 → 0.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/serve-sim-bin CHANGED
Binary file
package/dist/serve-sim.js CHANGED
@@ -111,7 +111,7 @@ Usage:
111
111
  serve-sim permissions reset <permission|all> <bundle-id> [-d <udid|name>]
112
112
  serve-sim permissions list [bundle-id] [-d <udid|name>]
113
113
 
114
- Permissions: ${oS().join(", ")}`),process.exit(1);let C=s.device?Q(s.device):C_();if(!C)console.error("No booted simulator. Boot one or pass -d <udid|name>."),process.exit(1);if(s.verb==="list"){let i={udid:C,bundleId:s.bundleId??null,tcc:PA(C,s.bundleId),location:UA(C,s.bundleId),notifications:KA(C,s.bundleId)};console.log(JSON.stringify(i,null,e?0:2)),process.exit(0)}let t=s.bundleId;try{if(s.permission==="all")for(let i of oS())tC(C,"reset",i,void 0,t);else tC(C,s.verb,s.permission,s.value,t)}catch(i){console.error(i?.message??String(i)),process.exit(1)}if(e)console.log(JSON.stringify({udid:C,verb:s.verb,permission:s.permission,value:s.value??null,bundleId:t}));else{let i=s.value?` (${s.value})`:"";console.log(`\uD83D\uDD10 ${s.verb} ${s.permission}${i} for ${t} on ${C}`)}process.exit(0)}vS();VS();var x_="./serve-sim-bin-ae4qvz22.";var a_=ve(import.meta.url);function mr(){return"0.1.42-beta.87.1"}function cs(){if(!K(T_))Xe(T_,{recursive:!0})}function $_(_){if(_)return os(fe(_));for(let e of Ee()){let S=os(e);if(S)return S}return null}var Ie={at:0,booted:null};function Ir(){let _=Date.now();if(Ie.booted&&_-Ie.at<1000)return Ie.booted;try{let e=z("xcrun simctl list devices booted -j",{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:3000}),S=JSON.parse(e),s=new Set;for(let C of Object.values(S.devices))for(let t of C)if(t.state==="Booted")s.add(t.udid);return Ie={at:_,booted:s},s}catch{return null}}function os(_){try{if(!K(_))return c_("state file missing %s",_),null;let e=JSON.parse(S_(_,"utf-8"));try{process.kill(e.pid,0)}catch{return c_("helper pid %d dead, removing stale state %s",e.pid,_),j_(_),null}let S=Ir();if(S&&!S.has(e.device)){c_("helper pid %d bound to non-booted device %s — killing stale helper",e.pid,e.device),console.error(`[serve-sim] Helper pid ${e.pid} is bound to device ${e.device} which is no longer booted — killing stale helper.`);try{process.kill(e.pid,"SIGTERM")}catch{}try{j_(_)}catch{}return null}return c_("state ok pid=%d device=%s port=%d",e.pid,e.device,e.port),e}catch(e){return c_("readStateFile threw for %s: %o",_,e),null}}function Ze(){let _=[];for(let e of Ee()){let S=os(e);if(S)_.push(S)}return _}function jt(_){cs(),ze(fe(_.device),JSON.stringify(_,null,2)),c_("wrote state pid=%d device=%s port=%d",_.pid,_.device,_.port)}function Te(_){if(_){c_("clearState device=%s",_);try{j_(fe(_))}catch{}}else{c_("clearState (all)");for(let e of Ee())try{j_(e)}catch{}}}function Kr(){let _=x_.startsWith("/$bunfs/");if(!_&&K(x_))return x_;if(!_){let t=r_(a_,"../bin/serve-sim-bin");if(K(t))return t;throw Error(`serve-sim-bin not found. Run 'bun run build:swift' first.
114
+ Permissions: ${oS().join(", ")}`),process.exit(1);let C=s.device?Q(s.device):C_();if(!C)console.error("No booted simulator. Boot one or pass -d <udid|name>."),process.exit(1);if(s.verb==="list"){let i={udid:C,bundleId:s.bundleId??null,tcc:PA(C,s.bundleId),location:UA(C,s.bundleId),notifications:KA(C,s.bundleId)};console.log(JSON.stringify(i,null,e?0:2)),process.exit(0)}let t=s.bundleId;try{if(s.permission==="all")for(let i of oS())tC(C,"reset",i,void 0,t);else tC(C,s.verb,s.permission,s.value,t)}catch(i){console.error(i?.message??String(i)),process.exit(1)}if(e)console.log(JSON.stringify({udid:C,verb:s.verb,permission:s.permission,value:s.value??null,bundleId:t}));else{let i=s.value?` (${s.value})`:"";console.log(`\uD83D\uDD10 ${s.verb} ${s.permission}${i} for ${t} on ${C}`)}process.exit(0)}vS();VS();var x_="./serve-sim-bin-2bbcqrwg.";var a_=ve(import.meta.url);function mr(){return"0.1.42"}function cs(){if(!K(T_))Xe(T_,{recursive:!0})}function $_(_){if(_)return os(fe(_));for(let e of Ee()){let S=os(e);if(S)return S}return null}var Ie={at:0,booted:null};function Ir(){let _=Date.now();if(Ie.booted&&_-Ie.at<1000)return Ie.booted;try{let e=z("xcrun simctl list devices booted -j",{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:3000}),S=JSON.parse(e),s=new Set;for(let C of Object.values(S.devices))for(let t of C)if(t.state==="Booted")s.add(t.udid);return Ie={at:_,booted:s},s}catch{return null}}function os(_){try{if(!K(_))return c_("state file missing %s",_),null;let e=JSON.parse(S_(_,"utf-8"));try{process.kill(e.pid,0)}catch{return c_("helper pid %d dead, removing stale state %s",e.pid,_),j_(_),null}let S=Ir();if(S&&!S.has(e.device)){c_("helper pid %d bound to non-booted device %s — killing stale helper",e.pid,e.device),console.error(`[serve-sim] Helper pid ${e.pid} is bound to device ${e.device} which is no longer booted — killing stale helper.`);try{process.kill(e.pid,"SIGTERM")}catch{}try{j_(_)}catch{}return null}return c_("state ok pid=%d device=%s port=%d",e.pid,e.device,e.port),e}catch(e){return c_("readStateFile threw for %s: %o",_,e),null}}function Ze(){let _=[];for(let e of Ee()){let S=os(e);if(S)_.push(S)}return _}function jt(_){cs(),ze(fe(_.device),JSON.stringify(_,null,2)),c_("wrote state pid=%d device=%s port=%d",_.pid,_.device,_.port)}function Te(_){if(_){c_("clearState device=%s",_);try{j_(fe(_))}catch{}}else{c_("clearState (all)");for(let e of Ee())try{j_(e)}catch{}}}function Kr(){let _=x_.startsWith("/$bunfs/");if(!_&&K(x_))return x_;if(!_){let t=r_(a_,"../bin/serve-sim-bin");if(K(t))return t;throw Error(`serve-sim-bin not found. Run 'bun run build:swift' first.
115
115
  Checked: ${x_}, ${t}`)}let e=S_(x_),S=Ds("sha256").update(e).digest("hex").slice(0,16),s=r_(Ur(),"Library/Caches/serve-sim");Xe(s,{recursive:!0});let C=r_(s,`serve-sim-bin-${S}`);if(!K(C)){ze(C,e),Pr(C,493);try{z(`codesign -s - -f ${JSON.stringify(C)}`,{stdio:"ignore"})}catch{}}return C}function Yt(){try{let _=z("xcrun simctl list devices -j",{encoding:"utf-8"}),e=JSON.parse(_),S=Object.keys(e.devices).filter((s)=>/SimRuntime\.iOS-/i.test(s)).sort((s,C)=>{let t=(s.match(/iOS-(\d+)-(\d+)/)??[]).slice(1).map(Number),i=(C.match(/iOS-(\d+)-(\d+)/)??[]).slice(1).map(Number);return(i[0]??0)-(t[0]??0)||(i[1]??0)-(t[1]??0)});for(let s of S){let t=(e.devices[s]??[]).find((i)=>i.isAvailable!==!1&&/^iPhone\b/i.test(i.name));if(t)return{udid:t.udid,name:t.name}}}catch{}return null}function Jt(_){try{let e=z("xcrun simctl list devices -j",{encoding:"utf-8"}),S=JSON.parse(e);for(let s of Object.values(S.devices))for(let C of s)if(C.udid===_)return C.name}catch{}return null}function _i(_){try{let e=z("xcrun simctl list devices -j",{encoding:"utf-8"}),S=JSON.parse(e);for(let s of Object.values(S.devices))for(let C of s)if(C.udid===_)return C.state==="Booted"}catch{}return!1}function G_(_){try{return process.kill(_,0),!0}catch{return!1}}function ns(_){try{process.kill(_,"SIGTERM")}catch{return}let e=Date.now()+500;while(Date.now()<e)try{process.kill(_,0),V_(25)}catch{return}try{process.kill(_,"SIGKILL")}catch{}let S=Date.now()+500;while(Date.now()<S)try{process.kill(_,0),V_(25)}catch{return}}function Xr(_){if(!_i(_))try{z(`xcrun simctl boot ${_}`,{encoding:"utf-8",stdio:"pipe"})}catch(e){let S=(e.stderr??e.message??"").toLowerCase();if(!S.includes("booted")&&!S.includes("current state"))throw Error(`Failed to boot device ${_}: ${e.stderr||e.message}`)}try{z("open -ga Simulator",{encoding:"utf-8",stdio:"pipe",timeout:3000})}catch{}}function kr(){let _=qr();for(let e of Object.values(_))for(let S of e??[])if(S.family==="IPv4"&&!S.internal)return S.address;return null}async function ei(_){let e=new Set(Ze().map((S)=>S.port));for(let S=_;S<_+100;S++){if(e.has(S))continue;if(await eC(S))return S}throw Error(`No available port found in range ${_}-${_+99}`)}async function xr(_){Xr(_);try{z(`xcrun simctl bootstatus ${_} -b`,{encoding:"utf-8",stdio:"pipe",timeout:60000})}catch(e){if(!_i(_))console.error(`Device ${_} failed to reach booted state: ${e.stderr||e.message}`),process.exit(1)}}async function Si(_,e,S,s){let C=!1,t=Date.now();j("waitForHelperReady pid=%d url=%s",_,e);for(let o=0;o<30;o++){if(!s()){j("helper pid=%d died during /health polling (attempt %d)",_,o);break}try{if((await fetch(`${e}/health`)).ok){C=!0,j("helper pid=%d /health ok after %dms",_,Date.now()-t);break}}catch{}await new Promise((y)=>setTimeout(y,100))}if(!C)j("helper pid=%d /health never responded (%dms)",_,Date.now()-t);if(C){let o=Date.now(),y=o+8000,$=!1;while(Date.now()<y){if(await new Promise((A)=>setTimeout(A,200)),!s()){j("helper pid=%d died while awaiting Capture started",_),C=!1;break}try{if(S_(S,"utf-8").includes("Capture started")){$=!0,j("helper pid=%d saw 'Capture started' after %dms",_,Date.now()-o);break}}catch{}}if(C&&!$)j("helper pid=%d ready but never logged 'Capture started' within %dms — stream may not produce frames",_,Date.now()-o)}let i="";try{i=S_(S,"utf-8").trim()}catch{}return{ready:C,log:i}}async function zr(_){let{helperPath:e,udid:S,port:s,host:C,logFile:t}=_,i=`http://${C}:${s}`;cs();let o=ke(t,"w"),y=Ts(e,[S,"--port",String(s)],{detached:!0,stdio:["ignore",o,o]});y.unref(),xe(o);let $=y.pid,A=!1;y.once("exit",()=>{A=!0});let{ready:n,log:D}=await Si($,i,t,()=>!A&&G_($));return{ready:n,pid:$,exited:A||!G_($),log:D}}async function Zr(_){let{helperPath:e,udid:S,port:s,host:C,logFile:t}=_,i=`http://${C}:${s}`;cs();let o=ke(t,"w"),y=Ts(e,[S,"--port",String(s)],{detached:!1,stdio:["ignore",o,o]});xe(o);let $=y.pid,A=!1;y.once("exit",()=>{A=!0});let{ready:n,log:D}=await Si($,i,t,()=>!A&&G_($));return{ready:n,child:y,log:D}}async function si(_,e,S){j("startHelper udid=%s port=%d detach=%s",_,e,S.detach),await xr(_);let s="127.0.0.1",C=Kr(),t=e_(T_,`server-${_}.log`);j("helper binary=%s logFile=%s",C,t);let i={helperPath:C,udid:_,port:e,host:s,logFile:t},o="",y=2;for(let A=1;A<=y;A++){if(j("spawn attempt %d/%d",A,y),sC(e),S.detach){let n=await zr(i);if(j("spawnHelperDetached result ready=%s pid=%d exited=%s",n.ready,n.pid,n.exited),n.ready){let D={pid:n.pid,port:e,device:_,url:`http://${s}:${e}`,streamUrl:`http://${s}:${e}/stream.mjpeg`,wsUrl:`ws://${s}:${e}/ws`};return jt(D),{pid:n.pid}}ns(n.pid),o=n.log}else{let n=await Zr(i);if(j("spawnHelperAttached result ready=%s pid=%d",n.ready,n.child.pid),n.ready){let D={pid:n.child.pid,port:e,device:_,url:`http://${s}:${e}`,streamUrl:`http://${s}:${e}/stream.mjpeg`,wsUrl:`ws://${s}:${e}/ws`};return jt(D),{pid:n.child.pid,child:n.child}}ns(n.child.pid),o=n.log}if(A<y)await new Promise((n)=>setTimeout(n,500))}let $=o?`Helper failed:
116
116
  ${o}`:"Helper process failed to start";console.error($),process.exit(1)}async function Qr(_,e,S){wS("follow devices=%o startPort=%d",_,e);let s=_.length>0?_.map(Q):(()=>{let $=C_();if($)return[$];let A=Yt();if(!A)console.error("No device specified and no available iOS simulator found."),process.exit(1);if(!S)console.log(`No booted simulator — booting ${A.name}...`);return[A.udid]})(),C=new Map,t=[],i=e;for(let $ of s){let A=$_($);if(A){if(!S){let O=Jt($)??$;if(s.length>1)console.log(`
117
117
  ==> ${O} (${$}) <==`);console.log(` Already running on port ${A.port}`),console.log(` Stream: ${A.streamUrl}`),console.log(` WebSocket: ${A.wsUrl}`)}t.push(A);continue}i=await ei(i);let{pid:n,child:D}=await si($,i,{detach:!1});if(D)C.set($,D);let F="127.0.0.1",T={pid:n,port:i,device:$,url:`http://${F}:${i}`,streamUrl:`http://${F}:${i}/stream.mjpeg`,wsUrl:`ws://${F}:${i}/ws`};if(t.push(T),!S){let O=Jt($)??$;if(s.length>1)console.log(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serve-sim",
3
- "version": "0.1.42-beta.87.1",
3
+ "version": "0.1.42",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Evan Bacon",