@absolutejs/absolute 0.20.0-beta.43 → 0.20.0-beta.44

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.
Files changed (75) hide show
  1. package/dist/angular/browser.js +378 -361
  2. package/dist/angular/browser.js.map +2 -2
  3. package/dist/angular/components/core/streamingSlotRegistrar.js +7 -7
  4. package/dist/angular/components/core/streamingSlotRegistry.js +4 -4
  5. package/dist/angular/index.js +300 -294
  6. package/dist/angular/index.js.map +2 -2
  7. package/dist/angular/server.js +54 -50
  8. package/dist/angular/server.js.map +2 -2
  9. package/dist/build.js +199 -203
  10. package/dist/build.js.map +2 -2
  11. package/dist/cli/config/client.js +12 -12
  12. package/dist/cli/config/server.js +1096 -1090
  13. package/dist/cli/index.js +275 -161
  14. package/dist/client/index.js +29 -25
  15. package/dist/client/index.js.map +2 -2
  16. package/dist/core/streamingSlotRegistrar.js +15 -13
  17. package/dist/core/streamingSlotRegistrar.js.map +2 -2
  18. package/dist/core/streamingSlotRegistry.js +11 -9
  19. package/dist/core/streamingSlotRegistry.js.map +2 -2
  20. package/dist/image-client/imageClient.js +7 -7
  21. package/dist/index.js +782 -732
  22. package/dist/index.js.map +6 -5
  23. package/dist/islands/browser.js +11 -9
  24. package/dist/islands/browser.js.map +2 -2
  25. package/dist/islands/index.js +39 -35
  26. package/dist/islands/index.js.map +2 -2
  27. package/dist/mobile/browser.js +23 -22
  28. package/dist/mobile/browser.js.map +2 -2
  29. package/dist/mobile/index.js +552 -423
  30. package/dist/mobile/index.js.map +9 -9
  31. package/dist/mobile/remoteMacAgentEntry.js +115 -37
  32. package/dist/mobile/shellBootstrap.js +0 -1
  33. package/dist/mobile/shellExpoAuth.js +184 -0
  34. package/dist/mobile/shellExpoDevices.js +4 -5
  35. package/dist/mobile/shellSync.js +4 -4
  36. package/dist/react/browser.js +17 -15
  37. package/dist/react/browser.js.map +2 -2
  38. package/dist/react/components/browser/index.js +107 -107
  39. package/dist/react/components/index.js +118 -116
  40. package/dist/react/components/index.js.map +2 -2
  41. package/dist/react/hooks/index.js +11 -9
  42. package/dist/react/hooks/index.js.map +2 -2
  43. package/dist/react/index.js +53 -49
  44. package/dist/react/index.js.map +2 -2
  45. package/dist/react/jsxDevRuntimeCompat.js +11 -9
  46. package/dist/react/jsxDevRuntimeCompat.js.map +2 -2
  47. package/dist/react/jsxRuntimeCompat.js +11 -9
  48. package/dist/react/jsxRuntimeCompat.js.map +2 -2
  49. package/dist/react/router/browser.js +9 -7
  50. package/dist/react/router/browser.js.map +2 -2
  51. package/dist/react/router/index.js +9 -7
  52. package/dist/react/router/index.js.map +2 -2
  53. package/dist/react/server.js +12 -10
  54. package/dist/react/server.js.map +2 -2
  55. package/dist/src/mobile/devDeviceAdapter.d.ts +1 -1
  56. package/dist/src/mobile/expoBridge.d.ts +12 -12
  57. package/dist/src/mobile/nativeAuth.d.ts +3 -0
  58. package/dist/src/mobile/shellExpoAuth.d.ts +12 -0
  59. package/dist/svelte/browser.js +12 -10
  60. package/dist/svelte/browser.js.map +2 -2
  61. package/dist/svelte/index.js +47 -43
  62. package/dist/svelte/index.js.map +2 -2
  63. package/dist/svelte/server.js +29 -27
  64. package/dist/svelte/server.js.map +2 -2
  65. package/dist/vue/browser.js +14 -12
  66. package/dist/vue/browser.js.map +2 -2
  67. package/dist/vue/components/Image.js +9 -7
  68. package/dist/vue/components/Image.js.map +2 -2
  69. package/dist/vue/components/index.js +11 -9
  70. package/dist/vue/components/index.js.map +2 -2
  71. package/dist/vue/index.js +52 -48
  72. package/dist/vue/index.js.map +2 -2
  73. package/dist/vue/server.js +14 -12
  74. package/dist/vue/server.js.map +2 -2
  75. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  // @bun
2
- import{mkdir as ks,readFile as Rs,rm as Ie,writeFile as Cs}from"fs/promises";import{join as ue}from"path";import{createInterface as $r}from"readline";import{resolve as Ue}from"path";var Tr=/^[A-Za-z][\w]*(?:\.[A-Za-z][\w]*)+$/,mr=/^[a-z][a-z0-9+.-]*$/,Dr=/^[A-Z0-9]{10}$/,Nr=/^[0-9A-F]{64}$/,Ir=/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?))*$/,ee=(e,r,a)=>{let s=Ue(e),c=Ue(s,r);if(c!==s&&!c.startsWith(`${s}/`))throw TypeError(`${a} must remain inside the project root.`);return c},W=(e,r)=>{let a=e.trim();if(!a)throw TypeError(`${r} must not be empty.`);return a},Be=(e)=>{let r=W(e??"/","mobile.entry");if(!r.startsWith("/")||r.startsWith("//"))throw TypeError("mobile.entry must be an absolute application path.");return r},Mr=(e)=>{let r=new URL(W(e,"mobile.server.productionOrigin")),a=r.protocol==="http:"&&(r.hostname==="localhost"||r.hostname==="127.0.0.1"||r.hostname==="[::1]");if(r.protocol!=="https:"&&!a)throw TypeError("mobile.server.productionOrigin must use HTTPS, except for a loopback development origin.");if(r.username||r.password||r.pathname!=="/"||r.search||r.hash)throw TypeError("mobile.server.productionOrigin must be an origin without credentials, path, query, or hash.");return r.origin},kr=(e)=>{let r=[...new Set(e??["ios","android"])];if(r.length===0)throw TypeError("mobile.platforms must contain at least one platform.");return r},Rr=(e,r)=>{let a=(l)=>{let t=W(l,"mobile.deepLinks.hosts").toLowerCase();if(!Ir.test(t))throw TypeError("mobile.deepLinks.hosts entries must be valid hostnames without ports, wildcards, or paths.");return t},s=new URL(r).hostname,c=new Set(s==="[::1]"?[]:[a(s)]);for(let l of e??[])c.add(a(l));return[...c].sort()},Cr=(e)=>{if(e===void 0)return;let r=W(e,"mobile.deepLinks.apple.appIdPrefix").toUpperCase();if(!Dr.test(r))throw TypeError("mobile.deepLinks.apple.appIdPrefix must contain ten letters or digits.");return r},Wr=(e)=>{if(e===void 0)return;let r=W(e,"mobile.ios.version");if(!/^\d+(?:\.\d+){0,2}$/u.test(r))throw TypeError("mobile.ios.version must contain one to three dot-separated integer components, for example 1.4.0.");return r},Ur=(e)=>[...new Set((e??[]).map((r)=>W(r,"mobile.deepLinks.android.sha256CertificateFingerprints").replaceAll(":","").toUpperCase()).map((r)=>{if(!Nr.test(r))throw TypeError("mobile.deepLinks.android.sha256CertificateFingerprints entries must be SHA-256 certificate fingerprints.");return r.match(/.{2}/g)?.join(":")??r}))].sort(),Br=(e,r)=>{if(e.engine!=="expo")return{};let a=e.routes?.native??{},s={};for(let[c,l]of Object.entries(a)){let t=Be(c);if(t.includes("?")||t.includes("#")||t!=="/"&&t.endsWith("/"))throw TypeError(`mobile.routes.native route ${t} must be a canonical path without a query, fragment, or trailing slash.`);if(t==="/__absolute/native")throw TypeError("mobile.routes.native reserves /__absolute/native for the Expo diagnostic screen.");if(t.includes("*")||t.includes(":"))throw TypeError(`mobile.routes.native route ${t} must be static during the Expo experiment; parameters and wildcards are not supported yet.`);s[t]=ee(r,W(l,`mobile.routes.native[${t}]`),`mobile.routes.native[${t}]`)}return Object.fromEntries(Object.entries(s).sort(([c],[l])=>c.localeCompare(l)))},Je=(e,r)=>{let a=W(e.appId,"mobile.appId");if(!Tr.test(a))throw TypeError("mobile.appId must use reverse-domain notation, for example com.example.app.");let s=Mr(e.server.productionOrigin),c=(e.deepLinks?.scheme??a).trim().toLowerCase();if(c&&!mr.test(c))throw TypeError("mobile.deepLinks.scheme is not a valid URL scheme.");return{androidCertificateFingerprints:Ur(e.deepLinks?.android?.sha256CertificateFingerprints),appId:a,appleAppIdPrefix:Cr(e.deepLinks?.apple?.appIdPrefix),appName:W(e.appName,"mobile.appName"),bundleDirectory:ee(r,e.bundleDirectory??".absolutejs/mobile/web","mobile.bundleDirectory"),deepLinkHosts:Rr(e.deepLinks?.hosts,s),deepLinkScheme:c,engine:e.engine??"capacitor",entry:Be(e.entry),expoNativeRoutes:Br(e,r),...e.engine==="expo"?{expoSdkVersion:e.expo?.sdkVersion??57}:{},iosVersion:Wr(e.ios?.version),nativeProjectDirectory:ee(r,e.nativeProject?.directory??(e.engine==="expo"?".absolutejs/mobile/expo":"mobile"),"mobile.nativeProject.directory"),platforms:kr(e.platforms),productionOrigin:s,pushAndroidGoogleServicesFile:ee(r,e.pushNotifications?.android?.googleServicesFile??"google-services.json","mobile.pushNotifications.android.googleServicesFile")}};import{spawn as Pr}from"child_process";import{access as Yr}from"fs/promises";import{join as qr}from"path";import{randomUUID as Jr,X509Certificate as Hr}from"crypto";import{createServer as Lr}from"http";import{connect as Vr,createServer as He,isIP as Gr}from"net";import{readFile as Fr}from"fs/promises";var Ae=(e)=>new Promise((r,a)=>{e.close((s)=>{if(s)a(s);else r()})}),Le=(e,r)=>new Promise((a,s)=>{e.once("error",s),e.listen(r,"0.0.0.0",()=>{e.off("error",s);let c=e.address();if(!c||typeof c==="string"){s(Error("Could not determine the iOS device helper port."));return}a(c.port)})}),Xr=async()=>{let e=He(),r=await new Promise((a,s)=>{e.once("error",s),e.listen(0,"127.0.0.1",()=>{let c=e.address();if(!c||typeof c==="string"){s(Error("Could not allocate the iOS CA enrollment port."));return}a(c.port)})});return await Ae(e),r},ye=(e)=>{let r=e.trim();if(!r||r.length>253||/[\0\s/?#]/u.test(r))throw TypeError("Physical iOS development requires a valid LAN host.");return r},Ve=(e)=>{let r=e.trim();if(!r||r.length>256||/[\0\r\n]/u.test(r))throw TypeError("--ios-device requires a valid Xcode device identifier or name.");return r},Kr=(e,r,a)=>{let s=new URL(`${e}://localhost:${a}`),c=ye(r);return s.hostname=Gr(c)===6?`[${c}]`:c,s},re=async(e)=>{let a=new Hr(await Fr(e.certificateAuthorityPath)).raw,c=`/${Jr().replaceAll("-","")}/absolutejs-development-ca.cer`,l=Lr((w,b)=>{if(w.method!=="GET"||w.url!==c){b.writeHead(404,{"Cache-Control":"no-store","Content-Type":"text/plain; charset=utf-8"}),b.end("Not found.");return}b.writeHead(200,{"Cache-Control":"no-store","Content-Disposition":'attachment; filename="absolutejs-development-ca.cer"',"Content-Length":String(a.byteLength),"Content-Type":"application/x-x509-ca-cert","X-Content-Type-Options":"nosniff"}),b.end(a)}),t=await Xr();await Le(l,t);let u=Kr("http",e.displayHost,t);return u.pathname=c,{url:u.href,close:()=>Ae(l)}},ae=async(e)=>{let r=He((a)=>{let s=Vr({host:"127.0.0.1",port:e.targetPort});a.pipe(s),s.pipe(a);let c=()=>{a.destroy(),s.destroy()};a.once("error",c),s.once("error",c)});return await Le(r,e.listenPort),{close:()=>Ae(r)}};var Zr=60000,Qr=2000,zr=(e)=>({ABSOLUTE_EXPO_DEVELOPMENT:"1",...e.certificateAuthorityPath?{ABSOLUTE_EXPO_DEVELOPMENT_CA_PATH:e.certificateAuthorityPath}:{},...e.androidOrigin?{EXPO_PUBLIC_ABSOLUTE_DEV_ANDROID_ORIGIN:e.androidOrigin}:{},...e.iosOrigin?{EXPO_PUBLIC_ABSOLUTE_DEV_IOS_ORIGIN:e.iosOrigin}:{},...e.metroHost?{REACT_NATIVE_PACKAGER_HOSTNAME:e.metroHost}:{}}),ge=async(e)=>{let r=qr(e,"node_modules",".bin","expo");try{return await Yr(r),r}catch{throw TypeError("Expo dependencies are not installed in the generated shell. Run `absolute mobile init --yes`.")}},ir=(e,r)=>{if(e.engine!=="expo")throw TypeError("The Expo development controller requires Expo.");if(r.platforms.length===0&&r.metro==="external")throw TypeError("External Expo execution requires a target platform.");if([r.androidOrigin,r.iosOrigin].some((u)=>u&&new URL(u).protocol==="https:")&&!r.certificateAuthorityPath)throw TypeError("Expo HTTPS development requires the AbsoluteJS development CA certificate.");let s=zr(r),c={args:["start","--dev-client","--host","localhost","--port",String(r.metroPort)],env:s,role:"metro"},l=r.platforms.length===0?void 0:{args:["prebuild","--clean","--no-install","--platform",r.platforms.length===2?"all":r.platforms[0]??"all"],env:s,role:"native-prepare"},t=r.platforms.map((u)=>{let w=u==="android"?r.androidDevice:r.iosDevice;return{args:[`run:${u}`,"--no-bundler","--port",String(r.metroPort),...w?["--device",w]:[]],env:s,platform:u,role:"native-build"}});return{commands:[...l?[l]:[],...r.metro==="external"?[]:[c],...t],metroPort:r.metroPort,project:e.nativeProjectDirectory}},q=()=>new DOMException("Expo development aborted.","AbortError"),se=(e,r)=>{let a=(s)=>{if(!s)return;let c="";s.on("data",(l)=>{c+=l.toString("utf8");let t=c.indexOf(`
3
- `);while(t>=0)r(c.slice(0,t).replace(/\r$/u,"")),c=c.slice(t+1),t=c.indexOf(`
4
- `)}),s.on("end",()=>{if(c)r(c)})};a(e.stdout),a(e.stderr)},X=async(e)=>{if(e.exitCode!==null||e.killed)return;if(e.kill("SIGTERM"),await Promise.race([new Promise((r)=>e.once("exit",()=>r())),new Promise((r)=>setTimeout(r,Qr))]),e.exitCode===null)e.kill("SIGKILL")},Se=(e)=>new Promise((r)=>{if(e.exitCode!==null){r(e.exitCode);return}e.once("exit",(a)=>r(a??1))}),xe=async(e,r,a,s)=>{let c=e(r,a,{cwd:s.cwd,env:process.env,stdio:["ignore","pipe","pipe"]});se(c,s.log);let l=()=>void X(c);s.signal?.addEventListener("abort",l,{once:!0});let t=await Se(c);if(s.signal?.removeEventListener("abort",l),s.signal?.aborted)throw q();return t},Ge=async(e)=>{let r=ir(e.config,e),a=e.executable??await ge(r.project),s=e.spawnProcess??Pr,c=e.log??(()=>{return}),l={},t=null,u=async()=>{let d=t;t=null,await d?.close()},w=(d,E)=>{l[d]=(l[d]??0)+E,e.onPhaseTiming?.({durationMs:E,phase:d})},b=(d)=>{e.onStateChange?.(d)};if(e.signal?.aborted)throw q();let x=r.commands.find((d)=>d.role==="native-prepare"),A=r.commands.find((d)=>d.role==="metro"),f=r.commands.filter((d)=>d.role==="native-build"),O=async(d)=>{b("preparing-native");let E=performance.now(),m=s(a,d.args,{cwd:r.project,env:{...process.env,...d.env},stdio:["ignore","pipe","pipe"]});se(m,(U)=>{if(U)c(`[prebuild] ${U}`)});let M=()=>void X(m);e.signal?.addEventListener("abort",M,{once:!0});let N=await Se(m);if(e.signal?.removeEventListener("abort",M),e.signal?.aborted)throw q();if(N!==0)throw b("failed"),Error(`Expo native preparation exited with status ${N}.`);w("preparing-native",performance.now()-E)};if(x)await O(x);let n=A!==void 0;if(n)b("starting-metro");let y=performance.now(),S=A?s(a,A.args,{cwd:r.project,env:{...process.env,...A.env},stdio:["ignore","pipe","pipe"]}):void 0,D=!1,h,g=new Promise((d,E)=>{if(!S){d();return}let m=setTimeout(()=>{E(Error("Expo Metro did not become ready within 60 seconds."))},Zr);h=()=>{clearTimeout(m),d()},S.once("exit",(M)=>{if(!D)clearTimeout(m),E(Error(`Expo Metro exited with status ${M??1}.`))})});if(S)se(S,(d)=>{if(d)c(`[metro] ${d}`);if(!D&&/(?:Waiting on|Metro waiting on|Dev server ready)/iu.test(d))D=!0,h?.()});let C=()=>{if(S)X(S)};e.signal?.addEventListener("abort",C,{once:!0});let F=async(d)=>{if(e.signal?.aborted)throw q();let{platform:E}=d;if(!E)throw TypeError("Expo native build command is missing a platform.");let m=E==="android"?"building-android":"building-ios";b(m);let M=performance.now(),N=s(a,d.args,{cwd:r.project,env:{...process.env,...d.env},stdio:["ignore","pipe","pipe"]});se(N,(p)=>{if(p)c(`[${E}] ${p}`)});let U=()=>void X(N);e.signal?.addEventListener("abort",U,{once:!0});let B=await Se(N);if(e.signal?.removeEventListener("abort",U),e.signal?.aborted)throw q();if(B!==0)throw Error(`Expo ${E} development build exited with status ${B}.`);if(E==="ios"&&e.certificateAuthorityPath&&e.iosOrigin&&new URL(e.iosOrigin).protocol==="https:"&&!e.iosDevice){b("enrolling-trust");let p=performance.now(),fe={cwd:r.project,signal:e.signal,log:(We)=>We&&c(`[ios-trust] ${We}`)},Re=await xe(s,"xcrun",["simctl","keychain","booted","add-root-cert",e.certificateAuthorityPath],fe);if(Re!==0)throw Error(`Expo iOS Simulator development CA trust exited with status ${Re}.`);await xe(s,"xcrun",["simctl","terminate","booted",e.config.appId],fe);let Ce=await xe(s,"xcrun",["simctl","launch","booted",e.config.appId],fe);if(Ce!==0)throw Error(`Expo iOS Simulator relaunch exited with status ${Ce}.`);c("Installed the AbsoluteJS development CA into the Expo iOS Simulator and relaunched the app."),w("enrolling-trust",performance.now()-p)}let H=performance.now()-M;l[m]=H,e.onPhaseTiming?.({durationMs:H,phase:m})},o=async(d)=>{let[E,...m]=d;if(!E)return;await F(E),await o(m)},ne=async()=>{if(!e.iosDevice||!e.certificateAuthorityPath||!e.iosOrigin||new URL(e.iosOrigin).protocol!=="https:")return;b("enrolling-trust");let d=performance.now();t=await(e.startCaEnrollmentServer??re)({certificateAuthorityPath:e.certificateAuthorityPath,displayHost:new URL(e.iosOrigin).hostname}),c(`On the iOS device, open ${t.url}, install the AbsoluteJS development CA profile, then enable it under Settings > General > About > Certificate Trust Settings. This public CA endpoint exists only for this dev session.`),w("enrolling-trust",performance.now()-d)};try{if(await ne(),await g,n)w("starting-metro",performance.now()-y);return await o(f),b("ready"),{metroPort:r.metroPort,platforms:e.platforms,timings:l,close:async()=>{if(e.signal?.removeEventListener("abort",C),S)await X(S);await u(),b("closed")}}}catch(d){if(e.signal?.removeEventListener("abort",C),S)await X(S);throw await u(),b("failed"),d}};import{access as vr,cp as vs,mkdir as Fe,mkdtemp as js,readdir as jr,readFile as or,rename as pr,rm as os,writeFile as Xe}from"fs/promises";import{basename as ec,dirname as Ke,join as _,relative as ea,resolve as ra}from"path";var I=`// Generated by AbsoluteJS. Edit absolute.config.ts, then run absolute mobile sync.
5
- `;var aa=".absolutejs-expo-project",Z=async(e)=>{try{return await vr(e),!0}catch{return!1}},Pe=(e,r)=>{let a=ea(e,r).replaceAll("\\","/");return a.startsWith(".")?a:`./${a}`},sa=(e)=>e.split("/").filter(Boolean).map((r)=>{if(r.startsWith(":"))return`[${r.slice(1)}]`;if(r==="."||r===".."||!/^[A-Za-z0-9._~-]+$/u.test(r))throw TypeError(`Expo native route ${e} contains an unsupported segment ${r}.`);return r}),ca=(e,r)=>_(e,"app",...sa(r),"index.tsx"),la=()=>({dependencies:{expo:"~57.0.9","expo-asset":"~57.0.15","expo-constants":"~57.0.16","expo-dev-client":"~57.0.16","expo-file-system":"~57.0.6","expo-haptics":"~57.0.2","expo-linking":"~57.0.8","expo-router":"~57.0.17",react:"19.2.3","react-native":"0.86.3","react-native-safe-area-context":"~5.7.0","react-native-screens":"4.26.0","react-native-webview":"13.16.1"},devDependencies:{"@types/react":"~19.2.2",typescript:"~6.0.3"},main:"expo-router/entry",name:"absolutejs-expo-shell",private:!0,scripts:{android:"expo run:android",ios:"expo run:ios",start:"expo start --dev-client"},version:"0.0.0"}),ta=(e)=>({expo:{android:{intentFilters:e.deepLinkHosts.map((r)=>({action:"VIEW",autoVerify:!0,category:["BROWSABLE","DEFAULT"],data:[{host:r,pathPrefix:"/",scheme:"https"}]})),package:e.appId},experiments:{typedRoutes:!0},ios:{associatedDomains:e.deepLinkHosts.map((r)=>`applinks:${r}`),bundleIdentifier:e.appId,...e.iosVersion?{buildNumber:e.iosVersion}:{}},name:e.appName,plugins:["expo-router",["expo-dev-client",{launchMode:"most-recent"}]],runtimeVersion:{policy:"appVersion"},scheme:e.deepLinkScheme,slug:e.appId.toLowerCase().replaceAll(".","-"),version:e.iosVersion??"0.1.0"}}),wa=`${I}const config = require('./app.json');
2
+ import{mkdir as Jo,readFile as Vo,rm as Te,writeFile as zo}from"fs/promises";import{join as ue}from"path";import{createInterface as _t}from"readline";import{resolve as Me}from"path";var Tt=/^[A-Za-z][\w]*(?:\.[A-Za-z][\w]*)+$/,Pt=/^[a-z][a-z0-9+.-]*$/,Dt=/^[A-Z0-9]{10}$/,Ct=/^[0-9A-F]{64}$/,Rt=/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)(?:\.(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?))*$/,te=(e,t,r)=>{let o=Me(e),n=Me(o,t);if(n!==o&&!n.startsWith(`${o}/`))throw TypeError(`${r} must remain inside the project root.`);return n},R=(e,t)=>{let r=e.trim();if(!r)throw TypeError(`${t} must not be empty.`);return r},Le=(e)=>{let t=R(e??"/","mobile.entry");if(!t.startsWith("/")||t.startsWith("//"))throw TypeError("mobile.entry must be an absolute application path.");return t},Nt=(e)=>{let t=new URL(R(e,"mobile.server.productionOrigin")),r=t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]");if(t.protocol!=="https:"&&!r)throw TypeError("mobile.server.productionOrigin must use HTTPS, except for a loopback development origin.");if(t.username||t.password||t.pathname!=="/"||t.search||t.hash)throw TypeError("mobile.server.productionOrigin must be an origin without credentials, path, query, or hash.");return t.origin},Mt=(e)=>{let t=[...new Set(e??["ios","android"])];if(t.length===0)throw TypeError("mobile.platforms must contain at least one platform.");return t},Lt=(e,t)=>{let r=(s)=>{let i=R(s,"mobile.deepLinks.hosts").toLowerCase();if(!Rt.test(i))throw TypeError("mobile.deepLinks.hosts entries must be valid hostnames without ports, wildcards, or paths.");return i},o=new URL(t).hostname,n=new Set(o==="[::1]"?[]:[r(o)]);for(let s of e??[])n.add(r(s));return[...n].sort()},Ut=(e)=>{if(e===void 0)return;let t=R(e,"mobile.deepLinks.apple.appIdPrefix").toUpperCase();if(!Dt.test(t))throw TypeError("mobile.deepLinks.apple.appIdPrefix must contain ten letters or digits.");return t},$t=(e)=>{if(e===void 0)return;let t=R(e,"mobile.ios.version");if(!/^\d+(?:\.\d+){0,2}$/u.test(t))throw TypeError("mobile.ios.version must contain one to three dot-separated integer components, for example 1.4.0.");return t},kt=(e)=>[...new Set((e??[]).map((t)=>R(t,"mobile.deepLinks.android.sha256CertificateFingerprints").replaceAll(":","").toUpperCase()).map((t)=>{if(!Ct.test(t))throw TypeError("mobile.deepLinks.android.sha256CertificateFingerprints entries must be SHA-256 certificate fingerprints.");return t.match(/.{2}/g)?.join(":")??t}))].sort(),jt=(e,t)=>{if(e.engine!=="expo")return{};let r=e.routes?.native??{},o={};for(let[n,s]of Object.entries(r)){let i=Le(n);if(i.includes("?")||i.includes("#")||i!=="/"&&i.endsWith("/"))throw TypeError(`mobile.routes.native route ${i} must be a canonical path without a query, fragment, or trailing slash.`);if(i==="/__absolute/native")throw TypeError("mobile.routes.native reserves /__absolute/native for the Expo diagnostic screen.");if(i.includes("*")||i.includes(":"))throw TypeError(`mobile.routes.native route ${i} must be static during the Expo experiment; parameters and wildcards are not supported yet.`);o[i]=te(t,R(s,`mobile.routes.native[${i}]`),`mobile.routes.native[${i}]`)}return Object.fromEntries(Object.entries(o).sort(([n],[s])=>n.localeCompare(s)))},Ue=(e,t)=>{let r=R(e.appId,"mobile.appId");if(!Tt.test(r))throw TypeError("mobile.appId must use reverse-domain notation, for example com.example.app.");let o=Nt(e.server.productionOrigin),n=(e.deepLinks?.scheme??r).trim().toLowerCase();if(n&&!Pt.test(n))throw TypeError("mobile.deepLinks.scheme is not a valid URL scheme.");return{androidCertificateFingerprints:kt(e.deepLinks?.android?.sha256CertificateFingerprints),appId:r,appleAppIdPrefix:Ut(e.deepLinks?.apple?.appIdPrefix),appName:R(e.appName,"mobile.appName"),bundleDirectory:te(t,e.bundleDirectory??".absolutejs/mobile/web","mobile.bundleDirectory"),deepLinkHosts:Lt(e.deepLinks?.hosts,o),deepLinkScheme:n,engine:e.engine??"capacitor",entry:Le(e.entry),expoNativeRoutes:jt(e,t),...e.engine==="expo"?{expoSdkVersion:e.expo?.sdkVersion??57}:{},iosVersion:$t(e.ios?.version),nativeProjectDirectory:te(t,e.nativeProject?.directory??(e.engine==="expo"?".absolutejs/mobile/expo":"mobile"),"mobile.nativeProject.directory"),platforms:Mt(e.platforms),productionOrigin:o,pushAndroidGoogleServicesFile:te(t,e.pushNotifications?.android?.googleServicesFile??"google-services.json","mobile.pushNotifications.android.googleServicesFile")}};import{spawn as Xt}from"child_process";import{access as qt}from"fs/promises";import{join as Kt}from"path";import{randomUUID as Bt,X509Certificate as Ht}from"crypto";import{createServer as Ft}from"http";import{connect as Wt,createServer as $e,isIP as Gt}from"net";import{readFile as Jt}from"fs/promises";var ge=(e)=>new Promise((t,r)=>{e.close((o)=>{if(o)r(o);else t()})}),ke=(e,t)=>new Promise((r,o)=>{e.once("error",o),e.listen(t,"0.0.0.0",()=>{e.off("error",o);let n=e.address();if(!n||typeof n==="string"){o(Error("Could not determine the iOS device helper port."));return}r(n.port)})}),Vt=async()=>{let e=$e(),t=await new Promise((r,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>{let n=e.address();if(!n||typeof n==="string"){o(Error("Could not allocate the iOS CA enrollment port."));return}r(n.port)})});return await ge(e),t},fe=(e)=>{let t=e.trim();if(!t||t.length>253||/[\0\s/?#]/u.test(t))throw TypeError("Physical iOS development requires a valid LAN host.");return t},je=(e)=>{let t=e.trim();if(!t||t.length>256||/[\0\r\n]/u.test(t))throw TypeError("--ios-device requires a valid Xcode device identifier or name.");return t},zt=(e,t,r)=>{let o=new URL(`${e}://localhost:${r}`),n=fe(t);return o.hostname=Gt(n)===6?`[${n}]`:n,o},re=async(e)=>{let r=new Ht(await Jt(e.certificateAuthorityPath)).raw,n=`/${Bt().replaceAll("-","")}/absolutejs-development-ca.cer`,s=Ft((a,c)=>{if(a.method!=="GET"||a.url!==n){c.writeHead(404,{"Cache-Control":"no-store","Content-Type":"text/plain; charset=utf-8"}),c.end("Not found.");return}c.writeHead(200,{"Cache-Control":"no-store","Content-Disposition":'attachment; filename="absolutejs-development-ca.cer"',"Content-Length":String(r.byteLength),"Content-Type":"application/x-x509-ca-cert","X-Content-Type-Options":"nosniff"}),c.end(r)}),i=await Vt();await ke(s,i);let l=zt("http",e.displayHost,i);return l.pathname=n,{url:l.href,close:()=>ge(s)}},oe=async(e)=>{let t=$e((r)=>{let o=Wt({host:"127.0.0.1",port:e.targetPort});r.pipe(o),o.pipe(r);let n=()=>{r.destroy(),o.destroy()};r.once("error",n),o.once("error",n)});return await ke(t,e.listenPort),{close:()=>ge(t)}};var Yt=60000,Zt=2000,Qt=(e)=>({ABSOLUTE_EXPO_DEVELOPMENT:"1",...e.certificateAuthorityPath?{ABSOLUTE_EXPO_DEVELOPMENT_CA_PATH:e.certificateAuthorityPath}:{},...e.androidOrigin?{EXPO_PUBLIC_ABSOLUTE_DEV_ANDROID_ORIGIN:e.androidOrigin}:{},...e.iosOrigin?{EXPO_PUBLIC_ABSOLUTE_DEV_IOS_ORIGIN:e.iosOrigin}:{},...e.metroHost?{REACT_NATIVE_PACKAGER_HOSTNAME:e.metroHost}:{}}),Ae=async(e)=>{let t=Kt(e,"node_modules",".bin","expo");try{return await qt(t),t}catch{throw TypeError("Expo dependencies are not installed in the generated shell. Run `absolute mobile init --yes`.")}},er=(e,t)=>{if(e.engine!=="expo")throw TypeError("The Expo development controller requires Expo.");if(t.platforms.length===0&&t.metro==="external")throw TypeError("External Expo execution requires a target platform.");if([t.androidOrigin,t.iosOrigin].some((l)=>l&&new URL(l).protocol==="https:")&&!t.certificateAuthorityPath)throw TypeError("Expo HTTPS development requires the AbsoluteJS development CA certificate.");let o=Qt(t),n={args:["start","--dev-client","--host","localhost","--port",String(t.metroPort)],env:o,role:"metro"},s=t.platforms.length===0?void 0:{args:["prebuild","--clean","--no-install","--platform",t.platforms.length===2?"all":t.platforms[0]??"all"],env:o,role:"native-prepare"},i=t.platforms.map((l)=>{let a=l==="android"?t.androidDevice:t.iosDevice;return{args:[`run:${l}`,"--no-bundler","--port",String(t.metroPort),...a?["--device",a]:[]],env:o,platform:l,role:"native-build"}});return{commands:[...s?[s]:[],...t.metro==="external"?[]:[n],...i],metroPort:t.metroPort,project:e.nativeProjectDirectory}},V=()=>new DOMException("Expo development aborted.","AbortError"),ne=(e,t)=>{let r=(o)=>{if(!o)return;let n="";o.on("data",(s)=>{n+=s.toString("utf8");let i=n.indexOf(`
3
+ `);while(i>=0)t(n.slice(0,i).replace(/\r$/u,"")),n=n.slice(i+1),i=n.indexOf(`
4
+ `)}),o.on("end",()=>{if(n)t(n)})};r(e.stdout),r(e.stderr)},F=async(e)=>{if(e.exitCode!==null||e.killed)return;if(e.kill("SIGTERM"),await Promise.race([new Promise((t)=>e.once("exit",()=>t())),new Promise((t)=>setTimeout(t,Zt))]),e.exitCode===null)e.kill("SIGKILL")},he=(e)=>new Promise((t)=>{if(e.exitCode!==null){t(e.exitCode);return}e.once("exit",(r)=>t(r??1))}),be=async(e,t,r,o)=>{let n=e(t,r,{cwd:o.cwd,env:process.env,stdio:["ignore","pipe","pipe"]});ne(n,o.log);let s=()=>void F(n);o.signal?.addEventListener("abort",s,{once:!0});let i=await he(n);if(o.signal?.removeEventListener("abort",s),o.signal?.aborted)throw V();return i},Be=async(e)=>{let t=er(e.config,e),r=e.executable??await Ae(t.project),o=e.spawnProcess??Xt,n=e.log??(()=>{return}),s={},i=null,l=async()=>{let d=i;i=null,await d?.close()},a=(d,w)=>{s[d]=(s[d]??0)+w,e.onPhaseTiming?.({durationMs:w,phase:d})},c=(d)=>{e.onStateChange?.(d)};if(e.signal?.aborted)throw V();let g=t.commands.find((d)=>d.role==="native-prepare"),m=t.commands.find((d)=>d.role==="metro"),b=t.commands.filter((d)=>d.role==="native-build"),x=async(d)=>{c("preparing-native");let w=performance.now(),y=o(r,d.args,{cwd:t.project,env:{...process.env,...d.env},stdio:["ignore","pipe","pipe"]});ne(y,(N)=>{if(N)n(`[prebuild] ${N}`)});let T=()=>void F(y);e.signal?.addEventListener("abort",T,{once:!0});let O=await he(y);if(e.signal?.removeEventListener("abort",T),e.signal?.aborted)throw V();if(O!==0)throw c("failed"),Error(`Expo native preparation exited with status ${O}.`);a("preparing-native",performance.now()-w)};if(g)await x(g);let u=m!==void 0;if(u)c("starting-metro");let p=performance.now(),f=m?o(r,m.args,{cwd:t.project,env:{...process.env,...m.env},stdio:["ignore","pipe","pipe"]}):void 0,_=!1,A,h=new Promise((d,w)=>{if(!f){d();return}let y=setTimeout(()=>{w(Error("Expo Metro did not become ready within 60 seconds."))},Yt);A=()=>{clearTimeout(y),d()},f.once("exit",(T)=>{if(!_)clearTimeout(y),w(Error(`Expo Metro exited with status ${T??1}.`))})});if(f)ne(f,(d)=>{if(d)n(`[metro] ${d}`);if(!_&&/(?:Waiting on|Metro waiting on|Dev server ready)/iu.test(d))_=!0,A?.()});let C=()=>{if(f)F(f)};e.signal?.addEventListener("abort",C,{once:!0});let H=async(d)=>{if(e.signal?.aborted)throw V();let{platform:w}=d;if(!w)throw TypeError("Expo native build command is missing a platform.");let y=w==="android"?"building-android":"building-ios";c(y);let T=performance.now(),O=o(r,d.args,{cwd:t.project,env:{...process.env,...d.env},stdio:["ignore","pipe","pipe"]});ne(O,(ee)=>{if(ee)n(`[${w}] ${ee}`)});let N=()=>void F(O);e.signal?.addEventListener("abort",N,{once:!0});let M=await he(O);if(e.signal?.removeEventListener("abort",N),e.signal?.aborted)throw V();if(M!==0)throw Error(`Expo ${w} development build exited with status ${M}.`);if(w==="ios"&&e.certificateAuthorityPath&&e.iosOrigin&&new URL(e.iosOrigin).protocol==="https:"&&!e.iosDevice){c("enrolling-trust");let ee=performance.now(),me={cwd:t.project,signal:e.signal,log:(Ne)=>Ne&&n(`[ios-trust] ${Ne}`)},Ce=await be(o,"xcrun",["simctl","keychain","booted","add-root-cert",e.certificateAuthorityPath],me);if(Ce!==0)throw Error(`Expo iOS Simulator development CA trust exited with status ${Ce}.`);await be(o,"xcrun",["simctl","terminate","booted",e.config.appId],me);let Re=await be(o,"xcrun",["simctl","launch","booted",e.config.appId],me);if(Re!==0)throw Error(`Expo iOS Simulator relaunch exited with status ${Re}.`);n("Installed the AbsoluteJS development CA into the Expo iOS Simulator and relaunched the app."),a("enrolling-trust",performance.now()-ee)}let U=performance.now()-T;s[y]=U,e.onPhaseTiming?.({durationMs:U,phase:y})},Q=async(d)=>{let[w,...y]=d;if(!w)return;await H(w),await Q(y)},pe=async()=>{if(!e.iosDevice||!e.certificateAuthorityPath||!e.iosOrigin||new URL(e.iosOrigin).protocol!=="https:")return;c("enrolling-trust");let d=performance.now();i=await(e.startCaEnrollmentServer??re)({certificateAuthorityPath:e.certificateAuthorityPath,displayHost:new URL(e.iosOrigin).hostname}),n(`On the iOS device, open ${i.url}, install the AbsoluteJS development CA profile, then enable it under Settings > General > About > Certificate Trust Settings. This public CA endpoint exists only for this dev session.`),a("enrolling-trust",performance.now()-d)};try{if(await pe(),await h,u)a("starting-metro",performance.now()-p);return await Q(b),c("ready"),{metroPort:t.metroPort,platforms:e.platforms,timings:s,close:async()=>{if(e.signal?.removeEventListener("abort",C),f)await F(f);await l(),c("closed")}}}catch(d){if(e.signal?.removeEventListener("abort",C),f)await F(f);throw await l(),c("failed"),d}};import{access as lr,cp as bn,mkdir as Je,mkdtemp as hn,readdir as ur,readFile as dr,rename as pr,rm as An,writeFile as Ve}from"fs/promises";import{createHash as mr}from"crypto";import{basename as vn,dirname as ze,join as v,relative as gr,resolve as fr}from"path";import{readFileSync as tr}from"fs";import{join as rr}from"path";var or="@absolutejs/auth",He="0.75.6",Fe="@absolutejs/auth-expo",We="0.0.2";var nr=["openid","profile"];var sr=(e)=>{try{return JSON.parse(tr(rr(e,"package.json"),"utf8"))}catch{return}},ir=(e,t)=>{if(typeof e!=="object"||e===null)return!1;return[Reflect.get(e,"dependencies"),Reflect.get(e,"devDependencies"),Reflect.get(e,"optionalDependencies"),Reflect.get(e,"peerDependencies")].some((r)=>typeof r==="object"&&r!==null&&Object.hasOwn(r,t))},ar=(e)=>{let t=e.deepLinkScheme??e.appId.toLowerCase();return{clientId:`absolutejs-native:${e.appId}`,issuer:e.productionOrigin,redirectUri:`${t}://auth/callback`,scopes:[...nr]}};var cr=(e)=>ir(sr(e),or);var Ge=(e,t)=>cr(e)?ar(t):void 0;var I=`// Generated by AbsoluteJS. Edit absolute.config.ts, then run absolute mobile sync.
5
+ `;var br=".absolutejs-expo-project",z=async(e)=>{try{return await lr(e),!0}catch{return!1}},Xe=(e,t)=>{let r=gr(e,t).replaceAll("\\","/");return r.startsWith(".")?r:`./${r}`},hr=(e)=>e.split("/").filter(Boolean).map((t)=>{if(t.startsWith(":"))return`[${t.slice(1)}]`;if(t==="."||t===".."||!/^[A-Za-z0-9._~-]+$/u.test(t))throw TypeError(`Expo native route ${e} contains an unsupported segment ${t}.`);return t}),Ar=(e,t)=>v(e,"app",...hr(t),"index.tsx"),wr=(e)=>({dependencies:{...e?{"@absolutejs/auth":He,[Fe]:We}:{},expo:"~57.0.9","expo-asset":"~57.0.15","expo-constants":"~57.0.16","expo-dev-client":"~57.0.16","expo-file-system":"~57.0.6","expo-haptics":"~57.0.2","expo-linking":"~57.0.8","expo-router":"~57.0.17",...e?{"expo-secure-store":"~57.0.2","expo-web-browser":"~57.0.2"}:{},react:"19.2.3","react-native":"0.86.3","react-native-safe-area-context":"~5.7.0","react-native-screens":"4.26.0","react-native-webview":"13.16.1"},devDependencies:{"@types/react":"~19.2.2",typescript:"~6.0.3"},main:"expo-router/entry",name:"absolutejs-expo-shell",private:!0,scripts:{android:"expo run:android",ios:"expo run:ios",start:"expo start --dev-client"},version:"0.0.0"}),Er=(e,t)=>({expo:{android:{intentFilters:e.deepLinkHosts.map((r)=>({action:"VIEW",autoVerify:!0,category:["BROWSABLE","DEFAULT"],data:[{host:r,pathPrefix:"/",scheme:"https"}]})),package:e.appId},experiments:{typedRoutes:!0},ios:{associatedDomains:e.deepLinkHosts.map((r)=>`applinks:${r}`),bundleIdentifier:e.appId,...e.iosVersion?{buildNumber:e.iosVersion}:{}},name:e.appName,plugins:["expo-router",["expo-dev-client",{launchMode:"most-recent"}],...t?["expo-secure-store"]:[]],runtimeVersion:{policy:"appVersion"},scheme:e.deepLinkScheme,slug:e.appId.toLowerCase().replaceAll(".","-"),version:e.iosVersion??"0.1.0"}}),vr=`${I}const config = require('./app.json');
6
6
 
7
7
  if (process.env.ABSOLUTE_EXPO_DEVELOPMENT === '1' && process.env.ABSOLUTE_EXPO_DEVELOPMENT_CA_PATH) {
8
8
  config.expo.plugins = [
@@ -12,7 +12,7 @@ if (process.env.ABSOLUTE_EXPO_DEVELOPMENT === '1' && process.env.ABSOLUTE_EXPO_D
12
12
  }
13
13
 
14
14
  module.exports = config;
15
- `,ba=`${I}const { AndroidConfig, withAndroidManifest, withDangerousMod } = require('expo/config-plugins');
15
+ `,Sr=`${I}const { AndroidConfig, withAndroidManifest, withDangerousMod } = require('expo/config-plugins');
16
16
  const { copyFile, mkdir } = require('node:fs/promises');
17
17
  const path = require('node:path');
18
18
 
@@ -51,7 +51,7 @@ const withAbsoluteDevelopmentCa = config => {
51
51
  };
52
52
 
53
53
  module.exports = withAbsoluteDevelopmentCa;
54
- `,ua=(e)=>`${I}const { getDefaultConfig } = require('expo/metro-config');
54
+ `,yr=(e)=>`${I}const { getDefaultConfig } = require('expo/metro-config');
55
55
  const path = require('node:path');
56
56
 
57
57
  const projectRoot = __dirname;
@@ -65,12 +65,17 @@ config.resolver.nodeModulesPaths = [
65
65
  config.watchFolders = [appRoot];
66
66
 
67
67
  module.exports = config;
68
- `,da=`${I}import { Stack } from 'expo-router';
68
+ `,xr=(e)=>`${I}import { Stack } from 'expo-router';
69
+ ${e?`import { useEffect } from 'react';
70
+ import { startAbsoluteExpoAuth } from '../src/generated/AbsoluteAuth';`:""}
69
71
 
70
72
  export default function AbsoluteLayout() {
73
+ ${e?`useEffect(() => {
74
+ void startAbsoluteExpoAuth();
75
+ }, []);`:""}
71
76
  return <Stack screenOptions={{ headerShown: false }} />;
72
77
  }
73
- `,na=`${I}import * as Haptics from 'expo-haptics';
78
+ `,Ir=`${I}import * as Haptics from 'expo-haptics';
74
79
  import { Link } from 'expo-router';
75
80
  import { Pressable, SafeAreaView, StyleSheet, Text, View } from 'react-native';
76
81
 
@@ -100,15 +105,44 @@ const styles = StyleSheet.create({
100
105
  page: { alignItems: 'center', backgroundColor: '#020617', flex: 1, justifyContent: 'center', padding: 20 },
101
106
  title: { color: '#f8fafc', fontSize: 32, fontWeight: '800' }
102
107
  });
103
- `,fa=(e)=>{let r=["/__absolute/native",...Object.keys(e.expoNativeRoutes)];return`${I}import * as Haptics from 'expo-haptics';
108
+ `,_r=(e,t)=>{let r=mr("sha256").update(t).digest("hex").slice(0,24);return`${I}import { createAbsoluteExpoAuthClient } from '@absolutejs/auth-expo';
109
+ import { createMobileAuthTransport, installAuthClientRuntimeTransport } from '@absolutejs/auth/client/mobile';
110
+
111
+ export const absoluteExpoAuth = createAbsoluteExpoAuthClient({
112
+ allowedOrigins: [${JSON.stringify(e.issuer)}],
113
+ clientId: ${JSON.stringify(e.clientId)},
114
+ issuer: ${JSON.stringify(e.issuer)},
115
+ redirectUri: ${JSON.stringify(e.redirectUri)},
116
+ resource: ${JSON.stringify(e.issuer)},
117
+ scopes: ${JSON.stringify(e.scopes)},
118
+ storagePrefix: ${JSON.stringify(`absolutejs.auth.${r}`)}
119
+ });
120
+ installAuthClientRuntimeTransport(createMobileAuthTransport(absoluteExpoAuth, { baseUrl: ${JSON.stringify(e.issuer)} }));
121
+
122
+ let currentPrincipal: Awaited<ReturnType<typeof absoluteExpoAuth.principal>> = null;
123
+ absoluteExpoAuth.onPrincipalChange(principal => {
124
+ currentPrincipal = principal;
125
+ });
126
+ export const getAbsoluteExpoAuthPrincipal = () => currentPrincipal;
127
+
128
+ let startPromise: Promise<void> | undefined;
129
+ export const startAbsoluteExpoAuth = () => {
130
+ startPromise ??= absoluteExpoAuth.start().then(async () => {
131
+ await absoluteExpoAuth.principal();
132
+ });
133
+
134
+ return startPromise;
135
+ };
136
+ `},Or=(e,t)=>{let r=["/__absolute/native",...Object.keys(e.expoNativeRoutes)];return`${I}import * as Haptics from 'expo-haptics';
104
137
  import * as Linking from 'expo-linking';
105
138
  import { router, usePathname } from 'expo-router';
106
139
  import { useEffect, useRef, useState } from 'react';
107
140
  import { ActivityIndicator, BackHandler, Platform, StyleSheet, View } from 'react-native';
108
141
  import { WebView, type WebViewMessageEvent } from 'react-native-webview';
109
142
  import { materializeAbsoluteWebBundle } from './webAssets';
143
+ ${t?"import { absoluteExpoAuth, getAbsoluteExpoAuthPrincipal, startAbsoluteExpoAuth } from './AbsoluteAuth';":""}
110
144
 
111
- const BRIDGE_FORMAT = 1;
145
+ const BRIDGE_FORMAT = 2;
112
146
  const MAX_MESSAGE_BYTES = 64 * 1024;
113
147
  const MAX_HTTP_BODY_BYTES = 48 * 1024;
114
148
  const NATIVE_ROUTES = new Set(${JSON.stringify(r)});
@@ -117,6 +151,7 @@ const DEV_ORIGIN = Platform.OS === 'android'
117
151
  ? process.env.EXPO_PUBLIC_ABSOLUTE_DEV_ANDROID_ORIGIN
118
152
  : process.env.EXPO_PUBLIC_ABSOLUTE_DEV_IOS_ORIGIN;
119
153
  const HMR_TARGET = Platform.OS === 'android' ? 'expo-android' : 'expo-ios';
154
+ const AUTH_ENABLED = ${t?"true":"false"};
120
155
 
121
156
  const bridgeBootstrap = (path: string) => {
122
157
  const initialPath = DEV_ORIGIN
@@ -124,6 +159,7 @@ const bridgeBootstrap = (path: string) => {
124
159
  : JSON.stringify(path);
125
160
  return \`(() => {
126
161
  const pending = new Map();
162
+ const listeners = new Map();
127
163
  let sequence = 0;
128
164
  let currentPath = \${initialPath};
129
165
  const send = value => {
@@ -133,6 +169,10 @@ const bridgeBootstrap = (path: string) => {
133
169
  };
134
170
  globalThis.__absoluteExpoReceive = source => {
135
171
  const message = JSON.parse(source);
172
+ if (message.kind === 'event') {
173
+ for (const listener of listeners.get(message.event) || []) listener(message.payload || {});
174
+ return;
175
+ }
136
176
  const operation = pending.get(message.id);
137
177
  if (!operation) return;
138
178
  pending.delete(message.id);
@@ -140,9 +180,18 @@ const bridgeBootstrap = (path: string) => {
140
180
  message.error ? operation.reject(new Error(message.error.message)) : operation.resolve(message.result);
141
181
  };
142
182
  globalThis.__absoluteExpoBridge = {
183
+ on(event, listener) {
184
+ const values = listeners.get(event) || new Set();
185
+ values.add(listener);
186
+ listeners.set(event, values);
187
+ return () => {
188
+ values.delete(listener);
189
+ if (values.size === 0) listeners.delete(event);
190
+ };
191
+ },
143
192
  request(method, params) {
144
193
  const id = 'web_' + Date.now().toString(36) + '_' + (++sequence).toString(36);
145
- send({ format: 1, id, kind: 'request', method, params, path: currentPath });
194
+ send({ format: 2, id, kind: 'request', method, params, path: currentPath });
146
195
  return new Promise((resolve, reject) => {
147
196
  const timer = setTimeout(() => {
148
197
  pending.delete(id);
@@ -153,7 +202,7 @@ const bridgeBootstrap = (path: string) => {
153
202
  },
154
203
  setPath(path) {
155
204
  currentPath = path;
156
- send({ format: 1, kind: 'event', event: 'navigation', path });
205
+ send({ format: 2, kind: 'event', event: 'navigation', path });
157
206
  }
158
207
  };
159
208
  if (\${DEV_ORIGIN ? 'true' : 'false'}) {
@@ -161,7 +210,7 @@ const bridgeBootstrap = (path: string) => {
161
210
  const path = location.pathname + location.search + location.hash;
162
211
  if (path === currentPath) return;
163
212
  currentPath = path;
164
- send({ format: 1, kind: 'event', event: 'navigation', path });
213
+ send({ format: 2, kind: 'event', event: 'navigation', path });
165
214
  };
166
215
  for (const method of ['pushState', 'replaceState']) {
167
216
  const original = history[method];
@@ -180,9 +229,9 @@ const bridgeBootstrap = (path: string) => {
180
229
  const url = new URL(anchor.href, location.href);
181
230
  if (!${JSON.stringify(r)}.includes(url.pathname)) return;
182
231
  event.preventDefault();
183
- send({ format: 1, kind: 'event', event: 'navigation', path: url.pathname + url.search + url.hash });
232
+ send({ format: 2, kind: 'event', event: 'navigation', path: url.pathname + url.search + url.hash });
184
233
  }, true);
185
- send({ format: 1, kind: 'event', event: 'ready', path: currentPath });
234
+ send({ format: 2, kind: 'event', event: 'ready', path: currentPath });
186
235
  })(); true;\`;
187
236
  };
188
237
 
@@ -198,16 +247,16 @@ const impact = async (params: Record<string, unknown>) => {
198
247
  };
199
248
 
200
249
  const bridgeFetch = async (params: Record<string, unknown>) => {
201
- if (params.method !== 'GET' || typeof params.url !== 'string' || typeof params.headers !== 'object' || params.headers === null || Array.isArray(params.headers)) throw new Error('Expo bridge HTTP request is invalid.');
250
+ if (typeof params.method !== 'string' || !['DELETE', 'GET', 'PATCH', 'POST', 'PUT'].includes(params.method) || typeof params.url !== 'string' || typeof params.headers !== 'object' || params.headers === null || Array.isArray(params.headers) || params.body !== undefined && typeof params.body !== 'string') throw new Error('Expo bridge HTTP request is invalid.');
202
251
  const url = new URL(params.url);
203
252
  if (url.origin !== PRODUCTION_ORIGIN || url.username || url.password) throw new Error('Expo bridge HTTP request left productionOrigin.');
204
253
  const headers = new Headers();
205
254
  for (const [name, value] of Object.entries(params.headers as Record<string, unknown>)) {
206
255
  const normalized = name.toLowerCase();
207
- if (typeof value !== 'string' || (normalized !== 'accept' && !normalized.startsWith('x-absolute-mobile-'))) throw new Error('Expo bridge HTTP header is not allowed.');
256
+ if (typeof value !== 'string' || (normalized !== 'accept' && normalized !== 'content-type' && !normalized.startsWith('x-absolute-mobile-'))) throw new Error('Expo bridge HTTP header is not allowed.');
208
257
  headers.set(normalized, value);
209
258
  }
210
- const response = await fetch(url, { headers, method: 'GET', redirect: 'manual' });
259
+ const response = await ${t?"absoluteExpoAuth.fetchOptional":"fetch"}(url, { ...(typeof params.body === 'string' ? { body: params.body } : {}), headers, method: params.method, redirect: 'manual' });
211
260
  if (new URL(response.url || url.href).origin !== PRODUCTION_ORIGIN || response.status >= 300 && response.status < 400) throw new Error('Expo bridge HTTP redirects are not allowed.');
212
261
  const body = await response.text();
213
262
  if (new TextEncoder().encode(body).byteLength > MAX_HTTP_BODY_BYTES) throw new Error('Expo bridge HTTP response exceeds 48 KiB.');
@@ -219,13 +268,32 @@ const bridgeFetch = async (params: Record<string, unknown>) => {
219
268
  return { body, headers: responseHeaders, status: response.status };
220
269
  };
221
270
 
271
+ const authStatus = async () => {
272
+ ${t?`const user = await absoluteExpoAuth.status();
273
+ const principal = getAbsoluteExpoAuthPrincipal();
274
+ return { principal: principal ? { namespace: principal.namespace } : null, user };`:"throw new Error('Expo Auth is not configured.');"}
275
+ };
276
+
222
277
  export function AbsoluteWebHost() {
223
278
  const pathname = usePathname() || '/';
224
279
  const webView = useRef<WebView>(null);
225
280
  const [indexUri, setIndexUri] = useState<string>();
226
281
  const [canGoBack, setCanGoBack] = useState(false);
282
+ const [authReady, setAuthReady] = useState(!AUTH_ENABLED);
227
283
  const activeWebPath = useRef(pathname);
228
284
 
285
+ useEffect(() => {
286
+ if (!AUTH_ENABLED) return;
287
+ let active = true;
288
+ ${t?`const stop = absoluteExpoAuth.onPrincipalChange(principal => {
289
+ if (!active) return;
290
+ const source = JSON.stringify({ event: 'auth.principal', format: BRIDGE_FORMAT, kind: 'event', path: activeWebPath.current, payload: { principal: principal ? { namespace: principal.namespace } : null } });
291
+ webView.current?.injectJavaScript(\`globalThis.__absoluteExpoReceive(\${JSON.stringify(source)}); true;\`);
292
+ });
293
+ void startAbsoluteExpoAuth().then(() => { if (active) setAuthReady(true); });
294
+ return () => { active = false; stop(); };`:""}
295
+ }, []);
296
+
229
297
  useEffect(() => {
230
298
  if (DEV_ORIGIN) {
231
299
  const target = new URL(pathname, DEV_ORIGIN);
@@ -275,6 +343,16 @@ export function AbsoluteWebHost() {
275
343
  respond({ format: BRIDGE_FORMAT, id: message.id, kind: 'response', result: null });
276
344
  } else if (message.method === 'http.fetch') {
277
345
  respond({ format: BRIDGE_FORMAT, id: message.id, kind: 'response', result: await bridgeFetch(message.params as Record<string, unknown>) });
346
+ } else if (message.method === 'auth.signIn') {
347
+ ${t?`const params = message.params as Record<string, unknown>;
348
+ if (typeof params.email !== 'string' || typeof params.signup !== 'boolean') throw new Error('Expo Auth sign-in params are invalid.');
349
+ await absoluteExpoAuth.signIn({ authorizationParameters: { login_hint: params.email, ...(params.signup ? { screen_hint: 'signup' } : {}) } });
350
+ respond({ format: BRIDGE_FORMAT, id: message.id, kind: 'response', result: await authStatus() });`:"throw new Error('Expo Auth is not configured.');"}
351
+ } else if (message.method === 'auth.signOut') {
352
+ ${t?`await absoluteExpoAuth.signOut();
353
+ respond({ format: BRIDGE_FORMAT, id: message.id, kind: 'response', result: null });`:"throw new Error('Expo Auth is not configured.');"}
354
+ } else if (message.method === 'auth.status') {
355
+ respond({ format: BRIDGE_FORMAT, id: message.id, kind: 'response', result: await authStatus() });
278
356
  } else {
279
357
  throw new Error('Expo bridge method is not allowed.');
280
358
  }
@@ -283,7 +361,7 @@ export function AbsoluteWebHost() {
283
361
  }
284
362
  };
285
363
 
286
- if (!indexUri) return <View style={styles.loading}><ActivityIndicator /></View>;
364
+ if (!indexUri || !authReady) return <View style={styles.loading}><ActivityIndicator /></View>;
287
365
  return <WebView
288
366
  allowFileAccess
289
367
  allowFileAccessFromFileURLs
@@ -304,47 +382,47 @@ export function AbsoluteWebHost() {
304
382
  }
305
383
 
306
384
  const styles = StyleSheet.create({ loading: { alignItems: 'center', flex: 1, justifyContent: 'center' }, web: { flex: 1 } });
307
- `},Aa=`${I}import { AbsoluteWebHost } from '../src/generated/AbsoluteWebHost';
385
+ `},Tr=`${I}import { AbsoluteWebHost } from '../src/generated/AbsoluteWebHost';
308
386
 
309
387
  export default AbsoluteWebHost;
310
- `,ya=`${I}import { AbsoluteWebHost } from '../src/generated/AbsoluteWebHost';
388
+ `,Pr=`${I}import { AbsoluteWebHost } from '../src/generated/AbsoluteWebHost';
311
389
 
312
390
  export default AbsoluteWebHost;
313
- `,xa=(e,r)=>`${I}export { default } from ${JSON.stringify(Pe(Ke(e),r).replace(/\.(?:[cm]?[jt]sx?)$/u,""))};
314
- `,Sa=(e,r)=>({compilerOptions:{paths:{"*":["./node_modules/*",`${Pe(r,e)}/node_modules/*`],react:["./node_modules/@types/react/index.d.ts"],"react/*":["./node_modules/@types/react/*"]},strict:!0},extends:"expo/tsconfig.base"}),ga=async(e,r,a)=>{if(await Fe(Ke(e),{recursive:!0}),await Z(e)){let c=await or(e,"utf8");if(c===r)return!1;if(!a&&!c.startsWith(I))throw TypeError(`Expo project file ${e} is not AbsoluteJS-managed; rerun with --force only after reviewing it.`)}let s=`${e}.${crypto.randomUUID()}.tmp`;return await Xe(s,r,{flag:"wx"}),await pr(s,e),!0},he=(e)=>`${JSON.stringify(e,null,"\t")}
315
- `,ha=`${I}export const materializeAbsoluteWebBundle = async () => {
391
+ `,Dr=(e,t)=>`${I}export { default } from ${JSON.stringify(Xe(ze(e),t).replace(/\.(?:[cm]?[jt]sx?)$/u,""))};
392
+ `,Cr=(e,t,r)=>({compilerOptions:{paths:{...r?{"@absolutejs/auth":["./node_modules/@absolutejs/auth/dist/index.d.ts"],"@absolutejs/auth/*":["./node_modules/@absolutejs/auth/dist/*"]}:{},"*":["./node_modules/*",`${Xe(t,e)}/node_modules/*`],react:["./node_modules/@types/react/index.d.ts"],"react/*":["./node_modules/@types/react/*"]},strict:!0},extends:"expo/tsconfig.base"}),Rr=async(e,t,r)=>{if(await Je(ze(e),{recursive:!0}),await z(e)){let n=await dr(e,"utf8");if(n===t)return!1;if(!r&&!n.startsWith(I))throw TypeError(`Expo project file ${e} is not AbsoluteJS-managed; rerun with --force only after reviewing it.`)}let o=`${e}.${crypto.randomUUID()}.tmp`;return await Ve(o,t,{flag:"wx"}),await pr(o,e),!0},we=(e)=>`${JSON.stringify(e,null,"\t")}
393
+ `,Nr=`${I}export const materializeAbsoluteWebBundle = async () => {
316
394
  throw new Error('The embedded AbsoluteJS bundle is unavailable. Run absolute prepare before a production Expo build.');
317
395
  };
318
- `,Ye=async(e,r)=>{if(e.engine!=="expo")throw TypeError("Expo project generation requires mobile.engine: expo.");let a=ra(r.projectRoot),s=e.nativeProjectDirectory,c=Object.entries(e.expoNativeRoutes),t=(await Promise.all(c.map(async([f,O])=>({exists:await Z(O),module:O,route:f})))).find((f)=>!f.exists);if(t)throw TypeError(`Expo native route ${t.route} references missing module ${t.module}.`);let u=_(s,aa);if(await Z(s)&&!await Z(u)){if((await jr(s)).length>0&&!r.force)throw TypeError(`Expo project directory ${s} is not AbsoluteJS-managed; rerun with --force only after reviewing it.`)}await Fe(s,{recursive:!0}),await Xe(u,`format=1
319
- `);let w=new Map([[_(s,".gitignore"),`.expo/
396
+ `,qe=async(e,t)=>{if(e.engine!=="expo")throw TypeError("Expo project generation requires mobile.engine: expo.");let r=fr(t.projectRoot),o=e.nativeProjectDirectory,n=Ge(r,e),s=Object.entries(e.expoNativeRoutes),l=(await Promise.all(s.map(async([u,p])=>({exists:await z(p),module:p,route:u})))).find((u)=>!u.exists);if(l)throw TypeError(`Expo native route ${l.route} references missing module ${l.module}.`);let a=v(o,br);if(await z(o)&&!await z(a)){if((await ur(o)).length>0&&!t.force)throw TypeError(`Expo project directory ${o} is not AbsoluteJS-managed; rerun with --force only after reviewing it.`)}await Je(o,{recursive:!0}),await Ve(a,`format=1
397
+ `);let c=Boolean(n),g=new Map([[v(o,".gitignore"),`.expo/
320
398
  android/
321
399
  ios/
322
400
  node_modules/
323
- `],[_(s,"app.json"),he(ta(e))],[_(s,"app.config.js"),wa],[_(s,"package.json"),he(la())],[_(s,"metro.config.js"),ua(a)],[_(s,"plugins","withAbsoluteDevelopmentCa.js"),ba],[_(s,"tsconfig.json"),he(Sa(a,s))],[_(s,"app","_layout.tsx"),da],[_(s,"app","__absolute","native","index.tsx"),na],[_(s,"src","generated","AbsoluteWebHost.tsx"),fa(e)]]),b=_(s,"src","generated","webAssets.ts");if(!await Z(b))w.set(b,ha);if(!e.expoNativeRoutes["/"])w.set(_(s,"app","index.tsx"),Aa);w.set(_(s,"app","[...absolute].tsx"),ya);for(let[f,O]of c){let n=f==="/"?_(s,"app","index.tsx"):ca(s,f);w.set(n,xa(n,O))}return{changed:(await Promise.all([...w].map(([f,O])=>ga(f,O,!0)))).filter(Boolean).length,path:s,written:[...w.keys()]}};import{createHash as dr,randomUUID as Fa}from"crypto";import{access as Xa,copyFile as ar,mkdir as P,readFile as te,rename as Ka,rm as _e,writeFile as G}from"fs/promises";import{isIP as Pa}from"net";import{dirname as nr,isAbsolute as Ya,join as T,relative as qa,resolve as we,sep as Za}from"path";import{access as Ea}from"fs/promises";import{homedir as Qe}from"os";import{join as i}from"path";import{existsSync as nc,readFileSync as Oa}from"fs";var Q=1000;var qe=60000;var Oe=2;var z=(e)=>{let r;if(e<Q)r=`${e.toFixed(Oe)}ms`;else if(e<qe)r=`${(e/Q).toFixed(Oe)}s`;else{let a=Math.round(e/Q),s=Math.floor(a/60),c=a%60;r=c===0?`${s}m`:`${s}m ${c}s`}return r};var Ze=()=>{try{let e=Oa("/proc/version","utf-8");return/microsoft|wsl/i.test(e)}catch{return!1}};var ze="AbsoluteJS_API_36",$a=(e)=>{try{let r=Bun.spawnSync(e,{stderr:"ignore",stdout:"pipe"});return{exitCode:r.exitCode,stdout:r.stdout.toString()}}catch{return{exitCode:1,stdout:""}}},_a=(e)=>{try{let r=JSON.parse(e);if(typeof r!=="object"||r===null)return!1;let a=Reflect.get(r,"runtimes");if(!Array.isArray(a))return!1;return a.some((s)=>typeof s==="object"&&s!==null&&Reflect.get(s,"isAvailable")===!0&&typeof Reflect.get(s,"identifier")==="string"&&String(Reflect.get(s,"identifier")).includes("iOS"))}catch{return!1}},Ta=(e)=>{let r=/^([a-z]):[\\/](.*)$/i.exec(e.trim());if(!r)return e.trim().replaceAll("\\","/");return`/mnt/${r[1]?.toLowerCase()}/${r[2]?.replaceAll("\\","/")}`},ma=()=>{try{let e=Bun.spawnSync(["cmd.exe","/d","/c","echo","%LOCALAPPDATA%"],{stderr:"ignore",stdout:"pipe"});if(e.exitCode!==0)return;let r=e.stdout.toString().trim();if(!r||r==="%LOCALAPPDATA%")return;return Ta(r)}catch{return}},Da=(e,r=process.env)=>{if(e==="windows")return i(r.LOCALAPPDATA??i(Qe(),"AppData","Local"),"AbsoluteJS","Android","Sdk");if(e==="wsl"){let a=ma();if(a)return i(a,"AbsoluteJS","Android","Sdk")}return i(Qe(),".absolutejs","android-sdk")},Na=async(e)=>{try{return await Ea(e),!0}catch{return!1}},ce=(e=process.platform,r=Ze())=>{if(e==="darwin")return"macos";if(e==="win32")return"windows";if(e==="linux"&&r)return"wsl";return"linux"},Ia=(e,r)=>{if(e==="wsl")return[`${r}.exe`,`${r}.bat`,r];if(e==="windows")return[r,`${r}.exe`,`${r}.bat`];return[r]},L=async(e,r,a,s)=>{let l=(await Promise.all(r.map(async(t)=>await a.exists(t)?t:void 0))).find((t)=>t!==void 0);if(l)return l;for(let t of Ia(s,e)){let u=a.which(t);if(u)return u}return},V=(e,r,a,s,c)=>s?{id:e,label:r,path:s,platform:a,status:"pass"}:{id:e,label:r,platform:a,remediation:c,status:"fail"},ie=async(e={})=>{let r=e.env??process.env,a=e.host??ce(),s=e.exists??Na,c=e.which??((h)=>Bun.which(h)),l=e.capture??$a,t=e.androidRoot===null?void 0:e.androidRoot??r.ANDROID_HOME??r.ANDROID_SDK_ROOT??Da(a,r),u=a==="windows"||a==="wsl",w=(h)=>t?i(t,...h):void 0,b=(h)=>h.filter((g)=>Boolean(g)),x=await L("adb",b([w(["platform-tools",u?"adb.exe":"adb"])]),{exists:s,which:c},a),A=await L("emulator",b([w(["emulator",u?"emulator.exe":"emulator"])]),{exists:s,which:c},a),f=await L("sdkmanager",b([w(["cmdline-tools","latest","bin",u?"sdkmanager.bat":"sdkmanager"])]),{exists:s,which:c},a),O=await L("avdmanager",b([w(["cmdline-tools","latest","bin",u?"avdmanager.bat":"avdmanager"])]),{exists:s,which:c},a),n=await L("java",[],{exists:s,which:c},a),y=[{id:"host",label:`Development host: ${a}`,platform:"host",status:"pass"},V("android.adb","Android Debug Bridge","android",x,"Install Android SDK Platform Tools or expose adb on PATH."),V("android.emulator","Android Emulator","android",A,"Install the Android Emulator from Android Studio SDK Manager."),V("android.sdkmanager","Android SDK Manager","android",f,"Install Android SDK Command-line Tools (latest)."),V("android.avdmanager","Android Virtual Device Manager","android",O,"Install Android SDK Command-line Tools (latest)."),V("android.java","Java runtime","android",n,"Install the JDK required by the configured Android Gradle plugin.")];if(A){let h=l([A,"-list-avds"]),g=h.exitCode===0&&h.stdout.split(/\r?\n/).includes(ze);y.push({id:"android.avd",label:`AbsoluteJS Android emulator (${ze})`,platform:"android",remediation:g?void 0:"Run absolute mobile doctor android --fix to provision the managed emulator.",status:g?"pass":"fail"})}if(a==="wsl")y.push({id:"android.virtualization",label:x?.endsWith(".exe")?"Windows-host Android bridge available to WSL":"WSL requires a Windows-host emulator bridge or Linux KVM",platform:"android",remediation:x?.endsWith(".exe")?void 0:"Expose the Windows Android SDK adb.exe to WSL, or enable /dev/kvm for a Linux SDK.",status:x?.endsWith(".exe")?"pass":"warn"});else if(a==="linux"){let h=await s("/dev/kvm");y.push({id:"android.virtualization",label:"Linux KVM acceleration",platform:"android",remediation:h?void 0:"Enable KVM and grant the current user access to /dev/kvm.",status:h?"pass":"warn"})}if(a!=="macos")return y.push({id:"ios.simulator",label:"iOS Simulator requires macOS and Xcode",platform:"ios",status:"skip"}),y;let S=await L("xcrun",[],{exists:s,which:c},a),D=await L("xcodebuild",[],{exists:s,which:c},a);if(y.push(V("ios.xcrun","Xcode command runner","ios",S,"Install Xcode and select it with xcode-select."),V("ios.xcodebuild","Xcode build system","ios",D,"Install Xcode and select it with xcode-select.")),S){let h=l([S,"simctl","list","runtimes","--json"]),g=h.exitCode===0&&_a(h.stdout);y.push({id:"ios.runtime",label:"iOS Simulator runtime",platform:"ios",remediation:g?void 0:"Run absolute mobile doctor ios --fix to download an iOS Simulator runtime.",status:g?"pass":"fail"})}return y};import{access as Ma,readFile as ka,rename as Ra,writeFile as Ca}from"fs/promises";import{relative as Wa,resolve as ve}from"path";var je="capacitor.config.ts",Ee=(e,r)=>Wa(e,r).replaceAll("\\","/"),Ua=(e,r)=>`import type { CapacitorConfig } from '@capacitor/cli';
401
+ `],[v(o,"app.json"),we(Er(e,c))],[v(o,"app.config.js"),vr],[v(o,"package.json"),we(wr(c))],[v(o,"metro.config.js"),yr(r)],[v(o,"plugins","withAbsoluteDevelopmentCa.js"),Sr],[v(o,"tsconfig.json"),we(Cr(r,o,c))],[v(o,"app","_layout.tsx"),xr(c)],[v(o,"app","__absolute","native","index.tsx"),Ir],[v(o,"src","generated","AbsoluteWebHost.tsx"),Or(e,n)]]);if(n)g.set(v(o,"src","generated","AbsoluteAuth.ts"),_r(n,e.appId));let m=v(o,"src","generated","webAssets.ts");if(!await z(m))g.set(m,Nr);if(!e.expoNativeRoutes["/"])g.set(v(o,"app","index.tsx"),Tr);g.set(v(o,"app","[...absolute].tsx"),Pr);for(let[u,p]of s){let f=u==="/"?v(o,"app","index.tsx"):Ar(o,u);g.set(f,Dr(f,p))}return{changed:(await Promise.all([...g].map(([u,p])=>Rr(u,p,!0)))).filter(Boolean).length,path:o,written:[...g.keys()]}};import{createHash as ft,randomUUID as to}from"crypto";import{access as ro,copyFile as at,mkdir as G,readFile as ae,rename as oo,rm as ye,writeFile as B}from"fs/promises";import{isIP as no}from"net";import{dirname as bt,isAbsolute as so,join as S,relative as io,resolve as ce,sep as ao}from"path";import{access as Lr}from"fs/promises";import{homedir as Ze}from"os";import{join as K}from"path";import{existsSync as Nn,readFileSync as Mr}from"fs";var X=1000;var Ke=60000;var Ee=2;var q=(e)=>{let t;if(e<X)t=`${e.toFixed(Ee)}ms`;else if(e<Ke)t=`${(e/X).toFixed(Ee)}s`;else{let r=Math.round(e/X),o=Math.floor(r/60),n=r%60;t=n===0?`${o}m`:`${o}m ${n}s`}return t};var Ye=()=>{try{let e=Mr("/proc/version","utf-8");return/microsoft|wsl/i.test(e)}catch{return!1}};var Qe="AbsoluteJS_API_36",Ur=(e)=>{try{let t=Bun.spawnSync(e,{stderr:"ignore",stdout:"pipe"});return{exitCode:t.exitCode,stdout:t.stdout.toString()}}catch{return{exitCode:1,stdout:""}}},$r=(e)=>{try{let t=JSON.parse(e);if(typeof t!=="object"||t===null)return!1;let r=Reflect.get(t,"runtimes");if(!Array.isArray(r))return!1;return r.some((o)=>typeof o==="object"&&o!==null&&Reflect.get(o,"isAvailable")===!0&&typeof Reflect.get(o,"identifier")==="string"&&String(Reflect.get(o,"identifier")).includes("iOS"))}catch{return!1}},kr=(e)=>{let t=/^([a-z]):[\\/](.*)$/i.exec(e.trim());if(!t)return e.trim().replaceAll("\\","/");return`/mnt/${t[1]?.toLowerCase()}/${t[2]?.replaceAll("\\","/")}`},jr=()=>{try{let e=Bun.spawnSync(["cmd.exe","/d","/c","echo","%LOCALAPPDATA%"],{stderr:"ignore",stdout:"pipe"});if(e.exitCode!==0)return;let t=e.stdout.toString().trim();if(!t||t==="%LOCALAPPDATA%")return;return kr(t)}catch{return}},Br=(e,t=process.env)=>{if(e==="windows")return K(t.LOCALAPPDATA??K(Ze(),"AppData","Local"),"AbsoluteJS","Android","Sdk");if(e==="wsl"){let r=jr();if(r)return K(r,"AbsoluteJS","Android","Sdk")}return K(Ze(),".absolutejs","android-sdk")},Hr=async(e)=>{try{return await Lr(e),!0}catch{return!1}},se=(e=process.platform,t=Ye())=>{if(e==="darwin")return"macos";if(e==="win32")return"windows";if(e==="linux"&&t)return"wsl";return"linux"},Fr=(e,t)=>{if(e==="wsl")return[`${t}.exe`,`${t}.bat`,t];if(e==="windows")return[t,`${t}.exe`,`${t}.bat`];return[t]},k=async(e,t,r,o)=>{let s=(await Promise.all(t.map(async(i)=>await r.exists(i)?i:void 0))).find((i)=>i!==void 0);if(s)return s;for(let i of Fr(o,e)){let l=r.which(i);if(l)return l}return},j=(e,t,r,o,n)=>o?{id:e,label:t,path:o,platform:r,status:"pass"}:{id:e,label:t,platform:r,remediation:n,status:"fail"},et=async(e={})=>{let t=e.env??process.env,r=e.host??se(),o=e.exists??Hr,n=e.which??((A)=>Bun.which(A)),s=e.capture??Ur,i=e.androidRoot===null?void 0:e.androidRoot??t.ANDROID_HOME??t.ANDROID_SDK_ROOT??Br(r,t),l=r==="windows"||r==="wsl",a=(A)=>i?K(i,...A):void 0,c=(A)=>A.filter((h)=>Boolean(h)),g=await k("adb",c([a(["platform-tools",l?"adb.exe":"adb"])]),{exists:o,which:n},r),m=await k("emulator",c([a(["emulator",l?"emulator.exe":"emulator"])]),{exists:o,which:n},r),b=await k("sdkmanager",c([a(["cmdline-tools","latest","bin",l?"sdkmanager.bat":"sdkmanager"])]),{exists:o,which:n},r),x=await k("avdmanager",c([a(["cmdline-tools","latest","bin",l?"avdmanager.bat":"avdmanager"])]),{exists:o,which:n},r),u=await k("java",[],{exists:o,which:n},r),p=[{id:"host",label:`Development host: ${r}`,platform:"host",status:"pass"},j("android.adb","Android Debug Bridge","android",g,"Install Android SDK Platform Tools or expose adb on PATH."),j("android.emulator","Android Emulator","android",m,"Install the Android Emulator from Android Studio SDK Manager."),j("android.sdkmanager","Android SDK Manager","android",b,"Install Android SDK Command-line Tools (latest)."),j("android.avdmanager","Android Virtual Device Manager","android",x,"Install Android SDK Command-line Tools (latest)."),j("android.java","Java runtime","android",u,"Install the JDK required by the configured Android Gradle plugin.")];if(m){let A=s([m,"-list-avds"]),h=A.exitCode===0&&A.stdout.split(/\r?\n/).includes(Qe);p.push({id:"android.avd",label:`AbsoluteJS Android emulator (${Qe})`,platform:"android",remediation:h?void 0:"Run absolute mobile doctor android --fix to provision the managed emulator.",status:h?"pass":"fail"})}if(r==="wsl")p.push({id:"android.virtualization",label:g?.endsWith(".exe")?"Windows-host Android bridge available to WSL":"WSL requires a Windows-host emulator bridge or Linux KVM",platform:"android",remediation:g?.endsWith(".exe")?void 0:"Expose the Windows Android SDK adb.exe to WSL, or enable /dev/kvm for a Linux SDK.",status:g?.endsWith(".exe")?"pass":"warn"});else if(r==="linux"){let A=await o("/dev/kvm");p.push({id:"android.virtualization",label:"Linux KVM acceleration",platform:"android",remediation:A?void 0:"Enable KVM and grant the current user access to /dev/kvm.",status:A?"pass":"warn"})}if(r!=="macos")return p.push({id:"ios.simulator",label:"iOS Simulator requires macOS and Xcode",platform:"ios",status:"skip"}),p;let f=await k("xcrun",[],{exists:o,which:n},r),_=await k("xcodebuild",[],{exists:o,which:n},r);if(p.push(j("ios.xcrun","Xcode command runner","ios",f,"Install Xcode and select it with xcode-select."),j("ios.xcodebuild","Xcode build system","ios",_,"Install Xcode and select it with xcode-select.")),f){let A=s([f,"simctl","list","runtimes","--json"]),h=A.exitCode===0&&$r(A.stdout);p.push({id:"ios.runtime",label:"iOS Simulator runtime",platform:"ios",remediation:h?void 0:"Run absolute mobile doctor ios --fix to download an iOS Simulator runtime.",status:h?"pass":"fail"})}return p};import{access as Wr,readFile as Gr,rename as Jr,writeFile as Vr}from"fs/promises";import{relative as zr,resolve as tt}from"path";var rt="capacitor.config.ts",ve=(e,t)=>zr(e,t).replaceAll("\\","/"),Xr=(e,t)=>`import type { CapacitorConfig } from '@capacitor/cli';
324
402
 
325
403
  const config: CapacitorConfig = {
326
404
  appId: ${JSON.stringify(e.appId)},
327
405
  appName: ${JSON.stringify(e.appName)},
328
- webDir: ${JSON.stringify(Ee(r,e.bundleDirectory))},
406
+ webDir: ${JSON.stringify(ve(t,e.bundleDirectory))},
329
407
  android: {
330
- path: ${JSON.stringify(Ee(r,`${e.nativeProjectDirectory}/android`))}
408
+ path: ${JSON.stringify(ve(t,`${e.nativeProjectDirectory}/android`))}
331
409
  },
332
410
  ios: {
333
- path: ${JSON.stringify(Ee(r,`${e.nativeProjectDirectory}/ios`))}
411
+ path: ${JSON.stringify(ve(t,`${e.nativeProjectDirectory}/ios`))}
334
412
  }
335
413
  };
336
414
 
337
415
  export default config;
338
- `,Ba=async(e)=>{try{return await Ma(e),!0}catch{return!1}},oe=async(e,r)=>{let a=ve(r.projectRoot),s=ve(a,je),c=Ua(e,a);if(await Ba(s)){if(await ka(s,"utf8")===c)return{changed:!1,path:s};if(!r.force)throw TypeError(`${je} already exists and differs; rerun with --force only after reviewing it.`)}let l=`${s}.${crypto.randomUUID()}.tmp`;return await Ca(l,c,{flag:"wx"}),await Ra(l,s),{changed:!0,path:s}};import{createHash as Ja}from"crypto";import{access as Dc,copyFile as Nc,mkdir as Ic,mkdtemp as Mc,readdir as Ha,readFile as La,rename as kc,rm as Rc,stat as Cc,writeFile as Wc}from"fs/promises";import{dirname as Bc,isAbsolute as Jc,join as Va,relative as pe,resolve as Hc,sep as Lc}from"path";var Ga=new Set(["Pods","DerivedData","build","xcuserdata"]),er=async(e,r=e,a={})=>{let s=await Ha(r,{withFileTypes:!0});return(await Promise.all(s.sort((l,t)=>l.name.localeCompare(t.name)).map(async(l)=>{let t=Va(r,l.name),u=pe(e,t).replaceAll("\\","/");if(l.isDirectory()&&(Ga.has(l.name)||u==="App/App/public"&&a.includePublicBundle!==!0))return[];if(l.isDirectory())return er(e,t,a);return l.isFile()?[t]:[]}))).flat()},rr=async(e,r={})=>{let a=Ja("sha256"),s=await er(e,e,r),c=await Promise.all(s.map((l)=>La(l)));return s.forEach((l,t)=>{a.update(pe(e,l).replaceAll("\\","/")),a.update("\x00"),a.update(c[t]??new Uint8Array),a.update("\x00")}),a.digest("hex")};var $e="AbsoluteJS iPhone",sr=180000,Qa=1000,Te=1,me=1,R=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),J=async(e)=>{try{return await Xa(e),!0}catch{return!1}},K=(e)=>e?.throwIfAborted(),za=(e,r={})=>{try{let a=Bun.spawnSync(e,{cwd:r.cwd,env:r.env,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return{exitCode:a.exitCode,stderr:a.stderr.toString(),stdout:a.stdout.toString()}}catch(a){return{exitCode:1,stderr:a instanceof Error?a.message:String(a),stdout:""}}},fr=async(e,r={})=>{return Bun.spawn(e,{cwd:r.cwd,env:r.env,signal:r.signal,stderr:"inherit",stdin:"inherit",stdout:"inherit"}).exited},ia=(e,r={})=>{Bun.spawn(e,{cwd:r.cwd,env:r.env,signal:r.signal,stderr:"ignore",stdin:"ignore",stdout:"ignore"})},cr=async(e,r)=>{let a=e.getReader(),s=new TextDecoder,c="",l=async()=>{let{done:t,value:u}=await a.read();if(t)return;c+=s.decode(u,{stream:!0});let w=c.split(/\r?\n/u);c=w.pop()??"",w.forEach(r),await l()};try{if(await l(),c+=s.decode(),c)r(c)}finally{a.releaseLock()}},va=(e,r,a)=>{let s=Bun.spawn(e,{cwd:r.cwd,env:r.env,signal:r.signal,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return cr(s.stdout,a),cr(s.stderr,a),{close:async()=>{try{s.kill()}catch{}await s.exited.catch(()=>{return})}}},k=async(e,r,a,s)=>{let c=await a(e,s);if(c!==0)throw Error(`${r} failed with status ${c}.`)},ja=async(e,r,a,s)=>{if(!e.https)return;if(!e.certificateAuthorityPath)throw Error("iOS Simulator HTTPS requires the AbsoluteJS development CA certificate.");await k([e.project.xcrun,"simctl","keychain",r,"add-root-cert",e.certificateAuthorityPath],"iOS Simulator development CA trust",a,{signal:e.signal}),s("Installed the AbsoluteJS development CA into this iOS Simulator trust store.")},lr=(e,r,a)=>a?[e.xcrun,"devicectl","device","process","launch","--terminate-existing","--device",r,e.config.appId]:[e.xcrun,"simctl","launch","--terminate-running-process",r,e.config.appId],j=(e,r)=>{if(e.exitCode!==0)throw Error(`${r} failed: ${e.stderr.trim()||e.stdout.trim()||`status ${e.exitCode}`}`);return e.stdout.trim()},De=(e,r)=>{try{let a=JSON.parse(e);if(R(a))return a}catch{}throw Error(`Invalid ${r} JSON from simctl.`)},oa=(e)=>{let a=De(e,"device type").devicetypes;if(!Array.isArray(a))return[];return a.flatMap((s)=>{if(!R(s))return[];let{identifier:c}=s,{name:l}=s;return typeof c==="string"&&typeof l==="string"?[{identifier:c,name:l}]:[]})},pa=(e)=>{let r=De(e,"runtime"),{runtimes:a}=r;if(!Array.isArray(a))return[];return a.flatMap((s)=>{if(!R(s))return[];let{identifier:c}=s,{name:l}=s,{version:t}=s;if(typeof c!=="string"||typeof l!=="string"||typeof t!=="string")return[];return[{identifier:c,isAvailable:s.isAvailable!==!1,name:l,version:t}]})},es=(e)=>{let r=De(e,"device"),{devices:a}=r;if(!R(a))return[];return Object.entries(a).flatMap(([s,c])=>{if(!Array.isArray(c))return[];return c.flatMap((l)=>{if(!R(l))return[];let{name:t}=l,{state:u}=l,{udid:w}=l;if(typeof t!=="string"||typeof u!=="string"||typeof w!=="string")return[];return[{isAvailable:l.isAvailable!==!1,name:t,runtime:s,state:u,udid:w}]})})},tr=(e)=>e.split(".").map((r)=>Number(r)),rs=(e,r)=>{let a=tr(e),s=tr(r),c=Math.max(a.length,s.length);for(let l=0;l<c;l++){let t=(a[l]??0)-(s[l]??0);if(t!==0)return t}return 0},as=(e)=>e.filter((r)=>r.isAvailable&&r.identifier.includes("SimRuntime.iOS-")).sort((r,a)=>rs(a.version,r.version))[0],wr=(e)=>Number(/iPhone\s+(\d+)/u.exec(e)?.[1]??0),ss=(e)=>e.filter((r)=>r.name.startsWith("iPhone")).sort((r,a)=>{let s=wr(a.name)-wr(r.name);if(s!==0)return s;let c=a.name.includes("Pro")?1:0,l=r.name.includes("Pro")?1:0;return c-l})[0],Ar=(e)=>{let r=T(e,".absolutejs","mobile","ios-dev-session");return{configBackup:T(r,"capacitor-config.backup"),infoBackup:T(r,"Info.plist.backup"),journal:T(r,"journal.json"),root:r}},yr=(e)=>T(e,".absolutejs","mobile","ios-native-cache.json"),v=(e,r)=>{let a=qa(we(e),we(r));return a===""||!a.startsWith(`..${Za}`)&&a!==".."&&!Ya(a)},cs=(e)=>{if(!R(e)||e.format!==Te)return null;let{configBackupPath:r}=e,{infoBackupPath:a}=e,{infoPath:s}=e,{nativeConfigPath:c}=e;if(typeof r!=="string"||typeof a!=="string"||typeof s!=="string"||typeof c!=="string")return null;return{configBackupPath:r,format:Te,infoBackupPath:a,infoPath:s,nativeConfigPath:c}},le=async(e)=>{let r=Ar(e);if(!await J(r.journal))return await _e(r.root,{force:!0,recursive:!0}),!1;let a=await te(r.journal,"utf8").then((s)=>cs(JSON.parse(s))).catch(()=>null);if(!a||!v(e,a.nativeConfigPath)||!v(e,a.infoPath)||!v(r.root,a.configBackupPath)||!v(r.root,a.infoBackupPath))throw Error(`Refusing unsafe or invalid iOS dev journal at ${r.journal}.`);if(await J(a.configBackupPath))await ar(a.configBackupPath,a.nativeConfigPath);if(await J(a.infoBackupPath))await ar(a.infoBackupPath,a.infoPath);return await _e(r.root,{force:!0,recursive:!0}),!0},ls=(e,r)=>{if(!r)return e;let a=/(<key>NSAllowsArbitraryLoads<\/key>\s*)<false\s*\/>/u;if(a.test(e))return e.replace(a,"$1<true/>");if(/<key>NSAllowsArbitraryLoads<\/key>\s*<true\s*\/>/u.test(e))return e;let s=/(<key>NSAppTransportSecurity<\/key>\s*<dict>)/u;if(s.test(e))return e.replace(s,`$1
416
+ `,qr=async(e)=>{try{return await Wr(e),!0}catch{return!1}},ot=async(e,t)=>{let r=tt(t.projectRoot),o=tt(r,rt),n=Xr(e,r);if(await qr(o)){if(await Gr(o,"utf8")===n)return{changed:!1,path:o};if(!t.force)throw TypeError(`${rt} already exists and differs; rerun with --force only after reviewing it.`)}let s=`${o}.${crypto.randomUUID()}.tmp`;return await Vr(s,n,{flag:"wx"}),await Jr(s,o),{changed:!0,path:o}};import{createHash as Kr}from"crypto";import{access as zn,copyFile as Xn,mkdir as qn,mkdtemp as Kn,readdir as Yr,readFile as Zr,rename as Yn,rm as Zn,stat as Qn,writeFile as es}from"fs/promises";import{dirname as rs,isAbsolute as os,join as Qr,relative as nt,resolve as ns,sep as ss}from"path";var eo=new Set(["Pods","DerivedData","build","xcuserdata"]),st=async(e,t=e,r={})=>{let o=await Yr(t,{withFileTypes:!0});return(await Promise.all(o.sort((s,i)=>s.name.localeCompare(i.name)).map(async(s)=>{let i=Qr(t,s.name),l=nt(e,i).replaceAll("\\","/");if(s.isDirectory()&&(eo.has(s.name)||l==="App/App/public"&&r.includePublicBundle!==!0))return[];if(s.isDirectory())return st(e,i,r);return s.isFile()?[i]:[]}))).flat()},it=async(e,t={})=>{let r=Kr("sha256"),o=await st(e,e,t),n=await Promise.all(o.map((s)=>Zr(s)));return o.forEach((s,i)=>{r.update(nt(e,s).replaceAll("\\","/")),r.update("\x00"),r.update(n[i]??new Uint8Array),r.update("\x00")}),r.digest("hex")};var Se="AbsoluteJS iPhone",ct=180000,co=1000,xe=1,Ie=1,D=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),L=async(e)=>{try{return await ro(e),!0}catch{return!1}},W=(e)=>e?.throwIfAborted(),lo=(e,t={})=>{try{let r=Bun.spawnSync(e,{cwd:t.cwd,env:t.env,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return{exitCode:r.exitCode,stderr:r.stderr.toString(),stdout:r.stdout.toString()}}catch(r){return{exitCode:1,stderr:r instanceof Error?r.message:String(r),stdout:""}}},ht=async(e,t={})=>Bun.spawn(e,{cwd:t.cwd,env:t.env,signal:t.signal,stderr:"inherit",stdin:"inherit",stdout:"inherit"}).exited,uo=(e,t={})=>{Bun.spawn(e,{cwd:t.cwd,env:t.env,signal:t.signal,stderr:"ignore",stdin:"ignore",stdout:"ignore"})},lt=async(e,t)=>{let r=e.getReader(),o=new TextDecoder,n="",s=async()=>{let{done:i,value:l}=await r.read();if(i)return;n+=o.decode(l,{stream:!0});let a=n.split(/\r?\n/u);n=a.pop()??"",a.forEach(t),await s()};try{if(await s(),n+=o.decode(),n)t(n)}finally{r.releaseLock()}},po=(e,t,r)=>{let o=Bun.spawn(e,{cwd:t.cwd,env:t.env,signal:t.signal,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return lt(o.stdout,r),lt(o.stderr,r),{close:async()=>{try{o.kill()}catch{}await o.exited.catch(()=>{return})}}},P=async(e,t,r,o)=>{let n=await r(e,o);if(n!==0)throw Error(`${t} failed with status ${n}.`)},mo=async(e,t,r,o)=>{if(!e.https)return;if(!e.certificateAuthorityPath)throw Error("iOS Simulator HTTPS requires the AbsoluteJS development CA certificate.");await P([e.project.xcrun,"simctl","keychain",t,"add-root-cert",e.certificateAuthorityPath],"iOS Simulator development CA trust",r,{signal:e.signal}),o("Installed the AbsoluteJS development CA into this iOS Simulator trust store.")},ut=(e,t,r)=>r?[e.xcrun,"devicectl","device","process","launch","--terminate-existing","--device",t,e.config.appId]:[e.xcrun,"simctl","launch","--terminate-running-process",t,e.config.appId],Z=(e,t)=>{if(e.exitCode!==0)throw Error(`${t} failed: ${e.stderr.trim()||e.stdout.trim()||`status ${e.exitCode}`}`);return e.stdout.trim()},_e=(e,t)=>{try{let r=JSON.parse(e);if(D(r))return r}catch{}throw Error(`Invalid ${t} JSON from simctl.`)},go=(e)=>{let r=_e(e,"device type").devicetypes;if(!Array.isArray(r))return[];return r.flatMap((o)=>{if(!D(o))return[];let{identifier:n}=o,{name:s}=o;return typeof n==="string"&&typeof s==="string"?[{identifier:n,name:s}]:[]})},fo=(e)=>{let t=_e(e,"runtime"),{runtimes:r}=t;if(!Array.isArray(r))return[];return r.flatMap((o)=>{if(!D(o))return[];let{identifier:n}=o,{name:s}=o,{version:i}=o;if(typeof n!=="string"||typeof s!=="string"||typeof i!=="string")return[];return[{identifier:n,isAvailable:o.isAvailable!==!1,name:s,version:i}]})},bo=(e)=>{let t=_e(e,"device"),{devices:r}=t;if(!D(r))return[];return Object.entries(r).flatMap(([o,n])=>{if(!Array.isArray(n))return[];return n.flatMap((s)=>{if(!D(s))return[];let{name:i}=s,{state:l}=s,{udid:a}=s;if(typeof i!=="string"||typeof l!=="string"||typeof a!=="string")return[];return[{isAvailable:s.isAvailable!==!1,name:i,runtime:o,state:l,udid:a}]})})},dt=(e)=>e.split(".").map((t)=>Number(t)),ho=(e,t)=>{let r=dt(e),o=dt(t),n=Math.max(r.length,o.length);for(let s=0;s<n;s++){let i=(r[s]??0)-(o[s]??0);if(i!==0)return i}return 0},Ao=(e)=>e.filter((t)=>t.isAvailable&&t.identifier.includes("SimRuntime.iOS-")).sort((t,r)=>ho(r.version,t.version))[0],pt=(e)=>Number(/iPhone\s+(\d+)/u.exec(e)?.[1]??0),wo=(e)=>e.filter((t)=>t.name.startsWith("iPhone")).sort((t,r)=>{let o=pt(r.name)-pt(t.name);if(o!==0)return o;let n=r.name.includes("Pro")?1:0,s=t.name.includes("Pro")?1:0;return n-s})[0],At=(e)=>{let t=S(e,".absolutejs","mobile","ios-dev-session");return{configBackup:S(t,"capacitor-config.backup"),infoBackup:S(t,"Info.plist.backup"),journal:S(t,"journal.json"),root:t}},wt=(e)=>S(e,".absolutejs","mobile","ios-native-cache.json"),Y=(e,t)=>{let r=io(ce(e),ce(t));return r===""||!r.startsWith(`..${ao}`)&&r!==".."&&!so(r)},Eo=(e)=>{if(!D(e)||e.format!==xe)return null;let{configBackupPath:t}=e,{infoBackupPath:r}=e,{infoPath:o}=e,{nativeConfigPath:n}=e;if(typeof t!=="string"||typeof r!=="string"||typeof o!=="string"||typeof n!=="string")return null;return{configBackupPath:t,format:xe,infoBackupPath:r,infoPath:o,nativeConfigPath:n}},ie=async(e)=>{let t=At(e);if(!await L(t.journal))return await ye(t.root,{force:!0,recursive:!0}),!1;let r=await ae(t.journal,"utf8").then((o)=>Eo(JSON.parse(o))).catch(()=>null);if(!r||!Y(e,r.nativeConfigPath)||!Y(e,r.infoPath)||!Y(t.root,r.configBackupPath)||!Y(t.root,r.infoBackupPath))throw Error(`Refusing unsafe or invalid iOS dev journal at ${t.journal}.`);if(await L(r.configBackupPath))await at(r.configBackupPath,r.nativeConfigPath);if(await L(r.infoBackupPath))await at(r.infoBackupPath,r.infoPath);return await ye(t.root,{force:!0,recursive:!0}),!0},vo=(e,t)=>{if(!t)return e;let r=/(<key>NSAllowsArbitraryLoads<\/key>\s*)<false\s*\/>/u;if(r.test(e))return e.replace(r,"$1<true/>");if(/<key>NSAllowsArbitraryLoads<\/key>\s*<true\s*\/>/u.test(e))return e;let o=/(<key>NSAppTransportSecurity<\/key>\s*<dict>)/u;if(o.test(e))return e.replace(o,`$1
339
417
  <key>NSAllowsArbitraryLoads</key>
340
418
  <true/>`);return e.replace(/<dict>/u,`<dict>
341
419
  <key>NSAppTransportSecurity</key>
342
420
  <dict>
343
421
  <key>NSAllowsArbitraryLoads</key>
344
422
  <true/>
345
- </dict>`)},ts=async(e,r,a,s="localhost")=>{let c=Ar(e.projectRoot);await le(e.projectRoot);let l=T(e.nativeDirectory,"App","App","capacitor.config.json"),t=T(e.nativeDirectory,"App","App","Info.plist"),[u,w]=await Promise.all([te(l,"utf8"),te(t,"utf8")]),b=JSON.parse(u);if(!R(b))throw Error(`Invalid Capacitor native config at ${l}.`);await P(c.root,{recursive:!0}),await Promise.all([G(c.configBackup,u,{flag:"wx"}),G(c.infoBackup,w,{flag:"wx"})]);let x={configBackupPath:c.configBackup,format:Te,infoBackupPath:c.infoBackup,infoPath:t,nativeConfigPath:l};await G(c.journal,`${JSON.stringify(x,null,"\t")}
346
- `,{flag:"wx"});let A=new URL(`${a?"https":"http"}://localhost:${r}${e.config.entry}`);A.hostname=Pa(s)===6?`[${s}]`:s,A.searchParams.set("__absolute_target","capacitor-ios");let f=b.server;b.server={...R(f)?f:{},cleartext:!a,url:A.href},await Promise.all([G(l,`${JSON.stringify(b,null,"\t")}
347
- `),G(t,ls(w,!a))])},ws=(e)=>{if(!R(e))return null;let{appId:r,fingerprint:a,format:s,installations:c}=e;if(s!==me||typeof r!=="string"||typeof a!=="string"||!R(c)||!Object.values(c).every((l)=>typeof l==="string"))return null;return{appId:r,fingerprint:a,format:s,installations:Object.fromEntries(Object.entries(c).map(([l,t])=>[l,String(t)]))}},bs=(e)=>te(yr(e),"utf8").then((r)=>ws(JSON.parse(r))).catch(()=>null),xr=async(e,r)=>{let a=yr(e),s=`${a}.${process.pid}.${Fa()}.tmp`;await P(nr(a),{recursive:!0});try{await G(s,`${JSON.stringify(r,null,"\t")}
348
- `,{flag:"wx"}),await Ka(s,a)}finally{await _e(s,{force:!0}).catch(()=>{return})}},us=async(e,r={})=>rr(e.nativeDirectory,r),Sr=(e,r)=>{let a=r([e,"simctl","list","devices","available","-j"]);return es(j(a,"iOS simulator discovery"))},ds=async(e,r)=>{let a=pa(j(r([e.xcrun,"simctl","list","runtimes","-j"]),"iOS runtime discovery")),s=as(a);if(!s)throw Error("No available iOS Simulator runtime. Run absolute mobile doctor ios --fix.");let[c]=Sr(e.xcrun,r).filter((w)=>w.isAvailable&&w.name===$e&&w.runtime===s.identifier).sort((w,b)=>Number(b.state==="Booted")-Number(w.state==="Booted"));if(c)return{created:!1,device:c};let l=oa(j(r([e.xcrun,"simctl","list","devicetypes","-j"]),"iOS device-type discovery")),t=ss(l);if(!t)throw Error("Xcode did not report an iPhone simulator type.");let[u]=j(r([e.xcrun,"simctl","create",$e,t.identifier,s.identifier]),"iOS simulator creation").split(/\s/u);if(!u)throw Error("simctl did not return the created simulator UDID.");return{created:!0,device:{isAvailable:!0,name:$e,runtime:s.identifier,state:"Shutdown",udid:u}}},ns=async(e,r,a,s,c)=>{let l=Date.now()+sr,t=async()=>{if(K(c),Sr(e.xcrun,a).find((w)=>w.udid===r)?.state==="Booted")return;if(Date.now()>l)throw Error(`iOS simulator ${r} did not finish booting within ${sr/1000}s.`);await s(Qa),await t()};return t()},fs=(e,r,a)=>{if(r.state==="Booted")return;j(a([e.xcrun,"simctl","boot",r.udid]),"iOS simulator boot")},br=(e,r,a)=>{let s=a([e.xcrun,"simctl","get_app_container",r,e.config.appId,"app"]);return s.exitCode===0&&s.stdout.trim()?s.stdout.trim():void 0},As=(e,r,a)=>{let s=a([e.xcrun,"devicectl","device","info","details","--device",r]);if(s.exitCode!==0)throw Error(`Physical iOS device ${JSON.stringify(r)} is unavailable: ${s.stderr.trim()||s.stdout.trim()||"pair it in Xcode Device Hub, trust this Mac, unlock it, and enable Developer Mode."}`)},ys=(e,r,a)=>{let s=a([e.xcrun,"devicectl","device","info","apps","--device",r]);return s.exitCode===0&&s.stdout.includes(e.config.appId)},xs=async(e,r,a,s,c)=>{let l=T(e.projectRoot,".absolutejs","mobile","ios-derived-data",dr("sha256").update(e.config.appId).digest("hex").slice(0,16));await P(l,{recursive:!0}),await k([e.xcodebuild,"-workspace",T(e.nativeDirectory,"App","App.xcworkspace"),"-scheme","App","-configuration","Debug","-destination",`platform=iOS Simulator,id=${r}`,"-derivedDataPath",l,"build"],"iOS simulator build",s,{cwd:e.nativeDirectory,signal:c});let t=T(l,"Build","Products","Debug-iphonesimulator","App.app");if(!await J(t))throw Error(`Xcode did not produce the simulator app at ${t}.`);return t},Ss=async(e,r,a,s)=>{let c=T(e.projectRoot,".absolutejs","mobile","ios-derived-data",dr("sha256").update(e.config.appId).digest("hex").slice(0,16));await P(c,{recursive:!0}),await k([e.xcodebuild,"-workspace",T(e.nativeDirectory,"App","App.xcworkspace"),"-scheme","App","-configuration","Debug","-destination",`platform=iOS,id=${r}`,"-derivedDataPath",c,"-allowProvisioningUpdates","build"],"iOS physical-device build (configure automatic signing and a Development Team in Xcode if this is the first run)",a,{cwd:e.nativeDirectory,signal:s});let l=T(c,"Build","Products","Debug-iphoneos","App.app");if(!await J(l))throw Error(`Xcode did not produce the physical-device app at ${l}.`);return l},gs=async(e)=>{if(e.cache?.appId===e.project.config.appId&&e.cache.fingerprint===e.fingerprint&&e.cache.installations[e.identifier]===e.fingerprint&&ys(e.project,e.identifier,e.capture))return e.log("iOS native app is unchanged on the selected physical device; skipped Xcode build and install."),!0;e.log("iOS native inputs changed or the physical-device install is stale; rebuilding."),e.transition("building");let a=await Ss(e.project,e.identifier,e.run,e.signal);return K(e.signal),e.transition("installing"),await k([e.project.xcrun,"devicectl","device","install","app","--device",e.identifier,a],"iOS physical-device app installation",e.run,{signal:e.signal}),await xr(e.project.projectRoot,{appId:e.project.config.appId,fingerprint:e.fingerprint,format:me,installations:{...e.cache?.appId===e.project.config.appId?e.cache.installations:{},[e.identifier]:e.fingerprint}}).catch((s)=>e.log(`iOS native cache could not be saved: ${s instanceof Error?s.message:String(s)}`)),!1},hs=async(e)=>{let r=br(e.project,e.udid,e.capture);if(e.cache?.appId===e.project.config.appId&&e.cache.fingerprint===e.fingerprint&&r!==void 0&&e.cache.installations[e.udid]===r)return e.log(`iOS native app is unchanged on ${e.udid}; skipped Xcode build and install.`),!0;e.log("iOS native inputs changed or the installed app is stale; rebuilding."),e.transition("building");let s=await xs(e.project,e.udid,e.fingerprint,e.run,e.signal);K(e.signal),e.transition("installing"),await k([e.project.xcrun,"simctl","install",e.udid,s],"iOS simulator app installation",e.run,{signal:e.signal});let c=br(e.project,e.udid,e.capture);if(c)await xr(e.project.projectRoot,{appId:e.project.config.appId,fingerprint:e.fingerprint,format:me,installations:{[e.udid]:c}}).catch((l)=>e.log(`iOS native cache could not be saved: ${l instanceof Error?l.message:String(l)}`));return!1},Os=/((?:authorization|cookie|password|secret|token|oauth[_-]?code)\s*[:=]\s*)([^\s,;]+)/giu,Es=new RegExp(String.raw`\bBearer\s+[A-Za-z0-9._~+/-]+=*`,"giu"),$s=/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu,_s=new RegExp(String.raw`\s(Debug|Info|Notice|Error|Fault)\s+.*?\[[^\]]+\]\s+\[([^\]]+)\]\s*(.*)$`,"iu"),Ts=(e)=>{let r=ms(e).trim();if(!r)return null;let a=_s.exec(r),s=a?.[1]?.toLowerCase();return{level:s==="debug"||s==="error"||s==="fault"||s==="notice"?s:"info",message:a?.[3]?.trim()||r,tag:a?.[2]?.trim()||"App"}},ms=(e)=>e.replaceAll(Es,"Bearer [REDACTED]").replaceAll($s,"[REDACTED_JWT]").replaceAll(Os,"$1[REDACTED]").replaceAll(/\p{C}/gu,""),ur=(e,r,a)=>{if(!a.nativeLog)return null;let s=a.startNativeLogs??va,c=a.deviceIdentifier?[e.xcrun,"devicectl","device","process","launch","--console","--terminate-existing","--device",r,e.config.appId]:[e.xcrun,"simctl","spawn",r,"log","stream","--style","compact","--level","debug","--predicate",'process == "App"'];return s(c,{signal:a.signal},(l)=>{let t=Ts(l);if(t)a.nativeLog?.(t)})},Ds=[["syncing","Capacitor sync"],["configuring","dev config"],["fingerprinting","fingerprint"],["booting","simulator"],["connecting","device ready"],["enrolling-trust","HTTPS trust"],["checking-native","app check"],["building","Xcode"],["installing","install"],["launching","launch"],["streaming-logs","logs"]],Ns=(e)=>Ds.map(([r,a])=>{let s=e[r];return s===void 0?null:`${a} ${z(s)}`}).filter((r)=>r!==null).join(", "),gr=async(e,r)=>{if(ce()!=="macos")throw Error("iOS development requires macOS and Xcode.");let a=r.target??"simulator",s=we(r.projectRoot),c=await ie({host:"macos"}),l=c.filter((A)=>A.platform==="ios"&&!(a==="device"&&A.id==="ios.runtime")&&(A.status==="fail"||A.status==="warn"));if(l.length>0)throw Error(`iOS ${a} development is not ready: ${l.map(({label:A})=>A).join(", ")}.`);let t=c.find((A)=>A.id==="ios.xcrun")?.path,u=c.find((A)=>A.id==="ios.xcodebuild")?.path;if(!t||!u)throw Error("Xcode tools disappeared after readiness checks.");let w=T(s,"node_modules",".bin","cap");if(!await J(w))throw Error("Capacitor CLI is not installed. Run absolute mobile init first.");await oe(e,{projectRoot:s}),await P(e.bundleDirectory,{recursive:!0});let b=T(e.bundleDirectory,"index.html");if(!await J(b))await G(b,`<!doctype html><title>AbsoluteJS mobile development</title>
349
- `);let x=T(e.nativeProjectDirectory,"ios");if(!await J(x)){if(!r.createNativeProject)throw Error("iOS native project has not been created.");if(await(r.run??fr)([w,"add","ios"],{cwd:s})!==0)throw Error("Capacitor iOS project creation failed.")}return{cap:w,config:e,nativeDirectory:x,projectRoot:s,xcodebuild:u,xcrun:t}},Is=async(e)=>{if(e.transition("connecting"),As(e.project,e.deviceIdentifier,e.capture),!e.startOptions.https)return{caEnrollmentServer:null,startedSimulator:!1,udid:e.deviceIdentifier};if(!e.startOptions.certificateAuthorityPath)throw Error("Physical iOS HTTPS development requires the AbsoluteJS development CA certificate.");e.transition("enrolling-trust");let a=await(e.startOptions.startCaEnrollmentServer??re)({certificateAuthorityPath:e.startOptions.certificateAuthorityPath,displayHost:e.serverHost});return e.log(`On the iOS device, open ${a.url}, install the AbsoluteJS development CA profile, then enable it under Settings > General > About > Certificate Trust Settings. This public CA endpoint exists only for this dev session.`),{caEnrollmentServer:a,startedSimulator:!1,udid:e.deviceIdentifier}},Ms=async(e)=>{e.transition("booting");let r=await ds(e.project,e.capture),{device:a}=r,s=r.created||a.state!=="Booted";return fs(e.project,a,e.capture),e.spawn(["open","-a","Simulator","--args","-CurrentDeviceUDID",a.udid]),e.transition("connecting"),await ns(e.project,a.udid,e.capture,e.sleep,e.startOptions.signal),await k([e.project.xcrun,"simctl","bootstatus",a.udid,"-b"],"iOS simulator boot readiness",e.run,{signal:e.startOptions.signal}),await ja(e.startOptions,a.udid,e.run,e.log),{caEnrollmentServer:null,startedSimulator:s,udid:a.udid}},Ne=async(e)=>{let{project:r}=e,a=e.deviceIdentifier?Ve(e.deviceIdentifier):void 0,s=a?"device":"simulator",c=a?ye(e.serverHost??""):"localhost",l=e.capture??za,t=e.run??fr,u=e.sleep??Bun.sleep,w=e.spawn??ia,b=e.log??console.log,x=performance.now(),A=performance.now(),f={},O="syncing",n=(g)=>{if(g===O){e.onStateChange?.(g);return}let C=performance.now(),F=C-A;f[O]=(f[O]??0)+F,e.onPhaseTiming?.({durationMs:F,phase:O,totalMs:C-x}),O=g,A=C,e.onStateChange?.(g)},y=null,S=null,D=async()=>{let g=y;y=null,await g?.close().catch(()=>{return})},h=async(g)=>{if(a&&e.nativeLog){await D(),y=ur(r,g,e);return}await k(lr(r,g,a!==void 0),"iOS app relaunch",t,{signal:e.signal})};try{if(await le(r.projectRoot),K(e.signal),n("syncing"),await k([r.cap,"sync","ios"],"Capacitor iOS synchronization",t,{cwd:r.projectRoot,signal:e.signal}),n("configuring"),e.embeddedBundle!==!0)await ts(r,e.port,e.https===!0,c);K(e.signal);let g=performance.now(),C=us(r,{includePublicBundle:e.embeddedBundle===!0}).then((B)=>{return f.fingerprinting=performance.now()-g,B}),F=a?await Is({capture:l,deviceIdentifier:a,log:b,project:r,serverHost:c,startOptions:e,transition:n}):await Ms({capture:l,log:b,project:r,run:t,sleep:u,spawn:w,startOptions:e,transition:n}),{caEnrollmentServer:o,startedSimulator:ne,udid:d}=F;S=o;let E=await C;n("checking-native");let m=await bs(r.projectRoot),M=a?await gs({cache:m,capture:l,fingerprint:E,identifier:a,log:b,project:r,run:t,signal:e.signal,transition:n}):await hs({cache:m,capture:l,fingerprint:E,log:b,project:r,run:t,signal:e.signal,transition:n,udid:d});if(K(e.signal),e.nativeLog)n("streaming-logs");if(y=ur(r,d,e),n("launching"),!a||!y)await k(lr(r,d,a!==void 0),"iOS app launch",t,{signal:e.signal});n("ready"),f.total=performance.now()-x,b(e.embeddedBundle===!0?`iOS ${s} connected with the embedded bundle and backend on port ${e.port} in ${z(f.total)} (${M?"native cache hit":"native build installed"}).`:`iOS ${s} connected with HMR on port ${e.port} in ${z(f.total)} (${M?"native cache hit":"native build installed"}).`),b(`iOS startup: ${Ns(f)}.`);let N=!1,U=async()=>{if(N)return;N=!0,n("closing"),await D(),await S?.close().catch(()=>{return}),S=null,await le(r.projectRoot),n("closed")};return{close:U,nativeCacheHit:M,startedSimulator:ne,targetKind:s,timings:{...f},udid:d,rebuild:async()=>{if(N)throw Error("iOS development session is closed.");return b("iOS native inputs changed; rebuilding without restarting the dev server."),await U(),Ne(e)},relaunch:async()=>{if(N)throw Error("iOS development session is closed.");n("launching");try{await h(d),n("ready"),b(`iOS app relaunched on the selected ${s}.`)}catch(B){throw n("failed"),B}},screenshot:async(B)=>{if(a)throw Error("Physical iOS screenshots are captured in Xcode Device Hub; the CLI never records a device screen automatically.");let H=we(r.projectRoot,B);if(!v(r.projectRoot,H))throw Error("iOS screenshot destination must remain inside the project.");return await P(nr(H),{recursive:!0}),await k([r.xcrun,"simctl","io",d,"screenshot",H],"iOS simulator screenshot",t,{signal:e.signal}),H},get state(){return O}}}catch(g){throw n("failed"),await D(),await S?.close().catch(()=>{return}),await le(r.projectRoot),g}};var hr="ABSOLUTE_REMOTE_MAC\t",be=2;var $=(e)=>process.stdout.write(`${hr}${JSON.stringify({...e,v:be})}
350
- `),de=(e)=>e instanceof Error?e.message:String(e),Y=(e,r)=>{let a=e.indexOf(r);return a<0?void 0:e[a+1]},Ws=(e)=>{let r=Number(Y(e,"--port"));if(!Number.isInteger(r)||r<1||r>65535)throw TypeError("Remote iOS agent requires a valid --port.");return r},Me=(e,r)=>{let a=Y(e,r);if(a===void 0)return;let s=Number(a);if(!Number.isInteger(s)||s<1||s>65535)throw TypeError(`Remote iOS agent requires a valid ${r}.`);return s},Us=(e)=>{let r=Y(e,"--mobile-config");if(!r)throw TypeError("Remote iOS agent requires --mobile-config.");let a=JSON.parse(Buffer.from(r,"base64url").toString("utf8"));if(typeof a!=="object"||a===null)throw TypeError("Remote iOS agent received an invalid mobile config.");return a},Or=async(e,r)=>{let a=e.getReader(),s=new TextDecoder,c="";try{while(!0){let{done:l,value:t}=await a.read();if(l)break;c+=s.decode(t,{stream:!0});let u=c.split(/\r?\n/u);c=u.pop()??"",u.forEach(r)}}finally{a.releaseLock()}},ke=async(e,r={})=>{let a=Bun.spawn(e,{cwd:r.cwd,env:r.env,signal:r.signal,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return Or(a.stdout,(s)=>$({message:s,type:"log"})),Or(a.stderr,(s)=>$({message:s,type:"log"})),a.exited},Bs=(e,r={})=>{try{let a=Bun.spawnSync(e,{cwd:r.cwd,env:r.env,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return{exitCode:a.exitCode,stderr:a.stderr.toString(),stdout:a.stdout.toString()}}catch(a){return{exitCode:1,stderr:de(a),stdout:""}}},Er=(e)=>({engine:"capacitor",nativeCacheHit:e.nativeCacheHit,startedSimulator:e.startedSimulator,targetKind:e.targetKind,timings:e.timings,type:"ready",udid:e.udid}),Js=async(e)=>{if(e.config.engine!=="expo")throw TypeError("The remote Expo executor requires Expo configuration.");let r=Me(e.args,"--metro-port");if(r===void 0)throw TypeError("Remote Expo execution requires --metro-port.");let a=Me(e.args,"--metro-relay-port");if(e.deviceIdentifier&&a===void 0)throw TypeError("Remote physical Expo execution requires --metro-relay-port.");let s=await Ye(e.config,{projectRoot:process.cwd()}),c=await Bun.file(ue(s.path,"node_modules","expo","package.json")).exists();if(!c){$({state:"preparing-native",type:"state"});let w=performance.now(),b=await ke([process.execPath,"install"],{cwd:s.path});if(b!==0)throw Error(`Remote Expo dependency installation exited with status ${b}.`);$({durationMs:performance.now()-w,phase:"preparing-native",type:"timing"})}let l,t,u;try{l=e.deviceIdentifier?await ae({listenPort:e.port,targetPort:e.relayPort??0}):void 0,t=e.deviceIdentifier?await ae({listenPort:r,targetPort:a??0}):void 0,u=await Ge({certificateAuthorityPath:e.certificateAuthorityPath,config:e.config,executable:await ge(s.path),iosDevice:e.deviceIdentifier,iosOrigin:`${e.args.includes("--https")?"https":"http"}://${e.serverHost??"localhost"}:${e.port}`,metro:"external",metroHost:e.serverHost??"localhost",metroPort:r,platforms:["ios"],log:(b)=>$({message:b,type:"log"}),onPhaseTiming:(b)=>$({...b,type:"timing"}),onStateChange:(b)=>$({state:b,type:"state"})}),$({engine:"expo",nativeCacheHit:c,startedSimulator:!1,targetKind:e.deviceIdentifier?"device":"simulator",timings:u.timings,type:"ready",udid:e.deviceIdentifier??"booted"});let w=$r({input:process.stdin,terminal:!1});try{for await(let b of w){let x;try{if(x=JSON.parse(b),x.v!==be||typeof x.id!=="string"||x.command!=="close")throw Error("Invalid remote Expo request.");await u.close(),$({id:x.id,ok:!0,type:"response"});return}catch(A){$({error:de(A),id:x?.id??"",ok:!1,type:"response"})}}}finally{w.close()}}finally{await u?.close().catch(()=>{return}),await Promise.all([l?.close().catch(()=>{return}),t?.close().catch(()=>{return})])}},Hs=async(e)=>{if(process.platform!=="darwin")throw Error("The AbsoluteJS remote iOS agent can run only on macOS.");let r=process.cwd(),a=Je(Us(e),r),s=Ws(e),c=Y(e,"--ios-device"),l=Y(e,"--server-host"),t=Me(e,"--relay-port");if(c&&(!l||t===void 0))throw TypeError("Remote physical iOS development requires --server-host and --relay-port.");let u=Y(e,"--certificate-authority"),w=u?ue(r,".absolutejs","mobile",`remote-dev-ca-${process.pid}.pem`):void 0;if(w&&u)await ks(ue(r,".absolutejs","mobile"),{recursive:!0}),await Cs(w,Buffer.from(u,"base64url"));if(a.engine==="expo"){try{await Js({args:e,certificateAuthorityPath:w,config:a,deviceIdentifier:c,port:s,relayPort:t,serverHost:l})}finally{if(w)await Ie(w,{force:!0})}return}let b=await gr(a,{createNativeProject:!1,projectRoot:r,run:ke,target:c?"device":"simulator"}),x=c?await ae({listenPort:s,targetPort:t??0}):void 0,A={capture:Bs,certificateAuthorityPath:w,deviceIdentifier:c,https:e.includes("--https"),port:s,project:b,run:ke,serverHost:l,log:(n)=>$({message:n,type:"log"}),nativeLog:(n)=>$({entry:n,type:"native-log"}),onPhaseTiming:(n)=>$({...n,type:"timing"}),onStateChange:(n)=>$({state:n,type:"state"}),spawn:(n,y={})=>{Bun.spawn(n,{cwd:y.cwd,env:y.env,signal:y.signal,stderr:"ignore",stdin:"ignore",stdout:"ignore"})}},f;try{f=await Ne(A)}catch(n){if(await x?.close().catch(()=>{return}),w)await Ie(w,{force:!0});throw n}$(Er(f));let O=$r({input:process.stdin,terminal:!1});try{for await(let n of O){let y;try{if(y=JSON.parse(n),y.v!==be||typeof y.id!=="string")throw Error("Invalid remote Mac request.");let S;if(y.command==="close")await f.close();else if(y.command==="relaunch")await f.relaunch();else if(y.command==="rebuild")f=await f.rebuild(),S=Er(f);else if(y.command==="screenshot"){let D=ue(".absolutejs","mobile","remote-screenshot.png"),h=await f.screenshot(D);S={data:(await Rs(h)).toString("base64")}}else throw Error("Unknown remote Mac request.");if($({id:y.id,ok:!0,result:S,type:"response"}),y.command==="close")return}catch(S){$({error:de(S),id:y?.id??"",ok:!1,type:"response"})}}}finally{if(O.close(),await f.close().catch(()=>{return}),await x?.close().catch(()=>{return}),w)await Ie(w,{force:!0})}},_r=async(e)=>{try{await Hs(e)}catch(r){$({error:de(r),type:"fatal"}),process.exitCode=1}};await _r(process.argv.slice(2));
423
+ </dict>`)},So=async(e,t,r,o="localhost")=>{let n=At(e.projectRoot);await ie(e.projectRoot);let s=S(e.nativeDirectory,"App","App","capacitor.config.json"),i=S(e.nativeDirectory,"App","App","Info.plist"),[l,a]=await Promise.all([ae(s,"utf8"),ae(i,"utf8")]),c=JSON.parse(l);if(!D(c))throw Error(`Invalid Capacitor native config at ${s}.`);await G(n.root,{recursive:!0}),await Promise.all([B(n.configBackup,l,{flag:"wx"}),B(n.infoBackup,a,{flag:"wx"})]);let g={configBackupPath:n.configBackup,format:xe,infoBackupPath:n.infoBackup,infoPath:i,nativeConfigPath:s};await B(n.journal,`${JSON.stringify(g,null,"\t")}
424
+ `,{flag:"wx"});let m=new URL(`${r?"https":"http"}://localhost:${t}${e.config.entry}`);m.hostname=no(o)===6?`[${o}]`:o,m.searchParams.set("__absolute_target","capacitor-ios");let b=c.server;c.server={...D(b)?b:{},cleartext:!r,url:m.href},await Promise.all([B(s,`${JSON.stringify(c,null,"\t")}
425
+ `),B(i,vo(a,!r))])},yo=(e)=>{if(!D(e))return null;let{appId:t,fingerprint:r,format:o,installations:n}=e;if(o!==Ie||typeof t!=="string"||typeof r!=="string"||!D(n)||!Object.values(n).every((s)=>typeof s==="string"))return null;return{appId:t,fingerprint:r,format:o,installations:Object.fromEntries(Object.entries(n).map(([s,i])=>[s,String(i)]))}},xo=(e)=>ae(wt(e),"utf8").then((t)=>yo(JSON.parse(t))).catch(()=>null),Et=async(e,t)=>{let r=wt(e),o=`${r}.${process.pid}.${to()}.tmp`;await G(bt(r),{recursive:!0});try{await B(o,`${JSON.stringify(t,null,"\t")}
426
+ `,{flag:"wx"}),await oo(o,r)}finally{await ye(o,{force:!0}).catch(()=>{return})}},Io=async(e,t={})=>it(e.nativeDirectory,t),vt=(e,t)=>{let r=t([e,"simctl","list","devices","available","-j"]);return bo(Z(r,"iOS simulator discovery"))},_o=async(e,t)=>{let r=fo(Z(t([e.xcrun,"simctl","list","runtimes","-j"]),"iOS runtime discovery")),o=Ao(r);if(!o)throw Error("No available iOS Simulator runtime. Run absolute mobile doctor ios --fix.");let[n]=vt(e.xcrun,t).filter((a)=>a.isAvailable&&a.name===Se&&a.runtime===o.identifier).sort((a,c)=>Number(c.state==="Booted")-Number(a.state==="Booted"));if(n)return{created:!1,device:n};let s=go(Z(t([e.xcrun,"simctl","list","devicetypes","-j"]),"iOS device-type discovery")),i=wo(s);if(!i)throw Error("Xcode did not report an iPhone simulator type.");let[l]=Z(t([e.xcrun,"simctl","create",Se,i.identifier,o.identifier]),"iOS simulator creation").split(/\s/u);if(!l)throw Error("simctl did not return the created simulator UDID.");return{created:!0,device:{isAvailable:!0,name:Se,runtime:o.identifier,state:"Shutdown",udid:l}}},Oo=async(e,t,r,o,n)=>{let s=Date.now()+ct,i=async()=>{if(W(n),vt(e.xcrun,r).find((a)=>a.udid===t)?.state==="Booted")return;if(Date.now()>s)throw Error(`iOS simulator ${t} did not finish booting within ${ct/1000}s.`);await o(co),await i()};return i()},To=(e,t,r)=>{if(t.state==="Booted")return;Z(r([e.xcrun,"simctl","boot",t.udid]),"iOS simulator boot")},mt=(e,t,r)=>{let o=r([e.xcrun,"simctl","get_app_container",t,e.config.appId,"app"]);return o.exitCode===0&&o.stdout.trim()?o.stdout.trim():void 0},Po=(e,t,r)=>{let o=r([e.xcrun,"devicectl","device","info","details","--device",t]);if(o.exitCode!==0)throw Error(`Physical iOS device ${JSON.stringify(t)} is unavailable: ${o.stderr.trim()||o.stdout.trim()||"pair it in Xcode Device Hub, trust this Mac, unlock it, and enable Developer Mode."}`)},Do=(e,t,r)=>{let o=r([e.xcrun,"devicectl","device","info","apps","--device",t]);return o.exitCode===0&&o.stdout.includes(e.config.appId)},Co=async(e,t,r,o,n)=>{let s=S(e.projectRoot,".absolutejs","mobile","ios-derived-data",ft("sha256").update(e.config.appId).digest("hex").slice(0,16));await G(s,{recursive:!0}),await P([e.xcodebuild,"-workspace",S(e.nativeDirectory,"App","App.xcworkspace"),"-scheme","App","-configuration","Debug","-destination",`platform=iOS Simulator,id=${t}`,"-derivedDataPath",s,"build"],"iOS simulator build",o,{cwd:e.nativeDirectory,signal:n});let i=S(s,"Build","Products","Debug-iphonesimulator","App.app");if(!await L(i))throw Error(`Xcode did not produce the simulator app at ${i}.`);return i},Ro=async(e,t,r,o)=>{let n=S(e.projectRoot,".absolutejs","mobile","ios-derived-data",ft("sha256").update(e.config.appId).digest("hex").slice(0,16));await G(n,{recursive:!0}),await P([e.xcodebuild,"-workspace",S(e.nativeDirectory,"App","App.xcworkspace"),"-scheme","App","-configuration","Debug","-destination",`platform=iOS,id=${t}`,"-derivedDataPath",n,"-allowProvisioningUpdates","build"],"iOS physical-device build (configure automatic signing and a Development Team in Xcode if this is the first run)",r,{cwd:e.nativeDirectory,signal:o});let s=S(n,"Build","Products","Debug-iphoneos","App.app");if(!await L(s))throw Error(`Xcode did not produce the physical-device app at ${s}.`);return s},No=async(e)=>{if(e.cache?.appId===e.project.config.appId&&e.cache.fingerprint===e.fingerprint&&e.cache.installations[e.identifier]===e.fingerprint&&Do(e.project,e.identifier,e.capture))return e.log("iOS native app is unchanged on the selected physical device; skipped Xcode build and install."),!0;e.log("iOS native inputs changed or the physical-device install is stale; rebuilding."),e.transition("building");let r=await Ro(e.project,e.identifier,e.run,e.signal);return W(e.signal),e.transition("installing"),await P([e.project.xcrun,"devicectl","device","install","app","--device",e.identifier,r],"iOS physical-device app installation",e.run,{signal:e.signal}),await Et(e.project.projectRoot,{appId:e.project.config.appId,fingerprint:e.fingerprint,format:Ie,installations:{...e.cache?.appId===e.project.config.appId?e.cache.installations:{},[e.identifier]:e.fingerprint}}).catch((o)=>e.log(`iOS native cache could not be saved: ${o instanceof Error?o.message:String(o)}`)),!1},Mo=async(e)=>{let t=mt(e.project,e.udid,e.capture);if(e.cache?.appId===e.project.config.appId&&e.cache.fingerprint===e.fingerprint&&t!==void 0&&e.cache.installations[e.udid]===t)return e.log(`iOS native app is unchanged on ${e.udid}; skipped Xcode build and install.`),!0;e.log("iOS native inputs changed or the installed app is stale; rebuilding."),e.transition("building");let o=await Co(e.project,e.udid,e.fingerprint,e.run,e.signal);W(e.signal),e.transition("installing"),await P([e.project.xcrun,"simctl","install",e.udid,o],"iOS simulator app installation",e.run,{signal:e.signal});let n=mt(e.project,e.udid,e.capture);if(n)await Et(e.project.projectRoot,{appId:e.project.config.appId,fingerprint:e.fingerprint,format:Ie,installations:{[e.udid]:n}}).catch((s)=>e.log(`iOS native cache could not be saved: ${s instanceof Error?s.message:String(s)}`));return!1},Lo=/((?:authorization|cookie|password|secret|token|oauth[_-]?code)\s*[:=]\s*)([^\s,;]+)/giu,Uo=new RegExp(String.raw`\bBearer\s+[A-Za-z0-9._~+/-]+=*`,"giu"),$o=/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu,ko=new RegExp(String.raw`\s(Debug|Info|Notice|Error|Fault)\s+.*?\[[^\]]+\]\s+\[([^\]]+)\]\s*(.*)$`,"iu"),jo=(e)=>{let t=Bo(e).trim();if(!t)return null;let r=ko.exec(t),o=r?.[1]?.toLowerCase();return{level:o==="debug"||o==="error"||o==="fault"||o==="notice"?o:"info",message:r?.[3]?.trim()||t,tag:r?.[2]?.trim()||"App"}},Bo=(e)=>e.replaceAll(Uo,"Bearer [REDACTED]").replaceAll($o,"[REDACTED_JWT]").replaceAll(Lo,"$1[REDACTED]").replaceAll(/\p{C}/gu,""),gt=(e,t,r)=>{if(!r.nativeLog)return null;let o=r.startNativeLogs??po,n=r.deviceIdentifier?[e.xcrun,"devicectl","device","process","launch","--console","--terminate-existing","--device",t,e.config.appId]:[e.xcrun,"simctl","spawn",t,"log","stream","--style","compact","--level","debug","--predicate",'process == "App"'];return o(n,{signal:r.signal},(s)=>{let i=jo(s);if(i)r.nativeLog?.(i)})},Ho=[["syncing","Capacitor sync"],["configuring","dev config"],["fingerprinting","fingerprint"],["booting","simulator"],["connecting","device ready"],["enrolling-trust","HTTPS trust"],["checking-native","app check"],["building","Xcode"],["installing","install"],["launching","launch"],["streaming-logs","logs"]],Fo=(e)=>Ho.map(([t,r])=>{let o=e[t];return o===void 0?null:`${r} ${q(o)}`}).filter((t)=>t!==null).join(", "),St=async(e,t)=>{if(se()!=="macos")throw Error("iOS development requires macOS and Xcode.");let r=t.target??"simulator",o=ce(t.projectRoot),n=await et({host:"macos"}),s=n.filter((m)=>m.platform==="ios"&&!(r==="device"&&m.id==="ios.runtime")&&(m.status==="fail"||m.status==="warn"));if(s.length>0)throw Error(`iOS ${r} development is not ready: ${s.map(({label:m})=>m).join(", ")}.`);let i=n.find((m)=>m.id==="ios.xcrun")?.path,l=n.find((m)=>m.id==="ios.xcodebuild")?.path;if(!i||!l)throw Error("Xcode tools disappeared after readiness checks.");let a=S(o,"node_modules",".bin","cap");if(!await L(a))throw Error("Capacitor CLI is not installed. Run absolute mobile init first.");await ot(e,{projectRoot:o}),await G(e.bundleDirectory,{recursive:!0});let c=S(e.bundleDirectory,"index.html");if(!await L(c))await B(c,`<!doctype html><title>AbsoluteJS mobile development</title>
427
+ `);let g=S(e.nativeProjectDirectory,"ios");if(!await L(g)){if(!t.createNativeProject)throw Error("iOS native project has not been created.");if(await(t.run??ht)([a,"add","ios"],{cwd:o})!==0)throw Error("Capacitor iOS project creation failed.")}return{cap:a,config:e,nativeDirectory:g,projectRoot:o,xcodebuild:l,xcrun:i}},Wo=async(e)=>{if(e.transition("connecting"),Po(e.project,e.deviceIdentifier,e.capture),!e.startOptions.https)return{caEnrollmentServer:null,startedSimulator:!1,udid:e.deviceIdentifier};if(!e.startOptions.certificateAuthorityPath)throw Error("Physical iOS HTTPS development requires the AbsoluteJS development CA certificate.");e.transition("enrolling-trust");let r=await(e.startOptions.startCaEnrollmentServer??re)({certificateAuthorityPath:e.startOptions.certificateAuthorityPath,displayHost:e.serverHost});return e.log(`On the iOS device, open ${r.url}, install the AbsoluteJS development CA profile, then enable it under Settings > General > About > Certificate Trust Settings. This public CA endpoint exists only for this dev session.`),{caEnrollmentServer:r,startedSimulator:!1,udid:e.deviceIdentifier}},Go=async(e)=>{e.transition("booting");let t=await _o(e.project,e.capture),{device:r}=t,o=t.created||r.state!=="Booted";return To(e.project,r,e.capture),e.spawn(["open","-a","Simulator","--args","-CurrentDeviceUDID",r.udid]),e.transition("connecting"),await Oo(e.project,r.udid,e.capture,e.sleep,e.startOptions.signal),await P([e.project.xcrun,"simctl","bootstatus",r.udid,"-b"],"iOS simulator boot readiness",e.run,{signal:e.startOptions.signal}),await mo(e.startOptions,r.udid,e.run,e.log),{caEnrollmentServer:null,startedSimulator:o,udid:r.udid}},Oe=async(e)=>{let{project:t}=e,r=e.deviceIdentifier?je(e.deviceIdentifier):void 0,o=r?"device":"simulator",n=r?fe(e.serverHost??""):"localhost",s=e.capture??lo,i=e.run??ht,l=e.sleep??Bun.sleep,a=e.spawn??uo,c=e.log??console.log,g=performance.now(),m=performance.now(),b={},x="syncing",u=(h)=>{if(h===x){e.onStateChange?.(h);return}let C=performance.now(),H=C-m;b[x]=(b[x]??0)+H,e.onPhaseTiming?.({durationMs:H,phase:x,totalMs:C-g}),x=h,m=C,e.onStateChange?.(h)},p=null,f=null,_=async()=>{let h=p;p=null,await h?.close().catch(()=>{return})},A=async(h)=>{if(r&&e.nativeLog){await _(),p=gt(t,h,e);return}await P(ut(t,h,r!==void 0),"iOS app relaunch",i,{signal:e.signal})};try{if(await ie(t.projectRoot),W(e.signal),u("syncing"),await P([t.cap,"sync","ios"],"Capacitor iOS synchronization",i,{cwd:t.projectRoot,signal:e.signal}),u("configuring"),e.embeddedBundle!==!0)await So(t,e.port,e.https===!0,n);W(e.signal);let h=performance.now(),C=Io(t,{includePublicBundle:e.embeddedBundle===!0}).then((M)=>(b.fingerprinting=performance.now()-h,M)),H=r?await Wo({capture:s,deviceIdentifier:r,log:c,project:t,serverHost:n,startOptions:e,transition:u}):await Go({capture:s,log:c,project:t,run:i,sleep:l,spawn:a,startOptions:e,transition:u}),{caEnrollmentServer:Q,startedSimulator:pe,udid:d}=H;f=Q;let w=await C;u("checking-native");let y=await xo(t.projectRoot),T=r?await No({cache:y,capture:s,fingerprint:w,identifier:r,log:c,project:t,run:i,signal:e.signal,transition:u}):await Mo({cache:y,capture:s,fingerprint:w,log:c,project:t,run:i,signal:e.signal,transition:u,udid:d});if(W(e.signal),e.nativeLog)u("streaming-logs");if(p=gt(t,d,e),u("launching"),!r||!p)await P(ut(t,d,r!==void 0),"iOS app launch",i,{signal:e.signal});u("ready"),b.total=performance.now()-g,c(e.embeddedBundle===!0?`iOS ${o} connected with the embedded bundle and backend on port ${e.port} in ${q(b.total)} (${T?"native cache hit":"native build installed"}).`:`iOS ${o} connected with HMR on port ${e.port} in ${q(b.total)} (${T?"native cache hit":"native build installed"}).`),c(`iOS startup: ${Fo(b)}.`);let O=!1,N=async()=>{if(O)return;O=!0,u("closing"),await _(),await f?.close().catch(()=>{return}),f=null,await ie(t.projectRoot),u("closed")};return{close:N,nativeCacheHit:T,startedSimulator:pe,targetKind:o,timings:{...b},udid:d,rebuild:async()=>{if(O)throw Error("iOS development session is closed.");return c("iOS native inputs changed; rebuilding without restarting the dev server."),await N(),Oe(e)},relaunch:async()=>{if(O)throw Error("iOS development session is closed.");u("launching");try{await A(d),u("ready"),c(`iOS app relaunched on the selected ${o}.`)}catch(M){throw u("failed"),M}},screenshot:async(M)=>{if(r)throw Error("Physical iOS screenshots are captured in Xcode Device Hub; the CLI never records a device screen automatically.");let U=ce(t.projectRoot,M);if(!Y(t.projectRoot,U))throw Error("iOS screenshot destination must remain inside the project.");return await G(bt(U),{recursive:!0}),await P([t.xcrun,"simctl","io",d,"screenshot",U],"iOS simulator screenshot",i,{signal:e.signal}),U},get state(){return x}}}catch(h){throw u("failed"),await _(),await f?.close().catch(()=>{return}),await ie(t.projectRoot),h}};var yt="ABSOLUTE_REMOTE_MAC\t",le=2;var E=(e)=>process.stdout.write(`${yt}${JSON.stringify({...e,v:le})}
428
+ `),de=(e)=>e instanceof Error?e.message:String(e),J=(e,t)=>{let r=e.indexOf(t);return r<0?void 0:e[r+1]},Xo=(e)=>{let t=Number(J(e,"--port"));if(!Number.isInteger(t)||t<1||t>65535)throw TypeError("Remote iOS agent requires a valid --port.");return t},Pe=(e,t)=>{let r=J(e,t);if(r===void 0)return;let o=Number(r);if(!Number.isInteger(o)||o<1||o>65535)throw TypeError(`Remote iOS agent requires a valid ${t}.`);return o},qo=(e)=>{let t=J(e,"--mobile-config");if(!t)throw TypeError("Remote iOS agent requires --mobile-config.");let r=JSON.parse(Buffer.from(t,"base64url").toString("utf8"));if(typeof r!=="object"||r===null)throw TypeError("Remote iOS agent received an invalid mobile config.");return r},xt=async(e,t)=>{let r=e.getReader(),o=new TextDecoder,n="";try{while(!0){let{done:s,value:i}=await r.read();if(s)break;n+=o.decode(i,{stream:!0});let l=n.split(/\r?\n/u);n=l.pop()??"",l.forEach(t)}}finally{r.releaseLock()}},De=async(e,t={})=>{let r=Bun.spawn(e,{cwd:t.cwd,env:t.env,signal:t.signal,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return xt(r.stdout,(o)=>E({message:o,type:"log"})),xt(r.stderr,(o)=>E({message:o,type:"log"})),r.exited},Ko=(e,t={})=>{try{let r=Bun.spawnSync(e,{cwd:t.cwd,env:t.env,stderr:"pipe",stdin:"ignore",stdout:"pipe"});return{exitCode:r.exitCode,stderr:r.stderr.toString(),stdout:r.stdout.toString()}}catch(r){return{exitCode:1,stderr:de(r),stdout:""}}},It=(e)=>({engine:"capacitor",nativeCacheHit:e.nativeCacheHit,startedSimulator:e.startedSimulator,targetKind:e.targetKind,timings:e.timings,type:"ready",udid:e.udid}),Yo=async(e)=>{if(e.config.engine!=="expo")throw TypeError("The remote Expo executor requires Expo configuration.");let t=Pe(e.args,"--metro-port");if(t===void 0)throw TypeError("Remote Expo execution requires --metro-port.");let r=Pe(e.args,"--metro-relay-port");if(e.deviceIdentifier&&r===void 0)throw TypeError("Remote physical Expo execution requires --metro-relay-port.");let o=await qe(e.config,{projectRoot:process.cwd()}),n=await Bun.file(ue(o.path,"node_modules","expo","package.json")).exists();if(!n){E({state:"preparing-native",type:"state"});let a=performance.now(),c=await De([process.execPath,"install"],{cwd:o.path});if(c!==0)throw Error(`Remote Expo dependency installation exited with status ${c}.`);E({durationMs:performance.now()-a,phase:"preparing-native",type:"timing"})}let s,i,l;try{s=e.deviceIdentifier?await oe({listenPort:e.port,targetPort:e.relayPort??0}):void 0,i=e.deviceIdentifier?await oe({listenPort:t,targetPort:r??0}):void 0,l=await Be({certificateAuthorityPath:e.certificateAuthorityPath,config:e.config,executable:await Ae(o.path),iosDevice:e.deviceIdentifier,iosOrigin:`${e.args.includes("--https")?"https":"http"}://${e.serverHost??"localhost"}:${e.port}`,metro:"external",metroHost:e.serverHost??"localhost",metroPort:t,platforms:["ios"],log:(c)=>E({message:c,type:"log"}),onPhaseTiming:(c)=>E({...c,type:"timing"}),onStateChange:(c)=>E({state:c,type:"state"})}),E({engine:"expo",nativeCacheHit:n,startedSimulator:!1,targetKind:e.deviceIdentifier?"device":"simulator",timings:l.timings,type:"ready",udid:e.deviceIdentifier??"booted"});let a=_t({input:process.stdin,terminal:!1});try{for await(let c of a){let g;try{if(g=JSON.parse(c),g.v!==le||typeof g.id!=="string"||g.command!=="close")throw Error("Invalid remote Expo request.");await l.close(),E({id:g.id,ok:!0,type:"response"});return}catch(m){E({error:de(m),id:g?.id??"",ok:!1,type:"response"})}}}finally{a.close()}}finally{await l?.close().catch(()=>{return}),await Promise.all([s?.close().catch(()=>{return}),i?.close().catch(()=>{return})])}},Zo=async(e)=>{if(process.platform!=="darwin")throw Error("The AbsoluteJS remote iOS agent can run only on macOS.");let t=process.cwd(),r=Ue(qo(e),t),o=Xo(e),n=J(e,"--ios-device"),s=J(e,"--server-host"),i=Pe(e,"--relay-port");if(n&&(!s||i===void 0))throw TypeError("Remote physical iOS development requires --server-host and --relay-port.");let l=J(e,"--certificate-authority"),a=l?ue(t,".absolutejs","mobile",`remote-dev-ca-${process.pid}.pem`):void 0;if(a&&l)await Jo(ue(t,".absolutejs","mobile"),{recursive:!0}),await zo(a,Buffer.from(l,"base64url"));if(r.engine==="expo"){try{await Yo({args:e,certificateAuthorityPath:a,config:r,deviceIdentifier:n,port:o,relayPort:i,serverHost:s})}finally{if(a)await Te(a,{force:!0})}return}let c=await St(r,{createNativeProject:!1,projectRoot:t,run:De,target:n?"device":"simulator"}),g=n?await oe({listenPort:o,targetPort:i??0}):void 0,m={capture:Ko,certificateAuthorityPath:a,deviceIdentifier:n,https:e.includes("--https"),port:o,project:c,run:De,serverHost:s,log:(u)=>E({message:u,type:"log"}),nativeLog:(u)=>E({entry:u,type:"native-log"}),onPhaseTiming:(u)=>E({...u,type:"timing"}),onStateChange:(u)=>E({state:u,type:"state"}),spawn:(u,p={})=>{Bun.spawn(u,{cwd:p.cwd,env:p.env,signal:p.signal,stderr:"ignore",stdin:"ignore",stdout:"ignore"})}},b;try{b=await Oe(m)}catch(u){if(await g?.close().catch(()=>{return}),a)await Te(a,{force:!0});throw u}E(It(b));let x=_t({input:process.stdin,terminal:!1});try{for await(let u of x){let p;try{if(p=JSON.parse(u),p.v!==le||typeof p.id!=="string")throw Error("Invalid remote Mac request.");let f;if(p.command==="close")await b.close();else if(p.command==="relaunch")await b.relaunch();else if(p.command==="rebuild")b=await b.rebuild(),f=It(b);else if(p.command==="screenshot"){let _=ue(".absolutejs","mobile","remote-screenshot.png"),A=await b.screenshot(_);f={data:(await Vo(A)).toString("base64")}}else throw Error("Unknown remote Mac request.");if(E({id:p.id,ok:!0,result:f,type:"response"}),p.command==="close")return}catch(f){E({error:de(f),id:p?.id??"",ok:!1,type:"response"})}}}finally{if(x.close(),await b.close().catch(()=>{return}),await g?.close().catch(()=>{return}),a)await Te(a,{force:!0})}},Ot=async(e)=>{try{await Zo(e)}catch(t){E({error:de(t),type:"fatal"}),process.exitCode=1}};await Ot(process.argv.slice(2));