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.
- package/README.md +21 -3
- package/cli/app-bundle-resources.ts +2 -1
- package/cli/app-fonts.ts +4 -4
- package/cli/app-splash.ts +4 -4
- package/cli/app-stubs.ts +17 -0
- package/cli/command-registry.ts +1 -0
- package/cli/commands/control.ts +83 -822
- package/cli/commands/coverage-swift.ts +112 -4
- package/cli/commands/daemon.ts +8 -0
- package/cli/commands/detox.ts +3 -0
- package/cli/commands/doctor.ts +19 -2
- package/cli/commands/inspect/actions.ts +74 -14
- package/cli/commands/inspect/core.ts +5 -1
- package/cli/commands/inspect/settling.ts +5 -2
- package/cli/commands/inspect/wait-ready.ts +6 -0
- package/cli/commands/inspect.ts +48 -45
- package/cli/commands/kotlin.ts +12 -2
- package/cli/commands/package.ts +760 -0
- package/cli/commands/serve.ts +6 -0
- package/cli/commands/shell-url.ts +838 -0
- package/cli/commands/swift.ts +42 -102
- package/cli/commands/test.ts +20 -0
- package/cli/commands/upload.ts +1 -1
- package/cli/device-option.ts +1 -1
- package/cli/main.ts +13 -1
- package/cli/native-input.ts +199 -0
- package/cli/outbound-endpoints.ts +26 -1
- package/cli/packaged-app-launcher.ts +95 -0
- package/cli/scene-video.ts +36 -12
- package/detox/index.ts +196 -24
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +5 -2
- package/dist-lib/auth/shared-session.cjs +5 -2
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +39889 -31873
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +195 -63
- package/dist-lib/dev-bundle-resolution.cjs +14 -13
- package/dist-lib/expo-swift-bundle.cjs +18507 -11835
- package/dist-lib/expo-swift-metadata.cjs +4 -1
- package/dist-lib/expo-swift-metadata.mjs +3 -1
- package/dist-lib/home-paths.cjs +27 -3
- package/dist-lib/host/bridge-host.cjs +28373 -24090
- package/dist-lib/host/fetch-proxy-handler.cjs +235 -225
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +915 -399
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +335 -47
- package/dist-lib/menu.cjs +13 -1
- package/dist-lib/menu.mjs +13 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +918 -411
- package/dist-lib/native-app-identity-project.cjs +703 -283
- package/dist-lib/native-app-identity-project.mjs +500 -87
- package/dist-lib/native-app-identity.cjs +13 -2
- package/dist-lib/native-app-identity.mjs +13 -2
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +5 -2
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +28 -23
- package/dist-lib/public-origins-lib.json +418 -224
- package/dist-lib/react-native-host-modules.cjs +35 -2
- package/dist-lib/react-native-host-modules.mjs +35 -2
- package/dist-lib/reap-browser.cjs +12 -4
- package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
- package/dist-lib/sdk.cjs +17 -7
- package/dist-lib/sdk.mjs +16 -7
- package/dist-lib/skills.cjs +44825 -29141
- package/dist-lib/swift-compile.cjs +616 -400
- package/dist-lib/swift-compile.mjs +528 -315
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +105 -17
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +4660 -2252
- package/dist-lib/vite.cjs +248 -234
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
- package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +7 -4
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +9 -6
- package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +0 -5
- package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +11 -1
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +5 -12
- package/dist-types/packages/peach-engine/src/engine/render-damage.d.ts +2 -2
- package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +5 -0
- package/dist-types/packages/peach-engine/src/engine/text-paragraph.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
- package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +7 -2
- package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +5 -0
- package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +36 -2
- package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
- package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
- package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
- package/kotlin/README.md +3 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/scripts/dev-server-scanner.ts +12 -25
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccount.h +55 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountCredential.h +35 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountStore.h +94 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountType.h +53 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACError.h +37 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/Accounts.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/AccountsDefines.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Accounts.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +3 -1
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +58 -3
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +711 -46
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
- package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
- package/sdk/ios/usr/include/module.modulemap +1 -0
- package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
- package/sdk/ios/usr/include/os/signpost.h +414 -0
- package/sdk/ios/usr/include/os.modulemap +10 -0
- package/sdk/ios/usr/include/sys/cdefs.h +5 -0
- package/sdk/ios/usr/include/sys/ioccom.h +99 -0
- package/sdk/ios/usr/include/sys/syslog.h +236 -0
- package/sdk/ios/usr/include/syslog.h +24 -0
- package/sdk/ios/wasm/include/errno.h +4 -20
- package/sdk/ios/wasm/include/fcntl.h +4 -2
- package/sdk/ios/wasm/include/pthread.h +3 -0
- package/sdk/ios/wasm/include/setjmp.h +57 -0
- package/sdk/ios/wasm/include/stdio.h +24 -0
- package/sdk/ios/wasm/include/stdlib.h +32 -7
- package/sdk/ios/wasm/include/sys/file.h +7 -0
- package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
- package/sdk/ios/wasm/include/sys/resource.h +2 -2
- package/sdk/ios/wasm/include/sys/syscall.h +9 -0
- package/sdk/ios/wasm/include/sys/time.h +10 -0
- package/sdk/ios/wasm/include/unistd.h +12 -3
- package/sdk/native-hashes.json +4 -3
- package/skills/contrast/SKILL.md +2 -1
- package/skills/peach-debug/SKILL.md +0 -1
- package/skills/peach-perf/SKILL.md +0 -1
- package/skills/peach-setup/SKILL.md +0 -1
- package/skills/peach-test/SKILL.md +7 -4
- package/skills/peach-visual/SKILL.md +0 -1
- package/src/admitted-mac-build.ts +3 -0
- package/src/android-app-identity.ts +18 -0
- package/src/android-autolinking.ts +1 -0
- package/src/android-bridge-packages.ts +279 -0
- package/src/android-root-module.ts +9 -9
- package/src/appPackageContract.ts +83 -0
- package/src/bridge-contract.ts +50 -0
- package/src/bundle-channel.mjs +41 -6
- package/src/cli-runtime.ts +9 -5
- package/src/dev-bundle-resolution.ts +7 -27
- package/src/dom-source-reference.ts +15 -0
- package/src/expo-discovery-cache.ts +134 -26
- package/src/expo-kotlin-host.ts +97 -26
- package/src/expo-manifest-body.ts +33 -0
- package/src/expo-native-workspace.ts +158 -38
- package/src/expo-swift-host.ts +350 -75
- package/src/expo-swift-ready.ts +5 -1
- package/src/expoKotlinContract.ts +12 -2
- package/src/expoSwiftContract.ts +10 -0
- package/src/generated/swift-c-predefines.json +1 -1
- package/src/home-paths.ts +41 -2
- package/src/host/app-package-handler.ts +47 -0
- package/src/host/bridge-host.ts +8 -0
- package/src/host/fetch-proxy-handler.ts +10 -0
- package/src/host/staged-host-files.ts +18 -0
- package/src/index.ts +3 -0
- package/src/kotlin-host.ts +225 -48
- package/src/kotlin-instance-source.ts +126 -0
- package/src/kotlinSdkContract.ts +2 -1
- package/src/menu.ts +14 -0
- package/src/native-app-identity-project.ts +7 -2
- package/src/native-app-identity.ts +11 -0
- package/src/native-firebase-config.ts +24 -1
- package/src/native-prebuilt.ts +154 -0
- package/src/nitro-adapter.lock.json +270 -270
- package/src/nitro-adapter.ts +56 -50
- package/src/nitro-bundle.ts +92 -74
- package/src/nitro-compile.ts +45 -14
- package/src/nitro-dependencies.ts +63 -46
- package/src/nitro-source.ts +64 -26
- package/src/nitroAdapterContract.ts +146 -98
- package/src/nitroContract.ts +71 -21
- package/src/react-native-bridge-modules.ts +70 -42
- package/src/react-native-host-modules.ts +34 -1
- package/src/reactNativeConfigurationContract.ts +14 -0
- package/src/reap-browser.ts +15 -3
- package/src/sdk.ts +5 -0
- package/src/settingsContract.ts +38 -1
- package/src/sim-client.ts +4 -1
- package/src/storageSnapshotContract.ts +32 -81
- package/src/swift-compile.ts +268 -89
- package/src/swift-coverage/indexdump.ts +22 -6
- package/src/swift-coverage/indexing.ts +4 -4
- package/src/swift-coverage/provenance.ts +1 -0
- package/src/swift-coverage/sdk.ts +104 -20
- package/src/swift-coverage/types.ts +34 -0
- package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
- package/src/swift-coverage/xcode-assets.ts +89 -131
- package/src/swift-coverage/xcode.ts +10 -2
- package/src/swift-cxx-reachable.ts +2 -1
- package/src/swift-distribution.lock.json +20 -16
- package/src/swift-host.ts +98 -22
- package/src/swift-icu.ts +1 -1
- package/src/swift-link-roots.ts +118 -0
- package/src/swift-objc-compile.ts +144 -22
- package/src/swift-objc-import.ts +6 -0
- package/src/swift-objc-standin.ts +2 -14
- package/src/swift-package-manifest.ts +14 -6
- package/src/swift-packages.ts +75 -11
- package/src/swift-pdf-raster.ts +1 -0
- package/src/swift-root-lock.ts +17 -1
- package/src/swift-source-pods.ts +2 -10
- package/src/swift-standin-emit.ts +597 -57
- package/src/swift-standins.ts +599 -56
- package/src/swift-submit.ts +7 -1
- package/src/swift-toolchain.ts +140 -17
- package/src/turbo-bundle.ts +81 -0
- package/src/turbo-codegen-intake.ts +91 -0
- package/src/turbo-compile.ts +120 -0
- package/src/turbo-runtime.lock.json +69 -0
- package/src/turbo-source.ts +754 -0
- package/src/vite-plugin-one.ts +17 -12
- package/src/vite-plugin.ts +28 -15
- package/src/xcode-project.ts +223 -22
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { pinSharedListenerScan, probePort } from '../../scripts/dev-server-scanner'
|
|
5
|
+
import { readAndroidLauncherRootModuleName } from '../../src/android-root-module'
|
|
6
|
+
import { ANDROID_ROOT_MODULE_QUERY_PARAM } from '../../src/androidRootModuleContract'
|
|
7
|
+
import { isLoopbackHost, loopbackOriginOf } from '../../src/backend-origin'
|
|
8
|
+
import { resolveSootsimShellBaseUrlForBridgePort } from '../../src/bridge-constants'
|
|
9
|
+
import { getCliRuntime } from '../../src/cli-runtime.ts'
|
|
10
|
+
import {
|
|
11
|
+
mergePeachConfig,
|
|
12
|
+
PEACH_CONFIG_QUERY_PARAM,
|
|
13
|
+
readPeachConfigFromSearchParams,
|
|
14
|
+
} from '../../src/config'
|
|
15
|
+
import {
|
|
16
|
+
resolveConnectionInput,
|
|
17
|
+
type ResolvedDevBundle,
|
|
18
|
+
} from '../../src/dev-bundle-resolution'
|
|
19
|
+
import { isDeviceModel } from '../../src/device-catalog.ts'
|
|
20
|
+
import { projectLoopbackUrl } from '../../src/host/loopback-ports'
|
|
21
|
+
import {
|
|
22
|
+
isStagedHostFileRequest,
|
|
23
|
+
stageHostBytes,
|
|
24
|
+
stageHostFile,
|
|
25
|
+
stageHostLaunchMetadata,
|
|
26
|
+
} from '../../src/host/staged-host-files'
|
|
27
|
+
import { readInstalledNativePackageVersions } from '../../src/installed-package-versions'
|
|
28
|
+
import { resolveMetroProjectRoot } from '../../src/metro-project-root'
|
|
29
|
+
import {
|
|
30
|
+
canExtractNativeAppIdentity,
|
|
31
|
+
createNativeAppIdentityHeader,
|
|
32
|
+
} from '../../src/native-app-identity'
|
|
33
|
+
import {
|
|
34
|
+
NativeAppTargetSelectionError,
|
|
35
|
+
readNativeAppIdentityFromProject,
|
|
36
|
+
} from '../../src/native-app-identity-project'
|
|
37
|
+
import { applyHotMode } from '../../src/native-dev-bundle-url'
|
|
38
|
+
import {
|
|
39
|
+
readExpoConfigAsync,
|
|
40
|
+
readNativeFirebaseConfig,
|
|
41
|
+
resolveExpoConfigModule,
|
|
42
|
+
} from '../../src/native-firebase-config'
|
|
43
|
+
import {
|
|
44
|
+
PEACH_SIMULATOR_SHELL_FILE,
|
|
45
|
+
isPeachSimulatorDocumentPath,
|
|
46
|
+
} from '../../src/simulator-route'
|
|
47
|
+
import { sleep } from '../../src/sleep'
|
|
48
|
+
import { stageAppBundleResources } from '../app-bundle-resources'
|
|
49
|
+
import { discoverAppCatalog } from '../app-catalog'
|
|
50
|
+
import { discoverNativeLinkedAppFonts } from '../app-fonts'
|
|
51
|
+
import {
|
|
52
|
+
findExpoAppConfig,
|
|
53
|
+
resolveAppProject,
|
|
54
|
+
type ResolvedAppProject,
|
|
55
|
+
} from '../app-project'
|
|
56
|
+
import {
|
|
57
|
+
type DiscoveredAppSplashSpec,
|
|
58
|
+
discoverConfigPluginAppSplash,
|
|
59
|
+
discoverOneNativeAppSplash,
|
|
60
|
+
encodeAppSplashWire,
|
|
61
|
+
splashImageUrls,
|
|
62
|
+
} from '../app-splash'
|
|
63
|
+
import {
|
|
64
|
+
resolveBridgePortForPin,
|
|
65
|
+
resolveBridgeWorld,
|
|
66
|
+
worldForBridgePort,
|
|
67
|
+
} from '../ws-bridge'
|
|
68
|
+
import { readNativeProjectRenderer } from './detect'
|
|
69
|
+
|
|
70
|
+
// built-in shell apps use pathname-based routing, not ?bundle= params
|
|
71
|
+
const SHELL_APPS: Record<string, string> = {
|
|
72
|
+
rn: '/rn',
|
|
73
|
+
connectrn: '/rn',
|
|
74
|
+
'connect-rn': '/rn',
|
|
75
|
+
clock: '/app/clock',
|
|
76
|
+
'native-ui': '/app/native-ui',
|
|
77
|
+
tamagui: '/app/tamagui',
|
|
78
|
+
settings: '/app/settings',
|
|
79
|
+
photos: '/app/photos',
|
|
80
|
+
camera: '/app/camera',
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function normalizeKnownTarget(target: string): string {
|
|
84
|
+
return target.trim()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function looksLikeSootsimUrl(target: string): boolean {
|
|
88
|
+
try {
|
|
89
|
+
const url = new URL(target)
|
|
90
|
+
const pathname = url.pathname.replace(/\/+$/, '') || '/'
|
|
91
|
+
return (
|
|
92
|
+
url.searchParams.has('open') ||
|
|
93
|
+
url.searchParams.has('port') ||
|
|
94
|
+
url.searchParams.has('bundle') ||
|
|
95
|
+
url.searchParams.has('demo') ||
|
|
96
|
+
url.searchParams.has('test') ||
|
|
97
|
+
url.searchParams.has('case') ||
|
|
98
|
+
url.pathname.includes(PEACH_SIMULATOR_SHELL_FILE) ||
|
|
99
|
+
isPeachSimulatorDocumentPath(pathname) ||
|
|
100
|
+
pathname === '/sootsim' ||
|
|
101
|
+
url.pathname === '/__peachsim' ||
|
|
102
|
+
url.pathname === '/__peachsim/' ||
|
|
103
|
+
pathname === '/rn' ||
|
|
104
|
+
/^\/rn\/[^/]+$/i.test(pathname) ||
|
|
105
|
+
/^\/app\/[^/]+$/i.test(pathname) ||
|
|
106
|
+
pathname === '/__peachsim/rn' ||
|
|
107
|
+
/^\/__peachsim\/rn\/[^/]+$/i.test(pathname) ||
|
|
108
|
+
/^\/__peachsim\/app\/[^/]+$/i.test(pathname)
|
|
109
|
+
)
|
|
110
|
+
} catch {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function looksLikeShellPathTarget(target: string): boolean {
|
|
116
|
+
try {
|
|
117
|
+
const url = new URL(target, 'http://sootsim.local')
|
|
118
|
+
if (url.origin !== 'http://sootsim.local') return false
|
|
119
|
+
const pathname = url.pathname.replace(/\/+$/, '') || '/'
|
|
120
|
+
return (
|
|
121
|
+
pathname === '/rn' ||
|
|
122
|
+
/^\/rn\/[^/]+$/i.test(pathname) ||
|
|
123
|
+
/^\/app\/[^/]+$/i.test(pathname) ||
|
|
124
|
+
pathname === '/__peachsim/rn' ||
|
|
125
|
+
/^\/__peachsim\/rn\/[^/]+$/i.test(pathname) ||
|
|
126
|
+
/^\/__peachsim\/app\/[^/]+$/i.test(pathname)
|
|
127
|
+
)
|
|
128
|
+
} catch {
|
|
129
|
+
return false
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function buildShellPathOpenUrl(target: string, baseUrl: string): string {
|
|
134
|
+
const targetUrl = new URL(target, 'http://sootsim.local')
|
|
135
|
+
const url = new URL(baseUrl)
|
|
136
|
+
const prefix = getShellRoutePrefix(url.pathname)
|
|
137
|
+
const routePath = targetUrl.pathname.startsWith('/__peachsim/')
|
|
138
|
+
? targetUrl.pathname.slice('/__peachsim'.length)
|
|
139
|
+
: targetUrl.pathname
|
|
140
|
+
|
|
141
|
+
url.pathname = `${prefix}${routePath}`
|
|
142
|
+
const baseDemo = url.searchParams.getAll('demo')
|
|
143
|
+
url.search = targetUrl.search
|
|
144
|
+
// demo also sets embed chrome around native routes; a target can override it.
|
|
145
|
+
if (!targetUrl.searchParams.has('demo')) {
|
|
146
|
+
for (const demo of baseDemo) url.searchParams.append('demo', demo)
|
|
147
|
+
}
|
|
148
|
+
url.hash = targetUrl.hash
|
|
149
|
+
return url.toString()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function localBasePort(target: string): number | null {
|
|
153
|
+
try {
|
|
154
|
+
const url = new URL(target.startsWith('http') ? target : `http://${target}`)
|
|
155
|
+
const pathname = url.pathname || '/'
|
|
156
|
+
if ((pathname !== '/' && pathname !== '') || url.search || url.hash) return null
|
|
157
|
+
if (!isLoopbackHost(url.hostname)) return null
|
|
158
|
+
const port = url.port ? Number(url.port) : url.protocol === 'https:' ? 443 : 80
|
|
159
|
+
return Number.isFinite(port) && port > 0 ? port : null
|
|
160
|
+
} catch {
|
|
161
|
+
return null
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// a dev server started alongside open connect may still be booting when the
|
|
166
|
+
// first probe lands. retry briefly so staging does not fail on a server that
|
|
167
|
+
// becomes probe-ready a few seconds later.
|
|
168
|
+
const DEV_BUNDLE_RESOLVE_ATTEMPTS = 15
|
|
169
|
+
const DEV_BUNDLE_RESOLVE_INTERVAL_MS = 1000
|
|
170
|
+
|
|
171
|
+
export async function resolveConnectionInputForCli(
|
|
172
|
+
target: string,
|
|
173
|
+
signal?: AbortSignal,
|
|
174
|
+
): Promise<ResolvedDevBundle> {
|
|
175
|
+
const normalized = normalizeKnownTarget(target)
|
|
176
|
+
const registeredPort = /^\d+$/.test(normalized)
|
|
177
|
+
? Number(normalized)
|
|
178
|
+
: localBasePort(normalized)
|
|
179
|
+
|
|
180
|
+
console.log(` resolving native bundle for ${normalized} (waiting for the dev server)…`)
|
|
181
|
+
let lastError: Error | null = null
|
|
182
|
+
const releaseListenerScan = pinSharedListenerScan()
|
|
183
|
+
try {
|
|
184
|
+
for (let attempt = 0; attempt < DEV_BUNDLE_RESOLVE_ATTEMPTS; attempt++) {
|
|
185
|
+
signal?.throwIfAborted()
|
|
186
|
+
let resolutionTarget = normalized
|
|
187
|
+
if (registeredPort && registeredPort > 0) {
|
|
188
|
+
const discovered = await probePort(registeredPort)
|
|
189
|
+
// a provisional bundle URL is enough to LIST the server but not to open
|
|
190
|
+
// it; resolveConnectionInput joins the scanner's pending manifest with
|
|
191
|
+
// the server response instead of starting the same work again.
|
|
192
|
+
if (discovered && !discovered.bundleUrlProvisional) {
|
|
193
|
+
return {
|
|
194
|
+
bundleUrl: projectLoopbackUrl(discovered.bundleUrl),
|
|
195
|
+
port: discovered.port,
|
|
196
|
+
framework: discovered.framework,
|
|
197
|
+
projectName: discovered.projectName,
|
|
198
|
+
manifestProjectRoot: discovered.manifestProjectRoot,
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// keep the scanner's answering address and join its manifest request.
|
|
202
|
+
// probing both loopback families again duplicates cold config work.
|
|
203
|
+
if (discovered?.bundleUrlProvisional && /^\d+$/.test(normalized)) {
|
|
204
|
+
resolutionTarget = new URL(discovered.bundleUrl).origin
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
const resolved = await resolveConnectionInput(resolutionTarget, undefined, {
|
|
210
|
+
waitMs: null,
|
|
211
|
+
signal,
|
|
212
|
+
})
|
|
213
|
+
return { ...resolved, bundleUrl: projectLoopbackUrl(resolved.bundleUrl) }
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (
|
|
216
|
+
!(error instanceof Error) ||
|
|
217
|
+
!error.message.startsWith('could not resolve a native bundle')
|
|
218
|
+
) {
|
|
219
|
+
throw error
|
|
220
|
+
}
|
|
221
|
+
lastError = error
|
|
222
|
+
}
|
|
223
|
+
await sleep(DEV_BUNDLE_RESOLVE_INTERVAL_MS)
|
|
224
|
+
}
|
|
225
|
+
throw (
|
|
226
|
+
lastError ??
|
|
227
|
+
new Error(
|
|
228
|
+
'could not resolve a native bundle for ' + normalized + ' after retrying.',
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
} finally {
|
|
232
|
+
releaseListenerScan()
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function getShellRoutePrefix(pathname: string): string {
|
|
237
|
+
const normalized = pathname.replace(/\/+$/, '') || '/'
|
|
238
|
+
if (normalized === '/__peachsim' || normalized.startsWith('/__peachsim/')) {
|
|
239
|
+
return '/__peachsim'
|
|
240
|
+
}
|
|
241
|
+
return ''
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function buildConnectOpenUrl(target: string, baseUrl: string): string {
|
|
245
|
+
const normalizedTarget = normalizeKnownTarget(target)
|
|
246
|
+
const url = new URL(baseUrl)
|
|
247
|
+
const prefix = getShellRoutePrefix(url.pathname)
|
|
248
|
+
|
|
249
|
+
url.pathname = `${prefix}/rn`
|
|
250
|
+
url.searchParams.delete('bundle')
|
|
251
|
+
url.searchParams.delete('app')
|
|
252
|
+
url.searchParams.delete('open')
|
|
253
|
+
url.searchParams.delete('port')
|
|
254
|
+
|
|
255
|
+
if (/^\d+$/.test(normalizedTarget)) {
|
|
256
|
+
url.pathname = `${prefix}/rn/${normalizedTarget}`
|
|
257
|
+
} else {
|
|
258
|
+
url.pathname = `${prefix}/rn`
|
|
259
|
+
url.searchParams.set('open', normalizedTarget)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return url.toString()
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function shouldResolveBundleTargetInCli(target: string): boolean {
|
|
266
|
+
// a shell url already names its app; resolving it as a dev server turned
|
|
267
|
+
// http://localhost:5173/?demo=x into the native app /rn/443.
|
|
268
|
+
if (looksLikeSootsimUrl(target)) return false
|
|
269
|
+
const normalizedTarget = normalizeKnownTarget(target)
|
|
270
|
+
if (/^\d+$/.test(normalizedTarget)) return true
|
|
271
|
+
if (/^https?:\/\//i.test(normalizedTarget)) return true
|
|
272
|
+
return /^(localhost|127\.0\.0\.1|\[::1\]|[^/]+\.localhost):\d+(?:\/.*)?$/i.test(
|
|
273
|
+
normalizedTarget,
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async function buildResolvedBundleOpenUrl(
|
|
278
|
+
target: string,
|
|
279
|
+
baseUrl: string,
|
|
280
|
+
opts: BuildShellUrlOptions = {},
|
|
281
|
+
): Promise<string> {
|
|
282
|
+
const resolved = opts.resolvedBundle ?? (await resolveConnectionInputForCli(target))
|
|
283
|
+
const url = new URL(baseUrl)
|
|
284
|
+
const prefix = getShellRoutePrefix(url.pathname)
|
|
285
|
+
url.pathname = `${prefix}/rn`
|
|
286
|
+
url.searchParams.delete('open')
|
|
287
|
+
url.searchParams.delete('port')
|
|
288
|
+
url.searchParams.delete('app')
|
|
289
|
+
const bundleUrl =
|
|
290
|
+
opts.hot === undefined
|
|
291
|
+
? resolved.bundleUrl
|
|
292
|
+
: applyHotMode(resolved.bundleUrl, opts.hot)
|
|
293
|
+
url.searchParams.set('bundle', bundleUrl)
|
|
294
|
+
return url.toString()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export async function resolveAppProjectForBundleUrl(
|
|
298
|
+
bundleUrl?: string,
|
|
299
|
+
projectRoot?: string,
|
|
300
|
+
manifestProjectRoot?: string | null,
|
|
301
|
+
signal?: AbortSignal,
|
|
302
|
+
): Promise<ResolvedAppProject | null> {
|
|
303
|
+
if (projectRoot !== undefined) {
|
|
304
|
+
const project = resolveAppProject(projectRoot)
|
|
305
|
+
if (!project) throw new Error(`app project could not be found at ${projectRoot}`)
|
|
306
|
+
return project
|
|
307
|
+
}
|
|
308
|
+
if (!bundleUrl) return null
|
|
309
|
+
const advertisedRoot = await resolveMetroProjectRoot(bundleUrl, manifestProjectRoot, {
|
|
310
|
+
waitMs: null,
|
|
311
|
+
signal,
|
|
312
|
+
})
|
|
313
|
+
return advertisedRoot ? resolveAppProject(advertisedRoot) : null
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function resolveDefaultShellBaseUrl(): string {
|
|
317
|
+
return resolveBridgeWorld().shellBaseUrl
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** the shell that belongs to a bridge port: the world a fresh lockfile claims
|
|
321
|
+
* for it, otherwise the shell that shares the port's own offset. every caller
|
|
322
|
+
* that has already settled on a bridge port goes through this, so a page can
|
|
323
|
+
* never open in one stack's shell while the CLI polls another's bridge. the
|
|
324
|
+
* development bridge registry keeps every live port addressable, while this
|
|
325
|
+
* function preserves an explicit caller's already-selected world. */
|
|
326
|
+
export function resolveShellBaseUrlForBridgePort(bridgePort: number): string {
|
|
327
|
+
return (
|
|
328
|
+
worldForBridgePort(bridgePort)?.shellBaseUrl ??
|
|
329
|
+
resolveSootsimShellBaseUrlForBridgePort(bridgePort) ??
|
|
330
|
+
resolveDefaultShellBaseUrl()
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// stamp a bounded catalog reference on the engine page url so the
|
|
335
|
+
// engine's app-font-loader registers native config-only fonts at boot. fonts
|
|
336
|
+
// loaded by JS already flow through normal runtime fetch capture; this covers
|
|
337
|
+
// UIAppFonts-style assets that Metro can serve but the guest bundle never
|
|
338
|
+
// fetches itself. auto-discovery only — scans the repo for expo-font config
|
|
339
|
+
// plugin declarations, no user-facing flag. discovery keeps only font files
|
|
340
|
+
// that exist on disk, so the stamp never waits on the dev server.
|
|
341
|
+
function stampAppFonts(
|
|
342
|
+
urlStr: string,
|
|
343
|
+
platform: 'ios' | 'android',
|
|
344
|
+
nativeAssetOrigin: string,
|
|
345
|
+
project?: ResolvedAppProject | null,
|
|
346
|
+
): string {
|
|
347
|
+
try {
|
|
348
|
+
const url = new URL(urlStr)
|
|
349
|
+
if (!url.searchParams.get('bundle') || !project) return urlStr
|
|
350
|
+
const specs = discoverNativeLinkedAppFonts({
|
|
351
|
+
projectDir: project.appDir,
|
|
352
|
+
platform,
|
|
353
|
+
nativeAssetOrigin,
|
|
354
|
+
})
|
|
355
|
+
if (specs.length === 0) return urlStr
|
|
356
|
+
const catalogUrl = stageHostBytes(
|
|
357
|
+
new TextEncoder().encode(
|
|
358
|
+
getCliRuntime().engine_config_plugin_fonts.encodeAppFontsWire(specs),
|
|
359
|
+
),
|
|
360
|
+
nativeAssetOrigin,
|
|
361
|
+
)
|
|
362
|
+
url.searchParams.set('appFonts', `@${catalogUrl}`)
|
|
363
|
+
return url.toString()
|
|
364
|
+
} catch {
|
|
365
|
+
return urlStr
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async function resolveShellUrl(
|
|
370
|
+
target: string,
|
|
371
|
+
baseUrl: string,
|
|
372
|
+
opts: BuildShellUrlOptions = {},
|
|
373
|
+
): Promise<string> {
|
|
374
|
+
// no target = open home screen
|
|
375
|
+
if (!target) {
|
|
376
|
+
return new URL(baseUrl).toString()
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (looksLikeSootsimUrl(target)) {
|
|
380
|
+
const url = new URL(target)
|
|
381
|
+
const base = new URL(baseUrl)
|
|
382
|
+
const baseConfig = base.searchParams.get(PEACH_CONFIG_QUERY_PARAM)
|
|
383
|
+
if (baseConfig && !url.searchParams.has(PEACH_CONFIG_QUERY_PARAM)) {
|
|
384
|
+
url.searchParams.set(PEACH_CONFIG_QUERY_PARAM, baseConfig)
|
|
385
|
+
}
|
|
386
|
+
return url.toString()
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (looksLikeShellPathTarget(target)) {
|
|
390
|
+
return buildShellPathOpenUrl(target, baseUrl)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// check if this is a shell app (pathname-based route, not bundle)
|
|
394
|
+
const shellPath = SHELL_APPS[target.toLowerCase()]
|
|
395
|
+
if (shellPath) {
|
|
396
|
+
const url = new URL(baseUrl)
|
|
397
|
+
const prefix = getShellRoutePrefix(url.pathname)
|
|
398
|
+
url.pathname = `${prefix}${shellPath}`
|
|
399
|
+
return url.toString()
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (shouldResolveBundleTargetInCli(target)) {
|
|
403
|
+
return buildResolvedBundleOpenUrl(target, baseUrl, opts)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return buildConnectOpenUrl(target, baseUrl)
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// stamp the engine page url with `?appSplash=<encodeURIComponent(JSON)>` so the
|
|
410
|
+
// engine paints the app's REAL configured splash image + background on boot
|
|
411
|
+
// (instead of the contrast device-default chrome). same discovery path as
|
|
412
|
+
// fonts: scan the bundle's project for the expo-splash-screen /
|
|
413
|
+
// react-native-bootsplash config plugin (or legacy `expo.splash`). the metro
|
|
414
|
+
// manifest fallback in the engine covers the typed-URL case; this wire is the
|
|
415
|
+
// instant-first-paint optimization.
|
|
416
|
+
async function stampAppSplash(
|
|
417
|
+
urlStr: string,
|
|
418
|
+
project?: ResolvedAppProject | null,
|
|
419
|
+
oneAppSplash?: Promise<DiscoveredAppSplashSpec | null>,
|
|
420
|
+
): Promise<string> {
|
|
421
|
+
try {
|
|
422
|
+
const url = new URL(urlStr)
|
|
423
|
+
const bundleUrl = url.searchParams.get('bundle') || ''
|
|
424
|
+
if (!bundleUrl || !project) return urlStr
|
|
425
|
+
const spec = findExpoAppConfig(project.appDir)
|
|
426
|
+
? discoverConfigPluginAppSplash({
|
|
427
|
+
bundleUrl,
|
|
428
|
+
projectDir: project.appDir,
|
|
429
|
+
})
|
|
430
|
+
: await (oneAppSplash ?? discoverOneNativeAppSplash(bundleUrl))
|
|
431
|
+
if (!spec) return urlStr
|
|
432
|
+
// native splash assets are required for the first frame.
|
|
433
|
+
for (const imageUrl of splashImageUrls(spec)) {
|
|
434
|
+
if (!splashImageOnDisk(imageUrl, project.appDir)) return urlStr
|
|
435
|
+
}
|
|
436
|
+
url.searchParams.set('appSplash', encodeAppSplashWire(spec))
|
|
437
|
+
return url.toString()
|
|
438
|
+
} catch {
|
|
439
|
+
return urlStr
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// stamp the engine page url with `?appCatalog=` so an app's asset-catalog
|
|
444
|
+
// colors and images and its declared accent reach the tenant, which applies
|
|
445
|
+
// them to the bundle this url opens. the catalog lives in the native binary,
|
|
446
|
+
// never in the js bundle, so only the app's ios project on disk has it.
|
|
447
|
+
function stampAppCatalog(urlStr: string, project?: ResolvedAppProject | null): string {
|
|
448
|
+
try {
|
|
449
|
+
const url = new URL(urlStr)
|
|
450
|
+
const metroOrigin = loopbackOriginOf(url.searchParams.get('bundle') ?? '')
|
|
451
|
+
if (!metroOrigin || !project) return urlStr
|
|
452
|
+
const catalog = discoverAppCatalog(project.appDir, metroOrigin)
|
|
453
|
+
if (!catalog) return urlStr
|
|
454
|
+
url.searchParams.set(
|
|
455
|
+
'appCatalog',
|
|
456
|
+
getCliRuntime().engine_app_catalog_wire.encodeAppCatalogWire(catalog),
|
|
457
|
+
)
|
|
458
|
+
return url.toString()
|
|
459
|
+
} catch {
|
|
460
|
+
return urlStr
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// a splash spec names `<origin>/assets/<project-relative-path>`, the file the
|
|
465
|
+
// dev server serves from its project root, so the file is checked on disk and
|
|
466
|
+
// the stamp never waits on a dev server busy building.
|
|
467
|
+
function splashImageOnDisk(imageUrl: string, appDir: string): boolean {
|
|
468
|
+
const { pathname } = new URL(imageUrl)
|
|
469
|
+
if (!pathname.startsWith('/assets/')) return false
|
|
470
|
+
try {
|
|
471
|
+
return fs
|
|
472
|
+
.statSync(path.join(appDir, decodeURIComponent(pathname.slice('/assets/'.length))))
|
|
473
|
+
.isFile()
|
|
474
|
+
} catch {
|
|
475
|
+
return false
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export interface BuildShellUrlOptions {
|
|
480
|
+
// manifest and asset origin provided by an authenticated recorder proxy.
|
|
481
|
+
bundleOriginOverride?: string
|
|
482
|
+
// marks native host windows so the bridge can reuse a CLI-opened desktop sim.
|
|
483
|
+
hostDriver?: 'desktop'
|
|
484
|
+
// when set, forces the metro `hot` query on the resolved bundle URL. true
|
|
485
|
+
// for interactive opens (HMR runtime in bundle, edits hot-apply), false
|
|
486
|
+
// for `--driver playwright`/agent runs (no in-bundle HMR wiring, no ws
|
|
487
|
+
// chatter, deterministic e2e). undefined leaves whatever value metro's
|
|
488
|
+
// manifest emitted — matches real iOS sims so metro's bundle cache is
|
|
489
|
+
// shared. set by `runOpenCommand` only.
|
|
490
|
+
hot?: boolean
|
|
491
|
+
// device model slug (e.g. iphone-16) stamped onto the engine URL as
|
|
492
|
+
// ?device=<model> — the shell reads it at boot (main.tsx) and live-switch
|
|
493
|
+
// uses the same param. without this, every driver-opened sim silently ran
|
|
494
|
+
// whatever profile the shell last persisted.
|
|
495
|
+
device?: string
|
|
496
|
+
// fold posture (open|closed) stamped onto the engine URL as ?posture= next
|
|
497
|
+
// to ?device=. the shell reads it at boot (readUrlSettingOverrides) and
|
|
498
|
+
// keeps it in the URL on every pose change, so it round-trips the way
|
|
499
|
+
// device and orientation do. without this a manual ?posture= appended
|
|
500
|
+
// after the app path lands inside the bundle param and never reaches the
|
|
501
|
+
// shell. non-foldable devices resolve it to closed at boot.
|
|
502
|
+
posture?: string
|
|
503
|
+
// raster quality (high|medium|low) stamped as ?renderResolution=. high
|
|
504
|
+
// renders at the device's native scale, so a native-parity capture is not
|
|
505
|
+
// left at the interactive medium default of 2.
|
|
506
|
+
renderResolution?: string
|
|
507
|
+
// interface orientation (portrait|landscape) stamped as ?orientation=,
|
|
508
|
+
// which the shell reads at boot over the device's default: an open duo
|
|
509
|
+
// boots landscape unless this asks for it upright.
|
|
510
|
+
orientation?: string
|
|
511
|
+
// portrayed os version (major.minor) stamped as ?osVersion=, which the
|
|
512
|
+
// shell pins at boot over the device profile's own version. an oracle on a
|
|
513
|
+
// newer os than the profile compares only when the sim runs that os era.
|
|
514
|
+
osVersion?: string
|
|
515
|
+
// appearance scheme (light|dark|auto) stamped as ?theme=, which the shell
|
|
516
|
+
// reads at boot over the persisted scheme. set by `peach open -t/--theme`.
|
|
517
|
+
theme?: string
|
|
518
|
+
// the xcode application target whose version, bundle id and display name
|
|
519
|
+
// the app reads, for a project with several. set by `peach open --ios-target`.
|
|
520
|
+
iosTarget?: string
|
|
521
|
+
resolvedBundle?: ResolvedDevBundle
|
|
522
|
+
project?: ResolvedAppProject | null
|
|
523
|
+
// offline bundles already carry compiled native modules and a known project.
|
|
524
|
+
offline?: boolean
|
|
525
|
+
// a One app's splash, read from its dev server's manifest. `peach open`
|
|
526
|
+
// starts the read beside its early bundle request so the answer overlaps
|
|
527
|
+
// bridge and host setup instead of preceding the launch.
|
|
528
|
+
oneAppSplash?: Promise<DiscoveredAppSplashSpec | null>
|
|
529
|
+
// deterministic-capture mode, stamped onto the engine URL as ?proof=1. the
|
|
530
|
+
// shell worker, compositor worker and tenant worker each read it off the
|
|
531
|
+
// host page URL at boot (syncProofModeFromInitUrl) and pin everything that
|
|
532
|
+
// would otherwise differ frame to frame: the TextInput caret stops blinking
|
|
533
|
+
// and stays visible, and notifications stop auto-dismissing. capture-frame
|
|
534
|
+
// also reads the raw param and stops clipping the device corners, and the
|
|
535
|
+
// shell leaves out the Dynamic Island, which is hardware, so a
|
|
536
|
+
// capture matches simctl's rectangular framebuffer. without it a
|
|
537
|
+
// screen holding a focused text field never reaches three identical idle
|
|
538
|
+
// frames, so the screenshot guard burns all 12 attempts and then fails.
|
|
539
|
+
proof?: boolean
|
|
540
|
+
// a temporary storage profile, stamped as ?ephemeral=1. the shell then
|
|
541
|
+
// neither reads nor writes the machine-wide settings in
|
|
542
|
+
// ~/.peach/config.json, so a preference another sim saved (bold text,
|
|
543
|
+
// reduce motion, appearance) cannot steer this boot.
|
|
544
|
+
ephemeral?: boolean
|
|
545
|
+
// launch-time environment variables, stamped as repeated ?env=KEY%3DVALUE.
|
|
546
|
+
// see the --env flag above.
|
|
547
|
+
env?: string[]
|
|
548
|
+
// the project's env file as react-native-config's iOS build compiles it,
|
|
549
|
+
// stamped as ?dotEnv=<json>. set by `peach open --load-env` only.
|
|
550
|
+
dotEnv?: Record<string, string>
|
|
551
|
+
// the bridge an explicit --port names; the expo swift compile endpoint
|
|
552
|
+
// stamped onto the URL uses it instead of the discovered world's bridge.
|
|
553
|
+
bridgePort?: number
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
type ProjectExpoConfigRead = { config: Record<string, unknown> } | { error: string }
|
|
557
|
+
|
|
558
|
+
function errorMessage(error: unknown): string {
|
|
559
|
+
return error instanceof Error ? error.message : String(error)
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function readProjectExpoConfig(
|
|
563
|
+
project: ResolvedAppProject,
|
|
564
|
+
): Promise<ProjectExpoConfigRead | null> {
|
|
565
|
+
try {
|
|
566
|
+
resolveExpoConfigModule(project.appDir)
|
|
567
|
+
} catch {
|
|
568
|
+
return Promise.resolve(null)
|
|
569
|
+
}
|
|
570
|
+
return readExpoConfigAsync(project.appDir).then(
|
|
571
|
+
(config) => ({ config }),
|
|
572
|
+
(error: unknown) => ({ error: errorMessage(error) }),
|
|
573
|
+
)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// evaluating the Expo config spawns node, so `peach open` starts the read as
|
|
577
|
+
// soon as the project resolves and the shell url it builds takes that read. a
|
|
578
|
+
// later build reads the config again.
|
|
579
|
+
const startedExpoConfigReads = new Map<string, Promise<ProjectExpoConfigRead | null>>()
|
|
580
|
+
|
|
581
|
+
export function startExpoConfigRead(project: ResolvedAppProject | null) {
|
|
582
|
+
if (project) startedExpoConfigReads.set(project.appDir, readProjectExpoConfig(project))
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function takeExpoConfigRead(project: ResolvedAppProject | null | undefined) {
|
|
586
|
+
if (!project) return Promise.resolve(null)
|
|
587
|
+
const started = startedExpoConfigReads.get(project.appDir)
|
|
588
|
+
startedExpoConfigReads.delete(project.appDir)
|
|
589
|
+
return started ?? readProjectExpoConfig(project)
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function nativeFirebaseFromExpoConfig(
|
|
593
|
+
project: ResolvedAppProject,
|
|
594
|
+
read: ProjectExpoConfigRead,
|
|
595
|
+
iosTarget: string | undefined,
|
|
596
|
+
): Record<string, unknown> {
|
|
597
|
+
if ('error' in read) return { expoConfigError: read.error }
|
|
598
|
+
try {
|
|
599
|
+
return readNativeFirebaseConfig(
|
|
600
|
+
project.appDir,
|
|
601
|
+
undefined,
|
|
602
|
+
iosTarget,
|
|
603
|
+
read.config,
|
|
604
|
+
true,
|
|
605
|
+
)
|
|
606
|
+
} catch (error) {
|
|
607
|
+
return { error: errorMessage(error) }
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// a built bundle staged on the bridge has no packager to serve its manifest.
|
|
612
|
+
// the built binary embeds its evaluated app config (expo's `app.config`
|
|
613
|
+
// resource, and the Info.plist prebuild writes from it), so the bundle's
|
|
614
|
+
// manifest is that config, staged beside it
|
|
615
|
+
function stageBuiltBundleManifest(
|
|
616
|
+
bundleUrl: string,
|
|
617
|
+
config: Record<string, unknown>,
|
|
618
|
+
): string | null {
|
|
619
|
+
const bundle = new URL(bundleUrl)
|
|
620
|
+
if (!isStagedHostFileRequest(bundle.pathname) || Object.keys(config).length === 0)
|
|
621
|
+
return null
|
|
622
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'peach-app-manifest-'))
|
|
623
|
+
try {
|
|
624
|
+
const file = path.join(directory, 'manifest.json')
|
|
625
|
+
fs.writeFileSync(file, JSON.stringify({ extra: { expoClient: config } }))
|
|
626
|
+
return stageHostFile(file, bundle.origin)
|
|
627
|
+
} finally {
|
|
628
|
+
fs.rmSync(directory, { recursive: true, force: true })
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// a plain Metro carries no identity footer or header, so the page carries the
|
|
633
|
+
// identity the Peach Metro plugin reads from the same project. its icon
|
|
634
|
+
// artwork stays with bundle builders, where data uris cannot swell a url. a
|
|
635
|
+
// project with several app targets needs a named target, as xcode needs a
|
|
636
|
+
// scheme: `--ios-target` here, the plugin's iosTarget for a Peach Metro.
|
|
637
|
+
function readProjectNativeAppIdentityWire(
|
|
638
|
+
project: ResolvedAppProject,
|
|
639
|
+
platform: 'ios' | 'android',
|
|
640
|
+
iosTarget: string | undefined,
|
|
641
|
+
environment: Record<string, string> | undefined,
|
|
642
|
+
): string | null {
|
|
643
|
+
if (!canExtractNativeAppIdentity(platform)) return null
|
|
644
|
+
try {
|
|
645
|
+
const identity = readNativeAppIdentityFromProject(
|
|
646
|
+
project.appDir,
|
|
647
|
+
platform,
|
|
648
|
+
undefined,
|
|
649
|
+
iosTarget,
|
|
650
|
+
undefined,
|
|
651
|
+
environment,
|
|
652
|
+
)
|
|
653
|
+
return (
|
|
654
|
+
identity &&
|
|
655
|
+
createNativeAppIdentityHeader({ ...identity, appIconArtwork: undefined })
|
|
656
|
+
)
|
|
657
|
+
} catch (error) {
|
|
658
|
+
if (error instanceof NativeAppTargetSelectionError) return null
|
|
659
|
+
throw error
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function bundleUrlOf(urlStr: string): string | undefined {
|
|
664
|
+
try {
|
|
665
|
+
return new URL(urlStr).searchParams.get('bundle') || undefined
|
|
666
|
+
} catch {
|
|
667
|
+
return undefined
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export async function buildShellUrl(
|
|
672
|
+
target: string,
|
|
673
|
+
baseUrl: string = resolveDefaultShellBaseUrl(),
|
|
674
|
+
opts: BuildShellUrlOptions = {},
|
|
675
|
+
): Promise<string> {
|
|
676
|
+
const resolved = await resolveShellUrl(target, baseUrl, opts)
|
|
677
|
+
// callers that hand us a bare port or url (the flow/maestro runner, the
|
|
678
|
+
// electron companion) have no project to pass. derive it from the bundle
|
|
679
|
+
// metro advertises so those paths get the same UIAppFonts and splash
|
|
680
|
+
// stamping an `peach open` gets. without it a flow renders the app's text in a
|
|
681
|
+
// fallback typeface, which then reads as a conformance diff.
|
|
682
|
+
const project = opts.offline
|
|
683
|
+
? opts.project
|
|
684
|
+
: (opts.project ?? (await resolveAppProjectForBundleUrl(bundleUrlOf(resolved))))
|
|
685
|
+
const expoRoot = project?.appDir ?? null
|
|
686
|
+
const world = resolveBridgeWorld()
|
|
687
|
+
const port = resolveBridgePortForPin({
|
|
688
|
+
baseUrl,
|
|
689
|
+
wsPort: opts.bridgePort ?? world.bridgePort,
|
|
690
|
+
explicitPort: opts.bridgePort !== undefined,
|
|
691
|
+
})
|
|
692
|
+
if (project && port.error) throw new Error(port.error)
|
|
693
|
+
const nativeAssetOrigin = `http://127.0.0.1:${port.port}`
|
|
694
|
+
const device = opts.device ?? new URL(resolved).searchParams.get('device')
|
|
695
|
+
const bundle = bundleUrlOf(resolved)
|
|
696
|
+
const platform =
|
|
697
|
+
device && isDeviceModel(device)
|
|
698
|
+
? getCliRuntime().settings_devices.getRuntimePlatform(device)
|
|
699
|
+
: bundle && new URL(bundle).searchParams.get('platform') === 'android'
|
|
700
|
+
? 'android'
|
|
701
|
+
: 'ios'
|
|
702
|
+
const stamped = stampAppCatalog(
|
|
703
|
+
await stampAppSplash(
|
|
704
|
+
stampAppFonts(resolved, platform, nativeAssetOrigin, project),
|
|
705
|
+
project,
|
|
706
|
+
opts.oneAppSplash,
|
|
707
|
+
),
|
|
708
|
+
project,
|
|
709
|
+
)
|
|
710
|
+
const expoStamped = new URL(stamped)
|
|
711
|
+
expoStamped.searchParams.delete('nativeAppIdentity')
|
|
712
|
+
expoStamped.searchParams.delete(ANDROID_ROOT_MODULE_QUERY_PARAM)
|
|
713
|
+
expoStamped.searchParams.delete('appBundleResources')
|
|
714
|
+
if (project) {
|
|
715
|
+
const nativeRenderer = readNativeProjectRenderer(project.appDir, platform)
|
|
716
|
+
if (nativeRenderer !== undefined) {
|
|
717
|
+
const config = readPeachConfigFromSearchParams(expoStamped.searchParams)
|
|
718
|
+
if (
|
|
719
|
+
config?.nativeRenderer !== undefined &&
|
|
720
|
+
config.nativeRenderer !== nativeRenderer
|
|
721
|
+
)
|
|
722
|
+
throw new Error('peach config contradicts native project renderer')
|
|
723
|
+
expoStamped.searchParams.set(
|
|
724
|
+
PEACH_CONFIG_QUERY_PARAM,
|
|
725
|
+
JSON.stringify(mergePeachConfig(config, { nativeRenderer })),
|
|
726
|
+
)
|
|
727
|
+
}
|
|
728
|
+
const nativeAppIdentity = bundle
|
|
729
|
+
? readProjectNativeAppIdentityWire(project, platform, opts.iosTarget, opts.dotEnv)
|
|
730
|
+
: null
|
|
731
|
+
if (nativeAppIdentity)
|
|
732
|
+
expoStamped.searchParams.set('nativeAppIdentity', nativeAppIdentity)
|
|
733
|
+
const androidRoot =
|
|
734
|
+
bundle && platform === 'android'
|
|
735
|
+
? readAndroidLauncherRootModuleName(project.appDir)
|
|
736
|
+
: undefined
|
|
737
|
+
if (androidRoot !== undefined)
|
|
738
|
+
expoStamped.searchParams.set(ANDROID_ROOT_MODULE_QUERY_PARAM, androidRoot)
|
|
739
|
+
if (platform === 'ios' && nativeAppIdentity) {
|
|
740
|
+
const resources = stageAppBundleResources(
|
|
741
|
+
project.appDir,
|
|
742
|
+
nativeAssetOrigin,
|
|
743
|
+
opts.iosTarget,
|
|
744
|
+
opts.dotEnv,
|
|
745
|
+
)
|
|
746
|
+
if (Object.keys(resources).length > 0)
|
|
747
|
+
expoStamped.searchParams.set('appBundleResources', JSON.stringify(resources))
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
// a plain Metro has no native Firebase config endpoint, so the CLI reads it
|
|
751
|
+
// from the project whose Expo config it can evaluate. a project without its
|
|
752
|
+
// own `@expo/config` (a dependency-free recorder) leaves it to the Peach
|
|
753
|
+
// Metro plugin's endpoint.
|
|
754
|
+
expoStamped.searchParams.delete('nativeFirebase')
|
|
755
|
+
expoStamped.searchParams.delete('appManifest')
|
|
756
|
+
expoStamped.searchParams.delete('packageVersions')
|
|
757
|
+
if (project && expoStamped.searchParams.get('bundle')) {
|
|
758
|
+
expoStamped.searchParams.set(
|
|
759
|
+
'packageVersions',
|
|
760
|
+
JSON.stringify(readInstalledNativePackageVersions(project.appDir)),
|
|
761
|
+
)
|
|
762
|
+
}
|
|
763
|
+
const expoConfigRead = await takeExpoConfigRead(project)
|
|
764
|
+
const stampedBundle = expoStamped.searchParams.get('bundle')
|
|
765
|
+
if (project && !expoConfigRead && stampedBundle) {
|
|
766
|
+
// no Expo config tooling, but the native project still configures Firebase
|
|
767
|
+
const nativeFirebase = nativeFirebaseFromExpoConfig(
|
|
768
|
+
project,
|
|
769
|
+
{ config: {} },
|
|
770
|
+
opts.iosTarget,
|
|
771
|
+
)
|
|
772
|
+
if (Object.keys(nativeFirebase).length > 0)
|
|
773
|
+
expoStamped.searchParams.set('nativeFirebase', JSON.stringify(nativeFirebase))
|
|
774
|
+
}
|
|
775
|
+
if (project && expoConfigRead && stampedBundle) {
|
|
776
|
+
expoStamped.searchParams.set(
|
|
777
|
+
'nativeFirebase',
|
|
778
|
+
JSON.stringify(
|
|
779
|
+
nativeFirebaseFromExpoConfig(project, expoConfigRead, opts.iosTarget),
|
|
780
|
+
),
|
|
781
|
+
)
|
|
782
|
+
const manifest =
|
|
783
|
+
'config' in expoConfigRead
|
|
784
|
+
? stageBuiltBundleManifest(stampedBundle, expoConfigRead.config)
|
|
785
|
+
: null
|
|
786
|
+
if (manifest) expoStamped.searchParams.set('appManifest', manifest)
|
|
787
|
+
}
|
|
788
|
+
if (opts.bundleOriginOverride)
|
|
789
|
+
expoStamped.searchParams.set('bundleOriginOverride', opts.bundleOriginOverride)
|
|
790
|
+
if (opts.hostDriver) expoStamped.searchParams.set('peachHostDriver', opts.hostDriver)
|
|
791
|
+
if (expoRoot && !opts.offline) {
|
|
792
|
+
expoStamped.searchParams.set(
|
|
793
|
+
'expoSwift',
|
|
794
|
+
`${nativeAssetOrigin}/__peach/expo-swift?root=${encodeURIComponent(expoRoot)}`,
|
|
795
|
+
)
|
|
796
|
+
expoStamped.searchParams.set(
|
|
797
|
+
'nitro',
|
|
798
|
+
`${nativeAssetOrigin}/__peach/nitro?root=${encodeURIComponent(expoRoot)}`,
|
|
799
|
+
)
|
|
800
|
+
expoStamped.searchParams.set(
|
|
801
|
+
'turbo',
|
|
802
|
+
`${nativeAssetOrigin}/__peach/turbo?root=${encodeURIComponent(expoRoot)}`,
|
|
803
|
+
)
|
|
804
|
+
// the engine fetches only its device platform's build
|
|
805
|
+
expoStamped.searchParams.set(
|
|
806
|
+
'expoKotlin',
|
|
807
|
+
`${nativeAssetOrigin}/__peach/expo-kotlin?root=${encodeURIComponent(expoRoot)}`,
|
|
808
|
+
)
|
|
809
|
+
}
|
|
810
|
+
if (
|
|
811
|
+
!opts.device &&
|
|
812
|
+
!opts.proof &&
|
|
813
|
+
!opts.ephemeral &&
|
|
814
|
+
!opts.posture &&
|
|
815
|
+
!opts.renderResolution &&
|
|
816
|
+
!opts.orientation &&
|
|
817
|
+
!opts.osVersion &&
|
|
818
|
+
!opts.theme &&
|
|
819
|
+
!opts.env?.length &&
|
|
820
|
+
!opts.dotEnv
|
|
821
|
+
)
|
|
822
|
+
return opts.offline
|
|
823
|
+
? expoStamped.toString()
|
|
824
|
+
: stageHostLaunchMetadata(expoStamped, nativeAssetOrigin)
|
|
825
|
+
const url = expoStamped
|
|
826
|
+
if (opts.dotEnv) url.searchParams.set('dotEnv', JSON.stringify(opts.dotEnv))
|
|
827
|
+
if (opts.device) url.searchParams.set('device', opts.device)
|
|
828
|
+
if (opts.posture) url.searchParams.set('posture', opts.posture)
|
|
829
|
+
if (opts.renderResolution)
|
|
830
|
+
url.searchParams.set('renderResolution', opts.renderResolution)
|
|
831
|
+
if (opts.orientation) url.searchParams.set('orientation', opts.orientation)
|
|
832
|
+
if (opts.osVersion) url.searchParams.set('osVersion', opts.osVersion)
|
|
833
|
+
if (opts.theme) url.searchParams.set('theme', opts.theme)
|
|
834
|
+
if (opts.proof) url.searchParams.set('proof', '1')
|
|
835
|
+
if (opts.ephemeral) url.searchParams.set('ephemeral', '1')
|
|
836
|
+
for (const entry of opts.env ?? []) url.searchParams.append('env', entry)
|
|
837
|
+
return opts.offline ? url.toString() : stageHostLaunchMetadata(url, nativeAssetOrigin)
|
|
838
|
+
}
|