vxrn 1.2.46 → 1.2.48

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 (203) hide show
  1. package/dist/cli.js +6 -2
  2. package/dist/cli.js.map +1 -1
  3. package/dist/cli.mjs.map +1 -1
  4. package/dist/cli.native.js.map +1 -1
  5. package/dist/config/getBaseVitePlugins.js.map +1 -1
  6. package/dist/config/getBaseVitePlugins.mjs.map +1 -1
  7. package/dist/config/getBaseVitePlugins.native.js.map +1 -1
  8. package/dist/config/getOptionsFilled.js +2 -2
  9. package/dist/config/getOptionsFilled.js.map +1 -1
  10. package/dist/config/getOptionsFilled.mjs +2 -2
  11. package/dist/config/getOptionsFilled.mjs.map +1 -1
  12. package/dist/config/getOptionsFilled.native.js +2 -2
  13. package/dist/config/getOptionsFilled.native.js.map +1 -1
  14. package/dist/config/getReactNativeBuildConfig.js +7 -2
  15. package/dist/config/getReactNativeBuildConfig.js.map +1 -1
  16. package/dist/config/getReactNativeBuildConfig.mjs.map +1 -1
  17. package/dist/config/getReactNativeBuildConfig.native.js.map +1 -1
  18. package/dist/config/getServerOptionsFilled.js +1 -1
  19. package/dist/config/getServerOptionsFilled.js.map +1 -1
  20. package/dist/config/getServerOptionsFilled.mjs +1 -1
  21. package/dist/config/getServerOptionsFilled.mjs.map +1 -1
  22. package/dist/config/getServerOptionsFilled.native.js +3 -2
  23. package/dist/config/getServerOptionsFilled.native.js.map +1 -1
  24. package/dist/config/getViteServerConfig.js.map +1 -1
  25. package/dist/config/getViteServerConfig.mjs.map +1 -1
  26. package/dist/config/getViteServerConfig.native.js.map +1 -1
  27. package/dist/config/mergeUserConfig.js +3 -3
  28. package/dist/config/mergeUserConfig.js.map +1 -1
  29. package/dist/config/mergeUserConfig.mjs +3 -3
  30. package/dist/config/mergeUserConfig.mjs.map +1 -1
  31. package/dist/config/mergeUserConfig.native.js +3 -3
  32. package/dist/config/mergeUserConfig.native.js.map +1 -1
  33. package/dist/exports/build.js +12 -4
  34. package/dist/exports/build.js.map +1 -1
  35. package/dist/exports/build.mjs.map +1 -1
  36. package/dist/exports/build.native.js.map +1 -1
  37. package/dist/exports/dev.js +1 -1
  38. package/dist/exports/dev.js.map +1 -1
  39. package/dist/exports/dev.mjs +1 -1
  40. package/dist/exports/dev.mjs.map +1 -1
  41. package/dist/exports/dev.native.js +1 -1
  42. package/dist/exports/dev.native.js.map +1 -1
  43. package/dist/exports/loadEnv.js.map +1 -1
  44. package/dist/exports/loadEnv.mjs.map +1 -1
  45. package/dist/exports/loadEnv.native.js.map +1 -1
  46. package/dist/exports/prebuild.js +4 -1
  47. package/dist/exports/prebuild.js.map +1 -1
  48. package/dist/exports/prebuild.mjs.map +1 -1
  49. package/dist/exports/prebuild.native.js.map +1 -1
  50. package/dist/exports/serveStaticAssets.js.map +1 -1
  51. package/dist/exports/serveStaticAssets.mjs.map +1 -1
  52. package/dist/exports/serveStaticAssets.native.js.map +1 -1
  53. package/dist/index.js +4 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/index.mjs.map +1 -1
  56. package/dist/index.native.js.map +1 -1
  57. package/dist/patches/builtInDepPatches.js +44 -4
  58. package/dist/patches/builtInDepPatches.js.map +1 -1
  59. package/dist/patches/builtInDepPatches.mjs +21 -1
  60. package/dist/patches/builtInDepPatches.mjs.map +1 -1
  61. package/dist/patches/builtInDepPatches.native.js +25 -1
  62. package/dist/patches/builtInDepPatches.native.js.map +1 -1
  63. package/dist/plugins/autoDepOptimizePlugin.js +17 -4
  64. package/dist/plugins/autoDepOptimizePlugin.js.map +1 -1
  65. package/dist/plugins/autoDepOptimizePlugin.mjs.map +1 -1
  66. package/dist/plugins/autoDepOptimizePlugin.native.js.map +1 -1
  67. package/dist/plugins/expoManifestRequestHandlerPlugin.js +12 -11
  68. package/dist/plugins/expoManifestRequestHandlerPlugin.js.map +1 -1
  69. package/dist/plugins/expoManifestRequestHandlerPlugin.mjs +1 -1
  70. package/dist/plugins/expoManifestRequestHandlerPlugin.mjs.map +1 -1
  71. package/dist/plugins/expoManifestRequestHandlerPlugin.native.js +1 -1
  72. package/dist/plugins/expoManifestRequestHandlerPlugin.native.js.map +1 -1
  73. package/dist/plugins/reactNativeCommonJsPlugin.js +4 -2
  74. package/dist/plugins/reactNativeCommonJsPlugin.js.map +1 -1
  75. package/dist/plugins/reactNativeCommonJsPlugin.mjs +1 -1
  76. package/dist/plugins/reactNativeCommonJsPlugin.mjs.map +1 -1
  77. package/dist/plugins/reactNativeCommonJsPlugin.native.js +1 -1
  78. package/dist/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
  79. package/dist/plugins/reactNativeDevAssetPlugin.js +16 -2
  80. package/dist/plugins/reactNativeDevAssetPlugin.js.map +1 -1
  81. package/dist/plugins/reactNativeDevAssetPlugin.mjs.map +1 -1
  82. package/dist/plugins/reactNativeDevAssetPlugin.native.js.map +1 -1
  83. package/dist/plugins/reactNativeHMRPlugin.js +17 -3
  84. package/dist/plugins/reactNativeHMRPlugin.js.map +1 -1
  85. package/dist/plugins/reactNativeHMRPlugin.mjs.map +1 -1
  86. package/dist/plugins/reactNativeHMRPlugin.native.js.map +1 -1
  87. package/dist/plugins/resolveIdScan.test.js +3 -6
  88. package/dist/plugins/resolveIdScan.test.js.map +1 -1
  89. package/dist/plugins/resolveIdScan.test.mjs.map +1 -1
  90. package/dist/plugins/resolveIdScan.test.native.js.map +1 -1
  91. package/dist/plugins/rollupRemoveUnusedImports.js +1 -1
  92. package/dist/plugins/rollupRemoveUnusedImports.js.map +1 -1
  93. package/dist/plugins/rollupRemoveUnusedImports.mjs +1 -1
  94. package/dist/plugins/rollupRemoveUnusedImports.mjs.map +1 -1
  95. package/dist/plugins/rollupRemoveUnusedImports.native.js +1 -1
  96. package/dist/plugins/rollupRemoveUnusedImports.native.js.map +1 -1
  97. package/dist/rn-commands/bundle/buildBundle.js +3 -5
  98. package/dist/rn-commands/bundle/buildBundle.js.map +1 -1
  99. package/dist/rn-commands/bundle/buildBundle.mjs +10 -13
  100. package/dist/rn-commands/bundle/buildBundle.mjs.map +1 -1
  101. package/dist/rn-commands/bundle/buildBundle.native.js +3 -5
  102. package/dist/rn-commands/bundle/buildBundle.native.js.map +1 -1
  103. package/dist/user-interface/index.js +15 -6
  104. package/dist/user-interface/index.js.map +1 -1
  105. package/dist/user-interface/index.mjs.map +1 -1
  106. package/dist/user-interface/index.native.js.map +1 -1
  107. package/dist/utils/expoRun.js +4 -2
  108. package/dist/utils/expoRun.js.map +1 -1
  109. package/dist/utils/expoRun.mjs.map +1 -1
  110. package/dist/utils/expoRun.native.js.map +1 -1
  111. package/dist/utils/getReactNativeBundle.js +12 -7
  112. package/dist/utils/getReactNativeBundle.js.map +1 -1
  113. package/dist/utils/getReactNativeBundle.mjs.map +1 -1
  114. package/dist/utils/getReactNativeBundle.native.js.map +1 -1
  115. package/dist/utils/getVitePath.js.map +1 -1
  116. package/dist/utils/getVitePath.mjs.map +1 -1
  117. package/dist/utils/getVitePath.native.js.map +1 -1
  118. package/dist/utils/patches.js +12 -3
  119. package/dist/utils/patches.js.map +1 -1
  120. package/dist/utils/patches.mjs.map +1 -1
  121. package/dist/utils/patches.native.js.map +1 -1
  122. package/dist/utils/scanDepsToOptimize.js +8 -3
  123. package/dist/utils/scanDepsToOptimize.js.map +1 -1
  124. package/dist/utils/scanDepsToOptimize.mjs +1 -1
  125. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  126. package/dist/utils/scanDepsToOptimize.native.js +1 -1
  127. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  128. package/dist/utils/swapPrebuiltReactModules.js +8 -2
  129. package/dist/utils/swapPrebuiltReactModules.js.map +1 -1
  130. package/dist/utils/swapPrebuiltReactModules.mjs.map +1 -1
  131. package/dist/utils/swapPrebuiltReactModules.native.js.map +1 -1
  132. package/dist/utils/utils.js.map +1 -1
  133. package/dist/utils/utils.mjs.map +1 -1
  134. package/dist/utils/utils.native.js.map +1 -1
  135. package/dist/worker.js +15 -12
  136. package/dist/worker.js.map +1 -1
  137. package/dist/worker.mjs.map +1 -1
  138. package/dist/worker.native.js.map +1 -1
  139. package/expo-js-native-debugging-plugin.cjs +9 -2
  140. package/expo-plugin.cjs +26 -9
  141. package/package.json +13 -13
  142. package/react-native-template.js +25 -13
  143. package/src/cli.ts +12 -5
  144. package/src/config/getBaseVitePlugins.ts +4 -1
  145. package/src/config/getOptionsFilled.ts +9 -4
  146. package/src/config/getReactNativeBuildConfig.ts +7 -2
  147. package/src/config/getServerOptionsFilled.ts +4 -1
  148. package/src/config/getViteServerConfig.ts +4 -1
  149. package/src/config/mergeUserConfig.ts +3 -3
  150. package/src/exports/build.ts +16 -5
  151. package/src/exports/dev.ts +3 -2
  152. package/src/exports/loadEnv.ts +17 -11
  153. package/src/exports/prebuild.ts +13 -3
  154. package/src/exports/serveStaticAssets.ts +4 -1
  155. package/src/index.ts +5 -1
  156. package/src/patches/builtInDepPatches.ts +58 -4
  157. package/src/plugins/autoDepOptimizePlugin.ts +18 -5
  158. package/src/plugins/clientInjectPlugin.ts +1 -1
  159. package/src/plugins/expoManifestRequestHandlerPlugin.ts +23 -19
  160. package/src/plugins/reactNativeCommonJsPlugin.ts +4 -2
  161. package/src/plugins/reactNativeDevAssetPlugin.ts +22 -4
  162. package/src/plugins/reactNativeHMRPlugin.ts +18 -4
  163. package/src/plugins/resolveIdScan.test.ts +8 -7
  164. package/src/plugins/rollupRemoveUnusedImports.ts +1 -1
  165. package/src/rn-commands/bundle/buildBundle.ts +1 -3
  166. package/src/types.ts +14 -3
  167. package/src/user-interface/index.ts +21 -6
  168. package/src/utils/expoRun.ts +8 -2
  169. package/src/utils/getReactNativeBundle.ts +13 -7
  170. package/src/utils/getVitePath.ts +4 -1
  171. package/src/utils/patches.ts +20 -6
  172. package/src/utils/scanDepsToOptimize.ts +16 -6
  173. package/src/utils/swapPrebuiltReactModules.ts +13 -3
  174. package/src/utils/utils.ts +4 -1
  175. package/src/worker.ts +19 -16
  176. package/types/config/getBaseVitePlugins.d.ts.map +1 -1
  177. package/types/config/getOptionsFilled.d.ts.map +1 -1
  178. package/types/config/getServerOptionsFilled.d.ts.map +1 -1
  179. package/types/config/getViteServerConfig.d.ts.map +1 -1
  180. package/types/exports/build.d.ts.map +1 -1
  181. package/types/exports/dev.d.ts.map +1 -1
  182. package/types/exports/loadEnv.d.ts.map +1 -1
  183. package/types/exports/prebuild.d.ts.map +1 -1
  184. package/types/exports/serveStaticAssets.d.ts.map +1 -1
  185. package/types/index.d.ts +1 -1
  186. package/types/index.d.ts.map +1 -1
  187. package/types/patches/builtInDepPatches.d.ts.map +1 -1
  188. package/types/plugins/autoDepOptimizePlugin.d.ts +1 -1
  189. package/types/plugins/autoDepOptimizePlugin.d.ts.map +1 -1
  190. package/types/plugins/expoManifestRequestHandlerPlugin.d.ts.map +1 -1
  191. package/types/plugins/reactNativeCommonJsPlugin.d.ts.map +1 -1
  192. package/types/plugins/reactNativeDevAssetPlugin.d.ts.map +1 -1
  193. package/types/plugins/reactNativeHMRPlugin.d.ts.map +1 -1
  194. package/types/rn-commands/bundle/buildBundle.d.ts.map +1 -1
  195. package/types/types.d.ts.map +1 -1
  196. package/types/utils/expoRun.d.ts.map +1 -1
  197. package/types/utils/getReactNativeBundle.d.ts.map +1 -1
  198. package/types/utils/getVitePath.d.ts.map +1 -1
  199. package/types/utils/patches.d.ts.map +1 -1
  200. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
  201. package/types/utils/swapPrebuiltReactModules.d.ts.map +1 -1
  202. package/types/utils/utils.d.ts.map +1 -1
  203. /package/types/utils/{filterPluginsForNative.d.ts → filterPluginsforNative.d.ts} +0 -0
package/src/cli.ts CHANGED
@@ -14,7 +14,9 @@ async function importCLIEndpoint<T>(path: string): Promise<T> {
14
14
  }
15
15
 
16
16
  if (typeof import.meta.dirname !== 'string') {
17
- console.error(`One uses "import.meta.dirname", for Node this is version 20.11.0 or greater`)
17
+ console.error(
18
+ `One uses "import.meta.dirname", for Node this is version 20.11.0 or greater`
19
+ )
18
20
  process.exit(1)
19
21
  }
20
22
 
@@ -193,7 +195,9 @@ const prebuild = defineCommand({
193
195
  async run({ args }) {
194
196
  if (args.install === false) args['no-install'] = true // citty seems to convert --no-install to install: false, leaving no-install as default
195
197
 
196
- const { prebuild } = await importCLIEndpoint<typeof prebuildExport>('./exports/prebuild.mjs')
198
+ const { prebuild } = await importCLIEndpoint<typeof prebuildExport>(
199
+ './exports/prebuild.mjs'
200
+ )
197
201
  const root = process.cwd()
198
202
  const { platform, expo } = args
199
203
 
@@ -208,7 +212,8 @@ const runIos = defineCommand({
208
212
  },
209
213
  args: {},
210
214
  async run() {
211
- const { runIos } = await importCLIEndpoint<typeof runIOSExport>('./exports/runIos.mjs')
215
+ const { runIos } =
216
+ await importCLIEndpoint<typeof runIOSExport>('./exports/runIos.mjs')
212
217
  const root = process.cwd()
213
218
  await runIos({ root })
214
219
  },
@@ -237,7 +242,8 @@ const patch = defineCommand({
237
242
  },
238
243
  args: {},
239
244
  async run() {
240
- const { patch: vxrnPatch } = await importCLIEndpoint<typeof patchExport>('./exports/patch.mjs')
245
+ const { patch: vxrnPatch } =
246
+ await importCLIEndpoint<typeof patchExport>('./exports/patch.mjs')
241
247
  await vxrnPatch({
242
248
  root: process.cwd(),
243
249
  })
@@ -252,7 +258,8 @@ const clean = defineCommand({
252
258
  },
253
259
  args: {},
254
260
  async run() {
255
- const { clean: vxrnClean } = await importCLIEndpoint<typeof cleanExport>('./exports/clean.mjs')
261
+ const { clean: vxrnClean } =
262
+ await importCLIEndpoint<typeof cleanExport>('./exports/clean.mjs')
256
263
  await vxrnClean({
257
264
  root: process.cwd(),
258
265
  })
@@ -93,7 +93,10 @@ export function getBaseVitePlugins(): PluginOption[] {
93
93
  configureServer() {
94
94
  const ogWarn = console.warn
95
95
  console.warn = (...args: any[]) => {
96
- if (typeof args[0] === 'string' && args[0].startsWith(`Failed to resolve dependency:`)) {
96
+ if (
97
+ typeof args[0] === 'string' &&
98
+ args[0].startsWith(`Failed to resolve dependency:`)
99
+ ) {
97
100
  return
98
101
  }
99
102
  return ogWarn(...args)
@@ -42,7 +42,10 @@ export type VXRNOptionsFilled = Awaited<ReturnType<typeof fillOptions>>
42
42
 
43
43
  let optionsFilled: VXRNOptionsFilled | null = null
44
44
 
45
- export async function fillOptions(options: VXRNOptions, { mode = 'dev' }: { mode?: Mode } = {}) {
45
+ export async function fillOptions(
46
+ options: VXRNOptions,
47
+ { mode = 'dev' }: { mode?: Mode } = {}
48
+ ) {
46
49
  const { root = process.cwd(), entries } = options
47
50
 
48
51
  const devMode = options.mode === 'production' ? false : mode === 'dev'
@@ -61,14 +64,16 @@ export async function fillOptions(options: VXRNOptions, { mode = 'dev' }: { mode
61
64
  const packageVersions =
62
65
  deps.react && deps['react-native']
63
66
  ? {
64
- react: deps.react.replace(/[\^\~]/, ''),
65
- reactNative: deps['react-native'].replace(/[\^\~]/, ''),
67
+ react: deps.react.replace(/[\^~]/, ''),
68
+ reactNative: deps['react-native'].replace(/[\^~]/, ''),
66
69
  }
67
70
  : undefined
68
71
 
69
72
  const versionHash = hashString(JSON.stringify(packageJSON))
70
73
  const clean =
71
- (options.clean ?? (state.versionHash && state.versionHash !== versionHash)) ? 'vite' : false
74
+ (options.clean ?? (state.versionHash && state.versionHash !== versionHash))
75
+ ? 'vite'
76
+ : false
72
77
 
73
78
  // no need to wait to write state
74
79
  void writeState(cacheDir, { versionHash })
@@ -342,9 +342,14 @@ async function findModulePath(
342
342
  const parentDir = dirname(currentDir)
343
343
 
344
344
  if (parentDir === currentDir) {
345
- throw new Error(`Could not find module in any of these paths: ${triedPaths?.join(', ')}`)
345
+ throw new Error(
346
+ `Could not find module in any of these paths: ${triedPaths?.join(', ')}`
347
+ )
346
348
  }
347
349
 
348
- return findModulePath(modulePath, parentDir, [...(triedPaths || []), currentModulePath])
350
+ return findModulePath(modulePath, parentDir, [
351
+ ...(triedPaths || []),
352
+ currentModulePath,
353
+ ])
349
354
  }
350
355
  }
@@ -18,6 +18,9 @@ export async function getServerOptionsFilled(
18
18
  host,
19
19
  })
20
20
 
21
+ // Use localhost for the URL when host is 0.0.0.0 since that's how clients will access it
22
+ const urlHost = host === '0.0.0.0' ? 'localhost' : host
23
+
21
24
  return {
22
25
  loadEnv: false,
23
26
  compress: true,
@@ -25,6 +28,6 @@ export async function getServerOptionsFilled(
25
28
  port,
26
29
  host,
27
30
  protocol,
28
- url: `${protocol}//${host}:${port}`,
31
+ url: `${protocol}//${urlHost}:${port}`,
29
32
  }
30
33
  }
@@ -12,7 +12,10 @@ import { getAdditionalViteConfig } from './getAdditionalViteConfig'
12
12
  * Only used in CLI mode since this hard-codes the `mode` to `'serve'` and contains
13
13
  * custom config merging logic.
14
14
  */
15
- export async function getViteServerConfig(config: VXRNOptionsFilled, userViteConfig?: UserConfig) {
15
+ export async function getViteServerConfig(
16
+ config: VXRNOptionsFilled,
17
+ userViteConfig?: UserConfig
18
+ ) {
16
19
  const { root, server } = config
17
20
  const { optimizeDeps } = getOptimizeDeps('serve')
18
21
 
@@ -100,8 +100,8 @@ export function deepMergeOptimizeDeps(
100
100
  ])
101
101
 
102
102
  a.optimizeDeps.esbuildOptions = {
103
- ...(a.optimizeDeps.esbuildOptions || {}),
104
- ...(b.optimizeDeps.esbuildOptions || {}),
105
- ...(extraDepsOpt?.esbuildOptions || {}),
103
+ ...a.optimizeDeps.esbuildOptions,
104
+ ...b.optimizeDeps.esbuildOptions,
105
+ ...extraDepsOpt?.esbuildOptions,
106
106
  }
107
107
  }
@@ -142,7 +142,10 @@ export const build = async (optionsIn: VXRNOptions, buildArgs: BuildArgs = {}) =
142
142
  }
143
143
 
144
144
  if (warning.code === 'EVAL') {
145
- warning.message = warning.message.replace(/(\.+\/){0,}node_modules/, 'node_modules')
145
+ warning.message = warning.message.replace(
146
+ /(\.+\/){0,}node_modules/,
147
+ 'node_modules'
148
+ )
146
149
  }
147
150
 
148
151
  if (warning.code === 'INVALID_ANNOTATION') {
@@ -224,7 +227,9 @@ export const build = async (optionsIn: VXRNOptions, buildArgs: BuildArgs = {}) =
224
227
  clientBuildConfig = mergeConfig(clientBuildConfig, disableOptimizationConfig)
225
228
  }
226
229
 
227
- console.info(`\n 🔨 build ${options.build?.server !== false ? 'client + server' : 'client'}\n`)
230
+ console.info(
231
+ `\n 🔨 build ${options.build?.server !== false ? 'client + server' : 'client'}\n`
232
+ )
228
233
 
229
234
  clientBuildPromise = viteBuild(clientBuildConfig) as Promise<RollupOutput>
230
235
  }
@@ -295,16 +300,22 @@ export const build = async (optionsIn: VXRNOptions, buildArgs: BuildArgs = {}) =
295
300
  }
296
301
 
297
302
  const userServerConf = optionsIn.build?.server
298
- const userServerBuildConf = typeof userServerConf === 'boolean' ? null : userServerConf?.config
303
+ const userServerBuildConf =
304
+ typeof userServerConf === 'boolean' ? null : userServerConf?.config
299
305
 
300
306
  serverBuildPromise = viteBuild(
301
- userServerBuildConf ? mergeConfig(serverBuildConfig, userServerBuildConf) : serverBuildConfig
307
+ userServerBuildConf
308
+ ? mergeConfig(serverBuildConfig, userServerBuildConf)
309
+ : serverBuildConfig
302
310
  ) as Promise<RollupOutput>
303
311
  }
304
312
 
305
313
  // Wait for both builds to complete in parallel
306
314
  if (clientBuildPromise && serverBuildPromise) {
307
- const [clientResult, serverResult] = await Promise.all([clientBuildPromise, serverBuildPromise])
315
+ const [clientResult, serverResult] = await Promise.all([
316
+ clientBuildPromise,
317
+ serverBuildPromise,
318
+ ])
308
319
  clientOutput = clientResult.output
309
320
  serverOutput = serverResult.output
310
321
  } else if (clientBuildPromise) {
@@ -25,7 +25,8 @@ export const dev = async (optionsIn: DevOptions) => {
25
25
  const { getViteServerConfig } = await import('../config/getViteServerConfig')
26
26
  const { printServerUrls } = await import('../utils/printServerUrls')
27
27
  const { clean } = await import('./clean')
28
- const { filterViteServerResolvedUrls } = await import('../utils/filterViteServerResolvedUrls')
28
+ const { filterViteServerResolvedUrls } =
29
+ await import('../utils/filterViteServerResolvedUrls')
29
30
  const { removeUndefined } = await import('../utils/removeUndefined')
30
31
  const { createServer, loadConfigFromFile } = await import('vite')
31
32
 
@@ -61,7 +62,7 @@ export default defineConfig({
61
62
  const options = await fillOptions({
62
63
  ...optionsIn,
63
64
  server: {
64
- ...(oneServerConfig || {}),
65
+ ...oneServerConfig,
65
66
  ...removeUndefined(optionsIn.server || {}),
66
67
  },
67
68
  })
@@ -9,7 +9,11 @@ type Mode = 'development' | 'production' | string
9
9
 
10
10
  const DEFAULT_PREFIX = /^(ONE|VITE|TAMAGUI)_/
11
11
 
12
- export async function loadEnv(mode: Mode, root = process.cwd(), userPrefix?: string | string[]) {
12
+ export async function loadEnv(
13
+ mode: Mode,
14
+ root = process.cwd(),
15
+ userPrefix?: string | string[]
16
+ ) {
13
17
  const loadedEnv = await loadJustEnvFiles(mode)
14
18
  const prefix = userPrefix ? (Array.isArray(userPrefix) ? userPrefix : [userPrefix]) : []
15
19
  const isPublicKey = (key: string) => {
@@ -69,22 +73,24 @@ function getEnvFilesForMode(mode: Mode) {
69
73
 
70
74
  async function loadJustEnvFiles(mode: Mode) {
71
75
  const envFiles = getEnvFilesForMode(mode)
72
-
76
+
73
77
  // load all env files and merge them
74
78
  const parsed = Object.fromEntries(
75
- (await Promise.all(
76
- envFiles.map(async (filePath) => {
77
- if (!tryStatSync(filePath)?.isFile()) return []
78
- const contents = await readFile(filePath, 'utf-8')
79
- return Object.entries(parse(contents))
80
- })
81
- )).flat()
79
+ (
80
+ await Promise.all(
81
+ envFiles.map(async (filePath) => {
82
+ if (!tryStatSync(filePath)?.isFile()) return []
83
+ const contents = await readFile(filePath, 'utf-8')
84
+ return Object.entries(parse(contents))
85
+ })
86
+ )
87
+ ).flat()
82
88
  )
83
-
89
+
84
90
  // support dotenv-expand for variable expansion
85
91
  const processEnv = { ...process.env } as DotenvPopulateInput
86
92
  expand({ parsed, processEnv })
87
-
93
+
88
94
  return parsed
89
95
  }
90
96
 
@@ -41,7 +41,10 @@ export const prebuild = async ({
41
41
  let packageJsonContents = await FSExtra.readFile(packageJsonPath, 'utf8')
42
42
 
43
43
  packageJsonContents = packageJsonContents.replace(/expo run:ios/g, 'one run:ios')
44
- packageJsonContents = packageJsonContents.replace(/expo run:android/g, 'one run:android')
44
+ packageJsonContents = packageJsonContents.replace(
45
+ /expo run:android/g,
46
+ 'one run:android'
47
+ )
45
48
 
46
49
  await FSExtra.writeFile(packageJsonPath, packageJsonContents, 'utf8')
47
50
  } catch (error) {
@@ -204,7 +207,10 @@ Android:
204
207
  }
205
208
 
206
209
  function isMissingCliDependency(error) {
207
- return error.code === 'MODULE_NOT_FOUND' && /@react-native-community\/cli/.test(error.message)
210
+ return (
211
+ error.code === 'MODULE_NOT_FOUND' &&
212
+ /@react-native-community\/cli/.test(error.message)
213
+ )
208
214
  }
209
215
 
210
216
  function warnMissingCliDependency() {
@@ -218,7 +224,11 @@ ${colors.white(
218
224
  )}`)
219
225
  }
220
226
 
221
- export async function replaceInUTF8File(filePath: string, findThis: string, replaceWith: string) {
227
+ export async function replaceInUTF8File(
228
+ filePath: string,
229
+ findThis: string,
230
+ replaceWith: string
231
+ ) {
222
232
  const fileContent = await FSExtra.readFile(filePath, 'utf8')
223
233
  const replacedFileContent = fileContent.replace(findThis, replaceWith)
224
234
  if (fileContent !== replacedFileContent) {
@@ -4,7 +4,10 @@ import type { Context } from 'hono'
4
4
  export async function serveStaticAssets({
5
5
  context,
6
6
  next,
7
- }: { context: Context; next?: () => Promise<void> }) {
7
+ }: {
8
+ context: Context
9
+ next?: () => Promise<void>
10
+ }) {
8
11
  let didCallNext = false
9
12
 
10
13
  const response = await serveStatic({
package/src/index.ts CHANGED
@@ -9,7 +9,11 @@ export { patch } from './exports/patch'
9
9
  export { loadEnv } from './exports/loadEnv'
10
10
  export { serveStaticAssets } from './exports/serveStaticAssets'
11
11
 
12
- export { type VXRNOptionsFilled, getOptionsFilled, fillOptions } from './config/getOptionsFilled'
12
+ export {
13
+ type VXRNOptionsFilled,
14
+ getOptionsFilled,
15
+ fillOptions,
16
+ } from './config/getOptionsFilled'
13
17
  export * from './config/getOptimizeDeps'
14
18
  export * from './config/getBaseViteConfigOnly'
15
19
  export * from './config/getBaseVitePlugins'
@@ -25,7 +25,9 @@ export const builtInDepPatches: DepPatch[] = [
25
25
  const existingExports = { ...pkg.exports }
26
26
 
27
27
  if (!pkg.exports['.']) {
28
- throw new Error(`Expected a version of React that has package.json exports defined`)
28
+ throw new Error(
29
+ `Expected a version of React that has package.json exports defined`
30
+ )
29
31
  }
30
32
 
31
33
  pkg.exports['.'] = {
@@ -126,7 +128,9 @@ ${contents}
126
128
  const existingExports = { ...pkg.exports }
127
129
 
128
130
  if (!pkg.exports['.']) {
129
- throw new Error(`Expected a version of React that has package.json exports defined`)
131
+ throw new Error(
132
+ `Expected a version of React that has package.json exports defined`
133
+ )
130
134
  }
131
135
 
132
136
  pkg.exports['.'] = {
@@ -318,6 +322,33 @@ install('URLSearchParams', () => URLSearchParams);
318
322
  module: 'react-native-css-interop',
319
323
  patchFiles: {
320
324
  'dist/**/*.js': ['jsx'],
325
+
326
+ // Fix the dynamic require inside wrapJSX function to be a top-level import
327
+ // This ensures components.js is bundled and executed to register Text, View, etc. with cssInterop
328
+ 'dist/runtime/wrap-jsx.js': (contents) => {
329
+ assertString(contents)
330
+ // Move the require("./components") from inside the function to module level
331
+ return contents
332
+ .replace(
333
+ /if\s*\(\s*process\.env\.NODE_ENV\s*!==\s*["']test["']\s*\)\s*require\s*\(\s*["']\.\/components["']\s*\)\s*;?/,
334
+ ''
335
+ )
336
+ .replace(
337
+ '"use strict";',
338
+ `"use strict";
339
+ if (process.env.NODE_ENV !== "test") require("./components");`
340
+ )
341
+ },
342
+
343
+ // Fix sideEffects: false causing components.js to be tree-shaken
344
+ // components.js registers Text, View, etc. with cssInterop and MUST run
345
+ 'package.json': (contents) => {
346
+ assertString(contents)
347
+ const pkg = JSON.parse(contents)
348
+ // Change sideEffects to include components.js
349
+ pkg.sideEffects = ['dist/runtime/components.js']
350
+ return JSON.stringify(pkg, null, 2)
351
+ },
321
352
  },
322
353
  },
323
354
 
@@ -400,14 +431,37 @@ install('URLSearchParams', () => URLSearchParams);
400
431
  },
401
432
  },
402
433
 
434
+ {
435
+ module: 'expo-asset',
436
+ patchFiles: {
437
+ // Fix: expo-asset re-exports from react-native but RN uses properties on default export, not named exports
438
+ // This patch explicitly re-exports the functions so they're available as named exports
439
+ 'build/resolveAssetSource.native.js': (contents) => {
440
+ assertString(contents)
441
+ return contents.replace(
442
+ `export * from 'react-native/Libraries/Image/resolveAssetSource';`,
443
+ `export const pickScale = resolveAssetSource.pickScale;
444
+ export const setCustomSourceTransformer = resolveAssetSource.setCustomSourceTransformer;
445
+ export const addCustomSourceTransformer = resolveAssetSource.addCustomSourceTransformer;`
446
+ )
447
+ },
448
+ },
449
+ },
450
+
403
451
  {
404
452
  module: 'whatwg-url-without-unicode',
405
453
  // https://github.com/onejs/one/issues/258
406
454
  patchFiles: {
407
455
  '**/*.js': (contents) =>
408
456
  contents
409
- ?.replace(/punycode\.ucs2\.decode/gm, '(punycode.ucs2decode || punycode.ucs2.decode)')
410
- ?.replace(/punycode\.ucs2\.encode/gm, '(punycode.ucs2encode || punycode.ucs2.encode)'),
457
+ ?.replace(
458
+ /punycode\.ucs2\.decode/gm,
459
+ '(punycode.ucs2decode || punycode.ucs2.decode)'
460
+ )
461
+ ?.replace(
462
+ /punycode\.ucs2\.encode/gm,
463
+ '(punycode.ucs2encode || punycode.ucs2.encode)'
464
+ ),
411
465
  },
412
466
  },
413
467
 
@@ -3,7 +3,11 @@ import FSExtra from 'fs-extra'
3
3
  import path from 'node:path'
4
4
  import { createFilter, type Plugin } from 'vite'
5
5
  import type { AutoDepOptimizationOptions } from '../types'
6
- import { EXCLUDE_LIST, type ScanDepsResult, scanDepsToOptimize } from '../utils/scanDepsToOptimize'
6
+ import {
7
+ EXCLUDE_LIST,
8
+ type ScanDepsResult,
9
+ scanDepsToOptimize,
10
+ } from '../utils/scanDepsToOptimize'
7
11
  import { getFileHash, lookupFile } from '../utils/utils'
8
12
  import { getCacheDir } from '../utils/getCacheDir'
9
13
 
@@ -75,7 +79,12 @@ export async function getScannedOptimizeDepsConfig(props: FindDepsOptionsByMode)
75
79
 
76
80
  let sessionCacheVal: ScanDepsResult | null = null
77
81
 
78
- export async function findDepsToOptimize({ root, mode, exclude, include }: FindDepsOptionsByMode) {
82
+ export async function findDepsToOptimize({
83
+ root,
84
+ mode,
85
+ exclude,
86
+ include,
87
+ }: FindDepsOptionsByMode) {
79
88
  const cacheFilePath = getSSRExternalsCachePath(root)
80
89
  const startedAt = debug ? Date.now() : 0
81
90
 
@@ -102,8 +111,10 @@ export async function findDepsToOptimize({ root, mode, exclude, include }: FindD
102
111
 
103
112
  if (lockFileHash && !noCache) {
104
113
  try {
105
- const { lockFileHash: cachedLockFileHash, depsToPreBundleForSsr: cachedDepsToPreBundle } =
106
- await FSExtra.readJSON(cacheFilePath)
114
+ const {
115
+ lockFileHash: cachedLockFileHash,
116
+ depsToPreBundleForSsr: cachedDepsToPreBundle,
117
+ } = await FSExtra.readJSON(cacheFilePath)
107
118
 
108
119
  if (
109
120
  lockFileHash === cachedLockFileHash &&
@@ -143,7 +154,9 @@ export async function findDepsToOptimize({ root, mode, exclude, include }: FindD
143
154
  : ` (Focus on this debug scope, "DEBUG=${debug.namespace}", to see more details.)`)
144
155
  )
145
156
 
146
- debugDetails?.(`Deps discovered to be pre-bundled for SSR: ${value.prebundleDeps.join(', ')}`)
157
+ debugDetails?.(
158
+ `Deps discovered to be pre-bundled for SSR: ${value.prebundleDeps.join(', ')}`
159
+ )
147
160
 
148
161
  return value
149
162
  }
@@ -6,7 +6,7 @@ import { getResolvedConfig, setResolvedConfig } from './getResolvedConfigSubset'
6
6
 
7
7
  let config: ResolvedConfig | null
8
8
 
9
- const isObject = (x: any): x is Object => x && typeof x === 'object'
9
+ const isObject = (x: any): x is object => x && typeof x === 'object'
10
10
 
11
11
  export function getServerConfigPlugin() {
12
12
  return {
@@ -34,7 +34,8 @@ export function expoManifestRequestHandlerPlugin(
34
34
  return next()
35
35
  }
36
36
 
37
- const protocol = req.socket instanceof TLSSocket && req.socket.encrypted ? 'https' : 'http'
37
+ const protocol =
38
+ req.socket instanceof TLSSocket && req.socket.encrypted ? 'https' : 'http'
38
39
  const host = `${req.headers['x-forwarded-host'] || req.headers.host || '127.0.0.1'}`
39
40
 
40
41
  // Try to dynamically import the internal Expo manifest handler from expo packages installed in the user's project.
@@ -57,7 +58,8 @@ export function expoManifestRequestHandlerPlugin(
57
58
  if (!ExpoGoManifestHandlerMiddleware) {
58
59
  if (
59
60
  expoGoManifestHandlerMiddlewareImportError instanceof Error &&
60
- (expoGoManifestHandlerMiddlewareImportError as any).code === 'MODULE_NOT_FOUND'
61
+ (expoGoManifestHandlerMiddlewareImportError as any).code ===
62
+ 'MODULE_NOT_FOUND'
61
63
  ) {
62
64
  logger.warn(
63
65
  colors.yellow(
@@ -95,15 +97,19 @@ export function expoManifestRequestHandlerPlugin(
95
97
  return
96
98
  }
97
99
 
98
- const manifestHandlerMiddleware = new ExpoGoManifestHandlerMiddleware(projectRoot, {
99
- constructUrl: () => {
100
- return `${protocol}://${host}`
101
- },
102
- })
100
+ const manifestHandlerMiddleware = new ExpoGoManifestHandlerMiddleware(
101
+ projectRoot,
102
+ {
103
+ constructUrl: () => {
104
+ return `${protocol}://${host}`
105
+ },
106
+ }
107
+ )
103
108
 
104
109
  // Override the `_getBundleUrl` method ensure the same host and protocol are used for the bundle URL.
105
- const origGetBundleUrl =
106
- manifestHandlerMiddleware._getBundleUrl.bind(manifestHandlerMiddleware)
110
+ const origGetBundleUrl = manifestHandlerMiddleware._getBundleUrl.bind(
111
+ manifestHandlerMiddleware
112
+ )
107
113
  manifestHandlerMiddleware._getBundleUrl = (...args) => {
108
114
  /** Will be something like `http://127.0.0.1:8081/index.bundle?platform=ios&dev=true&hot=false&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app`. */
109
115
  const origBundleUrl = origGetBundleUrl(...args)
@@ -123,11 +129,13 @@ export function expoManifestRequestHandlerPlugin(
123
129
 
124
130
  manifestHandlerMiddleware._getManifestResponseAsync = async (...args) => {
125
131
  try {
126
- const results = await manifestHandlerMiddleware._origGetManifestResponseAsync(...args)
132
+ const results = await manifestHandlerMiddleware._origGetManifestResponseAsync(
133
+ ...args
134
+ )
127
135
 
128
136
  // Seems that results.body may have a leading and trailing string that is not JSON, so we need to extract the JSON from it.
129
137
  const [, beforeBodyJson, bodyJson, afterBodyJson] =
130
- results.body.match(/([^\{]*)(\{.*\})([^\}]*)/) || []
138
+ results.body.match(/([^{]*)({.*})([^}]*)/) || []
131
139
  if (!bodyJson) {
132
140
  throw new Error(`Unrecognized manifest response from expo: ${results.body}`)
133
141
  }
@@ -141,16 +149,12 @@ export function expoManifestRequestHandlerPlugin(
141
149
  }
142
150
 
143
151
  if (typeof parsedBody.extra.expoClient.hostUri === 'string') {
144
- parsedBody.extra.expoClient.hostUri = parsedBody.extra.expoClient.hostUri.replace(
145
- /^https?:\/\//,
146
- ''
147
- )
152
+ parsedBody.extra.expoClient.hostUri =
153
+ parsedBody.extra.expoClient.hostUri.replace(/^https?:\/\//, '')
148
154
  }
149
155
  if (typeof parsedBody.extra.expoGo.debuggerHost === 'string') {
150
- parsedBody.extra.expoGo.debuggerHost = parsedBody.extra.expoGo.debuggerHost.replace(
151
- /^https?:\/\//,
152
- ''
153
- )
156
+ parsedBody.extra.expoGo.debuggerHost =
157
+ parsedBody.extra.expoGo.debuggerHost.replace(/^https?:\/\//, '')
154
158
  }
155
159
 
156
160
  // TODO: Using a static icon and splash for branding for now.
@@ -78,7 +78,9 @@ export function reactNativeCommonJsPlugin(options: {
78
78
  base: undefined,
79
79
 
80
80
  define: {
81
- 'process.env.REACT_NATIVE_SERVER_PUBLIC_PORT': JSON.stringify(`${options.port}`),
81
+ 'process.env.REACT_NATIVE_SERVER_PUBLIC_PORT': JSON.stringify(
82
+ `${options.port}`
83
+ ),
82
84
  },
83
85
 
84
86
  build: {
@@ -162,7 +164,7 @@ export function reactNativeCommonJsPlugin(options: {
162
164
  for (const line of code.split('\n')) {
163
165
  if (line.startsWith('export * from')) {
164
166
  const [_, exportedName] =
165
- line.match(/export \* from [\'\"]([^\'\"]+)[\'\"]/) || []
167
+ line.match(/export \* from ['"]([^'"]+)['"]/) || []
166
168
  if (exportedName) {
167
169
  found++
168
170
  const name = `__vxrnExp${found}`
@@ -5,7 +5,18 @@ import type { Plugin, ResolvedConfig } from 'vite'
5
5
  import colors from 'picocolors'
6
6
  import { isNativeEnvironment } from '../utils/environmentUtils'
7
7
 
8
- const IMAGE_ASSET_EXTS = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff', 'ktx']
8
+ const IMAGE_ASSET_EXTS = [
9
+ 'png',
10
+ 'jpg',
11
+ 'jpeg',
12
+ 'bmp',
13
+ 'gif',
14
+ 'webp',
15
+ 'psd',
16
+ 'svg',
17
+ 'tiff',
18
+ 'ktx',
19
+ ]
9
20
  const IMAGE_ASSET_EXTS_SET = new Set(IMAGE_ASSET_EXTS)
10
21
 
11
22
  const ASSET_DEST_DIR = 'assets'
@@ -21,7 +32,9 @@ type ReactNativeDevAssetPluginConfig = {
21
32
  assetsDest?: string
22
33
  }
23
34
 
24
- export function reactNativeDevAssetPlugin(options: ReactNativeDevAssetPluginConfig): Plugin {
35
+ export function reactNativeDevAssetPlugin(
36
+ options: ReactNativeDevAssetPluginConfig
37
+ ): Plugin {
25
38
  const { assetExts } = options
26
39
 
27
40
  const assetExtsRegExp = new RegExp(`\\.(${assetExts.join('|')})$`)
@@ -91,7 +104,10 @@ export function reactNativeDevAssetPlugin(options: ReactNativeDevAssetPluginConf
91
104
  assetData.relativeFileSystemLocation
92
105
  )
93
106
  await FSExtra.ensureDir(assetsDestDir)
94
- await FSExtra.copyFile(id, path.join(assetsDestDir, `${assetData.name}.${assetData.type}`))
107
+ await FSExtra.copyFile(
108
+ id,
109
+ path.join(assetsDestDir, `${assetData.name}.${assetData.type}`)
110
+ )
95
111
  }
96
112
 
97
113
  /**
@@ -148,7 +164,9 @@ export default asset;
148
164
  )
149
165
 
150
166
  res.statusCode =
151
- e instanceof Error && (e as NodeJS.ErrnoException).code === 'ENOENT' ? 404 : 500
167
+ e instanceof Error && (e as NodeJS.ErrnoException).code === 'ENOENT'
168
+ ? 404
169
+ : 500
152
170
  res.end()
153
171
  }
154
172
  })