peachsim 0.1.793 → 0.1.795
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/app-config.ts +3 -7
- package/dist-lib/agent-daemon-client.cjs +2 -2
- package/dist-lib/agent-events.cjs +2 -2
- package/dist-lib/agent-identity.cjs +2 -2
- package/dist-lib/agent-sessions.cjs +2 -2
- package/dist-lib/attached-projects.cjs +2 -2
- package/dist-lib/auth/shared-session.cjs +2 -2
- package/dist-lib/backend-origin.cjs +2 -2
- package/dist-lib/beta.cjs +2 -2
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +2 -2
- package/dist-lib/bridge-contract-input.cjs +2 -2
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +2 -2
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +9077 -0
- package/dist-lib/capture-contract.cjs +2 -2
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +2 -2
- package/dist-lib/cloud-contract.cjs +2 -2
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +2 -2
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -2
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +2 -2
- package/dist-lib/detox/index.cjs +2 -2
- package/dist-lib/dev-bundle-resolution.cjs +2 -2
- package/dist-lib/expo-swift-bundle.cjs +8425 -0
- package/dist-lib/expo-swift-metadata.cjs +91 -0
- package/dist-lib/expo-swift-metadata.mjs +63 -0
- package/dist-lib/home-paths.cjs +2 -2
- package/dist-lib/host/bridge-host.cjs +244 -130
- package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
- package/dist-lib/host/fetch-proxy-overrides.cjs +2 -2
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +2 -2
- package/dist-lib/host/websocket-proxy.cjs +2 -2
- package/dist-lib/index.cjs +110 -12
- package/dist-lib/jump-to-source-babel.cjs +2 -2
- package/dist-lib/jump-to-source-native.cjs +2 -2
- package/dist-lib/kotlin-host.cjs +2 -2
- package/dist-lib/menu.cjs +2 -2
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +2 -2
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +2 -2
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +110 -12
- package/dist-lib/native-app-identity.cjs +2 -2
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +2 -2
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +2 -2
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +2 -2
- package/dist-lib/public-brand.cjs +2 -2
- package/dist-lib/react-native-host-modules.cjs +2 -2
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +2 -2
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +2 -2
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +355 -165
- package/dist-lib/swift-compile.cjs +105 -5
- package/dist-lib/swift-compile.mjs +101 -2
- package/dist-lib/swift-package.cjs +2 -2
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +2 -2
- package/dist-lib/swift.cjs +2 -2
- package/dist-lib/vite-swift.cjs +64 -8
- package/dist-lib/vite.cjs +2 -2
- package/package.json +18 -2
- package/src/bundle-channel.mjs +251 -0
- package/src/expo-swift-bundle.ts +32 -0
- package/src/expo-swift-host.ts +161 -128
- package/src/expoSwiftContract.ts +88 -0
- package/src/swift-compile.ts +111 -1
- package/src/swift-host.ts +4 -1
package/src/expoSwiftContract.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface ExpoSwiftSourceUnit {
|
|
2
2
|
namespace: string
|
|
3
|
+
moduleId: string
|
|
3
4
|
classes: string[]
|
|
4
5
|
files: Record<string, string>
|
|
5
6
|
}
|
|
@@ -17,3 +18,90 @@ export interface ExpoSwiftCompilationResult {
|
|
|
17
18
|
modules: ExpoSwiftCompiledModule[]
|
|
18
19
|
failures: { namespace: string; diagnostic: string }[]
|
|
19
20
|
}
|
|
21
|
+
|
|
22
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
23
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
24
|
+
}
|
|
25
|
+
function strings(value: unknown): value is string[] {
|
|
26
|
+
return Array.isArray(value) && value.every((item) => typeof item === 'string')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function isExpoSwiftCompilationResult(
|
|
30
|
+
value: unknown,
|
|
31
|
+
): value is ExpoSwiftCompilationResult {
|
|
32
|
+
if (
|
|
33
|
+
!record(value) ||
|
|
34
|
+
!strings(value.namespaces) ||
|
|
35
|
+
!Array.isArray(value.modules) ||
|
|
36
|
+
value.modules.length > 1 ||
|
|
37
|
+
!Array.isArray(value.failures)
|
|
38
|
+
)
|
|
39
|
+
return false
|
|
40
|
+
const remaining = new Set(value.namespaces)
|
|
41
|
+
if (remaining.size !== value.namespaces.length) return false
|
|
42
|
+
for (const artifact of value.modules) {
|
|
43
|
+
if (
|
|
44
|
+
!record(artifact) ||
|
|
45
|
+
!strings(artifact.namespaces) ||
|
|
46
|
+
artifact.namespaces.length === 0 ||
|
|
47
|
+
!artifact.namespaces.every((namespace) => remaining.delete(namespace)) ||
|
|
48
|
+
typeof artifact.url !== 'string' ||
|
|
49
|
+
typeof artifact.hash !== 'string' ||
|
|
50
|
+
typeof artifact.icuUrl !== 'string' ||
|
|
51
|
+
typeof artifact.rootId !== 'string'
|
|
52
|
+
)
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
|
+
for (const failure of value.failures) {
|
|
56
|
+
if (
|
|
57
|
+
!record(failure) ||
|
|
58
|
+
typeof failure.namespace !== 'string' ||
|
|
59
|
+
!remaining.delete(failure.namespace) ||
|
|
60
|
+
typeof failure.diagnostic !== 'string'
|
|
61
|
+
)
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
return remaining.size === 0
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const FOOTER_PREFIX = 'globalThis.__peachExpoSwift='
|
|
68
|
+
|
|
69
|
+
export function readExpoSwiftMetadata(value: unknown): ExpoSwiftCompilationResult | null {
|
|
70
|
+
if (value === null || value === undefined) return null
|
|
71
|
+
if (!isExpoSwiftCompilationResult(value))
|
|
72
|
+
throw new Error('invalid Expo Swift compilation metadata')
|
|
73
|
+
return value
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function readExpoSwiftFooter(source: string): ExpoSwiftCompilationResult | null {
|
|
77
|
+
const start = source.lastIndexOf(`\n${FOOTER_PREFIX}`)
|
|
78
|
+
if (start < 0) return null
|
|
79
|
+
const end = source.indexOf('\n', start + 1)
|
|
80
|
+
const line = source.slice(start + 1, end < 0 ? undefined : end)
|
|
81
|
+
if (!line.endsWith(';')) throw new Error('Expo Swift footer is truncated')
|
|
82
|
+
const metadata = readExpoSwiftMetadata(JSON.parse(line.slice(FOOTER_PREFIX.length, -1)))
|
|
83
|
+
if (!metadata) throw new Error('Expo Swift footer has no metadata')
|
|
84
|
+
return metadata
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function insertExpoSwiftFooter(
|
|
88
|
+
source: string,
|
|
89
|
+
metadata: ExpoSwiftCompilationResult,
|
|
90
|
+
): string {
|
|
91
|
+
readExpoSwiftMetadata(metadata)
|
|
92
|
+
const start = source.lastIndexOf(`\n${FOOTER_PREFIX}`)
|
|
93
|
+
if (start >= 0) {
|
|
94
|
+
readExpoSwiftFooter(source)
|
|
95
|
+
const end = source.indexOf('\n', start + 1)
|
|
96
|
+
source = source.slice(0, start) + (end < 0 ? '' : source.slice(end))
|
|
97
|
+
}
|
|
98
|
+
const json = JSON.stringify(metadata)
|
|
99
|
+
.replace(/\u2028/g, '\\u2028')
|
|
100
|
+
.replace(/\u2029/g, '\\u2029')
|
|
101
|
+
.replace(/<\//g, '<\\/')
|
|
102
|
+
const footer = `\n${FOOTER_PREFIX}${json};`
|
|
103
|
+
const identity = source.lastIndexOf('\nglobalThis.__sootsimModulePaths=')
|
|
104
|
+
return identity < 0
|
|
105
|
+
? source + footer
|
|
106
|
+
: source.slice(0, identity) + footer + source.slice(identity)
|
|
107
|
+
}
|
package/src/swift-compile.ts
CHANGED
|
@@ -1350,6 +1350,63 @@ export function lowerNSValueTimeBox(source: string): string {
|
|
|
1350
1350
|
return out
|
|
1351
1351
|
}
|
|
1352
1352
|
|
|
1353
|
+
// the notification delegate is an Objective-C optional protocol on Apple.
|
|
1354
|
+
// preserve its selectors and expose conforming methods through PeachObjC;
|
|
1355
|
+
// optional Void calls use the protocol's absent-method defaults on WASI.
|
|
1356
|
+
export function lowerNotificationDelegate(source: string): string {
|
|
1357
|
+
const code = swiftCodeMask(source)
|
|
1358
|
+
const selectors: Record<string, string> = {
|
|
1359
|
+
willPresent: 'userNotificationCenter:willPresentNotification:withCompletionHandler:',
|
|
1360
|
+
didReceive:
|
|
1361
|
+
'userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:',
|
|
1362
|
+
openSettingsFor: 'userNotificationCenter:openSettingsForNotification:',
|
|
1363
|
+
}
|
|
1364
|
+
const edits: [number, number, string][] = []
|
|
1365
|
+
const selector =
|
|
1366
|
+
/#(?:selector|Selector)\(\s*UNUserNotificationCenterDelegate\.userNotificationCenter\(\s*_\s*:\s*(willPresent|didReceive|openSettingsFor)\s*:[^)]*\)\s*\)/g
|
|
1367
|
+
for (const match of code.matchAll(selector)) {
|
|
1368
|
+
edits.push([
|
|
1369
|
+
match.index,
|
|
1370
|
+
match[0].length,
|
|
1371
|
+
`NSSelectorFromString(${JSON.stringify(selectors[match[1]!])})`,
|
|
1372
|
+
])
|
|
1373
|
+
}
|
|
1374
|
+
const receivers = new Set<string>()
|
|
1375
|
+
for (const match of code.matchAll(
|
|
1376
|
+
/\b(?:var|let)\s+(\w+)\s*:\s*(?:any\s+)?UNUserNotificationCenterDelegate\??/g,
|
|
1377
|
+
))
|
|
1378
|
+
receivers.add(match[1]!)
|
|
1379
|
+
for (const match of code.matchAll(/\blet\s+(\w+)\s*=\s*(?:self\.)?(\w+)\b/g)) {
|
|
1380
|
+
if (receivers.has(match[2]!)) receivers.add(match[1]!)
|
|
1381
|
+
}
|
|
1382
|
+
for (const match of code.matchAll(
|
|
1383
|
+
/\b(\w+)(?:[?!])?\.userNotificationCenter\s*\?(?=\s*\()/g,
|
|
1384
|
+
)) {
|
|
1385
|
+
if (receivers.has(match[1]!))
|
|
1386
|
+
edits.push([match.index + match[0].lastIndexOf('?'), 1, ' '])
|
|
1387
|
+
}
|
|
1388
|
+
const braces = [...code.matchAll(/[{}]/g)].map((match) => match.index)
|
|
1389
|
+
for (const owner of code.matchAll(
|
|
1390
|
+
/\b(?:class|extension)\s+[A-Za-z_]\w*[^{}]*\bUNUserNotificationCenterDelegate\b[^{}]*\{/g,
|
|
1391
|
+
)) {
|
|
1392
|
+
const open = owner.index + owner[0].length - 1
|
|
1393
|
+
const close = closingBrace(code, braces, open)
|
|
1394
|
+
const body = code.slice(open + 1, close - 1)
|
|
1395
|
+
for (const method of body.matchAll(/\bfunc\s+userNotificationCenter\s*\(/g)) {
|
|
1396
|
+
const at = open + 1 + method.index
|
|
1397
|
+
const signature = code.slice(at, code.indexOf('{', at))
|
|
1398
|
+
const label = Object.keys(selectors).find((name) =>
|
|
1399
|
+
new RegExp(`\\b${name}\\b`).test(signature),
|
|
1400
|
+
)
|
|
1401
|
+
if (label) edits.push([at, 0, `@ObjC(${JSON.stringify(selectors[label])}) `])
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
let result = source
|
|
1405
|
+
for (const [at, count, text] of edits.sort((a, b) => b[0] - a[0]))
|
|
1406
|
+
result = result.slice(0, at) + text + result.slice(at + count)
|
|
1407
|
+
return result
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1353
1410
|
// the index-preserving view lowerAnyObjectDoubleValue matches on: every
|
|
1354
1411
|
// char outside code (comments, strings, regex literals) reads as a space,
|
|
1355
1412
|
// so an identifier that survives is code. newlines stay, keeping every
|
|
@@ -1473,7 +1530,10 @@ export function swiftSourceAsIOS(
|
|
|
1473
1530
|
original: string,
|
|
1474
1531
|
extraObjCExtensions?: Map<string, Set<string>>,
|
|
1475
1532
|
): string {
|
|
1476
|
-
const source = liftExtensionOverrides(
|
|
1533
|
+
const source = liftExtensionOverrides(
|
|
1534
|
+
lowerNotificationDelegate(original),
|
|
1535
|
+
extraObjCExtensions,
|
|
1536
|
+
)
|
|
1477
1537
|
const { lineStarts, tokens } = swiftCodeScan(source)
|
|
1478
1538
|
let offset = 0
|
|
1479
1539
|
// equal width, so every token offset still holds
|
|
@@ -1590,6 +1650,56 @@ export function swiftSourceAsIOS(
|
|
|
1590
1650
|
)
|
|
1591
1651
|
}
|
|
1592
1652
|
|
|
1653
|
+
// a native module's file closure includes referenced top-level declarations
|
|
1654
|
+
// and extensions. masking uses the compiler's existing Swift lexical scanner.
|
|
1655
|
+
export function swiftSourceClosure(
|
|
1656
|
+
files: Record<string, string>,
|
|
1657
|
+
roots: string[],
|
|
1658
|
+
): Record<string, string> {
|
|
1659
|
+
const sources = new Map<string, Set<string>>()
|
|
1660
|
+
const owners = new Map<string, Set<string>>()
|
|
1661
|
+
const extensions = new Map<string, Set<string>>()
|
|
1662
|
+
for (const [file, source] of Object.entries(files)) {
|
|
1663
|
+
if (!file.endsWith('.swift')) continue
|
|
1664
|
+
const code = swiftCodeMask(source)
|
|
1665
|
+
const references = new Set(code.match(/[A-Za-z_]\w*/g) ?? [])
|
|
1666
|
+
const pattern =
|
|
1667
|
+
/[{}]|\b(class|struct|enum|protocol|actor|typealias|func|var|let|extension)\s+([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)/g
|
|
1668
|
+
let depth = 0
|
|
1669
|
+
for (const match of code.matchAll(pattern)) {
|
|
1670
|
+
if (match[0] === '{') {
|
|
1671
|
+
depth++
|
|
1672
|
+
continue
|
|
1673
|
+
}
|
|
1674
|
+
if (match[0] === '}') {
|
|
1675
|
+
depth--
|
|
1676
|
+
continue
|
|
1677
|
+
}
|
|
1678
|
+
if (depth !== 0 || !match[2]) continue
|
|
1679
|
+
const name = match[2].split('.').pop()!
|
|
1680
|
+
const index = match[1] === 'extension' ? extensions : owners
|
|
1681
|
+
const set = index.get(name) ?? new Set<string>()
|
|
1682
|
+
set.add(file)
|
|
1683
|
+
index.set(name, set)
|
|
1684
|
+
}
|
|
1685
|
+
sources.set(file, references)
|
|
1686
|
+
}
|
|
1687
|
+
const included = new Set<string>()
|
|
1688
|
+
const pending = [...roots]
|
|
1689
|
+
const seen = new Set<string>()
|
|
1690
|
+
while (pending.length) {
|
|
1691
|
+
const name = pending.pop()!
|
|
1692
|
+
if (seen.has(name)) continue
|
|
1693
|
+
seen.add(name)
|
|
1694
|
+
for (const file of [...(owners.get(name) ?? []), ...(extensions.get(name) ?? [])]) {
|
|
1695
|
+
if (included.has(file)) continue
|
|
1696
|
+
included.add(file)
|
|
1697
|
+
for (const reference of sources.get(file)!) pending.push(reference)
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return Object.fromEntries(Object.entries(files).filter(([file]) => included.has(file)))
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1593
1703
|
/** Swift's application entry declarations, ignoring comments and strings. */
|
|
1594
1704
|
export function swiftApplicationEntry(file: string, source: string): boolean {
|
|
1595
1705
|
const { tokens } = swiftCodeScan(source)
|
package/src/swift-host.ts
CHANGED
|
@@ -117,6 +117,8 @@ export function nativeSourceFiles(packagePath: string): string[] {
|
|
|
117
117
|
.filter((file) => fs.existsSync(file))
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
export class SwiftMissingModulesError extends Error {}
|
|
121
|
+
|
|
120
122
|
export interface SwiftArtifact {
|
|
121
123
|
hash: string
|
|
122
124
|
bytes: Buffer
|
|
@@ -911,7 +913,8 @@ async function compile(
|
|
|
911
913
|
...(targets.length > 0 ? targets : ['App']),
|
|
912
914
|
]),
|
|
913
915
|
)
|
|
914
|
-
if (missing.size > 0)
|
|
916
|
+
if (missing.size > 0)
|
|
917
|
+
throw new SwiftMissingModulesError(await missingModulesMessage(packagePath, missing))
|
|
915
918
|
const artifact = await compileSwiftProjectUnit(input, {
|
|
916
919
|
// the compile rewrites Sources/App in its root before swiftpm builds, and
|
|
917
920
|
// its lock orders one process only: two vites on one root (a lane's dev
|