peachsim 0.1.686 → 0.1.688
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/cli/cloud-client.ts +3 -3
- package/cli/command-registry.ts +2 -0
- package/cli/commands/control.ts +1 -0
- package/cli/commands/debug.ts +10 -33
- package/cli/commands/do-chain.ts +56 -6
- package/cli/commands/inspect/core.ts +2 -0
- package/cli/commands/inspect/list.ts +2 -1
- package/cli/commands/inspect/settling.ts +17 -3
- package/cli/commands/inspect/shared.ts +2 -0
- package/cli/commands/inspect/wait-idle.ts +2 -2
- package/cli/commands/inspect/wait-ready.ts +3 -3
- package/cli/commands/inspect.ts +33 -7
- package/cli/commands/location.ts +164 -0
- package/cli/commands/platform.ts +1 -1
- package/cli/drivers/playwright-sim-host.ts +46 -25
- package/cli/main.ts +6 -0
- package/detox/index.ts +13 -8
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.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 +4 -3
- package/dist-lib/bridge-contract-input.cjs +12 -1
- package/dist-lib/bridge-contract-input.mjs +12 -1
- package/dist-lib/bridge-contract.cjs +4 -3
- package/dist-lib/bridge-contract.mjs +4 -3
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +2 -1
- package/dist-lib/cloud-contract.mjs +2 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -1
- package/dist-lib/cloud.mjs +2 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1197 -65
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +402 -113
- package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
- package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
- package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +29 -11
- 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 +89 -13
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -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 +5 -3
- package/dist-lib/native-app-identity.cjs +8 -3
- package/dist-lib/native-app-identity.mjs +8 -3
- 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/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +21 -6
- package/dist-lib/sdk.mjs +21 -6
- package/dist-lib/skills.cjs +441 -135
- package/dist-lib/swift-compile.cjs +317 -27
- package/dist-lib/swift-compile.mjs +315 -27
- 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 +10 -10
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +320 -49
- package/dist-lib/vite.cjs +1 -1
- package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
- package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
- package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
- package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
- package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
- package/package.json +2 -2
- package/scripts/dev-server-scanner.ts +3 -1
- package/skills/contrast/SKILL.md +1 -0
- package/src/android-drawables.ts +315 -0
- package/src/android-theme.ts +9 -0
- package/src/bridge-constants.ts +3 -2
- package/src/bridge-contract-input.ts +11 -0
- package/src/bridge-contract.ts +45 -3
- package/src/cloud-contract.ts +1 -0
- package/src/host/fetch-proxy-handler.ts +13 -49
- package/src/host/fetch-proxy-overrides.ts +69 -12
- package/src/kotlin-app.ts +6 -0
- package/src/kotlin-host.ts +103 -15
- package/src/native-app-identity.ts +16 -3
- package/src/swift-compile.ts +426 -29
- package/src/swift-distribution-contract.ts +11 -4
- package/src/swift-distribution.lock.json +11 -9
- package/src/swift-distribution.ts +4 -4
- package/src/swift-icu.ts +8 -11
- package/src/swift-submit.ts +13 -1
- package/src/swift-toolchain.ts +17 -9
- package/src/vite-plugin.ts +86 -34
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// (scripts/ops/swift-distribution-publish.ts) and the CLI that installs it
|
|
4
4
|
// (swift-distribution.ts). docs/swift-distribution.md owns the design.
|
|
5
5
|
import { isRecord } from './is-record'
|
|
6
|
+
import type { SwiftWasmSdk } from './swift-toolchain'
|
|
6
7
|
|
|
7
8
|
/** the file at the root of an unpacked distribution, and its install marker. */
|
|
8
9
|
export const SWIFT_DISTRIBUTION_MANIFEST = 'distribution.json'
|
|
@@ -23,12 +24,11 @@ export function swiftDistributionHost(
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** the host-independent half: wasm32 modules and their objects. */
|
|
26
|
-
export interface SwiftDistributionWasm {
|
|
27
|
+
export interface SwiftDistributionWasm extends SwiftWasmSdk {
|
|
27
28
|
/** the digest of the module sources it was built from (swiftModuleDigest). */
|
|
28
29
|
id: string
|
|
29
30
|
/** the swift.org release that built it, the only one that can read it. */
|
|
30
31
|
release: string
|
|
31
|
-
wasmSdkChecksum: string
|
|
32
32
|
/** the importable Swift modules under modules/. */
|
|
33
33
|
modules: string[]
|
|
34
34
|
/** the modules' wasm32 objects, relative to the root, in link order. */
|
|
@@ -47,10 +47,9 @@ export interface SwiftDistributionManifest extends SwiftDistributionWasm {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/** the published archives one CLI build installs, committed beside this file. */
|
|
50
|
-
export interface SwiftDistributionLock {
|
|
50
|
+
export interface SwiftDistributionLock extends SwiftWasmSdk {
|
|
51
51
|
id: string
|
|
52
52
|
release: string
|
|
53
|
-
wasmSdkChecksum: string
|
|
54
53
|
/** the commit the module sources were built from. */
|
|
55
54
|
source: string
|
|
56
55
|
hosts: Record<SwiftDistributionHost, { sha256: string; size: number }>
|
|
@@ -66,6 +65,8 @@ export function parseSwiftDistributionManifest(
|
|
|
66
65
|
!isRecord(value) ||
|
|
67
66
|
typeof value.id !== 'string' ||
|
|
68
67
|
typeof value.release !== 'string' ||
|
|
68
|
+
typeof value.wasmSdkId !== 'string' ||
|
|
69
|
+
typeof value.wasmSdkUrl !== 'string' ||
|
|
69
70
|
typeof value.wasmSdkChecksum !== 'string' ||
|
|
70
71
|
!isStrings(value.modules) ||
|
|
71
72
|
!isStrings(value.objects) ||
|
|
@@ -82,6 +83,8 @@ export function parseSwiftDistributionManifest(
|
|
|
82
83
|
return {
|
|
83
84
|
id: value.id,
|
|
84
85
|
release: value.release,
|
|
86
|
+
wasmSdkId: value.wasmSdkId,
|
|
87
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
85
88
|
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
86
89
|
modules: value.modules,
|
|
87
90
|
objects: value.objects,
|
|
@@ -100,6 +103,8 @@ export function parseSwiftDistributionLock(value: unknown): SwiftDistributionLoc
|
|
|
100
103
|
typeof value.id !== 'string' ||
|
|
101
104
|
!/^[a-f0-9]{16}$/.test(value.id) ||
|
|
102
105
|
typeof value.release !== 'string' ||
|
|
106
|
+
typeof value.wasmSdkId !== 'string' ||
|
|
107
|
+
typeof value.wasmSdkUrl !== 'string' ||
|
|
103
108
|
typeof value.wasmSdkChecksum !== 'string' ||
|
|
104
109
|
typeof value.source !== 'string' ||
|
|
105
110
|
!isRecord(value.hosts)
|
|
@@ -122,6 +127,8 @@ export function parseSwiftDistributionLock(value: unknown): SwiftDistributionLoc
|
|
|
122
127
|
return {
|
|
123
128
|
id: value.id,
|
|
124
129
|
release: value.release,
|
|
130
|
+
wasmSdkId: value.wasmSdkId,
|
|
131
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
125
132
|
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
126
133
|
source: value.source,
|
|
127
134
|
hosts: {
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
2
|
+
"id": "37329dbb7d21fea3",
|
|
3
3
|
"release": "swift-6.3-RELEASE",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"wasmSdkId": "swift-6.3-RELEASE_wasm-peach-503c2533",
|
|
5
|
+
"wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.3-RELEASE_wasm-peach-503c2533.artifactbundle.tar.gz",
|
|
6
|
+
"wasmSdkChecksum": "00fd9cc559652638552cc19c27624ea350f30bb866d87c41bbfe97d2ae1810eb",
|
|
7
|
+
"source": "dd8c803162eb6e23ce3fca4ab40d5eedf8717d9f",
|
|
6
8
|
"hosts": {
|
|
7
9
|
"darwin-arm64": {
|
|
8
|
-
"sha256": "
|
|
9
|
-
"size":
|
|
10
|
+
"sha256": "b00c5daa751bd315c8157bddb2dc5037b475c3587e4040d12ccb624bfe3f1bb2",
|
|
11
|
+
"size": 6796662
|
|
10
12
|
},
|
|
11
13
|
"linux-x64": {
|
|
12
|
-
"sha256": "
|
|
13
|
-
"size":
|
|
14
|
+
"sha256": "d3f00367c7d3858e922574a49f5c80281fecaa0b2fc595f43c6bbdfc1aed9ac6",
|
|
15
|
+
"size": 6802137
|
|
14
16
|
},
|
|
15
17
|
"linux-arm64": {
|
|
16
|
-
"sha256": "
|
|
17
|
-
"size":
|
|
18
|
+
"sha256": "2b58ae90a2c2c9709a6487ada493e2f556e74db42d16ebb93bc819e60139b363",
|
|
19
|
+
"size": 6801173
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
}
|
|
@@ -8,7 +8,7 @@ import fs from 'node:fs'
|
|
|
8
8
|
import path from 'node:path'
|
|
9
9
|
import { installVerifiedTarball } from '@contrast/runtime-delivery'
|
|
10
10
|
import { rnxHomeDir } from './home-paths'
|
|
11
|
-
import { swiftDistributionAt } from './swift-compile'
|
|
11
|
+
import { swiftDistributionAt, swiftModuleSdk } from './swift-compile'
|
|
12
12
|
import {
|
|
13
13
|
parseSwiftDistributionLock,
|
|
14
14
|
SWIFT_DISTRIBUTION_MANIFEST,
|
|
@@ -43,7 +43,7 @@ export function swiftDistributionRoot(): Promise<string | null> {
|
|
|
43
43
|
}
|
|
44
44
|
// the archive is useless without its compiler, so a missing or wrong
|
|
45
45
|
// toolchain fails before the download
|
|
46
|
-
swiftToolchain(lock.release, lock
|
|
46
|
+
swiftToolchain(lock.release, lock)
|
|
47
47
|
const dir = path.join(rnxHomeDir(), 'swift', `${lock.id}-${host}`)
|
|
48
48
|
let pending = installs.get(dir)
|
|
49
49
|
if (!pending) {
|
|
@@ -98,11 +98,11 @@ export function swiftModuleToolchain(root: string): {
|
|
|
98
98
|
release: string
|
|
99
99
|
toolchainBin: string
|
|
100
100
|
} {
|
|
101
|
-
const pin: { release: string
|
|
101
|
+
const pin: { release: string } =
|
|
102
102
|
swiftDistributionAt(root) ??
|
|
103
103
|
JSON.parse(fs.readFileSync(path.join(root, 'toolchain.json'), 'utf8'))
|
|
104
104
|
return {
|
|
105
105
|
release: pin.release,
|
|
106
|
-
toolchainBin: swiftToolchain(pin.release,
|
|
106
|
+
toolchainBin: swiftToolchain(pin.release, swiftModuleSdk(root)),
|
|
107
107
|
}
|
|
108
108
|
}
|
package/src/swift-icu.ts
CHANGED
|
@@ -48,31 +48,28 @@ function memo<T>(
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/** the raw blob, for a harness that fills an artifact in node. */
|
|
51
|
-
export function swiftIcuData(toolchainBin: string,
|
|
52
|
-
return memo(raw, `${toolchainBin}\0${
|
|
51
|
+
export function swiftIcuData(toolchainBin: string, sdk: string): Promise<Buffer> {
|
|
52
|
+
return memo(raw, `${toolchainBin}\0${sdk}`, () => load(toolchainBin, sdk))
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** the served form: gzipped and content-addressed. */
|
|
56
|
-
export function swiftIcuAsset(
|
|
57
|
-
toolchainBin
|
|
58
|
-
|
|
59
|
-
): Promise<SwiftIcuAsset> {
|
|
60
|
-
return memo(assets, `${toolchainBin}\0${release}`, async () => {
|
|
61
|
-
const zipped = await deflate(await swiftIcuData(toolchainBin, release))
|
|
56
|
+
export function swiftIcuAsset(toolchainBin: string, sdk: string): Promise<SwiftIcuAsset> {
|
|
57
|
+
return memo(assets, `${toolchainBin}\0${sdk}`, async () => {
|
|
58
|
+
const zipped = await deflate(await swiftIcuData(toolchainBin, sdk))
|
|
62
59
|
return { sha256: createHash('sha256').update(zipped).digest('hex'), gzip: zipped }
|
|
63
60
|
})
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
async function load(toolchainBin: string,
|
|
63
|
+
async function load(toolchainBin: string, sdk: string): Promise<Buffer> {
|
|
67
64
|
const { stdout } = await run(path.join(toolchainBin, 'swift'), [
|
|
68
65
|
'sdk',
|
|
69
66
|
'configure',
|
|
70
67
|
'--show-configuration',
|
|
71
|
-
|
|
68
|
+
sdk,
|
|
72
69
|
'wasm32-unknown-wasip1',
|
|
73
70
|
])
|
|
74
71
|
const resources = /^swiftStaticResourcesPath: (.+)$/m.exec(stdout)?.[1]?.trim()
|
|
75
|
-
if (!resources) throw new Error(`swift-icu: ${
|
|
72
|
+
if (!resources) throw new Error(`swift-icu: ${sdk} names no static resources`)
|
|
76
73
|
// a copy, so the 42 MB archive it was sliced from can be collected
|
|
77
74
|
return Buffer.from(
|
|
78
75
|
icuSegment(archiveMember(readFileSync(path.join(resources, ARCHIVE)), MEMBER)),
|
package/src/swift-submit.ts
CHANGED
|
@@ -49,8 +49,20 @@ export const MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024
|
|
|
49
49
|
* 4: the host handles Network path observations and cancellation.
|
|
50
50
|
* 5: the mount lowers SpriteKit's `SpriteKitView` draw list and sends it raw
|
|
51
51
|
* touches (`packages/sootsim-swift/src/spritekit.tsx`).
|
|
52
|
+
* 6: the mount draws UIKit's `UIKitHost`, which reports the safe area over a
|
|
53
|
+
* representable, and `UIKitScroll`, a UIScrollView on the engine scroll view.
|
|
54
|
+
* 7: a `UIKitView` carries masked corner radii and a symbol image's glyph.
|
|
55
|
+
* 8: AVAudioPlayer media requests and playback events use the shared audio host.
|
|
56
|
+
* 9: tracking authorization reads the persisted permission owner synchronously.
|
|
57
|
+
* 10: retained WebKit pages, evaluation replies, live named handlers and
|
|
58
|
+
* abortable Swift HTTP requests with native timeout errors.
|
|
59
|
+
* 11: the mount draws `UIKitHosting`, a hosting view's root in its safe area.
|
|
60
|
+
* 12: the mount draws `UIKitRefresh`, a refreshing UIRefreshControl's spinner.
|
|
61
|
+
* 13: fetch replies stream headers and pulled body chunks, with cancellation.
|
|
62
|
+
* 14: `permission_status` answers notifications (2) as UNAuthorizationStatus.
|
|
63
|
+
* 15: `rnx_display_link_active` asks the host to tick on every display frame.
|
|
52
64
|
*/
|
|
53
|
-
export const SWIFT_HOST_ABI =
|
|
65
|
+
export const SWIFT_HOST_ABI = 15
|
|
54
66
|
|
|
55
67
|
export interface SwiftImageUpload {
|
|
56
68
|
/** the raster file picked for the asset (has the extension). */
|
package/src/swift-toolchain.ts
CHANGED
|
@@ -36,15 +36,23 @@ export function swiftToolchainBin(release: string): string {
|
|
|
36
36
|
)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** the wasm SDK a release compiles with: its installed id, where it
|
|
40
|
+
* downloads from and its archive checksum (packages/sootsim-swift/toolchain.json). */
|
|
41
|
+
export interface SwiftWasmSdk {
|
|
42
|
+
wasmSdkId: string
|
|
43
|
+
wasmSdkUrl: string
|
|
44
|
+
wasmSdkChecksum: string
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
const verified = new Map<string, string>()
|
|
40
48
|
|
|
41
49
|
/**
|
|
42
50
|
* swiftToolchainBin, checked: its swift is exactly `release` and has the
|
|
43
|
-
*
|
|
51
|
+
* pinned wasm SDK installed. anything else fails with one message naming the
|
|
44
52
|
* release and the commands that install it.
|
|
45
53
|
*/
|
|
46
|
-
export function swiftToolchain(release: string,
|
|
47
|
-
const cached = verified.get(release)
|
|
54
|
+
export function swiftToolchain(release: string, sdk: SwiftWasmSdk): string {
|
|
55
|
+
const cached = verified.get(`${release}\0${sdk.wasmSdkId}`)
|
|
48
56
|
if (cached) return cached
|
|
49
57
|
const bin = swiftToolchainBin(release)
|
|
50
58
|
const swift = path.join(bin, 'swift')
|
|
@@ -61,27 +69,27 @@ export function swiftToolchain(release: string, wasmSdkChecksum: string): string
|
|
|
61
69
|
? `found no ${release}.xctoolchain in ~/Library/Developer/Toolchains or /Library/Developer/Toolchains`
|
|
62
70
|
: 'found no swift on PATH'
|
|
63
71
|
throw new Error(
|
|
64
|
-
`peach compiles Swift with the swift.org toolchain ${release} and its wasm SDK; ${found}.\n${swiftInstallSteps(release,
|
|
72
|
+
`peach compiles Swift with the swift.org toolchain ${release} and its wasm SDK; ${found}.\n${swiftInstallSteps(release, sdk)}`,
|
|
65
73
|
)
|
|
66
74
|
}
|
|
67
75
|
const sdks = execFileSync(swift, ['sdk', 'list'], {
|
|
68
76
|
encoding: 'utf8',
|
|
69
77
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
70
78
|
})
|
|
71
|
-
if (!sdks.split('\n').some((line) => line.trim() ===
|
|
79
|
+
if (!sdks.split('\n').some((line) => line.trim() === sdk.wasmSdkId)) {
|
|
72
80
|
throw new Error(
|
|
73
|
-
`peach compiles Swift with the ${
|
|
81
|
+
`peach compiles Swift with the ${sdk.wasmSdkId} SDK, which ${swift} does not have.\n${swiftInstallSteps(release, sdk)}`,
|
|
74
82
|
)
|
|
75
83
|
}
|
|
76
|
-
verified.set(release
|
|
84
|
+
verified.set(`${release}\0${sdk.wasmSdkId}`, bin)
|
|
77
85
|
return bin
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
/** the commands that install `release` and its wasm SDK on this host. */
|
|
81
|
-
export function swiftInstallSteps(release: string,
|
|
89
|
+
export function swiftInstallSteps(release: string, wasmSdk: SwiftWasmSdk): string {
|
|
82
90
|
const version = release.replace(/^swift-/, '').toLowerCase()
|
|
83
91
|
const downloads = `https://download.swift.org/swift-${version}`
|
|
84
|
-
const sdk = `swift sdk install ${
|
|
92
|
+
const sdk = `swift sdk install ${wasmSdk.wasmSdkUrl} --checksum ${wasmSdk.wasmSdkChecksum}`
|
|
85
93
|
if (process.platform === 'darwin') {
|
|
86
94
|
const swift = `~/Library/Developer/Toolchains/${release}.xctoolchain/usr/bin/swift`
|
|
87
95
|
return [
|
package/src/vite-plugin.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import crypto from 'crypto'
|
|
12
12
|
import fs from 'fs'
|
|
13
13
|
import { createRequire } from 'module'
|
|
14
|
+
import { runInNewContext } from 'node:vm'
|
|
14
15
|
import path from 'path'
|
|
15
16
|
import { fileURLToPath, pathToFileURL } from 'url'
|
|
16
17
|
import { type Plugin, transformWithOxc } from 'vite'
|
|
@@ -31,7 +32,9 @@ import {
|
|
|
31
32
|
compatStubsForBuildResolver,
|
|
32
33
|
reactNativeDeepStubsForBuildResolver,
|
|
33
34
|
} from '../../peach-compat/src/stub-manifest.ts'
|
|
35
|
+
import { WEBVIEW_SAME_ORIGIN_BOOTSTRAP_SOURCE } from '../../peach-engine/src/components/native-ui/webview-frame-bridge.ts'
|
|
34
36
|
import { isExpoHostSocketModule } from '../../peach-engine/src/guest-module-overrides.ts'
|
|
37
|
+
import { readPeachWarmManifest } from '../../peach-engine/src/peach-warm-manifest.ts'
|
|
35
38
|
import { resolveSootsimBridgePort } from './bridge-constants.ts'
|
|
36
39
|
import { isRecord } from './is-record.ts'
|
|
37
40
|
import {
|
|
@@ -447,6 +450,7 @@ export function recordingPluginWorkerRedirect(): Plugin {
|
|
|
447
450
|
|
|
448
451
|
export function engineShellWorkerPlugins(): Plugin[] {
|
|
449
452
|
return [
|
|
453
|
+
warmManifestJsonPlugin(),
|
|
450
454
|
workerReactBridgePlugin(),
|
|
451
455
|
fixJsxRuntimeExports(),
|
|
452
456
|
flowStripTransform(),
|
|
@@ -461,6 +465,87 @@ export function engineShellWorkerPlugins(): Plugin[] {
|
|
|
461
465
|
]
|
|
462
466
|
}
|
|
463
467
|
|
|
468
|
+
// admitted coverage repeats prefixes across entries; share their emitted bytes
|
|
469
|
+
// while each consumer still receives its own unchanged array.
|
|
470
|
+
function warmManifestJsonPlugin(): Plugin {
|
|
471
|
+
const marker = '\0peach:warm-manifest:'
|
|
472
|
+
return {
|
|
473
|
+
name: 'peach-warm-manifest-json',
|
|
474
|
+
enforce: 'pre',
|
|
475
|
+
resolveId(source, importer) {
|
|
476
|
+
if (!importer || !source.endsWith('/peach-warm-manifest.json')) return null
|
|
477
|
+
return marker + path.resolve(path.dirname(importer), source) + '.js'
|
|
478
|
+
},
|
|
479
|
+
load(id) {
|
|
480
|
+
if (!id.startsWith(marker)) return null
|
|
481
|
+
const filename = id.slice(marker.length, -3)
|
|
482
|
+
this.addWatchFile(filename)
|
|
483
|
+
const value: unknown = JSON.parse(fs.readFileSync(filename, 'utf8'))
|
|
484
|
+
const manifest = readPeachWarmManifest(value)
|
|
485
|
+
const prefixes = new Map<string, { values: number[]; count: number }>()
|
|
486
|
+
for (const entry of [
|
|
487
|
+
manifest.home,
|
|
488
|
+
...Object.values(manifest.launches),
|
|
489
|
+
...Object.values(manifest.screens),
|
|
490
|
+
]) {
|
|
491
|
+
for (let length = 1; length <= entry.pipelines.length; length++) {
|
|
492
|
+
const values = entry.pipelines.slice(0, length)
|
|
493
|
+
const key = JSON.stringify(values)
|
|
494
|
+
const prior = prefixes.get(key)
|
|
495
|
+
prefixes.set(key, { values, count: (prior?.count ?? 0) + 1 })
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
let shared: number[] = []
|
|
499
|
+
let savings = 0
|
|
500
|
+
for (const [key, prefix] of prefixes) {
|
|
501
|
+
const saved = (key.length - 13) * prefix.count - key.length - 16
|
|
502
|
+
if (saved > savings) {
|
|
503
|
+
shared = prefix.values
|
|
504
|
+
savings = saved
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
function serialize(item: unknown): string {
|
|
508
|
+
if (Array.isArray(item)) {
|
|
509
|
+
if (
|
|
510
|
+
shared.length > 0 &&
|
|
511
|
+
shared.every((index, offset) => item[offset] === index)
|
|
512
|
+
) {
|
|
513
|
+
return `[...shared${item.length > shared.length ? ',' + item.slice(shared.length).map(serialize).join(',') : ''}]`
|
|
514
|
+
}
|
|
515
|
+
return '[' + item.map(serialize).join(',') + ']'
|
|
516
|
+
}
|
|
517
|
+
if (isRecord(item)) {
|
|
518
|
+
return (
|
|
519
|
+
'{' +
|
|
520
|
+
Object.entries(item)
|
|
521
|
+
.map(
|
|
522
|
+
([key, child]) =>
|
|
523
|
+
(key === '__proto__'
|
|
524
|
+
? '[' + JSON.stringify(key) + ']'
|
|
525
|
+
: JSON.stringify(key)) +
|
|
526
|
+
':' +
|
|
527
|
+
serialize(child),
|
|
528
|
+
)
|
|
529
|
+
.join(',') +
|
|
530
|
+
'}'
|
|
531
|
+
)
|
|
532
|
+
}
|
|
533
|
+
return JSON.stringify(item)
|
|
534
|
+
}
|
|
535
|
+
const code = `const shared=${JSON.stringify(shared)};const manifest=${serialize(value)};`
|
|
536
|
+
const reconstructed: unknown = runInNewContext(
|
|
537
|
+
code + 'manifest',
|
|
538
|
+
Object.create(null),
|
|
539
|
+
{ timeout: 1000 },
|
|
540
|
+
)
|
|
541
|
+
if (JSON.stringify(reconstructed) !== JSON.stringify(value)) {
|
|
542
|
+
throw new Error('warm manifest module differs from its canonical JSON')
|
|
543
|
+
}
|
|
544
|
+
return code + 'export default manifest;'
|
|
545
|
+
},
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
464
549
|
// a worker cannot modulepreload, so every static level under its
|
|
465
550
|
// implementation root and every dynamic import on its boot path is a serial
|
|
466
551
|
// round trip before the worker is ready. this plugin bundles each declared
|
|
@@ -2244,41 +2329,8 @@ export function expoDomComponentsPlugin(
|
|
|
2244
2329
|
window.process.env = window.process.env || {};
|
|
2245
2330
|
window.process.env.NODE_ENV = window.process.env.NODE_ENV || 'development';
|
|
2246
2331
|
window.process.env.EXPO_OS = 'web';
|
|
2332
|
+
${WEBVIEW_SAME_ORIGIN_BOOTSTRAP_SOURCE}
|
|
2247
2333
|
(function () {
|
|
2248
|
-
var documentUrl = location.href;
|
|
2249
|
-
function frameUrl() { return String(location.href); }
|
|
2250
|
-
window.ReactNativeWebView = window.ReactNativeWebView || {
|
|
2251
|
-
postMessage: function (data) {
|
|
2252
|
-
window.parent.postMessage({
|
|
2253
|
-
__sootsimWebViewKind: 'reactNativeWebViewMessage',
|
|
2254
|
-
data: String(data),
|
|
2255
|
-
url: frameUrl(),
|
|
2256
|
-
loading: document.readyState !== 'complete',
|
|
2257
|
-
title: String(document.title || '')
|
|
2258
|
-
}, '*');
|
|
2259
|
-
},
|
|
2260
|
-
injectedObjectJson: function () {
|
|
2261
|
-
try {
|
|
2262
|
-
if (window.parent && window.parent.__sootsimGetInjectedObjectJson) {
|
|
2263
|
-
var res = window.parent.__sootsimGetInjectedObjectJson(frameUrl());
|
|
2264
|
-
if (res) return typeof res === 'string' ? res : JSON.stringify(res);
|
|
2265
|
-
}
|
|
2266
|
-
} catch (e) {}
|
|
2267
|
-
return "{}";
|
|
2268
|
-
}
|
|
2269
|
-
};
|
|
2270
|
-
window.addEventListener('message', function (event) {
|
|
2271
|
-
if (event.source !== window.parent) return;
|
|
2272
|
-
var payload = event.data;
|
|
2273
|
-
if (!payload || typeof payload !== 'object') return;
|
|
2274
|
-
if (payload.__sootsimWebViewKind !== 'injectJavaScript') return;
|
|
2275
|
-
event.stopImmediatePropagation();
|
|
2276
|
-
try {
|
|
2277
|
-
(0, eval)(String(payload.js || ''));
|
|
2278
|
-
} catch (err) {
|
|
2279
|
-
setTimeout(function () { throw err; }, 0);
|
|
2280
|
-
}
|
|
2281
|
-
}, true);
|
|
2282
2334
|
// metro-style require shim for expo's dom closure: classic scripts
|
|
2283
2335
|
// run before module imports evaluate, so this covers eval-time
|
|
2284
2336
|
// requires. static requires are rewritten to imports at serve time;
|