vxrn 2.0.0-beta.99.1 → 2.6.0

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 (210) hide show
  1. package/dist/backgroundComputation.mjs +145 -0
  2. package/dist/backgroundComputation.mjs.map +1 -0
  3. package/dist/backgroundComputation.native.js +163 -0
  4. package/dist/backgroundComputation.native.js.map +1 -0
  5. package/dist/backgroundComputationNative.mjs +16 -0
  6. package/dist/backgroundComputationNative.mjs.map +1 -0
  7. package/dist/backgroundComputationNative.native.js +18 -0
  8. package/dist/backgroundComputationNative.native.js.map +1 -0
  9. package/dist/config/getBaseViteConfigOnly.mjs +6 -10
  10. package/dist/config/getBaseViteConfigOnly.mjs.map +1 -1
  11. package/dist/config/getBaseViteConfigOnly.native.js +6 -10
  12. package/dist/config/getBaseViteConfigOnly.native.js.map +1 -1
  13. package/dist/config/getOptimizeDeps.mjs +2 -1
  14. package/dist/config/getOptimizeDeps.mjs.map +1 -1
  15. package/dist/config/getOptimizeDeps.native.js +2 -1
  16. package/dist/config/getOptimizeDeps.native.js.map +1 -1
  17. package/dist/config/getViteServerConfig.mjs +13 -0
  18. package/dist/config/getViteServerConfig.mjs.map +1 -1
  19. package/dist/config/getViteServerConfig.native.js +15 -1
  20. package/dist/config/getViteServerConfig.native.js.map +1 -1
  21. package/dist/constants/defaults.mjs +4 -0
  22. package/dist/constants/defaults.mjs.map +1 -1
  23. package/dist/constants/defaults.native.js +4 -0
  24. package/dist/constants/defaults.native.js.map +1 -1
  25. package/dist/exports/build.native.js +1 -1
  26. package/dist/exports/build.native.js.map +1 -1
  27. package/dist/exports/clean.native.js +1 -1
  28. package/dist/exports/clean.native.js.map +1 -1
  29. package/dist/exports/createServer.native.js +2 -2
  30. package/dist/exports/createServer.native.js.map +1 -1
  31. package/dist/exports/dev.mjs +3 -0
  32. package/dist/exports/dev.mjs.map +1 -1
  33. package/dist/exports/dev.native.js +6 -3
  34. package/dist/exports/dev.native.js.map +1 -1
  35. package/dist/exports/loadEnv.native.js +1 -1
  36. package/dist/exports/loadEnv.native.js.map +1 -1
  37. package/dist/exports/patch.native.js +1 -1
  38. package/dist/exports/patch.native.js.map +1 -1
  39. package/dist/exports/prebuild.mjs +0 -22
  40. package/dist/exports/prebuild.mjs.map +1 -1
  41. package/dist/exports/prebuild.native.js +1 -23
  42. package/dist/exports/prebuild.native.js.map +1 -1
  43. package/dist/exports/prebuildWithoutExpo.mjs +1116 -178
  44. package/dist/exports/prebuildWithoutExpo.mjs.map +1 -1
  45. package/dist/exports/prebuildWithoutExpo.native.js +1592 -243
  46. package/dist/exports/prebuildWithoutExpo.native.js.map +1 -1
  47. package/dist/exports/runAndroid.native.js +1 -1
  48. package/dist/exports/runAndroid.native.js.map +1 -1
  49. package/dist/exports/runIos.native.js +1 -1
  50. package/dist/exports/runIos.native.js.map +1 -1
  51. package/dist/exports/serve.native.js +1 -1
  52. package/dist/exports/serve.native.js.map +1 -1
  53. package/dist/exports/serveStaticAssets.native.js +1 -1
  54. package/dist/exports/serveStaticAssets.native.js.map +1 -1
  55. package/dist/index.js +4 -1
  56. package/dist/index.mjs +4 -1
  57. package/dist/index.native.js +4 -1
  58. package/dist/native-source-contract.mjs +3 -0
  59. package/dist/native-source-contract.native.js +3 -0
  60. package/dist/patches/builtInDepPatches.mjs +0 -13
  61. package/dist/patches/builtInDepPatches.mjs.map +1 -1
  62. package/dist/patches/builtInDepPatches.native.js +0 -13
  63. package/dist/patches/builtInDepPatches.native.js.map +1 -1
  64. package/dist/plugins/autoDepOptimizePlugin.mjs +3 -2
  65. package/dist/plugins/autoDepOptimizePlugin.mjs.map +1 -1
  66. package/dist/plugins/autoDepOptimizePlugin.native.js +6 -3
  67. package/dist/plugins/autoDepOptimizePlugin.native.js.map +1 -1
  68. package/dist/plugins/backgroundComputationPlugin.mjs +27 -0
  69. package/dist/plugins/backgroundComputationPlugin.mjs.map +1 -0
  70. package/dist/plugins/backgroundComputationPlugin.native.js +32 -0
  71. package/dist/plugins/backgroundComputationPlugin.native.js.map +1 -0
  72. package/dist/plugins/reactNativeCommonJsPlugin.native.js +3 -3
  73. package/dist/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
  74. package/dist/plugins/reactNativeDevAssetPlugin.mjs +2 -1
  75. package/dist/plugins/reactNativeDevAssetPlugin.mjs.map +1 -1
  76. package/dist/plugins/reactNativeDevAssetPlugin.native.js +3 -2
  77. package/dist/plugins/reactNativeDevAssetPlugin.native.js.map +1 -1
  78. package/dist/plugins/reactNativeDevServer.mjs +87 -24
  79. package/dist/plugins/reactNativeDevServer.mjs.map +1 -1
  80. package/dist/plugins/reactNativeDevServer.native.js +162 -45
  81. package/dist/plugins/reactNativeDevServer.native.js.map +1 -1
  82. package/dist/plugins/workletImportsPlugin.mjs +9 -30
  83. package/dist/plugins/workletImportsPlugin.mjs.map +1 -1
  84. package/dist/plugins/workletImportsPlugin.native.js +10 -35
  85. package/dist/plugins/workletImportsPlugin.native.js.map +1 -1
  86. package/dist/rn-commands/bundle/buildBundle.mjs +3 -3
  87. package/dist/rn-commands/bundle/buildBundle.mjs.map +1 -1
  88. package/dist/rn-commands/bundle/buildBundle.native.js +3 -3
  89. package/dist/rn-commands/bundle/buildBundle.native.js.map +1 -1
  90. package/dist/runtime/hmr-client.native.js +3 -7
  91. package/dist/runtime/hmr-client.native.js.map +1 -1
  92. package/dist/runtime/hmr-runtime.native.js +32 -40
  93. package/dist/runtime/hmr-runtime.native.js.map +1 -1
  94. package/dist/serve/node.native.js +2 -2
  95. package/dist/serve/node.native.js.map +1 -1
  96. package/dist/swift-package-id.mjs +3 -0
  97. package/dist/swift-package-id.native.js +3 -0
  98. package/dist/user-interface/index.native.js +6 -6
  99. package/dist/user-interface/index.native.js.map +1 -1
  100. package/dist/utils/compileNativeDevBytecode.mjs +93 -0
  101. package/dist/utils/compileNativeDevBytecode.mjs.map +1 -0
  102. package/dist/utils/compileNativeDevBytecode.native.js +98 -0
  103. package/dist/utils/compileNativeDevBytecode.native.js.map +1 -0
  104. package/dist/utils/createNativeDevEngine.mjs +227 -20
  105. package/dist/utils/createNativeDevEngine.mjs.map +1 -1
  106. package/dist/utils/createNativeDevEngine.native.js +249 -37
  107. package/dist/utils/createNativeDevEngine.native.js.map +1 -1
  108. package/dist/utils/execSync.native.js +1 -1
  109. package/dist/utils/execSync.native.js.map +1 -1
  110. package/dist/utils/getServerEntry.native.js +2 -2
  111. package/dist/utils/getServerEntry.native.js.map +1 -1
  112. package/dist/utils/nativeRun.mjs +32 -16
  113. package/dist/utils/nativeRun.mjs.map +1 -1
  114. package/dist/utils/nativeRun.native.js +43 -18
  115. package/dist/utils/nativeRun.native.js.map +1 -1
  116. package/dist/utils/nativeSourceContract.mjs +1823 -0
  117. package/dist/utils/nativeSourceContract.mjs.map +1 -0
  118. package/dist/utils/nativeSourceContract.native.js +2425 -0
  119. package/dist/utils/nativeSourceContract.native.js.map +1 -0
  120. package/dist/utils/patches.native.js +15 -24
  121. package/dist/utils/patches.native.js.map +1 -1
  122. package/dist/utils/printServerUrls.native.js +1 -1
  123. package/dist/utils/printServerUrls.native.js.map +1 -1
  124. package/dist/utils/scanDepsToOptimize.mjs +7 -1
  125. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  126. package/dist/utils/scanDepsToOptimize.native.js +27 -2
  127. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  128. package/dist/utils/swiftPackageId.mjs +31 -2
  129. package/dist/utils/swiftPackageId.mjs.map +1 -1
  130. package/dist/utils/swiftPackageId.native.js +50 -2
  131. package/dist/utils/swiftPackageId.native.js.map +1 -1
  132. package/dist/vxrn-vite-plugin.native.js +1 -1
  133. package/dist/vxrn-vite-plugin.native.js.map +1 -1
  134. package/expo-plugin.cjs +792 -2
  135. package/native-project-patches.cjs +201 -10
  136. package/package.json +34 -15
  137. package/src/backgroundComputation.ts +220 -0
  138. package/src/backgroundComputationNative.ts +23 -0
  139. package/src/config/getBaseViteConfigOnly.ts +8 -9
  140. package/src/config/getOptimizeDeps.ts +3 -1
  141. package/src/config/getViteServerConfig.ts +16 -0
  142. package/src/config/glbAssets.test.ts +228 -0
  143. package/src/constants/defaults.ts +6 -0
  144. package/src/exports/dev.ts +5 -1
  145. package/src/exports/expoPlugin.test.mjs +337 -15
  146. package/src/exports/prebuild.ts +0 -31
  147. package/src/exports/prebuildWithoutExpo.test.ts +1588 -48
  148. package/src/exports/prebuildWithoutExpo.ts +1573 -213
  149. package/src/index.ts +8 -0
  150. package/src/native-source-contract.ts +16 -0
  151. package/src/patches/builtInDepPatches.ts +0 -21
  152. package/src/plugins/autoDepOptimizePlugin.ts +7 -2
  153. package/src/plugins/backgroundComputationPlugin.test.ts +77 -0
  154. package/src/plugins/backgroundComputationPlugin.ts +29 -0
  155. package/src/plugins/reactNativeDevAssetPlugin.ts +5 -1
  156. package/src/plugins/reactNativeDevServer.test.ts +74 -0
  157. package/src/plugins/reactNativeDevServer.ts +145 -28
  158. package/src/plugins/rnCodegenPlugin.test.ts +30 -0
  159. package/src/plugins/workletImportsPlugin.ts +19 -37
  160. package/src/rn-commands/bundle/buildBundle.ts +5 -3
  161. package/src/swift-package-id.ts +1 -0
  162. package/src/utils/compileNativeDevBytecode.test.ts +168 -0
  163. package/src/utils/compileNativeDevBytecode.ts +117 -0
  164. package/src/utils/createNativeDevEngine.test.ts +643 -18
  165. package/src/utils/createNativeDevEngine.ts +278 -48
  166. package/src/utils/nativeRun.test.ts +125 -23
  167. package/src/utils/nativeRun.ts +51 -23
  168. package/src/utils/nativeSourceArtifacts.test.ts +39 -0
  169. package/src/utils/nativeSourceContract.test.ts +600 -0
  170. package/src/utils/nativeSourceContract.ts +1897 -0
  171. package/src/utils/scanDepsToOptimize.test.ts +80 -0
  172. package/src/utils/scanDepsToOptimize.ts +18 -7
  173. package/src/utils/swiftPackageId.ts +25 -1
  174. package/types/backgroundComputation.d.ts +28 -0
  175. package/types/backgroundComputation.d.ts.map +1 -0
  176. package/types/backgroundComputationNative.d.ts +2 -0
  177. package/types/backgroundComputationNative.d.ts.map +1 -0
  178. package/types/config/getBaseViteConfigOnly.d.ts.map +1 -1
  179. package/types/config/getOptimizeDeps.d.ts.map +1 -1
  180. package/types/config/getViteServerConfig.d.ts.map +1 -1
  181. package/types/constants/defaults.d.ts.map +1 -1
  182. package/types/exports/dev.d.ts.map +1 -1
  183. package/types/exports/prebuild.d.ts.map +1 -1
  184. package/types/exports/prebuildWithoutExpo.d.ts +6 -0
  185. package/types/exports/prebuildWithoutExpo.d.ts.map +1 -1
  186. package/types/index.d.ts +2 -0
  187. package/types/index.d.ts.map +1 -1
  188. package/types/native-source-contract.d.ts +2 -0
  189. package/types/native-source-contract.d.ts.map +1 -0
  190. package/types/patches/builtInDepPatches.d.ts.map +1 -1
  191. package/types/plugins/autoDepOptimizePlugin.d.ts.map +1 -1
  192. package/types/plugins/backgroundComputationPlugin.d.ts +3 -0
  193. package/types/plugins/backgroundComputationPlugin.d.ts.map +1 -0
  194. package/types/plugins/reactNativeDevAssetPlugin.d.ts.map +1 -1
  195. package/types/plugins/reactNativeDevServer.d.ts.map +1 -1
  196. package/types/plugins/workletImportsPlugin.d.ts.map +1 -1
  197. package/types/rn-commands/bundle/buildBundle.d.ts.map +1 -1
  198. package/types/swift-package-id.d.ts +2 -0
  199. package/types/swift-package-id.d.ts.map +1 -0
  200. package/types/utils/compileNativeDevBytecode.d.ts +3 -0
  201. package/types/utils/compileNativeDevBytecode.d.ts.map +1 -0
  202. package/types/utils/createNativeDevEngine.d.ts +7 -22
  203. package/types/utils/createNativeDevEngine.d.ts.map +1 -1
  204. package/types/utils/nativeRun.d.ts.map +1 -1
  205. package/types/utils/nativeSourceContract.d.ts +121 -0
  206. package/types/utils/nativeSourceContract.d.ts.map +1 -0
  207. package/types/utils/scanDepsToOptimize.d.ts +1 -0
  208. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
  209. package/types/utils/swiftPackageId.d.ts +1 -0
  210. package/types/utils/swiftPackageId.d.ts.map +1 -1
@@ -1,5 +1,5 @@
1
1
  import { execFileSync } from 'node:child_process'
2
- import { existsSync, readFileSync } from 'node:fs'
2
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
3
3
  import module from 'node:module'
4
4
  import path from 'node:path'
5
5
 
@@ -21,6 +21,8 @@ export function buildNativeRunCommand(args: {
21
21
  // whenever more than one simulator exists.
22
22
  if (args.simulator) argv.push('--simulator', args.simulator)
23
23
  if (args.udid) argv.push('--udid', args.udid)
24
+ if (args.platform === 'android' && process.env.ANDROID_SERIAL)
25
+ argv.push('--device', process.env.ANDROID_SERIAL)
24
26
  return {
25
27
  command: args.platform === 'ios' ? 'run-ios' : 'run-android',
26
28
  argv,
@@ -43,6 +45,28 @@ async function devServerRunning(port: number): Promise<boolean> {
43
45
  }
44
46
  }
45
47
 
48
+ // community cli logs a missing android device as an error and still exits
49
+ // 0, so a run with no target would read as a successful install. one checks
50
+ // the target itself, with the adb community cli resolves.
51
+ function connectedAndroidDevices(): string[] {
52
+ const sdk = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT
53
+ const adb = sdk ? path.join(sdk, 'platform-tools', 'adb') : 'adb'
54
+ let out: string
55
+ try {
56
+ out = execFileSync(adb, ['devices'], { encoding: 'utf8' })
57
+ } catch {
58
+ throw new Error(
59
+ `\nCould not run ${adb}. Install the Android SDK platform tools and set ANDROID_HOME.`
60
+ )
61
+ }
62
+ return out
63
+ .split('\n')
64
+ .slice(1)
65
+ .map((line) => line.trim().split(/\s+/))
66
+ .filter(([serial, state]) => serial && state === 'device')
67
+ .map(([serial]) => serial!)
68
+ }
69
+
46
70
  export type NativeRunSpawn = (
47
71
  executable: string,
48
72
  argv: string[],
@@ -87,18 +111,27 @@ export async function nativeRun({
87
111
  )
88
112
  }
89
113
 
114
+ if (platform === 'android') {
115
+ const devices = connectedAndroidDevices()
116
+ const serial = process.env.ANDROID_SERIAL
117
+ if (!devices.length || (serial && !devices.includes(serial))) {
118
+ throw new Error(
119
+ serial
120
+ ? `\nAndroid device ${serial} is not connected (connected: ${devices.join(', ') || 'none'}).`
121
+ : '\nNo Android device or emulator is connected. Start an emulator or plug in a device, then re-run this command.'
122
+ )
123
+ }
124
+ }
125
+
90
126
  // source-built React-Core bakes RCT_METRO_PORT from this environment
91
127
  // into a preprocessor define that RCTBundleURLProvider uses as its
92
128
  // default packager port. with prebuilt pods the port is already baked
93
129
  // (8081), so the simulator default below is what points the app.
94
130
  process.env.RCT_METRO_PORT = String(resolvedPort)
95
131
 
96
- // resolve the community cli from the user's project, since vxrn may be
97
- // installed globally or at the root workspace.
98
- const require = module.createRequire(root + '/')
99
- const cliPackageJson = require.resolve('@react-native-community/cli/package.json', {
100
- paths: [root],
101
- })
132
+ // vxrn owns the cli; cwd still selects the app's config and native project.
133
+ const require = module.createRequire(import.meta.url)
134
+ const cliPackageJson = require.resolve('@react-native-community/cli/package.json')
102
135
  const bin = path.join(path.dirname(cliPackageJson), 'build', 'bin.js')
103
136
 
104
137
  spawn(process.execPath, [bin, command, ...argv], {
@@ -116,23 +149,18 @@ export async function nativeRun({
116
149
  // localhost at its baked-in port (8081 with prebuilt pods) and gives up
117
150
  // with "no script url" when the dev server lives on one's port. writing
118
151
  // the provider's jsLocation default aims it at the real server.
152
+ // the bundle id the built app carries, read from the ios project either
153
+ // prebuild generated, so an app configured by native.app or app.json both
154
+ // resolve.
119
155
  export function resolveIosBundleId(root: string): string | null {
120
- try {
121
- const appJson = joinAppJson(root)
122
- if (!appJson) return null
123
- const parsed = JSON.parse(readFileSync(appJson, 'utf8')) as {
124
- expo?: { ios?: { bundleIdentifier?: unknown } }
125
- }
126
- const id = parsed?.expo?.ios?.bundleIdentifier
127
- return typeof id === 'string' && id ? id : null
128
- } catch {
129
- return null
130
- }
131
- }
132
-
133
- function joinAppJson(root: string): string | null {
134
- const file = path.join(root, 'app.json')
135
- return existsSync(file) ? file : null
156
+ const iosDir = path.join(root, 'ios')
157
+ if (!existsSync(iosDir)) return null
158
+ const project = readdirSync(iosDir).find((entry) => entry.endsWith('.xcodeproj'))
159
+ if (!project) return null
160
+ const pbxproj = path.join(iosDir, project, 'project.pbxproj')
161
+ if (!existsSync(pbxproj)) return null
162
+ const match = readFileSync(pbxproj, 'utf8').match(/PRODUCT_BUNDLE_IDENTIFIER = "?([A-Za-z0-9.-]+)"?;/)
163
+ return match ? match[1] : null
136
164
  }
137
165
 
138
166
  function bootedSimulatorUdid(): string | null {
@@ -0,0 +1,39 @@
1
+ import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
2
+ import { tmpdir } from 'node:os'
3
+ import { join } from 'node:path'
4
+ import { expect, test, vi } from 'vitest'
5
+ import { nativeSourceContract, renderSwiftSourceGlue, writeSwiftPackageArtifacts } from './nativeSourceContract'
6
+
7
+ // directory enumeration order is unspecified and differs between node and bun.
8
+ vi.mock('node:fs', async (importOriginal) => {
9
+ const fs = await importOriginal<typeof import('node:fs')>()
10
+ return {
11
+ ...fs,
12
+ readdirSync: (path: import('node:fs').PathLike, options: { withFileTypes: true }) => {
13
+ return fs.readdirSync(path, options)
14
+ .sort((a, b) => a.name < b.name ? 1 : a.name > b.name ? -1 : 0)
15
+ },
16
+ }
17
+ })
18
+
19
+ test('package hash and glue use canonical file order regardless of directory enumeration', () => {
20
+ const root = mkdtempSync(join(tmpdir(), 'one-source-order-'))
21
+ try {
22
+ const pkg = join(root, 'native-source')
23
+ mkdirSync(pkg)
24
+ const audio = '@MainActor final class Audio: PeachModule { init() {}\n func value() -> Double { 1 }\n}'
25
+ const echo = '@MainActor final class Echo: PeachModule { init() {}\n func value() -> Double { 2 }\n}'
26
+ writeFileSync(join(pkg, 'Echo.swift'), echo)
27
+ writeFileSync(join(pkg, 'Audio.swift'), audio)
28
+ const actual = writeSwiftPackageArtifacts(pkg)
29
+ const expected = renderSwiftSourceGlue('native_source', [
30
+ nativeSourceContract(join(pkg, 'Audio.swift'), audio),
31
+ nativeSourceContract(join(pkg, 'Echo.swift'), echo),
32
+ ])
33
+ expect(Object.keys(actual.files)).toEqual(['Audio.swift', 'Echo.swift'])
34
+ expect(actual.hash).toBe(expected.hash)
35
+ expect(actual.glue).toBe(expected.source)
36
+ } finally {
37
+ rmSync(root, { recursive: true, force: true })
38
+ }
39
+ })