@ng-native/desktop 0.0.0 → 0.24.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 (401) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  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 +277 -0
  14. package/native/appkit/CMakeLists.txt +130 -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-sheet.h +59 -0
  41. package/native/appkit/camera-sheet.mm +344 -0
  42. package/native/appkit/camera-view.h +15 -0
  43. package/native/appkit/camera-view.mm +134 -0
  44. package/native/appkit/camera.h +61 -0
  45. package/native/appkit/camera.mm +496 -0
  46. package/native/appkit/cg-canvas.h +24 -0
  47. package/native/appkit/cg-canvas.mm +663 -0
  48. package/native/appkit/component-view.h +17 -0
  49. package/native/appkit/crypto.h +19 -0
  50. package/native/appkit/crypto.mm +78 -0
  51. package/native/appkit/desktop-expo.h +29 -0
  52. package/native/appkit/desktop-expo.mm +385 -0
  53. package/native/appkit/expo-image-drawing.h +46 -0
  54. package/native/appkit/expo-image-drawing.mm +131 -0
  55. package/native/appkit/expo-image-view.h +15 -0
  56. package/native/appkit/expo-image-view.mm +182 -0
  57. package/native/appkit/expo-ui-renderer.h +68 -0
  58. package/native/appkit/expo-ui-renderer.mm +101 -0
  59. package/native/appkit/expo-ui-view.h +26 -0
  60. package/native/appkit/expo-ui-view.mm +134 -0
  61. package/native/appkit/expo-ui.swift +1284 -0
  62. package/native/appkit/file-system.h +16 -0
  63. package/native/appkit/file-system.mm +140 -0
  64. package/native/appkit/fonts.h +12 -0
  65. package/native/appkit/fonts.mm +48 -0
  66. package/native/appkit/geocoder.h +19 -0
  67. package/native/appkit/geocoder.mm +101 -0
  68. package/native/appkit/glass-effect.h +22 -0
  69. package/native/appkit/glass-effect.mm +63 -0
  70. package/native/appkit/glass-view.h +8 -0
  71. package/native/appkit/glass-view.mm +65 -0
  72. package/native/appkit/header-toolbar.h +60 -0
  73. package/native/appkit/header-toolbar.mm +632 -0
  74. package/native/appkit/host-view.h +54 -0
  75. package/native/appkit/host-view.mm +1228 -0
  76. package/native/appkit/image-manipulator.h +14 -0
  77. package/native/appkit/image-manipulator.mm +191 -0
  78. package/native/appkit/image-request.h +22 -0
  79. package/native/appkit/image-request.mm +62 -0
  80. package/native/appkit/image-view.h +8 -0
  81. package/native/appkit/image-view.mm +142 -0
  82. package/native/appkit/input-replay.h +25 -0
  83. package/native/appkit/input-replay.mm +418 -0
  84. package/native/appkit/language-model.h +14 -0
  85. package/native/appkit/language-model.mm +99 -0
  86. package/native/appkit/language-model.swift +472 -0
  87. package/native/appkit/local-authentication.h +15 -0
  88. package/native/appkit/local-authentication.mm +133 -0
  89. package/native/appkit/location.h +16 -0
  90. package/native/appkit/location.mm +214 -0
  91. package/native/appkit/main.mm +1475 -0
  92. package/native/appkit/map-view.h +15 -0
  93. package/native/appkit/map-view.mm +109 -0
  94. package/native/appkit/maps.h +35 -0
  95. package/native/appkit/maps.mm +343 -0
  96. package/native/appkit/menu-bar.h +22 -0
  97. package/native/appkit/menu-bar.mm +208 -0
  98. package/native/appkit/modal-focus.h +16 -0
  99. package/native/appkit/modal-focus.mm +26 -0
  100. package/native/appkit/modal-host-view.h +79 -0
  101. package/native/appkit/modal-host-view.mm +442 -0
  102. package/native/appkit/native-controls.h +22 -0
  103. package/native/appkit/native-controls.mm +431 -0
  104. package/native/appkit/network-state.h +12 -0
  105. package/native/appkit/network-state.mm +64 -0
  106. package/native/appkit/network.h +14 -0
  107. package/native/appkit/network.mm +396 -0
  108. package/native/appkit/notifications.h +19 -0
  109. package/native/appkit/notifications.mm +309 -0
  110. package/native/appkit/photo-library.h +33 -0
  111. package/native/appkit/photo-library.mm +548 -0
  112. package/native/appkit/pointer-buttons.h +32 -0
  113. package/native/appkit/presentation-label.h +15 -0
  114. package/native/appkit/presentation-label.mm +12 -0
  115. package/native/appkit/presented-screen.h +19 -0
  116. package/native/appkit/presented-screen.mm +181 -0
  117. package/native/appkit/printing.h +42 -0
  118. package/native/appkit/printing.mm +393 -0
  119. package/native/appkit/push.h +19 -0
  120. package/native/appkit/push.mm +81 -0
  121. package/native/appkit/red-box.h +26 -0
  122. package/native/appkit/red-box.mm +387 -0
  123. package/native/appkit/screen-capture.h +21 -0
  124. package/native/appkit/screen-capture.mm +92 -0
  125. package/native/appkit/scroll-view.h +13 -0
  126. package/native/appkit/scroll-view.mm +251 -0
  127. package/native/appkit/scrollers.h +25 -0
  128. package/native/appkit/scrollers.mm +43 -0
  129. package/native/appkit/search-field.h +34 -0
  130. package/native/appkit/search-field.mm +291 -0
  131. package/native/appkit/search-toolbar-item.h +19 -0
  132. package/native/appkit/search-toolbar-item.mm +269 -0
  133. package/native/appkit/share-picker.h +34 -0
  134. package/native/appkit/share-picker.mm +121 -0
  135. package/native/appkit/split-view.h +77 -0
  136. package/native/appkit/split-view.mm +1206 -0
  137. package/native/appkit/store-review.h +13 -0
  138. package/native/appkit/store-review.mm +28 -0
  139. package/native/appkit/surface-view.h +45 -0
  140. package/native/appkit/surface-view.mm +562 -0
  141. package/native/appkit/svg-view.h +18 -0
  142. package/native/appkit/svg-view.mm +103 -0
  143. package/native/appkit/symbol-drawing.h +24 -0
  144. package/native/appkit/symbol-drawing.mm +117 -0
  145. package/native/appkit/symbol-view.h +8 -0
  146. package/native/appkit/symbol-view.mm +33 -0
  147. package/native/appkit/system-access.h +34 -0
  148. package/native/appkit/system-access.mm +210 -0
  149. package/native/appkit/system.h +24 -0
  150. package/native/appkit/system.mm +403 -0
  151. package/native/appkit/tab-walk.h +31 -0
  152. package/native/appkit/tab-walk.mm +64 -0
  153. package/native/appkit/test-launch.h +36 -0
  154. package/native/appkit/test-launch.mm +115 -0
  155. package/native/appkit/text-input-field.h +81 -0
  156. package/native/appkit/text-input-field.mm +525 -0
  157. package/native/appkit/text-layout.h +58 -0
  158. package/native/appkit/text-layout.mm +485 -0
  159. package/native/appkit/text-recognition.h +13 -0
  160. package/native/appkit/text-recognition.mm +102 -0
  161. package/native/appkit/tracking.h +13 -0
  162. package/native/appkit/tracking.mm +51 -0
  163. package/native/appkit/tray-and-dock.h +45 -0
  164. package/native/appkit/tray-and-dock.mm +130 -0
  165. package/native/appkit/undo.h +23 -0
  166. package/native/appkit/undo.mm +125 -0
  167. package/native/appkit/updates.h +17 -0
  168. package/native/appkit/updates.mm +71 -0
  169. package/native/appkit/video-view.h +10 -0
  170. package/native/appkit/video-view.mm +42 -0
  171. package/native/appkit/video.h +38 -0
  172. package/native/appkit/video.mm +404 -0
  173. package/native/appkit/web-browser.h +12 -0
  174. package/native/appkit/web-browser.mm +97 -0
  175. package/native/appkit/web-view-component.h +10 -0
  176. package/native/appkit/web-view-component.mm +62 -0
  177. package/native/appkit/web-view.h +31 -0
  178. package/native/appkit/web-view.mm +401 -0
  179. package/native/cmake/libraries/react-native-reanimated.cmake +45 -0
  180. package/native/cmake/libraries/react-native-worklets.cmake +46 -0
  181. package/native/cmake/libraries.cmake +109 -0
  182. package/native/cmake/linked-modules.cmake +112 -0
  183. package/native/cmake/react-native.cmake +175 -0
  184. package/native/cmake/runtime-dependencies.cmake +34 -0
  185. package/native/cmake/swift.cmake +43 -0
  186. package/native/cmake/third-party.cmake +74 -0
  187. package/native/core/include/ngn/absent-views.h +27 -0
  188. package/native/core/include/ngn/accessibility.h +140 -0
  189. package/native/core/include/ngn/address-search.h +69 -0
  190. package/native/core/include/ngn/animation-frames.h +39 -0
  191. package/native/core/include/ngn/app-info.h +52 -0
  192. package/native/core/include/ngn/app-menus.h +151 -0
  193. package/native/core/include/ngn/app-windows.h +181 -0
  194. package/native/core/include/ngn/apple-authentication.h +116 -0
  195. package/native/core/include/ngn/asset.h +28 -0
  196. package/native/core/include/ngn/audio.h +125 -0
  197. package/native/core/include/ngn/back-swipe.h +121 -0
  198. package/native/core/include/ngn/battery.h +48 -0
  199. package/native/core/include/ngn/bytes.h +59 -0
  200. package/native/core/include/ngn/calendar.h +180 -0
  201. package/native/core/include/ngn/camera.h +222 -0
  202. package/native/core/include/ngn/control-sizes.h +111 -0
  203. package/native/core/include/ngn/core-modules.h +108 -0
  204. package/native/core/include/ngn/crypto.h +38 -0
  205. package/native/core/include/ngn/default-menu.h +91 -0
  206. package/native/core/include/ngn/desktop-expo.h +193 -0
  207. package/native/core/include/ngn/desktop-modal.h +109 -0
  208. package/native/core/include/ngn/desktop-props.h +75 -0
  209. package/native/core/include/ngn/desktop-view-props.h +110 -0
  210. package/native/core/include/ngn/dev-server.h +33 -0
  211. package/native/core/include/ngn/dom-web-view.h +53 -0
  212. package/native/core/include/ngn/download.h +24 -0
  213. package/native/core/include/ngn/expo-image.h +192 -0
  214. package/native/core/include/ngn/expo-ui.h +133 -0
  215. package/native/core/include/ngn/file-system.h +274 -0
  216. package/native/core/include/ngn/focus-order.h +63 -0
  217. package/native/core/include/ngn/fonts.h +64 -0
  218. package/native/core/include/ngn/gestures.h +305 -0
  219. package/native/core/include/ngn/glass.h +67 -0
  220. package/native/core/include/ngn/header-bar.h +112 -0
  221. package/native/core/include/ngn/host-state.h +243 -0
  222. package/native/core/include/ngn/image-manipulator.h +70 -0
  223. package/native/core/include/ngn/input-dispatcher.h +211 -0
  224. package/native/core/include/ngn/input-script.h +56 -0
  225. package/native/core/include/ngn/input.h +112 -0
  226. package/native/core/include/ngn/key-value-store.h +41 -0
  227. package/native/core/include/ngn/language-model.h +69 -0
  228. package/native/core/include/ngn/launch-frame.h +47 -0
  229. package/native/core/include/ngn/launch-settings.h +98 -0
  230. package/native/core/include/ngn/layout-animations.h +24 -0
  231. package/native/core/include/ngn/library-components.h +13 -0
  232. package/native/core/include/ngn/library-glue.h +53 -0
  233. package/native/core/include/ngn/live-regions.h +54 -0
  234. package/native/core/include/ngn/local-authentication.h +74 -0
  235. package/native/core/include/ngn/location.h +89 -0
  236. package/native/core/include/ngn/maps.h +226 -0
  237. package/native/core/include/ngn/module-registry.h +51 -0
  238. package/native/core/include/ngn/mounting-backend.h +96 -0
  239. package/native/core/include/ngn/mounting-manager.h +155 -0
  240. package/native/core/include/ngn/native-controls.h +161 -0
  241. package/native/core/include/ngn/native-module.h +109 -0
  242. package/native/core/include/ngn/network-state.h +44 -0
  243. package/native/core/include/ngn/network.h +100 -0
  244. package/native/core/include/ngn/notifications.h +185 -0
  245. package/native/core/include/ngn/photo-library.h +134 -0
  246. package/native/core/include/ngn/printing.h +69 -0
  247. package/native/core/include/ngn/processes.h +114 -0
  248. package/native/core/include/ngn/red-box.h +119 -0
  249. package/native/core/include/ngn/reload-thread.h +258 -0
  250. package/native/core/include/ngn/runtime.h +163 -0
  251. package/native/core/include/ngn/safe-areas.h +82 -0
  252. package/native/core/include/ngn/screen-capture.h +35 -0
  253. package/native/core/include/ngn/screen-presentation.h +85 -0
  254. package/native/core/include/ngn/screen-stacks.h +80 -0
  255. package/native/core/include/ngn/scrollers.h +106 -0
  256. package/native/core/include/ngn/sharing.h +39 -0
  257. package/native/core/include/ngn/spawn-rules.h +78 -0
  258. package/native/core/include/ngn/splash-screen.h +41 -0
  259. package/native/core/include/ngn/split-view.h +270 -0
  260. package/native/core/include/ngn/sqlite.h +38 -0
  261. package/native/core/include/ngn/store-review.h +26 -0
  262. package/native/core/include/ngn/surface-book.h +101 -0
  263. package/native/core/include/ngn/surface-metrics.h +51 -0
  264. package/native/core/include/ngn/svg.h +434 -0
  265. package/native/core/include/ngn/symbol.h +90 -0
  266. package/native/core/include/ngn/system.h +102 -0
  267. package/native/core/include/ngn/tabs-host.h +171 -0
  268. package/native/core/include/ngn/text-input.h +134 -0
  269. package/native/core/include/ngn/text-measurer.h +38 -0
  270. package/native/core/include/ngn/text-recognition.h +55 -0
  271. package/native/core/include/ngn/tracking.h +34 -0
  272. package/native/core/include/ngn/tray-and-dock.h +107 -0
  273. package/native/core/include/ngn/undo.h +37 -0
  274. package/native/core/include/ngn/updates.h +253 -0
  275. package/native/core/include/ngn/video.h +126 -0
  276. package/native/core/include/ngn/view-box.h +126 -0
  277. package/native/core/include/ngn/view-transform.h +26 -0
  278. package/native/core/include/ngn/view-tree.h +85 -0
  279. package/native/core/include/ngn/web-browser.h +45 -0
  280. package/native/core/include/ngn/web-view.h +137 -0
  281. package/native/core/include/ngn/worklet-host.h +98 -0
  282. package/native/core/src/absent-views.cpp +41 -0
  283. package/native/core/src/accessibility.cpp +374 -0
  284. package/native/core/src/animation-frames.cpp +49 -0
  285. package/native/core/src/app-menus.cpp +359 -0
  286. package/native/core/src/app-windows.cpp +444 -0
  287. package/native/core/src/back-swipe.cpp +98 -0
  288. package/native/core/src/bytes.cpp +158 -0
  289. package/native/core/src/control-sizes.cpp +232 -0
  290. package/native/core/src/default-menu.cpp +96 -0
  291. package/native/core/src/desktop-modal.cpp +162 -0
  292. package/native/core/src/desktop-view-props.cpp +80 -0
  293. package/native/core/src/dev-server-helper.cpp +152 -0
  294. package/native/core/src/dev-server.cpp +103 -0
  295. package/native/core/src/dom-web-view.cpp +45 -0
  296. package/native/core/src/download.cpp +53 -0
  297. package/native/core/src/expo-image.cpp +548 -0
  298. package/native/core/src/expo-ui.cpp +203 -0
  299. package/native/core/src/focus-order.cpp +441 -0
  300. package/native/core/src/gestures.cpp +1806 -0
  301. package/native/core/src/glass.cpp +49 -0
  302. package/native/core/src/header-bar.cpp +104 -0
  303. package/native/core/src/host-services.cpp +50 -0
  304. package/native/core/src/host-state.cpp +61 -0
  305. package/native/core/src/input-dispatcher.cpp +727 -0
  306. package/native/core/src/input-script.cpp +123 -0
  307. package/native/core/src/key-value-store.cpp +169 -0
  308. package/native/core/src/launch-settings.cpp +148 -0
  309. package/native/core/src/layout-animations.cpp +62 -0
  310. package/native/core/src/libraries/RNCWebViewSpec.cpp +80 -0
  311. package/native/core/src/libraries/react-native-reanimated.cpp +216 -0
  312. package/native/core/src/libraries/react-native-worklets.cpp +192 -0
  313. package/native/core/src/libraries/rnscreens.cpp +125 -0
  314. package/native/core/src/libraries/rnsvg.cpp +358 -0
  315. package/native/core/src/libraries/safeareacontext.cpp +70 -0
  316. package/native/core/src/libraries/worklets-idle-frames.js +70 -0
  317. package/native/core/src/library-glue.cpp +35 -0
  318. package/native/core/src/live-regions.cpp +122 -0
  319. package/native/core/src/module-registry.cpp +50 -0
  320. package/native/core/src/modules/accessibility-manager.cpp +98 -0
  321. package/native/core/src/modules/address-search.cpp +219 -0
  322. package/native/core/src/modules/alert-manager.cpp +140 -0
  323. package/native/core/src/modules/app-info.cpp +74 -0
  324. package/native/core/src/modules/app-modules.cpp +412 -0
  325. package/native/core/src/modules/apple-authentication.cpp +188 -0
  326. package/native/core/src/modules/asset.cpp +111 -0
  327. package/native/core/src/modules/async-storage.cpp +192 -0
  328. package/native/core/src/modules/audio.cpp +541 -0
  329. package/native/core/src/modules/battery.cpp +88 -0
  330. package/native/core/src/modules/calendar.cpp +457 -0
  331. package/native/core/src/modules/camera.cpp +401 -0
  332. package/native/core/src/modules/core-modules.cpp +62 -0
  333. package/native/core/src/modules/crypto.cpp +117 -0
  334. package/native/core/src/modules/desktop-expo.cpp +527 -0
  335. package/native/core/src/modules/file-system.cpp +941 -0
  336. package/native/core/src/modules/fonts.cpp +163 -0
  337. package/native/core/src/modules/image-loader.cpp +105 -0
  338. package/native/core/src/modules/image-manipulator.cpp +305 -0
  339. package/native/core/src/modules/language-model.cpp +195 -0
  340. package/native/core/src/modules/local-authentication.cpp +140 -0
  341. package/native/core/src/modules/location.cpp +186 -0
  342. package/native/core/src/modules/maps.cpp +500 -0
  343. package/native/core/src/modules/network-state.cpp +72 -0
  344. package/native/core/src/modules/networking.cpp +387 -0
  345. package/native/core/src/modules/notifications.cpp +549 -0
  346. package/native/core/src/modules/photo-library.cpp +385 -0
  347. package/native/core/src/modules/printing.cpp +201 -0
  348. package/native/core/src/modules/screen-capture.cpp +71 -0
  349. package/native/core/src/modules/sharing.cpp +59 -0
  350. package/native/core/src/modules/splash-screen.cpp +70 -0
  351. package/native/core/src/modules/sqlite.cpp +421 -0
  352. package/native/core/src/modules/store-review.cpp +23 -0
  353. package/native/core/src/modules/text-recognition.cpp +107 -0
  354. package/native/core/src/modules/tracking.cpp +46 -0
  355. package/native/core/src/modules/undo.cpp +59 -0
  356. package/native/core/src/modules/video.cpp +366 -0
  357. package/native/core/src/modules/web-browser.cpp +100 -0
  358. package/native/core/src/modules/web-socket.cpp +266 -0
  359. package/native/core/src/mounting-manager.cpp +384 -0
  360. package/native/core/src/native-controls.cpp +129 -0
  361. package/native/core/src/native-module.cpp +250 -0
  362. package/native/core/src/network.cpp +219 -0
  363. package/native/core/src/posix-launcher.cpp +366 -0
  364. package/native/core/src/processes.cpp +324 -0
  365. package/native/core/src/red-box-errors.js +83 -0
  366. package/native/core/src/red-box.cpp +306 -0
  367. package/native/core/src/runtime.cpp +420 -0
  368. package/native/core/src/safe-areas.cpp +137 -0
  369. package/native/core/src/screen-presentation.cpp +61 -0
  370. package/native/core/src/screen-stacks.cpp +254 -0
  371. package/native/core/src/scrollers.cpp +181 -0
  372. package/native/core/src/spawn-rules.cpp +292 -0
  373. package/native/core/src/split-view.cpp +343 -0
  374. package/native/core/src/svg.cpp +2190 -0
  375. package/native/core/src/symbol.cpp +94 -0
  376. package/native/core/src/tabs-host.cpp +234 -0
  377. package/native/core/src/text-input.cpp +139 -0
  378. package/native/core/src/text-layout-manager.cpp +63 -0
  379. package/native/core/src/tray-and-dock.cpp +154 -0
  380. package/native/core/src/updates.cpp +965 -0
  381. package/native/core/src/view-box.cpp +788 -0
  382. package/native/core/src/view-transform.cpp +45 -0
  383. package/native/core/src/view-tree.cpp +234 -0
  384. package/native/core/src/web-view.cpp +143 -0
  385. package/native/core/src/worklet-host.cpp +10 -0
  386. package/native/scripts/build-hermes.sh +44 -0
  387. package/native/scripts/build.sh +175 -0
  388. package/native/scripts/cache-dir.sh +18 -0
  389. package/native/scripts/codegen-library.sh +193 -0
  390. package/native/scripts/compiler-launcher.sh +17 -0
  391. package/native/scripts/fetch.sh +174 -0
  392. package/native/scripts/hermes-built.sh +10 -0
  393. package/native/scripts/host-dir.sh +16 -0
  394. package/native/scripts/launch-probe.sh +60 -0
  395. package/native/scripts/macos-target.sh +8 -0
  396. package/native/scripts/make-prebuilt.mjs +360 -0
  397. package/native/scripts/prebuilt-host-cache.mjs +158 -0
  398. package/native/shim/openssl/sha.h +22 -0
  399. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +37 -0
  400. package/package.json +73 -1
  401. package/prebuilt.json +33 -0
@@ -0,0 +1,971 @@
1
+ /**
2
+ * `ng-native-desktop package`: the app as something to hand to someone.
3
+ *
4
+ * - `--format app` (the default): an ad-hoc signed `.app`, for this Mac and for testing.
5
+ * - `--format dmg`: Developer ID signed with the hardened runtime, notarised and stapled, in a
6
+ * `.dmg`. With `--feed-url`, Sparkle is embedded with that appcast and the `.zip` it updates from
7
+ * is made beside the `.dmg`. `--skip-notarize` makes the same `.dmg` without Apple, signed with
8
+ * `NGN_SIGN_IDENTITY` or ad hoc, for testing the package on this Mac only.
9
+ * - `--format mas`: sandboxed, signed for the Mac App Store, in a `.pkg`. Capabilities the App
10
+ * Sandbox forbids are named before it is built.
11
+ *
12
+ * Release builds are universal (arm64 and x86_64) with a minimum of macOS 14. The bundle comes from
13
+ * `expo export:embed`, which lays the assets out the way React Native's asset resolver reads them
14
+ * beside an embedded bundle, compiled to Hermes bytecode by the `hermesc` built with the host's
15
+ * Hermes, so the bytecode is the version the host runs. Credentials come from the environment (see `notaryArguments`), never
16
+ * from app.json. Packaging needs full Xcode, for `actool` to compile the icon.
17
+ */
18
+ import path from 'node:path';
19
+ import { parseArgs } from 'node:util';
20
+
21
+ import { hostCapabilities } from './app-config.mjs';
22
+ import { plist } from './plist.mjs';
23
+ import { prepareHost, readExpoConfig, UsageError } from './host.mjs';
24
+
25
+ /** The oldest macOS a packaged app runs on. */
26
+ export const MINIMUM_MACOS = '14.0';
27
+
28
+ /** Where the packages go, in the app's directory, unless `--output` says otherwise. */
29
+ export const DEFAULT_OUTPUT = 'dist/macos';
30
+
31
+ const FORMATS = ['app', 'dmg', 'mas'];
32
+
33
+ export const PACKAGE_USAGE = `Usage: ng-native-desktop package [--format app|dmg|mas] [--output <dir>] [--feed-url <url> [--sparkle-key <key>]] [--skip-notarize]
34
+
35
+ Builds the app for release, universal for arm64 and x86_64, into dist/macos. Needs full Xcode.
36
+
37
+ --format app an ad-hoc signed .app (default)
38
+ --format dmg a Developer ID signed, notarised and stapled .dmg
39
+ --format mas a sandboxed Mac App Store .pkg
40
+ --output <dir> where the packages go (default: dist/macos)
41
+ --feed-url <url> dmg only: the Sparkle appcast the app updates from, embedding Sparkle
42
+ --sparkle-key <key> with --feed-url: Sparkle's public EdDSA key, which updates are checked
43
+ against (or NGN_SPARKLE_PUBLIC_KEY)
44
+ --skip-notarize dmg only, for testing on this Mac: no notarisation, and signed ad hoc
45
+ unless NGN_SIGN_IDENTITY is set. Gatekeeper refuses it on any other Mac.
46
+
47
+ Signing and notarising read the environment:
48
+ NGN_SIGN_IDENTITY the codesign identity (dmg: Developer ID Application, mas: Apple Distribution)
49
+ NGN_NOTARY_PROFILE a notarytool keychain profile (xcrun notarytool store-credentials), or
50
+ APPLE_API_KEY, APPLE_API_KEY_ID, APPLE_API_ISSUER an App Store Connect API key
51
+ mas: NGN_INSTALLER_IDENTITY, NGN_PROVISIONING_PROFILE and APPLE_TEAM_ID
52
+ dmg with ios.usesAppleSignIn: NGN_PROVISIONING_PROFILE (Developer ID) and APPLE_TEAM_ID`;
53
+
54
+ /**
55
+ * @typedef {{ command: 'package', format: 'app' | 'dmg' | 'mas', output: string, feedUrl: string | undefined, sparkleKey: string | undefined, skipNotarize: boolean }} PackageCommand
56
+ * @typedef {import('./host.mjs').system} System
57
+ * @typedef {import('./app-config.mjs').DesktopAppConfig} DesktopAppConfig
58
+ */
59
+
60
+ /**
61
+ * @param {string[]} args the arguments after `package`
62
+ * @returns {PackageCommand}
63
+ */
64
+ export function parsePackage(args) {
65
+ const { values } = parseArgs({
66
+ args,
67
+ options: {
68
+ format: { type: 'string', default: 'app' },
69
+ output: { type: 'string', default: DEFAULT_OUTPUT },
70
+ 'feed-url': { type: 'string' },
71
+ 'sparkle-key': { type: 'string' },
72
+ 'skip-notarize': { type: 'boolean', default: false },
73
+ },
74
+ });
75
+ const format = values.format;
76
+ if (!FORMATS.includes(format)) {
77
+ throw new UsageError(`--format takes app, dmg or mas, not "${format}".`);
78
+ }
79
+ const feedUrl = values['feed-url'];
80
+ if (feedUrl !== undefined) {
81
+ if (format !== 'dmg') {
82
+ throw new UsageError(
83
+ `--feed-url is for --format dmg only: ${format === 'mas' ? 'the Mac App Store updates a mas build itself' : 'an app build has no updater'}.`,
84
+ );
85
+ }
86
+ if (!/^https:\/\/[^\s/]+/.test(feedUrl)) {
87
+ throw new UsageError(
88
+ `--feed-url takes the https URL of a Sparkle appcast, not "${feedUrl}".`,
89
+ );
90
+ }
91
+ }
92
+ const sparkleKey = values['sparkle-key'];
93
+ if (sparkleKey !== undefined && feedUrl === undefined) {
94
+ throw new UsageError(
95
+ '--sparkle-key goes with --feed-url, the appcast whose updates it checks.',
96
+ );
97
+ }
98
+ const skipNotarize = values['skip-notarize'];
99
+ if (skipNotarize && format !== 'dmg') {
100
+ throw new UsageError(
101
+ `--skip-notarize is for --format dmg only: ${format === 'mas' ? 'the Mac App Store notarises a mas build itself' : 'an app build is never notarised'}.`,
102
+ );
103
+ }
104
+ return {
105
+ command: 'package',
106
+ format: /** @type {'app' | 'dmg' | 'mas'} */ (format),
107
+ output: values.output,
108
+ feedUrl,
109
+ sparkleKey,
110
+ skipNotarize,
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Stops before anything is built unless full Xcode is selected: the Command Line Tools have no
116
+ * `actool`, which compiles the app icon (and macOS 26's `.icon` files).
117
+ *
118
+ * @param {System} sys
119
+ */
120
+ export function checkXcode(sys) {
121
+ const fix =
122
+ 'Packaging needs full Xcode for the app icon, which the Command Line Tools cannot compile. ' +
123
+ 'Install Xcode, then run: sudo xcode-select -s /Applications/Xcode.app';
124
+ const selected = sys.run('xcode-select', ['-p'], { capture: true });
125
+ if (selected.status !== 0 || /CommandLineTools/.test(selected.stdout)) throw new UsageError(fix);
126
+ if (sys.run('xcrun', ['--find', 'actool'], { capture: true }).status !== 0) {
127
+ throw new UsageError(fix);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * The credentials `notarytool` takes, from the environment: a keychain profile or an App Store
133
+ * Connect API key (the one to use in CI). An app-specific password is refused, because notarytool
134
+ * takes it only as an argument, which any process can read. Throws
135
+ * naming what is missing, so a half-set group never reads as no notarisation.
136
+ *
137
+ * @param {Record<string, string | undefined>} env
138
+ * @returns {string[]}
139
+ */
140
+ export function notaryArguments(env) {
141
+ if (env['NGN_NOTARY_PROFILE']) return ['--keychain-profile', env['NGN_NOTARY_PROFILE']];
142
+ const groups = [
143
+ {
144
+ names: ['APPLE_API_KEY', 'APPLE_API_KEY_ID', 'APPLE_API_ISSUER'],
145
+ flags: ['--key', '--key-id', '--issuer'],
146
+ },
147
+ ];
148
+ for (const { names, flags } of groups) {
149
+ const set = names.filter((name) => env[name]);
150
+ if (set.length === names.length) {
151
+ return names.flatMap((name, index) => [
152
+ /** @type {string} */ (flags[index]),
153
+ String(env[name]),
154
+ ]);
155
+ }
156
+ if (set.length > 0) {
157
+ const missing = names.filter((name) => !env[name]);
158
+ throw new UsageError(`Notarising with ${set.join(', ')} needs ${missing.join(' and ')} too.`);
159
+ }
160
+ }
161
+ // notarytool takes an app-specific password only as a --password argument, which every process
162
+ // on the Mac can read, so it is read from the keychain instead.
163
+ const password = env['APPLE_APP_SPECIFIC_PASSWORD']
164
+ ? 'APPLE_APP_SPECIFIC_PASSWORD is not read, because notarytool would take it as an argument ' +
165
+ 'any process can see. Store it in the keychain once with xcrun notarytool store-credentials ' +
166
+ '<profile>, which prompts for it, and set NGN_NOTARY_PROFILE to the profile. '
167
+ : '';
168
+ throw new UsageError(
169
+ `${password}--format dmg notarises the app, and found no credentials. Set NGN_NOTARY_PROFILE ` +
170
+ 'to a notarytool keychain profile, or APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER.',
171
+ );
172
+ }
173
+
174
+ /** What each refusal of a dmg's credentials adds, for someone only trying the package out. */
175
+ const SKIP_NOTARIZE_HINT =
176
+ ' To try the package on this Mac without them, add --skip-notarize, which makes a dmg no other Mac opens.';
177
+
178
+ /**
179
+ * A `--skip-notarize` dmg's signing: `NGN_SIGN_IDENTITY` when set, else ad hoc, and no notary.
180
+ *
181
+ * @param {string | undefined} feedUrl
182
+ * @param {Record<string, string | undefined>} env
183
+ */
184
+ function localSigning(feedUrl, env) {
185
+ const identity = env['NGN_SIGN_IDENTITY'];
186
+ if (!identity && feedUrl) {
187
+ throw new UsageError(
188
+ '--feed-url needs NGN_SIGN_IDENTITY even with --skip-notarize: Sparkle loads only into an ' +
189
+ 'app signed with a Team ID, and an ad hoc signature has none.',
190
+ );
191
+ }
192
+ return {
193
+ identity: identity || '-',
194
+ installer: undefined,
195
+ // A dmg signed for Sign in with Apple embeds a profile, under --skip-notarize too.
196
+ profile: env['NGN_PROVISIONING_PROFILE'],
197
+ team: env['APPLE_TEAM_ID'],
198
+ notary: null,
199
+ };
200
+ }
201
+
202
+ /**
203
+ * What a dmg signed for Sign in with Apple needs: a restricted entitlement is honoured only in an
204
+ * app signed with a Team ID whose embedded profile grants it, a Developer ID profile for a dmg.
205
+ */
206
+ const DMG_SIGN_IN = ['NGN_SIGN_IDENTITY', 'NGN_PROVISIONING_PROFILE', 'APPLE_TEAM_ID'];
207
+
208
+ /**
209
+ * The environment variables a format needs, by name, each checked before anything is built. A
210
+ * `dmg` with `--skip-notarize` needs none: it signs with `NGN_SIGN_IDENTITY` when that is set and
211
+ * ad hoc (`-`) when not, and never asks Apple.
212
+ *
213
+ * @param {PackageCommand} options
214
+ * @param {Record<string, string | undefined>} env
215
+ */
216
+ function credentials({ format, skipNotarize, feedUrl }, env) {
217
+ if (format === 'app') return null;
218
+ if (feedUrl && env['NGN_SIGN_IDENTITY'] === '-') {
219
+ throw new UsageError(
220
+ "--feed-url needs a NGN_SIGN_IDENTITY other than -, codesign's ad hoc identity: Sparkle " +
221
+ 'loads only into an app signed with a Team ID, and an ad hoc signature has none.',
222
+ );
223
+ }
224
+ if (format === 'dmg' && skipNotarize) return localSigning(feedUrl, env);
225
+ const required =
226
+ format === 'dmg'
227
+ ? ['NGN_SIGN_IDENTITY']
228
+ : [
229
+ 'NGN_SIGN_IDENTITY',
230
+ 'NGN_INSTALLER_IDENTITY',
231
+ 'NGN_PROVISIONING_PROFILE',
232
+ 'APPLE_TEAM_ID',
233
+ ];
234
+ const missing = required.filter((name) => !env[name]);
235
+ if (missing.length > 0) {
236
+ const hint = format === 'dmg' ? SKIP_NOTARIZE_HINT : '';
237
+ throw new UsageError(
238
+ `--format ${format} needs ${missing.join(', ')} set in the environment.${hint}`,
239
+ );
240
+ }
241
+ let notary = null;
242
+ if (format === 'dmg') {
243
+ try {
244
+ notary = notaryArguments(env);
245
+ } catch (error) {
246
+ if (error instanceof UsageError) throw new UsageError(error.message + SKIP_NOTARIZE_HINT);
247
+ throw error;
248
+ }
249
+ }
250
+ return {
251
+ identity: String(env['NGN_SIGN_IDENTITY']),
252
+ installer: env['NGN_INSTALLER_IDENTITY'],
253
+ profile: env['NGN_PROVISIONING_PROFILE'],
254
+ team: env['APPLE_TEAM_ID'],
255
+ notary,
256
+ };
257
+ }
258
+
259
+ /**
260
+ * What a `mas` build cannot do inside the App Sandbox, one line each. Those capabilities report
261
+ * themselves absent in the build.
262
+ *
263
+ * @param {DesktopAppConfig} config
264
+ */
265
+ export function sandboxProblems(config) {
266
+ const capabilities = config.options.capabilities ?? {};
267
+ const problems = [];
268
+ if ((capabilities.spawn ?? []).length > 0) {
269
+ problems.push(
270
+ 'capabilities.spawn: the App Sandbox runs no program outside the app, so Processes.spawn is absent in a mas build.',
271
+ );
272
+ }
273
+ if ((capabilities.paths ?? []).length > 0) {
274
+ problems.push(
275
+ 'capabilities.paths: the App Sandbox reaches only the files the user picks, so declared paths are absent in a mas build.',
276
+ );
277
+ }
278
+ return problems;
279
+ }
280
+
281
+ /**
282
+ * The app's `Info.plist`: the Expo keys' settings, the document types and URL schemes, what the
283
+ * host reads before JavaScript runs (the bundle, the capabilities, the updates server and how it
284
+ * was distributed, and the certificate updates are signed with), and Sparkle's feed and public key
285
+ * in a `dmg` that has one. Sparkle checks for updates on its own schedule by default
286
+ * (`SUEnableAutomaticChecks`), so it does not ask the user on the second launch whether to.
287
+ *
288
+ * @param {DesktopAppConfig} config
289
+ * @param {{ format: 'app' | 'dmg' | 'mas', executable: string, bundleIdentifier: string, iconName: string | null, feedUrl?: string, sparkleKey?: string, updatesCertificate?: string }} options
290
+ */
291
+ export function infoPlist(
292
+ config,
293
+ { format, executable, bundleIdentifier, iconName, feedUrl, sparkleKey, updatesCertificate },
294
+ ) {
295
+ const signing = updatesCertificate
296
+ ? {
297
+ NGNUpdatesCodeSigningCertificate: updatesCertificate,
298
+ NGNUpdatesCodeSigningKeyId: config.updatesCodeSigning?.keyId ?? 'main',
299
+ NGNUpdatesCodeSigningAlg: config.updatesCodeSigning?.alg ?? 'rsa-v1_5-sha256',
300
+ }
301
+ : {};
302
+ const { options, permissions } = config;
303
+ return plist({
304
+ CFBundleDevelopmentRegion: 'en',
305
+ CFBundleDisplayName: config.name,
306
+ CFBundleExecutable: executable,
307
+ CFBundleIdentifier: bundleIdentifier,
308
+ CFBundleInfoDictionaryVersion: '6.0',
309
+ CFBundleName: config.name,
310
+ CFBundlePackageType: 'APPL',
311
+ CFBundleShortVersionString: config.version,
312
+ CFBundleVersion: config.buildNumber,
313
+ CFBundleIconName: iconName,
314
+ CFBundleIconFile: iconName,
315
+ CFBundleURLTypes:
316
+ config.schemes.length > 0
317
+ ? [{ CFBundleURLName: bundleIdentifier, CFBundleURLSchemes: config.schemes }]
318
+ : undefined,
319
+ CFBundleDocumentTypes: options.documentTypes?.map((type) => ({
320
+ CFBundleTypeName: type.name,
321
+ CFBundleTypeRole: type.role === 'viewer' ? 'Viewer' : 'Editor',
322
+ CFBundleTypeExtensions: [...type.extensions],
323
+ LSItemContentTypes: type.utis ? [...type.utis] : undefined,
324
+ CFBundleTypeIconFile: type.icon ? path.basename(type.icon) : undefined,
325
+ })),
326
+ LSMinimumSystemVersion: MINIMUM_MACOS,
327
+ NSHighResolutionCapable: true,
328
+ NSPrincipalClass: 'NSApplication',
329
+ ...permissions.usageStrings,
330
+ NGNBundleFile: 'main.jsbundle',
331
+ NGNModuleName: 'main',
332
+ NGNDistribution: format,
333
+ NGNCapabilities: hostCapabilities(options),
334
+ NGNUpdatesURL: config.updatesUrl,
335
+ NGNRuntimeVersion: config.runtimeVersion,
336
+ ...signing,
337
+ SUFeedURL: feedUrl,
338
+ SUPublicEDKey: feedUrl ? sparkleKey : undefined,
339
+ SUEnableAutomaticChecks: feedUrl ? true : undefined,
340
+ });
341
+ }
342
+
343
+ /** The package whose use signs an app for Sign in with Apple. */
344
+ const APPLE_AUTHENTICATION = 'expo-apple-authentication';
345
+
346
+ /**
347
+ * Whether each format is signed with the Sign in with Apple entitlement, decided as the iOS build
348
+ * decides it: a `mas` build whenever the app uses `expo-apple-authentication` (its config plugin
349
+ * listed, or the package installed, which Expo applies the plugin for) or sets
350
+ * `ios.usesAppleSignIn`; a `dmg` only when `ios.usesAppleSignIn` asks, since it then needs a
351
+ * Developer ID profile that a dmg has no other use for.
352
+ *
353
+ * @param {import('./app-config.mjs').ExpoConfig} expo
354
+ * @param {boolean} installed whether the app has `expo-apple-authentication` installed
355
+ */
356
+ export function appleSignIn(expo, installed) {
357
+ const listed = (expo.plugins ?? []).some(
358
+ (entry) => (Array.isArray(entry) ? entry[0] : entry) === APPLE_AUTHENTICATION,
359
+ );
360
+ const asked = expo.ios?.usesAppleSignIn === true;
361
+ return { mas: asked || listed || installed, dmg: asked };
362
+ }
363
+
364
+ /** The package whose use signs an app for remote notifications. */
365
+ const NOTIFICATIONS = 'expo-notifications';
366
+
367
+ /**
368
+ * Whether each format is signed for remote notifications (APNs), decided as the iOS build decides
369
+ * it: a `mas` build whenever the app uses `expo-notifications` (its config plugin listed, or the
370
+ * package installed) or sets `ios.entitlements['aps-environment']`; a `dmg` only when that
371
+ * entitlement is set, since it then needs a Developer ID profile, as Sign in with Apple does.
372
+ *
373
+ * @param {import('./app-config.mjs').ExpoConfig} expo
374
+ * @param {boolean} installed whether the app has `expo-notifications` installed
375
+ */
376
+ export function remotePush(expo, installed) {
377
+ const listed = (expo.plugins ?? []).some(
378
+ (entry) => (Array.isArray(entry) ? entry[0] : entry) === NOTIFICATIONS,
379
+ );
380
+ const asked = typeof expo.ios?.entitlements?.['aps-environment'] === 'string';
381
+ return { mas: asked || listed || installed, dmg: asked };
382
+ }
383
+
384
+ /**
385
+ * Whether a dmg asking for `capability` can be signed for it: a signing identity, a Developer ID
386
+ * profile and its team, checked before anything is built, since macOS opens no app with a
387
+ * restricted entitlement and no profile granting it.
388
+ *
389
+ * @param {System} sys
390
+ * @param {string} capability what asked, as the error names it
391
+ */
392
+ function requireDmgProfile(sys, capability) {
393
+ const missing = DMG_SIGN_IN.filter((name) => !sys.env[name]);
394
+ if (missing.length > 0) {
395
+ throw new UsageError(
396
+ `${capability} in a dmg needs ${missing.join(', ')} set in the environment: a Developer ID ` +
397
+ 'provisioning profile with the capability, and its team. Without them macOS would not ' +
398
+ 'open the app.',
399
+ );
400
+ }
401
+ }
402
+
403
+ /**
404
+ * Whether this build is signed for remote notifications (`remotePush`), with the dmg's profile
405
+ * checked as for Sign in with Apple.
406
+ *
407
+ * @param {System} sys
408
+ * @param {import('./app-config.mjs').ExpoConfig} expo
409
+ * @param {'app' | 'dmg' | 'mas'} format
410
+ */
411
+ function receivesPush(sys, expo, format) {
412
+ const uses = remotePush(expo, sys.resolvePackage(sys.cwd(), NOTIFICATIONS) !== null);
413
+ if (format === 'mas') return uses.mas;
414
+ if (format !== 'dmg' || !uses.dmg) return false;
415
+ requireDmgProfile(sys, "Remote notifications (ios.entitlements['aps-environment'])");
416
+ return true;
417
+ }
418
+
419
+ /**
420
+ * Whether this build is signed for Sign in with Apple (`appleSignIn`). A dmg that is needs a
421
+ * signing identity, a Developer ID profile and its team, checked before anything is built: macOS
422
+ * opens no app with a restricted entitlement and no profile granting it.
423
+ *
424
+ * @param {System} sys
425
+ * @param {import('./app-config.mjs').ExpoConfig} expo
426
+ * @param {'app' | 'dmg' | 'mas'} format
427
+ */
428
+ function signsInWithApple(sys, expo, format) {
429
+ const uses = appleSignIn(expo, sys.resolvePackage(sys.cwd(), APPLE_AUTHENTICATION) !== null);
430
+ if (format === 'mas') return uses.mas;
431
+ if (format !== 'dmg' || !uses.dmg) return false;
432
+ requireDmgProfile(sys, 'Sign in with Apple (ios.usesAppleSignIn)');
433
+ return true;
434
+ }
435
+
436
+ /**
437
+ * The entitlements the app is signed with: none for `app`; for `dmg` the hardened runtime's for
438
+ * the devices and data the usage strings declare; for `mas` the App Sandbox with those, the
439
+ * network, the files the user picks, and the app's identity on the team. `appleSignIn` adds Sign
440
+ * in with Apple and `push` remote notifications (production APNs, which both distribution formats
441
+ * use), and either adds to a `dmg` the app's identity on the team, which its profile is for.
442
+ *
443
+ * @param {DesktopAppConfig} config
444
+ * @param {'app' | 'dmg' | 'mas'} format
445
+ * @param {{ bundleIdentifier: string, team?: string, appleSignIn?: boolean, push?: boolean }} identity
446
+ * @returns {string | null}
447
+ */
448
+ export function entitlements(
449
+ config,
450
+ format,
451
+ { bundleIdentifier, team, appleSignIn = false, push = false },
452
+ ) {
453
+ if (format === 'app') return null;
454
+ /** @type {import('./plist.mjs').PlistDict} */
455
+ const granted = Object.fromEntries(
456
+ config.permissions.sandboxEntitlements.map((entitlement) => [entitlement, true]),
457
+ );
458
+ if (appleSignIn) granted['com.apple.developer.applesignin'] = ['Default'];
459
+ if (push) granted['com.apple.developer.aps-environment'] = 'production';
460
+ if (format === 'dmg') {
461
+ if (!appleSignIn && !push) return plist(granted);
462
+ return plist({
463
+ ...granted,
464
+ 'com.apple.application-identifier': `${team}.${bundleIdentifier}`,
465
+ 'com.apple.developer.team-identifier': team,
466
+ });
467
+ }
468
+ return plist({
469
+ 'com.apple.security.app-sandbox': true,
470
+ 'com.apple.security.network.client': true,
471
+ 'com.apple.security.files.user-selected.read-write': true,
472
+ // The bookmarks that keep the user's picks reachable in later launches.
473
+ 'com.apple.security.files.bookmarks.app-scope': true,
474
+ ...granted,
475
+ 'com.apple.application-identifier': `${team}.${bundleIdentifier}`,
476
+ 'com.apple.developer.team-identifier': team,
477
+ });
478
+ }
479
+
480
+ /** The point sizes of a macOS app icon, each at 1x and 2x. */
481
+ const ICON_SIZES = [16, 32, 128, 256, 512];
482
+
483
+ /**
484
+ * Compiles the app icon into `resources` with `actool`, and answers its name for `Info.plist`. An
485
+ * Icon Composer `.icon` folder goes to `actool` as it is; an image is first scaled into an asset
486
+ * catalog's icon set with `sips`.
487
+ *
488
+ * @param {System} sys
489
+ * @param {string} icon the icon's absolute path
490
+ * @param {string} resources the bundle's Resources folder
491
+ * @param {string} staging a folder for what is built on the way
492
+ */
493
+ export function compileIcon(sys, icon, resources, staging) {
494
+ const composer = icon.endsWith('.icon');
495
+ const name = composer ? path.basename(icon, '.icon') : 'AppIcon';
496
+ let input = icon;
497
+ if (!composer) {
498
+ const catalog = path.join(staging, 'Assets.xcassets');
499
+ const set = path.join(catalog, 'AppIcon.appiconset');
500
+ const images = ICON_SIZES.flatMap((size) =>
501
+ [1, 2].map((scale) => ({
502
+ size: `${size}x${size}`,
503
+ scale: `${scale}x`,
504
+ idiom: 'mac',
505
+ filename: `icon_${size}x${size}${scale === 2 ? '@2x' : ''}.png`,
506
+ pixels: size * scale,
507
+ })),
508
+ );
509
+ sys.writeFile(path.join(catalog, 'Contents.json'), JSON.stringify({ info: { version: 1 } }));
510
+ // Written first: it makes the set's folder, and sips writes into a folder only when it is there.
511
+ const contents = images.map(({ pixels: _, ...entry }) => entry);
512
+ sys.writeFile(
513
+ path.join(set, 'Contents.json'),
514
+ JSON.stringify({ images: contents, info: { version: 1 } }, null, 2),
515
+ );
516
+ for (const image of images) {
517
+ const out = path.join(set, image.filename);
518
+ const px = String(image.pixels);
519
+ expectSuccess(
520
+ sys.run('sips', ['-s', 'format', 'png', '-z', px, px, icon, '--out', out], {
521
+ capture: true,
522
+ }),
523
+ `sips could not scale ${icon} to ${px} pixels.`,
524
+ );
525
+ }
526
+ input = catalog;
527
+ }
528
+ expectSuccess(
529
+ sys.run('xcrun', [
530
+ 'actool',
531
+ input,
532
+ '--compile',
533
+ resources,
534
+ '--platform',
535
+ 'macosx',
536
+ '--minimum-deployment-target',
537
+ MINIMUM_MACOS,
538
+ '--app-icon',
539
+ name,
540
+ '--output-partial-info-plist',
541
+ path.join(staging, 'icon-info.plist'),
542
+ ]),
543
+ `actool could not compile the app icon ${icon}.`,
544
+ );
545
+ return name;
546
+ }
547
+
548
+ /**
549
+ * @param {{ status: number }} result
550
+ * @param {string} message
551
+ */
552
+ function expectSuccess(result, message) {
553
+ if (result.status !== 0) throw new Error(message);
554
+ }
555
+
556
+ /**
557
+ * Submits `file` to Apple's notary service and waits, failing unless Apple accepts it, then staples
558
+ * the ticket to `staple`. The status is read from notarytool's JSON, so a rejected submission never
559
+ * reads as done. stapler takes an app or a dmg and refuses a zip, so an app sent as a zip is
560
+ * stapled itself.
561
+ *
562
+ * @param {System} sys
563
+ * @param {string} file
564
+ * @param {string[]} notary
565
+ * @param {string} [staple]
566
+ */
567
+ function notarise(sys, file, notary, staple = file) {
568
+ const result = sys.run(
569
+ 'xcrun',
570
+ ['notarytool', 'submit', file, '--wait', '--output-format', 'json', ...notary],
571
+ { capture: true },
572
+ );
573
+ /** @type {{ status?: string, id?: string } | null} */
574
+ let answer = null;
575
+ try {
576
+ answer = JSON.parse(result.stdout);
577
+ } catch {
578
+ answer = null;
579
+ }
580
+ if (result.status !== 0 || answer?.status !== 'Accepted') {
581
+ const id = answer?.id ? ` Run xcrun notarytool log ${answer.id} for Apple's reasons.` : '';
582
+ throw new Error(
583
+ `Apple did not notarise ${path.basename(file)}: ${answer?.status ?? 'no answer'}.${id}`,
584
+ );
585
+ }
586
+ expectSuccess(
587
+ sys.run('xcrun', ['stapler', 'staple', staple]),
588
+ `stapler could not staple ${path.basename(staple)}.`,
589
+ );
590
+ }
591
+
592
+ /**
593
+ * Sparkle's public EdDSA key for a package with a feed: `--sparkle-key`, else
594
+ * `NGN_SPARKLE_PUBLIC_KEY`. Without one Sparkle would refuse every update, so it stops first.
595
+ *
596
+ * @param {PackageCommand} options
597
+ * @param {Record<string, string | undefined>} env
598
+ */
599
+ function sparkleKeyFor(options, env) {
600
+ if (!options.feedUrl) return undefined;
601
+ const key = options.sparkleKey ?? env['NGN_SPARKLE_PUBLIC_KEY'];
602
+ if (!key) {
603
+ throw new UsageError(
604
+ "--feed-url needs Sparkle's public EdDSA key, which Sparkle checks each update against: " +
605
+ "pass --sparkle-key or set NGN_SPARKLE_PUBLIC_KEY to the key Sparkle's generate_keys prints.",
606
+ );
607
+ }
608
+ return key;
609
+ }
610
+
611
+ /**
612
+ * The PEM certificate update manifests are signed with, read from `updates.codeSigningCertificate`.
613
+ *
614
+ * @param {System} sys
615
+ * @param {string} cwd
616
+ * @param {DesktopAppConfig} config
617
+ */
618
+ function certificateOf(sys, cwd, config) {
619
+ const signing = config.updatesCodeSigning;
620
+ return signing ? sys.readFile(path.resolve(cwd, signing.certificate)) : undefined;
621
+ }
622
+
623
+ /**
624
+ * The `hermesc` the host build in `buildDir` puts beside its binary, built with the Hermes the
625
+ * binary links. Expo's own compiler can be another Hermes version, whose bytecode the host would
626
+ * refuse.
627
+ *
628
+ * @param {System} sys
629
+ * @param {string} buildDir
630
+ */
631
+ export function hermesCompiler(sys, buildDir) {
632
+ const hermesc = path.join(buildDir, 'appkit', 'hermesc');
633
+ if (!sys.exists(hermesc)) {
634
+ throw new Error(
635
+ `The desktop host in ${buildDir} has no hermesc beside it, so the bundle cannot be compiled ` +
636
+ 'to Hermes bytecode. Delete that folder and package again to rebuild it.',
637
+ );
638
+ }
639
+ return hermesc;
640
+ }
641
+
642
+ /**
643
+ * Compiles the JavaScript bundle at `source` to Hermes bytecode at `out`, optimised as React
644
+ * Native's iOS release build does.
645
+ *
646
+ * @param {System} sys
647
+ * @param {string} hermesc
648
+ * @param {string} source
649
+ * @param {string} out
650
+ */
651
+ function compileBytecode(sys, hermesc, source, out) {
652
+ expectSuccess(
653
+ sys.run(hermesc, ['-emit-binary', '-O', '-w', '-max-diagnostic-width=80', '-out', out, source]),
654
+ 'hermesc could not compile the bundle to Hermes bytecode; the output above says why.',
655
+ );
656
+ }
657
+
658
+ /**
659
+ * Copies each document type's icon into `resources`. The plist names it by its file, which has to
660
+ * be in the bundle for Finder to find it.
661
+ *
662
+ * @param {System} sys
663
+ * @param {string} cwd
664
+ * @param {DesktopAppConfig} config
665
+ * @param {string} resources
666
+ */
667
+ function copyDocumentIcons(sys, cwd, config, resources) {
668
+ for (const type of config.options.documentTypes ?? []) {
669
+ if (type.icon) {
670
+ sys.copy(path.resolve(cwd, type.icon), path.join(resources, path.basename(type.icon)));
671
+ }
672
+ }
673
+ }
674
+
675
+ /**
676
+ * Builds the app and makes the package `options.format` asks for. Returns the exit status.
677
+ *
678
+ * @param {PackageCommand} options
679
+ * @param {System} sys
680
+ */
681
+ export async function packageApp(options, sys) {
682
+ if (sys.platform !== 'darwin') {
683
+ throw new UsageError('Packaging for macOS runs on macOS only.');
684
+ }
685
+ checkXcode(sys);
686
+ const expo = readExpoConfig(sys, sys.cwd());
687
+ const signIn = signsInWithApple(sys, expo, options.format);
688
+ const push = receivesPush(sys, expo, options.format);
689
+ const keys = credentials(options, sys.env);
690
+ const sparkleKey = sparkleKeyFor(options, sys.env);
691
+ const { cwd, config, buildDir } = prepareHost(sys, { universal: true, release: true, expo });
692
+ const hermesc = hermesCompiler(sys, buildDir);
693
+ if (options.format === 'mas') for (const line of sandboxProblems(config)) sys.warn(line);
694
+ const bundleIdentifier = config.bundleIdentifier ?? fallbackIdentifier(options.format, expo);
695
+
696
+ const output = path.resolve(cwd, options.output);
697
+ const staging = path.join(cwd, '.expo', 'ng-native-desktop', 'package');
698
+ const app = path.join(output, `${config.name}.app`);
699
+ const contents = path.join(app, 'Contents');
700
+ const resources = path.join(contents, 'Resources');
701
+ sys.remove(app);
702
+ sys.remove(staging);
703
+
704
+ const javascript = path.join(staging, 'main.js');
705
+ expectSuccess(
706
+ sys.expo(cwd, [
707
+ 'export:embed',
708
+ '--platform',
709
+ 'macos',
710
+ '--dev',
711
+ 'false',
712
+ '--bundle-output',
713
+ javascript,
714
+ '--assets-dest',
715
+ resources,
716
+ ]),
717
+ 'expo export:embed did not bundle the app for macos; the output above says why.',
718
+ );
719
+ compileBytecode(sys, hermesc, javascript, path.join(resources, 'main.jsbundle'));
720
+ const executable = path.join(contents, 'MacOS', config.name);
721
+ sys.copy(path.join(buildDir, 'appkit', 'ngn-macos'), executable);
722
+ // Local symbols only, which nothing resolves at run time; the exported ones stay.
723
+ expectSuccess(sys.run('strip', ['-x', executable]), `strip could not strip ${executable}.`);
724
+ const iconName = config.icon
725
+ ? compileIcon(sys, path.resolve(cwd, config.icon), resources, staging)
726
+ : null;
727
+ copyDocumentIcons(sys, cwd, config, resources);
728
+ if (options.feedUrl) embedSparkle(sys, buildDir, contents);
729
+ sys.writeFile(
730
+ path.join(contents, 'Info.plist'),
731
+ infoPlist(config, {
732
+ format: options.format,
733
+ executable: config.name,
734
+ bundleIdentifier,
735
+ iconName,
736
+ feedUrl: options.feedUrl,
737
+ sparkleKey,
738
+ updatesCertificate: certificateOf(sys, cwd, config),
739
+ }),
740
+ );
741
+ sys.writeFile(path.join(contents, 'PkgInfo'), 'APPL????');
742
+
743
+ const made = [app];
744
+ if (options.format === 'app') {
745
+ expectSuccess(sys.run('codesign', ['--force', '--sign', '-', app]), 'codesign failed.');
746
+ } else if (options.format === 'dmg' && keys) {
747
+ made.push(
748
+ ...shipDmg(sys, {
749
+ config,
750
+ app,
751
+ output,
752
+ staging,
753
+ bundleIdentifier,
754
+ keys,
755
+ options,
756
+ signIn,
757
+ push,
758
+ }),
759
+ );
760
+ } else if (keys) {
761
+ made.push(shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, signIn, push }));
762
+ }
763
+ for (const file of made) console.log(path.relative(cwd, file));
764
+ return 0;
765
+ }
766
+
767
+ /**
768
+ * A `dmg` or `mas` build needs the app's own bundle identifier; an `app` build for this Mac makes
769
+ * one up from the slug.
770
+ *
771
+ * @param {'app' | 'dmg' | 'mas'} format
772
+ * @param {import('./app-config.mjs').ExpoConfig} expo
773
+ */
774
+ function fallbackIdentifier(format, expo) {
775
+ if (format !== 'app') {
776
+ throw new UsageError(
777
+ `--format ${format} signs the app with its bundle identifier, and app.json sets none. Set ` +
778
+ 'expo.ios.bundleIdentifier, which macOS shares with iOS.',
779
+ );
780
+ }
781
+ const slug = (expo.slug ?? expo.name ?? 'app').toLowerCase().replace(/[^a-z0-9]/g, '');
782
+ return `dev.ngnative.${slug || 'app'}`;
783
+ }
784
+
785
+ /**
786
+ * Sparkle, from the host build, into the app's Frameworks.
787
+ *
788
+ * @param {System} sys
789
+ * @param {string} buildDir
790
+ * @param {string} contents
791
+ */
792
+ function embedSparkle(sys, buildDir, contents) {
793
+ const sparkle = path.join(buildDir, 'appkit', 'Sparkle.framework');
794
+ if (!sys.exists(sparkle)) {
795
+ throw new Error(
796
+ 'This desktop host was built without Sparkle, so --feed-url cannot be embedded. Package ' +
797
+ 'without --feed-url, or update @ng-native/desktop.',
798
+ );
799
+ }
800
+ sys.copy(sparkle, path.join(contents, 'Frameworks', 'Sparkle.framework'));
801
+ }
802
+
803
+ /**
804
+ * Signs with the hardened runtime, notarises and staples the app, zips it for Sparkle when there
805
+ * is a feed, then makes, signs, notarises and staples the `.dmg`. With no notary credentials
806
+ * (`--skip-notarize`) nothing goes to Apple, and an ad hoc signature takes no timestamp, which
807
+ * only a real identity can get.
808
+ *
809
+ * @param {System} sys
810
+ * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, options: PackageCommand, signIn: boolean, push: boolean }} build
811
+ * @returns {string[]} the files made beside the app
812
+ */
813
+ function shipDmg(
814
+ sys,
815
+ { config, app, output, staging, bundleIdentifier, keys, options, signIn, push },
816
+ ) {
817
+ if (signIn || push) embedProfile(sys, keys, app);
818
+ const file = path.join(staging, 'entitlements.plist');
819
+ const granted = entitlements(config, 'dmg', {
820
+ bundleIdentifier,
821
+ team: keys.team,
822
+ appleSignIn: signIn,
823
+ push,
824
+ });
825
+ sys.writeFile(file, /** @type {string} */ (granted));
826
+ const timestamp = keys.identity === '-' ? '--timestamp=none' : '--timestamp';
827
+ /** @param {string} target @param {string[]} [extra] */
828
+ const sign = (target, extra = []) =>
829
+ expectSuccess(
830
+ sys.run('codesign', [
831
+ '--force',
832
+ '--options',
833
+ 'runtime',
834
+ timestamp,
835
+ ...extra,
836
+ '--sign',
837
+ keys.identity,
838
+ target,
839
+ ]),
840
+ `codesign could not sign ${path.basename(target)}.`,
841
+ );
842
+ if (options.feedUrl) signSparkle(path.join(app, 'Contents', 'Frameworks', 'Sparkle.framework'));
843
+ sign(app, ['--entitlements', file]);
844
+
845
+ /**
846
+ * Sparkle's nested code before the framework, inside out, as Sparkle documents for signing
847
+ * outside Xcode (sparkle-project.org/documentation/sandboxing): no `--deep`, since the Downloader
848
+ * service keeps the entitlements it ships with and the rest take none.
849
+ *
850
+ * @param {string} framework
851
+ */
852
+ function signSparkle(framework) {
853
+ const version = path.join(framework, 'Versions', 'B');
854
+ sign(path.join(version, 'XPCServices', 'Installer.xpc'));
855
+ sign(path.join(version, 'XPCServices', 'Downloader.xpc'), ['--preserve-metadata=entitlements']);
856
+ sign(path.join(version, 'Autoupdate'));
857
+ sign(path.join(version, 'Updater.app'));
858
+ sign(framework);
859
+ }
860
+
861
+ if (keys.notary) {
862
+ const submission = path.join(staging, `${config.name}.zip`);
863
+ zip(sys, app, submission);
864
+ notarise(sys, submission, keys.notary, app);
865
+ }
866
+
867
+ const made = [];
868
+ if (options.feedUrl) {
869
+ const update = path.join(output, `${config.name}.zip`);
870
+ zip(sys, app, update);
871
+ made.push(update);
872
+ }
873
+ const dmg = path.join(output, `${config.name}.dmg`);
874
+ expectSuccess(
875
+ sys.run('hdiutil', [
876
+ 'create',
877
+ '-volname',
878
+ config.name,
879
+ '-srcfolder',
880
+ app,
881
+ '-ov',
882
+ '-format',
883
+ 'UDZO',
884
+ dmg,
885
+ ]),
886
+ 'hdiutil could not make the disk image.',
887
+ );
888
+ expectSuccess(
889
+ sys.run('codesign', ['--force', timestamp, '--sign', keys.identity, dmg]),
890
+ 'codesign could not sign the disk image.',
891
+ );
892
+ if (keys.notary) {
893
+ notarise(sys, dmg, keys.notary);
894
+ } else {
895
+ sys.warn(
896
+ `${path.basename(dmg)} is not notarised (--skip-notarize): it is for testing on this Mac ` +
897
+ 'only, and Gatekeeper refuses it on any other.',
898
+ );
899
+ }
900
+ made.push(dmg);
901
+ return made;
902
+ }
903
+
904
+ /**
905
+ * @param {System} sys
906
+ * @param {string} app
907
+ * @param {string} to
908
+ */
909
+ function zip(sys, app, to) {
910
+ expectSuccess(
911
+ sys.run('ditto', ['-c', '-k', '--keepParent', app, to]),
912
+ `ditto could not zip ${path.basename(app)}.`,
913
+ );
914
+ }
915
+
916
+ /**
917
+ * The provisioning profile in `NGN_PROVISIONING_PROFILE`, embedded where macOS reads it.
918
+ *
919
+ * @param {System} sys
920
+ * @param {NonNullable<ReturnType<typeof credentials>>} keys
921
+ * @param {string} app
922
+ */
923
+ function embedProfile(sys, keys, app) {
924
+ sys.copy(
925
+ path.resolve(String(keys.profile)),
926
+ path.join(app, 'Contents', 'embedded.provisionprofile'),
927
+ );
928
+ }
929
+
930
+ /**
931
+ * Embeds the provisioning profile, signs inside the App Sandbox and makes the installer package.
932
+ *
933
+ * @param {System} sys
934
+ * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, signIn: boolean, push: boolean }} build
935
+ */
936
+ function shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, signIn, push }) {
937
+ embedProfile(sys, keys, app);
938
+ const file = path.join(staging, 'entitlements.plist');
939
+ const granted = entitlements(config, 'mas', {
940
+ bundleIdentifier,
941
+ team: keys.team,
942
+ appleSignIn: signIn,
943
+ push,
944
+ });
945
+ sys.writeFile(file, /** @type {string} */ (granted));
946
+ expectSuccess(
947
+ sys.run('codesign', [
948
+ '--force',
949
+ '--timestamp',
950
+ '--entitlements',
951
+ file,
952
+ '--sign',
953
+ keys.identity,
954
+ app,
955
+ ]),
956
+ `codesign could not sign ${path.basename(app)}.`,
957
+ );
958
+ const pkg = path.join(output, `${config.name}.pkg`);
959
+ expectSuccess(
960
+ sys.run('productbuild', [
961
+ '--component',
962
+ app,
963
+ '/Applications',
964
+ '--sign',
965
+ String(keys.installer),
966
+ pkg,
967
+ ]),
968
+ 'productbuild could not make the installer package.',
969
+ );
970
+ return pkg;
971
+ }