peachsim 0.1.801 → 0.1.809

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 (80) 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/bundle-channel.cjs +11 -4
  16. package/dist-lib/capture-contract.cjs +1 -1
  17. package/dist-lib/capture-contract.mjs +1 -1
  18. package/dist-lib/cli-constants.cjs +1 -1
  19. package/dist-lib/cloud-contract.cjs +1 -1
  20. package/dist-lib/cloud-contract.mjs +1 -1
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +1 -1
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +1 -1
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/detox/index.cjs +1 -1
  27. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  28. package/dist-lib/expo-swift-bundle.cjs +11 -4
  29. package/dist-lib/expo-swift-metadata.cjs +1 -1
  30. package/dist-lib/expo-swift-metadata.mjs +1 -1
  31. package/dist-lib/home-paths.cjs +1 -1
  32. package/dist-lib/host/bridge-host.cjs +131 -102
  33. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  34. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  35. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  36. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  37. package/dist-lib/host/websocket-proxy.cjs +1 -1
  38. package/dist-lib/index.cjs +1 -1
  39. package/dist-lib/jump-to-source-babel.cjs +1 -1
  40. package/dist-lib/jump-to-source-native.cjs +1 -1
  41. package/dist-lib/kotlin-host.cjs +1 -1
  42. package/dist-lib/menu.cjs +1 -1
  43. package/dist-lib/menu.mjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  45. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  46. package/dist-lib/metro-production-bundle.cjs +1 -1
  47. package/dist-lib/metro-production-bundle.mjs +1 -1
  48. package/dist-lib/metro.cjs +1 -1
  49. package/dist-lib/native-app-identity.cjs +1 -1
  50. package/dist-lib/native-app-identity.mjs +1 -1
  51. package/dist-lib/native-firebase-metadata.cjs +1 -1
  52. package/dist-lib/native-firebase-metadata.mjs +1 -1
  53. package/dist-lib/plist.cjs +1 -1
  54. package/dist-lib/plist.mjs +1 -1
  55. package/dist-lib/profiles.cjs +1 -1
  56. package/dist-lib/public-brand.cjs +1 -1
  57. package/dist-lib/react-native-host-modules.cjs +1 -1
  58. package/dist-lib/react-native-host-modules.mjs +1 -1
  59. package/dist-lib/render-mode.cjs +1 -1
  60. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  61. package/dist-lib/sdk.cjs +1 -1
  62. package/dist-lib/sdk.mjs +1 -1
  63. package/dist-lib/skills.cjs +131 -102
  64. package/dist-lib/swift-compile.cjs +11 -4
  65. package/dist-lib/swift-compile.mjs +11 -4
  66. package/dist-lib/swift-package.cjs +1 -1
  67. package/dist-lib/swift-package.mjs +1 -1
  68. package/dist-lib/swift-submit.cjs +1 -1
  69. package/dist-lib/swift-submit.mjs +1 -1
  70. package/dist-lib/swift-toolchain.cjs +1 -1
  71. package/dist-lib/swift.cjs +1 -1
  72. package/dist-lib/vite-swift.cjs +11 -4
  73. package/dist-lib/vite.cjs +1 -1
  74. package/dist-lib/worklet-executable.cjs +119 -0
  75. package/dist-lib/worklet-executable.mjs +93 -0
  76. package/package.json +9 -1
  77. package/src/swift-compile.ts +11 -2
  78. package/src/vite-plugin.ts +5 -2
  79. package/src/worklet-executable.ts +125 -0
  80. package/src/worklets-babel.ts +47 -6
@@ -3,7 +3,11 @@ import fs from 'node:fs'
3
3
  import { createRequire } from 'node:module'
4
4
  import path from 'node:path'
5
5
  import { fileURLToPath } from 'node:url'
6
- import type { TransformOptions } from '@babel/core'
6
+ import {
7
+ compileWorkletExecutables,
8
+ workletExecutableBodies,
9
+ } from './worklet-executable.ts'
10
+ import type { PluginObj, TransformOptions } from '@babel/core'
7
11
  import type { TransformResult } from 'vite'
8
12
 
9
13
  const sootsimPluginRequire = createRequire(import.meta.url)
@@ -87,7 +91,9 @@ function isTypescriptFile(id: string): boolean {
87
91
  // output is a pure function of the source text, the file path, the sourcemap
88
92
  // flag, and the babel toolchain, so cache it on disk keyed by all four. a
89
93
  // normal dev rebuild changes a handful of files and replays the rest.
90
- const CACHE_SCHEMA = 'v1'
94
+ export type WorkletBodyMode = 'executable' | 'transport'
95
+
96
+ const CACHE_SCHEMA = 'v4'
91
97
  const CACHE_ROOT = path.resolve(
92
98
  workspaceRoot,
93
99
  'node_modules',
@@ -134,6 +140,7 @@ function getCacheEntryPath(
134
140
  code: string,
135
141
  id: string,
136
142
  sourceMaps: TransformOptions['sourceMaps'],
143
+ bodyMode: WorkletBodyMode,
137
144
  ): string | null {
138
145
  const dir = getCacheDir()
139
146
  if (!dir) return null
@@ -146,6 +153,7 @@ function getCacheEntryPath(
146
153
  [
147
154
  id,
148
155
  String(sourceMaps),
156
+ bodyMode,
149
157
  process.env.BABEL_ENV ?? '',
150
158
  process.env.NODE_ENV ?? '',
151
159
  code,
@@ -180,9 +188,36 @@ function writeCachedTransform(
180
188
  } catch {}
181
189
  }
182
190
 
191
+ // the final program visitor runs after upstream has built its init records.
192
+ // inserting syntax here lets babel map the original source in the same pass.
193
+ function executableWorkletsPlugin(
194
+ api: Pick<typeof import('@babel/core'), 'types' | 'template'>,
195
+ ): PluginObj {
196
+ return {
197
+ visitor: {
198
+ Program: {
199
+ exit(path) {
200
+ for (const { initData, code } of workletExecutableBodies(path.node)) {
201
+ const properties = Reflect.get(initData, 'properties')
202
+ if (!Array.isArray(properties))
203
+ throw new Error('peach: invalid worklet init record')
204
+ properties.push(
205
+ api.types.objectProperty(
206
+ api.types.identifier('__peachExecutable'),
207
+ api.template.expression.ast(`(${compileWorkletExecutables(code)})`),
208
+ ),
209
+ )
210
+ }
211
+ },
212
+ },
213
+ },
214
+ }
215
+ }
216
+
183
217
  function createWorkletsBabelOptions(
184
218
  id: string,
185
219
  sourceMaps: TransformOptions['sourceMaps'],
220
+ bodyMode: WorkletBodyMode,
186
221
  ): TransformOptions {
187
222
  const isTSX = id.endsWith('.tsx')
188
223
  const isTS = isTypescriptFile(id)
@@ -202,6 +237,7 @@ function createWorkletsBabelOptions(
202
237
  plugins: [
203
238
  [sootsimPluginRequire.resolve('@babel/plugin-syntax-jsx')],
204
239
  [getWorkletsPluginPath(), { processNestedWorklets: true }],
240
+ ...(bodyMode === 'executable' ? [executableWorkletsPlugin] : []),
205
241
  ],
206
242
  }
207
243
  }
@@ -210,15 +246,19 @@ export async function transformWorkletsCode(
210
246
  code: string,
211
247
  id: string,
212
248
  sourceMaps: TransformOptions['sourceMaps'] = true,
249
+ bodyMode: WorkletBodyMode = 'executable',
213
250
  ): Promise<Pick<TransformResult, 'code' | 'map'> | null> {
214
- const entryPath = getCacheEntryPath(code, id, sourceMaps)
251
+ const entryPath = getCacheEntryPath(code, id, sourceMaps, bodyMode)
215
252
  const cached = readCachedTransform(entryPath)
216
253
  if (cached) return cached
217
254
  if (!babelCorePromise) {
218
255
  babelCorePromise = import('@babel/core') as Promise<typeof import('@babel/core')>
219
256
  }
220
257
  const { transformAsync } = await babelCorePromise
221
- const result = await transformAsync(code, createWorkletsBabelOptions(id, sourceMaps))
258
+ const result = await transformAsync(
259
+ code,
260
+ createWorkletsBabelOptions(id, sourceMaps, bodyMode),
261
+ )
222
262
  if (!result?.code) return null
223
263
  const transformed = {
224
264
  code: result.code,
@@ -232,14 +272,15 @@ export function transformWorkletsCodeSync(
232
272
  code: string,
233
273
  id: string,
234
274
  sourceMaps: TransformOptions['sourceMaps'] = false,
275
+ bodyMode: WorkletBodyMode = 'executable',
235
276
  ): Pick<TransformResult, 'code' | 'map'> | null {
236
- const entryPath = getCacheEntryPath(code, id, sourceMaps)
277
+ const entryPath = getCacheEntryPath(code, id, sourceMaps, bodyMode)
237
278
  const cached = readCachedTransform(entryPath)
238
279
  if (cached) return cached
239
280
  const { transformSync } = sootsimPluginRequire(
240
281
  '@babel/core',
241
282
  ) as typeof import('@babel/core')
242
- const result = transformSync(code, createWorkletsBabelOptions(id, sourceMaps))
283
+ const result = transformSync(code, createWorkletsBabelOptions(id, sourceMaps, bodyMode))
243
284
  if (!result?.code) return null
244
285
  const transformed = {
245
286
  code: result.code,