peachsim 0.1.760 → 0.1.762

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.
Files changed (71) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/agent-identity.cjs +1 -1
  4. package/dist-lib/agent-sessions.cjs +1 -1
  5. package/dist-lib/attached-projects.cjs +1 -1
  6. package/dist-lib/auth/shared-session.cjs +1 -1
  7. package/dist-lib/backend-origin.cjs +1 -1
  8. package/dist-lib/beta.cjs +1 -1
  9. package/dist-lib/beta.mjs +1 -1
  10. package/dist-lib/bridge-constants.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.mjs +1 -1
  13. package/dist-lib/bridge-contract.cjs +1 -1
  14. package/dist-lib/bridge-contract.mjs +1 -1
  15. package/dist-lib/capture-contract.cjs +1 -1
  16. package/dist-lib/capture-contract.mjs +1 -1
  17. package/dist-lib/cli-constants.cjs +1 -1
  18. package/dist-lib/cloud-contract.cjs +1 -1
  19. package/dist-lib/cloud-contract.mjs +1 -1
  20. package/dist-lib/cloud-test-args.cjs +1 -1
  21. package/dist-lib/cloud-test-args.mjs +1 -1
  22. package/dist-lib/cloud.cjs +1 -1
  23. package/dist-lib/cloud.mjs +1 -1
  24. package/dist-lib/config.cjs +1 -1
  25. package/dist-lib/detox/index.cjs +1 -1
  26. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  27. package/dist-lib/home-paths.cjs +1 -1
  28. package/dist-lib/host/bridge-host.cjs +109 -44
  29. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  30. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  31. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  32. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  33. package/dist-lib/host/websocket-proxy.cjs +1 -1
  34. package/dist-lib/index.cjs +1 -1
  35. package/dist-lib/jump-to-source-babel.cjs +1 -1
  36. package/dist-lib/jump-to-source-native.cjs +1 -1
  37. package/dist-lib/kotlin-host.cjs +1 -1
  38. package/dist-lib/menu.cjs +1 -1
  39. package/dist-lib/menu.mjs +1 -1
  40. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  41. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  42. package/dist-lib/metro-production-bundle.cjs +1 -1
  43. package/dist-lib/metro-production-bundle.mjs +1 -1
  44. package/dist-lib/metro.cjs +1 -1
  45. package/dist-lib/native-app-identity.cjs +1 -1
  46. package/dist-lib/native-app-identity.mjs +1 -1
  47. package/dist-lib/native-firebase-metadata.cjs +1 -1
  48. package/dist-lib/native-firebase-metadata.mjs +1 -1
  49. package/dist-lib/plist.cjs +1 -1
  50. package/dist-lib/plist.mjs +1 -1
  51. package/dist-lib/profiles.cjs +1 -1
  52. package/dist-lib/public-brand.cjs +1 -1
  53. package/dist-lib/react-native-host-modules.cjs +1 -1
  54. package/dist-lib/react-native-host-modules.mjs +1 -1
  55. package/dist-lib/render-mode.cjs +1 -1
  56. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  57. package/dist-lib/sdk.cjs +1 -1
  58. package/dist-lib/sdk.mjs +1 -1
  59. package/dist-lib/skills.cjs +109 -44
  60. package/dist-lib/swift-compile.cjs +66 -8
  61. package/dist-lib/swift-compile.mjs +66 -8
  62. package/dist-lib/swift-package.cjs +1 -1
  63. package/dist-lib/swift-package.mjs +1 -1
  64. package/dist-lib/swift-submit.cjs +1 -1
  65. package/dist-lib/swift-submit.mjs +1 -1
  66. package/dist-lib/swift-toolchain.cjs +1 -1
  67. package/dist-lib/swift.cjs +1 -1
  68. package/dist-lib/vite-swift.cjs +66 -8
  69. package/dist-lib/vite.cjs +1 -1
  70. package/package.json +1 -1
  71. package/src/swift-compile.ts +102 -12
@@ -275,19 +275,108 @@ const OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES)
275
275
  const SWIFT_IMPORT =
276
276
  /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/
277
277
 
278
+ // a compilation condition as the wasm compile sees it after the source
279
+ // rewrite below: `os(iOS)` and `os(WASI)` hold, other platforms do not,
280
+ // `canImport` holds for an available module. what the scan cannot know
281
+ // (custom flags, swift versions, features) is undefined, three-valued
282
+ // through `!`, `&&` and `||`.
283
+ function swiftCondition(
284
+ text: string,
285
+ available: ReadonlySet<string>,
286
+ ): boolean | undefined {
287
+ const tokens = text.match(/\w+\s*\([^()]*\)|&&|\|\||!|\(|\)|\w+/g) ?? []
288
+ let index = 0
289
+ const atom = (): boolean | undefined => {
290
+ const token = tokens[index++]
291
+ if (token === '!') {
292
+ const value = atom()
293
+ return value === undefined ? undefined : !value
294
+ }
295
+ if (token === '(') {
296
+ const value = either()
297
+ index++
298
+ return value
299
+ }
300
+ if (token === 'true') return true
301
+ if (token === 'false') return false
302
+ const call = /^(\w+)\s*\(\s*([^,()]*?)\s*(?:,[^()]*)?\)$/.exec(token ?? '')
303
+ if (!call) return undefined
304
+ const [, name, argument] = call
305
+ if (name === 'os') return argument === 'iOS' || argument === 'WASI'
306
+ if (name === 'canImport') return available.has(argument!)
307
+ if (name === 'targetEnvironment') return false
308
+ if (name === 'arch') return argument === 'wasm32'
309
+ return undefined
310
+ }
311
+ const both = (): boolean | undefined => {
312
+ let value = atom()
313
+ while (tokens[index] === '&&') {
314
+ index++
315
+ const next = atom()
316
+ value = value === false || next === false ? false : value && next ? true : undefined
317
+ }
318
+ return value
319
+ }
320
+ const either = (): boolean | undefined => {
321
+ let value = both()
322
+ while (tokens[index] === '||') {
323
+ index++
324
+ const next = both()
325
+ value =
326
+ value === true || next === true
327
+ ? true
328
+ : value === false && next === false
329
+ ? false
330
+ : undefined
331
+ }
332
+ return value
333
+ }
334
+ return either()
335
+ }
336
+
278
337
  /**
279
- * the modules a source imports, in order. `unconditional` keeps only imports
280
- * outside every `#if`: a conditional one may compile out (`os(macOS)`,
281
- * `canImport`), so only an unconditional import is certainly required.
338
+ * the modules a source imports, in order. with `available`, only imports the
339
+ * wasm compile certainly reaches: those outside every `#if`, or in a branch
340
+ * whose condition holds there, `os(iOS)` included since the compile rewrites
341
+ * it to true. a branch the scan cannot decide may compile out, so its
342
+ * imports stay out of the list.
282
343
  */
283
- export function swiftImportNames(contents: string, unconditional = false): string[] {
344
+ export function swiftImportNames(
345
+ contents: string,
346
+ available?: ReadonlySet<string>,
347
+ ): string[] {
284
348
  const names: string[] = []
285
- let depth = 0
349
+ // per open `#if`: whether its current branch is active, and whether an
350
+ // earlier branch was taken (or may have been)
351
+ const frames: { active: boolean | undefined; taken: boolean | undefined }[] = []
286
352
  for (const line of contents.split('\n')) {
287
- const directive = /^\s*#(if|endif)\b/.exec(line)?.[1]
288
- if (directive === 'if') depth++
289
- else if (directive === 'endif') depth = Math.max(0, depth - 1)
290
- if (unconditional && depth > 0) continue
353
+ const directive = /^\s*#(if|elseif|else|endif)\b(.*)$/.exec(line)
354
+ if (directive && available) {
355
+ const [, kind, rest] = directive
356
+ const condition = (rest ?? '').replace(/\/\/.*$/, '').trim()
357
+ if (kind === 'if') {
358
+ const active = swiftCondition(condition, available)
359
+ frames.push({ active, taken: active })
360
+ } else if (kind === 'endif') frames.pop()
361
+ else if (frames.length > 0) {
362
+ const frame = frames[frames.length - 1]!
363
+ const holds = kind === 'else' ? true : swiftCondition(condition, available)
364
+ frame.active =
365
+ frame.taken === true
366
+ ? false
367
+ : frame.taken === false
368
+ ? holds
369
+ : holds && undefined
370
+ frame.taken =
371
+ frame.taken === true || holds === true
372
+ ? true
373
+ : frame.taken === false
374
+ ? holds
375
+ : undefined
376
+ }
377
+ continue
378
+ }
379
+ if (available && frames.some((frame) => frame.active !== true)) continue
291
380
  const name = SWIFT_IMPORT.exec(line)?.[1]
292
381
  if (name) names.push(name)
293
382
  }
@@ -346,8 +435,9 @@ export function swiftAvailableModules(
346
435
  }
347
436
 
348
437
  /**
349
- * the modules the sources import outside any `#if` that nothing available
350
- * provides, each with the files importing it. the compiler stops at the first
438
+ * the modules the sources certainly import (swiftImportNames with
439
+ * `available`) that nothing available provides, each with the files
440
+ * importing it. the compiler stops at the first
351
441
  * missing module; this names all of them at once.
352
442
  */
353
443
  export function missingSwiftModules(
@@ -357,7 +447,7 @@ export function missingSwiftModules(
357
447
  const missing = new Map<string, string[]>()
358
448
  for (const [file, contents] of Object.entries(files)) {
359
449
  if (!file.endsWith('.swift') || file === 'Package.swift') continue
360
- for (const name of new Set(swiftImportNames(contents, true))) {
450
+ for (const name of new Set(swiftImportNames(contents, available))) {
361
451
  if (available.has(name)) continue
362
452
  missing.set(name, [...(missing.get(name) ?? []), file])
363
453
  }