peachsim 0.1.1716 → 0.1.1728
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 +82 -822
- 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 +750 -0
- package/cli/commands/serve.ts +6 -0
- package/cli/commands/shell-url.ts +834 -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 +13 -6
- package/detox/index.ts +187 -23
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- 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 +38000 -31658
- 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 +184 -60
- package/dist-lib/dev-bundle-resolution.cjs +14 -13
- package/dist-lib/expo-swift-bundle.cjs +18199 -11834
- package/dist-lib/expo-swift-metadata.cjs +4 -1
- package/dist-lib/expo-swift-metadata.mjs +3 -1
- package/dist-lib/home-paths.cjs +21 -2
- package/dist-lib/host/bridge-host.cjs +26509 -23850
- package/dist-lib/host/fetch-proxy-handler.cjs +221 -222
- 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 +876 -389
- 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 +127 -16
- package/dist-lib/menu.cjs +7 -1
- package/dist-lib/menu.mjs +7 -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 +883 -404
- package/dist-lib/native-app-identity-project.cjs +694 -280
- package/dist-lib/native-app-identity-project.mjs +490 -83
- 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 +1 -1
- 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 +392 -224
- package/dist-lib/react-native-host-modules.cjs +32 -2
- package/dist-lib/react-native-host-modules.mjs +32 -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 +61838 -47851
- package/dist-lib/swift-compile.cjs +583 -360
- package/dist-lib/swift-compile.mjs +496 -275
- 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 +4453 -2231
- package/dist-lib/vite.cjs +230 -228
- 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/image-loader.d.ts +7 -5
- package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -11
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -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/shell-protocol.d.ts +4 -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 +23 -1
- 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/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/scripts/dev-server-scanner.ts +12 -25
- 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 +2 -0
- 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.h +75 -9
- 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.modulemap +5 -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/fcntl.h +4 -2
- 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/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 +1 -0
- package/skills/contrast/SKILL.md +2 -1
- package/skills/peach-test/SKILL.md +7 -3
- package/src/admitted-mac-build.ts +3 -0
- package/src/android-app-identity.ts +18 -0
- package/src/android-root-module.ts +9 -9
- package/src/appPackageContract.ts +81 -0
- package/src/bridge-contract.ts +50 -0
- package/src/bundle-channel.mjs +21 -4
- package/src/dev-bundle-resolution.ts +7 -27
- package/src/dom-source-reference.ts +15 -0
- package/src/expo-discovery-cache.ts +127 -23
- package/src/expo-manifest-body.ts +33 -0
- package/src/expo-native-workspace.ts +38 -13
- package/src/expo-swift-host.ts +264 -62
- package/src/expoSwiftContract.ts +3 -0
- package/src/generated/swift-c-predefines.json +1 -1
- package/src/home-paths.ts +35 -1
- package/src/host/app-package-handler.ts +47 -0
- package/src/host/bridge-host.ts +3 -0
- package/src/host/staged-host-files.ts +18 -0
- package/src/index.ts +3 -0
- package/src/kotlin-host.ts +21 -18
- package/src/kotlin-instance-source.ts +126 -0
- package/src/menu.ts +7 -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/nitro-adapter.lock.json +268 -268
- package/src/nitro-bundle.ts +8 -0
- package/src/nitro-compile.ts +35 -9
- package/src/nitro-dependencies.ts +21 -19
- package/src/nitro-source.ts +4 -0
- package/src/nitroContract.ts +7 -0
- package/src/react-native-bridge-modules.ts +68 -42
- package/src/react-native-host-modules.ts +31 -1
- package/src/reactNativeConfigurationContract.ts +14 -0
- package/src/reap-browser.ts +15 -3
- package/src/sdk.ts +5 -0
- package/src/settingsContract.ts +27 -1
- package/src/sim-client.ts +4 -1
- package/src/storageSnapshotContract.ts +3 -0
- package/src/swift-compile.ts +221 -41
- package/src/swift-coverage/provenance.ts +1 -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 +1 -1
- package/src/swift-cxx-reachable.ts +2 -1
- package/src/swift-distribution.lock.json +14 -13
- package/src/swift-host.ts +95 -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 +592 -57
- package/src/swift-standins.ts +430 -49
- package/src/swift-submit.ts +3 -1
- package/src/swift-toolchain.ts +140 -17
- package/src/turbo-codegen-intake.ts +91 -0
- package/src/vite-plugin-one.ts +13 -9
- package/src/vite-plugin.ts +28 -15
- package/src/xcode-project.ts +223 -22
package/cli/commands/swift.ts
CHANGED
|
@@ -3,14 +3,6 @@ import http from 'node:http'
|
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { WebSocket, WebSocketServer } from 'ws'
|
|
5
5
|
import { resolveContrastBackendOrigin } from '../../src/backend-origin'
|
|
6
|
-
import { produceConfiguredBundle } from '../../src/configured-bundle-producer'
|
|
7
|
-
import { swiftGuestBundle } from '../../src/guest-bundle'
|
|
8
|
-
import { insertNativeAppIdentityFooter } from '../../src/native-app-identity'
|
|
9
|
-
import {
|
|
10
|
-
resolveSwiftModule,
|
|
11
|
-
SWIFT_ENDPOINT_ENV,
|
|
12
|
-
type SwiftModule,
|
|
13
|
-
} from '../../src/swift-distribution'
|
|
14
6
|
import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from '../../src/swift-submit'
|
|
15
7
|
import {
|
|
16
8
|
SWIFT_DISCOVERY_PATH,
|
|
@@ -18,11 +10,9 @@ import {
|
|
|
18
10
|
SWIFT_ICON_PATH,
|
|
19
11
|
type SwiftHostDiscovery,
|
|
20
12
|
} from '../../src/swiftDiscoveryContract'
|
|
21
|
-
import { findXcodeProject, readXcodeScheme } from '../../src/xcode-project'
|
|
22
|
-
import { loadRNXAppConfig } from '../app-config'
|
|
23
|
-
import { resolveAppProject } from '../app-project'
|
|
24
13
|
import { authHeaderValue, resolveCliAuth } from '../auth'
|
|
25
14
|
import { validateDeviceOption } from '../device-option'
|
|
15
|
+
import { prepareSwiftInput, resolveNativeInput } from '../native-input'
|
|
26
16
|
import { PeachExit } from '../run-rnx'
|
|
27
17
|
import { runOpenCommand, type OpenCommandResources } from './control'
|
|
28
18
|
import {
|
|
@@ -39,6 +29,7 @@ export async function runSwift(
|
|
|
39
29
|
device?: string
|
|
40
30
|
driver?: string
|
|
41
31
|
headless?: boolean
|
|
32
|
+
openArgs?: string[]
|
|
42
33
|
} = {},
|
|
43
34
|
): Promise<number> {
|
|
44
35
|
const input = [...args]
|
|
@@ -119,68 +110,22 @@ export async function runSwift(
|
|
|
119
110
|
authorization: authHeaderValue(auth),
|
|
120
111
|
}
|
|
121
112
|
: null
|
|
122
|
-
|
|
123
|
-
if (!
|
|
124
|
-
try {
|
|
125
|
-
module = await resolveSwiftModule({ required: true })
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error(` ${error instanceof Error ? error.message : String(error)}`)
|
|
128
|
-
return 1
|
|
129
|
-
}
|
|
130
|
-
if (!module) {
|
|
131
|
-
console.error(
|
|
132
|
-
` peach swift compiles on this machine against Peach's Swift distribution: set ${SWIFT_ENDPOINT_ENV} to the endpoint you were given, or pass --upload-source to compile on Contrast`,
|
|
133
|
-
)
|
|
134
|
-
return 1
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
const host = await import('../../src/swift-host')
|
|
138
|
-
packagePath = fs.realpathSync(packagePath)
|
|
139
|
-
// a SwiftPM package compiles as itself; an xcode project compiles its
|
|
140
|
-
// application target, with the project directory as the package path.
|
|
141
|
-
const swiftPackage =
|
|
142
|
-
fs.statSync(packagePath).isDirectory() &&
|
|
143
|
-
fs.existsSync(path.join(packagePath, 'Package.swift'))
|
|
144
|
-
const xcodeproj = swiftPackage ? null : findXcodeProject(packagePath)
|
|
145
|
-
if (!swiftPackage && !xcodeproj) {
|
|
113
|
+
const nativeInput = resolveNativeInput(packagePath, true)
|
|
114
|
+
if (!nativeInput || nativeInput.kind === 'kotlin')
|
|
146
115
|
throw new Error(
|
|
147
|
-
'peach swift needs a
|
|
116
|
+
'peach swift needs a Swift file, SwiftPM directory, or Xcode project or workspace',
|
|
148
117
|
)
|
|
149
|
-
}
|
|
150
|
-
if ((target || scheme) && !xcodeproj)
|
|
151
|
-
throw new Error(
|
|
152
|
-
`${scheme ? '--scheme' : '--target'} selects an Xcode application target`,
|
|
153
|
-
)
|
|
154
|
-
if (target && scheme) throw new Error('--scheme names its own target; pass one of them')
|
|
155
|
-
// a scheme runs its launch action's target in that action's configuration
|
|
156
|
-
const run = scheme && xcodeproj ? readXcodeScheme(xcodeproj, scheme) : null
|
|
157
|
-
if (xcodeproj) {
|
|
158
|
-
packagePath = host.openXcodeProject(
|
|
159
|
-
xcodeproj,
|
|
160
|
-
run?.target ?? target,
|
|
161
|
-
module?.root,
|
|
162
|
-
run?.configuration,
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
const appProject = resolveAppProject(packagePath)
|
|
166
|
-
host.configureSwiftStandinBehavior(packagePath, await loadRNXAppConfig(appProject))
|
|
167
|
-
// collection preflights every input path before any source bytes are read.
|
|
168
|
-
try {
|
|
169
|
-
host.swiftPackageWatchFiles(packagePath, undefined)
|
|
170
|
-
} catch (error) {
|
|
171
|
-
const { SwiftObjCCompilationError } = await import('../../src/swift-objc-compile')
|
|
172
|
-
if (!(error instanceof SwiftObjCCompilationError)) throw error
|
|
173
|
-
console.error(error.message)
|
|
174
|
-
host.disposeSwiftProject(packagePath)
|
|
175
|
-
return 1
|
|
176
|
-
}
|
|
177
|
-
const packageName = path.basename(packagePath)
|
|
178
|
-
const appInfo = host.swiftProjectAppInfo(packagePath)
|
|
179
|
-
const guestSource = swiftGuestBundle(packageName)
|
|
180
|
-
const withIdentity = (source: string) =>
|
|
181
|
-
appInfo.identity ? insertNativeAppIdentityFooter(source, appInfo.identity) : source
|
|
182
|
-
let guest = withIdentity(guestSource)
|
|
183
118
|
const controller = new AbortController()
|
|
119
|
+
const prepared = await prepareSwiftInput(nativeInput, {
|
|
120
|
+
target,
|
|
121
|
+
scheme,
|
|
122
|
+
hosted: hosted ?? undefined,
|
|
123
|
+
signal: controller.signal,
|
|
124
|
+
})
|
|
125
|
+
const { host, module, appInfo } = prepared
|
|
126
|
+
packagePath = prepared.packagePath
|
|
127
|
+
const packageName = prepared.name
|
|
128
|
+
let guest = ''
|
|
184
129
|
const resources: OpenCommandResources = {}
|
|
185
130
|
let metadata: (SwiftEntryModuleArgs & { hmrPath: string }) | null = null
|
|
186
131
|
let compileError = 'Swift compilation is starting'
|
|
@@ -201,19 +146,9 @@ export async function runSwift(
|
|
|
201
146
|
while (!controller.signal.aborted && completed !== requested) {
|
|
202
147
|
const revision = requested
|
|
203
148
|
try {
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
await produceConfiguredBundle(guestSource, config, new Set()),
|
|
208
|
-
)
|
|
209
|
-
const next = await host.swiftPackageMetadata(
|
|
210
|
-
packagePath,
|
|
211
|
-
packageName,
|
|
212
|
-
module?.root,
|
|
213
|
-
origin,
|
|
214
|
-
hosted ?? undefined,
|
|
215
|
-
controller.signal,
|
|
216
|
-
)
|
|
149
|
+
const nextBuild = await prepared.build(origin)
|
|
150
|
+
guest = nextBuild.guestSource
|
|
151
|
+
const next = nextBuild.metadata
|
|
217
152
|
if (controller.signal.aborted) return
|
|
218
153
|
if (revision === requested) {
|
|
219
154
|
const sameArtifact = metadata?.hash === next.hash
|
|
@@ -330,24 +265,28 @@ export async function runSwift(
|
|
|
330
265
|
code = 1
|
|
331
266
|
stop()
|
|
332
267
|
})
|
|
333
|
-
watcher = fs.watch(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
268
|
+
watcher = fs.watch(
|
|
269
|
+
nativeInput.kind === 'swift-file' ? nativeInput.path : packagePath,
|
|
270
|
+
{ recursive: nativeInput.kind !== 'swift-file' },
|
|
271
|
+
(_event, file) => {
|
|
272
|
+
if (
|
|
273
|
+
file &&
|
|
274
|
+
file
|
|
275
|
+
.split(/[\\/]/)
|
|
276
|
+
.some(
|
|
277
|
+
(segment) =>
|
|
278
|
+
(segment.startsWith('.') &&
|
|
279
|
+
segment !== '.one-native-source.json' &&
|
|
280
|
+
segment !== '.one-native-source.swift.txt') ||
|
|
281
|
+
['node_modules', 'ios', 'android', 'build', 'dist', 'types'].includes(
|
|
282
|
+
segment,
|
|
283
|
+
),
|
|
284
|
+
)
|
|
285
|
+
)
|
|
286
|
+
return
|
|
287
|
+
void refresh()
|
|
288
|
+
},
|
|
289
|
+
)
|
|
351
290
|
watcher.on('error', (error) => {
|
|
352
291
|
console.error(error.message)
|
|
353
292
|
code = 1
|
|
@@ -363,6 +302,7 @@ export async function runSwift(
|
|
|
363
302
|
controller.signal.throwIfAborted()
|
|
364
303
|
// refresh already printed the error
|
|
365
304
|
if (!metadata || compileError) return 1
|
|
305
|
+
if (opts.openArgs) openArgs.push(...opts.openArgs)
|
|
366
306
|
if (opts.device) openArgs.push('--device', opts.device)
|
|
367
307
|
if (opts.driver) openArgs.push('--driver', opts.driver)
|
|
368
308
|
if (opts.headless) openArgs.push('--headless')
|
|
@@ -395,7 +335,7 @@ export async function runSwift(
|
|
|
395
335
|
server.closeAllConnections()
|
|
396
336
|
await new Promise<void>((resolve) => server.close(() => resolve()))
|
|
397
337
|
if (!(await closeGuestResources(resources, 'Swift preview'))) code = 1
|
|
398
|
-
|
|
338
|
+
prepared.dispose()
|
|
399
339
|
}
|
|
400
340
|
return code
|
|
401
341
|
}
|
package/cli/commands/test.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
|
4
4
|
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path'
|
|
5
|
+
import { loopbackOriginOf } from '../../src/backend-origin'
|
|
5
6
|
import {
|
|
6
7
|
RNX_CLOUD_TEST_FILES_MAX_BYTES,
|
|
7
8
|
RNX_CLOUD_TEST_FILES_MAX_COUNT,
|
|
8
9
|
} from '../../src/cloud-contract'
|
|
9
10
|
import { isCloudTestValueFlag, parseCloudTestArgs } from '../../src/cloud-test-args'
|
|
11
|
+
import { rnxPublicBrand } from '../../src/public-brand'
|
|
10
12
|
import { authHeaderValue, resolveCliAuth } from '../auth'
|
|
11
13
|
import {
|
|
12
14
|
parseCloudTestSidecarPorts,
|
|
@@ -542,6 +544,18 @@ async function readJobStatus(
|
|
|
542
544
|
}
|
|
543
545
|
}
|
|
544
546
|
|
|
547
|
+
// the operator token proves admission to Contrast's own hosted queue only: never send it
|
|
548
|
+
// to an arbitrary --origin. other contrast.dev subdomains serve deployments and
|
|
549
|
+
// custom-domain targets, so only the exact queue hosts qualify.
|
|
550
|
+
function sendsAdminToken(origin: string): boolean {
|
|
551
|
+
const { hostname, origin: exact } = new URL(origin)
|
|
552
|
+
return (
|
|
553
|
+
hostname === 'contrast.dev' ||
|
|
554
|
+
loopbackOriginOf(origin) !== null ||
|
|
555
|
+
exact === new URL(rnxPublicBrand.origin).origin
|
|
556
|
+
)
|
|
557
|
+
}
|
|
558
|
+
|
|
545
559
|
export async function cancelCloudTest(jobId: string, origin: string): Promise<number> {
|
|
546
560
|
const auth = resolveCliAuth()
|
|
547
561
|
if (!auth) {
|
|
@@ -1012,6 +1026,12 @@ export async function runCloudTest(
|
|
|
1012
1026
|
headers: {
|
|
1013
1027
|
'content-type': 'application/json',
|
|
1014
1028
|
authorization: authHeaderValue(auth),
|
|
1029
|
+
// standalone submissions ride the private hosted queue, which
|
|
1030
|
+
// admits operators only: the account key above proves billing
|
|
1031
|
+
// entitlement while this header proves operator admission.
|
|
1032
|
+
...(process.env.E2E_ADMIN_TOKEN && sendsAdminToken(origin)
|
|
1033
|
+
? { 'x-soot-admin-token': process.env.E2E_ADMIN_TOKEN }
|
|
1034
|
+
: {}),
|
|
1015
1035
|
},
|
|
1016
1036
|
body: JSON.stringify(submitPayload),
|
|
1017
1037
|
})
|
package/cli/commands/upload.ts
CHANGED
|
@@ -124,7 +124,7 @@ function normalizeOrigin(origin: string): string {
|
|
|
124
124
|
return origin.replace(/\/$/, '')
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
function isContrastOrigin(origin: string): boolean {
|
|
127
|
+
export function isContrastOrigin(origin: string): boolean {
|
|
128
128
|
try {
|
|
129
129
|
const hostname = new URL(origin).hostname.toLowerCase()
|
|
130
130
|
return hostname === 'contrast.dev' || hostname.endsWith('.contrast.dev')
|
package/cli/device-option.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { devices, listSelectableDeviceModels } from '../src/device-catalog.ts'
|
|
|
2
2
|
|
|
3
3
|
export function validateDeviceOption(device: string | undefined): boolean {
|
|
4
4
|
if (!device || device in devices) return true
|
|
5
|
-
console.error(` peach
|
|
5
|
+
console.error(` peach: unknown device "${device}"`)
|
|
6
6
|
console.error(` known devices: ${listSelectableDeviceModels().join(', ')}`)
|
|
7
7
|
return false
|
|
8
8
|
}
|
package/cli/main.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { automaticPeachUpdatesEnabled } from '../src/automatic-update-policy'
|
|
|
6
6
|
import { getCliRuntime } from '../src/cli-runtime.ts'
|
|
7
7
|
import { exitWithFlushedOutput } from '../src/process-output'
|
|
8
8
|
import { rnxPublicBrand } from '../src/public-brand'
|
|
9
|
+
import { validateDeviceOption } from './device-option'
|
|
9
10
|
import { levenshtein } from './levenshtein'
|
|
10
11
|
import { COMMANDS, parseArgs, TOP_LEVEL_RUNTIME_COMMANDS } from './parse-args'
|
|
11
12
|
import { PeachExit } from './run-rnx'
|
|
@@ -328,6 +329,10 @@ if (theme && theme !== 'light' && theme !== 'dark' && theme !== 'auto') {
|
|
|
328
329
|
await exitWithFlush(1)
|
|
329
330
|
}
|
|
330
331
|
|
|
332
|
+
// the global -d/--device lands in settings unvalidated otherwise, and an unknown
|
|
333
|
+
// model silently renders the default device instead of the one asked for.
|
|
334
|
+
if (!validateDeviceOption(device)) await exitWithFlush(1)
|
|
335
|
+
|
|
331
336
|
// apply device/theme to settings store if provided
|
|
332
337
|
if (device || theme) {
|
|
333
338
|
// the settings store lives in the runtime companion, so a first-use home
|
|
@@ -581,7 +586,8 @@ try {
|
|
|
581
586
|
// global --device/--theme seed the opened sim like the open flags;
|
|
582
587
|
// an explicit open flag wins
|
|
583
588
|
const openArgs = [...commandArgsWithSim]
|
|
584
|
-
if (device && !openArgs.
|
|
589
|
+
if (device && !openArgs.some((arg) => arg === '--device' || arg === '-d'))
|
|
590
|
+
openArgs.push('--device', device)
|
|
585
591
|
if (theme && !openArgs.some((arg) => arg === '--theme' || arg === '-t')) {
|
|
586
592
|
openArgs.push('--theme', theme)
|
|
587
593
|
}
|
|
@@ -589,6 +595,12 @@ try {
|
|
|
589
595
|
break
|
|
590
596
|
}
|
|
591
597
|
|
|
598
|
+
case 'package': {
|
|
599
|
+
const { runPackage } = await import('./commands/package')
|
|
600
|
+
await runPackage(parsed.commandArgs)
|
|
601
|
+
break
|
|
602
|
+
}
|
|
603
|
+
|
|
592
604
|
case 'ios':
|
|
593
605
|
case 'android': {
|
|
594
606
|
const { runPlatformCommand } = await import('./commands/platform')
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { produceConfiguredBundle } from '../src/configured-bundle-producer'
|
|
4
|
+
import { swiftGuestBundle, kotlinGuestBundle } from '../src/guest-bundle'
|
|
5
|
+
import { KOTLIN_GUEST_PATH } from '../src/kotlinDiscoveryContract'
|
|
6
|
+
import { insertNativeAppIdentityFooter } from '../src/native-app-identity'
|
|
7
|
+
import { resolveSwiftModule } from '../src/swift-distribution'
|
|
8
|
+
import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from '../src/swift-submit'
|
|
9
|
+
import { SWIFT_GUEST_PATH } from '../src/swiftDiscoveryContract'
|
|
10
|
+
import { findXcodeProject, readXcodeScheme } from '../src/xcode-project'
|
|
11
|
+
import { loadRNXAppConfig } from './app-config'
|
|
12
|
+
import { resolveAppProject } from './app-project'
|
|
13
|
+
import type { SwiftHostedCompileOptions } from '../src/swift-host'
|
|
14
|
+
|
|
15
|
+
export type NativeInput =
|
|
16
|
+
| { kind: 'swift-file' | 'swift-package' | 'xcode'; path: string }
|
|
17
|
+
| { kind: 'kotlin'; path: string }
|
|
18
|
+
|
|
19
|
+
// URLs, ports, JavaScript, loose native files and directories holding several
|
|
20
|
+
// Xcode projects retain open's existing resolution path; peach swift passes
|
|
21
|
+
// ambiguous so the several-projects error reaches its user.
|
|
22
|
+
export function resolveNativeInput(
|
|
23
|
+
target: string,
|
|
24
|
+
ambiguous = false,
|
|
25
|
+
): NativeInput | null {
|
|
26
|
+
if (!target || /^\w+:\/\//.test(target) || /^\d+$/.test(target)) return null
|
|
27
|
+
const resolved = path.resolve(target)
|
|
28
|
+
const stat = fs.statSync(resolved, { throwIfNoEntry: false })
|
|
29
|
+
if (!stat) return null
|
|
30
|
+
if (stat.isFile()) {
|
|
31
|
+
if (resolved.endsWith('.swift') && path.basename(resolved) !== 'Package.swift')
|
|
32
|
+
return { kind: 'swift-file', path: fs.realpathSync(resolved) }
|
|
33
|
+
if (path.basename(resolved) === 'Package.swift')
|
|
34
|
+
return { kind: 'swift-package', path: fs.realpathSync(path.dirname(resolved)) }
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
if (!stat.isDirectory()) return null
|
|
38
|
+
if (fs.existsSync(path.join(resolved, 'Package.swift')))
|
|
39
|
+
return { kind: 'swift-package', path: fs.realpathSync(resolved) }
|
|
40
|
+
const xcode = ambiguous ? findXcodeProject(resolved) : singleXcodeProject(resolved)
|
|
41
|
+
if (xcode) return { kind: 'xcode', path: fs.realpathSync(xcode) }
|
|
42
|
+
if (fs.existsSync(path.join(resolved, 'src/main/AndroidManifest.xml')))
|
|
43
|
+
return { kind: 'kotlin', path: fs.realpathSync(resolved) }
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// findXcodeProject's own search order, answering null where it would throw.
|
|
48
|
+
function singleXcodeProject(directory: string): string | null {
|
|
49
|
+
const names = fs.readdirSync(directory)
|
|
50
|
+
for (const extension of ['.xcworkspace', '.xcodeproj']) {
|
|
51
|
+
const found = names.filter((name) => name.endsWith(extension))
|
|
52
|
+
if (found.length > 1) return null
|
|
53
|
+
if (found.length === 1) return findXcodeProject(directory)
|
|
54
|
+
}
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function prepareSwiftInput(
|
|
59
|
+
input: Exclude<NativeInput, { kind: 'kotlin' }>,
|
|
60
|
+
opts: {
|
|
61
|
+
target?: string
|
|
62
|
+
scheme?: string
|
|
63
|
+
hosted?: SwiftHostedCompileOptions
|
|
64
|
+
signal?: AbortSignal
|
|
65
|
+
} = {},
|
|
66
|
+
) {
|
|
67
|
+
if ((opts.target || opts.scheme) && input.kind !== 'xcode')
|
|
68
|
+
throw new Error(
|
|
69
|
+
`${opts.scheme ? '--scheme' : '--target'} selects an Xcode application target`,
|
|
70
|
+
)
|
|
71
|
+
if (opts.target && opts.scheme)
|
|
72
|
+
throw new Error('--scheme names its own target; pass one of them')
|
|
73
|
+
const module = opts.hosted
|
|
74
|
+
? null
|
|
75
|
+
: await resolveSwiftModule({ required: true, signal: opts.signal })
|
|
76
|
+
if (!module && !opts.hosted)
|
|
77
|
+
throw new Error(
|
|
78
|
+
'peach needs a local Swift distribution: set PEACH_SWIFT_ENDPOINT or pass --upload-source to compile on Contrast',
|
|
79
|
+
)
|
|
80
|
+
const host = await import('../src/swift-host')
|
|
81
|
+
const run = opts.scheme ? readXcodeScheme(input.path, opts.scheme) : null
|
|
82
|
+
const packagePath =
|
|
83
|
+
input.kind === 'swift-file'
|
|
84
|
+
? host.openSwiftFile(input.path)
|
|
85
|
+
: input.kind === 'xcode'
|
|
86
|
+
? host.openXcodeProject(
|
|
87
|
+
input.path,
|
|
88
|
+
run?.target ?? opts.target,
|
|
89
|
+
module?.root,
|
|
90
|
+
run?.configuration,
|
|
91
|
+
)
|
|
92
|
+
: input.path
|
|
93
|
+
const name =
|
|
94
|
+
input.kind === 'swift-file'
|
|
95
|
+
? path.basename(input.path, '.swift')
|
|
96
|
+
: path.basename(packagePath)
|
|
97
|
+
const appProject = resolveAppProject(packagePath)
|
|
98
|
+
let appInfo: ReturnType<typeof host.swiftProjectAppInfo>
|
|
99
|
+
try {
|
|
100
|
+
host.configureSwiftStandinBehavior(packagePath, await loadRNXAppConfig(appProject))
|
|
101
|
+
host.swiftPackageWatchFiles(packagePath, undefined)
|
|
102
|
+
appInfo = host.swiftProjectAppInfo(packagePath)
|
|
103
|
+
} catch (error) {
|
|
104
|
+
host.disposeSwiftProject(packagePath)
|
|
105
|
+
throw error
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
host,
|
|
109
|
+
module,
|
|
110
|
+
packagePath,
|
|
111
|
+
name,
|
|
112
|
+
appProject,
|
|
113
|
+
appInfo,
|
|
114
|
+
async build(origin: string) {
|
|
115
|
+
const config = await loadRNXAppConfig(appProject)
|
|
116
|
+
host.configureSwiftStandinBehavior(packagePath, config)
|
|
117
|
+
const source = await produceConfiguredBundle(
|
|
118
|
+
swiftGuestBundle(name),
|
|
119
|
+
config,
|
|
120
|
+
new Set(),
|
|
121
|
+
)
|
|
122
|
+
const guestSource = appInfo.identity
|
|
123
|
+
? insertNativeAppIdentityFooter(source, appInfo.identity)
|
|
124
|
+
: source
|
|
125
|
+
const metadata = await host.swiftPackageMetadata(
|
|
126
|
+
packagePath,
|
|
127
|
+
name,
|
|
128
|
+
module?.root,
|
|
129
|
+
origin,
|
|
130
|
+
opts.hosted,
|
|
131
|
+
opts.signal,
|
|
132
|
+
)
|
|
133
|
+
return { guestSource, metadata }
|
|
134
|
+
},
|
|
135
|
+
dispose() {
|
|
136
|
+
host.disposeSwiftProject(packagePath, opts.signal)
|
|
137
|
+
},
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// the packager writes these existing guest routes beside its own runtime.
|
|
142
|
+
// no source checkout, compiler or foreground build server is needed at launch.
|
|
143
|
+
export async function prepareNativeInput(
|
|
144
|
+
input: NativeInput,
|
|
145
|
+
opts: {
|
|
146
|
+
origin: string
|
|
147
|
+
target?: string
|
|
148
|
+
scheme?: string
|
|
149
|
+
activity?: string
|
|
150
|
+
signal?: AbortSignal
|
|
151
|
+
},
|
|
152
|
+
) {
|
|
153
|
+
if (input.kind === 'kotlin') {
|
|
154
|
+
const host = await import('../src/kotlin-host')
|
|
155
|
+
const { readAndroidPins, readKotlinApp } = await import('../src/kotlin-app')
|
|
156
|
+
const moduleRoot = host.peachKotlinModuleRoot()
|
|
157
|
+
const project = readKotlinApp(input.path, {
|
|
158
|
+
activity: opts.activity,
|
|
159
|
+
pins: readAndroidPins(moduleRoot),
|
|
160
|
+
})
|
|
161
|
+
const metadata = await host.kotlinAppArtifact(project, moduleRoot, opts.origin)
|
|
162
|
+
const prefix = new URL(metadata.url).pathname.slice(0, -'app.mjs'.length)
|
|
163
|
+
return {
|
|
164
|
+
name: path.basename(project.projectDir),
|
|
165
|
+
guestSource: kotlinGuestBundle(),
|
|
166
|
+
guestPath: KOTLIN_GUEST_PATH,
|
|
167
|
+
metadataPath: host.KOTLIN_PACKAGE_PATH,
|
|
168
|
+
metadata: { ...metadata, hmrPath: '/__peach/kotlin-hmr' },
|
|
169
|
+
icon: null,
|
|
170
|
+
assets: new Map(
|
|
171
|
+
host
|
|
172
|
+
.kotlinArtifactFiles(metadata.hash)
|
|
173
|
+
.map(({ name, ...asset }) => [prefix + name, asset]),
|
|
174
|
+
),
|
|
175
|
+
dispose() {},
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const prepared = await prepareSwiftInput(input, opts)
|
|
179
|
+
try {
|
|
180
|
+
const built = await prepared.build(opts.origin)
|
|
181
|
+
const assets = prepared.host.swiftPackageAssets(
|
|
182
|
+
prepared.packagePath,
|
|
183
|
+
built.metadata.hash,
|
|
184
|
+
)
|
|
185
|
+
return {
|
|
186
|
+
name: prepared.appInfo.name,
|
|
187
|
+
...built,
|
|
188
|
+
metadata: { ...built.metadata, hmrPath: opts.origin + SWIFT_HMR_PATH },
|
|
189
|
+
guestPath: SWIFT_GUEST_PATH,
|
|
190
|
+
metadataPath: SWIFT_PACKAGE_PATH + encodeURIComponent(prepared.name),
|
|
191
|
+
icon: prepared.appInfo.icon,
|
|
192
|
+
assets,
|
|
193
|
+
dispose: prepared.dispose,
|
|
194
|
+
}
|
|
195
|
+
} catch (error) {
|
|
196
|
+
prepared.dispose()
|
|
197
|
+
throw error
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -266,6 +266,27 @@ export interface OutboundCallDeclaration {
|
|
|
266
266
|
// a new fetch, websocket, node HTTP request, or TCP connection has no entry and
|
|
267
267
|
// fails scripts/check/outbound-endpoints.ts until its destination and consent behavior are declared.
|
|
268
268
|
export const DECLARED_OUTBOUND_CALLS: Record<string, OutboundCallDeclaration> = {
|
|
269
|
+
'packages/peachsim/cli/commands/package.ts :: fetch :: target': {
|
|
270
|
+
category: 'guest_app_network',
|
|
271
|
+
count: 1,
|
|
272
|
+
},
|
|
273
|
+
'packages/peachsim/cli/commands/package.ts :: fetch :: channel.bundleUrl': {
|
|
274
|
+
category: 'guest_app_network',
|
|
275
|
+
count: 1,
|
|
276
|
+
},
|
|
277
|
+
'packages/peachsim/cli/commands/package.ts :: fetch :: channel.iconUrl': {
|
|
278
|
+
category: 'guest_app_network',
|
|
279
|
+
count: 1,
|
|
280
|
+
},
|
|
281
|
+
"packages/peachsim/cli/commands/package.ts :: fetch :: `${directory.href.replace(/\\/$/, '')}/${filename}`":
|
|
282
|
+
{
|
|
283
|
+
category: 'guest_app_network',
|
|
284
|
+
count: 1,
|
|
285
|
+
},
|
|
286
|
+
'packages/peachsim/cli/commands/package.ts :: fetch :: url': {
|
|
287
|
+
category: 'guest_app_network',
|
|
288
|
+
count: 1,
|
|
289
|
+
},
|
|
269
290
|
'packages/peach-engine/src/launch-metadata.ts :: fetch :: reference': {
|
|
270
291
|
category: 'local_development',
|
|
271
292
|
count: 1,
|
|
@@ -519,6 +540,10 @@ export const DECLARED_OUTBOUND_CALLS: Record<string, OutboundCallDeclaration> =
|
|
|
519
540
|
category: 'guest_app_network',
|
|
520
541
|
count: 1,
|
|
521
542
|
},
|
|
543
|
+
'packages/peach-engine/src/react-native/NetworkingBody.ts :: fetch :: data.uri': {
|
|
544
|
+
category: 'guest_app_network',
|
|
545
|
+
count: 1,
|
|
546
|
+
},
|
|
522
547
|
'packages/peach-engine/src/engine/font-data.ts :: fetch-alias :: String(wasmUrl)': {
|
|
523
548
|
category: 'same_origin_runtime',
|
|
524
549
|
count: 1,
|
|
@@ -583,7 +608,7 @@ export const DECLARED_OUTBOUND_CALLS: Record<string, OutboundCallDeclaration> =
|
|
|
583
608
|
category: 'guest_app_network',
|
|
584
609
|
count: 1,
|
|
585
610
|
},
|
|
586
|
-
'packages/peach-engine/src/react-native/
|
|
611
|
+
'packages/peach-engine/src/react-native/file-access-module.ts :: fetch :: resource': {
|
|
587
612
|
category: 'guest_app_network',
|
|
588
613
|
count: 1,
|
|
589
614
|
},
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { APP_PACKAGE_ADDRESS_PATTERN } from '../src/appPackageContract'
|
|
2
|
+
|
|
3
|
+
// runs with the host's bundled Node, then replaces itself with the native host.
|
|
4
|
+
// keeping the pid lets Launch Services and background launchers track the app.
|
|
5
|
+
export const packagedAppLauncher = String.raw`
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const { spawn } = require('node:child_process');
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
const resources = __dirname;
|
|
13
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(resources, 'peach-app.json'), 'utf8'));
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const homeFlag = args.indexOf('--peach-app-home');
|
|
16
|
+
const home = homeFlag < 0 ? path.join(os.homedir(), 'Library', 'Application Support', manifest.identifier) : path.resolve(args.splice(homeFlag, 2)[1]);
|
|
17
|
+
fs.mkdirSync(path.join(home, 'runtimes'), { recursive: true, mode: 0o700 });
|
|
18
|
+
const config = path.join(home, 'config.json');
|
|
19
|
+
if (!fs.existsSync(config)) fs.writeFileSync(config, JSON.stringify({ settings: manifest.defaults }), { flag: 'wx', mode: 0o600 });
|
|
20
|
+
const desktop = path.join(home, 'desktop');
|
|
21
|
+
fs.mkdirSync(desktop, { recursive: true });
|
|
22
|
+
const windowState = path.join(desktop, 'window-state.json');
|
|
23
|
+
if (!fs.existsSync(windowState)) fs.writeFileSync(windowState, JSON.stringify({ default: { device: manifest.defaults.deviceModel, posture: { posture: manifest.defaults.posture }, orientation: manifest.defaults.orientation, bezels: manifest.defaults.showFrame } }), { flag: 'wx', mode: 0o600 });
|
|
24
|
+
const runtime = path.join(resources, 'runtime');
|
|
25
|
+
const link = path.join(home, 'runtimes', manifest.runtimeVersion);
|
|
26
|
+
const env = Object.fromEntries(Object.entries({ ...process.env, PEACH_HOME: home, PEACH_APP_MANIFEST: path.join(resources, 'peach-app.json'), PEACH_UPDATE_CHECK: '0', SOOTSIM_DEV: '0' }).filter(([, value]) => value !== undefined));
|
|
27
|
+
const lockPath = path.join(home, 'daemon.json');
|
|
28
|
+
function readLock() {
|
|
29
|
+
if (!fs.existsSync(lockPath)) return null;
|
|
30
|
+
const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
|
|
31
|
+
if (Date.now() - lock.heartbeatAt > 30000) return null;
|
|
32
|
+
try { process.kill(lock.pid, 0); } catch (error) { if (error.code === 'ESRCH') return null; throw error; }
|
|
33
|
+
if (lock.bootstrapping) return null;
|
|
34
|
+
return lock;
|
|
35
|
+
}
|
|
36
|
+
let lock = readLock();
|
|
37
|
+
const recordPath = path.join(home, 'app-runtime.json');
|
|
38
|
+
const record = fs.existsSync(recordPath) ? JSON.parse(fs.readFileSync(recordPath, 'utf8')) : null;
|
|
39
|
+
if (lock && (record?.pid !== lock.pid || record.buildId !== manifest.buildId)) {
|
|
40
|
+
await new Promise((resolve, reject) => {
|
|
41
|
+
const watcher = fs.watch(home, () => { if (!readLock()) { watcher.close(); clearTimeout(timer); resolve(); } });
|
|
42
|
+
const timer = setTimeout(() => { watcher.close(); reject(new Error('Quit the previous app version before opening this update.')); }, 30000);
|
|
43
|
+
});
|
|
44
|
+
lock = null;
|
|
45
|
+
}
|
|
46
|
+
if (fs.lstatSync(link, { throwIfNoEntry: false })) fs.unlinkSync(link);
|
|
47
|
+
fs.symlinkSync(runtime, link, 'dir');
|
|
48
|
+
fs.writeFileSync(path.join(home, 'runtimes', 'active'), manifest.runtimeVersion + '\n');
|
|
49
|
+
if (!lock) {
|
|
50
|
+
lock = await new Promise((resolve, reject) => {
|
|
51
|
+
let child;
|
|
52
|
+
let settled = false;
|
|
53
|
+
const watcher = fs.watch(home, () => {
|
|
54
|
+
try { const ready = readLock(); if (ready) finish(null, ready); } catch (error) { finish(error); }
|
|
55
|
+
});
|
|
56
|
+
const timer = setTimeout(() => finish(new Error('The bundled Peach runtime did not become ready.')), 30000);
|
|
57
|
+
function finish(error, ready) {
|
|
58
|
+
if (settled) return;
|
|
59
|
+
settled = true;
|
|
60
|
+
watcher.close(); clearTimeout(timer);
|
|
61
|
+
if (error) { child?.kill('SIGTERM'); reject(error); } else resolve(ready);
|
|
62
|
+
}
|
|
63
|
+
const log = fs.openSync(path.join(home, 'runtime.log'), 'a', 0o600);
|
|
64
|
+
child = spawn(path.join(resources, 'bin', 'peach'), ['serve', '--quiet', '--port', '0', '--exit-when-unused'], { env, detached: true, stdio: ['pipe', log, log] });
|
|
65
|
+
fs.closeSync(log);
|
|
66
|
+
child.once('error', error => finish(error));
|
|
67
|
+
child.once('exit', code => finish(new Error('Bundled runtime exited: ' + code)));
|
|
68
|
+
child.unref();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
fs.writeFileSync(recordPath, JSON.stringify({ pid: lock.pid, buildId: manifest.buildId }));
|
|
72
|
+
const address = new RegExp(${JSON.stringify(APP_PACKAGE_ADDRESS_PATTERN)}, 'gi');
|
|
73
|
+
function relocate(text) {
|
|
74
|
+
return text.replace(address, match => match.slice(0, -new URL(manifest.origin).port.length) + lock.bridgePort);
|
|
75
|
+
}
|
|
76
|
+
const staged = path.join(home, 'cache', 'staged');
|
|
77
|
+
fs.mkdirSync(staged, { recursive: true });
|
|
78
|
+
for (const name of fs.readdirSync(path.join(resources, 'payload'))) {
|
|
79
|
+
const source = path.join(resources, 'payload', name);
|
|
80
|
+
const destination = path.join(staged, name);
|
|
81
|
+
if (manifest.relocatableFiles.includes(name)) fs.writeFileSync(destination, relocate(fs.readFileSync(source, 'utf8')));
|
|
82
|
+
else fs.copyFileSync(source, destination);
|
|
83
|
+
}
|
|
84
|
+
const url = new URL(relocate(manifest.launchUrl));
|
|
85
|
+
url.searchParams.set('wsPort', String(lock.bridgePort));
|
|
86
|
+
const saved = JSON.parse(fs.readFileSync(windowState, 'utf8')).default;
|
|
87
|
+
url.searchParams.set('device', saved.device);
|
|
88
|
+
url.searchParams.set('posture', saved.posture.posture);
|
|
89
|
+
url.searchParams.set('orientation', saved.orientation ?? manifest.defaults.orientation);
|
|
90
|
+
env.PEACH_BRIDGE_PORT = String(lock.bridgePort);
|
|
91
|
+
const executable = path.join(resources, '..', 'MacOS', manifest.hostExecutable);
|
|
92
|
+
process.execve(executable, [executable, '--url', url.href, '-SUEnableAutomaticChecks', 'NO', '-SUAutomaticallyUpdate', 'NO', ...manifest.hostArguments, ...args], env);
|
|
93
|
+
}
|
|
94
|
+
main().catch(error => { console.error(error); process.exitCode = 1; });
|
|
95
|
+
`
|