vxrn 1.2.47 → 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 (193) 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/getViteServerConfig.js.map +1 -1
  19. package/dist/config/getViteServerConfig.mjs.map +1 -1
  20. package/dist/config/getViteServerConfig.native.js.map +1 -1
  21. package/dist/config/mergeUserConfig.js +3 -3
  22. package/dist/config/mergeUserConfig.js.map +1 -1
  23. package/dist/config/mergeUserConfig.mjs +3 -3
  24. package/dist/config/mergeUserConfig.mjs.map +1 -1
  25. package/dist/config/mergeUserConfig.native.js +3 -3
  26. package/dist/config/mergeUserConfig.native.js.map +1 -1
  27. package/dist/exports/build.js +12 -4
  28. package/dist/exports/build.js.map +1 -1
  29. package/dist/exports/build.mjs.map +1 -1
  30. package/dist/exports/build.native.js.map +1 -1
  31. package/dist/exports/dev.js +1 -1
  32. package/dist/exports/dev.js.map +1 -1
  33. package/dist/exports/dev.mjs +1 -1
  34. package/dist/exports/dev.mjs.map +1 -1
  35. package/dist/exports/dev.native.js +1 -1
  36. package/dist/exports/dev.native.js.map +1 -1
  37. package/dist/exports/loadEnv.js.map +1 -1
  38. package/dist/exports/loadEnv.mjs.map +1 -1
  39. package/dist/exports/loadEnv.native.js.map +1 -1
  40. package/dist/exports/prebuild.js +4 -1
  41. package/dist/exports/prebuild.js.map +1 -1
  42. package/dist/exports/prebuild.mjs.map +1 -1
  43. package/dist/exports/prebuild.native.js.map +1 -1
  44. package/dist/exports/serveStaticAssets.js.map +1 -1
  45. package/dist/exports/serveStaticAssets.mjs.map +1 -1
  46. package/dist/exports/serveStaticAssets.native.js.map +1 -1
  47. package/dist/index.js +4 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/index.native.js.map +1 -1
  51. package/dist/patches/builtInDepPatches.js +13 -3
  52. package/dist/patches/builtInDepPatches.js.map +1 -1
  53. package/dist/patches/builtInDepPatches.mjs.map +1 -1
  54. package/dist/patches/builtInDepPatches.native.js.map +1 -1
  55. package/dist/plugins/autoDepOptimizePlugin.js +17 -4
  56. package/dist/plugins/autoDepOptimizePlugin.js.map +1 -1
  57. package/dist/plugins/autoDepOptimizePlugin.mjs.map +1 -1
  58. package/dist/plugins/autoDepOptimizePlugin.native.js.map +1 -1
  59. package/dist/plugins/expoManifestRequestHandlerPlugin.js +12 -11
  60. package/dist/plugins/expoManifestRequestHandlerPlugin.js.map +1 -1
  61. package/dist/plugins/expoManifestRequestHandlerPlugin.mjs +1 -1
  62. package/dist/plugins/expoManifestRequestHandlerPlugin.mjs.map +1 -1
  63. package/dist/plugins/expoManifestRequestHandlerPlugin.native.js +1 -1
  64. package/dist/plugins/expoManifestRequestHandlerPlugin.native.js.map +1 -1
  65. package/dist/plugins/reactNativeCommonJsPlugin.js +4 -2
  66. package/dist/plugins/reactNativeCommonJsPlugin.js.map +1 -1
  67. package/dist/plugins/reactNativeCommonJsPlugin.mjs +1 -1
  68. package/dist/plugins/reactNativeCommonJsPlugin.mjs.map +1 -1
  69. package/dist/plugins/reactNativeCommonJsPlugin.native.js +1 -1
  70. package/dist/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
  71. package/dist/plugins/reactNativeDevAssetPlugin.js +16 -2
  72. package/dist/plugins/reactNativeDevAssetPlugin.js.map +1 -1
  73. package/dist/plugins/reactNativeDevAssetPlugin.mjs.map +1 -1
  74. package/dist/plugins/reactNativeDevAssetPlugin.native.js.map +1 -1
  75. package/dist/plugins/reactNativeHMRPlugin.js +17 -3
  76. package/dist/plugins/reactNativeHMRPlugin.js.map +1 -1
  77. package/dist/plugins/reactNativeHMRPlugin.mjs.map +1 -1
  78. package/dist/plugins/reactNativeHMRPlugin.native.js.map +1 -1
  79. package/dist/plugins/resolveIdScan.test.js +3 -6
  80. package/dist/plugins/resolveIdScan.test.js.map +1 -1
  81. package/dist/plugins/resolveIdScan.test.mjs.map +1 -1
  82. package/dist/plugins/resolveIdScan.test.native.js.map +1 -1
  83. package/dist/plugins/rollupRemoveUnusedImports.js +1 -1
  84. package/dist/plugins/rollupRemoveUnusedImports.js.map +1 -1
  85. package/dist/plugins/rollupRemoveUnusedImports.mjs +1 -1
  86. package/dist/plugins/rollupRemoveUnusedImports.mjs.map +1 -1
  87. package/dist/plugins/rollupRemoveUnusedImports.native.js +1 -1
  88. package/dist/plugins/rollupRemoveUnusedImports.native.js.map +1 -1
  89. package/dist/rn-commands/bundle/buildBundle.js +3 -5
  90. package/dist/rn-commands/bundle/buildBundle.js.map +1 -1
  91. package/dist/rn-commands/bundle/buildBundle.mjs +10 -13
  92. package/dist/rn-commands/bundle/buildBundle.mjs.map +1 -1
  93. package/dist/rn-commands/bundle/buildBundle.native.js +3 -5
  94. package/dist/rn-commands/bundle/buildBundle.native.js.map +1 -1
  95. package/dist/user-interface/index.js +15 -6
  96. package/dist/user-interface/index.js.map +1 -1
  97. package/dist/user-interface/index.mjs.map +1 -1
  98. package/dist/user-interface/index.native.js.map +1 -1
  99. package/dist/utils/expoRun.js +4 -2
  100. package/dist/utils/expoRun.js.map +1 -1
  101. package/dist/utils/expoRun.mjs.map +1 -1
  102. package/dist/utils/expoRun.native.js.map +1 -1
  103. package/dist/utils/getReactNativeBundle.js +12 -7
  104. package/dist/utils/getReactNativeBundle.js.map +1 -1
  105. package/dist/utils/getReactNativeBundle.mjs.map +1 -1
  106. package/dist/utils/getReactNativeBundle.native.js.map +1 -1
  107. package/dist/utils/getVitePath.js.map +1 -1
  108. package/dist/utils/getVitePath.mjs.map +1 -1
  109. package/dist/utils/getVitePath.native.js.map +1 -1
  110. package/dist/utils/patches.js +12 -3
  111. package/dist/utils/patches.js.map +1 -1
  112. package/dist/utils/patches.mjs.map +1 -1
  113. package/dist/utils/patches.native.js.map +1 -1
  114. package/dist/utils/scanDepsToOptimize.js +8 -3
  115. package/dist/utils/scanDepsToOptimize.js.map +1 -1
  116. package/dist/utils/scanDepsToOptimize.mjs +1 -1
  117. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  118. package/dist/utils/scanDepsToOptimize.native.js +1 -1
  119. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  120. package/dist/utils/swapPrebuiltReactModules.js +8 -2
  121. package/dist/utils/swapPrebuiltReactModules.js.map +1 -1
  122. package/dist/utils/swapPrebuiltReactModules.mjs.map +1 -1
  123. package/dist/utils/swapPrebuiltReactModules.native.js.map +1 -1
  124. package/dist/utils/utils.js.map +1 -1
  125. package/dist/utils/utils.mjs.map +1 -1
  126. package/dist/utils/utils.native.js.map +1 -1
  127. package/dist/worker.js +15 -12
  128. package/dist/worker.js.map +1 -1
  129. package/dist/worker.mjs.map +1 -1
  130. package/dist/worker.native.js.map +1 -1
  131. package/expo-js-native-debugging-plugin.cjs +9 -2
  132. package/expo-plugin.cjs +26 -9
  133. package/package.json +13 -13
  134. package/react-native-template.js +25 -13
  135. package/src/cli.ts +12 -5
  136. package/src/config/getBaseVitePlugins.ts +4 -1
  137. package/src/config/getOptionsFilled.ts +9 -4
  138. package/src/config/getReactNativeBuildConfig.ts +7 -2
  139. package/src/config/getViteServerConfig.ts +4 -1
  140. package/src/config/mergeUserConfig.ts +3 -3
  141. package/src/exports/build.ts +16 -5
  142. package/src/exports/dev.ts +3 -2
  143. package/src/exports/loadEnv.ts +17 -11
  144. package/src/exports/prebuild.ts +13 -3
  145. package/src/exports/serveStaticAssets.ts +4 -1
  146. package/src/index.ts +5 -1
  147. package/src/patches/builtInDepPatches.ts +14 -4
  148. package/src/plugins/autoDepOptimizePlugin.ts +18 -5
  149. package/src/plugins/clientInjectPlugin.ts +1 -1
  150. package/src/plugins/expoManifestRequestHandlerPlugin.ts +23 -19
  151. package/src/plugins/reactNativeCommonJsPlugin.ts +4 -2
  152. package/src/plugins/reactNativeDevAssetPlugin.ts +22 -4
  153. package/src/plugins/reactNativeHMRPlugin.ts +18 -4
  154. package/src/plugins/resolveIdScan.test.ts +8 -7
  155. package/src/plugins/rollupRemoveUnusedImports.ts +1 -1
  156. package/src/rn-commands/bundle/buildBundle.ts +1 -3
  157. package/src/types.ts +14 -3
  158. package/src/user-interface/index.ts +21 -6
  159. package/src/utils/expoRun.ts +8 -2
  160. package/src/utils/getReactNativeBundle.ts +13 -7
  161. package/src/utils/getVitePath.ts +4 -1
  162. package/src/utils/patches.ts +20 -6
  163. package/src/utils/scanDepsToOptimize.ts +16 -6
  164. package/src/utils/swapPrebuiltReactModules.ts +13 -3
  165. package/src/utils/utils.ts +4 -1
  166. package/src/worker.ts +19 -16
  167. package/types/config/getBaseVitePlugins.d.ts.map +1 -1
  168. package/types/config/getOptionsFilled.d.ts.map +1 -1
  169. package/types/config/getViteServerConfig.d.ts.map +1 -1
  170. package/types/exports/build.d.ts.map +1 -1
  171. package/types/exports/dev.d.ts.map +1 -1
  172. package/types/exports/loadEnv.d.ts.map +1 -1
  173. package/types/exports/prebuild.d.ts.map +1 -1
  174. package/types/exports/serveStaticAssets.d.ts.map +1 -1
  175. package/types/index.d.ts +1 -1
  176. package/types/index.d.ts.map +1 -1
  177. package/types/patches/builtInDepPatches.d.ts.map +1 -1
  178. package/types/plugins/autoDepOptimizePlugin.d.ts +1 -1
  179. package/types/plugins/autoDepOptimizePlugin.d.ts.map +1 -1
  180. package/types/plugins/expoManifestRequestHandlerPlugin.d.ts.map +1 -1
  181. package/types/plugins/reactNativeCommonJsPlugin.d.ts.map +1 -1
  182. package/types/plugins/reactNativeDevAssetPlugin.d.ts.map +1 -1
  183. package/types/plugins/reactNativeHMRPlugin.d.ts.map +1 -1
  184. package/types/rn-commands/bundle/buildBundle.d.ts.map +1 -1
  185. package/types/types.d.ts.map +1 -1
  186. package/types/utils/expoRun.d.ts.map +1 -1
  187. package/types/utils/getReactNativeBundle.d.ts.map +1 -1
  188. package/types/utils/getVitePath.d.ts.map +1 -1
  189. package/types/utils/patches.d.ts.map +1 -1
  190. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
  191. package/types/utils/swapPrebuiltReactModules.d.ts.map +1 -1
  192. package/types/utils/utils.d.ts.map +1 -1
  193. /package/types/utils/{filterPluginsForNative.d.ts → filterPluginsforNative.d.ts} +0 -0
@@ -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['.'] = {
@@ -450,8 +454,14 @@ export const addCustomSourceTransformer = resolveAssetSource.addCustomSourceTran
450
454
  patchFiles: {
451
455
  '**/*.js': (contents) =>
452
456
  contents
453
- ?.replace(/punycode\.ucs2\.decode/gm, '(punycode.ucs2decode || punycode.ucs2.decode)')
454
- ?.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
+ ),
455
465
  },
456
466
  },
457
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
  })
@@ -114,7 +114,9 @@ export function reactNativeHMRPlugin({
114
114
 
115
115
  source = transformResult.code
116
116
  } catch (e) {
117
- console.warn(`Error transforming source for HMR: ${e}. Retrying without plugins.`)
117
+ console.warn(
118
+ `Error transforming source for HMR: ${e}. Retrying without plugins.`
119
+ )
118
120
  source = (await transformSWCStripJSX(id, source))?.code || ''
119
121
  }
120
122
 
@@ -155,11 +157,20 @@ export function reactNativeHMRPlugin({
155
157
  const resolver: ResolveFn = idResolver.bind(null, environment)
156
158
  const resolverWithPlugins: ResolveFn = async (id, importer) => {
157
159
  // Need this since `idResolver` will not run through user plugins, but we might need plugins like `vite-tsconfig-paths` to work if they are used
158
- const resolvedIdData = await environment.pluginContainer.resolveId(id, importer)
160
+ const resolvedIdData = await environment.pluginContainer.resolveId(
161
+ id,
162
+ importer
163
+ )
159
164
  return resolvedIdData?.id
160
165
  }
161
166
 
162
- let id = await getVitePath(entryRoot, file, importName, resolver, resolverWithPlugins)
167
+ let id = await getVitePath(
168
+ entryRoot,
169
+ file,
170
+ importName,
171
+ resolver,
172
+ resolverWithPlugins
173
+ )
163
174
  if (!id) {
164
175
  console.warn('???')
165
176
  continue
@@ -207,7 +218,10 @@ export function reactNativeHMRPlugin({
207
218
  ${source
208
219
  .replace(`import.meta.hot.accept(() => {})`, ``)
209
220
  // replace import.meta.glob with empty array in hot reloads
210
- .replaceAll(/import.meta.glob\(.*\)/gi, `globalThis['__importMetaGlobbed'] || {}`)};
221
+ .replaceAll(
222
+ /import.meta.glob\(.*\)/gi,
223
+ `globalThis['__importMetaGlobbed'] || {}`
224
+ )};
211
225
  return exports })({})`
212
226
 
213
227
  if (process.env.DEBUG) {
@@ -20,7 +20,11 @@ describe('resolveId hooks should skip during dep optimization scan', () => {
20
20
 
21
21
  // Find the platform-specific-resolve plugin
22
22
  const plugin = plugins.find(
23
- (p) => typeof p === 'object' && p !== null && 'name' in p && p.name === 'platform-specific-resolve'
23
+ (p) =>
24
+ typeof p === 'object' &&
25
+ p !== null &&
26
+ 'name' in p &&
27
+ p.name === 'platform-specific-resolve'
24
28
  )
25
29
 
26
30
  expect(plugin).toBeDefined()
@@ -37,12 +41,9 @@ describe('resolveId hooks should skip during dep optimization scan', () => {
37
41
  }
38
42
 
39
43
  // When scan is true, should return undefined (skip processing)
40
- const result = await resolveId.call(
41
- mockContext,
42
- 'some-module',
43
- '/importer.ts',
44
- { scan: true }
45
- )
44
+ const result = await resolveId.call(mockContext, 'some-module', '/importer.ts', {
45
+ scan: true,
46
+ })
46
47
 
47
48
  expect(result).toBeUndefined()
48
49
  // Should NOT have called resolve when scan is true
@@ -4,7 +4,7 @@ export const rollupRemoveUnusedImportsPlugin = {
4
4
  // Use a simple regex or AST parser to remove unused imports
5
5
  // Here, we use a regex to remove all imports, adapt as needed
6
6
  return {
7
- code: code.replace(/import\s+['"][a-zA-Z0-9\_\-\@]+['"];\n/g, ''),
7
+ code: code.replace(/import\s+['"][a-zA-Z0-9_\-@]+['"];\n/g, ''),
8
8
  map: null,
9
9
  }
10
10
  },
@@ -92,9 +92,7 @@ export async function buildBundle(
92
92
  const optionsIn = {
93
93
  root,
94
94
  host: '0.0.0.0', // TODO: Hardcoded for now.
95
- entries: {
96
- ...(nativeEntry ? { native: nativeEntry } : {}),
97
- },
95
+ entries: nativeEntry ? { native: nativeEntry } : {},
98
96
  }
99
97
 
100
98
  const options = await fillOptions(optionsIn, { mode: dev ? 'dev' : 'prod' })
package/src/types.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Hono } from 'hono'
2
- import type { OutputAsset, OutputChunk, TreeshakingOptions, TreeshakingPreset } from 'rollup'
2
+ import type {
3
+ OutputAsset,
4
+ OutputChunk,
5
+ TreeshakingOptions,
6
+ TreeshakingPreset,
7
+ } from 'rollup'
3
8
  import type { FilterPattern, InlineConfig, UserConfig } from 'vite'
4
9
 
5
10
  type RollupOutputList = [OutputChunk, ...(OutputChunk | OutputAsset)[]]
@@ -137,6 +142,12 @@ export type VXRNServeOptionsFilled = Required<VXRNServeOptionsBase> & {
137
142
 
138
143
  export type VXRNServeOptions = VXRNServeOptionsBase & {
139
144
  app?: Hono
140
- beforeRegisterRoutes?: (options: VXRNServeOptionsFilled, app: Hono) => void | Promise<void>
141
- afterRegisterRoutes?: (options: VXRNServeOptionsFilled, app: Hono) => void | Promise<void>
145
+ beforeRegisterRoutes?: (
146
+ options: VXRNServeOptionsFilled,
147
+ app: Hono
148
+ ) => void | Promise<void>
149
+ afterRegisterRoutes?: (
150
+ options: VXRNServeOptionsFilled,
151
+ app: Hono
152
+ ) => void | Promise<void>
142
153
  }
@@ -132,7 +132,10 @@ export async function startUserInterface(context: Context) {
132
132
  }
133
133
 
134
134
  function printCommandsTable(context: Context) {
135
- const longestKeyLength = COMMANDS.reduce((max, command) => Math.max(max, command.keys.length), 0)
135
+ const longestKeyLength = COMMANDS.reduce(
136
+ (max, command) => Math.max(max, command.keys.length),
137
+ 0
138
+ )
136
139
 
137
140
  const commandsInfo = COMMANDS.map((cmd) =>
138
141
  getCommandInfoInTerminal(cmd, { longestKeyLength })
@@ -214,12 +217,16 @@ function handleKeypress(context: Context, key: string) {
214
217
 
215
218
  if (pressedKeys.length >= 3) {
216
219
  clearPrintedInfo()
217
- console.info(`> ${pressedKeys}\nNo matching command for "${pressedKeys}"! Press "?" for help.`)
220
+ console.info(
221
+ `> ${pressedKeys}\nNo matching command for "${pressedKeys}"! Press "?" for help.`
222
+ )
218
223
  pressedKeys = ''
219
224
  return
220
225
  }
221
226
 
222
- const possibleCommands = COMMANDS.filter((command) => command.keys.startsWith(pressedKeys))
227
+ const possibleCommands = COMMANDS.filter((command) =>
228
+ command.keys.startsWith(pressedKeys)
229
+ )
223
230
 
224
231
  const commandsInfo = possibleCommands
225
232
  .map((command) => {
@@ -260,7 +267,11 @@ async function printNativeQrCodeAndInstructions(url: string) {
260
267
 
261
268
  function nativeOpen(url: string) {
262
269
  const start =
263
- process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'
270
+ process.platform === 'darwin'
271
+ ? 'open'
272
+ : process.platform === 'win32'
273
+ ? 'start'
274
+ : 'xdg-open'
264
275
 
265
276
  exec(`${start} ${url}`)
266
277
  }
@@ -310,7 +321,9 @@ async function openAndroid(ctx: Context) {
310
321
  paths: [projectRoot],
311
322
  }
312
323
  )
313
- const androidPlatformManagerModule = await import(androidPlatformManagerModuleImportPath)
324
+ const androidPlatformManagerModule = await import(
325
+ androidPlatformManagerModuleImportPath
326
+ )
314
327
  const PlatformManager = androidPlatformManagerModule.default.AndroidPlatformManager
315
328
 
316
329
  // TODO: Support dev client
@@ -327,7 +340,9 @@ async function openAndroid(ctx: Context) {
327
340
  await platformManager.openAsync({ runtime: 'expo' })
328
341
  } catch (e) {
329
342
  const stack = e instanceof Error ? e.stack : null
330
- console.error(`Failed to open app in Android Emulator: ${e}${stack ? `\n${stack}` : ''}`)
343
+ console.error(
344
+ `Failed to open app in Android Emulator: ${e}${stack ? `\n${stack}` : ''}`
345
+ )
331
346
  }
332
347
  }
333
348
 
@@ -6,7 +6,11 @@ export async function expoRun({
6
6
  root,
7
7
  platform,
8
8
  port,
9
- }: { root: string; platform: 'ios' | 'android'; port?: number }) {
9
+ }: {
10
+ root: string
11
+ platform: 'ios' | 'android'
12
+ port?: number
13
+ }) {
10
14
  const options = await fillOptions({ root })
11
15
 
12
16
  applyBuiltInPatches(options).catch((err) => {
@@ -30,6 +34,8 @@ export async function expoRun({
30
34
  // `${port || 8081}`,
31
35
  ])
32
36
  } catch (e) {
33
- console.error(`Failed to run native project: ${e}\nIs "expo" listed in your dependencies?`)
37
+ console.error(
38
+ `Failed to run native project: ${e}\nIs "expo" listed in your dependencies?`
39
+ )
34
40
  }
35
41
  }
@@ -7,7 +7,10 @@ import type { VXRNOptionsFilled } from '../config/getOptionsFilled'
7
7
  import { getReactNativeBuildConfig } from '../config/getReactNativeBuildConfig'
8
8
  import { filterPluginsForNative } from './filterPluginsForNative'
9
9
  import { getCacheDir } from './getCacheDir'
10
- import { isBuildingNativeBundle, setIsBuildingNativeBundle } from './isBuildingNativeBundle'
10
+ import {
11
+ isBuildingNativeBundle,
12
+ setIsBuildingNativeBundle,
13
+ } from './isBuildingNativeBundle'
11
14
  import { prebuildReactNativeModules } from './swapPrebuiltReactModules'
12
15
 
13
16
  // used for normalizing hot reloads
@@ -58,7 +61,9 @@ export async function getReactNativeBundle(
58
61
  // build app
59
62
  const nativeBuildConfig = await getReactNativeBuildConfig(options, internal, platform)
60
63
 
61
- nativeBuildConfig.plugins = filterPluginsForNative(nativeBuildConfig.plugins, { isNative: true })
64
+ nativeBuildConfig.plugins = filterPluginsForNative(nativeBuildConfig.plugins, {
65
+ isNative: true,
66
+ })
62
67
 
63
68
  // instrument plugins:
64
69
  const buildStats: Record<string, number> = {}
@@ -125,10 +130,8 @@ export async function getReactNativeBundle(
125
130
  const importsMap = {}
126
131
  for (const imp of outputModule.imports) {
127
132
  const relativePath = relative(dirname(id), imp)
128
- importsMap[relativePath[0] === '.' ? relativePath : './' + relativePath] = imp.replace(
129
- /.*node_modules\//,
130
- ''
131
- )
133
+ importsMap[relativePath[0] === '.' ? relativePath : './' + relativePath] =
134
+ imp.replace(/.*node_modules\//, '')
132
135
  }
133
136
 
134
137
  let code = outputModule.code
@@ -222,7 +225,10 @@ async function getReactNativeTemplate(mode: 'dev' | 'prod') {
222
225
  template = template.replace(/process\.env\.DEBUG/g, 'undefined')
223
226
 
224
227
  // In production mode, the prebuilt modules have `.production` in their filenames
225
- template = template.replaceAll('.vxrn/react-jsx-runtime.js', '.vxrn/react-jsx-runtime.production.js')
228
+ template = template.replaceAll(
229
+ '.vxrn/react-jsx-runtime.js',
230
+ '.vxrn/react-jsx-runtime.production.js'
231
+ )
226
232
  template = template.replaceAll('.vxrn/react.js', '.vxrn/react.production.js')
227
233
  // react-native already has platform in filename, need to add .production before platform
228
234
  template = template.replace(
@@ -7,7 +7,10 @@ export async function getVitePath(
7
7
  importer: string,
8
8
  moduleName: string,
9
9
  resolver: (moduleName: string, importer: string) => Promise<string | undefined>,
10
- resolverWithPlugins: (moduleName: string, importer: string) => Promise<string | undefined>,
10
+ resolverWithPlugins: (
11
+ moduleName: string,
12
+ importer: string
13
+ ) => Promise<string | undefined>,
11
14
  absolute = false
12
15
  ) {
13
16
  // our virtual modules