peachsim 0.1.1716 → 0.1.1738

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 (282) hide show
  1. package/README.md +21 -3
  2. package/cli/app-bundle-resources.ts +2 -1
  3. package/cli/app-fonts.ts +4 -4
  4. package/cli/app-splash.ts +4 -4
  5. package/cli/app-stubs.ts +17 -0
  6. package/cli/command-registry.ts +1 -0
  7. package/cli/commands/control.ts +83 -822
  8. package/cli/commands/coverage-swift.ts +112 -4
  9. package/cli/commands/daemon.ts +8 -0
  10. package/cli/commands/detox.ts +3 -0
  11. package/cli/commands/doctor.ts +19 -2
  12. package/cli/commands/inspect/actions.ts +74 -14
  13. package/cli/commands/inspect/core.ts +5 -1
  14. package/cli/commands/inspect/settling.ts +5 -2
  15. package/cli/commands/inspect/wait-ready.ts +6 -0
  16. package/cli/commands/inspect.ts +48 -45
  17. package/cli/commands/kotlin.ts +12 -2
  18. package/cli/commands/package.ts +760 -0
  19. package/cli/commands/serve.ts +6 -0
  20. package/cli/commands/shell-url.ts +838 -0
  21. package/cli/commands/swift.ts +42 -102
  22. package/cli/commands/test.ts +20 -0
  23. package/cli/commands/upload.ts +1 -1
  24. package/cli/device-option.ts +1 -1
  25. package/cli/main.ts +13 -1
  26. package/cli/native-input.ts +199 -0
  27. package/cli/outbound-endpoints.ts +26 -1
  28. package/cli/packaged-app-launcher.ts +95 -0
  29. package/cli/scene-video.ts +36 -12
  30. package/detox/index.ts +196 -24
  31. package/dist-lib/agent-daemon-client.cjs +1 -1
  32. package/dist-lib/agent-events.cjs +1 -1
  33. package/dist-lib/attached-projects.cjs +5 -2
  34. package/dist-lib/auth/shared-session.cjs +5 -2
  35. package/dist-lib/backend-origin.cjs +1 -1
  36. package/dist-lib/beta.cjs +1 -1
  37. package/dist-lib/beta.mjs +1 -1
  38. package/dist-lib/bridge-constants.cjs +1 -1
  39. package/dist-lib/bridge-contract-input.cjs +1 -1
  40. package/dist-lib/bridge-contract-input.mjs +1 -1
  41. package/dist-lib/bridge-contract.cjs +1 -1
  42. package/dist-lib/bridge-contract.mjs +1 -1
  43. package/dist-lib/bundle-channel.cjs +39889 -31873
  44. package/dist-lib/capture-contract.cjs +1 -1
  45. package/dist-lib/capture-contract.mjs +1 -1
  46. package/dist-lib/cloud-contract.cjs +1 -1
  47. package/dist-lib/cloud-contract.mjs +1 -1
  48. package/dist-lib/cloud-test-args.cjs +1 -1
  49. package/dist-lib/cloud-test-args.mjs +1 -1
  50. package/dist-lib/cloud.cjs +1 -1
  51. package/dist-lib/cloud.mjs +1 -1
  52. package/dist-lib/config.cjs +1 -1
  53. package/dist-lib/config.mjs +1 -1
  54. package/dist-lib/detox/index.cjs +195 -63
  55. package/dist-lib/dev-bundle-resolution.cjs +14 -13
  56. package/dist-lib/expo-swift-bundle.cjs +18507 -11835
  57. package/dist-lib/expo-swift-metadata.cjs +4 -1
  58. package/dist-lib/expo-swift-metadata.mjs +3 -1
  59. package/dist-lib/home-paths.cjs +27 -3
  60. package/dist-lib/host/bridge-host.cjs +28373 -24090
  61. package/dist-lib/host/fetch-proxy-handler.cjs +235 -225
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +915 -399
  67. package/dist-lib/jump-to-source-babel.cjs +1 -1
  68. package/dist-lib/jump-to-source-native.cjs +1 -1
  69. package/dist-lib/kotlin-host.cjs +335 -47
  70. package/dist-lib/menu.cjs +13 -1
  71. package/dist-lib/menu.mjs +13 -1
  72. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  73. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  74. package/dist-lib/metro-production-bundle.cjs +1 -1
  75. package/dist-lib/metro-production-bundle.mjs +1 -1
  76. package/dist-lib/metro.cjs +918 -411
  77. package/dist-lib/native-app-identity-project.cjs +703 -283
  78. package/dist-lib/native-app-identity-project.mjs +500 -87
  79. package/dist-lib/native-app-identity.cjs +13 -2
  80. package/dist-lib/native-app-identity.mjs +13 -2
  81. package/dist-lib/native-firebase-metadata.cjs +1 -1
  82. package/dist-lib/native-firebase-metadata.mjs +1 -1
  83. package/dist-lib/plist.cjs +1 -1
  84. package/dist-lib/plist.mjs +1 -1
  85. package/dist-lib/profiles.cjs +5 -2
  86. package/dist-lib/public-brand.cjs +1 -1
  87. package/dist-lib/public-origins-lib-esm.json +28 -23
  88. package/dist-lib/public-origins-lib.json +418 -224
  89. package/dist-lib/react-native-host-modules.cjs +35 -2
  90. package/dist-lib/react-native-host-modules.mjs +35 -2
  91. package/dist-lib/reap-browser.cjs +12 -4
  92. package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
  93. package/dist-lib/sdk.cjs +17 -7
  94. package/dist-lib/sdk.mjs +16 -7
  95. package/dist-lib/skills.cjs +44825 -29141
  96. package/dist-lib/swift-compile.cjs +616 -400
  97. package/dist-lib/swift-compile.mjs +528 -315
  98. package/dist-lib/swift-package.cjs +1 -1
  99. package/dist-lib/swift-package.mjs +1 -1
  100. package/dist-lib/swift-submit.cjs +2 -2
  101. package/dist-lib/swift-submit.mjs +2 -2
  102. package/dist-lib/swift-toolchain.cjs +105 -17
  103. package/dist-lib/swift.cjs +1 -1
  104. package/dist-lib/vite-swift.cjs +4660 -2252
  105. package/dist-lib/vite.cjs +248 -234
  106. package/dist-lib/worklet-executable.cjs +1 -1
  107. package/dist-lib/worklet-executable.mjs +1 -1
  108. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
  109. package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
  110. package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +7 -4
  111. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +9 -6
  112. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +0 -5
  113. package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +11 -1
  114. package/dist-types/packages/peach-engine/src/engine/node.d.ts +5 -12
  115. package/dist-types/packages/peach-engine/src/engine/render-damage.d.ts +2 -2
  116. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +5 -0
  117. package/dist-types/packages/peach-engine/src/engine/text-paragraph.d.ts +1 -0
  118. package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
  119. package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +2 -0
  120. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
  121. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  122. package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
  123. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +7 -2
  124. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +5 -0
  125. package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
  126. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +36 -2
  127. package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
  128. package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
  129. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  130. package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
  131. package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
  132. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
  133. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  134. package/kotlin/README.md +3 -0
  135. package/kotlin/sdk.tar.gz +0 -0
  136. package/package.json +1 -1
  137. package/runtime-companion.json +1 -1
  138. package/scripts/dev-server-scanner.ts +12 -25
  139. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccount.h +55 -0
  140. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountCredential.h +35 -0
  141. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountStore.h +94 -0
  142. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountType.h +53 -0
  143. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACError.h +37 -0
  144. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/Accounts.h +13 -0
  145. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/AccountsDefines.h +13 -0
  146. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Modules/module.modulemap +5 -0
  147. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
  148. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
  149. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
  150. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
  151. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
  152. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
  153. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
  154. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
  155. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
  156. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
  157. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +3 -1
  158. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
  159. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
  160. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +58 -3
  161. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +711 -46
  162. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
  163. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
  164. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
  165. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
  166. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
  167. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
  168. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
  169. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
  170. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
  171. package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
  172. package/sdk/ios/usr/include/module.modulemap +1 -0
  173. package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
  174. package/sdk/ios/usr/include/os/signpost.h +414 -0
  175. package/sdk/ios/usr/include/os.modulemap +10 -0
  176. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  177. package/sdk/ios/usr/include/sys/ioccom.h +99 -0
  178. package/sdk/ios/usr/include/sys/syslog.h +236 -0
  179. package/sdk/ios/usr/include/syslog.h +24 -0
  180. package/sdk/ios/wasm/include/errno.h +4 -20
  181. package/sdk/ios/wasm/include/fcntl.h +4 -2
  182. package/sdk/ios/wasm/include/pthread.h +3 -0
  183. package/sdk/ios/wasm/include/setjmp.h +57 -0
  184. package/sdk/ios/wasm/include/stdio.h +24 -0
  185. package/sdk/ios/wasm/include/stdlib.h +32 -7
  186. package/sdk/ios/wasm/include/sys/file.h +7 -0
  187. package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
  188. package/sdk/ios/wasm/include/sys/resource.h +2 -2
  189. package/sdk/ios/wasm/include/sys/syscall.h +9 -0
  190. package/sdk/ios/wasm/include/sys/time.h +10 -0
  191. package/sdk/ios/wasm/include/unistd.h +12 -3
  192. package/sdk/native-hashes.json +4 -3
  193. package/skills/contrast/SKILL.md +2 -1
  194. package/skills/peach-debug/SKILL.md +0 -1
  195. package/skills/peach-perf/SKILL.md +0 -1
  196. package/skills/peach-setup/SKILL.md +0 -1
  197. package/skills/peach-test/SKILL.md +7 -4
  198. package/skills/peach-visual/SKILL.md +0 -1
  199. package/src/admitted-mac-build.ts +3 -0
  200. package/src/android-app-identity.ts +18 -0
  201. package/src/android-autolinking.ts +1 -0
  202. package/src/android-bridge-packages.ts +279 -0
  203. package/src/android-root-module.ts +9 -9
  204. package/src/appPackageContract.ts +83 -0
  205. package/src/bridge-contract.ts +50 -0
  206. package/src/bundle-channel.mjs +41 -6
  207. package/src/cli-runtime.ts +9 -5
  208. package/src/dev-bundle-resolution.ts +7 -27
  209. package/src/dom-source-reference.ts +15 -0
  210. package/src/expo-discovery-cache.ts +134 -26
  211. package/src/expo-kotlin-host.ts +97 -26
  212. package/src/expo-manifest-body.ts +33 -0
  213. package/src/expo-native-workspace.ts +158 -38
  214. package/src/expo-swift-host.ts +350 -75
  215. package/src/expo-swift-ready.ts +5 -1
  216. package/src/expoKotlinContract.ts +12 -2
  217. package/src/expoSwiftContract.ts +10 -0
  218. package/src/generated/swift-c-predefines.json +1 -1
  219. package/src/home-paths.ts +41 -2
  220. package/src/host/app-package-handler.ts +47 -0
  221. package/src/host/bridge-host.ts +8 -0
  222. package/src/host/fetch-proxy-handler.ts +10 -0
  223. package/src/host/staged-host-files.ts +18 -0
  224. package/src/index.ts +3 -0
  225. package/src/kotlin-host.ts +225 -48
  226. package/src/kotlin-instance-source.ts +126 -0
  227. package/src/kotlinSdkContract.ts +2 -1
  228. package/src/menu.ts +14 -0
  229. package/src/native-app-identity-project.ts +7 -2
  230. package/src/native-app-identity.ts +11 -0
  231. package/src/native-firebase-config.ts +24 -1
  232. package/src/native-prebuilt.ts +154 -0
  233. package/src/nitro-adapter.lock.json +270 -270
  234. package/src/nitro-adapter.ts +56 -50
  235. package/src/nitro-bundle.ts +92 -74
  236. package/src/nitro-compile.ts +45 -14
  237. package/src/nitro-dependencies.ts +63 -46
  238. package/src/nitro-source.ts +64 -26
  239. package/src/nitroAdapterContract.ts +146 -98
  240. package/src/nitroContract.ts +71 -21
  241. package/src/react-native-bridge-modules.ts +70 -42
  242. package/src/react-native-host-modules.ts +34 -1
  243. package/src/reactNativeConfigurationContract.ts +14 -0
  244. package/src/reap-browser.ts +15 -3
  245. package/src/sdk.ts +5 -0
  246. package/src/settingsContract.ts +38 -1
  247. package/src/sim-client.ts +4 -1
  248. package/src/storageSnapshotContract.ts +32 -81
  249. package/src/swift-compile.ts +268 -89
  250. package/src/swift-coverage/indexdump.ts +22 -6
  251. package/src/swift-coverage/indexing.ts +4 -4
  252. package/src/swift-coverage/provenance.ts +1 -0
  253. package/src/swift-coverage/sdk.ts +104 -20
  254. package/src/swift-coverage/types.ts +34 -0
  255. package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
  256. package/src/swift-coverage/xcode-assets.ts +89 -131
  257. package/src/swift-coverage/xcode.ts +10 -2
  258. package/src/swift-cxx-reachable.ts +2 -1
  259. package/src/swift-distribution.lock.json +20 -16
  260. package/src/swift-host.ts +98 -22
  261. package/src/swift-icu.ts +1 -1
  262. package/src/swift-link-roots.ts +118 -0
  263. package/src/swift-objc-compile.ts +144 -22
  264. package/src/swift-objc-import.ts +6 -0
  265. package/src/swift-objc-standin.ts +2 -14
  266. package/src/swift-package-manifest.ts +14 -6
  267. package/src/swift-packages.ts +75 -11
  268. package/src/swift-pdf-raster.ts +1 -0
  269. package/src/swift-root-lock.ts +17 -1
  270. package/src/swift-source-pods.ts +2 -10
  271. package/src/swift-standin-emit.ts +597 -57
  272. package/src/swift-standins.ts +599 -56
  273. package/src/swift-submit.ts +7 -1
  274. package/src/swift-toolchain.ts +140 -17
  275. package/src/turbo-bundle.ts +81 -0
  276. package/src/turbo-codegen-intake.ts +91 -0
  277. package/src/turbo-compile.ts +120 -0
  278. package/src/turbo-runtime.lock.json +69 -0
  279. package/src/turbo-source.ts +754 -0
  280. package/src/vite-plugin-one.ts +17 -12
  281. package/src/vite-plugin.ts +28 -15
  282. package/src/xcode-project.ts +223 -22
@@ -0,0 +1,760 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import { createHash, randomUUID } from 'node:crypto'
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+ import {
7
+ extractAssetDescriptors,
8
+ metroAssetScaleFilename,
9
+ } from '../../../contrast-bundler/src/metroAssetArtifact'
10
+ import {
11
+ APP_PACKAGE_ORIGIN,
12
+ APP_PACKAGE_ADDRESS_PATTERN,
13
+ packageSettingDefaults,
14
+ type AppPackageManifest,
15
+ } from '../../src/appPackageContract'
16
+ import {
17
+ detachBundleGlobalFooter,
18
+ stripBundleMetadataFooter,
19
+ } from '../../src/bundleGlobalFooter'
20
+ import { getCliRuntime, verifyCliCompanion } from '../../src/cli-runtime'
21
+ import { produceConfiguredBundle } from '../../src/configured-bundle-producer'
22
+ import { activeDesktopHostApp } from '../../src/desktop-host-delivery'
23
+ import { insertExpoKotlinFooter } from '../../src/expoKotlinContract'
24
+ import { insertExpoSwiftFooter } from '../../src/expoSwiftContract'
25
+ import { readActiveRuntime } from '../../src/home-paths'
26
+ import {
27
+ captureStagedHostFiles,
28
+ stageHostBytes,
29
+ stageHostLaunchMetadata,
30
+ } from '../../src/host/staged-host-files'
31
+ import { readInstalledNativePackageVersionsAsync } from '../../src/installed-package-versions'
32
+ import { isRecord } from '../../src/is-record'
33
+ import { readNativeAppIdentityFromProject } from '../../src/native-app-identity-project'
34
+ import { readExpoConfigAsync } from '../../src/native-firebase-config'
35
+ import { insertNitroFooter, insertTurboFooter } from '../../src/nitroContract'
36
+ import {
37
+ insertPackageVersionsFooter,
38
+ readPackageVersions,
39
+ readPackageVersionsFooter,
40
+ type PackageVersions,
41
+ } from '../../src/packageVersionsContract'
42
+ import { resolveActiveRuntimeRoot } from '../../src/runtime-assets'
43
+ import { loadRNXAppConfig } from '../app-config'
44
+ import { resolveAppProject } from '../app-project'
45
+ import {
46
+ parseAppSplashWire,
47
+ splashImageUrls,
48
+ splashImageContentType,
49
+ } from '../app-splash'
50
+ import { prepareNativeInput, resolveNativeInput } from '../native-input'
51
+ import { packagedAppLauncher } from '../packaged-app-launcher'
52
+ import { IS_STANDALONE } from '../standalone'
53
+ import {
54
+ buildShellUrl,
55
+ resolveAppProjectForBundleUrl,
56
+ stagePrebuiltBundle,
57
+ } from './control'
58
+
59
+ const origin = APP_PACKAGE_ORIGIN
60
+
61
+ async function projectIcon(
62
+ project: string,
63
+ scratch: string,
64
+ ): Promise<string | undefined> {
65
+ const config = await readExpoConfigAsync(project)
66
+ if (typeof config.icon === 'string') return path.resolve(project, config.icon)
67
+ const artwork = readNativeAppIdentityFromProject(project, 'ios')?.appIconArtwork
68
+ ?.primary?.[0]?.uri
69
+ if (!artwork?.startsWith('data:')) return undefined
70
+ const icon = path.join(scratch, 'icon.png')
71
+ fs.writeFileSync(icon, Buffer.from(artwork.slice(artwork.indexOf(',') + 1), 'base64'))
72
+ return icon
73
+ }
74
+
75
+ export async function runPackage(args: string[]): Promise<void> {
76
+ if (process.platform !== 'darwin')
77
+ throw new Error('peach package currently builds macOS apps')
78
+ const input = [...args]
79
+ const values = new Map<string, string>()
80
+ const settings: string[] = []
81
+ const positionals: string[] = []
82
+ for (let i = 0; i < input.length; i++) {
83
+ const flag = input[i]!
84
+ if (!flag.startsWith('-')) {
85
+ positionals.push(flag)
86
+ continue
87
+ }
88
+ if (
89
+ ![
90
+ '--name',
91
+ '--output',
92
+ '--identifier',
93
+ '--icon',
94
+ '--splash',
95
+ '--setting',
96
+ '--cli',
97
+ '--host-app',
98
+ '--target',
99
+ '--scheme',
100
+ '--activity',
101
+ '--package-versions',
102
+ '--project-root',
103
+ '--compositor',
104
+ '--sign',
105
+ '--notarize',
106
+ ].includes(flag)
107
+ )
108
+ throw new Error(`unknown peach package option: ${flag}`)
109
+ const value = input[++i]
110
+ if (!value || value.startsWith('--')) throw new Error(`${flag} requires a value`)
111
+ if (flag === '--setting') settings.push(value)
112
+ else values.set(flag, value)
113
+ }
114
+ const target = positionals[0]
115
+ if (!target || positionals.length !== 1)
116
+ throw new Error(
117
+ 'usage: peach package <target> --name <name> [--output <app|zip|dmg> --setting key=value --sign <identity> --notarize <profile>]',
118
+ )
119
+ const name = values.get('--name') ?? path.basename(target, path.extname(target))
120
+ const identifier =
121
+ values.get('--identifier') ??
122
+ `dev.peach.app.${name.toLowerCase().replace(/[^a-z0-9]+/g, '-')}`
123
+ if (
124
+ !name.trim() ||
125
+ /[/\0]/.test(name) ||
126
+ !/^[A-Za-z0-9]+(?:[.-][A-Za-z0-9-]+)+$/.test(identifier)
127
+ )
128
+ throw new Error('package name or bundle identifier is invalid')
129
+ const output = path.resolve(values.get('--output') ?? `${name}.app`)
130
+ const archive = path.extname(output)
131
+ if (!['.app', '.zip', '.dmg'].includes(archive) || fs.existsSync(output))
132
+ throw new Error('--output must name a new .app, .zip or .dmg')
133
+ // a Developer ID identity signs with the hardened runtime; notarization reads
134
+ // credentials saved by `xcrun notarytool store-credentials <profile>`
135
+ const identity = values.get('--sign')
136
+ const notaryProfile = values.get('--notarize')
137
+ if (identity && !identity.startsWith('Developer ID Application: '))
138
+ throw new Error('--sign needs a Developer ID Application identity')
139
+ if (notaryProfile && !identity) throw new Error('--notarize needs --sign')
140
+ const defaults = packageSettingDefaults(settings)
141
+ const compositor = values.get('--compositor') ?? 'node'
142
+ if (!['native', 'webkit', 'node'].includes(compositor))
143
+ throw new Error('--compositor must be native, webkit or node')
144
+ const versionsFile = values.get('--package-versions')
145
+ const versions = versionsFile
146
+ ? readPackageVersions(JSON.parse(fs.readFileSync(path.resolve(versionsFile), 'utf8')))
147
+ : null
148
+ let configuredVersions: PackageVersions | null = null
149
+ const prepareBundle = async (source: string) => {
150
+ source = source.replaceAll(origin, '')
151
+ if (versions || configuredVersions)
152
+ source = insertPackageVersionsFooter(source, {
153
+ ...configuredVersions,
154
+ ...readPackageVersionsFooter(source),
155
+ ...versions,
156
+ })
157
+ return getCliRuntime().rolldown_bundle_inventory.attachRolldownBundleHttpPayload(
158
+ source,
159
+ 'application/javascript',
160
+ )
161
+ }
162
+ const selectedHost =
163
+ values.get('--host-app') ?? process.env.PEACH_DESKTOP_APP ?? activeDesktopHostApp()
164
+ const host = selectedHost ? path.resolve(selectedHost) : null
165
+ const runtime = resolveActiveRuntimeRoot()
166
+ const runtimeVersion = readActiveRuntime()
167
+ if (!host || !runtime || !runtimeVersion)
168
+ throw new Error(
169
+ 'install the Peach desktop app and an engine runtime before packaging',
170
+ )
171
+ verifyCliCompanion(runtime)
172
+ const cli =
173
+ values.get('--cli') ??
174
+ (IS_STANDALONE
175
+ ? process.execPath
176
+ : path.resolve(import.meta.dirname, '../../dist-bin/peach-darwin-arm64'))
177
+ if (!fs.existsSync(cli))
178
+ throw new Error('source packaging needs a built CLI binary; pass --cli <binary>')
179
+ // the app is assembled beside the output, so archives and the final move stay on its volume
180
+ const staging = `${output}.${randomUUID()}`
181
+ const temporary = path.join(staging, `${name}.app`)
182
+ fs.mkdirSync(staging)
183
+ const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'peach-package-'))
184
+ const routes: AppPackageManifest['routes'] = {}
185
+ let icon = values.get('--icon')
186
+ let requiresServer = false
187
+ const route = (pathname: string, bytes: Uint8Array, contentType: string) => {
188
+ const extension = contentType === 'application/javascript' ? '.js' : ''
189
+ const url = stageHostBytes(bytes, origin, extension)
190
+ routes[pathname] = { file: path.basename(new URL(url).pathname), contentType }
191
+ return origin + pathname
192
+ }
193
+ try {
194
+ const captured = await captureStagedHostFiles(async () => {
195
+ let launchUrl: string
196
+ const native = resolveNativeInput(target)
197
+ const local = fs.statSync(path.resolve(target), { throwIfNoEntry: false })
198
+ const project = local
199
+ ? resolveAppProject(
200
+ local.isDirectory() ? target : path.dirname(path.resolve(target)),
201
+ )
202
+ : null
203
+ const configuredProject = values.has('--project-root')
204
+ ? resolveAppProject(values.get('--project-root')!)
205
+ : project
206
+ if (values.has('--project-root') && !configuredProject)
207
+ throw new Error('--project-root must name an app project')
208
+ if (configuredProject)
209
+ configuredVersions = await readInstalledNativePackageVersionsAsync(
210
+ configuredProject.appDir,
211
+ )
212
+ if (!icon && configuredProject)
213
+ icon = await projectIcon(configuredProject.appDir, scratch)
214
+ if (native) {
215
+ const app = await prepareNativeInput(native, {
216
+ origin,
217
+ target: values.get('--target'),
218
+ scheme: values.get('--scheme'),
219
+ activity: values.get('--activity'),
220
+ })
221
+ try {
222
+ for (const [pathname, asset] of app.assets)
223
+ route(pathname, asset.bytes, asset.contentType)
224
+ route(
225
+ app.metadataPath,
226
+ Buffer.from(JSON.stringify(app.metadata)),
227
+ 'application/json',
228
+ )
229
+ const bundle = route(
230
+ app.guestPath,
231
+ Buffer.from(app.guestSource),
232
+ 'application/javascript',
233
+ )
234
+ const url = new URL('/rn', origin)
235
+ url.searchParams.set('bundle', bundle)
236
+ launchUrl = url.href
237
+ if (!icon && app.icon) {
238
+ icon = path.join(scratch, 'icon.png')
239
+ fs.writeFileSync(icon, app.icon.bytes)
240
+ }
241
+ } finally {
242
+ app.dispose()
243
+ }
244
+ } else if (
245
+ (local?.isFile() && target.endsWith('.json')) ||
246
+ /^https?:\/\/.+\.json(?:\?.*)?$/.test(target)
247
+ ) {
248
+ const readChannel = async (): Promise<unknown> => {
249
+ if (local?.isFile())
250
+ return JSON.parse(fs.readFileSync(path.resolve(target), 'utf8'))
251
+ const response = await fetch(target)
252
+ if (!response.ok)
253
+ throw new Error(`app release metadata: HTTP ${response.status}`)
254
+ return response.json()
255
+ }
256
+ const channel = await readChannel()
257
+ if (
258
+ !isRecord(channel) ||
259
+ channel.schemaVersion !== 1 ||
260
+ typeof channel.bundleUrl !== 'string' ||
261
+ typeof channel.bundleHash !== 'string' ||
262
+ !/^[a-f0-9]{64}$/.test(channel.bundleHash) ||
263
+ typeof channel.iconUrl !== 'string'
264
+ )
265
+ throw new Error('invalid app release metadata')
266
+ const bundleResponse = await fetch(channel.bundleUrl)
267
+ if (!bundleResponse.ok)
268
+ throw new Error(`app release bundle: HTTP ${bundleResponse.status}`)
269
+ const bytes = Buffer.from(await bundleResponse.arrayBuffer())
270
+ if (createHash('sha256').update(bytes).digest('hex') !== channel.bundleHash)
271
+ throw new Error('app release bundle hash mismatch')
272
+ let source = bytes.toString('utf8')
273
+ const resources = new Set<string>()
274
+ const visit = (value: unknown) => {
275
+ if (Array.isArray(value)) {
276
+ for (const child of value) visit(child)
277
+ return
278
+ }
279
+ if (!isRecord(value)) return
280
+ for (const [key, child] of Object.entries(value)) {
281
+ if ((key === 'url' || key === 'icuUrl') && typeof child === 'string')
282
+ resources.add(child)
283
+ else visit(child)
284
+ }
285
+ }
286
+ if (configuredProject) {
287
+ const root = configuredProject.appDir
288
+ const config = await loadRNXAppConfig(configuredProject)
289
+ source = detachBundleGlobalFooter(source, '__peachExpoSwift').source
290
+ source = detachBundleGlobalFooter(source, '__peachExpoKotlin').source
291
+ source = stripBundleMetadataFooter(source, 'nitro')
292
+ source = stripBundleMetadataFooter(source, 'turbo')
293
+ if (channel.platform === 'android') {
294
+ const native = await (
295
+ await import('../../src/expo-kotlin-bundle')
296
+ ).buildExpoKotlinBundle(root)
297
+ if (native) {
298
+ for (const asset of native.assets)
299
+ route('/' + asset.path, asset.bytes, asset.contentType)
300
+ source = insertExpoKotlinFooter(source, native.metadata)
301
+ }
302
+ } else {
303
+ const native = await (
304
+ await import('../../src/expo-swift-bundle')
305
+ ).buildExpoSwiftBundle(root)
306
+ if (native) {
307
+ for (const asset of native.assets)
308
+ route('/' + asset.path, asset.bytes, asset.contentType)
309
+ source = insertExpoSwiftFooter(source, native.metadata)
310
+ }
311
+ const nitro = await (
312
+ await import('../../src/nitro-bundle')
313
+ ).buildNitroBundle(root)
314
+ if (nitro) {
315
+ for (const asset of nitro.assets)
316
+ route('/' + asset.path, asset.bytes, asset.contentType)
317
+ source = insertNitroFooter(source, nitro.metadata)
318
+ }
319
+ const turbo = await (
320
+ await import('../../src/turbo-bundle')
321
+ ).buildTurboBundle(root)
322
+ if (turbo) {
323
+ for (const asset of turbo.assets)
324
+ route('/' + asset.path, asset.bytes, asset.contentType)
325
+ source = insertTurboFooter(source, turbo.metadata)
326
+ }
327
+ }
328
+ source = await produceConfiguredBundle(
329
+ source,
330
+ config,
331
+ new Set(Object.keys(versions ?? readPackageVersionsFooter(source) ?? {})),
332
+ )
333
+ } else {
334
+ visit(channel.expoSwift)
335
+ visit(channel.expoKotlin)
336
+ visit(channel.nitro)
337
+ visit(channel.turbo)
338
+ }
339
+ for (const descriptor of extractAssetDescriptors(source)) {
340
+ if (!descriptor.httpServerLocation) continue
341
+ const directory = new URL(descriptor.httpServerLocation, channel.bundleUrl)
342
+ const packaged =
343
+ '/__peach/app-assets/' +
344
+ createHash('sha256').update(directory.href).digest('hex')
345
+ for (const scale of descriptor.scales) {
346
+ const filename = metroAssetScaleFilename(
347
+ descriptor.name,
348
+ descriptor.type,
349
+ scale,
350
+ )
351
+ const asset = await fetch(`${directory.href.replace(/\/$/, '')}/${filename}`)
352
+ if (!asset.ok) throw new Error(`app asset ${filename}: HTTP ${asset.status}`)
353
+ route(
354
+ `${packaged}/${filename}`,
355
+ new Uint8Array(await asset.arrayBuffer()),
356
+ asset.headers.get('content-type') ?? 'application/octet-stream',
357
+ )
358
+ }
359
+ source = source.replaceAll(
360
+ JSON.stringify(descriptor.httpServerLocation),
361
+ JSON.stringify(packaged),
362
+ )
363
+ }
364
+ for (const url of resources) {
365
+ const asset = await fetch(url)
366
+ if (!asset.ok) throw new Error(`native app resource: HTTP ${asset.status}`)
367
+ const packaged =
368
+ '/__peach/app-assets/' +
369
+ createHash('sha256').update(url).digest('hex') +
370
+ path.extname(new URL(url).pathname)
371
+ route(
372
+ packaged,
373
+ new Uint8Array(await asset.arrayBuffer()),
374
+ asset.headers.get('content-type') ?? 'application/octet-stream',
375
+ )
376
+ source = source.replaceAll(JSON.stringify(url), JSON.stringify(packaged))
377
+ }
378
+ if (!icon) {
379
+ const artwork = await fetch(channel.iconUrl)
380
+ if (!artwork.ok) throw new Error(`app icon: HTTP ${artwork.status}`)
381
+ icon = path.join(scratch, 'icon.png')
382
+ fs.writeFileSync(icon, Buffer.from(await artwork.arrayBuffer()))
383
+ }
384
+ const prepared = await prepareBundle(source)
385
+ const bundle = route(
386
+ '/__peach/app.js',
387
+ Buffer.from(prepared),
388
+ 'application/javascript',
389
+ )
390
+ const url = new URL('/rn', origin)
391
+ url.searchParams.set('bundle', bundle)
392
+ launchUrl = url.href
393
+ } else if (local?.isDirectory()) {
394
+ const { snapshotOneDevBundle, prepareBundleChannel } =
395
+ await import('../../src/bundle-channel.mjs')
396
+ const snapshot = await snapshotOneDevBundle(
397
+ path.resolve(target),
398
+ {},
399
+ // the project's own node: a notarized host's node refuses the
400
+ // project's ad hoc signed native addons under library validation.
401
+ { platforms: ['ios'], runtimeExecutable: 'node' },
402
+ )
403
+ const snapshotIcon = path.join(scratch, 'channel-icon.png')
404
+ execFileSync(
405
+ '/usr/bin/sips',
406
+ [
407
+ '-s',
408
+ 'format',
409
+ 'png',
410
+ icon ? path.resolve(icon) : path.join(host, 'Contents/Resources/Peach.icns'),
411
+ '--out',
412
+ snapshotIcon,
413
+ ],
414
+ { stdio: 'ignore' },
415
+ )
416
+ const release = prepareBundleChannel({
417
+ prefix: 'app',
418
+ publicOrigin: origin,
419
+ sourceSha: createHash('sha1')
420
+ .update(snapshot.platforms[0].bundle)
421
+ .digest('hex'),
422
+ runtimeVersion: '1',
423
+ name,
424
+ icon: fs.readFileSync(snapshotIcon),
425
+ ...snapshot,
426
+ })
427
+ const channel = release.channels[0]
428
+ for (const object of channel.objects) {
429
+ const bytes = object.key.endsWith('/bundle.js')
430
+ ? Buffer.from(await prepareBundle(object.bytes.toString('utf8')))
431
+ : object.bytes
432
+ route('/' + object.key, bytes, object.contentType)
433
+ }
434
+ launchUrl = await buildShellUrl(channel.metadata.bundleUrl, origin, {
435
+ bridgePort: 65534,
436
+ resolvedBundle: {
437
+ bundleUrl: channel.metadata.bundleUrl,
438
+ port: 65534,
439
+ framework: 'one',
440
+ },
441
+ project: resolveAppProject(target),
442
+ offline: true,
443
+ hot: false,
444
+ })
445
+ } else if (local?.isFile()) {
446
+ const bundle = await stagePrebuiltBundle(path.resolve(target), 65534)
447
+ launchUrl = await buildShellUrl(bundle.bundleUrl, origin, {
448
+ bridgePort: 65534,
449
+ resolvedBundle: bundle,
450
+ project: resolveAppProject(path.dirname(path.resolve(target))),
451
+ offline: true,
452
+ hot: false,
453
+ })
454
+ } else {
455
+ launchUrl = await buildShellUrl(target, origin, { bridgePort: 65534, hot: false })
456
+ requiresServer =
457
+ new URL(launchUrl).searchParams.has('bundle') ||
458
+ new URL(launchUrl).pathname.startsWith('/rn/')
459
+ if (!icon) {
460
+ const opened = await resolveAppProjectForBundleUrl(
461
+ new URL(launchUrl).searchParams.get('bundle') ?? undefined,
462
+ )
463
+ if (opened) icon = await projectIcon(opened.appDir, scratch)
464
+ }
465
+ }
466
+ if (project && !values.has('--splash')) {
467
+ const splash = new URL(launchUrl).searchParams.get('appSplash')
468
+ const spec = splash ? parseAppSplashWire(splash) : null
469
+ if (spec)
470
+ for (const image of splashImageUrls(spec)) {
471
+ const pathname = new URL(image).pathname
472
+ if (!pathname.startsWith('/assets/'))
473
+ throw new Error('app splash must name a project asset')
474
+ const file = path.resolve(
475
+ project.appDir,
476
+ decodeURIComponent(pathname.slice('/assets/'.length)),
477
+ )
478
+ if (!file.startsWith(project.appDir + path.sep))
479
+ throw new Error('app splash is outside its project')
480
+ route(pathname, fs.readFileSync(file), splashImageContentType(image))
481
+ }
482
+ }
483
+ if (values.has('--splash')) {
484
+ const url = new URL(launchUrl)
485
+ const image = stageHostBytes(
486
+ fs.readFileSync(path.resolve(values.get('--splash')!)),
487
+ origin,
488
+ path.extname(values.get('--splash')!),
489
+ )
490
+ const { encodeAppSplashWire } = await import('../app-splash')
491
+ url.searchParams.set(
492
+ 'appSplash',
493
+ encodeAppSplashWire({
494
+ source: 'one-native',
495
+ imageUrl: image,
496
+ backgroundColor: '#ffffff',
497
+ }),
498
+ )
499
+ launchUrl = url.href
500
+ }
501
+ return stageHostLaunchMetadata(new URL(launchUrl), origin)
502
+ })
503
+ fs.mkdirSync(path.dirname(output), { recursive: true })
504
+ execFileSync('/usr/bin/ditto', [host, temporary])
505
+ const contents = path.join(temporary, 'Contents')
506
+ const resources = path.join(contents, 'Resources')
507
+ const plist = path.join(contents, 'Info.plist')
508
+ const hostInfo: unknown = JSON.parse(
509
+ execFileSync('/usr/bin/plutil', ['-convert', 'json', '-o', '-', plist], {
510
+ encoding: 'utf8',
511
+ }),
512
+ )
513
+ if (!isRecord(hostInfo) || typeof hostInfo.CFBundleExecutable !== 'string')
514
+ throw new Error('native host has no executable')
515
+ const hostExecutable = hostInfo.CFBundleExecutable
516
+ fs.cpSync(runtime, path.join(resources, 'runtime'), {
517
+ recursive: true,
518
+ dereference: true,
519
+ })
520
+ fs.copyFileSync(cli, path.join(resources, 'bin', 'peach'))
521
+ fs.mkdirSync(path.join(resources, 'payload'))
522
+ const relocatableFiles: string[] = []
523
+ for (const [file, source] of captured.files) {
524
+ const bytes = fs.readFileSync(source)
525
+ if (
526
+ bytes.includes(Buffer.from('127.0.0.1')) &&
527
+ new RegExp(APP_PACKAGE_ADDRESS_PATTERN, 'i').test(bytes.toString('utf8'))
528
+ )
529
+ relocatableFiles.push(file)
530
+ fs.copyFileSync(source, path.join(resources, 'payload', file))
531
+ }
532
+ const manifest: AppPackageManifest = {
533
+ schemaVersion: 1,
534
+ buildId: randomUUID(),
535
+ identifier,
536
+ name,
537
+ origin,
538
+ hostExecutable,
539
+ hostArguments: ['--compositor', compositor],
540
+ runtimeVersion,
541
+ launchUrl: captured.value,
542
+ defaults,
543
+ relocatableFiles,
544
+ routes,
545
+ requiresServer,
546
+ }
547
+ fs.writeFileSync(path.join(resources, 'peach-app.json'), JSON.stringify(manifest))
548
+ fs.writeFileSync(path.join(resources, 'app-launcher.cjs'), packagedAppLauncher)
549
+ fs.writeFileSync(
550
+ path.join(contents, 'MacOS', 'PeachApp'),
551
+ '#!/bin/sh\nexec "$(dirname "$0")/../Frameworks/node" "$(dirname "$0")/../Resources/app-launcher.cjs" "$@"\n',
552
+ { mode: 0o755 },
553
+ )
554
+ const bundleInfo: Record<string, unknown> = {
555
+ ...hostInfo,
556
+ CFBundleExecutable: 'PeachApp',
557
+ CFBundleIdentifier: identifier,
558
+ CFBundleName: name,
559
+ CFBundleDisplayName: name,
560
+ }
561
+ for (const key of ['CFBundleURLTypes', 'SUFeedURL', 'SUPublicEDKey'])
562
+ delete bundleInfo[key]
563
+ fs.writeFileSync(plist, JSON.stringify(bundleInfo))
564
+ execFileSync('/usr/bin/plutil', ['-convert', 'xml1', plist])
565
+ if (icon) {
566
+ const iconset = path.join(scratch, 'App.iconset')
567
+ fs.mkdirSync(iconset)
568
+ for (const size of [16, 32, 128, 256, 512]) {
569
+ execFileSync(
570
+ '/usr/bin/sips',
571
+ [
572
+ '-s',
573
+ 'format',
574
+ 'png',
575
+ '-z',
576
+ String(size),
577
+ String(size),
578
+ path.resolve(icon),
579
+ '--out',
580
+ path.join(iconset, `icon_${size}x${size}.png`),
581
+ ],
582
+ { stdio: 'ignore' },
583
+ )
584
+ execFileSync(
585
+ '/usr/bin/sips',
586
+ [
587
+ '-s',
588
+ 'format',
589
+ 'png',
590
+ '-z',
591
+ String(size * 2),
592
+ String(size * 2),
593
+ path.resolve(icon),
594
+ '--out',
595
+ path.join(iconset, `icon_${size}x${size}@2x.png`),
596
+ ],
597
+ { stdio: 'ignore' },
598
+ )
599
+ }
600
+ execFileSync('/usr/bin/iconutil', [
601
+ '-c',
602
+ 'icns',
603
+ iconset,
604
+ '-o',
605
+ path.join(resources, 'Peach.icns'),
606
+ ])
607
+ }
608
+ // each binary keeps the entitlements the host release gave it
609
+ const entitlementsOf = (relative: string) => {
610
+ const file = path.join(scratch, `${relative.replaceAll('/', '-')}.entitlements`)
611
+ fs.writeFileSync(
612
+ file,
613
+ execFileSync('/usr/bin/codesign', [
614
+ '--display',
615
+ '--entitlements',
616
+ '-',
617
+ '--xml',
618
+ path.join(host, 'Contents', relative),
619
+ ]),
620
+ )
621
+ return file
622
+ }
623
+ const appEntitlements = entitlementsOf(`MacOS/${hostExecutable}`)
624
+ if (identity) {
625
+ // the release order of the host's own signing: every nested binary, then
626
+ // nested bundles deepest first, then the entitled binaries and the app
627
+ const sign = (target: string, entitlements?: string) =>
628
+ execFileSync('/usr/bin/codesign', [
629
+ '--force',
630
+ '--sign',
631
+ identity,
632
+ '--options',
633
+ 'runtime',
634
+ '--timestamp',
635
+ ...(entitlements ? ['--entitlements', entitlements] : []),
636
+ target,
637
+ ])
638
+ const files = fs
639
+ .readdirSync(contents, { recursive: true, withFileTypes: true })
640
+ .filter((entry) => entry.isFile())
641
+ .map((entry) => path.join(entry.parentPath, entry.name))
642
+ for (const file of files.sort((a, b) => b.length - a.length)) {
643
+ const head = Buffer.alloc(4)
644
+ const fd = fs.openSync(file, 'r')
645
+ const read = fs.readSync(fd, head, 0, 4, 0)
646
+ fs.closeSync(fd)
647
+ // a thin arm64 or a universal mach-o
648
+ if (read === 4 && [0xcffaedfe, 0xcafebabe].includes(head.readUInt32BE(0)))
649
+ sign(file)
650
+ }
651
+ for (const bundle of fs
652
+ .readdirSync(contents, { recursive: true, withFileTypes: true })
653
+ .filter(
654
+ (entry) => entry.isDirectory() && /\.(app|xpc|framework)$/.test(entry.name),
655
+ )
656
+ .map((entry) => path.join(entry.parentPath, entry.name))
657
+ .sort((a, b) => b.length - a.length))
658
+ sign(bundle)
659
+ sign(path.join(resources, 'bin', 'peach'), entitlementsOf('Resources/bin/peach'))
660
+ sign(path.join(contents, 'Frameworks', 'node'), entitlementsOf('Frameworks/node'))
661
+ // the launcher script is the bundle executable, so the host binary
662
+ // needs its jit entitlements signed on directly
663
+ sign(path.join(contents, 'MacOS', hostExecutable), appEntitlements)
664
+ sign(temporary, appEntitlements)
665
+ } else {
666
+ for (const executable of [
667
+ path.join(contents, 'MacOS', hostExecutable),
668
+ path.join(resources, 'bin', 'peach'),
669
+ ])
670
+ execFileSync('/usr/bin/codesign', [
671
+ '--force',
672
+ '--sign',
673
+ '-',
674
+ '--entitlements',
675
+ appEntitlements,
676
+ executable,
677
+ ])
678
+ execFileSync('/usr/bin/codesign', ['--force', '--sign', '-', temporary])
679
+ }
680
+ execFileSync('/usr/bin/codesign', ['--verify', '--deep', '--strict', temporary])
681
+ const notarize = (file: string) => {
682
+ const result: unknown = JSON.parse(
683
+ execFileSync(
684
+ '/usr/bin/xcrun',
685
+ [
686
+ 'notarytool',
687
+ 'submit',
688
+ file,
689
+ '--keychain-profile',
690
+ notaryProfile!,
691
+ '--wait',
692
+ '--output-format',
693
+ 'json',
694
+ ],
695
+ { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] },
696
+ ),
697
+ )
698
+ if (!isRecord(result) || result.status !== 'Accepted') {
699
+ const id = isRecord(result) && typeof result.id === 'string' ? result.id : ''
700
+ if (id)
701
+ execFileSync(
702
+ '/usr/bin/xcrun',
703
+ ['notarytool', 'log', id, '--keychain-profile', notaryProfile!],
704
+ { stdio: 'inherit' },
705
+ )
706
+ throw new Error(
707
+ `notarization did not accept ${path.basename(file)}: ${JSON.stringify(result)}`,
708
+ )
709
+ }
710
+ }
711
+ const staple = (file: string) =>
712
+ execFileSync('/usr/bin/xcrun', ['stapler', 'staple', file], { stdio: 'ignore' })
713
+ const zip = (destination: string) =>
714
+ execFileSync('/usr/bin/ditto', [
715
+ '-c',
716
+ '-k',
717
+ '--sequesterRsrc',
718
+ '--keepParent',
719
+ temporary,
720
+ destination,
721
+ ])
722
+ if (notaryProfile) {
723
+ const submission = path.join(scratch, 'notarization.zip')
724
+ zip(submission)
725
+ notarize(submission)
726
+ staple(temporary)
727
+ }
728
+ if (archive === '.app') fs.renameSync(temporary, output)
729
+ else if (archive === '.zip') zip(output)
730
+ else {
731
+ // the disk image opens to the app beside an Applications shortcut
732
+ fs.symlinkSync('/Applications', path.join(staging, 'Applications'))
733
+ execFileSync(
734
+ '/usr/bin/hdiutil',
735
+ ['create', '-volname', name, '-srcfolder', staging, '-format', 'UDZO', output],
736
+ { stdio: 'ignore' },
737
+ )
738
+ if (identity)
739
+ execFileSync('/usr/bin/codesign', [
740
+ '--force',
741
+ '--sign',
742
+ identity,
743
+ '--timestamp',
744
+ output,
745
+ ])
746
+ if (notaryProfile) {
747
+ notarize(output)
748
+ staple(output)
749
+ }
750
+ }
751
+ console.log(output)
752
+ if (requiresServer)
753
+ console.error(
754
+ 'This app reconnects to its configured server; keep that server running.',
755
+ )
756
+ } finally {
757
+ fs.rmSync(staging, { recursive: true, force: true })
758
+ fs.rmSync(scratch, { recursive: true, force: true })
759
+ }
760
+ }