@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/bin/host.mjs ADDED
@@ -0,0 +1,427 @@
1
+ /**
2
+ * What the `ng-native-desktop` commands share: the app's checked config, the native code its build
3
+ * links, and the desktop host built in the per-user cache (see `cacheDir`) from the pinned sources
4
+ * `native/scripts/fetch.sh` fetches, against the app's own `react-native`. The side effects go
5
+ * through `system`, which the tests replace.
6
+ */
7
+ import { spawn, spawnSync } from 'node:child_process';
8
+ import { createHash } from 'node:crypto';
9
+ import {
10
+ cpSync,
11
+ existsSync,
12
+ mkdirSync,
13
+ readFileSync,
14
+ renameSync,
15
+ rmSync,
16
+ writeFileSync,
17
+ } from 'node:fs';
18
+ import { createRequire } from 'node:module';
19
+ import { constants, homedir } from 'node:os';
20
+ import path from 'node:path';
21
+ import { fileURLToPath } from 'node:url';
22
+
23
+ import { desktopAppConfig } from './app-config.mjs';
24
+ import { desktopLinks, linkWarnings } from './autolink.mjs';
25
+ import { choosePrebuilt, fetchPrebuilt, readManifest } from './prebuilt.mjs';
26
+ import { checkToolchain, FIRST_BUILD_NOTE } from './toolchain.mjs';
27
+
28
+ export const packageDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
29
+
30
+ /**
31
+ * The per-user build cache for one React Native version. `native/scripts/cache-dir.sh` computes
32
+ * the same path for the build scripts.
33
+ *
34
+ * @param {string} version
35
+ * @param {{ env?: Record<string, string | undefined>, platform?: string, home?: string }} [options]
36
+ */
37
+ export function cacheDir(
38
+ version,
39
+ { env = process.env, platform = process.platform, home = homedir() } = {},
40
+ ) {
41
+ let root = env.NGN_DESKTOP_CACHE;
42
+ if (!root) {
43
+ root =
44
+ platform === 'darwin'
45
+ ? path.join(home, 'Library', 'Caches', 'ng-native', 'desktop')
46
+ : path.join(env.XDG_CACHE_HOME || path.join(home, '.cache'), 'ng-native', 'desktop');
47
+ }
48
+ return path.join(root, `rn-${version}`);
49
+ }
50
+
51
+ export class UsageError extends Error {}
52
+
53
+ /**
54
+ * The libraries whose Fabric components the host compiles in when the app has them installed:
55
+ * the stack, its header and the safe area that `@ng-native/router` and `<safe-area-view>` commit,
56
+ * the svg views `@ng-native/icons` commits, the web view `<web-view>` and an `<iframe>` commit, and
57
+ * the worklets and Reanimated, whose shared C++ the host builds by its own recipes
58
+ * (`native/cmake/libraries/`).
59
+ * They ship no desktop code of their own, so autolinking (`autolink.mjs`) does not find them.
60
+ */
61
+ export const HOST_LIBRARIES = [
62
+ 'react-native-screens',
63
+ 'react-native-safe-area-context',
64
+ 'react-native-svg',
65
+ 'react-native-webview',
66
+ 'react-native-worklets',
67
+ 'react-native-reanimated',
68
+ ];
69
+
70
+ /**
71
+ * The real side effects, replaced in tests.
72
+ */
73
+ export const system = {
74
+ platform: process.platform,
75
+ env: /** @type {Record<string, string | undefined>} */ (process.env),
76
+ cwd: () => process.cwd(),
77
+ /** @param {string} from */
78
+ resolveReactNative(from) {
79
+ const require = createRequire(path.join(from, 'package.json'));
80
+ return path.dirname(require.resolve('react-native/package.json'));
81
+ },
82
+ /**
83
+ * An installed package's directory, or null when the app does not have it.
84
+ *
85
+ * @param {string} from
86
+ * @param {string} name
87
+ * @returns {string | null}
88
+ */
89
+ resolvePackage(from, name) {
90
+ const require = createRequire(path.join(from, 'package.json'));
91
+ try {
92
+ return path.dirname(require.resolve(`${name}/package.json`));
93
+ } catch {
94
+ return null;
95
+ }
96
+ },
97
+ /**
98
+ * @param {string} command
99
+ * @param {string[]} args
100
+ * @param {{ capture?: boolean, env?: Record<string, string> }} [options] `env` is added to
101
+ * this process's environment
102
+ */
103
+ run(command, args, { capture = false, env } = {}) {
104
+ const result = spawnSync(command, args, {
105
+ stdio: capture ? ['inherit', 'pipe', 'inherit'] : 'inherit',
106
+ encoding: 'utf8',
107
+ ...(env && { env: { ...process.env, ...env } }),
108
+ });
109
+ if (result.error) throw result.error;
110
+ return { status: result.status ?? 1, stdout: result.stdout ?? '' };
111
+ },
112
+ /**
113
+ * Runs the host with this process's environment and terminal, passing on the signals that end a
114
+ * process (a test pool's SIGTERM, Ctrl-C), and resolves with its status: its exit code, or 128
115
+ * and the signal's number when a signal ended it.
116
+ *
117
+ * @param {string} command
118
+ * @param {string[]} args
119
+ * @returns {Promise<number>}
120
+ */
121
+ host(command, args) {
122
+ return new Promise((resolve, reject) => {
123
+ const child = spawn(command, args, { stdio: 'inherit' });
124
+ const signals = /** @type {const} */ (['SIGTERM', 'SIGINT', 'SIGHUP']);
125
+ const forward = (/** @type {NodeJS.Signals} */ signal) => child.kill(signal);
126
+ for (const signal of signals) process.on(signal, forward);
127
+ const done = () => {
128
+ for (const signal of signals) process.off(signal, forward);
129
+ };
130
+ child.once('error', (error) => {
131
+ done();
132
+ reject(error);
133
+ });
134
+ child.once('exit', (code, signal) => {
135
+ done();
136
+ resolve(code ?? 128 + (signal ? osSignal(signal) : 0));
137
+ });
138
+ });
139
+ },
140
+ /**
141
+ * The project's public Expo config, as the Expo CLI resolves it (app.json or app.config.js).
142
+ *
143
+ * @param {string} from
144
+ * @returns {ExpoConfig}
145
+ */
146
+ expoConfig(from) {
147
+ const require = createRequire(path.join(from, 'package.json'));
148
+ const result = spawnSync(
149
+ process.execPath,
150
+ [require.resolve('expo/bin/cli'), 'config', '--json', '--type', 'public'],
151
+ { cwd: from, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] },
152
+ );
153
+ if (result.error) throw result.error;
154
+ if (result.status !== 0) throw new Error('The Expo CLI could not read the app config.');
155
+ return JSON.parse(result.stdout);
156
+ },
157
+ /**
158
+ * Runs the app's own Expo CLI in its directory, with the terminal attached.
159
+ *
160
+ * @param {string} from
161
+ * @param {string[]} args
162
+ */
163
+ expo(from, args) {
164
+ const require = createRequire(path.join(from, 'package.json'));
165
+ const result = spawnSync(process.execPath, [require.resolve('expo/bin/cli'), ...args], {
166
+ cwd: from,
167
+ stdio: 'inherit',
168
+ });
169
+ if (result.error) throw result.error;
170
+ return { status: result.status ?? 1 };
171
+ },
172
+ links: desktopLinks,
173
+ /** @param {string} file */
174
+ exists: (file) => existsSync(file),
175
+ /** @param {string} file */
176
+ remove(file) {
177
+ rmSync(file, { recursive: true, force: true });
178
+ },
179
+ /**
180
+ * Copies a file or a folder, links and all, making the folders it goes in.
181
+ *
182
+ * @param {string} from
183
+ * @param {string} to
184
+ */
185
+ copy(from, to) {
186
+ mkdirSync(path.dirname(to), { recursive: true });
187
+ cpSync(from, to, { recursive: true, verbatimSymlinks: true });
188
+ },
189
+ /** @param {string} file */
190
+ readFile: (file) => readFileSync(file, 'utf8'),
191
+ /** @param {string} file the file's SHA-256, in hex */
192
+ sha256: (file) => createHash('sha256').update(readFileSync(file)).digest('hex'),
193
+ /**
194
+ * @param {string} from
195
+ * @param {string} to
196
+ */
197
+ rename(from, to) {
198
+ renameSync(from, to);
199
+ },
200
+ /**
201
+ * @param {string} file
202
+ * @param {string} text
203
+ */
204
+ writeFile(file, text) {
205
+ mkdirSync(path.dirname(file), { recursive: true });
206
+ writeFileSync(file, text);
207
+ },
208
+ /** @param {string} line */
209
+ warn(line) {
210
+ console.warn(line);
211
+ },
212
+ };
213
+
214
+ /** @typedef {import('./app-config.mjs').ExpoConfig} ExpoConfig */
215
+
216
+ /**
217
+ * Throws a usage error naming the fix when the app's Expo config cannot run on macOS: without
218
+ * `macos` in `expo.platforms`, Metro does not bundle for it, and without the experiment Expo drops
219
+ * `macos` from the list without a word.
220
+ *
221
+ * @param {ExpoConfig} config
222
+ */
223
+ export function checkExpoConfig(config) {
224
+ if (!config.platforms?.includes('macos')) {
225
+ throw new UsageError(
226
+ 'The app\'s Expo config does not list macos. Add "macos" to expo.platforms in app.json and set expo.experiments.outOfTreePlatforms to true.',
227
+ );
228
+ }
229
+ if (!config.experiments?.outOfTreePlatforms) {
230
+ throw new UsageError(
231
+ "The app's Expo config lists macos without expo.experiments.outOfTreePlatforms, so Expo ignores it. Set expo.experiments.outOfTreePlatforms to true in app.json.",
232
+ );
233
+ }
234
+ }
235
+
236
+ /**
237
+ * @param {typeof system} sys
238
+ * @param {string} cwd
239
+ */
240
+ function resolveReactNative(sys, cwd) {
241
+ try {
242
+ return sys.resolveReactNative(cwd);
243
+ } catch {
244
+ throw new UsageError(
245
+ `react-native is not installed in ${cwd}. Run this from the app's directory.`,
246
+ );
247
+ }
248
+ }
249
+
250
+ /**
251
+ * The app's Expo config, checked for macos.
252
+ *
253
+ * @param {typeof system} sys
254
+ * @param {string} cwd
255
+ */
256
+ export function readExpoConfig(sys, cwd) {
257
+ /** @type {ExpoConfig} */
258
+ let config;
259
+ try {
260
+ config = sys.expoConfig(cwd);
261
+ } catch (error) {
262
+ throw new UsageError(
263
+ `Could not read the app's Expo config in ${cwd}: ${error instanceof Error ? error.message : error}`,
264
+ );
265
+ }
266
+ checkExpoConfig(config);
267
+ return config;
268
+ }
269
+
270
+ /**
271
+ * Where the native code the app's build links is written for the host build, which reads it from
272
+ * `NGN_DESKTOP_LINK`. In the app's `.expo`, which every template ignores.
273
+ *
274
+ * @param {string} appDir
275
+ */
276
+ export function linkFile(appDir) {
277
+ return path.join(appDir, '.expo', 'ng-native-desktop', 'link.json');
278
+ }
279
+
280
+ /**
281
+ * Everything a command needs before it uses the host: the app's checked config, its links written
282
+ * for the build, a warning for each dependency the build leaves without its native code, and the
283
+ * host built (a no-op when nothing changed).
284
+ *
285
+ * @param {typeof system} sys
286
+ * @param {{ universal: boolean, release?: boolean, expo?: ExpoConfig }} options `release` builds
287
+ * the host as a packaged app ships it, without the core tests or the debugger, and takes the
288
+ * release prebuilt host where one fits (the debug one otherwise); `expo` is the app's config
289
+ * when the caller has read it already
290
+ */
291
+ export function prepareHost(sys, options) {
292
+ if (sys.platform !== 'darwin') {
293
+ throw new UsageError('The desktop host runs on macOS only for now.');
294
+ }
295
+ const cwd = sys.cwd();
296
+ const reactNative = resolveReactNative(sys, cwd);
297
+ const expo = options.expo ?? readExpoConfig(sys, cwd);
298
+ const config = desktopAppConfig(expo);
299
+ if (/[/\\]/.test(config.name) || config.name === '.' || config.name === '..') {
300
+ throw new UsageError(
301
+ `The app name "${config.name}" cannot contain a path separator or be . or .., because the ` +
302
+ 'app, its executable and its packages are named for it. Change "name" in app.json.',
303
+ );
304
+ }
305
+ const deny = config.options.deny ?? [];
306
+ const links = sys.links(cwd, { deny, builtIn: HOST_LIBRARIES });
307
+ for (const line of linkWarnings(links)) sys.warn(line);
308
+ // Written every time, so a library removed or denied leaves the build with the rest.
309
+ const file = linkFile(cwd);
310
+ const { libraries, appModules } = links;
311
+ sys.writeFile(file, `${JSON.stringify({ version: 1, libraries, appModules }, null, 2)}\n`);
312
+ // Where autolinking found each host library, under a dependency's node_modules too, else where
313
+ // it resolves from the app (a peer dependency the package manager installed, which the walk
314
+ // does not follow).
315
+ const found = new Map(links.hostLibraries.map(({ name, dir }) => [name, dir]));
316
+ const hostLibraries = HOST_LIBRARIES.filter((name) => !deny.includes(name)).flatMap((name) => {
317
+ const dir = found.get(name) ?? sys.resolvePackage(cwd, name);
318
+ return dir === null ? [] : [{ name, dir }];
319
+ });
320
+ const buildDir =
321
+ prebuiltHost(sys, reactNative, {
322
+ // A packaged app ships the Release host; a dev run gets the one with the debugger.
323
+ flavour: options.release ? 'release' : 'debug',
324
+ deny,
325
+ linked: libraries.length + appModules.length,
326
+ hostLibraries,
327
+ }) ??
328
+ buildHost(
329
+ sys,
330
+ reactNative,
331
+ hostLibraries.map(({ dir }) => dir),
332
+ options,
333
+ file,
334
+ );
335
+ return { cwd, expo, config, buildDir, reactNative };
336
+ }
337
+
338
+ /**
339
+ * A package's version, from its folder, or null when it has none.
340
+ *
341
+ * @param {typeof system} sys
342
+ * @param {string | null} dir
343
+ */
344
+ function versionIn(sys, dir) {
345
+ if (!dir) return null;
346
+ try {
347
+ return String(JSON.parse(sys.readFile(path.join(dir, 'package.json'))).version);
348
+ } catch {
349
+ return null;
350
+ }
351
+ }
352
+
353
+ /**
354
+ * The prebuilt host's build folder when `prebuilt.json` has one this app can run on (see
355
+ * `choosePrebuilt`), downloaded into the cache once; null when the host is built from source.
356
+ *
357
+ * @param {typeof system} sys
358
+ * @param {string} reactNative
359
+ * @param {{ flavour: import('./prebuilt.mjs').Flavour, deny: readonly string[], linked: number, hostLibraries: { name: string, dir: string }[] }} app
360
+ * `hostLibraries`: where each host library the app has is installed
361
+ */
362
+ function prebuiltHost(sys, reactNative, { flavour, deny, linked, hostLibraries }) {
363
+ let text = '';
364
+ try {
365
+ text = sys.readFile(path.join(packageDir, 'prebuilt.json'));
366
+ } catch {
367
+ return null;
368
+ }
369
+ const version = versionIn(sys, reactNative);
370
+ if (!version) return null;
371
+ const libraries = Object.fromEntries(
372
+ hostLibraries.map(({ name, dir }) => [name, versionIn(sys, dir)]),
373
+ );
374
+ const choice = choosePrebuilt(readManifest(text), {
375
+ reactNative: version,
376
+ flavour,
377
+ linked,
378
+ libraries,
379
+ deny,
380
+ env: sys.env,
381
+ });
382
+ if (!('host' in choice)) return null;
383
+ return fetchPrebuilt(
384
+ sys,
385
+ choice.host,
386
+ cacheDir(version, { env: sys.env, platform: sys.platform }),
387
+ );
388
+ }
389
+
390
+ /**
391
+ * Builds the host (a no-op when nothing changed) and returns its build directory.
392
+ *
393
+ * @param {typeof system} sys
394
+ * @param {string} reactNative
395
+ * @param {string[]} libraries
396
+ * @param {{ universal: boolean, release?: boolean }} options
397
+ * @param {string} link the file `linkFile` names
398
+ */
399
+ function buildHost(sys, reactNative, libraries, { universal, release }, link) {
400
+ checkToolchain(sys);
401
+ const version = versionIn(sys, reactNative);
402
+ if (
403
+ version &&
404
+ !sys.exists(path.join(cacheDir(version, { env: sys.env, platform: sys.platform }), 'host'))
405
+ ) {
406
+ sys.warn(FIRST_BUILD_NOTE);
407
+ }
408
+ const buildArgs = [reactNative, ...libraries.flatMap((dir) => ['--library', dir])];
409
+ if (universal) buildArgs.push('--universal');
410
+ // The core tests are the repo's own (`test:native`): the published package has no sources for
411
+ // them, so an app's build leaves them out.
412
+ buildArgs.push(release ? '--release' : '--no-tests');
413
+ const build = sys.run(path.join(packageDir, 'native', 'scripts', 'build.sh'), buildArgs, {
414
+ capture: true,
415
+ env: { NGN_DESKTOP_LINK: link },
416
+ });
417
+ const buildDir = build.stdout.trim().split('\n').pop();
418
+ if (build.status !== 0 || !buildDir) {
419
+ throw new Error('The desktop host did not build; the output above says why.');
420
+ }
421
+ return buildDir;
422
+ }
423
+
424
+ /** @param {NodeJS.Signals} signal */
425
+ function osSignal(signal) {
426
+ return constants.signals[signal] ?? 0;
427
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { main } from './cli.mjs';
3
+
4
+ process.exitCode = await main(process.argv.slice(2));