@ng-native/desktop 0.0.0-stage → 0.23.0

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 (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +51 -2
  3. package/app.plugin.cjs +17 -0
  4. package/bin/app-config.mjs +168 -0
  5. package/bin/autolink.mjs +224 -0
  6. package/bin/cli.mjs +158 -0
  7. package/bin/host.mjs +427 -0
  8. package/bin/ng-native-desktop.mjs +4 -0
  9. package/bin/package.mjs +971 -0
  10. package/bin/plist.mjs +68 -0
  11. package/bin/prebuilt.mjs +328 -0
  12. package/bin/toolchain.mjs +192 -0
  13. package/native/CMakeLists.txt +276 -0
  14. package/native/appkit/CMakeLists.txt +109 -0
  15. package/native/appkit/address-search.h +26 -0
  16. package/native/appkit/address-search.mm +277 -0
  17. package/native/appkit/animation-frames.h +14 -0
  18. package/native/appkit/animation-frames.mm +106 -0
  19. package/native/appkit/app-info.h +12 -0
  20. package/native/appkit/app-info.mm +98 -0
  21. package/native/appkit/app-updater.mm +128 -0
  22. package/native/appkit/app-windows.h +81 -0
  23. package/native/appkit/app-windows.mm +318 -0
  24. package/native/appkit/appkit-backend.h +73 -0
  25. package/native/appkit/appkit-backend.mm +276 -0
  26. package/native/appkit/apple-authentication.h +19 -0
  27. package/native/appkit/apple-authentication.mm +248 -0
  28. package/native/appkit/apple-button-view.h +10 -0
  29. package/native/appkit/apple-button-view.mm +37 -0
  30. package/native/appkit/apple-id-button.h +16 -0
  31. package/native/appkit/apple-id-button.mm +50 -0
  32. package/native/appkit/audio.h +16 -0
  33. package/native/appkit/audio.mm +275 -0
  34. package/native/appkit/battery.h +13 -0
  35. package/native/appkit/battery.mm +92 -0
  36. package/native/appkit/bookmarks.h +17 -0
  37. package/native/appkit/bookmarks.mm +145 -0
  38. package/native/appkit/calendar.h +25 -0
  39. package/native/appkit/calendar.mm +660 -0
  40. package/native/appkit/camera-view.h +15 -0
  41. package/native/appkit/camera-view.mm +130 -0
  42. package/native/appkit/camera.h +39 -0
  43. package/native/appkit/camera.mm +362 -0
  44. package/native/appkit/cg-canvas.h +17 -0
  45. package/native/appkit/cg-canvas.mm +518 -0
  46. package/native/appkit/component-view.h +17 -0
  47. package/native/appkit/crypto.h +19 -0
  48. package/native/appkit/crypto.mm +78 -0
  49. package/native/appkit/desktop-expo.h +29 -0
  50. package/native/appkit/desktop-expo.mm +385 -0
  51. package/native/appkit/expo-image-drawing.h +46 -0
  52. package/native/appkit/expo-image-drawing.mm +131 -0
  53. package/native/appkit/expo-image-view.h +15 -0
  54. package/native/appkit/expo-image-view.mm +182 -0
  55. package/native/appkit/expo-ui-renderer.h +68 -0
  56. package/native/appkit/expo-ui-renderer.mm +101 -0
  57. package/native/appkit/expo-ui-view.h +26 -0
  58. package/native/appkit/expo-ui-view.mm +134 -0
  59. package/native/appkit/expo-ui.swift +1284 -0
  60. package/native/appkit/file-system.h +16 -0
  61. package/native/appkit/file-system.mm +140 -0
  62. package/native/appkit/fonts.h +12 -0
  63. package/native/appkit/fonts.mm +48 -0
  64. package/native/appkit/geocoder.h +19 -0
  65. package/native/appkit/geocoder.mm +101 -0
  66. package/native/appkit/glass-effect.h +22 -0
  67. package/native/appkit/glass-effect.mm +63 -0
  68. package/native/appkit/glass-view.h +8 -0
  69. package/native/appkit/glass-view.mm +65 -0
  70. package/native/appkit/header-toolbar.h +60 -0
  71. package/native/appkit/header-toolbar.mm +629 -0
  72. package/native/appkit/host-view.h +54 -0
  73. package/native/appkit/host-view.mm +1200 -0
  74. package/native/appkit/image-manipulator.h +14 -0
  75. package/native/appkit/image-manipulator.mm +191 -0
  76. package/native/appkit/image-request.h +22 -0
  77. package/native/appkit/image-request.mm +62 -0
  78. package/native/appkit/image-view.h +8 -0
  79. package/native/appkit/image-view.mm +142 -0
  80. package/native/appkit/input-replay.h +25 -0
  81. package/native/appkit/input-replay.mm +418 -0
  82. package/native/appkit/language-model.h +14 -0
  83. package/native/appkit/language-model.mm +99 -0
  84. package/native/appkit/language-model.swift +472 -0
  85. package/native/appkit/local-authentication.h +15 -0
  86. package/native/appkit/local-authentication.mm +133 -0
  87. package/native/appkit/location.h +16 -0
  88. package/native/appkit/location.mm +214 -0
  89. package/native/appkit/main.mm +1515 -0
  90. package/native/appkit/map-view.h +15 -0
  91. package/native/appkit/map-view.mm +109 -0
  92. package/native/appkit/maps.h +35 -0
  93. package/native/appkit/maps.mm +343 -0
  94. package/native/appkit/menu-bar.h +22 -0
  95. package/native/appkit/menu-bar.mm +208 -0
  96. package/native/appkit/modal-focus.h +16 -0
  97. package/native/appkit/modal-focus.mm +26 -0
  98. package/native/appkit/modal-host-view.h +79 -0
  99. package/native/appkit/modal-host-view.mm +442 -0
  100. package/native/appkit/native-controls.h +22 -0
  101. package/native/appkit/native-controls.mm +431 -0
  102. package/native/appkit/network-state.h +12 -0
  103. package/native/appkit/network-state.mm +64 -0
  104. package/native/appkit/network.h +14 -0
  105. package/native/appkit/network.mm +396 -0
  106. package/native/appkit/notifications.h +19 -0
  107. package/native/appkit/notifications.mm +309 -0
  108. package/native/appkit/photo-library.h +33 -0
  109. package/native/appkit/photo-library.mm +548 -0
  110. package/native/appkit/pointer-buttons.h +32 -0
  111. package/native/appkit/presentation-label.h +15 -0
  112. package/native/appkit/presentation-label.mm +12 -0
  113. package/native/appkit/presented-screen.h +19 -0
  114. package/native/appkit/presented-screen.mm +181 -0
  115. package/native/appkit/printing.h +42 -0
  116. package/native/appkit/printing.mm +393 -0
  117. package/native/appkit/push.h +19 -0
  118. package/native/appkit/push.mm +81 -0
  119. package/native/appkit/red-box.h +26 -0
  120. package/native/appkit/red-box.mm +387 -0
  121. package/native/appkit/screen-capture.h +21 -0
  122. package/native/appkit/screen-capture.mm +92 -0
  123. package/native/appkit/scroll-view.h +13 -0
  124. package/native/appkit/scroll-view.mm +251 -0
  125. package/native/appkit/scrollers.h +25 -0
  126. package/native/appkit/scrollers.mm +43 -0
  127. package/native/appkit/search-field.h +34 -0
  128. package/native/appkit/search-field.mm +291 -0
  129. package/native/appkit/search-toolbar-item.h +19 -0
  130. package/native/appkit/search-toolbar-item.mm +269 -0
  131. package/native/appkit/share-picker.h +34 -0
  132. package/native/appkit/share-picker.mm +121 -0
  133. package/native/appkit/split-view.h +77 -0
  134. package/native/appkit/split-view.mm +1206 -0
  135. package/native/appkit/store-review.h +13 -0
  136. package/native/appkit/store-review.mm +28 -0
  137. package/native/appkit/surface-view.h +45 -0
  138. package/native/appkit/surface-view.mm +558 -0
  139. package/native/appkit/svg-view.h +17 -0
  140. package/native/appkit/svg-view.mm +57 -0
  141. package/native/appkit/symbol-drawing.h +24 -0
  142. package/native/appkit/symbol-drawing.mm +117 -0
  143. package/native/appkit/symbol-view.h +8 -0
  144. package/native/appkit/symbol-view.mm +33 -0
  145. package/native/appkit/system-access.h +34 -0
  146. package/native/appkit/system-access.mm +210 -0
  147. package/native/appkit/system.h +24 -0
  148. package/native/appkit/system.mm +403 -0
  149. package/native/appkit/test-launch.h +36 -0
  150. package/native/appkit/test-launch.mm +115 -0
  151. package/native/appkit/text-input-field.h +76 -0
  152. package/native/appkit/text-input-field.mm +444 -0
  153. package/native/appkit/text-layout.h +58 -0
  154. package/native/appkit/text-layout.mm +477 -0
  155. package/native/appkit/text-recognition.h +13 -0
  156. package/native/appkit/text-recognition.mm +102 -0
  157. package/native/appkit/tracking.h +13 -0
  158. package/native/appkit/tracking.mm +51 -0
  159. package/native/appkit/tray-and-dock.h +45 -0
  160. package/native/appkit/tray-and-dock.mm +130 -0
  161. package/native/appkit/undo.h +23 -0
  162. package/native/appkit/undo.mm +125 -0
  163. package/native/appkit/updates.h +17 -0
  164. package/native/appkit/updates.mm +71 -0
  165. package/native/appkit/video-view.h +10 -0
  166. package/native/appkit/video-view.mm +42 -0
  167. package/native/appkit/video.h +38 -0
  168. package/native/appkit/video.mm +404 -0
  169. package/native/appkit/web-browser.h +12 -0
  170. package/native/appkit/web-browser.mm +97 -0
  171. package/native/appkit/web-view-component.h +9 -0
  172. package/native/appkit/web-view-component.mm +56 -0
  173. package/native/appkit/web-view.h +31 -0
  174. package/native/appkit/web-view.mm +394 -0
  175. package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
  176. package/native/cmake/libraries/react-native-worklets.cmake +46 -0
  177. package/native/cmake/libraries.cmake +109 -0
  178. package/native/cmake/linked-modules.cmake +112 -0
  179. package/native/cmake/react-native.cmake +175 -0
  180. package/native/cmake/runtime-dependencies.cmake +34 -0
  181. package/native/cmake/swift.cmake +43 -0
  182. package/native/cmake/third-party.cmake +74 -0
  183. package/native/core/include/ngn/absent-views.h +27 -0
  184. package/native/core/include/ngn/accessibility.h +140 -0
  185. package/native/core/include/ngn/address-search.h +69 -0
  186. package/native/core/include/ngn/animation-frames.h +39 -0
  187. package/native/core/include/ngn/app-info.h +52 -0
  188. package/native/core/include/ngn/app-menus.h +146 -0
  189. package/native/core/include/ngn/app-windows.h +181 -0
  190. package/native/core/include/ngn/apple-authentication.h +116 -0
  191. package/native/core/include/ngn/asset.h +28 -0
  192. package/native/core/include/ngn/audio.h +125 -0
  193. package/native/core/include/ngn/back-swipe.h +112 -0
  194. package/native/core/include/ngn/battery.h +48 -0
  195. package/native/core/include/ngn/bytes.h +59 -0
  196. package/native/core/include/ngn/calendar.h +180 -0
  197. package/native/core/include/ngn/camera.h +128 -0
  198. package/native/core/include/ngn/control-sizes.h +111 -0
  199. package/native/core/include/ngn/core-modules.h +105 -0
  200. package/native/core/include/ngn/crypto.h +38 -0
  201. package/native/core/include/ngn/default-menu.h +91 -0
  202. package/native/core/include/ngn/desktop-expo.h +193 -0
  203. package/native/core/include/ngn/desktop-modal.h +109 -0
  204. package/native/core/include/ngn/desktop-props.h +75 -0
  205. package/native/core/include/ngn/desktop-view-props.h +110 -0
  206. package/native/core/include/ngn/dev-server.h +33 -0
  207. package/native/core/include/ngn/download.h +24 -0
  208. package/native/core/include/ngn/expo-image.h +192 -0
  209. package/native/core/include/ngn/expo-ui.h +133 -0
  210. package/native/core/include/ngn/file-system.h +274 -0
  211. package/native/core/include/ngn/focus-order.h +63 -0
  212. package/native/core/include/ngn/fonts.h +64 -0
  213. package/native/core/include/ngn/gestures.h +305 -0
  214. package/native/core/include/ngn/glass.h +67 -0
  215. package/native/core/include/ngn/header-bar.h +112 -0
  216. package/native/core/include/ngn/host-state.h +243 -0
  217. package/native/core/include/ngn/image-manipulator.h +70 -0
  218. package/native/core/include/ngn/input-dispatcher.h +211 -0
  219. package/native/core/include/ngn/input-script.h +56 -0
  220. package/native/core/include/ngn/input.h +112 -0
  221. package/native/core/include/ngn/key-value-store.h +41 -0
  222. package/native/core/include/ngn/language-model.h +69 -0
  223. package/native/core/include/ngn/launch-frame.h +47 -0
  224. package/native/core/include/ngn/launch-settings.h +98 -0
  225. package/native/core/include/ngn/layout-animations.h +24 -0
  226. package/native/core/include/ngn/library-components.h +13 -0
  227. package/native/core/include/ngn/library-glue.h +53 -0
  228. package/native/core/include/ngn/live-regions.h +54 -0
  229. package/native/core/include/ngn/local-authentication.h +74 -0
  230. package/native/core/include/ngn/location.h +89 -0
  231. package/native/core/include/ngn/maps.h +226 -0
  232. package/native/core/include/ngn/module-registry.h +51 -0
  233. package/native/core/include/ngn/mounting-backend.h +96 -0
  234. package/native/core/include/ngn/mounting-manager.h +155 -0
  235. package/native/core/include/ngn/native-controls.h +161 -0
  236. package/native/core/include/ngn/native-module.h +109 -0
  237. package/native/core/include/ngn/network-state.h +44 -0
  238. package/native/core/include/ngn/network.h +100 -0
  239. package/native/core/include/ngn/notifications.h +185 -0
  240. package/native/core/include/ngn/photo-library.h +130 -0
  241. package/native/core/include/ngn/printing.h +69 -0
  242. package/native/core/include/ngn/processes.h +114 -0
  243. package/native/core/include/ngn/red-box.h +119 -0
  244. package/native/core/include/ngn/reload-thread.h +258 -0
  245. package/native/core/include/ngn/runtime.h +161 -0
  246. package/native/core/include/ngn/safe-areas.h +77 -0
  247. package/native/core/include/ngn/screen-capture.h +35 -0
  248. package/native/core/include/ngn/screen-presentation.h +85 -0
  249. package/native/core/include/ngn/screen-stacks.h +80 -0
  250. package/native/core/include/ngn/scrollers.h +106 -0
  251. package/native/core/include/ngn/sharing.h +39 -0
  252. package/native/core/include/ngn/spawn-rules.h +78 -0
  253. package/native/core/include/ngn/splash-screen.h +41 -0
  254. package/native/core/include/ngn/split-view.h +270 -0
  255. package/native/core/include/ngn/sqlite.h +38 -0
  256. package/native/core/include/ngn/store-review.h +26 -0
  257. package/native/core/include/ngn/surface-book.h +101 -0
  258. package/native/core/include/ngn/svg.h +393 -0
  259. package/native/core/include/ngn/symbol.h +90 -0
  260. package/native/core/include/ngn/system.h +102 -0
  261. package/native/core/include/ngn/tabs-host.h +171 -0
  262. package/native/core/include/ngn/text-input.h +125 -0
  263. package/native/core/include/ngn/text-measurer.h +38 -0
  264. package/native/core/include/ngn/text-recognition.h +55 -0
  265. package/native/core/include/ngn/tracking.h +34 -0
  266. package/native/core/include/ngn/tray-and-dock.h +107 -0
  267. package/native/core/include/ngn/undo.h +37 -0
  268. package/native/core/include/ngn/updates.h +253 -0
  269. package/native/core/include/ngn/video.h +126 -0
  270. package/native/core/include/ngn/view-box.h +126 -0
  271. package/native/core/include/ngn/view-transform.h +26 -0
  272. package/native/core/include/ngn/view-tree.h +85 -0
  273. package/native/core/include/ngn/web-browser.h +45 -0
  274. package/native/core/include/ngn/web-view.h +133 -0
  275. package/native/core/include/ngn/worklet-host.h +98 -0
  276. package/native/core/src/absent-views.cpp +41 -0
  277. package/native/core/src/accessibility.cpp +374 -0
  278. package/native/core/src/animation-frames.cpp +49 -0
  279. package/native/core/src/app-menus.cpp +352 -0
  280. package/native/core/src/app-windows.cpp +444 -0
  281. package/native/core/src/back-swipe.cpp +91 -0
  282. package/native/core/src/bytes.cpp +158 -0
  283. package/native/core/src/control-sizes.cpp +232 -0
  284. package/native/core/src/default-menu.cpp +96 -0
  285. package/native/core/src/desktop-modal.cpp +162 -0
  286. package/native/core/src/desktop-view-props.cpp +80 -0
  287. package/native/core/src/dev-server-helper.cpp +152 -0
  288. package/native/core/src/dev-server.cpp +103 -0
  289. package/native/core/src/download.cpp +53 -0
  290. package/native/core/src/expo-image.cpp +548 -0
  291. package/native/core/src/expo-ui.cpp +203 -0
  292. package/native/core/src/focus-order.cpp +441 -0
  293. package/native/core/src/gestures.cpp +1806 -0
  294. package/native/core/src/glass.cpp +49 -0
  295. package/native/core/src/header-bar.cpp +104 -0
  296. package/native/core/src/host-services.cpp +50 -0
  297. package/native/core/src/host-state.cpp +61 -0
  298. package/native/core/src/input-dispatcher.cpp +727 -0
  299. package/native/core/src/input-script.cpp +123 -0
  300. package/native/core/src/key-value-store.cpp +169 -0
  301. package/native/core/src/launch-settings.cpp +148 -0
  302. package/native/core/src/layout-animations.cpp +62 -0
  303. package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
  304. package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
  305. package/native/core/src/libraries/react-native-worklets.cpp +192 -0
  306. package/native/core/src/libraries/rnscreens.cpp +125 -0
  307. package/native/core/src/libraries/rnsvg.cpp +345 -0
  308. package/native/core/src/libraries/safeareacontext.cpp +70 -0
  309. package/native/core/src/libraries/worklets-idle-frames.js +70 -0
  310. package/native/core/src/library-glue.cpp +35 -0
  311. package/native/core/src/live-regions.cpp +122 -0
  312. package/native/core/src/module-registry.cpp +50 -0
  313. package/native/core/src/modules/accessibility-manager.cpp +98 -0
  314. package/native/core/src/modules/address-search.cpp +219 -0
  315. package/native/core/src/modules/alert-manager.cpp +140 -0
  316. package/native/core/src/modules/app-info.cpp +74 -0
  317. package/native/core/src/modules/app-modules.cpp +405 -0
  318. package/native/core/src/modules/apple-authentication.cpp +188 -0
  319. package/native/core/src/modules/asset.cpp +111 -0
  320. package/native/core/src/modules/async-storage.cpp +192 -0
  321. package/native/core/src/modules/audio.cpp +541 -0
  322. package/native/core/src/modules/battery.cpp +88 -0
  323. package/native/core/src/modules/calendar.cpp +457 -0
  324. package/native/core/src/modules/camera.cpp +221 -0
  325. package/native/core/src/modules/core-modules.cpp +62 -0
  326. package/native/core/src/modules/crypto.cpp +117 -0
  327. package/native/core/src/modules/desktop-expo.cpp +527 -0
  328. package/native/core/src/modules/file-system.cpp +941 -0
  329. package/native/core/src/modules/fonts.cpp +163 -0
  330. package/native/core/src/modules/image-loader.cpp +105 -0
  331. package/native/core/src/modules/image-manipulator.cpp +305 -0
  332. package/native/core/src/modules/language-model.cpp +195 -0
  333. package/native/core/src/modules/local-authentication.cpp +140 -0
  334. package/native/core/src/modules/location.cpp +186 -0
  335. package/native/core/src/modules/maps.cpp +500 -0
  336. package/native/core/src/modules/network-state.cpp +72 -0
  337. package/native/core/src/modules/networking.cpp +387 -0
  338. package/native/core/src/modules/notifications.cpp +549 -0
  339. package/native/core/src/modules/photo-library.cpp +371 -0
  340. package/native/core/src/modules/printing.cpp +201 -0
  341. package/native/core/src/modules/screen-capture.cpp +71 -0
  342. package/native/core/src/modules/sharing.cpp +59 -0
  343. package/native/core/src/modules/splash-screen.cpp +70 -0
  344. package/native/core/src/modules/sqlite.cpp +421 -0
  345. package/native/core/src/modules/store-review.cpp +23 -0
  346. package/native/core/src/modules/text-recognition.cpp +107 -0
  347. package/native/core/src/modules/tracking.cpp +46 -0
  348. package/native/core/src/modules/undo.cpp +59 -0
  349. package/native/core/src/modules/video.cpp +366 -0
  350. package/native/core/src/modules/web-browser.cpp +100 -0
  351. package/native/core/src/modules/web-socket.cpp +266 -0
  352. package/native/core/src/mounting-manager.cpp +380 -0
  353. package/native/core/src/native-controls.cpp +129 -0
  354. package/native/core/src/native-module.cpp +250 -0
  355. package/native/core/src/network.cpp +219 -0
  356. package/native/core/src/posix-launcher.cpp +366 -0
  357. package/native/core/src/processes.cpp +324 -0
  358. package/native/core/src/red-box-errors.js +83 -0
  359. package/native/core/src/red-box.cpp +306 -0
  360. package/native/core/src/runtime.cpp +422 -0
  361. package/native/core/src/safe-areas.cpp +130 -0
  362. package/native/core/src/screen-presentation.cpp +61 -0
  363. package/native/core/src/screen-stacks.cpp +254 -0
  364. package/native/core/src/scrollers.cpp +181 -0
  365. package/native/core/src/spawn-rules.cpp +292 -0
  366. package/native/core/src/split-view.cpp +343 -0
  367. package/native/core/src/svg.cpp +1883 -0
  368. package/native/core/src/symbol.cpp +94 -0
  369. package/native/core/src/tabs-host.cpp +234 -0
  370. package/native/core/src/text-input.cpp +126 -0
  371. package/native/core/src/text-layout-manager.cpp +63 -0
  372. package/native/core/src/tray-and-dock.cpp +154 -0
  373. package/native/core/src/updates.cpp +965 -0
  374. package/native/core/src/view-box.cpp +788 -0
  375. package/native/core/src/view-transform.cpp +45 -0
  376. package/native/core/src/view-tree.cpp +234 -0
  377. package/native/core/src/web-view.cpp +143 -0
  378. package/native/core/src/worklet-host.cpp +10 -0
  379. package/native/scripts/build-hermes.sh +44 -0
  380. package/native/scripts/build.sh +171 -0
  381. package/native/scripts/cache-dir.sh +18 -0
  382. package/native/scripts/codegen-library.sh +193 -0
  383. package/native/scripts/compiler-launcher.sh +17 -0
  384. package/native/scripts/fetch.sh +174 -0
  385. package/native/scripts/hermes-built.sh +10 -0
  386. package/native/scripts/host-dir.sh +16 -0
  387. package/native/scripts/macos-target.sh +8 -0
  388. package/native/scripts/make-prebuilt.mjs +360 -0
  389. package/native/scripts/prebuilt-host-cache.mjs +158 -0
  390. package/native/shim/openssl/sha.h +22 -0
  391. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
  392. package/package.json +70 -3
  393. package/prebuilt.json +33 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ashley Hunter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,52 @@
1
- # Temporary Holding Version
1
+ # @ng-native/desktop
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The macOS desktop host for Angular Native: React Native's C++ core and Hermes, mounting an app's
4
+ views into AppKit, and the `ng-native-desktop` command that builds and launches it. You install the
5
+ package and never import it.
6
+
7
+ Alpha: APIs may change before 1.0.
8
+
9
+ ## Install
10
+
11
+ Most Mac apps start from `npx create-expo-app@latest my-app --template @ng-native/template-desktop`.
12
+ To add macOS to an app you have:
13
+
14
+ ```sh
15
+ npx expo install @ng-native/desktop
16
+ ```
17
+
18
+ Then list `macos` in `expo.platforms`, set `expo.experiments.outOfTreePlatforms` to `true` and add
19
+ `@ng-native/desktop` to `expo.plugins`. [Setup](https://ng-native.com/packages/desktop#setup) has
20
+ the details, and the Nx and Angular CLI generators that do it for you.
21
+
22
+ ## Commands
23
+
24
+ ```sh
25
+ npm start # the Expo CLI's dev server, in one terminal
26
+ npx ng-native-desktop run # builds the host the first time, then opens the app
27
+ npx ng-native-desktop package # dist/macos/<name>.app; --format dmg or mas to ship it
28
+ ```
29
+
30
+ The first run for a React Native version builds the host from source, which needs Xcode 16 or its
31
+ Command Line Tools, CMake and Ninja, unless the package has a prebuilt host for that version and
32
+ the app has no native desktop code of its own: `run` downloads the debug host, with React Native's
33
+ debugger, and `package` the release one.
34
+
35
+ ## Docs
36
+
37
+ - [Build for the Mac](https://ng-native.com/guide/desktop), the guide, and
38
+ [what differs](https://ng-native.com/guide/desktop-differences) from iOS and Android
39
+ - [Desktop](https://ng-native.com/packages/desktop): setup, running, packaging, config and native
40
+ code
41
+ - [Views and controls](https://ng-native.com/packages/desktop/views),
42
+ [windows, menus and the Dock](https://ng-native.com/packages/desktop/windows-and-menus) and
43
+ [focus and accessibility](https://ng-native.com/packages/desktop/accessibility)
44
+ - [Expo modules on macOS](https://ng-native.com/packages/desktop/expo-modules)
45
+ - [Debugging and launch settings](https://ng-native.com/packages/desktop/development)
46
+ - [Inside a package](https://ng-native.com/packages/desktop/packaging)
47
+ - [The desktop host](https://github.com/ng-native/ng-native/blob/main/docs/desktop-host.md): the
48
+ source layout and publishing a prebuilt host, for contributors
49
+
50
+ ## License
51
+
52
+ MIT
package/app.plugin.cjs ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `"plugins": [["@ng-native/desktop", { ... }]]` in app.json: the options of the macOS build that
3
+ * have no Expo key (document types, capabilities and the deny-list). Expo runs a plugin whenever
4
+ * it reads the config, so a mistake in the options stops `expo start`, `expo export` and
5
+ * `ng-native-desktop` with every problem listed, rather than turning into a capability the app
6
+ * quietly lacks.
7
+ *
8
+ * It changes nothing in the config: the desktop host is not a native project prebuild writes, and
9
+ * `ng-native-desktop` reads these options and the Expo keys it shares with iOS (`bin/app-config.mjs`)
10
+ * when it builds.
11
+ */
12
+ const { validateDesktopOptions } = require('@ng-native/device/desktop-options');
13
+
14
+ module.exports = function withNgNativeDesktop(config, options) {
15
+ validateDesktopOptions(options);
16
+ return config;
17
+ };
@@ -0,0 +1,168 @@
1
+ /**
2
+ * What the desktop build reads from an app's Expo config. Settings Expo already has a key for come
3
+ * from that key, the same one the iOS build reads: the bundle identifier, the URL schemes, the
4
+ * icon, the version, the updates URL and the usage strings. The `@ng-native/desktop` plugin options
5
+ * hold only what has no Expo key: document types, capabilities and the deny-list.
6
+ *
7
+ * The config plugin (`app.plugin.cjs`) and the `ng-native-desktop` command both read options
8
+ * through here, so an option the plugin accepts is one the command can build.
9
+ */
10
+ import { macosPermissions, validateDesktopOptions } from '@ng-native/device/desktop-options';
11
+
12
+ /** The name the plugin is listed under in `expo.plugins`. */
13
+ export const PLUGIN_NAME = '@ng-native/desktop';
14
+
15
+ /**
16
+ * @typedef {import('@ng-native/device/desktop-options').DesktopOptions} DesktopOptions
17
+ * @typedef {import('@ng-native/device/desktop-options').MacosPermissions} MacosPermissions
18
+ *
19
+ * @typedef {{
20
+ * name?: string,
21
+ * slug?: string,
22
+ * version?: string,
23
+ * scheme?: string | string[],
24
+ * icon?: string,
25
+ * runtimeVersion?: unknown,
26
+ * platforms?: string[],
27
+ * experiments?: { outOfTreePlatforms?: boolean },
28
+ * updates?: {
29
+ * url?: string,
30
+ * enabled?: boolean,
31
+ * codeSigningCertificate?: string,
32
+ * codeSigningMetadata?: { keyid?: string, alg?: string },
33
+ * },
34
+ * ios?: {
35
+ * bundleIdentifier?: string,
36
+ * buildNumber?: string,
37
+ * scheme?: string | string[],
38
+ * icon?: string | { light?: string, dark?: string, tinted?: string },
39
+ * infoPlist?: Record<string, unknown>,
40
+ * usesAppleSignIn?: boolean,
41
+ * entitlements?: Record<string, unknown>,
42
+ * },
43
+ * plugins?: unknown[],
44
+ * }} ExpoConfig
45
+ *
46
+ * @typedef {{
47
+ * name: string,
48
+ * version: string,
49
+ * buildNumber: string,
50
+ * bundleIdentifier: string | null,
51
+ * schemes: string[],
52
+ * icon: string | null,
53
+ * updatesUrl: string | null,
54
+ * updatesCodeSigning: { certificate: string, keyId: string, alg: string } | null,
55
+ * runtimeVersion: string | null,
56
+ * permissions: MacosPermissions,
57
+ * options: DesktopOptions,
58
+ * }} DesktopAppConfig
59
+ */
60
+
61
+ /**
62
+ * The plugin's options as `expo.plugins` lists them, or undefined when the plugin is listed bare
63
+ * or not at all.
64
+ *
65
+ * @param {ExpoConfig} config
66
+ * @returns {unknown}
67
+ */
68
+ export function pluginOptions(config) {
69
+ for (const entry of config.plugins ?? []) {
70
+ if (Array.isArray(entry) && entry[0] === PLUGIN_NAME) return entry[1];
71
+ }
72
+ return undefined;
73
+ }
74
+
75
+ /**
76
+ * The capabilities in the plugin options as the host reads them, from a packaged app's
77
+ * `NGNCapabilities` or the dev command's `--capabilities`: each path's access spelled out. Undefined
78
+ * where the options give none.
79
+ *
80
+ * @param {DesktopOptions} options
81
+ */
82
+ export function hostCapabilities(options) {
83
+ const capabilities = options.capabilities;
84
+ if (!capabilities) return undefined;
85
+ return {
86
+ spawn: capabilities.spawn?.map((rule) => ({
87
+ program: rule.program,
88
+ args: rule.args ? [...rule.args] : undefined,
89
+ })),
90
+ env: capabilities.env ? [...capabilities.env] : undefined,
91
+ paths: capabilities.paths?.map((entry) => ({
92
+ path: entry.path,
93
+ access: entry.access ?? 'read',
94
+ })),
95
+ };
96
+ }
97
+
98
+ /**
99
+ * The desktop build's settings for an app, from its resolved Expo config. Throws, listing every
100
+ * problem, when the plugin options are not valid.
101
+ *
102
+ * - `bundleIdentifier` is `ios.bundleIdentifier`: macOS and iOS share Apple's identifier, and a
103
+ * universal purchase needs them to be the same. Null when the app sets none.
104
+ * - `schemes` are `scheme` and `ios.scheme`, which deep links open the app by.
105
+ * - `icon` is `ios.icon` (an Icon Composer `.icon` folder or an image, its light variant when it
106
+ * has variants), else `icon`.
107
+ * - `updatesUrl` is `updates.url`, the bundle server, unless updates are turned off.
108
+ * - `updatesCodeSigning` is `updates.codeSigningCertificate`, the PEM file's path from the project,
109
+ * with `codeSigningMetadata`'s key id and algorithm, defaulting as expo-updates does to `main`
110
+ * and `rsa-v1_5-sha256`. Null without a certificate, or with updates turned off.
111
+ *
112
+ * @param {ExpoConfig} config
113
+ * @returns {DesktopAppConfig}
114
+ */
115
+ export function desktopAppConfig(config) {
116
+ const options = validateDesktopOptions(pluginOptions(config));
117
+ const ios = config.ios ?? {};
118
+ const version = config.version ?? '1.0.0';
119
+ return {
120
+ name: config.name ?? config.slug ?? 'ng-native',
121
+ version,
122
+ buildNumber: ios.buildNumber ?? version,
123
+ bundleIdentifier: ios.bundleIdentifier ?? null,
124
+ schemes: schemes(config),
125
+ icon: iosIcon(ios.icon) ?? config.icon ?? null,
126
+ updatesUrl: updatesUrl(config.updates),
127
+ updatesCodeSigning: updatesCodeSigning(config.updates),
128
+ runtimeVersion: typeof config.runtimeVersion === 'string' ? config.runtimeVersion : null,
129
+ permissions: macosPermissions(config),
130
+ options,
131
+ };
132
+ }
133
+
134
+ /**
135
+ * @param {ExpoConfig} config
136
+ * @returns {string[]}
137
+ */
138
+ function schemes(config) {
139
+ const all = [config.scheme, config.ios?.scheme].flat();
140
+ /** @param {unknown} scheme @returns {scheme is string} */
141
+ const named = (scheme) => typeof scheme === 'string' && scheme !== '';
142
+ return [...new Set(all.filter(named))];
143
+ }
144
+
145
+ /** @param {NonNullable<ExpoConfig['ios']>['icon']} icon */
146
+ function iosIcon(icon) {
147
+ if (typeof icon === 'string') return icon;
148
+ return icon?.light ?? null;
149
+ }
150
+
151
+ /** @param {ExpoConfig['updates']} updates */
152
+ function updatesUrl(updates) {
153
+ return updates?.enabled === false ? null : (updates?.url ?? null);
154
+ }
155
+
156
+ /** @param {ExpoConfig['updates']} updates */
157
+ function updatesCodeSigning(updates) {
158
+ const certificate = updates?.codeSigningCertificate;
159
+ if (updates?.enabled === false || typeof certificate !== 'string' || certificate === '') {
160
+ return null;
161
+ }
162
+ const metadata = updates?.codeSigningMetadata ?? {};
163
+ return {
164
+ certificate,
165
+ keyId: metadata.keyid ?? 'main',
166
+ alg: metadata.alg ?? 'rsa-v1_5-sha256',
167
+ };
168
+ }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Autolinking for the desktop build: which native code the host compiles in, found the way Expo's
3
+ * autolinking finds a library's iOS and Android code.
4
+ *
5
+ * - A library opts in through its `expo-module.config.json`: `macos` among its `platforms`, and a
6
+ * `macos` entry naming the CMake target its desktop code builds and the folder that holds its
7
+ * CMake fragment (`desktop` unless it says otherwise):
8
+ *
9
+ * { "platforms": ["apple", "android", "macos"],
10
+ * "macos": { "cmakeTarget": "haptics_desktop", "cmakeDir": "desktop" } }
11
+ *
12
+ * - The app's own modules are each `modules/<name>/macos/`, beside `ios/` and `android/`, compiled
13
+ * in with nothing to register. The module's `expo-module.config.json` may name its CMake target.
14
+ * - A package in the plugin options' `deny` list stays out, whatever it ships; the packages it
15
+ * depends on are still walked.
16
+ * - A dependency with native code and none for the desktop is listed, so `run` and `package` can
17
+ * say its native modules are absent on macOS.
18
+ *
19
+ * Plain Node with no dependencies, so it runs before anything is built.
20
+ */
21
+ import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
22
+ import path from 'node:path';
23
+
24
+ /**
25
+ * Packages whose native side is answered another way on macOS, so they are neither linked nor
26
+ * reported: React Native and React themselves, Expo (`expo` and `expo-*` resolve to empty modules
27
+ * there, and the host's own modules answer the services that use them) and this framework.
28
+ *
29
+ * @param {string} name
30
+ */
31
+ function suppliedOtherwise(name) {
32
+ return (
33
+ name === 'react' ||
34
+ name === 'react-native' ||
35
+ name === 'expo' ||
36
+ name.startsWith('expo-') ||
37
+ name.startsWith('@expo/') ||
38
+ name.startsWith('@ng-native/') ||
39
+ name.startsWith('@react-native/')
40
+ );
41
+ }
42
+
43
+ /**
44
+ * @typedef {{ name: string, dir: string, cmakeTarget: string, cmakeDir: string }} DesktopLibrary
45
+ * @typedef {{ name: string, dir: string, cmakeTarget: string | null }} AppModule
46
+ * @typedef {{
47
+ * libraries: DesktopLibrary[],
48
+ * appModules: AppModule[],
49
+ * hostLibraries: { name: string, dir: string }[],
50
+ * withoutDesktop: string[],
51
+ * problems: string[],
52
+ * }} DesktopLinks
53
+ */
54
+
55
+ /**
56
+ * The desktop code an app's build compiles in, and the dependencies with native code that have
57
+ * none. Walks the app's `dependencies` and theirs, as Expo's autolinking does, each package once.
58
+ *
59
+ * @param {string} appDir
60
+ * @param {{ deny?: readonly string[], builtIn?: readonly string[] }} [options] `builtIn` are the
61
+ * libraries the host compiles in itself, which are neither linked nor reported: `hostLibraries`
62
+ * says where each one the walk finds is installed, under a dependency's node_modules too
63
+ * @returns {DesktopLinks}
64
+ */
65
+ export function desktopLinks(appDir, { deny = [], builtIn = [] } = {}) {
66
+ /** @type {DesktopLinks} */
67
+ const links = {
68
+ libraries: [],
69
+ appModules: appModules(appDir),
70
+ hostLibraries: [],
71
+ withoutDesktop: [],
72
+ problems: [],
73
+ };
74
+ const seen = new Set();
75
+ // Breadth first, so a package nearer the app wins: the app's own version of a library is the
76
+ // one taken, not an older copy nested under a dependency listed before it.
77
+ const queue = [appDir];
78
+ for (let from = queue.shift(); from !== undefined; from = queue.shift()) {
79
+ for (const name of dependencyNames(from)) {
80
+ if (seen.has(name) || suppliedOtherwise(name)) continue;
81
+ seen.add(name);
82
+ const dir = packageDir(from, name);
83
+ if (dir === null) continue;
84
+ // A denied package stays out of the build and the warning, but what it depends on does not.
85
+ if (deny.includes(name)) {
86
+ // Neither linked nor reported.
87
+ } else if (builtIn.includes(name)) links.hostLibraries.push({ name, dir });
88
+ else classify(links, name, dir);
89
+ queue.push(dir);
90
+ }
91
+ }
92
+ links.libraries.sort((a, b) => a.name.localeCompare(b.name));
93
+ links.hostLibraries.sort((a, b) => builtIn.indexOf(a.name) - builtIn.indexOf(b.name));
94
+ links.withoutDesktop.sort();
95
+ return links;
96
+ }
97
+
98
+ /**
99
+ * @param {DesktopLinks} links
100
+ * @param {string} name
101
+ * @param {string} dir
102
+ */
103
+ function classify(links, name, dir) {
104
+ const config = readJson(path.join(dir, 'expo-module.config.json'));
105
+ const macos = config?.platforms?.includes('macos') ? config.macos : undefined;
106
+ if (macos === undefined) {
107
+ if (hasNativeCode(dir, config)) links.withoutDesktop.push(name);
108
+ return;
109
+ }
110
+ if (typeof macos?.cmakeTarget !== 'string' || macos.cmakeTarget === '') {
111
+ links.problems.push(
112
+ `${name} lists macos in expo-module.config.json without a macos.cmakeTarget, so it is left out.`,
113
+ );
114
+ return;
115
+ }
116
+ const cmakeDir = path.join(dir, typeof macos.cmakeDir === 'string' ? macos.cmakeDir : 'desktop');
117
+ if (!existsSync(path.join(cmakeDir, 'CMakeLists.txt'))) {
118
+ links.problems.push(
119
+ `${name} names ${path.relative(dir, cmakeDir)}/CMakeLists.txt for macos, which it does not have, so it is left out.`,
120
+ );
121
+ return;
122
+ }
123
+ links.libraries.push({ name, dir, cmakeTarget: macos.cmakeTarget, cmakeDir });
124
+ }
125
+
126
+ /**
127
+ * The app's own modules: each `modules/<name>/macos/` folder.
128
+ *
129
+ * @param {string} appDir
130
+ * @returns {AppModule[]}
131
+ */
132
+ function appModules(appDir) {
133
+ const root = path.join(appDir, 'modules');
134
+ if (!isDirectory(root)) return [];
135
+ return readdirSync(root)
136
+ .sort()
137
+ .filter((name) => isDirectory(path.join(root, name, 'macos')))
138
+ .map((name) => {
139
+ const config = readJson(path.join(root, name, 'expo-module.config.json'));
140
+ const target = config?.macos?.cmakeTarget;
141
+ return {
142
+ name,
143
+ dir: path.join(root, name, 'macos'),
144
+ cmakeTarget: typeof target === 'string' && target !== '' ? target : null,
145
+ };
146
+ });
147
+ }
148
+
149
+ /**
150
+ * Whether a package ships native code for a phone: an Expo module for iOS or Android, a React
151
+ * Native codegen spec, a podspec, or an `ios` or `android` folder.
152
+ *
153
+ * @param {string} dir
154
+ * @param {{ platforms?: string[] } | null} config its expo-module.config.json
155
+ */
156
+ function hasNativeCode(dir, config) {
157
+ if (config?.platforms?.some((platform) => ['apple', 'ios', 'android'].includes(platform))) {
158
+ return true;
159
+ }
160
+ if (readJson(path.join(dir, 'package.json'))?.codegenConfig) return true;
161
+ if (isDirectory(path.join(dir, 'ios')) || isDirectory(path.join(dir, 'android'))) return true;
162
+ return readdirSync(dir).some((file) => file.endsWith('.podspec'));
163
+ }
164
+
165
+ /** @param {string} dir */
166
+ function dependencyNames(dir) {
167
+ return Object.keys(readJson(path.join(dir, 'package.json'))?.dependencies ?? {});
168
+ }
169
+
170
+ /**
171
+ * A package's directory as Node finds it from `from`, or null when it is not installed: the first
172
+ * `node_modules/<name>` up the tree, with symlinks resolved. Looked up directly rather than through
173
+ * `require.resolve('<name>/package.json')`, which throws for a package whose `exports` leave
174
+ * package.json out.
175
+ *
176
+ * @param {string} from
177
+ * @param {string} name
178
+ */
179
+ function packageDir(from, name) {
180
+ for (let dir = from; ; dir = path.dirname(dir)) {
181
+ if (path.basename(dir) !== 'node_modules') {
182
+ const candidate = path.join(dir, 'node_modules', name);
183
+ if (existsSync(path.join(candidate, 'package.json'))) return realpathSync(candidate);
184
+ }
185
+ if (path.dirname(dir) === dir) return null;
186
+ }
187
+ }
188
+
189
+ /** @param {string} file @returns {any} */
190
+ function readJson(file) {
191
+ try {
192
+ return JSON.parse(readFileSync(file, 'utf8'));
193
+ } catch {
194
+ return null;
195
+ }
196
+ }
197
+
198
+ /** @param {string} dir */
199
+ function isDirectory(dir) {
200
+ try {
201
+ return statSync(dir).isDirectory();
202
+ } catch {
203
+ return false;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * What `run` and `package` print about the links: a line for each library left out, and one
209
+ * naming the dependencies with no desktop code. Empty when there is nothing to say.
210
+ *
211
+ * @param {DesktopLinks} links
212
+ * @returns {string[]}
213
+ */
214
+ export function linkWarnings(links) {
215
+ const lines = [...links.problems];
216
+ if (links.withoutDesktop.length > 0) {
217
+ lines.push(
218
+ `No desktop code in ${links.withoutDesktop.join(', ')}: their native modules are absent on ` +
219
+ 'macOS. List a package in the deny option of the @ng-native/desktop plugin to keep it out ' +
220
+ 'of this check.',
221
+ );
222
+ }
223
+ return lines;
224
+ }
package/bin/cli.mjs ADDED
@@ -0,0 +1,158 @@
1
+ /**
2
+ * The `ng-native-desktop` command: builds the desktop host when it needs building and launches it,
3
+ * or packages the app (`package.mjs`).
4
+ *
5
+ * ng-native-desktop run [bundle path or URL] [--module <name>] [--port <port>] [--url <link>] [--universal]
6
+ * ng-native-desktop package [--format app|dmg|mas] [--output <dir>] [--feed-url <url>]
7
+ *
8
+ * The host is built in the per-user cache (see `cacheDir`) from the pinned sources
9
+ * `native/scripts/fetch.sh` fetches, against the app's own `react-native`. With no bundle it loads
10
+ * the app from the dev server `npm start` runs, by URL, so reload and Fast Refresh work. The app's
11
+ * Expo config must list `macos`; the command says how to add it when it does not.
12
+ */
13
+ import path from 'node:path';
14
+ import { parseArgs } from 'node:util';
15
+
16
+ import { hostCapabilities } from './app-config.mjs';
17
+ import { prepareHost, system, UsageError } from './host.mjs';
18
+ import { PACKAGE_USAGE, packageApp, parsePackage } from './package.mjs';
19
+
20
+ export {
21
+ cacheDir,
22
+ checkExpoConfig,
23
+ HOST_LIBRARIES,
24
+ linkFile,
25
+ system,
26
+ UsageError,
27
+ } from './host.mjs';
28
+
29
+ export const USAGE = `Usage: ng-native-desktop run [bundle path or URL] [--module <name>] [--port <port>] [--url <link>]
30
+ [--universal]
31
+
32
+ Builds the macOS desktop host if it needs building, then opens the app in it: from the dev server
33
+ (start it with npm start) unless a bundle path or URL is given.
34
+
35
+ --module <name> the registered app to start (default: main)
36
+ --port <port> the dev server's port (default: 8081)
37
+ --url <link> a link to open the app on, as Linking's initial URL (myapp://settings)
38
+ --universal build for arm64 and x86_64 (default: this Mac's architecture)
39
+
40
+ ${PACKAGE_USAGE}`;
41
+
42
+ /**
43
+ * The dev server URL of an app's bundle for macOS. The entry is the one Expo's own clients load,
44
+ * which resolves the app's `main` (`/index.bundle` would need an index file at the root).
45
+ *
46
+ * @param {number} port
47
+ */
48
+ export function devServerBundleUrl(port) {
49
+ return `http://localhost:${port}/.expo/.virtual-metro-entry.bundle?platform=macos&dev=true`;
50
+ }
51
+
52
+ /**
53
+ * @param {string[]} argv the arguments after the command name
54
+ * @returns {{ command: 'help' } | { command: 'run', bundle: string | undefined, module: string, port: number, universal: boolean, url?: string } | import('./package.mjs').PackageCommand}
55
+ */
56
+ export function parseCommand(argv) {
57
+ const [command, ...rest] = argv;
58
+ if (command === undefined || command === 'help' || command === '--help' || command === '-h') {
59
+ return { command: 'help' };
60
+ }
61
+ if (command === 'package') return parsePackage(rest);
62
+ if (command !== 'run') {
63
+ throw new UsageError(`Unknown command "${command}".`);
64
+ }
65
+ const { values, positionals } = parseArgs({
66
+ args: rest,
67
+ allowPositionals: true,
68
+ options: {
69
+ module: { type: 'string', default: 'main' },
70
+ port: { type: 'string', default: '8081' },
71
+ universal: { type: 'boolean', default: false },
72
+ url: { type: 'string' },
73
+ },
74
+ });
75
+ if (positionals.length > 1) {
76
+ throw new UsageError('run takes at most one bundle path or URL.');
77
+ }
78
+ const port = Number(values.port);
79
+ if (!Number.isInteger(port) || port <= 0 || port > 65535) {
80
+ throw new UsageError(`--port takes a port number, not "${values.port}".`);
81
+ }
82
+ return {
83
+ command: 'run',
84
+ bundle: positionals[0],
85
+ module: values.module,
86
+ port,
87
+ universal: values.universal,
88
+ ...(values.url !== undefined && { url: values.url }),
89
+ };
90
+ }
91
+
92
+ /** @param {string} bundle */
93
+ export function isUrl(bundle) {
94
+ return /^https?:\/\//i.test(bundle);
95
+ }
96
+
97
+ /**
98
+ * Builds the host (a no-op when nothing changed) and runs it on the bundle. Returns the host's
99
+ * exit status.
100
+ *
101
+ * @param {{ bundle?: string, module: string, port?: number, universal: boolean, url?: string }} options
102
+ * @param {typeof system} [sys]
103
+ */
104
+ export async function run(options, sys = system) {
105
+ const { cwd, expo, config, buildDir } = prepareHost(sys, options);
106
+ const appId = config.bundleIdentifier ?? expo.slug ?? config.name;
107
+ // What Processes may run and read, as a packaged app's Info.plist gives it.
108
+ const capabilities = hostCapabilities(config.options);
109
+ return sys.host(path.join(buildDir, 'appkit', 'ngn-macos'), [
110
+ bundleArgument(options, cwd),
111
+ '--module',
112
+ options.module,
113
+ '--title',
114
+ config.name,
115
+ '--app-id',
116
+ appId,
117
+ ...(capabilities ? ['--capabilities', JSON.stringify(capabilities)] : []),
118
+ ...(options.url ? ['--url', options.url] : []),
119
+ ]);
120
+ }
121
+
122
+ /**
123
+ * What the host loads. A URL goes to the host as it is: it loads it from the dev server and stays
124
+ * connected for reload and Fast Refresh.
125
+ *
126
+ * @param {{ bundle?: string, port?: number }} options
127
+ * @param {string} cwd
128
+ */
129
+ function bundleArgument(options, cwd) {
130
+ if (!options.bundle) return devServerBundleUrl(options.port ?? 8081);
131
+ return isUrl(options.bundle) ? options.bundle : path.resolve(cwd, options.bundle);
132
+ }
133
+
134
+ /**
135
+ * @param {string[]} argv
136
+ * @param {typeof system} [sys]
137
+ */
138
+ export async function main(argv, sys = system) {
139
+ try {
140
+ const command = parseCommand(argv);
141
+ if (command.command === 'help') {
142
+ console.log(USAGE);
143
+ return 0;
144
+ }
145
+ if (command.command === 'package') return await packageApp(command, sys);
146
+ return await run(command, sys);
147
+ } catch (error) {
148
+ if (
149
+ error instanceof UsageError ||
150
+ (error instanceof Error && 'code' in error && String(error.code).startsWith('ERR_PARSE_ARGS'))
151
+ ) {
152
+ console.error(`${error.message}\n\n${USAGE}`);
153
+ return 2;
154
+ }
155
+ console.error(error instanceof Error ? error.message : error);
156
+ return 1;
157
+ }
158
+ }