peachsim 0.1.1808 → 0.1.1812

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 (236) hide show
  1. package/README.md +4 -2
  2. package/cli/app-bundle-resources.ts +15 -2
  3. package/cli/cloud-box-artifact.ts +115 -0
  4. package/cli/cloud-client.ts +148 -76
  5. package/cli/cloud-dispatch.ts +4 -4
  6. package/cli/cloud-session.ts +60 -22
  7. package/cli/commands/box.ts +8 -2
  8. package/cli/commands/compat.ts +7 -4
  9. package/cli/commands/control.ts +69 -3
  10. package/cli/commands/coverage.ts +14 -4
  11. package/cli/commands/daemon.ts +41 -0
  12. package/cli/commands/no-bridge-hint.ts +9 -0
  13. package/cli/commands/package.ts +31 -56
  14. package/cli/commands/platform.ts +71 -60
  15. package/cli/commands/preview.ts +73 -24
  16. package/cli/commands/record.ts +10 -2
  17. package/cli/commands/screenshot.ts +17 -60
  18. package/cli/commands/setup.ts +3 -1
  19. package/cli/commands/three-mode.ts +22 -12
  20. package/cli/commands/upload.ts +2 -1
  21. package/cli/desktop-companion.ts +6 -1
  22. package/cli/drivers/desktop.ts +4 -1
  23. package/cli/main.ts +12 -2
  24. package/cli/metro-bundle-assets.ts +14 -4
  25. package/cli/outbound-endpoints.ts +7 -3
  26. package/cli/output-redaction.ts +38 -0
  27. package/cli/privacy.ts +2 -2
  28. package/cli/recording-access.ts +5 -0
  29. package/cli/remote-project-bundle.ts +83 -0
  30. package/cli/shell-init.ts +7 -11
  31. package/cli/telemetry.ts +41 -4
  32. package/cli/usage-error.ts +3 -0
  33. package/cli/ws-bridge.ts +42 -6
  34. package/dist-lib/agent-daemon-client.cjs +1 -1
  35. package/dist-lib/agent-events.cjs +1 -1
  36. package/dist-lib/attached-projects.cjs +1 -1
  37. package/dist-lib/auth/shared-session.cjs +1 -1
  38. package/dist-lib/backend-origin.cjs +1 -1
  39. package/dist-lib/beta.cjs +1 -1
  40. package/dist-lib/beta.mjs +1 -1
  41. package/dist-lib/bridge-constants.cjs +1 -1
  42. package/dist-lib/bridge-contract-input.cjs +1 -1
  43. package/dist-lib/bridge-contract-input.mjs +1 -1
  44. package/dist-lib/bridge-contract.cjs +1 -1
  45. package/dist-lib/bridge-contract.mjs +1 -1
  46. package/dist-lib/bundle-channel.cjs +42897 -40755
  47. package/dist-lib/capture-contract.cjs +7 -8
  48. package/dist-lib/capture-contract.mjs +7 -8
  49. package/dist-lib/cloud-contract.cjs +1 -1
  50. package/dist-lib/cloud-contract.mjs +1 -1
  51. package/dist-lib/cloud-test-args.cjs +1 -1
  52. package/dist-lib/cloud-test-args.mjs +1 -1
  53. package/dist-lib/cloud.cjs +1 -1
  54. package/dist-lib/cloud.mjs +1 -1
  55. package/dist-lib/config.cjs +1 -1
  56. package/dist-lib/config.mjs +1 -1
  57. package/dist-lib/detox/index.cjs +13 -7
  58. package/dist-lib/dev-bundle-resolution.cjs +10 -4
  59. package/dist-lib/expo-swift-bundle.cjs +15889 -15553
  60. package/dist-lib/expo-swift-metadata.cjs +2 -1
  61. package/dist-lib/expo-swift-metadata.mjs +2 -1
  62. package/dist-lib/home-paths.cjs +2 -33
  63. package/dist-lib/host/bridge-host.cjs +20891 -18714
  64. package/dist-lib/host/fetch-proxy-handler.cjs +10 -11
  65. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  66. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  67. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  68. package/dist-lib/host/websocket-proxy.cjs +1 -1
  69. package/dist-lib/index.cjs +620 -553
  70. package/dist-lib/jump-to-source-babel.cjs +1 -1
  71. package/dist-lib/jump-to-source-native.cjs +1 -1
  72. package/dist-lib/kotlin-host.cjs +1 -1
  73. package/dist-lib/menu.cjs +1 -1
  74. package/dist-lib/menu.mjs +1 -1
  75. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  76. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  77. package/dist-lib/metro-production-bundle.cjs +1 -1
  78. package/dist-lib/metro-production-bundle.mjs +1 -1
  79. package/dist-lib/metro.cjs +57 -28
  80. package/dist-lib/native-app-identity-project.cjs +47 -14
  81. package/dist-lib/native-app-identity-project.mjs +55 -20
  82. package/dist-lib/native-app-identity.cjs +1 -1
  83. package/dist-lib/native-app-identity.mjs +1 -1
  84. package/dist-lib/native-firebase-metadata.cjs +1 -1
  85. package/dist-lib/native-firebase-metadata.mjs +1 -1
  86. package/dist-lib/pdfium-raster.cjs +1 -1
  87. package/dist-lib/pdfium-raster.mjs +1 -1
  88. package/dist-lib/plist.cjs +1 -1
  89. package/dist-lib/plist.mjs +1 -1
  90. package/dist-lib/profiles.cjs +1 -1
  91. package/dist-lib/public-brand.cjs +1 -1
  92. package/dist-lib/public-origins-lib-esm.json +27 -26
  93. package/dist-lib/public-origins-lib.json +104 -81
  94. package/dist-lib/react-native-host-modules.cjs +1 -1
  95. package/dist-lib/react-native-host-modules.mjs +1 -1
  96. package/dist-lib/reap-browser.cjs +1 -1
  97. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  98. package/dist-lib/sdk.cjs +1 -1
  99. package/dist-lib/sdk.mjs +1 -1
  100. package/dist-lib/skills.cjs +30700 -24410
  101. package/dist-lib/swift-compile.cjs +336 -222
  102. package/dist-lib/swift-compile.mjs +378 -263
  103. package/dist-lib/swift-package.cjs +19 -7
  104. package/dist-lib/swift-package.mjs +16 -6
  105. package/dist-lib/swift-submit.cjs +1 -1
  106. package/dist-lib/swift-submit.mjs +1 -1
  107. package/dist-lib/swift-toolchain.cjs +49 -1
  108. package/dist-lib/swift.cjs +1 -1
  109. package/dist-lib/vite-swift.cjs +19213 -18937
  110. package/dist-lib/vite.cjs +11 -12
  111. package/dist-lib/worklet-executable.cjs +1 -1
  112. package/dist-lib/worklet-executable.mjs +1 -1
  113. package/dist-types/packages/peach-engine/src/engine/animated.d.ts +4 -0
  114. package/dist-types/packages/peach-engine/src/engine/animation-graph.d.ts +1 -0
  115. package/dist-types/packages/peach-engine/src/engine/expo-manifest.d.ts +1 -0
  116. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -1
  117. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +1 -0
  118. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +8 -1
  119. package/dist-types/packages/peach-globals/src/electronBridgeContract.d.ts +2 -1
  120. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  121. package/kotlin/sdk.tar.gz +0 -0
  122. package/package.json +1 -1
  123. package/runtime-companion.json +1 -1
  124. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCall.h +1 -1
  125. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCallCenter.h +1 -1
  126. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCarrier.h +1 -1
  127. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTSubscriber.h +1 -1
  128. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTSubscriberInfo.h +1 -1
  129. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h +1 -1
  130. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSDictionary.h +1 -1
  131. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSExtensionItem.h +1 -1
  132. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/AVFoundation+MPNowPlayingInfoLanguageOptionAdditions.h +39 -0
  133. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/AVPlayerItem+MediaPlayerAdditions.h +26 -0
  134. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPContentItem.h +67 -0
  135. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPError.h +33 -0
  136. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaEntity.h +53 -0
  137. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItem.h +346 -0
  138. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItemCollection.h +42 -0
  139. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaLibrary.h +76 -0
  140. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPickerController.h +64 -0
  141. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPlayback.h +47 -0
  142. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPlaylist.h +82 -0
  143. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaQuery.h +120 -0
  144. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaQuerySection.h +26 -0
  145. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMoviePlayerController.h +444 -0
  146. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMoviePlayerViewController.h +43 -0
  147. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerApplicationController.h +47 -0
  148. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerController.h +147 -0
  149. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerQueueDescriptor.h +75 -0
  150. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingInfoCenter.h +197 -0
  151. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingInfoLanguageOption.h +107 -0
  152. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingSession.h +89 -0
  153. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentDataSource.h +59 -0
  154. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentDelegate.h +64 -0
  155. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentManager.h +46 -0
  156. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentManagerContext.h +32 -0
  157. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommand.h +143 -0
  158. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommandCenter.h +66 -0
  159. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommandEvent.h +128 -0
  160. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteControlTypes.h +27 -0
  161. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPVolumeSettings.h +20 -0
  162. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPVolumeView.h +82 -0
  163. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayer.apinotes +74 -0
  164. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayer.h +40 -0
  165. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayerDefines.h +84 -0
  166. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/NSUserActivity+MediaPlayerAdditions.h +20 -0
  167. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Modules/module.modulemap +5 -0
  168. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibilityCustomRotor.h +2 -2
  169. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAction.h +1 -1
  170. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBackgroundConfiguration.h +1 -1
  171. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIButtonConfiguration.h +1 -1
  172. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIContextMenuConfiguration.h +1 -1
  173. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIContextMenuInteraction.h +1 -1
  174. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDeferredMenuElement.h +1 -1
  175. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIMenu.h +1 -1
  176. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIPointerStyle.h +5 -5
  177. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISlider.h +1 -1
  178. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISplitViewController.h +12 -50
  179. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UISplitViewControllerLayoutEnvironment.h +2 -8
  180. package/sdk/ios/System/Library/Frameworks/UIKitTypes.framework/Headers/UIKitTypes.h +62 -0
  181. package/sdk/ios/usr/include/dispatch.modulemap +22 -0
  182. package/sdk/ios/usr/include/module.modulemap +8 -3
  183. package/sdk/ios/usr/include/net/if.h +24 -0
  184. package/sdk/ios/usr/include/sys/time.h +1 -1
  185. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +265 -0
  186. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -0
  187. package/sdk/ios/wasm/include/fcntl.h +2 -0
  188. package/sdk/ios/wasm/include/pthread.h +3 -0
  189. package/sdk/ios/wasm/include/stdlib.h +2 -0
  190. package/sdk/ios/wasm/include/unistd.h +2 -2
  191. package/skills/contrast/SKILL.md +2 -2
  192. package/src/bundle-channel.mjs +9 -72
  193. package/src/capture-contract.ts +12 -9
  194. package/src/desktop-host-delivery.ts +16 -2
  195. package/src/dev-bundle-resolution.ts +12 -3
  196. package/src/expo-native-workspace.ts +113 -46
  197. package/src/expo-swift-host.ts +17 -12
  198. package/src/expo-swift-ready.ts +4 -1
  199. package/src/expoSwiftContract.ts +1 -0
  200. package/src/home-paths.ts +4 -48
  201. package/src/host/bridge-host.ts +1 -0
  202. package/src/installed-native-libraries.ts +2 -8
  203. package/src/metro-project-root.ts +2 -1
  204. package/src/native-bundles.ts +122 -0
  205. package/src/native-static-libraries.ts +65 -8
  206. package/src/nitro-adapter.lock.json +272 -272
  207. package/src/nitro-bundle.ts +2 -2
  208. package/src/nitro-compile.ts +68 -28
  209. package/src/nitro-source.ts +24 -6
  210. package/src/nitro-superset.lock.json +94 -34
  211. package/src/nitroContract.ts +3 -0
  212. package/src/podspec-sources.ts +1966 -0
  213. package/src/storageSnapshotContract.ts +40 -0
  214. package/src/swift-compile.ts +77 -26
  215. package/src/swift-design-time.ts +18 -1
  216. package/src/swift-distribution.lock.json +12 -12
  217. package/src/swift-distribution.ts +9 -6
  218. package/src/swift-host.ts +1 -2
  219. package/src/swift-link-roots.ts +13 -2
  220. package/src/swift-objc-compile.ts +12 -0
  221. package/src/swift-objc-standin.ts +321 -114
  222. package/src/swift-package-manifest.ts +4 -3
  223. package/src/swift-package.ts +31 -4
  224. package/src/swift-root-lock.ts +11 -0
  225. package/src/swift-shared-sdk.ts +10 -9
  226. package/src/swift-source-pods.ts +2 -2
  227. package/src/swift-standins.ts +40 -143
  228. package/src/swift-toolchain.ts +59 -0
  229. package/src/swift-wasm-prune.ts +53 -21
  230. package/src/turbo-bundle.ts +4 -5
  231. package/src/turbo-codegen-intake.ts +111 -108
  232. package/src/turbo-compile.ts +63 -33
  233. package/src/turbo-runtime.lock.json +22 -22
  234. package/src/turbo-source.ts +171 -76
  235. package/src/wasm-optimize.ts +31 -2
  236. package/src/xcode-project.ts +65 -15
@@ -1,4 +1,4 @@
1
- import { execFile, execFileSync } from 'node:child_process'
1
+ import { execFile } from 'node:child_process'
2
2
  // the original native source of an app's C++ TurboModules, collected as
3
3
  // CocoaPods builds it for iOS: every autolinked pod whose sources register a
4
4
  // module into React Native's global C++ module map
@@ -10,13 +10,20 @@ import { execFile, execFileSync } from 'node:child_process'
10
10
  // classes are left out: React Native never reaches them for a C++ module.
11
11
  import { createHash } from 'node:crypto'
12
12
  import fs from 'node:fs'
13
- import { createRequire } from 'node:module'
14
13
  import path from 'node:path'
15
14
  import { promisify } from 'node:util'
16
15
  import { PEACH_ANSWERED_NATIVE_PACKAGE_NAMES } from '../../peach-compat/src/generated/supported-native-packages'
17
16
  import { rnxHomeDir } from './home-paths'
18
17
 
19
18
  const execFileAsync = promisify(execFile)
19
+
20
+ // react-native 0.81 emits codegen specs directly under build/generated/ios;
21
+ // other releases nest them in a ReactCodegen subdirectory. use whichever
22
+ // layout the installed release produced.
23
+ function codegenSpecRoot(codegen: string): string {
24
+ const nested = path.join(codegen, 'ReactCodegen')
25
+ return fs.existsSync(nested) ? nested : codegen
26
+ }
20
27
  import {
21
28
  glogSources,
22
29
  nitroDependencyIncludes,
@@ -24,9 +31,15 @@ import {
24
31
  nitroDependencySources,
25
32
  prepareNitroDependencies,
26
33
  } from './nitro-dependencies'
27
- import { iosAutolinkedDependencies, nitroRegisteredNames } from './nitro-source'
34
+ import { iosAutolinkedDependencies } from './nitro-source'
28
35
  import { TURBO_RUNTIME_HEADER } from './nitroAdapterContract'
29
36
  import { COMPILED_TURBO_NATIVE_PACKAGES } from './nitroContract'
37
+ import {
38
+ loadPodspec,
39
+ podspecLinksBinaries,
40
+ podspecMembers,
41
+ podspecSourceFiles as specSourceFiles,
42
+ } from './podspec-sources'
30
43
  import { readPackageFile, relativeInside } from './swift-source-file'
31
44
  import { MAX_SWIFT_COMPILE_SOURCE_BYTES } from './swift-submit'
32
45
  import {
@@ -80,6 +93,8 @@ export interface TurboSourceCollection {
80
93
  configured?: { template: string; originalSha256: string }
81
94
  }[]
82
95
  externalPodSources: { moduleName: string; file: string }[]
96
+ /** the Swift targets compiled from react-native's own renderer pods */
97
+ rendererSwiftTargets: string[]
83
98
  }
84
99
 
85
100
  export const TURBO_CORE_TARGET = 'TurboCore'
@@ -97,6 +112,8 @@ const OBJC_TURBO =
97
112
  /-\s*\(\s*std::shared_ptr<\s*(?:facebook::react::)?TurboModule\s*>\s*\)\s*getTurboModule\s*:/
98
113
  // RCT_EXTERN_MODULE pods are Swift bridge modules owned by collectInstalledSwiftBridgeUnits
99
114
  const OBJC_BRIDGE = /\b(?:RCT_EXPORT_MODULE|RCT_EXPORT_MODULE_NO_LOAD)\s*\(/
115
+ // the macros whose +load registers the class with RCTRegisterModule
116
+ const OBJC_REGISTERED = /\bRCT_EXPORT_MODULE\s*\(|\bRCT_EXTERN(?:_REMAP)?_MODULE\s*\(/
100
117
 
101
118
  function fabricComponents(root: string): boolean {
102
119
  const manifest: unknown = JSON.parse(
@@ -168,12 +185,15 @@ const REACT_NATIVE_OBJC_UNITS = [
168
185
  'React/Base/RCTModuleRegistry.m',
169
186
  'React/Base/RCTParserUtils.m',
170
187
  'React/Base/RCTRedBoxSetEnabled.m',
171
- 'React/Base/RCTUtils.mm',
172
188
  'React/Base/RCTViewRegistry.m',
173
189
  'React/Modules/RCTEventEmitter.m',
174
190
  ]
175
191
  // units added or removed between react native releases; compile those installed
176
192
  const REACT_NATIVE_OBJC_VERSIONED_UNITS = [
193
+ // RCTUtils is plain Objective-C in some releases (.m in 0.78) and
194
+ // Objective-C++ in others (.mm from 0.81); compile whichever is installed
195
+ 'React/Base/RCTUtils.mm',
196
+ 'React/Base/RCTUtils.m',
177
197
  // removed in react-native 0.79; nothing references it there
178
198
  'ReactCommon/runtimeexecutor/platform/ios/ReactCommon/RuntimeExecutorSyncUIThreadUtils.mm',
179
199
  'React/Base/RCTArrayBuffer.mm',
@@ -205,6 +225,12 @@ const REACT_NATIVE_HEADER_DIRS = [
205
225
  },
206
226
  ]
207
227
 
228
+ // pod public headers a quoted bare include reaches through CocoaPods' project
229
+ // header map, which lists every public header by file name
230
+ const REACT_NATIVE_BARE_HEADER_DIRS = [
231
+ 'ReactCommon/react/renderer/imagemanager/platform/ios/react/renderer/imagemanager',
232
+ ]
233
+
208
234
  function object(value: unknown): value is Record<string, unknown> {
209
235
  return value !== null && typeof value === 'object' && !Array.isArray(value)
210
236
  }
@@ -449,9 +475,9 @@ async function resolveExternalTurboPod(
449
475
  }
450
476
 
451
477
  type Pod = {
478
+ appRoot: string
452
479
  root: string
453
480
  file: string
454
- installationRoot: string
455
481
  directory: string
456
482
  text: string
457
483
  name: string
@@ -468,9 +494,9 @@ function readPod(
468
494
  const root = installed?.root ?? originalRoot
469
495
  const podspec = path.join(root, relative)
470
496
  return {
497
+ appRoot,
471
498
  root,
472
499
  file: podspec,
473
- installationRoot: path.join(appRoot, 'ios'),
474
500
  // CocoaPods resolves every glob against the podspec's own directory
475
501
  directory: path.relative(root, path.dirname(podspec)).split(path.sep).join('/'),
476
502
  text: readPackageFile(root, podspec, MAX_SWIFT_COMPILE_SOURCE_BYTES).toString('utf8'),
@@ -515,7 +541,7 @@ function podSegments(pod: Pod): string[] {
515
541
  return walk(pod.text.split('\n'))
516
542
  }
517
543
 
518
- // literal pod globs select directly; CocoaPods evaluates computed membership.
544
+ // literal pod globs select directly; computed membership is evaluated from the podspec.
519
545
  function podGlobFiles(pod: Pod): string[] | null {
520
546
  const segments = podSegments(pod)
521
547
  const lists = (attribute: string) =>
@@ -523,43 +549,20 @@ function podGlobFiles(pod: Pod): string[] | null {
523
549
  const allSources = lists('source_files')
524
550
  const allExcludes = lists('exclude_files')
525
551
  if ([...allSources, ...allExcludes].includes('computed')) {
526
- const require = createRequire(path.join(pod.root, 'package.json'))
527
- const reactNative = path.dirname(require.resolve('react-native/package.json'))
528
- const output = execFileSync(
529
- 'ruby',
530
- [
531
- '-E',
532
- 'UTF-8',
533
- '-r',
534
- 'cocoapods',
535
- '-e',
536
- `json_output = STDOUT.dup
537
- STDOUT.reopen(STDERR)
538
- require ARGV.fetch(3)
539
- root = Pathname.new(ARGV.fetch(0)).realpath
540
- Pod::Config.instance.installation_root = Pathname.new(ARGV.fetch(2))
541
- spec = Pod::Specification.from_file(ARGV.fetch(1))
542
- selected = lambda do |member|
543
- [member] + member.subspec_dependencies(:ios).flat_map { |dependency| selected.call(spec.subspec_by_name(dependency.name)) }
544
- end
545
- files = selected.call(spec).flat_map do |member|
546
- Pod::Sandbox::FileAccessor.new(Pathname.new(ARGV.fetch(1)).dirname, member.consumer(:ios)).source_files
547
- end
548
- json_output.puts JSON.generate(files.uniq.map { |file| file.realpath.relative_path_from(root).to_s }.sort)`,
549
- pod.root,
550
- pod.file,
551
- pod.installationRoot,
552
- path.join(reactNative, 'scripts/react_native_pods.rb'),
553
- ],
554
- { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 },
555
- )
556
- const files: unknown = JSON.parse(output)
557
- if (
558
- !Array.isArray(files) ||
559
- !files.every((file): file is string => typeof file === 'string')
560
- )
561
- throw new Error(`${pod.name}: CocoaPods returned invalid source membership`)
562
- return files
552
+ const directory = path.dirname(pod.file)
553
+ const root = fs.realpathSync(pod.root)
554
+ return [
555
+ ...new Set(
556
+ podspecMembers(loadPodspec(pod.file, pod.appRoot)).flatMap((member) =>
557
+ specSourceFiles(directory, member).map((file) =>
558
+ path
559
+ .relative(root, fs.realpathSync(path.join(directory, file)))
560
+ .split(path.sep)
561
+ .join('/'),
562
+ ),
563
+ ),
564
+ ),
565
+ ].sort()
563
566
  }
564
567
  const flat = (all: (string[] | 'computed' | null)[]) =>
565
568
  all.flatMap((list) => (Array.isArray(list) ? list : []))
@@ -612,16 +615,30 @@ function podHeaderMappings(pod: Pod): { dir: string; headerDir: string }[] {
612
615
  function podFiles(pod: Pod): string[] {
613
616
  if (pod.installed) return pod.installed.files
614
617
  const file = `${pod.name}.podspec`
615
- for (const binary of ['vendored_frameworks', 'vendored_libraries'])
616
- if (new RegExp(`\\.${binary}\\s*=`).test(pod.text))
617
- throw new Error(
618
- `${file}: the pod links prebuilt ${binary}, which only its own wasm build can replace`,
619
- )
618
+ // a binary named in a branch the podspec does not take is not linked, so the
619
+ // evaluated membership decides, as CocoaPods' own evaluation would
620
+ const named = ['vendored_frameworks', 'vendored_libraries'].filter((binary) =>
621
+ new RegExp(`\\.${binary}\\s*=`).test(pod.text),
622
+ )
623
+ if (
624
+ named.length > 0 &&
625
+ podspecMembers(loadPodspec(pod.file, pod.appRoot)).some(podspecLinksBinaries)
626
+ )
627
+ throw new Error(
628
+ `${file}: the pod links prebuilt ${named.join(' and ')}, which only its own wasm build can replace`,
629
+ )
620
630
  const files = podGlobFiles(pod)
621
631
  if (!files?.length) throw new Error(`${file}: no source_files`)
622
632
  return files
623
633
  }
624
634
 
635
+ /** the files a provider's podspec selects as CocoaPods would, absolute, for a
636
+ * project with no installed pods. refused when the pod links prebuilt binaries. */
637
+ export function podspecSourceFiles(provider: TurboProvider, appRoot: string): string[] {
638
+ const pod = readPod(provider, appRoot)
639
+ return podFiles(pod).map((file) => path.join(pod.root, file))
640
+ }
641
+
625
642
  function podPublicHeaders(pod: Pod, files: string[]): Set<string> {
626
643
  if (pod.installed) return new Set(pod.installed.publicHeaders)
627
644
  const segments = podSegments(pod)
@@ -755,19 +772,17 @@ function registers(root: string, files: Iterable<string>, objc = true): boolean
755
772
  export async function discoverTurboProviders(appRoot: string): Promise<TurboProvider[]> {
756
773
  const providers: TurboProvider[] = []
757
774
  for (const { name, root, podspecPath } of await iosAutolinkedDependencies(appRoot)) {
758
- const fabric = fabricComponents(root)
759
- if (
760
- answeredPackages.has(name) &&
761
- !COMPILED_TURBO_NATIVE_PACKAGES.includes(name) &&
762
- !fabric
763
- )
775
+ // a package peach-compat answers keeps its answer, Fabric views included,
776
+ // until COMPILED_TURBO_NATIVE_PACKAGES moves it to its original source.
777
+ if (answeredPackages.has(name) && !COMPILED_TURBO_NATIVE_PACKAGES.includes(name))
764
778
  continue
779
+ // a pod can register Nitro objects and Fabric components independently.
780
+ const fabric = fabricComponents(root)
765
781
  if (!podspecPath) continue
766
782
  const provider = { name, root, podspecPath }
767
783
  const pod = readPod(provider, appRoot)
768
- const files = podGlobFiles(pod)
769
- if (files === null) continue
770
- if (registers(pod.root, files) || fabric) {
784
+ const files = fabric ? null : podGlobFiles(pod)
785
+ if (fabric || (files !== null && registers(pod.root, files))) {
771
786
  const dependencies = await Promise.all(
772
787
  podspecDependencies(pod.text).map((dep) =>
773
788
  resolveExternalTurboPod(dep.name, dep.version),
@@ -893,6 +908,7 @@ export async function collectTurboSources(options: {
893
908
  reactNative,
894
909
  sources: [],
895
910
  externalPodSources: [],
911
+ rendererSwiftTargets: [],
896
912
  }
897
913
  const add = (file: string, text: string) => {
898
914
  if (Object.hasOwn(result.files, file)) {
@@ -966,6 +982,13 @@ export async function collectTurboSources(options: {
966
982
  reactHeaderMap.set(name, file)
967
983
  }
968
984
  }
985
+ for (const from of REACT_NATIVE_BARE_HEADER_DIRS) {
986
+ const found = new Set<string>()
987
+ walkFiles(reactNative.root, from, found)
988
+ for (const file of [...found].sort())
989
+ if (HEADER.test(file))
990
+ reactHeaderMap.set(`bare/${path.posix.basename(file)}`, file)
991
+ }
969
992
  // react native pods expose their umbrella headers through subspecs with
970
993
  // an empty header_dir and a mapping rooted at the podspec directory.
971
994
  const podspecs = new Set<string>()
@@ -1128,7 +1151,7 @@ export async function collectTurboSources(options: {
1128
1151
  return
1129
1152
  }
1130
1153
  if (codegen && HEADER.test(include)) {
1131
- const generated = path.join(codegen, 'ReactCodegen')
1154
+ const generated = codegenSpecRoot(codegen)
1132
1155
  const relative = path.posix.normalize(include.replace(/^ReactCodegen\//, ''))
1133
1156
  if (
1134
1157
  !relative.startsWith('../') &&
@@ -1179,7 +1202,10 @@ export async function collectTurboSources(options: {
1179
1202
  .find((file) => file !== undefined)
1180
1203
  const react =
1181
1204
  mappedReact ??
1182
- reactHeaders().get(quoted && !include.includes('/') ? `React/${include}` : include)
1205
+ (quoted && !include.includes('/')
1206
+ ? (reactHeaders().get(`React/${include}`) ??
1207
+ reactHeaders().get(`bare/${include}`))
1208
+ : reactHeaders().get(include))
1183
1209
  if (react) {
1184
1210
  alias(
1185
1211
  `${core}/include/${include}`,
@@ -1273,6 +1299,8 @@ export async function collectTurboSources(options: {
1273
1299
  let objc = false
1274
1300
  let fabric = false
1275
1301
  const objcClasses = new Set<string>()
1302
+ // module classes no macro registers: React Native finds them by name
1303
+ const unregisteredObjcClasses = new Set<string>()
1276
1304
  const deferredDepUnits: {
1277
1305
  targetName: string
1278
1306
  label: string
@@ -1302,7 +1330,6 @@ export async function collectTurboSources(options: {
1302
1330
  { tool: 'cxx', flags: pod.installed.preprocessorFlags.cxx },
1303
1331
  ]
1304
1332
  const root = pod.root
1305
- const nitro = nitroRegisteredNames(root)
1306
1333
  fabric ||= fabricComponents(root)
1307
1334
  if (pod.installed?.library) {
1308
1335
  result.libraries ??= {}
@@ -1317,7 +1344,15 @@ export async function collectTurboSources(options: {
1317
1344
  headers,
1318
1345
  label,
1319
1346
  root,
1320
- searchPaths: pod.installed?.headerSearchPaths ?? [],
1347
+ // without an installed pod, the roots the podspec's own HEADER_SEARCH_PATHS
1348
+ // name under the pod directory
1349
+ searchPaths:
1350
+ pod.installed?.headerSearchPaths ??
1351
+ [...pod.text.matchAll(/HEADER_SEARCH_PATHS['"]?\s*=>\s*(.+)/g)].flatMap((line) =>
1352
+ [...line[1]!.matchAll(/\$\(PODS_TARGET_SRCROOT\)\/([^\s"'\\)]+)/g)].map(
1353
+ (match) => match[1]!,
1354
+ ),
1355
+ ),
1321
1356
  reactHeaderMaps: (pod.installed?.reactHeaderMaps ?? []).map(
1322
1357
  ({ flag, entries }) => ({
1323
1358
  flag,
@@ -1386,8 +1421,12 @@ export async function collectTurboSources(options: {
1386
1421
  providerObjC = true
1387
1422
  const stripped = stripComments(text)
1388
1423
  if (OBJC_TURBO.test(stripped) || OBJC_BRIDGE.test(stripped)) {
1424
+ const registers = OBJC_REGISTERED.test(stripped)
1389
1425
  for (const [, className] of stripped.matchAll(/@implementation\s+(\w+)/g))
1390
- if (!managers.has(className!)) objcClasses.add(className!)
1426
+ if (!managers.has(className!)) {
1427
+ objcClasses.add(className!)
1428
+ if (!registers) unregisteredObjcClasses.add(className!)
1429
+ }
1391
1430
  for (const [, className] of stripped.matchAll(
1392
1431
  /\bRCT_EXTERN_MODULE\s*\(\s*(\w+)/g,
1393
1432
  ))
@@ -1398,7 +1437,7 @@ export async function collectTurboSources(options: {
1398
1437
  if (!managers.has(className!)) objcClasses.add(className!)
1399
1438
  }
1400
1439
  }
1401
- } else if (file.endsWith('.swift') && !nitro) swiftSources.push(file)
1440
+ } else if (file.endsWith('.swift')) swiftSources.push(file)
1402
1441
  }
1403
1442
  if (providerObjC) sources.push(...codegenObjCSources)
1404
1443
  const depUnits: {
@@ -1546,7 +1585,7 @@ export async function collectTurboSources(options: {
1546
1585
  throw new Error(`${label}: codegenConfig has no name`)
1547
1586
  codegen ??= (await runInstalledTurboCodegen(options.appRoot, options.codegenDir))
1548
1587
  .generatedRoot
1549
- const generated = path.join(codegen, 'ReactCodegen')
1588
+ const generated = codegenSpecRoot(codegen)
1550
1589
  const owned = new Set<string>()
1551
1590
  walkFiles(generated, '', owned)
1552
1591
  const spec = codegenConfig.name
@@ -1774,15 +1813,18 @@ export async function collectTurboSources(options: {
1774
1813
  ])
1775
1814
  codegen ??= (await runInstalledTurboCodegen(options.appRoot, options.codegenDir))
1776
1815
  .generatedRoot
1777
- const generated = path.join(codegen, 'ReactCodegen')
1778
- original(TURBO_CORE_TARGET, 'ReactCodegen', generated, 'RCTModuleProviders.mm')
1779
- alias(
1780
- `${core}/include/ReactCodegen/RCTModuleProviders.h`,
1781
- original(TURBO_CORE_TARGET, 'ReactCodegen', generated, 'RCTModuleProviders.h'),
1782
- )
1816
+ const generated = codegenSpecRoot(codegen)
1817
+ // some releases (0.78) emit no central provider file; their specs self-register
1818
+ if (fs.existsSync(path.join(generated, 'RCTModuleProviders.mm'))) {
1819
+ original(TURBO_CORE_TARGET, 'ReactCodegen', generated, 'RCTModuleProviders.mm')
1820
+ alias(
1821
+ `${core}/include/ReactCodegen/RCTModuleProviders.h`,
1822
+ original(TURBO_CORE_TARGET, 'ReactCodegen', generated, 'RCTModuleProviders.h'),
1823
+ )
1824
+ }
1783
1825
  }
1784
1826
  if (fabric) {
1785
- for (const pod of await installedFabricSources(reactNative.root)) {
1827
+ for (const pod of installedFabricSources(reactNative.root)) {
1786
1828
  const swift = pod.files.some((file) => file.endsWith('.swift'))
1787
1829
  const name = swift ? pod.module : TURBO_CORE_TARGET
1788
1830
  if (swift) {
@@ -1795,10 +1837,11 @@ export async function collectTurboSources(options: {
1795
1837
  languageMode: Number(pod.swiftVersion),
1796
1838
  cxxInterop: false,
1797
1839
  })
1840
+ result.rendererSwiftTargets.push(name)
1798
1841
  }
1799
1842
  for (const file of pod.files) original(name, 'react-native', reactNative.root, file)
1800
1843
  }
1801
- const patterns = await installedRendererDependencyGlobs(reactNative.root)
1844
+ const patterns = installedRendererDependencyGlobs(reactNative.root)
1802
1845
  const matchers = new Map(
1803
1846
  Object.entries(patterns).map(([name, globs]) => [name, globs.map(globRegex)]),
1804
1847
  )
@@ -1830,7 +1873,11 @@ export async function collectTurboSources(options: {
1830
1873
  add(
1831
1874
  host,
1832
1875
  objc
1833
- ? turboObjCHostSource([...objcClasses].sort(), decoratorHasPerformanceLogger)
1876
+ ? turboObjCHostSource(
1877
+ [...objcClasses].sort(),
1878
+ [...unregisteredObjcClasses].sort(),
1879
+ decoratorHasPerformanceLogger,
1880
+ )
1834
1881
  : turboHostSource(withRuntime),
1835
1882
  )
1836
1883
  scanText(
@@ -1969,9 +2016,13 @@ extern "C" __attribute__((export_name("peach_turbo_module_names"))) const char*
1969
2016
 
1970
2017
  function turboObjCHostSource(
1971
2018
  objcClasses: readonly string[],
2019
+ unregisteredClasses: readonly string[],
1972
2020
  decoratorHasPerformanceLogger: boolean,
1973
2021
  ): string {
1974
2022
  const classNamesList = objcClasses.map((name) => `@${JSON.stringify(name)}`).join(', ')
2023
+ const unregisteredList = unregisteredClasses
2024
+ .map((name) => `@${JSON.stringify(name)}`)
2025
+ .join(', ')
1975
2026
  return `// React Native's RCTTurboModuleManager on the process's JSI runtime, set up
1976
2027
  // as a bridgeless RCTInstance sets it up, with the delegate an app gets from
1977
2028
  // RCTDefaultReactNativeFactoryDelegate: module providers from the app's codegen
@@ -2135,6 +2186,18 @@ static BOOL peachIdleTimerDisabled = NO;
2135
2186
  }
2136
2187
  @end
2137
2188
 
2189
+ // React Native's own modules register before any provider's, and RCTBridge.mm
2190
+ // creates the registry's queue in the first RCTRegisterModule. the engine
2191
+ // supplies those modules, so a process whose providers register none (codegen
2192
+ // or class-name modules) would reach RCTGetModuleClasses with a nil queue and
2193
+ // trap. this module stands in for the registration native always has.
2194
+ @interface PeachTurboRegistry : NSObject <RCTBridgeModule>
2195
+ @end
2196
+
2197
+ @implementation PeachTurboRegistry
2198
+ RCT_EXPORT_MODULE()
2199
+ @end
2200
+
2138
2201
  @interface RCTTurboModuleManager (PeachTurboLegacy)
2139
2202
  - (std::shared_ptr<facebook::react::TurboModule>)provideLegacyModule:(const char *)moduleName;
2140
2203
  @end
@@ -2142,6 +2205,7 @@ static BOOL peachIdleTimerDisabled = NO;
2142
2205
  @interface PeachTurboModuleDelegate : NSObject <RCTTurboModuleManagerDelegate>
2143
2206
  @end
2144
2207
 
2208
+ extern "C" void RCTRegisterModule(Class);
2145
2209
  static PeachTurboModuleDelegate *delegate;
2146
2210
  static RCTTurboModuleManager *manager;
2147
2211
 
@@ -2219,6 +2283,15 @@ extern "C" void peachTurboInitialize() {
2219
2283
  moduleRegistry:[RCTModuleRegistry new]
2220
2284
  bundleManager:nil
2221
2285
  callableJSModules:[RCTCallableJSModules new]${decoratorHasPerformanceLogger ? '\n launchOptions:nil\n performanceLogger:[RCTPerformanceLogger new]' : ''}];
2286
+ // RCTGetModuleClasses reads a queue only RCTRegisterModule creates. a React
2287
+ // Native app always has its core modules registered; here the app's own
2288
+ // RCT_EXPORT_MODULE classes are the only registrations, so a provider found by
2289
+ // name alone leaves the manager reading a queue that does not exist
2290
+ for (NSString *className in @[${unregisteredList}]) {
2291
+ Class moduleClass = NSClassFromString(className);
2292
+ if (moduleClass && [moduleClass conformsToProtocol:@protocol(RCTBridgeModule)])
2293
+ RCTRegisterModule(moduleClass);
2294
+ }
2222
2295
  RCTEnableTurboModuleInterop(YES);
2223
2296
  delegate = [PeachTurboModuleDelegate new];
2224
2297
  manager = [[RCTTurboModuleManager alloc] initWithBridgeProxy:nil
@@ -2226,10 +2299,31 @@ extern "C" void peachTurboInitialize() {
2226
2299
  delegate:delegate
2227
2300
  jsInvoker:invoker
2228
2301
  devMenuConfigurationDecorator:nil];
2302
+ // native's RCTInstance routes a module's callFunctionOnModule into React
2303
+ // Native's callable-module registry; here the guest's evaluation answers it,
2304
+ // so a module's RCTEventEmitter events reach the guest's RCTDeviceEventEmitter.
2305
+ [decorator.callableJSModules
2306
+ setBridgelessJSModuleMethodInvoker:^(NSString *moduleName, NSString *methodName, NSArray *args, dispatch_block_t onComplete) {
2307
+ invoker->invokeAsync([=](jsi::Runtime& rt) {
2308
+ auto call = rt.global().getPropertyAsFunction(rt, "peachInvokeCallableModule");
2309
+ call.call(rt,
2310
+ jsi::String::createFromUtf8(rt, moduleName.UTF8String),
2311
+ jsi::String::createFromUtf8(rt, methodName.UTF8String),
2312
+ react::TurboModuleConvertUtils::convertObjCObjectToJSIValue(rt, args));
2313
+ if (onComplete) onComplete();
2314
+ });
2315
+ }];
2229
2316
  [decorator.moduleRegistry setTurboModuleRegistry:manager];
2230
2317
  [manager installJSBindings:runtime];
2231
2318
  }
2232
2319
 
2320
+ // the screenshot the device took, as UIKit posts it to every observer in the
2321
+ // app: the host calls this when the device's screenshot action fires.
2322
+ extern "C" __attribute__((export_name("peach_turbo_post_screenshot"))) void peachTurboPostScreenshot() {
2323
+ [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationUserDidTakeScreenshotNotification
2324
+ object:nil];
2325
+ }
2326
+
2233
2327
  // the names the process answers, newline separated, for the host to claim:
2234
2328
  // the global C++ map, the codegen module providers and each registered
2235
2329
  // Objective-C TurboModule class
@@ -2239,8 +2333,9 @@ extern "C" __attribute__((export_name("peach_turbo_module_names"))) const char*
2239
2333
  [found addObject:@(name.c_str())];
2240
2334
  [found addObjectsFromArray:RCTModuleProviders.moduleProviders.allKeys];
2241
2335
  for (Class moduleClass in RCTGetModuleClasses())
2242
- if ([moduleClass conformsToProtocol:@protocol(RCTTurboModule)] ||
2243
- [moduleClass conformsToProtocol:@protocol(RCTBridgeModule)])
2336
+ if (moduleClass != [PeachTurboRegistry class] &&
2337
+ ([moduleClass conformsToProtocol:@protocol(RCTTurboModule)] ||
2338
+ [moduleClass conformsToProtocol:@protocol(RCTBridgeModule)]))
2244
2339
  [found addObject:RCTBridgeModuleNameForClass(moduleClass)];
2245
2340
  for (NSString *className in @[${classNamesList}]) {
2246
2341
  Class moduleClass = NSClassFromString(className);
@@ -1,4 +1,5 @@
1
- import { BINARYEN_VERSION, wasmOpt } from 'wasm-opt'
1
+ import { execFileSync } from 'node:child_process'
2
+ import { BinaryNotFoundError, BINARYEN_VERSION, wasmOpt } from 'wasm-opt'
2
3
 
3
4
  // the linked executable of a Nitro or Turbo module, size-optimized. clang's own
4
5
  // optimizer pass is off (-O0 on the link) so an edit never pays for it and the
@@ -21,7 +22,7 @@ const FEATURES = [
21
22
  /** feeds the artifact hash: a new optimizer or flag set is a new artifact. */
22
23
  export const WASM_OPTIMIZE_IDENTITY = `wasm-opt ${BINARYEN_VERSION} -Oz ${FEATURES.join(',')}`
23
24
 
24
- export async function optimizeWasm(file: string, output: string): Promise<void> {
25
+ async function runWasmOpt(file: string, output: string): Promise<void> {
25
26
  const result = await wasmOpt([
26
27
  '-Oz',
27
28
  ...FEATURES.map((feature) => `--enable-${feature}`),
@@ -32,3 +33,31 @@ export async function optimizeWasm(file: string, output: string): Promise<void>
32
33
  if (result.status !== 0)
33
34
  throw new Error(`wasm-opt exited ${result.status}: ${result.stderr}`)
34
35
  }
36
+
37
+ // the standalone CLI ships no native binaryen, and a stranger's machine has
38
+ // none on PATH: fetch the pinned release into the shared cache on first use
39
+ // so the first native link works instead of failing.
40
+ function installWasmOpt(): void {
41
+ try {
42
+ execFileSync('npx', ['-y', 'wasm-opt', '--wasm-opt-install'], {
43
+ timeout: 600_000,
44
+ stdio: ['ignore', 'pipe', 'pipe'],
45
+ env: { ...process.env, WASM_OPT_VERSION: BINARYEN_VERSION },
46
+ })
47
+ } catch (error) {
48
+ const detail = error instanceof Error ? error.message : String(error)
49
+ throw new Error(`wasm-opt binary missing and on-demand install failed: ${detail}`, {
50
+ cause: error,
51
+ })
52
+ }
53
+ }
54
+
55
+ export async function optimizeWasm(file: string, output: string): Promise<void> {
56
+ try {
57
+ await runWasmOpt(file, output)
58
+ } catch (error) {
59
+ if (!(error instanceof BinaryNotFoundError)) throw error
60
+ installWasmOpt()
61
+ await runWasmOpt(file, output)
62
+ }
63
+ }