peachsim 0.1.730 → 0.1.746
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/bridge-flow-runner.ts +15 -2
- package/cli/commands/control.ts +13 -3
- package/cli/commands/desktop.ts +1 -0
- package/cli/commands/electron.ts +12 -8
- package/cli/commands/flow.ts +1 -3
- package/cli/commands/install-desktop.ts +105 -66
- package/cli/commands/logout.ts +5 -1
- package/cli/commands/no-bridge-hint.ts +2 -2
- package/cli/commands/swift.ts +26 -9
- package/cli/desktop-companion.ts +36 -9
- package/cli/drivers/desktop.ts +65 -0
- package/cli/drivers/electron.ts +4 -66
- package/cli/drivers/index.ts +1 -0
- package/cli/drivers/playwright-sim-host.ts +2 -0
- package/cli/drivers/playwright.ts +3 -3
- package/cli/drivers/registry.ts +7 -2
- package/cli/drivers/types.ts +4 -3
- package/cli/maestro-js.ts +10 -0
- package/cli/outbound-endpoints.ts +2 -2
- 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 +39 -9
- 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/capture-contract.cjs +13 -19
- package/dist-lib/capture-contract.mjs +13 -19
- package/dist-lib/cli-constants.cjs +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/detox/index.cjs +117 -11
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +32 -1
- package/dist-lib/host/bridge-host.cjs +1741 -540
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- 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 +17 -22
- 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 +1 -1
- 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 +1 -1
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- 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 +1 -1
- package/dist-lib/sdk.cjs +2 -1
- package/dist-lib/sdk.mjs +2 -1
- package/dist-lib/skills.cjs +2431 -1075
- package/dist-lib/swift-compile.cjs +374 -65
- package/dist-lib/swift-compile.mjs +369 -66
- package/dist-lib/swift-package.cjs +146 -9
- package/dist-lib/swift-package.mjs +144 -9
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +1690 -233
- package/dist-lib/vite.cjs +4 -4
- package/package.json +1 -1
- package/skills/contrast/SKILL.md +1 -1
- package/src/auth/shared-session.ts +45 -9
- package/src/bridge-constants.ts +7 -7
- package/src/capture-contract.ts +18 -33
- package/src/desktop-host-delivery.ts +81 -0
- package/src/home-paths.ts +30 -0
- package/src/host/bridge-host.ts +11 -6
- package/src/native-seam-manifest.ts +0 -11
- package/src/sim-client.ts +1 -0
- package/src/swift-compile.ts +479 -76
- package/src/swift-distribution.lock.json +11 -11
- package/src/swift-host.ts +338 -45
- package/src/swift-package.ts +204 -19
- package/src/swift-remote-packages.ts +255 -0
- package/src/swift-submit.ts +4 -1
- package/src/vite-plugin-one.ts +2 -2
- package/src/vite-plugin.ts +29 -9
- package/src/xcode-project.ts +612 -0
package/src/swift-package.ts
CHANGED
|
@@ -34,26 +34,40 @@ export function swiftImplicitResourcePaths(paths: readonly string[]): string[] {
|
|
|
34
34
|
.sort()
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
interface ManifestCall {
|
|
38
|
+
kind: string
|
|
39
|
+
/** the call's own depth only: nested calls and their arguments dropped. */
|
|
40
|
+
flat: string
|
|
41
|
+
/** the call's whole argument text. */
|
|
42
|
+
call: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// each top-level `.<kind>(` call in a manifest with comments removed, matched
|
|
46
|
+
// to its balanced close paren. string-aware, so a paren inside a literal cannot end
|
|
47
|
+
// a call early.
|
|
48
|
+
const MANIFEST_DECLARATIONS = [
|
|
49
|
+
'executableTarget',
|
|
50
|
+
'testTarget',
|
|
51
|
+
'binaryTarget',
|
|
52
|
+
'systemLibrary',
|
|
53
|
+
'macro',
|
|
54
|
+
'plugin',
|
|
55
|
+
'target',
|
|
56
|
+
'library',
|
|
57
|
+
'executable',
|
|
58
|
+
'package',
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
function manifestCalls(manifest: string, kinds: readonly string[]): ManifestCall[] {
|
|
62
|
+
const code = manifest
|
|
63
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
64
|
+
.replace(/(^|[^:"])\/\/[^\n]*/g, '$1')
|
|
65
|
+
const calls: ManifestCall[] = []
|
|
66
|
+
// every declaration kind is scanned, so a `.target(name:)` dependency
|
|
67
|
+
// nested in an unrequested `.testTarget(` is skipped as part of it
|
|
68
|
+
const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join('|')})\\s*\\(`, 'g')
|
|
54
69
|
let match: RegExpExecArray | null
|
|
55
70
|
while ((match = pattern.exec(code)) !== null) {
|
|
56
|
-
const executable = match[1] === 'executableTarget'
|
|
57
71
|
let depth = 1
|
|
58
72
|
const start = pattern.lastIndex
|
|
59
73
|
let i = start
|
|
@@ -81,6 +95,178 @@ export function swiftManifestTargets(
|
|
|
81
95
|
}
|
|
82
96
|
i++
|
|
83
97
|
}
|
|
98
|
+
if (kinds.includes(match[1]!))
|
|
99
|
+
calls.push({ kind: match[1]!, flat, call: code.slice(start, i) })
|
|
100
|
+
// declarations never nest, so a call inside one is part of it
|
|
101
|
+
pattern.lastIndex = i
|
|
102
|
+
}
|
|
103
|
+
return calls
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** a target dependency: a target of the same package, or another package's product. */
|
|
107
|
+
export type SwiftTargetDependency =
|
|
108
|
+
| { kind: 'target'; name: string }
|
|
109
|
+
| { kind: 'product'; name: string; package: string }
|
|
110
|
+
|
|
111
|
+
/** the parts of a manifest that say which targets a product compiles. */
|
|
112
|
+
export interface SwiftManifestGraph {
|
|
113
|
+
/** library product name to the targets it vends. */
|
|
114
|
+
products: Map<string, string[]>
|
|
115
|
+
/** every target, binary ones included, to its dependencies on iOS. */
|
|
116
|
+
dependencies: Map<string, SwiftTargetDependency[]>
|
|
117
|
+
binaryTargets: Set<string>
|
|
118
|
+
/** `.systemLibrary` targets: c modules the system provides. */
|
|
119
|
+
systemLibraries: Set<string>
|
|
120
|
+
/** `.package(url:)` dependencies, by the name a `.product(package:)` uses. */
|
|
121
|
+
packageURLs: Map<string, string>
|
|
122
|
+
/** `.package(path:)` dependencies, as written. */
|
|
123
|
+
packagePaths: string[]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const NAME = /\bname\s*:\s*"([^"]+)"/
|
|
127
|
+
|
|
128
|
+
// the elements of the `[...]` following `label:` at a call's top level.
|
|
129
|
+
function listArgument(call: string, label: string): string[] {
|
|
130
|
+
const start = new RegExp(`\\b${label}\\s*:\\s*\\[`).exec(call)
|
|
131
|
+
if (!start) return []
|
|
132
|
+
const items: string[] = []
|
|
133
|
+
let depth = 0
|
|
134
|
+
let inString = false
|
|
135
|
+
let item = ''
|
|
136
|
+
for (let i = start.index + start[0].length; i < call.length; i++) {
|
|
137
|
+
const ch = call[i]!
|
|
138
|
+
if (inString) {
|
|
139
|
+
item += ch
|
|
140
|
+
if (ch === '"' && call[i - 1] !== '\\') inString = false
|
|
141
|
+
continue
|
|
142
|
+
}
|
|
143
|
+
if (ch === '"') inString = true
|
|
144
|
+
else if (ch === '(' || ch === '[') depth++
|
|
145
|
+
else if (ch === ')' || ch === ']') {
|
|
146
|
+
if (depth === 0) break
|
|
147
|
+
depth--
|
|
148
|
+
} else if (ch === ',' && depth === 0) {
|
|
149
|
+
items.push(item.trim())
|
|
150
|
+
item = ''
|
|
151
|
+
continue
|
|
152
|
+
}
|
|
153
|
+
item += ch
|
|
154
|
+
}
|
|
155
|
+
if (item.trim()) items.push(item.trim())
|
|
156
|
+
return items
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// swiftpm names a package by its explicit `name:`, else its url's last path
|
|
160
|
+
// component without `.git`; `.product(package:)` may use either spelling.
|
|
161
|
+
export function swiftPackageIdentity(url: string): string {
|
|
162
|
+
return (url.split('/').pop() ?? url).replace(/\.git$/, '').toLowerCase()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** the products, target dependencies and package urls a manifest declares. */
|
|
166
|
+
export function swiftManifestGraph(manifest: string): SwiftManifestGraph {
|
|
167
|
+
const graph: SwiftManifestGraph = {
|
|
168
|
+
products: new Map(),
|
|
169
|
+
dependencies: new Map(),
|
|
170
|
+
binaryTargets: new Set(),
|
|
171
|
+
systemLibraries: new Set(),
|
|
172
|
+
packageURLs: new Map(),
|
|
173
|
+
packagePaths: [],
|
|
174
|
+
}
|
|
175
|
+
for (const { kind, flat, call } of manifestCalls(manifest, [
|
|
176
|
+
'library',
|
|
177
|
+
'executableTarget',
|
|
178
|
+
'target',
|
|
179
|
+
'binaryTarget',
|
|
180
|
+
'systemLibrary',
|
|
181
|
+
'package',
|
|
182
|
+
])) {
|
|
183
|
+
if (kind === 'package') {
|
|
184
|
+
const local = /\bpath\s*:\s*"([^"]+)"/.exec(flat)?.[1]
|
|
185
|
+
if (local) graph.packagePaths.push(local)
|
|
186
|
+
const url = /\burl\s*:\s*"([^"]+)"/.exec(flat)?.[1]
|
|
187
|
+
if (!url) continue
|
|
188
|
+
graph.packageURLs.set(swiftPackageIdentity(url), url)
|
|
189
|
+
const name = NAME.exec(flat)?.[1]
|
|
190
|
+
if (name) graph.packageURLs.set(name.toLowerCase(), url)
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
const name = NAME.exec(flat)?.[1]
|
|
194
|
+
if (!name) continue
|
|
195
|
+
if (kind === 'library') {
|
|
196
|
+
graph.products.set(
|
|
197
|
+
name,
|
|
198
|
+
listArgument(call, 'targets').flatMap(
|
|
199
|
+
(item) => /^"([^"]+)"$/.exec(item)?.[1] ?? [],
|
|
200
|
+
),
|
|
201
|
+
)
|
|
202
|
+
continue
|
|
203
|
+
}
|
|
204
|
+
if (kind === 'binaryTarget') graph.binaryTargets.add(name)
|
|
205
|
+
if (kind === 'systemLibrary') graph.systemLibraries.add(name)
|
|
206
|
+
const dependencies: SwiftTargetDependency[] = []
|
|
207
|
+
for (const item of listArgument(call, 'dependencies')) {
|
|
208
|
+
// a dependency conditioned to other platforms never links on iOS
|
|
209
|
+
const platforms = /condition\s*:\s*\.when\(\s*platforms\s*:\s*\[([^\]]*)\]/.exec(
|
|
210
|
+
item,
|
|
211
|
+
)?.[1]
|
|
212
|
+
if (platforms !== undefined && !/\.iOS\b/.test(platforms)) continue
|
|
213
|
+
// a trait-gated dependency is opt-in; default traits are swift code a
|
|
214
|
+
// scanner cannot evaluate, and the gated ones are optional backends
|
|
215
|
+
if (/condition\s*:\s*\.when\([^)]*\btraits\s*:/.test(item)) continue
|
|
216
|
+
const plain = /^"([^"]+)"$/.exec(item)?.[1]
|
|
217
|
+
const product =
|
|
218
|
+
/^\.product(?:Item)?\(\s*name\s*:\s*"([^"]+)"\s*,\s*package\s*:\s*"([^"]+)"/.exec(
|
|
219
|
+
item,
|
|
220
|
+
)
|
|
221
|
+
const target = /^\.(?:target|byName)(?:Item)?\(\s*name\s*:\s*"([^"]+)"/.exec(
|
|
222
|
+
item,
|
|
223
|
+
)?.[1]
|
|
224
|
+
if (plain) dependencies.push({ kind: 'target', name: plain })
|
|
225
|
+
else if (product)
|
|
226
|
+
dependencies.push({
|
|
227
|
+
kind: 'product',
|
|
228
|
+
name: product[1]!,
|
|
229
|
+
package: product[2]!.toLowerCase(),
|
|
230
|
+
})
|
|
231
|
+
else if (target) dependencies.push({ kind: 'target', name: target })
|
|
232
|
+
}
|
|
233
|
+
graph.dependencies.set(name, dependencies)
|
|
234
|
+
}
|
|
235
|
+
// a bare name that is no target here is swiftpm's by-name product: the
|
|
236
|
+
// product of that name in the dependency package of the same name
|
|
237
|
+
for (const dependencies of graph.dependencies.values()) {
|
|
238
|
+
for (const [index, dependency] of dependencies.entries()) {
|
|
239
|
+
if (dependency.kind === 'target' && !graph.dependencies.has(dependency.name))
|
|
240
|
+
dependencies[index] = {
|
|
241
|
+
kind: 'product',
|
|
242
|
+
name: dependency.name,
|
|
243
|
+
package: dependency.name.toLowerCase(),
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return graph
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* the library and executable targets a sent root manifest declares, in order.
|
|
252
|
+
*
|
|
253
|
+
* A manifest is Swift code, not data, so this is a scanner, not a parser:
|
|
254
|
+
* each `.target(` / `.executableTarget(` call is matched to its balanced
|
|
255
|
+
* close paren (string-aware, so a paren inside a literal cannot end it
|
|
256
|
+
* early), and `name:` / `path:` are read from the call's own depth only, so
|
|
257
|
+
* a nested `.product(name: "SwiftUI", ...)` inside dependencies never wins.
|
|
258
|
+
*/
|
|
259
|
+
export function swiftManifestTargets(
|
|
260
|
+
manifest: string,
|
|
261
|
+
resourcePaths: readonly string[] = [],
|
|
262
|
+
): SwiftPackageTarget[] {
|
|
263
|
+
const implicitResources = swiftImplicitResourcePaths(resourcePaths)
|
|
264
|
+
const targets: SwiftPackageTarget[] = []
|
|
265
|
+
for (const { kind, flat, call } of manifestCalls(manifest, [
|
|
266
|
+
'executableTarget',
|
|
267
|
+
'target',
|
|
268
|
+
])) {
|
|
269
|
+
const executable = kind === 'executableTarget'
|
|
84
270
|
const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1]
|
|
85
271
|
if (!name) continue
|
|
86
272
|
const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1]
|
|
@@ -90,7 +276,6 @@ export function swiftManifestTargets(
|
|
|
90
276
|
: rawPath.replace(/^\.\//, '').replace(/\/+$/, '')
|
|
91
277
|
// settings sit inside nested calls, which `flat` drops, so they are read
|
|
92
278
|
// from the call's whole text; a dependency list cannot spell either one.
|
|
93
|
-
const call = code.slice(start, i)
|
|
94
279
|
const languageMode = Number(
|
|
95
280
|
/\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? '5',
|
|
96
281
|
)
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// the remote swift packages an app links, compiled from source: each package
|
|
2
|
+
// is fetched at the revision the project's Package.resolved pins, into the
|
|
3
|
+
// project's .build/peach/checkouts, and each linked product resolves to the
|
|
4
|
+
// source targets that build it. peach compiles swift source only, so a
|
|
5
|
+
// product reaching a binary or c-family target stays missing, with the reason.
|
|
6
|
+
|
|
7
|
+
import { execFileSync } from 'node:child_process'
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import {
|
|
11
|
+
swiftManifestGraph,
|
|
12
|
+
swiftManifestTargets,
|
|
13
|
+
swiftPackageIdentity,
|
|
14
|
+
type SwiftManifestGraph,
|
|
15
|
+
type SwiftPackageTarget,
|
|
16
|
+
} from './swift-package'
|
|
17
|
+
|
|
18
|
+
export interface RemoteProduct {
|
|
19
|
+
product: string
|
|
20
|
+
repositoryURL: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** a source target from a remote checkout, its path absolute. */
|
|
24
|
+
export interface RemotePackageTarget extends SwiftPackageTarget {
|
|
25
|
+
dir: string
|
|
26
|
+
/** every file under the target directory. */
|
|
27
|
+
files: string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RemotePackages {
|
|
31
|
+
targets: RemotePackageTarget[]
|
|
32
|
+
/** linked products peach cannot compile, with why. */
|
|
33
|
+
unavailable: Map<string, { repositoryURL: string; reason: string }>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** where checkouts live, relative to the project directory. */
|
|
37
|
+
export const REMOTE_CHECKOUTS = path.join('.build', 'peach', 'checkouts')
|
|
38
|
+
|
|
39
|
+
interface Pin {
|
|
40
|
+
location: string
|
|
41
|
+
revision: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// sources the swift compile cannot build: c, c++, objective-c and assembly.
|
|
45
|
+
const C_FAMILY = /\.(c|cc|cpp|cxx|m|mm|s|S)$/
|
|
46
|
+
|
|
47
|
+
function readPins(resolved: string): Map<string, Pin> {
|
|
48
|
+
const data: unknown = JSON.parse(fs.readFileSync(resolved, 'utf8'))
|
|
49
|
+
const pins =
|
|
50
|
+
data && typeof data === 'object' && 'pins' in data && Array.isArray(data.pins)
|
|
51
|
+
? data.pins
|
|
52
|
+
: null
|
|
53
|
+
if (!pins)
|
|
54
|
+
throw new Error(`${resolved} has no pins; resolve packages in a current Xcode`)
|
|
55
|
+
const out = new Map<string, Pin>()
|
|
56
|
+
for (const pin of pins) {
|
|
57
|
+
const identity = pin?.identity
|
|
58
|
+
const location = pin?.location
|
|
59
|
+
const revision = pin?.state?.revision
|
|
60
|
+
if (
|
|
61
|
+
typeof identity === 'string' &&
|
|
62
|
+
typeof location === 'string' &&
|
|
63
|
+
typeof revision === 'string'
|
|
64
|
+
)
|
|
65
|
+
out.set(identity, { location, revision })
|
|
66
|
+
}
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function walk(dir: string): string[] {
|
|
71
|
+
if (!fs.existsSync(dir)) return []
|
|
72
|
+
const out: string[] = []
|
|
73
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
74
|
+
if (entry.name.startsWith('.')) continue
|
|
75
|
+
const full = path.join(dir, entry.name)
|
|
76
|
+
if (entry.isDirectory()) out.push(...walk(full))
|
|
77
|
+
else if (entry.isFile()) out.push(full)
|
|
78
|
+
}
|
|
79
|
+
return out.sort()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const verified = new Set<string>()
|
|
83
|
+
|
|
84
|
+
// a shallow checkout of exactly the pinned revision, reused while HEAD is it.
|
|
85
|
+
function checkout(checkouts: string, identity: string, pin: Pin): string {
|
|
86
|
+
const dir = path.join(checkouts, identity)
|
|
87
|
+
const key = `${dir}\0${pin.revision}`
|
|
88
|
+
if (verified.has(key)) return dir
|
|
89
|
+
const git = (...args: string[]) =>
|
|
90
|
+
execFileSync('git', ['-C', dir, ...args], {
|
|
91
|
+
encoding: 'utf8',
|
|
92
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
93
|
+
}).trim()
|
|
94
|
+
const current = fs.existsSync(path.join(dir, '.git')) ? git('rev-parse', 'HEAD') : ''
|
|
95
|
+
if (current !== pin.revision) {
|
|
96
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
97
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
98
|
+
try {
|
|
99
|
+
git('init', '-q')
|
|
100
|
+
git('fetch', '-q', '--depth', '1', pin.location, pin.revision)
|
|
101
|
+
git('checkout', '-q', 'FETCH_HEAD')
|
|
102
|
+
} catch (error) {
|
|
103
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
104
|
+
const stderr =
|
|
105
|
+
error instanceof Error && 'stderr' in error ? String(error.stderr).trim() : ''
|
|
106
|
+
throw new Error(
|
|
107
|
+
`could not fetch ${pin.location} at ${pin.revision}${stderr ? `: ${stderr}` : ''}`,
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
verified.add(key)
|
|
112
|
+
return dir
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* fetches and resolves `products` against the pins in `resolved`. products
|
|
117
|
+
* named in `provided` are peach modules and link as those instead.
|
|
118
|
+
*/
|
|
119
|
+
export function resolveRemotePackages(
|
|
120
|
+
projectDir: string,
|
|
121
|
+
resolved: string | null,
|
|
122
|
+
products: readonly RemoteProduct[],
|
|
123
|
+
provided: ReadonlySet<string>,
|
|
124
|
+
): RemotePackages {
|
|
125
|
+
const result: RemotePackages = { targets: [], unavailable: new Map() }
|
|
126
|
+
const wanted = products.filter((entry) => !provided.has(entry.product))
|
|
127
|
+
if (wanted.length === 0) return result
|
|
128
|
+
if (!resolved) {
|
|
129
|
+
for (const entry of wanted)
|
|
130
|
+
result.unavailable.set(entry.product, {
|
|
131
|
+
repositoryURL: entry.repositoryURL,
|
|
132
|
+
reason: 'no Package.resolved pins it; resolve packages in Xcode once',
|
|
133
|
+
})
|
|
134
|
+
return result
|
|
135
|
+
}
|
|
136
|
+
const pins = readPins(resolved)
|
|
137
|
+
const checkouts = path.join(projectDir, REMOTE_CHECKOUTS)
|
|
138
|
+
fs.mkdirSync(checkouts, { recursive: true })
|
|
139
|
+
// fetched sources never show up as changes in the app's repository
|
|
140
|
+
fs.writeFileSync(path.join(path.dirname(checkouts), '.gitignore'), '*\n')
|
|
141
|
+
|
|
142
|
+
const packages = new Map<
|
|
143
|
+
string,
|
|
144
|
+
{ dir: string; manifest: string; graph: SwiftManifestGraph }
|
|
145
|
+
>()
|
|
146
|
+
const load = (identity: string) => {
|
|
147
|
+
const cached = packages.get(identity)
|
|
148
|
+
if (cached) return cached
|
|
149
|
+
const pin = pins.get(identity)
|
|
150
|
+
if (!pin) return null
|
|
151
|
+
const dir = checkout(checkouts, identity, pin)
|
|
152
|
+
const manifest = fs.readFileSync(path.join(dir, 'Package.swift'), 'utf8')
|
|
153
|
+
const loaded = { dir, manifest, graph: swiftManifestGraph(manifest) }
|
|
154
|
+
packages.set(identity, loaded)
|
|
155
|
+
return loaded
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const targets = new Map<string, RemotePackageTarget>()
|
|
159
|
+
// product key to the reason it cannot compile, or null once it can
|
|
160
|
+
const outcomes = new Map<string, string | null>()
|
|
161
|
+
const resolveProduct = (identity: string, product: string): string | null => {
|
|
162
|
+
const key = `${identity}\0${product}`
|
|
163
|
+
if (outcomes.has(key)) return outcomes.get(key)!
|
|
164
|
+
outcomes.set(key, null)
|
|
165
|
+
const pkg = load(identity)
|
|
166
|
+
if (!pkg) {
|
|
167
|
+
outcomes.set(key, `package ${identity} is not pinned in Package.resolved`)
|
|
168
|
+
return outcomes.get(key)!
|
|
169
|
+
}
|
|
170
|
+
const roots = pkg.graph.products.get(product)
|
|
171
|
+
if (!roots) {
|
|
172
|
+
outcomes.set(key, `package ${identity} has no library ${product}`)
|
|
173
|
+
return outcomes.get(key)!
|
|
174
|
+
}
|
|
175
|
+
const declared = new Map(
|
|
176
|
+
swiftManifestTargets(pkg.manifest).map((target) => [target.name, target]),
|
|
177
|
+
)
|
|
178
|
+
const reached: SwiftPackageTarget[] = []
|
|
179
|
+
const seen = new Set<string>()
|
|
180
|
+
const pending = [...roots]
|
|
181
|
+
let reason: string | null = null
|
|
182
|
+
while (pending.length > 0 && !reason) {
|
|
183
|
+
const name = pending.pop()!
|
|
184
|
+
if (seen.has(name) || provided.has(name)) continue
|
|
185
|
+
seen.add(name)
|
|
186
|
+
if (pkg.graph.binaryTargets.has(name)) {
|
|
187
|
+
reason = `${name} is a binary framework`
|
|
188
|
+
break
|
|
189
|
+
}
|
|
190
|
+
if (pkg.graph.systemLibraries.has(name)) {
|
|
191
|
+
reason = `${name} is a system C library`
|
|
192
|
+
break
|
|
193
|
+
}
|
|
194
|
+
const target = declared.get(name)
|
|
195
|
+
if (!target) {
|
|
196
|
+
reason = `${identity} declares no target ${name}`
|
|
197
|
+
break
|
|
198
|
+
}
|
|
199
|
+
const files = walk(path.join(pkg.dir, target.path))
|
|
200
|
+
if (files.some((file) => C_FAMILY.test(file))) {
|
|
201
|
+
reason = `${name} is a C or Objective-C target`
|
|
202
|
+
break
|
|
203
|
+
}
|
|
204
|
+
reached.push(target)
|
|
205
|
+
for (const dependency of pkg.graph.dependencies.get(name) ?? []) {
|
|
206
|
+
if (dependency.kind === 'target') pending.push(dependency.name)
|
|
207
|
+
else if (!provided.has(dependency.name)) {
|
|
208
|
+
const url = pkg.graph.packageURLs.get(dependency.package)
|
|
209
|
+
const nested = resolveProduct(
|
|
210
|
+
url ? swiftPackageIdentity(url) : dependency.package,
|
|
211
|
+
dependency.name,
|
|
212
|
+
)
|
|
213
|
+
if (nested) reason = `${dependency.name}: ${nested}`
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (reason) {
|
|
218
|
+
outcomes.set(key, reason)
|
|
219
|
+
return reason
|
|
220
|
+
}
|
|
221
|
+
// resources need the files each target holds, relative to its package
|
|
222
|
+
const relative = reached.flatMap((target) =>
|
|
223
|
+
walk(path.join(pkg.dir, target.path)).map((file) =>
|
|
224
|
+
path.relative(pkg.dir, file).split(path.sep).join(path.posix.sep),
|
|
225
|
+
),
|
|
226
|
+
)
|
|
227
|
+
const withResources = new Map(
|
|
228
|
+
swiftManifestTargets(pkg.manifest, relative).map((target) => [target.name, target]),
|
|
229
|
+
)
|
|
230
|
+
for (const target of reached) {
|
|
231
|
+
const dir = path.join(pkg.dir, target.path)
|
|
232
|
+
targets.set(target.name, {
|
|
233
|
+
...(withResources.get(target.name) ?? target),
|
|
234
|
+
executable: false,
|
|
235
|
+
dir,
|
|
236
|
+
files: walk(dir),
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
return null
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
for (const entry of wanted) {
|
|
243
|
+
const reason = resolveProduct(
|
|
244
|
+
swiftPackageIdentity(entry.repositoryURL),
|
|
245
|
+
entry.product,
|
|
246
|
+
)
|
|
247
|
+
if (reason)
|
|
248
|
+
result.unavailable.set(entry.product, {
|
|
249
|
+
repositoryURL: entry.repositoryURL,
|
|
250
|
+
reason,
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
result.targets = [...targets.values()]
|
|
254
|
+
return result
|
|
255
|
+
}
|
package/src/swift-submit.ts
CHANGED
|
@@ -68,8 +68,11 @@ export const MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024
|
|
|
68
68
|
* 19: synchronous UIImage/ImageIO bitmap decode, frame sources and context drawing.
|
|
69
69
|
* 20: peach_codec provides synchronous streaming Brotli and zlib decoders.
|
|
70
70
|
* 21: the system environment supplies UIKitCore's semantic color components.
|
|
71
|
+
* 22: WebKit script messages carry request ids and receive Promise replies.
|
|
72
|
+
* 23: URLSessionWebSocketTask uses the networking host for real WebSocket transport.
|
|
73
|
+
* 24: WebKit cookie stores share native jars with isolated store lifetimes.
|
|
71
74
|
*/
|
|
72
|
-
export const SWIFT_HOST_ABI =
|
|
75
|
+
export const SWIFT_HOST_ABI = 24
|
|
73
76
|
|
|
74
77
|
export interface SwiftImageUpload {
|
|
75
78
|
/** the raster file picked for the asset (has the extension). */
|
package/src/vite-plugin-one.ts
CHANGED
|
@@ -10,7 +10,6 @@ import fs from 'fs'
|
|
|
10
10
|
import { randomUUID } from 'node:crypto'
|
|
11
11
|
import { createRequire } from 'node:module'
|
|
12
12
|
import path from 'path'
|
|
13
|
-
import { swiftPackageDirectories } from 'vxrn'
|
|
14
13
|
import { WebSocket, WebSocketServer } from 'ws'
|
|
15
14
|
import { DEFAULT_SOOTSIM_BRIDGE_PORT } from './bridge-constants'
|
|
16
15
|
import {
|
|
@@ -62,8 +61,9 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
62
61
|
return { optimizeDeps: { include: ['use-latest-callback'] } }
|
|
63
62
|
},
|
|
64
63
|
|
|
65
|
-
configureServer(server) {
|
|
64
|
+
async configureServer(server) {
|
|
66
65
|
if (options.enabled === false) return
|
|
66
|
+
const { swiftPackageDirectories } = await import('vxrn')
|
|
67
67
|
let swiftPackages: Map<string, string> | undefined
|
|
68
68
|
// the workspace SwiftUI module beside peachsim compiles locally; an
|
|
69
69
|
// npm install has none (null), and its packages compile on Contrast.
|
package/src/vite-plugin.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { createRequire } from 'module'
|
|
|
14
14
|
import { runInNewContext, Script } from 'node:vm'
|
|
15
15
|
import path from 'path'
|
|
16
16
|
import { fileURLToPath, pathToFileURL } from 'url'
|
|
17
|
+
import { minify } from 'terser'
|
|
17
18
|
import { type Plugin, transformWithOxc } from 'vite'
|
|
18
19
|
|
|
19
20
|
declare module '@babel/core' {
|
|
@@ -465,8 +466,9 @@ export function engineShellWorkerPlugins(): Plugin[] {
|
|
|
465
466
|
]
|
|
466
467
|
}
|
|
467
468
|
|
|
468
|
-
// admitted coverage repeats prefixes across entries
|
|
469
|
-
// while each consumer still receives
|
|
469
|
+
// admitted coverage repeats prefixes across entries, and entries repeat the same
|
|
470
|
+
// image records; share their emitted bytes while each consumer still receives
|
|
471
|
+
// its own unchanged array and record.
|
|
470
472
|
function warmManifestJsonPlugin(): Plugin {
|
|
471
473
|
const marker = '\0peach:warm-manifest:'
|
|
472
474
|
return {
|
|
@@ -482,12 +484,20 @@ function warmManifestJsonPlugin(): Plugin {
|
|
|
482
484
|
this.addWatchFile(filename)
|
|
483
485
|
const value: unknown = JSON.parse(fs.readFileSync(filename, 'utf8'))
|
|
484
486
|
const manifest = readPeachWarmManifest(value)
|
|
485
|
-
const
|
|
486
|
-
for (const entry of [
|
|
487
|
+
const entries = [
|
|
487
488
|
manifest.home,
|
|
488
489
|
...Object.values(manifest.launches),
|
|
489
490
|
...Object.values(manifest.screens),
|
|
490
|
-
]
|
|
491
|
+
]
|
|
492
|
+
const imageCounts = new Map<string, number>()
|
|
493
|
+
for (const image of entries.flatMap((entry) => entry.images)) {
|
|
494
|
+
const key = JSON.stringify(image)
|
|
495
|
+
imageCounts.set(key, (imageCounts.get(key) ?? 0) + 1)
|
|
496
|
+
}
|
|
497
|
+
const sharedImages = [...imageCounts].filter(([, count]) => count > 1)
|
|
498
|
+
const sharedImageIndex = new Map(sharedImages.map(([key], index) => [key, index]))
|
|
499
|
+
const prefixes = new Map<string, { values: number[]; count: number }>()
|
|
500
|
+
for (const entry of entries) {
|
|
491
501
|
for (let length = 1; length <= entry.pipelines.length; length++) {
|
|
492
502
|
const values = entry.pipelines.slice(0, length)
|
|
493
503
|
const key = JSON.stringify(values)
|
|
@@ -515,6 +525,8 @@ function warmManifestJsonPlugin(): Plugin {
|
|
|
515
525
|
return '[' + item.map(serialize).join(',') + ']'
|
|
516
526
|
}
|
|
517
527
|
if (isRecord(item)) {
|
|
528
|
+
const image = sharedImageIndex.get(JSON.stringify(item))
|
|
529
|
+
if (image !== undefined) return `{...images[${image}]}`
|
|
518
530
|
return (
|
|
519
531
|
'{' +
|
|
520
532
|
Object.entries(item)
|
|
@@ -532,7 +544,7 @@ function warmManifestJsonPlugin(): Plugin {
|
|
|
532
544
|
}
|
|
533
545
|
return JSON.stringify(item)
|
|
534
546
|
}
|
|
535
|
-
const code = `const shared=${JSON.stringify(shared)};const manifest=${serialize(value)};`
|
|
547
|
+
const code = `const shared=${JSON.stringify(shared)};const images=[${sharedImages.map(([key]) => key).join(',')}];const manifest=${serialize(value)};`
|
|
536
548
|
const reconstructed: unknown = runInNewContext(
|
|
537
549
|
code + 'manifest',
|
|
538
550
|
Object.create(null),
|
|
@@ -637,10 +649,18 @@ export function workerBootChunkPlugin(closures: WorkerBootClosure[]): Plugin {
|
|
|
637
649
|
if (!isWorker) return null
|
|
638
650
|
// vite introduces relative child-worker urls during rendering. resolve
|
|
639
651
|
// their module base after that pass, using syntax-aware replacement.
|
|
640
|
-
|
|
652
|
+
const transformed = await transformWithOxc(code, chunk.fileName, {
|
|
641
653
|
define: { 'import.meta.url': 'globalThis.location.href' },
|
|
642
654
|
sourcemap: true,
|
|
643
655
|
})
|
|
656
|
+
const compact = await minify(transformed.code, {
|
|
657
|
+
module: true,
|
|
658
|
+
compress: { passes: 2 },
|
|
659
|
+
mangle: true,
|
|
660
|
+
sourceMap: { content: transformed.map, asObject: true },
|
|
661
|
+
})
|
|
662
|
+
if (!compact.code) this.error('worker minification produced no code')
|
|
663
|
+
return { code: compact.code, map: compact.map }
|
|
644
664
|
},
|
|
645
665
|
},
|
|
646
666
|
generateBundle(_options, bundle) {
|
|
@@ -1192,7 +1212,7 @@ function sootsimConfigPlugin(
|
|
|
1192
1212
|
): Plugin {
|
|
1193
1213
|
return {
|
|
1194
1214
|
name: 'sootsim-config',
|
|
1195
|
-
config(
|
|
1215
|
+
config() {
|
|
1196
1216
|
const fsAllow = ['.']
|
|
1197
1217
|
for (const src of extraSources) fsAllow.push(src)
|
|
1198
1218
|
if (appDir) {
|
|
@@ -1258,7 +1278,7 @@ function sootsimConfigPlugin(
|
|
|
1258
1278
|
|
|
1259
1279
|
return {
|
|
1260
1280
|
define: {
|
|
1261
|
-
'process.env.NODE_ENV': JSON.stringify(
|
|
1281
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
1262
1282
|
'process.env.TEST_NATIVE_PLATFORM': JSON.stringify(''),
|
|
1263
1283
|
'process.env.TAMAGUI_TARGET': JSON.stringify('native'),
|
|
1264
1284
|
// expo sdk 57's winter runtime (expo/src/winter/runtime.native.ts)
|