peachsim 0.1.2159 → 0.1.2172

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 (130) hide show
  1. package/README.md +7 -1
  2. package/cli/app-catalog.ts +22 -15
  3. package/cli/bridge-flow-runner.ts +8 -7
  4. package/cli/commands/cleanup.ts +4 -2
  5. package/cli/commands/control.ts +2 -1
  6. package/cli/commands/kotlin.ts +2 -2
  7. package/cli/commands/package.ts +22 -7
  8. package/cli/commands/shell-url.ts +4 -2
  9. package/cli/native-input.ts +1 -1
  10. package/cli/outbound-endpoints.ts +13 -2
  11. package/dist-lib/agent-daemon-client.cjs +1 -1
  12. package/dist-lib/agent-events.cjs +1 -1
  13. package/dist-lib/attached-projects.cjs +2 -3
  14. package/dist-lib/auth/shared-session.cjs +2 -3
  15. package/dist-lib/backend-origin.cjs +1 -1
  16. package/dist-lib/beta.cjs +1 -1
  17. package/dist-lib/beta.mjs +1 -1
  18. package/dist-lib/bridge-constants.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.cjs +1 -1
  20. package/dist-lib/bridge-contract-input.mjs +1 -1
  21. package/dist-lib/bridge-contract.cjs +1 -1
  22. package/dist-lib/bridge-contract.mjs +1 -1
  23. package/dist-lib/bundle-channel.cjs +3639 -3304
  24. package/dist-lib/capture-contract.cjs +1 -1
  25. package/dist-lib/capture-contract.mjs +1 -1
  26. package/dist-lib/cloud-contract.cjs +1 -1
  27. package/dist-lib/cloud-contract.mjs +1 -1
  28. package/dist-lib/cloud-test-args.cjs +1 -1
  29. package/dist-lib/cloud-test-args.mjs +1 -1
  30. package/dist-lib/cloud.cjs +1 -1
  31. package/dist-lib/cloud.mjs +1 -1
  32. package/dist-lib/config.cjs +1 -1
  33. package/dist-lib/config.mjs +1 -1
  34. package/dist-lib/detox/index.cjs +6 -5
  35. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  36. package/dist-lib/expo-swift-bundle.cjs +4226 -8528
  37. package/dist-lib/expo-swift-metadata.cjs +5 -1
  38. package/dist-lib/expo-swift-metadata.mjs +5 -1
  39. package/dist-lib/home-paths.cjs +2 -3
  40. package/dist-lib/host/bridge-host.cjs +4562 -4251
  41. package/dist-lib/host/fetch-proxy-handler.cjs +35 -15
  42. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  43. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  44. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  45. package/dist-lib/host/websocket-proxy.cjs +1 -1
  46. package/dist-lib/index.cjs +195 -155
  47. package/dist-lib/jump-to-source-babel.cjs +1 -1
  48. package/dist-lib/jump-to-source-native.cjs +1 -1
  49. package/dist-lib/kotlin-host.cjs +12 -7
  50. package/dist-lib/menu.cjs +1 -1
  51. package/dist-lib/menu.mjs +1 -1
  52. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  54. package/dist-lib/metro-production-bundle.cjs +1 -1
  55. package/dist-lib/metro-production-bundle.mjs +1 -1
  56. package/dist-lib/metro.cjs +42 -16
  57. package/dist-lib/native-app-identity-project.cjs +10 -5
  58. package/dist-lib/native-app-identity-project.mjs +10 -5
  59. package/dist-lib/native-app-identity.cjs +9 -1
  60. package/dist-lib/native-app-identity.mjs +9 -1
  61. package/dist-lib/native-firebase-metadata.cjs +1 -1
  62. package/dist-lib/native-firebase-metadata.mjs +1 -1
  63. package/dist-lib/pdfium-raster.cjs +1 -1
  64. package/dist-lib/pdfium-raster.mjs +1 -1
  65. package/dist-lib/plist.cjs +1 -1
  66. package/dist-lib/plist.mjs +1 -1
  67. package/dist-lib/profiles.cjs +2 -3
  68. package/dist-lib/public-brand.cjs +1 -1
  69. package/dist-lib/public-origins-lib-esm.json +24 -24
  70. package/dist-lib/public-origins-lib.json +99 -78
  71. package/dist-lib/react-native-host-modules.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.mjs +1 -1
  73. package/dist-lib/reap-browser.cjs +4 -2
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +1 -1
  76. package/dist-lib/sdk.mjs +1 -1
  77. package/dist-lib/skills.cjs +5756 -5114
  78. package/dist-lib/swift-compile.cjs +22 -11
  79. package/dist-lib/swift-compile.mjs +22 -11
  80. package/dist-lib/swift-package.cjs +1 -1
  81. package/dist-lib/swift-package.mjs +1 -1
  82. package/dist-lib/swift-submit.cjs +1 -1
  83. package/dist-lib/swift-submit.mjs +1 -1
  84. package/dist-lib/swift-toolchain.cjs +1 -1
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +27 -13
  87. package/dist-lib/vite.cjs +119 -85
  88. package/dist-lib/worklet-executable.cjs +1 -1
  89. package/dist-lib/worklet-executable.mjs +1 -1
  90. package/dist-types/packages/peach-engine/src/engine/inspect-info.d.ts +0 -1
  91. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +3 -1
  92. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +9 -1
  93. package/dist-types/packages/peach-engine/src/render-worker/ui-frame-clock.d.ts +26 -0
  94. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +2 -2
  95. package/dist-types/packages/peach-engine/src/render-worker/worklet-sab.d.ts +1 -6
  96. package/kotlin/README.md +5 -0
  97. package/kotlin/sdk.tar.gz +0 -0
  98. package/package.json +2 -1
  99. package/runtime-companion.json +1 -1
  100. package/src/answeredNativePackages.ts +1 -5
  101. package/src/disk-cleanup.ts +44 -1
  102. package/src/expo-native-compiler-digest.ts +2 -0
  103. package/src/expo-native-workspace.ts +61 -16
  104. package/src/expo-swift-host.ts +64 -53
  105. package/src/expoSwiftContract.ts +6 -0
  106. package/src/home-activity.ts +124 -0
  107. package/src/home-paths.ts +1 -2
  108. package/src/installed-native-build-options.ts +27 -3
  109. package/src/kotlin-app.ts +156 -31
  110. package/src/kotlin-compose-bom.ts +64 -0
  111. package/src/kotlin-host.ts +12 -3
  112. package/src/kotlin-version-catalog.ts +77 -0
  113. package/src/native-app-identity-project.ts +3 -0
  114. package/src/native-app-identity.ts +15 -0
  115. package/src/native-git.ts +12 -0
  116. package/src/native-prebuilt.ts +11 -2
  117. package/src/nitro-compile.ts +12 -4
  118. package/src/one-native-app-catalog.ts +59 -0
  119. package/src/one-sdk-preparation.ts +53 -8
  120. package/src/react-native-core-digest.ts +24 -0
  121. package/src/react-native-core.ts +239 -0
  122. package/src/reap-browser.ts +3 -1
  123. package/src/swift-compile.ts +6 -5
  124. package/src/swift-packages.ts +2 -0
  125. package/src/swift-wasm-prune.ts +20 -2
  126. package/src/turbo-bundle.ts +1 -1
  127. package/src/turbo-compile.ts +27 -6
  128. package/src/turbo-source.ts +29 -9
  129. package/src/vite-plugin-one.ts +8 -5
  130. package/src/one-native-app-accent.ts +0 -32
@@ -0,0 +1,77 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { parse } from 'smol-toml'
4
+ import { isRecord } from './is-record'
5
+
6
+ // gradle generates the same accessor for dash, underscore and dot separators.
7
+ const accessorName = (name: string) => name.replace(/[-_.]/g, '.')
8
+
9
+ export class KotlinVersionCatalog {
10
+ private readonly file: string
11
+ private readonly tables: Record<string, unknown>
12
+
13
+ constructor(projectDir: string) {
14
+ this.file = path.join(projectDir, 'gradle/libs.versions.toml')
15
+ this.tables = fs.existsSync(this.file)
16
+ ? parse(fs.readFileSync(this.file, 'utf8'))
17
+ : {}
18
+ }
19
+
20
+ private entry(section: string, accessor: string, where: string): unknown {
21
+ const table = this.tables[section]
22
+ const matches = isRecord(table)
23
+ ? Object.entries(table).filter(([name]) => accessorName(name) === accessor)
24
+ : []
25
+ if (matches.length !== 1)
26
+ throw new Error(
27
+ `${where}: libs.${section === 'libraries' ? '' : `${section}.`}${accessor} resolves ${matches.length} entries in ${this.file}`,
28
+ )
29
+ return matches[0]?.[1]
30
+ }
31
+
32
+ private version(value: unknown, where: string): string {
33
+ if (typeof value === 'string') return value
34
+ if (isRecord(value) && typeof value.ref === 'string') {
35
+ const versions = this.tables.versions
36
+ const referenced = isRecord(versions) ? versions[value.ref] : undefined
37
+ if (typeof referenced === 'string') return referenced
38
+ }
39
+ throw new Error(`${where}: ${this.file} declares no simple version for this alias`)
40
+ }
41
+
42
+ scalar(accessor: string, where: string): string {
43
+ return this.version(this.entry('versions', accessor, where), where)
44
+ }
45
+
46
+ plugin(accessor: string, where: string): { id: string; version: string } {
47
+ const entry = this.entry('plugins', accessor, where)
48
+ if (!isRecord(entry) || typeof entry.id !== 'string')
49
+ throw new Error(`${where}: ${this.file} declares no plugin id for ${accessor}`)
50
+ return { id: entry.id, version: this.version(entry.version, where) }
51
+ }
52
+
53
+ dependencies(accessor: string, where: string): string[] {
54
+ const library = (name: string): string => {
55
+ const entry = this.entry('libraries', name, where)
56
+ if (typeof entry === 'string') return entry
57
+ if (!isRecord(entry))
58
+ throw new Error(`${where}: invalid library ${name} in ${this.file}`)
59
+ const module =
60
+ typeof entry.module === 'string'
61
+ ? entry.module
62
+ : typeof entry.group === 'string' && typeof entry.name === 'string'
63
+ ? `${entry.group}:${entry.name}`
64
+ : null
65
+ if (!module)
66
+ throw new Error(`${where}: ${this.file} declares no module for ${name}`)
67
+ return entry.version === undefined
68
+ ? module
69
+ : `${module}:${this.version(entry.version, where)}`
70
+ }
71
+ if (!accessor.startsWith('bundles.')) return [library(accessor)]
72
+ const bundle = this.entry('bundles', accessor.slice('bundles.'.length), where)
73
+ if (!Array.isArray(bundle) || !bundle.every((name) => typeof name === 'string'))
74
+ throw new Error(`${where}: invalid bundle ${accessor} in ${this.file}`)
75
+ return bundle.map((name) => library(accessorName(name)))
76
+ }
77
+ }
@@ -110,8 +110,10 @@ export function readNativeAppIdentityFromXcodeTarget(
110
110
  }
111
111
 
112
112
  const infoPlistStrings: Record<string, string> = {}
113
+ const infoPlistBooleans: Record<string, boolean> = {}
113
114
  for (const [key, value] of Object.entries(dictionary)) {
114
115
  if (typeof value === 'string') infoPlistStrings[key] = value
116
+ else if (typeof value === 'boolean') infoPlistBooleans[key] = value
115
117
  }
116
118
 
117
119
  const querySchemes = dictionary.LSApplicationQueriesSchemes
@@ -222,6 +224,7 @@ export function readNativeAppIdentityFromXcodeTarget(
222
224
  ),
223
225
  permissionUsageDescriptions,
224
226
  infoPlistStrings,
227
+ infoPlistBooleans,
225
228
  urlQuerySchemes,
226
229
  ...(shareIntoAppGroupId ? { shareIntoAppGroupId } : {}),
227
230
  ...(rtcAppGroupIdentifier ? { rtcAppGroupIdentifier } : {}),
@@ -72,6 +72,7 @@ export interface NativeAppIdentity {
72
72
  // every top-level string the app's Info.plist declares, build settings
73
73
  // resolved, for native code that reads its own plist keys.
74
74
  infoPlistStrings?: Readonly<Record<string, string>>
75
+ infoPlistBooleans?: Readonly<Record<string, boolean>>
75
76
  googleSignIn?: Readonly<Record<string, unknown>>
76
77
  urlQuerySchemes?: readonly unknown[]
77
78
  appIntentIdentifiers?: readonly string[]
@@ -198,6 +199,14 @@ export function isNativeAppIdentity(value: unknown): value is NativeAppIdentity
198
199
  !Object.values(value.infoPlistStrings).every((entry) => typeof entry === 'string'))
199
200
  )
200
201
  return false
202
+ if (
203
+ value.infoPlistBooleans !== undefined &&
204
+ (!isRecord(value.infoPlistBooleans) ||
205
+ !Object.values(value.infoPlistBooleans).every(
206
+ (entry) => typeof entry === 'boolean',
207
+ ))
208
+ )
209
+ return false
201
210
  if (value.urlQuerySchemes !== undefined && !Array.isArray(value.urlQuerySchemes))
202
211
  return false
203
212
  if (
@@ -367,6 +376,9 @@ export function readNativeAppIdentity(value: unknown): NativeAppIdentity | null
367
376
  ...(value.infoPlistStrings === undefined
368
377
  ? {}
369
378
  : { infoPlistStrings: { ...value.infoPlistStrings } }),
379
+ ...(value.infoPlistBooleans === undefined
380
+ ? {}
381
+ : { infoPlistBooleans: { ...value.infoPlistBooleans } }),
370
382
  ...(value.appIntentIdentifiers === undefined
371
383
  ? {}
372
384
  : { appIntentIdentifiers: [...value.appIntentIdentifiers] }),
@@ -1087,7 +1099,9 @@ function nativeAppIdentityFromIos(
1087
1099
  }
1088
1100
 
1089
1101
  const infoPlistStrings: Record<string, string> = {}
1102
+ const infoPlistBooleans: Record<string, boolean> = {}
1090
1103
  for (const [key, value] of Object.entries(dictionary)) {
1104
+ if (typeof value === 'boolean') infoPlistBooleans[key] = value
1091
1105
  if (typeof value !== 'string') continue
1092
1106
  const resolved = resolveBuildSetting(value, settings)
1093
1107
  if (resolved !== null) infoPlistStrings[key] = resolved
@@ -1214,6 +1228,7 @@ function nativeAppIdentityFromIos(
1214
1228
  : {}),
1215
1229
  permissionUsageDescriptions,
1216
1230
  infoPlistStrings,
1231
+ infoPlistBooleans,
1217
1232
  urlQuerySchemes,
1218
1233
  ...(keychainAccessGroups === undefined ? {} : { keychainAccessGroups }),
1219
1234
  ...(shareIntoAppGroupId === undefined ? {} : { shareIntoAppGroupId }),
@@ -0,0 +1,12 @@
1
+ import { spawnSync } from 'node:child_process'
2
+
3
+ export function requireNativeGit(): void {
4
+ const result = spawnSync('git', ['--version'], { encoding: 'utf8' })
5
+ if (result.error && 'code' in result.error && result.error.code === 'ENOENT')
6
+ throw new Error(
7
+ 'Git is required to prepare native apps. Install git, then run peach open again.',
8
+ )
9
+ if (result.error) throw result.error
10
+ if (result.status !== 0)
11
+ throw new Error(`Git could not run: ${result.stderr.trim() || result.stdout.trim()}`)
12
+ }
@@ -8,7 +8,8 @@
8
8
  // <kind> is `rust` for the build cache, `slice` for a hand-ported library's
9
9
  // wasm slice, `turbo` for an app's compiled C++ TurboModule executable, `nitro`
10
10
  // for the shared Nitro executable, `expo` for a standard Expo app's native
11
- // build and `expo-pod` for one installed Expo module package's compiled Swift; <key> is a digest of everything the bytes depend on, so an entry can
11
+ // build, `expo-pod` for one installed Expo module package's compiled Swift and
12
+ // `one-sdk` for One's generated Swift SDK sources; <key> is a digest of everything the bytes depend on, so an entry can
12
13
  // never serve different inputs. only CI publishers hold the bucket credentials
13
14
  // (scripts/ops/native-prebuilt-publish.ts, nitro-superset.ts,
14
15
  // expo-native-prebuilt.ts); a host only reads.
@@ -21,7 +22,15 @@ import { isRecord } from './is-record'
21
22
 
22
23
  export const NATIVE_PREBUILT_ORIGIN = 'https://r2.rnxsim.com'
23
24
 
24
- export type NativeEntryKind = 'expo' | 'expo-pod' | 'nitro' | 'rust' | 'slice' | 'turbo'
25
+ export type NativeEntryKind =
26
+ | 'expo'
27
+ | 'expo-pod'
28
+ | 'nitro'
29
+ | 'one-sdk'
30
+ | 'react-native'
31
+ | 'rust'
32
+ | 'slice'
33
+ | 'turbo'
25
34
 
26
35
  export interface NativeEntryFile {
27
36
  path: string
@@ -83,11 +83,22 @@ export function collectNitroCompileInput(
83
83
  // (NitroDefines.hpp) in C++ and in the Swift importer alike.
84
84
  const ndebug = configuration === 'Release' ? ['-DNDEBUG'] : []
85
85
  const files = { ...collection.files }
86
+ const headerAliases = {
87
+ ...dependencies?.headerAliases,
88
+ ...collection.headerAliases,
89
+ }
86
90
  for (const [file, source] of Object.entries(dependencies?.files ?? {})) {
87
91
  if (file === 'Package.swift') continue
88
92
  if (Object.hasOwn(files, file))
89
93
  throw new Error(`Nitro dependency source collision: ${file}`)
90
94
  files[file] = source
95
+ const installed = `ios/${file}`
96
+ if (
97
+ file.startsWith('Pods/') &&
98
+ /\.(?:h|hh|hpp|hxx|inc|inl)$/.test(file) &&
99
+ collection.files[installed] === source
100
+ )
101
+ headerAliases[installed] = file
91
102
  }
92
103
  const manifest = dependencies?.files['Package.swift'] ?? ''
93
104
  const dependencyTargets = manifestCalls(manifest, ['target', 'systemLibrary']).map(
@@ -229,10 +240,7 @@ export function collectNitroCompileInput(
229
240
  ...(dependencies?.nativeTargets ?? []),
230
241
  ...(collection.nativeTargets ?? []),
231
242
  ],
232
- headerAliases: {
233
- ...dependencies?.headerAliases,
234
- ...collection.headerAliases,
235
- },
243
+ headerAliases,
236
244
  resourceBundles: [
237
245
  ...new Map(
238
246
  [
@@ -0,0 +1,59 @@
1
+ // what `one prebuild` writes into Images.xcassets from `native.app.ios`: the
2
+ // AccentColor asset from `accentColor` and the entries of the `assetCatalog`
3
+ // folder. a One app with no ios/ on disk declares them only in the config its
4
+ // dev server evaluated, so the plugin in that server reports them and the cli
5
+ // stamps them into the page's app catalog the way it stamps a prebuilt one.
6
+
7
+ import path from 'node:path'
8
+ import { isRecord } from './is-record'
9
+
10
+ export const ONE_NATIVE_APP_CATALOG_ROUTE = '/__peach/native-app-catalog'
11
+
12
+ const HEX_COLOR = /^#[\da-f]{6}$/i
13
+
14
+ export interface OneNativeAppAccent {
15
+ light: string
16
+ dark: string
17
+ }
18
+
19
+ export interface OneNativeAppCatalog {
20
+ accentColor: OneNativeAppAccent | null
21
+ // absolute path of the declared xcassets folder
22
+ assetCatalog: string | null
23
+ }
24
+
25
+ function parseAccent(value: unknown): OneNativeAppAccent | null {
26
+ if (!isRecord(value) || typeof value.light !== 'string') return null
27
+ if (!HEX_COLOR.test(value.light)) return null
28
+ const dark =
29
+ typeof value.dark === 'string' && HEX_COLOR.test(value.dark)
30
+ ? value.dark
31
+ : value.light
32
+ return { light: value.light, dark }
33
+ }
34
+
35
+ export function parseOneNativeAppCatalog(value: unknown): OneNativeAppCatalog | null {
36
+ if (!isRecord(value)) return null
37
+ const accentColor = parseAccent(value.accentColor)
38
+ const assetCatalog =
39
+ typeof value.assetCatalog === 'string' && path.isAbsolute(value.assetCatalog)
40
+ ? value.assetCatalog
41
+ : null
42
+ return accentColor || assetCatalog ? { accentColor, assetCatalog } : null
43
+ }
44
+
45
+ // the native entry config One's dev server holds on globalThis; the catalog
46
+ // folder resolves against the app root, as prebuild resolves it.
47
+ export function readOneNativeAppCatalog(
48
+ entryConfig: unknown,
49
+ root: string,
50
+ ): OneNativeAppCatalog | null {
51
+ const app = isRecord(entryConfig) ? entryConfig.app : undefined
52
+ const ios = isRecord(app) ? app.ios : undefined
53
+ if (!isRecord(ios)) return null
54
+ return parseOneNativeAppCatalog({
55
+ accentColor: ios.accentColor,
56
+ assetCatalog:
57
+ typeof ios.assetCatalog === 'string' ? path.resolve(root, ios.assetCatalog) : null,
58
+ })
59
+ }
@@ -1,8 +1,14 @@
1
+ import { createHash } from 'node:crypto'
1
2
  import fs from 'node:fs'
2
3
  import { createRequire } from 'node:module'
3
4
  import path from 'node:path'
4
5
  import { pathToFileURL } from 'node:url'
5
- import { ONE_SDK_SOURCE_DIRECTORY, type OneSDKSourceManifest } from './oneSdkContract'
6
+ import { fetchNativeEntry, nativeEntryKey } from './native-prebuilt'
7
+ import {
8
+ ONE_SDK_SOURCE_DIRECTORY,
9
+ readOneSDKSourceManifest,
10
+ type OneSDKSourceManifest,
11
+ } from './oneSdkContract'
6
12
 
7
13
  interface SDKGenerator {
8
14
  importedFrameworks(root: string): string[]
@@ -32,20 +38,59 @@ export async function selectOneSDK(appRoot: string) {
32
38
  return frameworks.length ? { one, generator, frameworks } : null
33
39
  }
34
40
 
35
- export async function prepareOneSDKSources(appRoot: string) {
41
+ export function oneSDKSourceEntry(one: string, frameworks: string[]) {
42
+ const digest = (file: string) =>
43
+ createHash('sha256')
44
+ .update(fs.readFileSync(path.join(one, file)))
45
+ .digest('hex')
46
+ const inputs = {
47
+ generator: digest('dist/sdk/app.mjs'),
48
+ manifest: digest('ios-bindings/manifest.json'),
49
+ facades: createHash('sha256')
50
+ .update(
51
+ frameworks
52
+ .map((name) => `${name}\0${digest(`ios-bindings/${name}.ts`)}`)
53
+ .join('\n'),
54
+ )
55
+ .digest('hex'),
56
+ frameworks: JSON.stringify(frameworks),
57
+ }
58
+ return { name: 'bindings', inputs, key: nativeEntryKey(inputs) }
59
+ }
60
+
61
+ export async function prepareOneSDKSources(appRoot: string, output?: string) {
36
62
  const selected = await selectOneSDK(appRoot)
37
63
  if (!selected) return
38
- if (process.platform !== 'darwin')
39
- throw new Error(
40
- 'One SDK source preparation requires a Mac; supply its prepared native workspace',
41
- )
42
- const generated = await selected.generator.generateAppSdk(selected.frameworks)
64
+ const entry = oneSDKSourceEntry(selected.one, selected.frameworks)
65
+ const directory = output ?? path.join(appRoot, ONE_SDK_SOURCE_DIRECTORY)
43
66
  const { generation } = JSON.parse(
44
67
  fs.readFileSync(path.join(selected.one, 'ios-bindings/manifest.json'), 'utf8'),
45
68
  )
69
+ if (process.platform !== 'darwin') {
70
+ const published = fetchNativeEntry('one-sdk', entry.name, entry.key)
71
+ if (!published)
72
+ throw new Error(
73
+ `One SDK bindings ${entry.key} are not published for this One version. Run peach upgrade after its native bindings are published.`,
74
+ )
75
+ const manifest = readOneSDKSourceManifest(
76
+ JSON.parse(fs.readFileSync(path.join(published, 'manifest.json'), 'utf8')),
77
+ )
78
+ if (
79
+ manifest.generation !== generation ||
80
+ JSON.stringify(manifest.frameworks) !== JSON.stringify(selected.frameworks)
81
+ )
82
+ throw new Error(
83
+ 'published One SDK sources differ from the installed facades or app imports',
84
+ )
85
+ fs.rmSync(directory, { recursive: true, force: true })
86
+ fs.mkdirSync(directory, { recursive: true })
87
+ for (const name of [...manifest.files, 'manifest.json'])
88
+ fs.copyFileSync(path.join(published, name), path.join(directory, name))
89
+ return
90
+ }
91
+ const generated = await selected.generator.generateAppSdk(selected.frameworks)
46
92
  if (generated.generation !== generation)
47
93
  throw new Error('One SDK source generation differs from the installed facades')
48
- const directory = path.join(appRoot, ONE_SDK_SOURCE_DIRECTORY)
49
94
  fs.rmSync(directory, { recursive: true, force: true })
50
95
  fs.mkdirSync(directory, { recursive: true })
51
96
  for (const [name, from] of generated.files)
@@ -0,0 +1,24 @@
1
+ import { createHash } from 'node:crypto'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+
5
+ export const REACT_NATIVE_CORE_SOURCES = [
6
+ 'react-native-core.ts',
7
+ 'turbo-source.ts',
8
+ 'turbo-codegen-intake.ts',
9
+ 'turbo-compile.ts',
10
+ 'nitro-dependencies.ts',
11
+ 'nitroAdapterContract.ts',
12
+ 'podspec-sources.ts',
13
+ '../../../scripts/lib/react-native-core.ts',
14
+ ]
15
+
16
+ export function reactNativeCoreDigest(directory: string): string {
17
+ const hash = createHash('sha256')
18
+ for (const file of REACT_NATIVE_CORE_SOURCES)
19
+ hash
20
+ .update(file)
21
+ .update('\0')
22
+ .update(fs.readFileSync(path.join(directory, file)))
23
+ return hash.digest('hex')
24
+ }
@@ -0,0 +1,239 @@
1
+ import { createHash } from 'node:crypto'
2
+ import fs from 'node:fs'
3
+ import { createRequire } from 'node:module'
4
+ import path from 'node:path'
5
+ import { isDeepStrictEqual } from 'node:util'
6
+ import { cacheDir } from './home-paths'
7
+ import { isRecord } from './is-record'
8
+ import {
9
+ fetchNativeEntry,
10
+ nativeEntryKey,
11
+ nativeEntryPrefix,
12
+ NATIVE_PREBUILT_ORIGIN,
13
+ describeNativeEntry,
14
+ } from './native-prebuilt'
15
+ import { combineNativeStaticLibraries } from './native-static-libraries'
16
+ import { reactNativeCoreDigest } from './react-native-core-digest'
17
+ import {
18
+ compilerSourceDigest,
19
+ swiftDistributionAt,
20
+ swiftModuleDigest,
21
+ swiftModuleSdk,
22
+ } from './swift-compile'
23
+ import { swiftModuleCompiler } from './swift-distribution'
24
+ import { isSwiftNativeTranslationUnit, swiftManifestTargets } from './swift-package'
25
+ import { isSwiftHeaderAliases, isSwiftNativeTargets } from './swiftContract'
26
+ import type { SwiftCompileInput } from './swift-compile'
27
+ import type { TurboSourceCollection } from './turbo-source'
28
+
29
+ export type ReactNativeCoreMode = 'expo' | 'turbo' | 'turbo-cxx'
30
+
31
+ declare const __REACT_NATIVE_CORE_DIGEST__: string | undefined
32
+ const recipe =
33
+ typeof __REACT_NATIVE_CORE_DIGEST__ === 'string'
34
+ ? __REACT_NATIVE_CORE_DIGEST__
35
+ : reactNativeCoreDigest(import.meta.dirname)
36
+
37
+ export type ReactNativeCoreInput = Pick<
38
+ SwiftCompileInput,
39
+ | 'files'
40
+ | 'entry'
41
+ | 'libraries'
42
+ | 'binaryModules'
43
+ | 'staticClangTargets'
44
+ | 'headerAliases'
45
+ | 'nativeTargets'
46
+ >
47
+
48
+ export function reactNativeCoreFloor(reactNativeRoot: string): string {
49
+ const helpers = fs.readFileSync(
50
+ path.join(reactNativeRoot, 'scripts/cocoapods/helpers.rb'),
51
+ 'utf8',
52
+ )
53
+ const floor = /def self\.min_ios_version_supported\s+return ['"]([\d.]+)['"]/.exec(
54
+ helpers,
55
+ )?.[1]
56
+ if (!floor)
57
+ throw new Error(`${reactNativeRoot}: cannot read React Native's iOS minimum`)
58
+ return floor
59
+ }
60
+
61
+ const strings = (value: unknown): value is Record<string, string> =>
62
+ isRecord(value) && Object.values(value).every((item) => typeof item === 'string')
63
+
64
+ export function readReactNativeCore(value: unknown): ReactNativeCoreInput {
65
+ if (
66
+ !isRecord(value) ||
67
+ !strings(value.files) ||
68
+ typeof value.entry !== 'string' ||
69
+ !strings(value.libraries) ||
70
+ !strings(value.binaryModules) ||
71
+ !Array.isArray(value.staticClangTargets) ||
72
+ !value.staticClangTargets.every((name): name is string => typeof name === 'string') ||
73
+ (value.headerAliases !== undefined && !isSwiftHeaderAliases(value.headerAliases)) ||
74
+ (value.nativeTargets !== undefined && !isSwiftNativeTargets(value.nativeTargets))
75
+ )
76
+ throw new Error('invalid prebuilt React Native core')
77
+ return {
78
+ files: value.files,
79
+ entry: value.entry,
80
+ libraries: value.libraries,
81
+ binaryModules: value.binaryModules,
82
+ staticClangTargets: value.staticClangTargets,
83
+ ...(value.headerAliases ? { headerAliases: value.headerAliases } : {}),
84
+ ...(value.nativeTargets ? { nativeTargets: value.nativeTargets } : {}),
85
+ }
86
+ }
87
+
88
+ export function reactNativeCoreEntry(
89
+ reactNativeRoot: string,
90
+ moduleRoot: string,
91
+ mode: ReactNativeCoreMode,
92
+ ) {
93
+ reactNativeRoot = fs.realpathSync(reactNativeRoot)
94
+ const manifest: unknown = JSON.parse(
95
+ fs.readFileSync(path.join(reactNativeRoot, 'package.json'), 'utf8'),
96
+ )
97
+ if (!isRecord(manifest) || typeof manifest.version !== 'string')
98
+ throw new Error(`${reactNativeRoot}: react-native has no version`)
99
+ const headers = createHash('sha256')
100
+ const sources = createHash('sha256')
101
+ const walk = (relative: string) => {
102
+ for (const file of fs
103
+ .readdirSync(path.join(reactNativeRoot, relative), { withFileTypes: true })
104
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
105
+ if (file.name === 'node_modules' || file.name.startsWith('.')) continue
106
+ const name = path.posix.join(relative, file.name)
107
+ if (file.isDirectory()) walk(name)
108
+ else if (
109
+ file.isFile() &&
110
+ (name === 'package.json' ||
111
+ /\.(?:h|hh|hpp|hxx|inl|ipp|c|cc|cpp|cxx|m|mm|swift|podspec|rb)$/.test(name) ||
112
+ (name.startsWith('scripts/') && name.endsWith('.js')))
113
+ ) {
114
+ const bytes = fs.readFileSync(path.join(reactNativeRoot, name))
115
+ sources.update(`${name}\0`).update(bytes)
116
+ if (/\.(?:h|hh|hpp|hxx|inl|ipp)$/.test(name))
117
+ headers.update(`${name}\0`).update(bytes)
118
+ }
119
+ }
120
+ }
121
+ walk('')
122
+ const codegenRoot = path.dirname(
123
+ createRequire(path.join(reactNativeRoot, 'package.json')).resolve(
124
+ '@react-native/codegen/package.json',
125
+ ),
126
+ )
127
+ for (const file of fs
128
+ .readdirSync(codegenRoot, { recursive: true, withFileTypes: true })
129
+ .filter((file) => file.isFile())
130
+ .map((file) => path.relative(codegenRoot, path.join(file.parentPath, file.name)))
131
+ .filter((file) => !file.split(path.sep).includes('node_modules'))
132
+ .sort())
133
+ sources
134
+ .update(`codegen/${file}\0`)
135
+ .update(fs.readFileSync(path.join(codegenRoot, file)))
136
+ const distribution = swiftDistributionAt(moduleRoot)
137
+ const sdk = swiftModuleSdk(moduleRoot)
138
+ const inputs = {
139
+ 'react-native': manifest.version,
140
+ headers: headers.digest('hex'),
141
+ sources: sources.digest('hex'),
142
+ compiler: compilerSourceDigest,
143
+ recipe,
144
+ mode,
145
+ 'ios-deployment-target': reactNativeCoreFloor(reactNativeRoot),
146
+ distribution: distribution?.id ?? swiftModuleDigest(moduleRoot).toString('hex'),
147
+ release: swiftModuleCompiler(moduleRoot).release,
148
+ sdk: sdk.wasmSdkId,
149
+ sdkChecksum: sdk.wasmSdkChecksum,
150
+ }
151
+ const name = `${manifest.version}-${mode}`
152
+ return { name, inputs, key: nativeEntryKey(inputs) }
153
+ }
154
+
155
+ export function prebuiltReactNativeCore(
156
+ reactNativeRoot: string,
157
+ moduleRoot: string,
158
+ mode: ReactNativeCoreMode,
159
+ ): ReactNativeCoreInput {
160
+ const entry = reactNativeCoreEntry(reactNativeRoot, moduleRoot, mode)
161
+ const dir = fetchNativeEntry('react-native', entry.name, entry.key)
162
+ if (!dir)
163
+ throw new Error(
164
+ `no prebuilt React Native ${entry.inputs['react-native']} ${mode} core for headers ${entry.inputs.headers}; publish ${NATIVE_PREBUILT_ORIGIN}/${nativeEntryPrefix('react-native', entry.name, entry.key)}/descriptor.json before opening this app`,
165
+ )
166
+ const file = path.join(dir, 'core.json')
167
+ const descriptor: unknown = JSON.parse(
168
+ fs.readFileSync(path.join(dir, 'descriptor.json'), 'utf8'),
169
+ )
170
+ if (
171
+ !isDeepStrictEqual(
172
+ descriptor,
173
+ describeNativeEntry('react-native', entry.name, entry.inputs, [file]),
174
+ )
175
+ )
176
+ throw new Error(`React Native core ${entry.key} does not match its descriptor`)
177
+ return readReactNativeCore(JSON.parse(fs.readFileSync(file, 'utf8')))
178
+ }
179
+
180
+ export function linkReactNativeCore(
181
+ collection: TurboSourceCollection,
182
+ core: ReactNativeCoreInput,
183
+ moduleRoot: string,
184
+ ): void {
185
+ const targets = swiftManifestTargets(core.files['Package.swift']!).filter(
186
+ (target) => !target.executable,
187
+ )
188
+ const excluded = new Set(
189
+ targets.flatMap((target) =>
190
+ (target.exclude ?? []).map((file) => `${target.path}/${file}`),
191
+ ),
192
+ )
193
+ for (const file of Object.keys(collection.files)) {
194
+ if (excluded.has(file) && collection.files[file] !== core.files[file])
195
+ throw new Error(`React Native core source differs from its prebuilt: ${file}`)
196
+ if (
197
+ isSwiftNativeTranslationUnit(file) &&
198
+ /\/upstream\/react-native\//.test(file) &&
199
+ !excluded.has(file)
200
+ )
201
+ throw new Error(`React Native core prebuilt does not provide ${file}`)
202
+ }
203
+ for (const [file, source] of Object.entries(core.files)) {
204
+ if (file === 'Package.swift' || file === core.entry) continue
205
+ if (collection.files[file] !== undefined && collection.files[file] !== source)
206
+ throw new Error(`conflicting React Native core header ${file}`)
207
+ collection.files[file] = source
208
+ }
209
+ for (const target of targets) {
210
+ const existing = collection.targets.find(({ name }) => name === target.name)
211
+ if (existing)
212
+ existing.exclude = [
213
+ ...new Set([...(existing.exclude ?? []), ...(target.exclude ?? [])]),
214
+ ]
215
+ else collection.targets.push(target)
216
+ }
217
+ collection.binaryModules = { ...collection.binaryModules, ...core.binaryModules }
218
+ collection.headerAliases = { ...collection.headerAliases, ...core.headerAliases }
219
+ for (const [name, library] of Object.entries(core.libraries ?? {})) {
220
+ collection.libraries ??= {}
221
+ const previous = collection.libraries[name]
222
+ if (!previous) collection.libraries[name] = library
223
+ else {
224
+ const staged = [previous, library].map((data) => {
225
+ const file = path.join(
226
+ cacheDir(),
227
+ 'native-archives',
228
+ `${createHash('sha256').update(data).digest('hex')}.a`,
229
+ )
230
+ fs.mkdirSync(path.dirname(file), { recursive: true })
231
+ if (!fs.existsSync(file)) fs.writeFileSync(file, Buffer.from(data, 'base64'))
232
+ return file
233
+ })
234
+ collection.libraries[name] = fs
235
+ .readFileSync(combineNativeStaticLibraries([staged[0]!, staged[1]!], moduleRoot))
236
+ .toString('base64')
237
+ }
238
+ }
239
+ }
@@ -931,7 +931,9 @@ export function softwareChromeLaunchOptions(
931
931
  // native workers own the gpu; chromium presents their bitmaps and DOM.
932
932
  const native: Record<string, unknown> = {
933
933
  ...opts,
934
- args: [...callerArgs, '--disable-gpu'],
934
+ // chrome 156's concurrent marker hits the filler-object check in
935
+ // v8/src/heap/concurrent-marking.cc; native realms keep their own gc.
936
+ args: [...callerArgs, '--disable-gpu', '--js-flags=--no-concurrent-marking'],
935
937
  }
936
938
  delete native.channel
937
939
  delete native.executablePath
@@ -7147,11 +7147,12 @@ function compileSwiftProjectOnce(
7147
7147
  ]),
7148
7148
  ]
7149
7149
  const linked = builtArtifact(layout)
7150
- if (input.optimize) {
7151
- rmSync(path.join(root, '.peach-link.rsp'), { force: true })
7152
- if (existsSync(linked) && statSync(linked).size <= 8)
7153
- rmSync(linked, { force: true })
7154
- }
7150
+ // every link is deferred: a build stopped after the linker wrapper wrote
7151
+ // its 8-byte placeholder would otherwise leave swiftpm seeing a fresh,
7152
+ // empty executable and skipping the link on the next build.
7153
+ rmSync(path.join(root, '.peach-link.rsp'), { force: true })
7154
+ if (existsSync(linked) && statSync(linked).size <= 8)
7155
+ rmSync(linked, { force: true })
7155
7156
  report('compiling and linking Swift modules')
7156
7157
  try {
7157
7158
  // clang consumes the real emitted headers after swift finishes.
@@ -16,6 +16,7 @@ import path from 'node:path'
16
16
  import { setTimeout as sleep } from 'node:timers/promises'
17
17
  import { promisify } from 'node:util'
18
18
  import { cacheDir } from './home-paths'
19
+ import { requireNativeGit } from './native-git'
19
20
  import { tryAcquireNumberedLock } from './numbered-lock'
20
21
  import { preparedSwiftCheckouts, preparedSwiftPin } from './prepared-xcode-phases'
21
22
  import {
@@ -319,6 +320,7 @@ async function fetchCheckout(
319
320
  ): Promise<void> {
320
321
  const dir = path.join(checkouts, identity)
321
322
  if (preparedSwiftPin(checkouts, identity, pin.location, pin.revision)) return
323
+ requireNativeGit()
322
324
  const key = checkoutKey(dir, pin)
323
325
  const git: Git = async (cwd, ...args) =>
324
326
  (