@expo/cli 0.11.0 → 0.12.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 (281) hide show
  1. package/build/bin/cli +2 -2
  2. package/build/src/api/getExpoGoIntermediateCertificate.js +1 -1
  3. package/build/src/api/getExpoGoIntermediateCertificate.js.map +1 -1
  4. package/build/src/api/getExpoSchema.js +1 -1
  5. package/build/src/api/getExpoSchema.js.map +1 -1
  6. package/build/src/api/getNativeModuleVersions.js +1 -1
  7. package/build/src/api/getNativeModuleVersions.js.map +1 -1
  8. package/build/src/api/getProjectDevelopmentCertificate.js +1 -1
  9. package/build/src/api/getProjectDevelopmentCertificate.js.map +1 -1
  10. package/build/src/api/getVersions.js +1 -1
  11. package/build/src/api/getVersions.js.map +1 -1
  12. package/build/src/api/rest/cache/wrapFetchWithCache.js.map +1 -1
  13. package/build/src/api/rest/client.js +5 -5
  14. package/build/src/api/rest/client.js.map +1 -1
  15. package/build/src/api/rest/wrapFetchWithOffline.js.map +1 -1
  16. package/build/src/api/rest/wrapFetchWithProgress.js.map +1 -1
  17. package/build/src/api/rest/wrapFetchWithProxy.js.map +1 -1
  18. package/build/src/api/updateDevelopmentSession.js +1 -1
  19. package/build/src/api/updateDevelopmentSession.js.map +1 -1
  20. package/build/src/api/user/actions.js +2 -2
  21. package/build/src/api/user/actions.js.map +1 -1
  22. package/build/src/api/user/otp.js +1 -1
  23. package/build/src/api/user/otp.js.map +1 -1
  24. package/build/src/api/user/user.js +2 -2
  25. package/build/src/api/user/user.js.map +1 -1
  26. package/build/src/config/configAsync.js +17 -1
  27. package/build/src/config/configAsync.js.map +1 -1
  28. package/build/src/customize/customizeAsync.js +1 -1
  29. package/build/src/customize/customizeAsync.js.map +1 -1
  30. package/build/src/customize/generate.js +29 -2
  31. package/build/src/customize/generate.js.map +1 -1
  32. package/build/src/customize/templates.js +8 -0
  33. package/build/src/customize/templates.js.map +1 -1
  34. package/build/src/customize/typescript.js +54 -0
  35. package/build/src/customize/typescript.js.map +1 -0
  36. package/build/src/export/createBundles.js +1 -1
  37. package/build/src/export/createBundles.js.map +1 -1
  38. package/build/src/export/createMetadataJson.js.map +1 -1
  39. package/build/src/export/embed/exportEmbedAsync.js +50 -4
  40. package/build/src/export/embed/exportEmbedAsync.js.map +1 -1
  41. package/build/src/export/embed/index.js +1 -3
  42. package/build/src/export/embed/index.js.map +1 -1
  43. package/build/src/export/embed/resolveOptions.js +6 -10
  44. package/build/src/export/embed/resolveOptions.js.map +1 -1
  45. package/build/src/export/exportApp.js +50 -41
  46. package/build/src/export/exportApp.js.map +1 -1
  47. package/build/src/export/exportAssets.js +2 -2
  48. package/build/src/export/exportAssets.js.map +1 -1
  49. package/build/src/export/exportAsync.js +1 -1
  50. package/build/src/export/exportAsync.js.map +1 -1
  51. package/build/src/export/exportStaticAsync.js +42 -12
  52. package/build/src/export/exportStaticAsync.js.map +1 -1
  53. package/build/src/export/fork-bundleAsync.js +27 -2
  54. package/build/src/export/fork-bundleAsync.js.map +1 -1
  55. package/build/src/export/getPublicExpoManifest.js +1 -1
  56. package/build/src/export/getPublicExpoManifest.js.map +1 -1
  57. package/build/src/export/getResolvedLocales.js.map +1 -1
  58. package/build/src/export/printBundleSizes.js.map +1 -1
  59. package/build/src/export/web/exportWebAsync.js.map +1 -1
  60. package/build/src/export/writeContents.js +5 -1
  61. package/build/src/export/writeContents.js.map +1 -1
  62. package/build/src/install/checkPackages.js +1 -1
  63. package/build/src/install/checkPackages.js.map +1 -1
  64. package/build/src/install/installAsync.js +1 -1
  65. package/build/src/install/installAsync.js.map +1 -1
  66. package/build/src/prebuild/configureProjectAsync.js +5 -9
  67. package/build/src/prebuild/configureProjectAsync.js.map +1 -1
  68. package/build/src/prebuild/prebuildAsync.js +5 -5
  69. package/build/src/prebuild/prebuildAsync.js.map +1 -1
  70. package/build/src/prebuild/updateFromTemplate.js +8 -5
  71. package/build/src/prebuild/updateFromTemplate.js.map +1 -1
  72. package/build/src/register/registerAsync.js +0 -1
  73. package/build/src/register/registerAsync.js.map +1 -1
  74. package/build/src/run/android/resolveInstallApkName.js.map +1 -1
  75. package/build/src/run/android/resolveOptions.js +1 -1
  76. package/build/src/run/android/resolveOptions.js.map +1 -1
  77. package/build/src/run/android/runAndroidAsync.js +2 -2
  78. package/build/src/run/android/runAndroidAsync.js.map +1 -1
  79. package/build/src/run/ios/XcodeBuild.js +2 -2
  80. package/build/src/run/ios/XcodeBuild.js.map +1 -1
  81. package/build/src/run/ios/appleDevice/AppleDevice.js +4 -4
  82. package/build/src/run/ios/appleDevice/AppleDevice.js.map +1 -1
  83. package/build/src/run/ios/appleDevice/ClientManager.js +1 -1
  84. package/build/src/run/ios/appleDevice/ClientManager.js.map +1 -1
  85. package/build/src/run/ios/appleDevice/client/AFCClient.js +1 -1
  86. package/build/src/run/ios/appleDevice/client/AFCClient.js.map +1 -1
  87. package/build/src/run/ios/appleDevice/client/DebugserverClient.js +1 -1
  88. package/build/src/run/ios/appleDevice/client/DebugserverClient.js.map +1 -1
  89. package/build/src/run/ios/appleDevice/client/InstallationProxyClient.js +1 -1
  90. package/build/src/run/ios/appleDevice/client/InstallationProxyClient.js.map +1 -1
  91. package/build/src/run/ios/appleDevice/client/LockdowndClient.js +1 -1
  92. package/build/src/run/ios/appleDevice/client/LockdowndClient.js.map +1 -1
  93. package/build/src/run/ios/appleDevice/client/MobileImageMounterClient.js +1 -1
  94. package/build/src/run/ios/appleDevice/client/MobileImageMounterClient.js.map +1 -1
  95. package/build/src/run/ios/appleDevice/client/ServiceClient.js.map +1 -1
  96. package/build/src/run/ios/appleDevice/client/UsbmuxdClient.js +1 -1
  97. package/build/src/run/ios/appleDevice/client/UsbmuxdClient.js.map +1 -1
  98. package/build/src/run/ios/appleDevice/installOnDeviceAsync.js +1 -1
  99. package/build/src/run/ios/appleDevice/installOnDeviceAsync.js.map +1 -1
  100. package/build/src/run/ios/appleDevice/protocol/AFCProtocol.js +1 -1
  101. package/build/src/run/ios/appleDevice/protocol/AFCProtocol.js.map +1 -1
  102. package/build/src/run/ios/appleDevice/protocol/AbstractProtocol.js.map +1 -1
  103. package/build/src/run/ios/appleDevice/protocol/GDBProtocol.js +1 -1
  104. package/build/src/run/ios/appleDevice/protocol/GDBProtocol.js.map +1 -1
  105. package/build/src/run/ios/appleDevice/protocol/LockdownProtocol.js +1 -1
  106. package/build/src/run/ios/appleDevice/protocol/LockdownProtocol.js.map +1 -1
  107. package/build/src/run/ios/codeSigning/configureCodeSigning.js +1 -1
  108. package/build/src/run/ios/codeSigning/configureCodeSigning.js.map +1 -1
  109. package/build/src/run/ios/codeSigning/resolveCertificateSigningIdentity.js +2 -2
  110. package/build/src/run/ios/codeSigning/resolveCertificateSigningIdentity.js.map +1 -1
  111. package/build/src/run/ios/codeSigning/xcodeCodeSigning.js +3 -0
  112. package/build/src/run/ios/codeSigning/xcodeCodeSigning.js.map +1 -1
  113. package/build/src/run/ios/index.js.map +1 -1
  114. package/build/src/run/ios/launchApp.js +2 -2
  115. package/build/src/run/ios/launchApp.js.map +1 -1
  116. package/build/src/run/ios/options/resolveDevice.js +1 -1
  117. package/build/src/run/ios/options/resolveDevice.js.map +1 -1
  118. package/build/src/run/ios/options/resolveOptions.js +2 -2
  119. package/build/src/run/ios/options/resolveOptions.js.map +1 -1
  120. package/build/src/run/ios/runIosAsync.js +3 -3
  121. package/build/src/run/ios/runIosAsync.js.map +1 -1
  122. package/build/src/start/doctor/apple/XcodePrerequisite.js +43 -2
  123. package/build/src/start/doctor/apple/XcodePrerequisite.js.map +1 -1
  124. package/build/src/start/doctor/dependencies/ensureDependenciesAsync.js +1 -1
  125. package/build/src/start/doctor/dependencies/ensureDependenciesAsync.js.map +1 -1
  126. package/build/src/start/doctor/dependencies/getVersionedPackages.js +5 -3
  127. package/build/src/start/doctor/dependencies/getVersionedPackages.js.map +1 -1
  128. package/build/src/start/doctor/dependencies/validateDependenciesVersions.js +1 -1
  129. package/build/src/start/doctor/dependencies/validateDependenciesVersions.js.map +1 -1
  130. package/build/src/start/doctor/ngrok/ExternalModule.js.map +1 -1
  131. package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js +7 -7
  132. package/build/src/start/doctor/typescript/TypeScriptProjectPrerequisite.js.map +1 -1
  133. package/build/src/start/doctor/typescript/updateTSConfig.js +11 -10
  134. package/build/src/start/doctor/typescript/updateTSConfig.js.map +1 -1
  135. package/build/src/start/index.js +0 -2
  136. package/build/src/start/index.js.map +1 -1
  137. package/build/src/start/interface/interactiveActions.js +1 -1
  138. package/build/src/start/interface/interactiveActions.js.map +1 -1
  139. package/build/src/start/interface/startInterface.js +3 -3
  140. package/build/src/start/interface/startInterface.js.map +1 -1
  141. package/build/src/start/platforms/ExpoGoInstaller.js.map +1 -1
  142. package/build/src/start/platforms/PlatformManager.js.map +1 -1
  143. package/build/src/start/platforms/android/ADBServer.js +1 -1
  144. package/build/src/start/platforms/android/ADBServer.js.map +1 -1
  145. package/build/src/start/platforms/android/AndroidDeviceManager.js +5 -5
  146. package/build/src/start/platforms/android/AndroidDeviceManager.js.map +1 -1
  147. package/build/src/start/platforms/android/AndroidPlatformManager.js +1 -1
  148. package/build/src/start/platforms/android/AndroidPlatformManager.js.map +1 -1
  149. package/build/src/start/platforms/android/adb.js +1 -1
  150. package/build/src/start/platforms/android/adb.js.map +1 -1
  151. package/build/src/start/platforms/android/adbReverse.js +2 -2
  152. package/build/src/start/platforms/android/adbReverse.js.map +1 -1
  153. package/build/src/start/platforms/android/emulator.js +1 -1
  154. package/build/src/start/platforms/android/emulator.js.map +1 -1
  155. package/build/src/start/platforms/android/getDevices.js +1 -1
  156. package/build/src/start/platforms/android/getDevices.js.map +1 -1
  157. package/build/src/start/platforms/android/promptAndroidDevice.js +1 -1
  158. package/build/src/start/platforms/android/promptAndroidDevice.js.map +1 -1
  159. package/build/src/start/platforms/ios/AppleDeviceManager.js +5 -5
  160. package/build/src/start/platforms/ios/AppleDeviceManager.js.map +1 -1
  161. package/build/src/start/platforms/ios/ApplePlatformManager.js +1 -1
  162. package/build/src/start/platforms/ios/ApplePlatformManager.js.map +1 -1
  163. package/build/src/start/platforms/ios/ensureSimulatorAppRunning.js.map +1 -1
  164. package/build/src/start/platforms/ios/getBestSimulator.js +1 -1
  165. package/build/src/start/platforms/ios/getBestSimulator.js.map +1 -1
  166. package/build/src/start/platforms/ios/promptAppleDevice.js +1 -1
  167. package/build/src/start/platforms/ios/promptAppleDevice.js.map +1 -1
  168. package/build/src/start/platforms/ios/simctl.js +1 -1
  169. package/build/src/start/platforms/ios/simctl.js.map +1 -1
  170. package/build/src/start/platforms/ios/simctlLogging.js +1 -1
  171. package/build/src/start/platforms/ios/simctlLogging.js.map +1 -1
  172. package/build/src/start/resolveOptions.js +0 -5
  173. package/build/src/start/resolveOptions.js.map +1 -1
  174. package/build/src/start/server/AsyncNgrok.js +4 -3
  175. package/build/src/start/server/AsyncNgrok.js.map +1 -1
  176. package/build/src/start/server/BundlerDevServer.js +4 -11
  177. package/build/src/start/server/BundlerDevServer.js.map +1 -1
  178. package/build/src/start/server/DevServerManager.js +3 -2
  179. package/build/src/start/server/DevServerManager.js.map +1 -1
  180. package/build/src/start/server/UrlCreator.js +2 -1
  181. package/build/src/start/server/UrlCreator.js.map +1 -1
  182. package/build/src/start/server/getStaticRenderFunctions.js +2 -2
  183. package/build/src/start/server/getStaticRenderFunctions.js.map +1 -1
  184. package/build/src/start/server/metro/MetroBundlerDevServer.js +42 -25
  185. package/build/src/start/server/metro/MetroBundlerDevServer.js.map +1 -1
  186. package/build/src/start/server/metro/MetroTerminalReporter.js +14 -3
  187. package/build/src/start/server/metro/MetroTerminalReporter.js.map +1 -1
  188. package/build/src/start/server/metro/TerminalReporter.js.map +1 -1
  189. package/build/src/start/server/metro/TerminalReporter.types.js.map +1 -1
  190. package/build/src/start/server/metro/inspector-proxy/device.js.map +1 -1
  191. package/build/src/start/server/metro/inspector-proxy/handlers/NetworkResponse.js.map +1 -1
  192. package/build/src/start/server/metro/inspector-proxy/handlers/PageReload.js.map +1 -1
  193. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerGetPossibleBreakpoints.js.map +1 -1
  194. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerScriptParsed.js.map +1 -1
  195. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeDebuggerSetBreakpointByUrl.js.map +1 -1
  196. package/build/src/start/server/metro/inspector-proxy/handlers/VscodeRuntimeGetProperties.js.map +1 -1
  197. package/build/src/start/server/metro/inspector-proxy/handlers/types.js.map +1 -1
  198. package/build/src/start/server/metro/inspector-proxy/index.js +1 -1
  199. package/build/src/start/server/metro/inspector-proxy/index.js.map +1 -1
  200. package/build/src/start/server/metro/instantiateMetro.js +49 -8
  201. package/build/src/start/server/metro/instantiateMetro.js.map +1 -1
  202. package/build/src/start/server/metro/resolveFromProject.js +0 -4
  203. package/build/src/start/server/metro/resolveFromProject.js.map +1 -1
  204. package/build/src/start/server/metro/runServer-fork.js +1 -1
  205. package/build/src/start/server/metro/runServer-fork.js.map +1 -1
  206. package/build/src/start/server/metro/withMetroMultiPlatform.js +59 -9
  207. package/build/src/start/server/metro/withMetroMultiPlatform.js.map +1 -1
  208. package/build/src/start/server/metro/withMetroResolvers.js +6 -5
  209. package/build/src/start/server/metro/withMetroResolvers.js.map +1 -1
  210. package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js +2 -2
  211. package/build/src/start/server/middleware/ExpoGoManifestHandlerMiddleware.js.map +1 -1
  212. package/build/src/start/server/middleware/ExpoMiddleware.js.map +1 -1
  213. package/build/src/start/server/middleware/FaviconMiddleware.js +1 -1
  214. package/build/src/start/server/middleware/FaviconMiddleware.js.map +1 -1
  215. package/build/src/start/server/middleware/ManifestMiddleware.js +8 -11
  216. package/build/src/start/server/middleware/ManifestMiddleware.js.map +1 -1
  217. package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js +1 -1
  218. package/build/src/start/server/middleware/RuntimeRedirectMiddleware.js.map +1 -1
  219. package/build/src/start/server/middleware/ServeStaticMiddleware.js +1 -1
  220. package/build/src/start/server/middleware/ServeStaticMiddleware.js.map +1 -1
  221. package/build/src/start/server/middleware/resolvePlatform.js.map +1 -1
  222. package/build/src/start/server/middleware/server.types.js.map +1 -1
  223. package/build/src/start/server/openPlatforms.js.map +1 -1
  224. package/build/src/start/server/type-generation/__typetests__/fixtures/basic.js.map +1 -1
  225. package/build/src/start/server/type-generation/routes.js +6 -6
  226. package/build/src/start/server/type-generation/routes.js.map +1 -1
  227. package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js +3 -3
  228. package/build/src/start/server/type-generation/startTypescriptTypeGeneration.js.map +1 -1
  229. package/build/src/start/server/webpack/WebpackBundlerDevServer.js +10 -5
  230. package/build/src/start/server/webpack/WebpackBundlerDevServer.js.map +1 -1
  231. package/build/src/start/server/webpack/compile.js +1 -1
  232. package/build/src/start/server/webpack/compile.js.map +1 -1
  233. package/build/src/start/startAsync.js +10 -32
  234. package/build/src/start/startAsync.js.map +1 -1
  235. package/build/src/utils/FileNotifier.js +1 -1
  236. package/build/src/utils/FileNotifier.js.map +1 -1
  237. package/build/src/utils/analytics/metroDebuggerMiddleware.js +1 -1
  238. package/build/src/utils/analytics/metroDebuggerMiddleware.js.map +1 -1
  239. package/build/src/utils/analytics/rudderstackClient.js +2 -2
  240. package/build/src/utils/array.js.map +1 -1
  241. package/build/src/utils/cocoapods.js +2 -2
  242. package/build/src/utils/cocoapods.js.map +1 -1
  243. package/build/src/utils/codesigning.js +2 -2
  244. package/build/src/utils/codesigning.js.map +1 -1
  245. package/build/src/utils/downloadAppAsync.js +1 -1
  246. package/build/src/utils/downloadAppAsync.js.map +1 -1
  247. package/build/src/utils/downloadExpoGoAsync.js +2 -2
  248. package/build/src/utils/downloadExpoGoAsync.js.map +1 -1
  249. package/build/src/utils/editor.js +1 -1
  250. package/build/src/utils/editor.js.map +1 -1
  251. package/build/src/utils/env.js +1 -1
  252. package/build/src/utils/env.js.map +1 -1
  253. package/build/src/utils/errors.js.map +1 -1
  254. package/build/src/utils/getOrPromptApplicationId.js +2 -2
  255. package/build/src/utils/getOrPromptApplicationId.js.map +1 -1
  256. package/build/src/utils/git.js +1 -1
  257. package/build/src/utils/git.js.map +1 -1
  258. package/build/src/utils/modifyConfigAsync.js +1 -1
  259. package/build/src/utils/modifyConfigAsync.js.map +1 -1
  260. package/build/src/utils/modifyConfigPlugins.js +1 -1
  261. package/build/src/utils/modifyConfigPlugins.js.map +1 -1
  262. package/build/src/utils/npm.js +1 -1
  263. package/build/src/utils/npm.js.map +1 -1
  264. package/build/src/utils/obj.js.map +1 -1
  265. package/build/src/utils/plist.js +1 -1
  266. package/build/src/utils/plist.js.map +1 -1
  267. package/build/src/utils/port.js +1 -1
  268. package/build/src/utils/port.js.map +1 -1
  269. package/build/src/utils/profile.js +1 -1
  270. package/build/src/utils/profile.js.map +1 -1
  271. package/build/src/utils/scheme.js +1 -1
  272. package/build/src/utils/scheme.js.map +1 -1
  273. package/build/src/utils/tsconfig/loadTsConfigPaths.js +1 -1
  274. package/build/src/utils/tsconfig/loadTsConfigPaths.js.map +1 -1
  275. package/build/src/utils/validateApplicationId.js +85 -5
  276. package/build/src/utils/validateApplicationId.js.map +1 -1
  277. package/package.json +11 -8
  278. package/build/src/api/signManifest.js +0 -26
  279. package/build/src/api/signManifest.js.map +0 -1
  280. package/build/src/start/server/middleware/ClassicManifestMiddleware.js +0 -155
  281. package/build/src/start/server/middleware/ClassicManifestMiddleware.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/metro/withMetroMultiPlatform.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport { ConfigT } from 'metro-config';\nimport { Resolution, ResolutionContext } from 'metro-resolver';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport { Log } from '../../../log';\nimport { FileNotifier } from '../../../utils/FileNotifier';\nimport { env } from '../../../utils/env';\nimport { installExitHooks } from '../../../utils/exit';\nimport { isInteractive } from '../../../utils/interactive';\nimport { learnMore } from '../../../utils/link';\nimport { loadTsConfigPathsAsync, TsConfigPaths } from '../../../utils/tsconfig/loadTsConfigPaths';\nimport { resolveWithTsConfigPaths } from '../../../utils/tsconfig/resolveWithTsConfigPaths';\nimport { WebSupportProjectPrerequisite } from '../../doctor/web/WebSupportProjectPrerequisite';\nimport { PlatformBundlers } from '../platformBundlers';\nimport {\n EXTERNAL_REQUIRE_NATIVE_POLYFILL,\n EXTERNAL_REQUIRE_POLYFILL,\n getNodeExternalModuleId,\n isNodeExternal,\n setupNodeExternals,\n} from './externals';\nimport { isFailedToResolveNameError, isFailedToResolvePathError } from './metroErrors';\nimport { importMetroResolverFromProject } from './resolveFromProject';\nimport { getAppRouterRelativeEntryPath } from './router';\nimport { withMetroResolvers } from './withMetroResolvers';\n\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] };\n\nconst debug = require('debug')('expo:start:server:metro:multi-platform') as typeof console.log;\n\nfunction withWebPolyfills(config: ConfigT, projectRoot: string): ConfigT {\n const originalGetPolyfills = config.serializer.getPolyfills\n ? config.serializer.getPolyfills.bind(config.serializer)\n : () => [];\n\n const getPolyfills = (ctx: { platform: string | null }): readonly string[] => {\n if (ctx.platform === 'web') {\n return [\n // NOTE: We might need this for all platforms\n path.join(projectRoot, EXTERNAL_REQUIRE_POLYFILL),\n // TODO: runtime polyfills, i.e. Fast Refresh, error overlay, React Dev Tools...\n ];\n }\n // Generally uses `rn-get-polyfills`\n const polyfills = originalGetPolyfills(ctx);\n\n return [...polyfills, EXTERNAL_REQUIRE_NATIVE_POLYFILL];\n };\n\n return {\n ...config,\n serializer: {\n ...config.serializer,\n getPolyfills,\n },\n };\n}\n\nfunction normalizeSlashes(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\n/**\n * Apply custom resolvers to do the following:\n * - Disable `.native.js` extensions on web.\n * - Alias `react-native` to `react-native-web` on web.\n * - Redirect `react-native-web/dist/modules/AssetRegistry/index.js` to `@react-native/assets/registry.js` on web.\n * - Add support for `tsconfig.json`/`jsconfig.json` aliases via `compilerOptions.paths`.\n */\nexport function withExtendedResolver(\n config: ConfigT,\n {\n projectRoot,\n tsconfig,\n platforms,\n isTsconfigPathsEnabled,\n }: {\n projectRoot: string;\n tsconfig: TsConfigPaths | null;\n platforms: string[];\n isTsconfigPathsEnabled?: boolean;\n }\n) {\n // Get the `transformer.assetRegistryPath`\n // this needs to be unified since you can't dynamically\n // swap out the transformer based on platform.\n const assetRegistryPath = fs.realpathSync(\n // This is the native asset registry alias for native.\n path.resolve(resolveFrom(projectRoot, 'react-native/Libraries/Image/AssetRegistry'))\n // NOTE(EvanBacon): This is the newer import but it doesn't work in the expo/expo monorepo.\n // path.resolve(resolveFrom(projectRoot, '@react-native/assets/registry.js'))\n );\n\n const isWebEnabled = platforms.includes('web');\n\n const { resolve } = importMetroResolverFromProject(projectRoot);\n\n const extraNodeModules: { [key: string]: Record<string, string> } = {};\n\n const aliases: { [key: string]: Record<string, string> } = {\n web: {\n 'react-native': 'react-native-web',\n 'react-native/index': 'react-native-web',\n },\n };\n\n if (isWebEnabled) {\n // Allow `react-native-web` to be optional when web is not enabled but path aliases is.\n extraNodeModules['web'] = {\n 'react-native': path.resolve(require.resolve('react-native-web/package.json'), '..'),\n };\n }\n\n const preferredMainFields: { [key: string]: string[] } = {\n // Defaults from Expo Webpack. Most packages using `react-native` don't support web\n // in the `react-native` field, so we should prefer the `browser` field.\n // https://github.com/expo/router/issues/37\n web: ['browser', 'module', 'main'],\n };\n\n let tsConfigResolve = tsconfig?.paths\n ? resolveWithTsConfigPaths.bind(resolveWithTsConfigPaths, {\n paths: tsconfig.paths ?? {},\n baseUrl: tsconfig.baseUrl,\n })\n : null;\n\n if (isTsconfigPathsEnabled && isInteractive()) {\n // TODO: We should track all the files that used imports and invalidate them\n // currently the user will need to save all the files that use imports to\n // use the new aliases.\n const configWatcher = new FileNotifier(projectRoot, ['./tsconfig.json', './jsconfig.json']);\n configWatcher.startObserving(() => {\n debug('Reloading tsconfig.json');\n loadTsConfigPathsAsync(projectRoot).then((tsConfigPaths) => {\n if (tsConfigPaths?.paths && !!Object.keys(tsConfigPaths.paths).length) {\n debug('Enabling tsconfig.json paths support');\n tsConfigResolve = resolveWithTsConfigPaths.bind(resolveWithTsConfigPaths, {\n paths: tsConfigPaths.paths ?? {},\n baseUrl: tsConfigPaths.baseUrl,\n });\n } else {\n debug('Disabling tsconfig.json paths support');\n tsConfigResolve = null;\n }\n });\n });\n\n // TODO: This probably prevents the process from exiting.\n installExitHooks(() => {\n configWatcher.stopObserving();\n });\n } else {\n debug('Skipping tsconfig.json paths support');\n }\n\n return withMetroResolvers(config, projectRoot, [\n // Add a resolver to alias the web asset resolver.\n (immutableContext: ResolutionContext, moduleName: string, platform: string | null) => {\n let context = {\n ...immutableContext,\n } as Mutable<ResolutionContext> & {\n mainFields: string[];\n customResolverOptions?: Record<string, string>;\n };\n\n const environment = context.customResolverOptions?.environment;\n const isNode = environment === 'node';\n\n // TODO: We need to prevent the require.context from including API routes as these use externals.\n // Should be fine after async routes lands.\n if (isNode) {\n const moduleId = isNodeExternal(moduleName);\n if (moduleId) {\n moduleName = getNodeExternalModuleId(context.originModulePath, moduleId);\n debug(`Redirecting Node.js external \"${moduleId}\" to \"${moduleName}\"`);\n }\n }\n\n // Conditionally remap `react-native` to `react-native-web` on web in\n // a way that doesn't require Babel to resolve the alias.\n if (platform && platform in aliases && aliases[platform][moduleName]) {\n moduleName = aliases[platform][moduleName];\n }\n\n // TODO: We may be able to remove this in the future, it's doing no harm\n // by staying here.\n // Conditionally remap `react-native` to `react-native-web`\n if (platform && platform in extraNodeModules) {\n context.extraNodeModules = {\n ...extraNodeModules[platform],\n ...context.extraNodeModules,\n };\n }\n\n if (tsconfig?.baseUrl && isTsconfigPathsEnabled) {\n context = {\n ...context,\n nodeModulesPaths: [\n ...immutableContext.nodeModulesPaths,\n // add last to ensure node modules are resolved first\n tsconfig.baseUrl,\n ],\n };\n }\n\n let mainFields: string[] = context.mainFields;\n\n if (isNode) {\n // Node.js runtimes should only be importing main at the moment.\n // This is a temporary fix until we can support the package.json exports.\n mainFields = ['main'];\n } else if (env.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE) {\n mainFields = context.mainFields;\n } else if (platform && platform in preferredMainFields) {\n mainFields = preferredMainFields[platform];\n }\n function doResolve(moduleName: string): Resolution | null {\n return resolve(\n {\n ...context,\n resolveRequest: undefined,\n mainFields,\n\n // Passing `mainFields` directly won't be considered (in certain version of Metro)\n // we need to extend the `getPackageMainPath` directly to\n // use platform specific `mainFields`.\n // @ts-ignore\n getPackageMainPath(packageJsonPath) {\n // @ts-expect-error: mainFields is not on type\n const package_ = context.moduleCache.getPackage(packageJsonPath);\n return package_.getMain(mainFields);\n },\n },\n moduleName,\n platform\n );\n }\n\n function optionalResolve(moduleName: string): Resolution | null {\n try {\n return doResolve(moduleName);\n } catch (error) {\n // If the error is directly related to a resolver not being able to resolve a module, then\n // we can ignore the error and try the next resolver. Otherwise, we should throw the error.\n const isResolutionError =\n isFailedToResolveNameError(error) || isFailedToResolvePathError(error);\n if (!isResolutionError) {\n throw error;\n }\n }\n return null;\n }\n\n let result: Resolution | null = null;\n\n if (tsConfigResolve) {\n result = tsConfigResolve(\n {\n originModulePath: context.originModulePath,\n moduleName,\n },\n optionalResolve\n );\n }\n\n result ??= doResolve(moduleName);\n\n if (result) {\n // Replace the web resolver with the original one.\n // This is basically an alias for web-only.\n if (shouldAliasAssetRegistryForWeb(platform, result)) {\n // @ts-expect-error: `readonly` for some reason.\n result.filePath = assetRegistryPath;\n }\n }\n return result;\n },\n ]);\n}\n\n/** @returns `true` if the incoming resolution should be swapped on web. */\nexport function shouldAliasAssetRegistryForWeb(\n platform: string | null,\n result: Resolution\n): boolean {\n return (\n platform === 'web' &&\n result?.type === 'sourceFile' &&\n typeof result?.filePath === 'string' &&\n normalizeSlashes(result.filePath).endsWith(\n 'react-native-web/dist/modules/AssetRegistry/index.js'\n )\n );\n}\n\n/** Add support for `react-native-web` and the Web platform. */\nexport async function withMetroMultiPlatformAsync(\n projectRoot: string,\n {\n config,\n platformBundlers,\n isTsconfigPathsEnabled,\n webOutput,\n routerDirectory,\n }: {\n config: ConfigT;\n isTsconfigPathsEnabled: boolean;\n platformBundlers: PlatformBundlers;\n webOutput?: 'single' | 'static';\n routerDirectory: string;\n }\n) {\n // Auto pick app entry for router.\n process.env.EXPO_ROUTER_APP_ROOT = getAppRouterRelativeEntryPath(projectRoot, routerDirectory);\n\n // Required for @expo/metro-runtime to format paths in the web LogBox.\n process.env.EXPO_PUBLIC_PROJECT_ROOT = process.env.EXPO_PUBLIC_PROJECT_ROOT ?? projectRoot;\n\n if (webOutput === 'static') {\n // Enable static rendering in runtime space.\n process.env.EXPO_PUBLIC_USE_STATIC = '1';\n }\n\n // Ensure the cache is invalidated if these values change.\n // @ts-expect-error\n config.transformer._expoRouterRootDirectory = process.env.EXPO_ROUTER_APP_ROOT;\n // @ts-expect-error\n config.transformer._expoRouterWebRendering = webOutput;\n // TODO: import mode\n\n if (platformBundlers.web === 'metro') {\n await new WebSupportProjectPrerequisite(projectRoot).assertAsync();\n } else if (!isTsconfigPathsEnabled) {\n // Bail out early for performance enhancements if no special features are enabled.\n return config;\n }\n\n let tsconfig: null | TsConfigPaths = null;\n\n if (isTsconfigPathsEnabled) {\n Log.warn(\n chalk.yellow`Experimental path aliases feature is enabled. ` +\n learnMore('https://docs.expo.dev/guides/typescript/#path-aliases')\n );\n tsconfig = await loadTsConfigPathsAsync(projectRoot);\n }\n\n await setupNodeExternals(projectRoot);\n\n return withMetroMultiPlatform(projectRoot, {\n config,\n platformBundlers,\n tsconfig,\n isTsconfigPathsEnabled,\n });\n}\n\nfunction withMetroMultiPlatform(\n projectRoot: string,\n {\n config,\n platformBundlers,\n isTsconfigPathsEnabled,\n tsconfig,\n }: {\n config: ConfigT;\n isTsconfigPathsEnabled: boolean;\n platformBundlers: PlatformBundlers;\n tsconfig: TsConfigPaths | null;\n }\n) {\n let expoConfigPlatforms = Object.entries(platformBundlers)\n .filter(([, bundler]) => bundler === 'metro')\n .map(([platform]) => platform);\n\n if (Array.isArray(config.resolver.platforms)) {\n expoConfigPlatforms = [...new Set(expoConfigPlatforms.concat(config.resolver.platforms))];\n }\n\n // @ts-expect-error: typed as `readonly`.\n config.resolver.platforms = expoConfigPlatforms;\n\n if (expoConfigPlatforms.includes('web')) {\n config = withWebPolyfills(config, projectRoot);\n }\n\n return withExtendedResolver(config, {\n projectRoot,\n tsconfig,\n isTsconfigPathsEnabled,\n platforms: expoConfigPlatforms,\n });\n}\n"],"names":["withExtendedResolver","shouldAliasAssetRegistryForWeb","withMetroMultiPlatformAsync","debug","require","withWebPolyfills","config","projectRoot","originalGetPolyfills","serializer","getPolyfills","bind","ctx","platform","path","join","EXTERNAL_REQUIRE_POLYFILL","polyfills","EXTERNAL_REQUIRE_NATIVE_POLYFILL","normalizeSlashes","p","replace","tsconfig","platforms","isTsconfigPathsEnabled","assetRegistryPath","fs","realpathSync","resolve","resolveFrom","isWebEnabled","includes","importMetroResolverFromProject","extraNodeModules","aliases","web","preferredMainFields","tsConfigResolve","paths","resolveWithTsConfigPaths","baseUrl","isInteractive","configWatcher","FileNotifier","startObserving","loadTsConfigPathsAsync","then","tsConfigPaths","Object","keys","length","installExitHooks","stopObserving","withMetroResolvers","immutableContext","moduleName","context","environment","customResolverOptions","isNode","moduleId","isNodeExternal","getNodeExternalModuleId","originModulePath","nodeModulesPaths","mainFields","env","EXPO_METRO_NO_MAIN_FIELD_OVERRIDE","doResolve","resolveRequest","undefined","getPackageMainPath","packageJsonPath","package_","moduleCache","getPackage","getMain","optionalResolve","error","isResolutionError","isFailedToResolveNameError","isFailedToResolvePathError","result","filePath","type","endsWith","platformBundlers","webOutput","routerDirectory","process","EXPO_ROUTER_APP_ROOT","getAppRouterRelativeEntryPath","EXPO_PUBLIC_PROJECT_ROOT","EXPO_PUBLIC_USE_STATIC","transformer","_expoRouterRootDirectory","_expoRouterWebRendering","WebSupportProjectPrerequisite","assertAsync","Log","warn","chalk","yellow","learnMore","setupNodeExternals","withMetroMultiPlatform","expoConfigPlatforms","entries","filter","bundler","map","Array","isArray","resolver","Set","concat"],"mappings":"AAMA;;;;QAwEgBA,oBAAoB,GAApBA,oBAAoB;QAqNpBC,8BAA8B,GAA9BA,8BAA8B;QAexBC,2BAA2B,GAA3BA,2BAA2B;AA5S/B,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAGF,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AAElB,IAAA,IAAc,WAAd,cAAc,CAAA;AACL,IAAA,aAA6B,WAA7B,6BAA6B,CAAA;AACtC,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACP,IAAA,KAAqB,WAArB,qBAAqB,CAAA;AACxB,IAAA,YAA4B,WAA5B,4BAA4B,CAAA;AAChC,IAAA,KAAqB,WAArB,qBAAqB,CAAA;AACO,IAAA,kBAA2C,WAA3C,2CAA2C,CAAA;AACxD,IAAA,yBAAkD,WAAlD,kDAAkD,CAAA;AAC7C,IAAA,8BAAgD,WAAhD,gDAAgD,CAAA;AAQvF,IAAA,UAAa,WAAb,aAAa,CAAA;AACmD,IAAA,YAAe,WAAf,eAAe,CAAA;AACvC,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACvB,IAAA,OAAU,WAAV,UAAU,CAAA;AACrB,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;;;;;;AAIzD,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,wCAAwC,CAAC,AAAsB,AAAC;AAE/F,SAASC,gBAAgB,CAACC,MAAe,EAAEC,WAAmB,EAAW;IACvE,MAAMC,oBAAoB,GAAGF,MAAM,CAACG,UAAU,CAACC,YAAY,GACvDJ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ACJ;AAED,SAASiF,sBAAsB,CAC7BlG,WAAmB,EACnB,EACED,MAAM,CAAA,EACNgF,gBAAgB,CAAA,EAChB9D,sBAAsB,CAAA,EACtBF,QAAQ,CAAA,EAMT,EACD;IACA,IAAIoF,mBAAmB,GAAG1D,MAAM,CAAC2D,OAAO,CAACrB,gBAAgB,CAAC,CACvDsB,MAAM,CAAC,CAAC,GAAGC,OAAO,CAAC,GAAKA,OAAO,KAAK,OAAO;IAAA,CAAC,CAC5CC,GAAG,CAAC,CAAC,CAACjG,QAAQ,CAAC,GAAKA,QAAQ;IAAA,CAAC,AAAC;IAEjC,IAAIkG,KAAK,CAACC,OAAO,CAAC1G,MAAM,CAAC2G,QAAQ,CAAC1F,SAAS,CAAC,EAAE;QAC5CmF,mBAAmB,GAAG;eAAI,IAAIQ,GAAG,CAACR,mBAAmB,CAACS,MAAM,CAAC7G,MAAM,CAAC2G,QAAQ,CAAC1F,SAAS,CAAC,CAAC;SAAC,CAAC;KAC3F;IAED,yCAAyC;IACzCjB,MAAM,CAAC2G,QAAQ,CAAC1F,SAAS,GAAGmF,mBAAmB,CAAC;IAEhD,IAAIA,mBAAmB,CAAC3E,QAAQ,CAAC,KAAK,CAAC,EAAE;QACvCzB,MAAM,GAAGD,gBAAgB,CAACC,MAAM,EAAEC,WAAW,CAAC,CAAC;KAChD;IAED,OAAOP,oBAAoB,CAACM,MAAM,EAAE;QAClCC,WAAW;QACXe,QAAQ;QACRE,sBAAsB;QACtBD,SAAS,EAAEmF,mBAAmB;KAC/B,CAAC,CAAC;CACJ"}
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/withMetroMultiPlatform.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport chalk from 'chalk';\nimport fs from 'fs';\nimport { ConfigT } from 'metro-config';\nimport { Resolution, ResolutionContext } from 'metro-resolver';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\nimport {\n EXTERNAL_REQUIRE_NATIVE_POLYFILL,\n EXTERNAL_REQUIRE_POLYFILL,\n getNodeExternalModuleId,\n isNodeExternal,\n setupNodeExternals,\n} from './externals';\nimport { isFailedToResolveNameError, isFailedToResolvePathError } from './metroErrors';\nimport { importMetroResolverFromProject } from './resolveFromProject';\nimport { getAppRouterRelativeEntryPath } from './router';\nimport { withMetroResolvers } from './withMetroResolvers';\nimport { Log } from '../../../log';\nimport { FileNotifier } from '../../../utils/FileNotifier';\nimport { env } from '../../../utils/env';\nimport { installExitHooks } from '../../../utils/exit';\nimport { isInteractive } from '../../../utils/interactive';\nimport { learnMore } from '../../../utils/link';\nimport { loadTsConfigPathsAsync, TsConfigPaths } from '../../../utils/tsconfig/loadTsConfigPaths';\nimport { resolveWithTsConfigPaths } from '../../../utils/tsconfig/resolveWithTsConfigPaths';\nimport { WebSupportProjectPrerequisite } from '../../doctor/web/WebSupportProjectPrerequisite';\nimport { PlatformBundlers } from '../platformBundlers';\n\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] };\n\nconst debug = require('debug')('expo:start:server:metro:multi-platform') as typeof console.log;\n\nfunction withWebPolyfills(config: ConfigT, projectRoot: string): ConfigT {\n const originalGetPolyfills = config.serializer.getPolyfills\n ? config.serializer.getPolyfills.bind(config.serializer)\n : () => [];\n\n const getPolyfills = (ctx: { platform: string | null }): readonly string[] => {\n if (ctx.platform === 'web') {\n return [\n // NOTE: We might need this for all platforms\n path.join(projectRoot, EXTERNAL_REQUIRE_POLYFILL),\n // TODO: runtime polyfills, i.e. Fast Refresh, error overlay, React Dev Tools...\n ];\n }\n // Generally uses `rn-get-polyfills`\n const polyfills = originalGetPolyfills(ctx);\n\n return [...polyfills, EXTERNAL_REQUIRE_NATIVE_POLYFILL];\n };\n\n return {\n ...config,\n serializer: {\n ...config.serializer,\n getPolyfills,\n },\n };\n}\n\nfunction normalizeSlashes(p: string) {\n return p.replace(/\\\\/g, '/');\n}\n\nexport function getNodejsExtensions(srcExts: readonly string[]): string[] {\n const mjsExts = srcExts.filter((ext) => /mjs$/.test(ext));\n const nodejsSourceExtensions = srcExts.filter((ext) => !/mjs$/.test(ext));\n // find index of last `*.js` extension\n const jsIndex = nodejsSourceExtensions.reduce((index, ext, i) => {\n return /jsx?$/.test(ext) ? i : index;\n }, -1);\n\n // insert `*.mjs` extensions after `*.js` extensions\n nodejsSourceExtensions.splice(jsIndex + 1, 0, ...mjsExts);\n\n return nodejsSourceExtensions;\n}\n\n/**\n * Apply custom resolvers to do the following:\n * - Disable `.native.js` extensions on web.\n * - Alias `react-native` to `react-native-web` on web.\n * - Redirect `react-native-web/dist/modules/AssetRegistry/index.js` to `@react-native/assets/registry.js` on web.\n * - Add support for `tsconfig.json`/`jsconfig.json` aliases via `compilerOptions.paths`.\n */\nexport function withExtendedResolver(\n config: ConfigT,\n {\n projectRoot,\n tsconfig,\n platforms,\n isTsconfigPathsEnabled,\n }: {\n projectRoot: string;\n tsconfig: TsConfigPaths | null;\n platforms: string[];\n isTsconfigPathsEnabled?: boolean;\n }\n) {\n // Get the `transformer.assetRegistryPath`\n // this needs to be unified since you can't dynamically\n // swap out the transformer based on platform.\n const assetRegistryPath = fs.realpathSync(\n // This is the native asset registry alias for native.\n path.resolve(resolveFrom(projectRoot, 'react-native/Libraries/Image/AssetRegistry'))\n // NOTE(EvanBacon): This is the newer import but it doesn't work in the expo/expo monorepo.\n // path.resolve(resolveFrom(projectRoot, '@react-native/assets/registry.js'))\n );\n\n let reactNativeWebAppContainer: string | null = null;\n try {\n reactNativeWebAppContainer = fs.realpathSync(\n // This is the native asset registry alias for native.\n path.resolve(resolveFrom(projectRoot, 'expo-router/build/fork/react-native-web-container'))\n // NOTE(EvanBacon): This is the newer import but it doesn't work in the expo/expo monorepo.\n // path.resolve(resolveFrom(projectRoot, '@react-native/assets/registry.js'))\n );\n } catch {}\n\n const isWebEnabled = platforms.includes('web');\n\n const { resolve } = importMetroResolverFromProject(projectRoot);\n\n const extraNodeModules: { [key: string]: Record<string, string> } = {};\n\n const aliases: { [key: string]: Record<string, string> } = {\n web: {\n 'react-native': 'react-native-web',\n 'react-native/index': 'react-native-web',\n },\n };\n\n if (isWebEnabled) {\n // Allow `react-native-web` to be optional when web is not enabled but path aliases is.\n extraNodeModules['web'] = {\n 'react-native': path.resolve(require.resolve('react-native-web/package.json'), '..'),\n };\n }\n\n const preferredMainFields: { [key: string]: string[] } = {\n // Defaults from Expo Webpack. Most packages using `react-native` don't support web\n // in the `react-native` field, so we should prefer the `browser` field.\n // https://github.com/expo/router/issues/37\n web: ['browser', 'module', 'main'],\n };\n\n let tsConfigResolve = tsconfig?.paths\n ? resolveWithTsConfigPaths.bind(resolveWithTsConfigPaths, {\n paths: tsconfig.paths ?? {},\n baseUrl: tsconfig.baseUrl,\n })\n : null;\n\n if (isTsconfigPathsEnabled && isInteractive()) {\n // TODO: We should track all the files that used imports and invalidate them\n // currently the user will need to save all the files that use imports to\n // use the new aliases.\n const configWatcher = new FileNotifier(projectRoot, ['./tsconfig.json', './jsconfig.json']);\n configWatcher.startObserving(() => {\n debug('Reloading tsconfig.json');\n loadTsConfigPathsAsync(projectRoot).then((tsConfigPaths) => {\n if (tsConfigPaths?.paths && !!Object.keys(tsConfigPaths.paths).length) {\n debug('Enabling tsconfig.json paths support');\n tsConfigResolve = resolveWithTsConfigPaths.bind(resolveWithTsConfigPaths, {\n paths: tsConfigPaths.paths ?? {},\n baseUrl: tsConfigPaths.baseUrl,\n });\n } else {\n debug('Disabling tsconfig.json paths support');\n tsConfigResolve = null;\n }\n });\n });\n\n // TODO: This probably prevents the process from exiting.\n installExitHooks(() => {\n configWatcher.stopObserving();\n });\n } else {\n debug('Skipping tsconfig.json paths support');\n }\n\n let nodejsSourceExtensions: string[] | null = null;\n\n return withMetroResolvers(config, projectRoot, [\n // Add a resolver to alias the web asset resolver.\n (immutableContext: ResolutionContext, moduleName: string, platform: string | null) => {\n let context = {\n ...immutableContext,\n } as Mutable<ResolutionContext> & {\n mainFields: string[];\n customResolverOptions?: Record<string, string>;\n };\n\n const environment = context.customResolverOptions?.environment;\n const isNode = environment === 'node';\n\n // TODO: We need to prevent the require.context from including API routes as these use externals.\n // Should be fine after async routes lands.\n if (isNode) {\n const moduleId = isNodeExternal(moduleName);\n if (moduleId) {\n moduleName = getNodeExternalModuleId(context.originModulePath, moduleId);\n debug(`Redirecting Node.js external \"${moduleId}\" to \"${moduleName}\"`);\n }\n\n // Adjust nodejs source extensions to sort mjs after js, including platform variants.\n if (nodejsSourceExtensions === null) {\n nodejsSourceExtensions = getNodejsExtensions(context.sourceExts);\n }\n context.sourceExts = nodejsSourceExtensions;\n }\n\n // Conditionally remap `react-native` to `react-native-web` on web in\n // a way that doesn't require Babel to resolve the alias.\n if (platform && platform in aliases && aliases[platform][moduleName]) {\n moduleName = aliases[platform][moduleName];\n }\n\n // TODO: We may be able to remove this in the future, it's doing no harm\n // by staying here.\n // Conditionally remap `react-native` to `react-native-web`\n if (platform && platform in extraNodeModules) {\n context.extraNodeModules = {\n ...extraNodeModules[platform],\n ...context.extraNodeModules,\n };\n }\n\n if (tsconfig?.baseUrl && isTsconfigPathsEnabled) {\n context = {\n ...context,\n nodeModulesPaths: [\n ...immutableContext.nodeModulesPaths,\n // add last to ensure node modules are resolved first\n tsconfig.baseUrl,\n ],\n };\n }\n\n let mainFields: string[] = context.mainFields;\n\n if (isNode) {\n // Node.js runtimes should only be importing main at the moment.\n // This is a temporary fix until we can support the package.json exports.\n mainFields = ['main', 'module'];\n } else if (env.EXPO_METRO_NO_MAIN_FIELD_OVERRIDE) {\n mainFields = context.mainFields;\n } else if (platform && platform in preferredMainFields) {\n mainFields = preferredMainFields[platform];\n }\n function doResolve(moduleName: string): Resolution | null {\n return resolve(\n {\n ...context,\n resolveRequest: undefined,\n mainFields,\n\n // Passing `mainFields` directly won't be considered (in certain version of Metro)\n // we need to extend the `getPackageMainPath` directly to\n // use platform specific `mainFields`.\n // @ts-ignore\n getPackageMainPath(packageJsonPath) {\n // @ts-expect-error: mainFields is not on type\n const package_ = context.moduleCache.getPackage(packageJsonPath);\n return package_.getMain(mainFields);\n },\n },\n moduleName,\n platform\n );\n }\n\n function optionalResolve(moduleName: string): Resolution | null {\n try {\n return doResolve(moduleName);\n } catch (error) {\n // If the error is directly related to a resolver not being able to resolve a module, then\n // we can ignore the error and try the next resolver. Otherwise, we should throw the error.\n const isResolutionError =\n isFailedToResolveNameError(error) || isFailedToResolvePathError(error);\n if (!isResolutionError) {\n throw error;\n }\n }\n return null;\n }\n\n let result: Resolution | null = null;\n\n // React Native uses `event-target-shim` incorrectly and this causes the native runtime\n // to fail to load. This is a temporary workaround until we can fix this upstream.\n // https://github.com/facebook/react-native/pull/38628\n if (\n moduleName.includes('event-target-shim') &&\n context.originModulePath.includes(path.sep + 'react-native' + path.sep)\n ) {\n context.sourceExts = context.sourceExts.filter((f) => !f.includes('mjs'));\n debug('Skip mjs support for event-target-shim in:', context.originModulePath);\n }\n\n if (tsConfigResolve) {\n result = tsConfigResolve(\n {\n originModulePath: context.originModulePath,\n moduleName,\n },\n optionalResolve\n );\n }\n\n result ??= doResolve(moduleName);\n\n if (result) {\n // Replace the web resolver with the original one.\n // This is basically an alias for web-only.\n if (shouldAliasAssetRegistryForWeb(platform, result)) {\n // @ts-expect-error: `readonly` for some reason.\n result.filePath = assetRegistryPath;\n }\n\n // React Native Web adds a couple extra divs for no reason, these\n // make static rendering much harder as we expect the root element to be `<html>`.\n // This resolution will alias to a simple in-out component to avoid React Native web.\n if (\n // Only apply the transform if expo-router is present.\n reactNativeWebAppContainer &&\n shouldAliasModule(\n {\n platform,\n result,\n },\n {\n platform: 'web',\n output: 'react-native-web/dist/exports/AppRegistry/AppContainer.js',\n }\n )\n ) {\n // @ts-expect-error: `readonly` for some reason.\n result.filePath = reactNativeWebAppContainer;\n }\n }\n return result;\n },\n ]);\n}\n\n/** @returns `true` if the incoming resolution should be swapped on web. */\nexport function shouldAliasAssetRegistryForWeb(\n platform: string | null,\n result: Resolution\n): boolean {\n return (\n platform === 'web' &&\n result?.type === 'sourceFile' &&\n typeof result?.filePath === 'string' &&\n normalizeSlashes(result.filePath).endsWith(\n 'react-native-web/dist/modules/AssetRegistry/index.js'\n )\n );\n}\n/** @returns `true` if the incoming resolution should be swapped. */\nexport function shouldAliasModule(\n input: {\n platform: string | null;\n result: Resolution;\n },\n alias: { platform: string; output: string }\n): boolean {\n return (\n input.platform === alias.platform &&\n input.result?.type === 'sourceFile' &&\n typeof input.result?.filePath === 'string' &&\n normalizeSlashes(input.result.filePath).endsWith(alias.output)\n );\n}\n\n/** Add support for `react-native-web` and the Web platform. */\nexport async function withMetroMultiPlatformAsync(\n projectRoot: string,\n {\n config,\n platformBundlers,\n isTsconfigPathsEnabled,\n webOutput,\n routerDirectory,\n }: {\n config: ConfigT;\n isTsconfigPathsEnabled: boolean;\n platformBundlers: PlatformBundlers;\n webOutput?: 'single' | 'static';\n routerDirectory: string;\n }\n) {\n // Auto pick app entry for router.\n process.env.EXPO_ROUTER_APP_ROOT = getAppRouterRelativeEntryPath(projectRoot, routerDirectory);\n\n // Required for @expo/metro-runtime to format paths in the web LogBox.\n process.env.EXPO_PUBLIC_PROJECT_ROOT = process.env.EXPO_PUBLIC_PROJECT_ROOT ?? projectRoot;\n\n if (webOutput === 'static') {\n // Enable static rendering in runtime space.\n process.env.EXPO_PUBLIC_USE_STATIC = '1';\n }\n\n // Ensure the cache is invalidated if these values change.\n // @ts-expect-error\n config.transformer._expoRouterRootDirectory = process.env.EXPO_ROUTER_APP_ROOT;\n // @ts-expect-error\n config.transformer._expoRouterWebRendering = webOutput;\n // TODO: import mode\n\n if (platformBundlers.web === 'metro') {\n await new WebSupportProjectPrerequisite(projectRoot).assertAsync();\n }\n\n let tsconfig: null | TsConfigPaths = null;\n\n if (isTsconfigPathsEnabled) {\n Log.warn(\n chalk.yellow`Experimental path aliases feature is enabled. ` +\n learnMore('https://docs.expo.dev/guides/typescript/#path-aliases')\n );\n tsconfig = await loadTsConfigPathsAsync(projectRoot);\n }\n\n await setupNodeExternals(projectRoot);\n\n return withMetroMultiPlatform(projectRoot, {\n config,\n platformBundlers,\n tsconfig,\n isTsconfigPathsEnabled,\n });\n}\n\nfunction withMetroMultiPlatform(\n projectRoot: string,\n {\n config,\n platformBundlers,\n isTsconfigPathsEnabled,\n tsconfig,\n }: {\n config: ConfigT;\n isTsconfigPathsEnabled: boolean;\n platformBundlers: PlatformBundlers;\n tsconfig: TsConfigPaths | null;\n }\n) {\n let expoConfigPlatforms = Object.entries(platformBundlers)\n .filter(([, bundler]) => bundler === 'metro')\n .map(([platform]) => platform);\n\n if (Array.isArray(config.resolver.platforms)) {\n expoConfigPlatforms = [...new Set(expoConfigPlatforms.concat(config.resolver.platforms))];\n }\n\n // @ts-expect-error: typed as `readonly`.\n config.resolver.platforms = expoConfigPlatforms;\n\n if (expoConfigPlatforms.includes('web')) {\n config = withWebPolyfills(config, projectRoot);\n }\n\n return withExtendedResolver(config, {\n projectRoot,\n tsconfig,\n isTsconfigPathsEnabled,\n platforms: expoConfigPlatforms,\n });\n}\n"],"names":["getNodejsExtensions","withExtendedResolver","shouldAliasAssetRegistryForWeb","shouldAliasModule","withMetroMultiPlatformAsync","debug","require","withWebPolyfills","config","projectRoot","originalGetPolyfills","serializer","getPolyfills","bind","ctx","platform","path","join","EXTERNAL_REQUIRE_POLYFILL","polyfills","EXTERNAL_REQUIRE_NATIVE_POLYFILL","normalizeSlashes","p","replace","srcExts","mjsExts","filter","ext","test","nodejsSourceExtensions","jsIndex","reduce","index","i","splice","tsconfig","platforms","isTsconfigPathsEnabled","assetRegistryPath","fs","realpathSync","resolve","resolveFrom","reactNativeWebAppContainer","isWebEnabled","includes","importMetroResolverFromProject","extraNodeModules","aliases","web","preferredMainFields","tsConfigResolve","paths","resolveWithTsConfigPaths","baseUrl","isInteractive","configWatcher","FileNotifier","startObserving","loadTsConfigPathsAsync","then","tsConfigPaths","Object","keys","length","installExitHooks","stopObserving","withMetroResolvers","immutableContext","moduleName","context","environment","customResolverOptions","isNode","moduleId","isNodeExternal","getNodeExternalModuleId","originModulePath","sourceExts","nodeModulesPaths","mainFields","env","EXPO_METRO_NO_MAIN_FIELD_OVERRIDE","doResolve","resolveRequest","undefined","getPackageMainPath","packageJsonPath","package_","moduleCache","getPackage","getMain","optionalResolve","error","isResolutionError","isFailedToResolveNameError","isFailedToResolvePathError","result","sep","f","filePath","output","type","endsWith","input","alias","platformBundlers","webOutput","routerDirectory","process","EXPO_ROUTER_APP_ROOT","getAppRouterRelativeEntryPath","EXPO_PUBLIC_PROJECT_ROOT","EXPO_PUBLIC_USE_STATIC","transformer","_expoRouterRootDirectory","_expoRouterWebRendering","WebSupportProjectPrerequisite","assertAsync","Log","warn","chalk","yellow","learnMore","setupNodeExternals","withMetroMultiPlatform","expoConfigPlatforms","entries","bundler","map","Array","isArray","resolver","Set","concat"],"mappings":"AAMA;;;;QAiEgBA,mBAAmB,GAAnBA,mBAAmB;QAqBnBC,oBAAoB,GAApBA,oBAAoB;QAuQpBC,8BAA8B,GAA9BA,8BAA8B;QAc9BC,iBAAiB,GAAjBA,iBAAiB;QAgBXC,2BAA2B,GAA3BA,2BAA2B;AA3X/B,IAAA,MAAO,kCAAP,OAAO,EAAA;AACV,IAAA,GAAI,kCAAJ,IAAI,EAAA;AAGF,IAAA,KAAM,kCAAN,MAAM,EAAA;AACC,IAAA,YAAc,kCAAd,cAAc,EAAA;AAQ/B,IAAA,UAAa,WAAb,aAAa,CAAA;AACmD,IAAA,YAAe,WAAf,eAAe,CAAA;AACvC,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACvB,IAAA,OAAU,WAAV,UAAU,CAAA;AACrB,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACrC,IAAA,IAAc,WAAd,cAAc,CAAA;AACL,IAAA,aAA6B,WAA7B,6BAA6B,CAAA;AACtC,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACP,IAAA,KAAqB,WAArB,qBAAqB,CAAA;AACxB,IAAA,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B;QACtBD,SAAS,EAAE0F,mBAAmB;KAC/B,CAAC,CAAC;CACJ"}
@@ -6,9 +6,9 @@ exports.getDefaultMetroResolver = getDefaultMetroResolver;
6
6
  exports.withMetroResolvers = withMetroResolvers;
7
7
  var _chalk = _interopRequireDefault(require("chalk"));
8
8
  var _path = _interopRequireDefault(require("path"));
9
- var _env = require("../../../utils/env");
10
9
  var _metroErrors = require("./metroErrors");
11
10
  var _resolveFromProject = require("./resolveFromProject");
11
+ var _env = require("../../../utils/env");
12
12
  function _interopRequireDefault(obj) {
13
13
  return obj && obj.__esModule ? obj : {
14
14
  default: obj
@@ -28,8 +28,9 @@ function optionsKeyForContext(context) {
28
28
  return (ref = JSON.stringify((_customResolverOptions = context.customResolverOptions) != null ? _customResolverOptions : {}, canonicalize)) != null ? ref : "";
29
29
  }
30
30
  function withMetroResolvers(config, projectRoot, resolvers) {
31
- debug(`Appending ${resolvers.length} custom resolvers to Metro config. (has custom resolver: ${!!config.resolver.resolveRequest})`);
32
- const originalResolveRequest = config.resolver.resolveRequest || getDefaultMetroResolver(projectRoot);
31
+ var ref4, ref1;
32
+ debug(`Appending ${resolvers.length} custom resolvers to Metro config. (has custom resolver: ${!!((ref4 = config.resolver) == null ? void 0 : ref4.resolveRequest)})`);
33
+ const originalResolveRequest = ((ref1 = config.resolver) == null ? void 0 : ref1.resolveRequest) || getDefaultMetroResolver(projectRoot);
33
34
  function mutateResolutionError(error, context, moduleName, platform) {
34
35
  var ref;
35
36
  if (!_env.env.EXPO_METRO_UNSTABLE_ERRORS || !platform) {
@@ -66,8 +67,8 @@ function withMetroResolvers(config, projectRoot, resolvers) {
66
67
  const pad = (num)=>{
67
68
  return new Array(num).fill(" ").join("");
68
69
  };
69
- var ref1, ref2;
70
- const root = (ref2 = (ref1 = (ref = config.server) == null ? void 0 : ref.unstable_serverRoot) != null ? ref1 : config.projectRoot) != null ? ref2 : projectRoot;
70
+ var ref2, ref3;
71
+ const root = (ref3 = (ref2 = (ref = config.server) == null ? void 0 : ref.unstable_serverRoot) != null ? ref2 : config.projectRoot) != null ? ref3 : projectRoot;
71
72
  const recurseBackWithLimit = (req, limit, count = 0)=>{
72
73
  const results = {
73
74
  origin: req.origin,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/metro/withMetroResolvers.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport chalk from 'chalk';\nimport { ConfigT as MetroConfig } from 'metro-config';\nimport { ResolutionContext } from 'metro-resolver';\nimport path from 'path';\n\nimport { env } from '../../../utils/env';\nimport { isFailedToResolveNameError, isFailedToResolvePathError } from './metroErrors';\nimport { importMetroResolverFromProject } from './resolveFromProject';\n\nconst debug = require('debug')('expo:metro:withMetroResolvers') as typeof console.log;\n\nexport type MetroResolver = NonNullable<MetroConfig['resolver']['resolveRequest']>;\n\n/** Expo Metro Resolvers can return `null` to skip without throwing an error. Metro Resolvers will throw either a `FailedToResolveNameError` or `FailedToResolvePathError`. */\nexport type ExpoCustomMetroResolver = (\n ...args: Parameters<MetroResolver>\n) => ReturnType<MetroResolver> | null;\n\n/** @returns `MetroResolver` utilizing the upstream `resolve` method. */\nexport function getDefaultMetroResolver(projectRoot: string): MetroResolver {\n const { resolve } = importMetroResolverFromProject(projectRoot);\n return (context: ResolutionContext, moduleName: string, platform: string | null) => {\n return resolve(context, moduleName, platform);\n };\n}\n\nfunction optionsKeyForContext(context: ResolutionContext) {\n const canonicalize = require('metro-core/src/canonicalize');\n\n // Compound key for the resolver cache\n return JSON.stringify(context.customResolverOptions ?? {}, canonicalize) ?? '';\n}\n\n/**\n * Extend the Metro config `resolver.resolveRequest` method with additional resolvers that can\n * exit early by returning a `Resolution` or skip to the next resolver by returning `null`.\n *\n * @param config Metro config.\n * @param projectRoot path to the project root used to resolve the default Metro resolver.\n * @param resolvers custom MetroResolver to chain.\n * @returns a new `MetroConfig` with the `resolver.resolveRequest` method chained.\n */\nexport function withMetroResolvers(\n config: MetroConfig,\n projectRoot: string,\n resolvers: ExpoCustomMetroResolver[]\n): MetroConfig {\n debug(\n `Appending ${\n resolvers.length\n } custom resolvers to Metro config. (has custom resolver: ${!!config.resolver.resolveRequest})`\n );\n const originalResolveRequest =\n config.resolver.resolveRequest || getDefaultMetroResolver(projectRoot);\n\n function mutateResolutionError(\n error: Error,\n context: ResolutionContext,\n moduleName: string,\n platform: string | null\n ) {\n if (!env.EXPO_METRO_UNSTABLE_ERRORS || !platform) {\n debug('Cannot mutate resolution error');\n return error;\n }\n\n const mapByOrigin = depGraph.get(optionsKeyForContext(context));\n const mapByPlatform = mapByOrigin?.get(platform);\n\n if (!mapByPlatform) {\n return error;\n }\n\n // collect all references inversely using some expensive lookup\n\n const getReferences = (origin: string) => {\n const inverseOrigin: { origin: string; previous: string; request: string }[] = [];\n\n if (!mapByPlatform) {\n return inverseOrigin;\n }\n\n for (const [originKey, mapByTarget] of mapByPlatform) {\n // search comparing origin to path\n\n const found = [...mapByTarget.values()].find((resolution) => resolution.path === origin);\n if (found) {\n inverseOrigin.push({\n origin,\n previous: originKey,\n request: found.request,\n });\n }\n }\n\n return inverseOrigin;\n };\n\n const pad = (num: number) => {\n return new Array(num).fill(' ').join('');\n };\n\n const root = config.server?.unstable_serverRoot ?? config.projectRoot ?? projectRoot;\n\n type InverseDepResult = {\n origin: string;\n request: string;\n previous: InverseDepResult[];\n };\n const recurseBackWithLimit = (\n req: { origin: string; request: string },\n limit: number,\n count: number = 0\n ) => {\n const results: InverseDepResult = {\n origin: req.origin,\n request: req.request,\n previous: [],\n };\n\n if (count >= limit) {\n return results;\n }\n\n const inverse = getReferences(req.origin);\n for (const match of inverse) {\n // Use more qualified name if possible\n // results.origin = match.origin;\n // Found entry point\n if (req.origin === match.previous) {\n continue;\n }\n results.previous.push(\n recurseBackWithLimit({ origin: match.previous, request: match.request }, limit, count + 1)\n );\n }\n return results;\n };\n\n const inverseTree = recurseBackWithLimit(\n { origin: context.originModulePath, request: moduleName },\n // TODO: Do we need to expose this?\n 35\n );\n\n if (inverseTree.previous.length > 0) {\n debug('Found inverse graph:', JSON.stringify(inverseTree, null, 2));\n let extraMessage = chalk.bold('Import stack:');\n const printRecursive = (tree: InverseDepResult, depth: number = 0) => {\n let filename = path.relative(root, tree.origin);\n if (filename.match(/\\?ctx=[\\w\\d]+$/)) {\n filename = filename.replace(/\\?ctx=[\\w\\d]+$/, chalk.dim(' (require.context)'));\n } else {\n let formattedRequest = chalk.green(`\"${tree.request}\"`);\n\n if (\n // If bundling for web and the import is pulling internals from outside of react-native\n // then mark it as an invalid import.\n platform === 'web' &&\n !/^(node_modules\\/)?react-native\\//.test(filename) &&\n tree.request.match(/^react-native\\/.*/)\n ) {\n formattedRequest =\n formattedRequest +\n chalk`\\n {yellow Importing react-native internals is not supported on web.}`;\n }\n\n filename = filename + chalk`\\n{gray |} {cyan import} ${formattedRequest}\\n`;\n }\n let line = '\\n' + pad(depth) + chalk.gray(' ') + filename;\n if (filename.match(/node_modules/)) {\n line = chalk.gray(\n // Bold the node module name\n line.replace(/node_modules\\/([^/]+)/, (_match, p1) => {\n return 'node_modules/' + chalk.bold(p1);\n })\n );\n }\n extraMessage += line;\n for (const child of tree.previous) {\n printRecursive(\n child,\n // Only add depth if there are multiple children\n tree.previous.length > 1 ? depth + 1 : depth\n );\n }\n };\n printRecursive(inverseTree);\n\n // @ts-expect-error\n error._expoImportStack = extraMessage;\n } else {\n debug('Found no inverse tree for:', context.originModulePath);\n }\n\n return error;\n }\n\n const depGraph: Map<\n // custom options\n string,\n Map<\n // platform\n string,\n Map<\n // origin module name\n string,\n Set<{\n // required module name\n path: string;\n // This isn't entirely accurate since a module can be imported multiple times in a file,\n // and use different names. But it's good enough for now.\n request: string;\n }>\n >\n >\n > = new Map();\n\n return {\n ...config,\n resolver: {\n ...config.resolver,\n resolveRequest(context, moduleName, platform) {\n const storeResult = (res: NonNullable<ReturnType<ExpoCustomMetroResolver>>) => {\n if (!env.EXPO_METRO_UNSTABLE_ERRORS || !platform) return;\n\n const key = optionsKeyForContext(context);\n if (!depGraph.has(key)) depGraph.set(key, new Map());\n const mapByTarget = depGraph.get(key);\n if (!mapByTarget!.has(platform)) mapByTarget!.set(platform, new Map());\n const mapByPlatform = mapByTarget!.get(platform);\n if (!mapByPlatform!.has(context.originModulePath))\n mapByPlatform!.set(context.originModulePath, new Set());\n const setForModule = mapByPlatform!.get(context.originModulePath)!;\n\n const qualifiedModuleName = res?.type === 'sourceFile' ? res.filePath : moduleName;\n setForModule.add({ path: qualifiedModuleName, request: moduleName });\n };\n\n const universalContext = {\n ...context,\n preferNativePlatform: platform !== 'web',\n };\n\n try {\n for (const resolver of resolvers) {\n try {\n const resolution = resolver(universalContext, moduleName, platform);\n if (resolution) {\n storeResult(resolution);\n return resolution;\n }\n } catch (error: any) {\n // If no user-defined resolver, use Expo's default behavior.\n // This prevents extraneous resolution attempts on failure.\n if (!config.resolver.resolveRequest) {\n throw error;\n }\n\n // If the error is directly related to a resolver not being able to resolve a module, then\n // we can ignore the error and try the next resolver. Otherwise, we should throw the error.\n const isResolutionError =\n isFailedToResolveNameError(error) || isFailedToResolvePathError(error);\n if (!isResolutionError) {\n throw error;\n }\n debug(\n `Custom resolver threw: ${error.constructor.name}. (module: ${moduleName}, platform: ${platform})`\n );\n }\n }\n // If we haven't returned by now, use the original resolver or upstream resolver.\n const res = originalResolveRequest(universalContext, moduleName, platform);\n storeResult(res);\n return res;\n } catch (error: any) {\n throw mutateResolutionError(error, universalContext, moduleName, platform);\n }\n },\n },\n };\n}\n"],"names":["getDefaultMetroResolver","withMetroResolvers","debug","require","projectRoot","resolve","importMetroResolverFromProject","context","moduleName","platform","optionsKeyForContext","canonicalize","JSON","stringify","customResolverOptions","config","resolvers","length","resolver","resolveRequest","originalResolveRequest","mutateResolutionError","error","env","EXPO_METRO_UNSTABLE_ERRORS","mapByOrigin","depGraph","get","mapByPlatform","getReferences","origin","inverseOrigin","originKey","mapByTarget","found","values","find","resolution","path","push","previous","request","pad","num","Array","fill","join","root","server","unstable_serverRoot","recurseBackWithLimit","req","limit","count","results","inverse","match","inverseTree","originModulePath","extraMessage","chalk","bold","printRecursive","tree","depth","filename","relative","replace","dim","formattedRequest","green","test","line","gray","_match","p1","child","_expoImportStack","Map","storeResult","res","key","has","set","Set","setForModule","qualifiedModuleName","type","filePath","add","universalContext","preferNativePlatform","isResolutionError","isFailedToResolveNameError","isFailedToResolvePathError","constructor","name"],"mappings":"AAMA;;;;QAmBgBA,uBAAuB,GAAvBA,uBAAuB;QAuBvBC,kBAAkB,GAAlBA,kBAAkB;AA1ChB,IAAA,MAAO,kCAAP,OAAO,EAAA;AAGR,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEH,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AAC+B,IAAA,YAAe,WAAf,eAAe,CAAA;AACvC,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;;;;;;AAErE,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,+BAA+B,CAAC,AAAsB,AAAC;AAU/E,SAASH,uBAAuB,CAACI,WAAmB,EAAiB;IAC1E,MAAM,EAAEC,OAAO,CAAA,EAAE,GAAGC,CAAAA,GAAAA,mBAA8B,AAAa,CAAA,+BAAb,CAACF,WAAW,CAAC,AAAC;IAChE,OAAO,CAACG,OAA0B,EAAEC,UAAkB,EAAEC,QAAuB,GAAK;QAClF,OAAOJ,OAAO,CAACE,OAAO,EAAEC,UAAU,EAAEC,QAAQ,CAAC,CAAC;KAC/C,CAAC;CACH;AAED,SAASC,oBAAoB,CAACH,OAA0B,EAAE;IACxD,MAAMI,YAAY,GAAGR,OAAO,CAAC,6BAA6B,CAAC,AAAC;QAGtCI,sBAA6B,EAA5CK,GAAiE;IADxE,sCAAsC;IACtC,OAAOA,CAAAA,GAAiE,GAAjEA,IAAI,CAACC,SAAS,CAACN,CAAAA,sBAA6B,GAA7BA,OAAO,CAACO,qBAAqB,YAA7BP,sBAA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,CAAC;oBACjB,OAAOA,GAAG,CAAC;iBACZ,CAAC,OAAO1D,KAAK,EAAO;oBACnB,MAAMD,qBAAqB,CAACC,KAAK,EAAEoE,gBAAgB,EAAElF,UAAU,EAAEC,QAAQ,CAAC,CAAC;iBAC5E;aACF;SACF;KACF,CAAC;CACH"}
1
+ {"version":3,"sources":["../../../../../src/start/server/metro/withMetroResolvers.ts"],"sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport chalk from 'chalk';\nimport { ConfigT as MetroConfig } from 'metro-config';\nimport { ResolutionContext } from 'metro-resolver';\nimport path from 'path';\n\nimport { isFailedToResolveNameError, isFailedToResolvePathError } from './metroErrors';\nimport { importMetroResolverFromProject } from './resolveFromProject';\nimport { env } from '../../../utils/env';\n\nconst debug = require('debug')('expo:metro:withMetroResolvers') as typeof console.log;\n\nexport type MetroResolver = NonNullable<MetroConfig['resolver']['resolveRequest']>;\n\n/** Expo Metro Resolvers can return `null` to skip without throwing an error. Metro Resolvers will throw either a `FailedToResolveNameError` or `FailedToResolvePathError`. */\nexport type ExpoCustomMetroResolver = (\n ...args: Parameters<MetroResolver>\n) => ReturnType<MetroResolver> | null;\n\n/** @returns `MetroResolver` utilizing the upstream `resolve` method. */\nexport function getDefaultMetroResolver(projectRoot: string): MetroResolver {\n const { resolve } = importMetroResolverFromProject(projectRoot);\n return (context: ResolutionContext, moduleName: string, platform: string | null) => {\n return resolve(context, moduleName, platform);\n };\n}\n\nfunction optionsKeyForContext(context: ResolutionContext) {\n const canonicalize = require('metro-core/src/canonicalize');\n\n // Compound key for the resolver cache\n return JSON.stringify(context.customResolverOptions ?? {}, canonicalize) ?? '';\n}\n\n/**\n * Extend the Metro config `resolver.resolveRequest` method with additional resolvers that can\n * exit early by returning a `Resolution` or skip to the next resolver by returning `null`.\n *\n * @param config Metro config.\n * @param projectRoot path to the project root used to resolve the default Metro resolver.\n * @param resolvers custom MetroResolver to chain.\n * @returns a new `MetroConfig` with the `resolver.resolveRequest` method chained.\n */\nexport function withMetroResolvers(\n config: MetroConfig,\n projectRoot: string,\n resolvers: ExpoCustomMetroResolver[]\n): MetroConfig {\n debug(\n `Appending ${\n resolvers.length\n } custom resolvers to Metro config. (has custom resolver: ${!!config.resolver?.resolveRequest})`\n );\n const originalResolveRequest =\n config.resolver?.resolveRequest || getDefaultMetroResolver(projectRoot);\n\n function mutateResolutionError(\n error: Error,\n context: ResolutionContext,\n moduleName: string,\n platform: string | null\n ) {\n if (!env.EXPO_METRO_UNSTABLE_ERRORS || !platform) {\n debug('Cannot mutate resolution error');\n return error;\n }\n\n const mapByOrigin = depGraph.get(optionsKeyForContext(context));\n const mapByPlatform = mapByOrigin?.get(platform);\n\n if (!mapByPlatform) {\n return error;\n }\n\n // collect all references inversely using some expensive lookup\n\n const getReferences = (origin: string) => {\n const inverseOrigin: { origin: string; previous: string; request: string }[] = [];\n\n if (!mapByPlatform) {\n return inverseOrigin;\n }\n\n for (const [originKey, mapByTarget] of mapByPlatform) {\n // search comparing origin to path\n\n const found = [...mapByTarget.values()].find((resolution) => resolution.path === origin);\n if (found) {\n inverseOrigin.push({\n origin,\n previous: originKey,\n request: found.request,\n });\n }\n }\n\n return inverseOrigin;\n };\n\n const pad = (num: number) => {\n return new Array(num).fill(' ').join('');\n };\n\n const root = config.server?.unstable_serverRoot ?? config.projectRoot ?? projectRoot;\n\n type InverseDepResult = {\n origin: string;\n request: string;\n previous: InverseDepResult[];\n };\n const recurseBackWithLimit = (\n req: { origin: string; request: string },\n limit: number,\n count: number = 0\n ) => {\n const results: InverseDepResult = {\n origin: req.origin,\n request: req.request,\n previous: [],\n };\n\n if (count >= limit) {\n return results;\n }\n\n const inverse = getReferences(req.origin);\n for (const match of inverse) {\n // Use more qualified name if possible\n // results.origin = match.origin;\n // Found entry point\n if (req.origin === match.previous) {\n continue;\n }\n results.previous.push(\n recurseBackWithLimit({ origin: match.previous, request: match.request }, limit, count + 1)\n );\n }\n return results;\n };\n\n const inverseTree = recurseBackWithLimit(\n { origin: context.originModulePath, request: moduleName },\n // TODO: Do we need to expose this?\n 35\n );\n\n if (inverseTree.previous.length > 0) {\n debug('Found inverse graph:', JSON.stringify(inverseTree, null, 2));\n let extraMessage = chalk.bold('Import stack:');\n const printRecursive = (tree: InverseDepResult, depth: number = 0) => {\n let filename = path.relative(root, tree.origin);\n if (filename.match(/\\?ctx=[\\w\\d]+$/)) {\n filename = filename.replace(/\\?ctx=[\\w\\d]+$/, chalk.dim(' (require.context)'));\n } else {\n let formattedRequest = chalk.green(`\"${tree.request}\"`);\n\n if (\n // If bundling for web and the import is pulling internals from outside of react-native\n // then mark it as an invalid import.\n platform === 'web' &&\n !/^(node_modules\\/)?react-native\\//.test(filename) &&\n tree.request.match(/^react-native\\/.*/)\n ) {\n formattedRequest =\n formattedRequest +\n chalk`\\n {yellow Importing react-native internals is not supported on web.}`;\n }\n\n filename = filename + chalk`\\n{gray |} {cyan import} ${formattedRequest}\\n`;\n }\n let line = '\\n' + pad(depth) + chalk.gray(' ') + filename;\n if (filename.match(/node_modules/)) {\n line = chalk.gray(\n // Bold the node module name\n line.replace(/node_modules\\/([^/]+)/, (_match, p1) => {\n return 'node_modules/' + chalk.bold(p1);\n })\n );\n }\n extraMessage += line;\n for (const child of tree.previous) {\n printRecursive(\n child,\n // Only add depth if there are multiple children\n tree.previous.length > 1 ? depth + 1 : depth\n );\n }\n };\n printRecursive(inverseTree);\n\n // @ts-expect-error\n error._expoImportStack = extraMessage;\n } else {\n debug('Found no inverse tree for:', context.originModulePath);\n }\n\n return error;\n }\n\n const depGraph: Map<\n // custom options\n string,\n Map<\n // platform\n string,\n Map<\n // origin module name\n string,\n Set<{\n // required module name\n path: string;\n // This isn't entirely accurate since a module can be imported multiple times in a file,\n // and use different names. But it's good enough for now.\n request: string;\n }>\n >\n >\n > = new Map();\n\n return {\n ...config,\n resolver: {\n ...config.resolver,\n resolveRequest(context, moduleName, platform) {\n const storeResult = (res: NonNullable<ReturnType<ExpoCustomMetroResolver>>) => {\n if (!env.EXPO_METRO_UNSTABLE_ERRORS || !platform) return;\n\n const key = optionsKeyForContext(context);\n if (!depGraph.has(key)) depGraph.set(key, new Map());\n const mapByTarget = depGraph.get(key);\n if (!mapByTarget!.has(platform)) mapByTarget!.set(platform, new Map());\n const mapByPlatform = mapByTarget!.get(platform);\n if (!mapByPlatform!.has(context.originModulePath))\n mapByPlatform!.set(context.originModulePath, new Set());\n const setForModule = mapByPlatform!.get(context.originModulePath)!;\n\n const qualifiedModuleName = res?.type === 'sourceFile' ? res.filePath : moduleName;\n setForModule.add({ path: qualifiedModuleName, request: moduleName });\n };\n\n const universalContext = {\n ...context,\n preferNativePlatform: platform !== 'web',\n };\n\n try {\n for (const resolver of resolvers) {\n try {\n const resolution = resolver(universalContext, moduleName, platform);\n if (resolution) {\n storeResult(resolution);\n return resolution;\n }\n } catch (error: any) {\n // If no user-defined resolver, use Expo's default behavior.\n // This prevents extraneous resolution attempts on failure.\n if (!config.resolver.resolveRequest) {\n throw error;\n }\n\n // If the error is directly related to a resolver not being able to resolve a module, then\n // we can ignore the error and try the next resolver. Otherwise, we should throw the error.\n const isResolutionError =\n isFailedToResolveNameError(error) || isFailedToResolvePathError(error);\n if (!isResolutionError) {\n throw error;\n }\n debug(\n `Custom resolver threw: ${error.constructor.name}. (module: ${moduleName}, platform: ${platform})`\n );\n }\n }\n // If we haven't returned by now, use the original resolver or upstream resolver.\n const res = originalResolveRequest(universalContext, moduleName, platform);\n storeResult(res);\n return res;\n } catch (error: any) {\n throw mutateResolutionError(error, universalContext, moduleName, platform);\n }\n },\n },\n };\n}\n"],"names":["getDefaultMetroResolver","withMetroResolvers","debug","require","projectRoot","resolve","importMetroResolverFromProject","context","moduleName","platform","optionsKeyForContext","canonicalize","JSON","stringify","customResolverOptions","config","resolvers","length","resolver","resolveRequest","originalResolveRequest","mutateResolutionError","error","env","EXPO_METRO_UNSTABLE_ERRORS","mapByOrigin","depGraph","get","mapByPlatform","getReferences","origin","inverseOrigin","originKey","mapByTarget","found","values","find","resolution","path","push","previous","request","pad","num","Array","fill","join","root","server","unstable_serverRoot","recurseBackWithLimit","req","limit","count","results","inverse","match","inverseTree","originModulePath","extraMessage","chalk","bold","printRecursive","tree","depth","filename","relative","replace","dim","formattedRequest","green","test","line","gray","_match","p1","child","_expoImportStack","Map","storeResult","res","key","has","set","Set","setForModule","qualifiedModuleName","type","filePath","add","universalContext","preferNativePlatform","isResolutionError","isFailedToResolveNameError","isFailedToResolvePathError","constructor","name"],"mappings":"AAMA;;;;QAmBgBA,uBAAuB,GAAvBA,uBAAuB;QAuBvBC,kBAAkB,GAAlBA,kBAAkB;AA1ChB,IAAA,MAAO,kCAAP,OAAO,EAAA;AAGR,IAAA,KAAM,kCAAN,MAAM,EAAA;AAEgD,IAAA,YAAe,WAAf,eAAe,CAAA;AACvC,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACjD,IAAA,IAAoB,WAApB,oBAAoB,CAAA;;;;;;AAExC,MAAMC,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,+BAA+B,CAAC,AAAsB,AAAC;AAU/E,SAASH,uBAAuB,CAACI,WAAmB,EAAiB;IAC1E,MAAM,EAAEC,OAAO,CAAA,EAAE,GAAGC,CAAAA,GAAAA,mBAA8B,AAAa,CAAA,+BAAb,CAACF,WAAW,CAAC,AAAC;IAChE,OAAO,CAACG,OAA0B,EAAEC,UAAkB,EAAEC,QAAuB,GAAK;QAClF,OAAOJ,OAAO,CAACE,OAAO,EAAEC,UAAU,EAAEC,QAAQ,CAAC,CAAC;KAC/C,CAAC;CACH;AAED,SAASC,oBAAoB,CAACH,OAA0B,EAAE;IACxD,MAAMI,YAAY,GAAGR,OAAO,CAAC,6BAA6B,CAAC,AAAC;QAGtCI,sBAA6B,EAA5CK,GAAiE;IADxE,sCAAsC;IACtC,OAAOA,CAAAA,GAAiE,GAAjEA,IAAI,CAACC,SAAS,CAACN,CAA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IAAI,CAAC,WAAW,EAAExF,UAAU,CAAC,YAAY,EAAEC,QAAQ,CAAC,CAAC,CAAC,CACnG,CAAC;yBACH;qBACF;oBACD,iFAAiF;oBACjF,MAAMuE,GAAG,GAAG5D,sBAAsB,CAACsE,gBAAgB,EAAElF,UAAU,EAAEC,QAAQ,CAAC,AAAC;oBAC3EsE,WAAW,CAACC,GAAG,CAAC,CAAC;oBACjB,OAAOA,GAAG,CAAC;iBACZ,CAAC,OAAO1D,KAAK,EAAO;oBACnB,MAAMD,qBAAqB,CAACC,KAAK,EAAEoE,gBAAgB,EAAElF,UAAU,EAAEC,QAAQ,CAAC,CAAC;iBAC5E;aACF;SACF;KACF,CAAC;CACH"}
@@ -8,14 +8,14 @@ var _accepts = _interopRequireDefault(require("accepts"));
8
8
  var _crypto = _interopRequireDefault(require("crypto"));
9
9
  var _formData = _interopRequireDefault(require("form-data"));
10
10
  var _structuredHeaders = require("structured-headers");
11
+ var _manifestMiddleware = require("./ManifestMiddleware");
12
+ var _resolvePlatform = require("./resolvePlatform");
11
13
  var _userSettings = _interopRequireDefault(require("../../../api/user/UserSettings"));
12
14
  var _user = require("../../../api/user/user");
13
15
  var _rudderstackClient = require("../../../utils/analytics/rudderstackClient");
14
16
  var _codesigning = require("../../../utils/codesigning");
15
17
  var _errors = require("../../../utils/errors");
16
18
  var _url = require("../../../utils/url");
17
- var _manifestMiddleware = require("./ManifestMiddleware");
18
- var _resolvePlatform = require("./resolvePlatform");
19
19
  function _interopRequireDefault(obj) {
20
20
  return obj && obj.__esModule ? obj : {
21
21
  default: obj
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/middleware/ExpoGoManifestHandlerMiddleware.ts"],"sourcesContent":["import { ExpoUpdatesManifest } from '@expo/config';\nimport { Updates } from '@expo/config-plugins';\nimport accepts from 'accepts';\nimport crypto from 'crypto';\nimport FormData from 'form-data';\nimport { serializeDictionary, Dictionary } from 'structured-headers';\n\nimport UserSettings from '../../../api/user/UserSettings';\nimport { ANONYMOUS_USERNAME } from '../../../api/user/user';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport {\n CodeSigningInfo,\n getCodeSigningInfoAsync,\n signManifestString,\n} from '../../../utils/codesigning';\nimport { CommandError } from '../../../utils/errors';\nimport { stripPort } from '../../../utils/url';\nimport { ManifestMiddleware, ManifestRequestInfo } from './ManifestMiddleware';\nimport { assertRuntimePlatform, parsePlatformHeader } from './resolvePlatform';\nimport { ServerHeaders, ServerRequest } from './server.types';\n\nconst debug = require('debug')('expo:start:server:middleware:ExpoGoManifestHandlerMiddleware');\n\nexport enum ResponseContentType {\n TEXT_PLAIN,\n APPLICATION_JSON,\n APPLICATION_EXPO_JSON,\n MULTIPART_MIXED,\n}\n\ninterface ExpoGoManifestRequestInfo extends ManifestRequestInfo {\n responseContentType: ResponseContentType;\n expectSignature: string | null;\n}\n\nexport class ExpoGoManifestHandlerMiddleware extends ManifestMiddleware<ExpoGoManifestRequestInfo> {\n public getParsedHeaders(req: ServerRequest): ExpoGoManifestRequestInfo {\n let platform = parsePlatformHeader(req);\n\n if (!platform) {\n debug(\n `No \"expo-platform\" header or \"platform\" query parameter specified. Falling back to \"ios\".`\n );\n platform = 'ios';\n }\n\n assertRuntimePlatform(platform);\n\n // Expo Updates clients explicitly accept \"multipart/mixed\" responses while browsers implicitly\n // accept them with \"accept: */*\". To make it easier to debug manifest responses by visiting their\n // URLs in a browser, we denote the response as \"text/plain\" if the user agent appears not to be\n // an Expo Updates client.\n const accept = accepts(req);\n const acceptedType = accept.types([\n 'unknown/unknown',\n 'multipart/mixed',\n 'application/json',\n 'application/expo+json',\n 'text/plain',\n ]);\n\n let responseContentType;\n switch (acceptedType) {\n case 'multipart/mixed':\n responseContentType = ResponseContentType.MULTIPART_MIXED;\n break;\n case 'application/json':\n responseContentType = ResponseContentType.APPLICATION_JSON;\n break;\n case 'application/expo+json':\n responseContentType = ResponseContentType.APPLICATION_EXPO_JSON;\n break;\n default:\n responseContentType = ResponseContentType.TEXT_PLAIN;\n break;\n }\n\n const expectSignature = req.headers['expo-expect-signature'];\n\n return {\n responseContentType,\n platform,\n expectSignature: expectSignature ? String(expectSignature) : null,\n hostname: stripPort(req.headers['host']),\n };\n }\n\n private getDefaultResponseHeaders(): ServerHeaders {\n const headers = new Map<string, number | string | readonly string[]>();\n // set required headers for Expo Updates manifest specification\n headers.set('expo-protocol-version', 0);\n headers.set('expo-sfv-version', 0);\n headers.set('cache-control', 'private, max-age=0');\n return headers;\n }\n\n public async _getManifestResponseAsync(requestOptions: ExpoGoManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }> {\n const { exp, hostUri, expoGoConfig, bundleUrl } = await this._resolveProjectSettingsAsync(\n requestOptions\n );\n\n const runtimeVersion = Updates.getRuntimeVersion(\n { ...exp, runtimeVersion: exp.runtimeVersion ?? { policy: 'sdkVersion' } },\n requestOptions.platform\n );\n if (!runtimeVersion) {\n throw new CommandError(\n 'MANIFEST_MIDDLEWARE',\n `Unable to determine runtime version for platform '${requestOptions.platform}'`\n );\n }\n\n const codeSigningInfo = await getCodeSigningInfoAsync(\n exp,\n requestOptions.expectSignature,\n this.options.privateKeyPath\n );\n\n const easProjectId = exp.extra?.eas?.projectId as string | undefined | null;\n const scopeKey = await ExpoGoManifestHandlerMiddleware.getScopeKeyAsync({\n slug: exp.slug,\n codeSigningInfo,\n });\n\n const expoUpdatesManifest: ExpoUpdatesManifest = {\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n runtimeVersion,\n launchAsset: {\n key: 'bundle',\n contentType: 'application/javascript',\n url: bundleUrl,\n },\n assets: [], // assets are not used in development\n metadata: {}, // required for the client to detect that this is an expo-updates manifest\n extra: {\n eas: {\n projectId: easProjectId ?? undefined,\n },\n expoClient: {\n ...exp,\n hostUri,\n },\n expoGo: expoGoConfig,\n scopeKey,\n },\n };\n\n const stringifiedManifest = JSON.stringify(expoUpdatesManifest);\n\n let manifestPartHeaders: { 'expo-signature': string } | null = null;\n let certificateChainBody: string | null = null;\n if (codeSigningInfo) {\n const signature = signManifestString(stringifiedManifest, codeSigningInfo);\n manifestPartHeaders = {\n 'expo-signature': serializeDictionary(\n convertToDictionaryItemsRepresentation({\n keyid: codeSigningInfo.keyId,\n sig: signature,\n alg: 'rsa-v1_5-sha256',\n })\n ),\n };\n certificateChainBody = codeSigningInfo.certificateChainForResponse.join('\\n');\n }\n\n const headers = this.getDefaultResponseHeaders();\n\n switch (requestOptions.responseContentType) {\n case ResponseContentType.MULTIPART_MIXED: {\n const form = this.getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n });\n headers.set('content-type', `multipart/mixed; boundary=${form.getBoundary()}`);\n return {\n body: form.getBuffer().toString(),\n version: runtimeVersion,\n headers,\n };\n }\n case ResponseContentType.APPLICATION_EXPO_JSON:\n case ResponseContentType.APPLICATION_JSON:\n case ResponseContentType.TEXT_PLAIN: {\n headers.set(\n 'content-type',\n ExpoGoManifestHandlerMiddleware.getContentTypeForResponseContentType(\n requestOptions.responseContentType\n )\n );\n if (manifestPartHeaders) {\n Object.entries(manifestPartHeaders).forEach(([key, value]) => {\n headers.set(key, value);\n });\n }\n\n return {\n body: stringifiedManifest,\n version: runtimeVersion,\n headers,\n };\n }\n }\n }\n\n private static getContentTypeForResponseContentType(\n responseContentType: ResponseContentType\n ): string {\n switch (responseContentType) {\n case ResponseContentType.MULTIPART_MIXED:\n return 'multipart/mixed';\n case ResponseContentType.APPLICATION_EXPO_JSON:\n return 'application/expo+json';\n case ResponseContentType.APPLICATION_JSON:\n return 'application/json';\n case ResponseContentType.TEXT_PLAIN:\n return 'text/plain';\n }\n }\n\n private getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n }: {\n stringifiedManifest: string;\n manifestPartHeaders: { 'expo-signature': string } | null;\n certificateChainBody: string | null;\n }): FormData {\n const form = new FormData();\n form.append('manifest', stringifiedManifest, {\n contentType: 'application/json',\n header: {\n ...manifestPartHeaders,\n },\n });\n if (certificateChainBody && certificateChainBody.length > 0) {\n form.append('certificate_chain', certificateChainBody, {\n contentType: 'application/x-pem-file',\n });\n }\n return form;\n }\n\n protected trackManifest(version?: string) {\n logEventAsync('Serve Expo Updates Manifest', {\n runtimeVersion: version,\n });\n }\n\n private static async getScopeKeyAsync({\n slug,\n codeSigningInfo,\n }: {\n slug: string;\n codeSigningInfo: CodeSigningInfo | null;\n }): Promise<string> {\n const scopeKeyFromCodeSigningInfo = codeSigningInfo?.scopeKey;\n if (scopeKeyFromCodeSigningInfo) {\n return scopeKeyFromCodeSigningInfo;\n }\n\n // Log.warn(\n // env.EXPO_OFFLINE\n // ? 'Using anonymous scope key in manifest for offline mode.'\n // : 'Using anonymous scope key in manifest.'\n // );\n return await getAnonymousScopeKeyAsync(slug);\n }\n}\n\nasync function getAnonymousScopeKeyAsync(slug: string): Promise<string> {\n const userAnonymousIdentifier = await UserSettings.getAnonymousIdentifierAsync();\n return `@${ANONYMOUS_USERNAME}/${slug}-${userAnonymousIdentifier}`;\n}\n\nfunction convertToDictionaryItemsRepresentation(obj: { [key: string]: string }): Dictionary {\n return new Map(\n Object.entries(obj).map(([k, v]) => {\n return [k, [v, new Map()]];\n })\n );\n}\n"],"names":["debug","require","ResponseContentType","TEXT_PLAIN","APPLICATION_JSON","APPLICATION_EXPO_JSON","MULTIPART_MIXED","ExpoGoManifestHandlerMiddleware","ManifestMiddleware","getParsedHeaders","req","platform","parsePlatformHeader","assertRuntimePlatform","accept","accepts","acceptedType","types","responseContentType","expectSignature","headers","String","hostname","stripPort","getDefaultResponseHeaders","Map","set","_getManifestResponseAsync","requestOptions","exp","hostUri","expoGoConfig","bundleUrl","_resolveProjectSettingsAsync","runtimeVersion","Updates","getRuntimeVersion","policy","CommandError","codeSigningInfo","getCodeSigningInfoAsync","options","privateKeyPath","easProjectId","extra","eas","projectId","scopeKey","getScopeKeyAsync","slug","expoUpdatesManifest","id","crypto","randomUUID","createdAt","Date","toISOString","launchAsset","key","contentType","url","assets","metadata","undefined","expoClient","expoGo","stringifiedManifest","JSON","stringify","manifestPartHeaders","certificateChainBody","signature","signManifestString","serializeDictionary","convertToDictionaryItemsRepresentation","keyid","keyId","sig","alg","certificateChainForResponse","join","form","getFormData","getBoundary","body","getBuffer","toString","version","getContentTypeForResponseContentType","Object","entries","forEach","value","FormData","append","header","length","trackManifest","logEventAsync","scopeKeyFromCodeSigningInfo","getAnonymousScopeKeyAsync","userAnonymousIdentifier","UserSettings","getAnonymousIdentifierAsync","ANONYMOUS_USERNAME","obj","map","k","v"],"mappings":"AAAA;;;;;AACwB,IAAA,cAAsB,WAAtB,sBAAsB,CAAA;AAC1B,IAAA,QAAS,kCAAT,SAAS,EAAA;AACV,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACN,IAAA,SAAW,kCAAX,WAAW,EAAA;AACgB,IAAA,kBAAoB,WAApB,oBAAoB,CAAA;AAE3C,IAAA,aAAgC,kCAAhC,gCAAgC,EAAA;AACtB,IAAA,KAAwB,WAAxB,wBAAwB,CAAA;AAC7B,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAKnE,IAAA,YAA4B,WAA5B,4BAA4B,CAAA;AACN,IAAA,OAAuB,WAAvB,uBAAuB,CAAA;AAC1B,IAAA,IAAoB,WAApB,oBAAoB,CAAA;AACU,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACnB,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;;;;;;AAG9E,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,8DAA8D,CAAC,AAAC;IAExF,mBAKN;;UALWC,mBAAmB;IAAnBA,mBAAmB,CAAnBA,mBAAmB,CAC7BC,YAAU,IAAVA,CAAU,IAAVA,YAAU;IADAD,mBAAmB,CAAnBA,mBAAmB,CAE7BE,kBAAgB,IAAhBA,CAAgB,IAAhBA,kBAAgB;IAFNF,mBAAmB,CAAnBA,mBAAmB,CAG7BG,uBAAqB,IAArBA,CAAqB,IAArBA,uBAA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2BAA2B,GAAG5D,eAAe,QAAU,GAAzBA,KAAAA,CAAyB,GAAzBA,eAAe,CAAEQ,QAAQ,AAAC;QAC9D,IAAIoD,2BAA2B,EAAE;YAC/B,OAAOA,2BAA2B,CAAC;SACpC;QAED,YAAY;QACZ,qBAAqB;QACrB,kEAAkE;QAClE,iDAAiD;QACjD,KAAK;QACL,OAAO,MAAMC,yBAAyB,CAACnD,IAAI,CAAC,CAAC;KAC9C;CACF;QA/OY1C,+BAA+B,GAA/BA,+BAA+B;AAiP5C,eAAe6F,yBAAyB,CAACnD,IAAY,EAAmB;IACtE,MAAMoD,uBAAuB,GAAG,MAAMC,aAAY,QAAA,CAACC,2BAA2B,EAAE,AAAC;IACjF,OAAO,CAAC,CAAC,EAAEC,KAAkB,mBAAA,CAAC,CAAC,EAAEvD,IAAI,CAAC,CAAC,EAAEoD,uBAAuB,CAAC,CAAC,CAAC;CACpE;AAED,SAAS3B,sCAAsC,CAAC+B,GAA8B,EAAc;IAC1F,OAAO,IAAIhF,GAAG,CACZgE,MAAM,CAACC,OAAO,CAACe,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,CAACC,CAAC,EAAEC,CAAC,CAAC,GAAK;QAClC,OAAO;YAACD,CAAC;YAAE;gBAACC,CAAC;gBAAE,IAAInF,GAAG,EAAE;aAAC;SAAC,CAAC;KAC5B,CAAC,CACH,CAAC;CACH"}
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/ExpoGoManifestHandlerMiddleware.ts"],"sourcesContent":["import { ExpoUpdatesManifest } from '@expo/config';\nimport { Updates } from '@expo/config-plugins';\nimport accepts from 'accepts';\nimport crypto from 'crypto';\nimport FormData from 'form-data';\nimport { serializeDictionary, Dictionary } from 'structured-headers';\n\nimport { ManifestMiddleware, ManifestRequestInfo } from './ManifestMiddleware';\nimport { assertRuntimePlatform, parsePlatformHeader } from './resolvePlatform';\nimport { ServerHeaders, ServerRequest } from './server.types';\nimport UserSettings from '../../../api/user/UserSettings';\nimport { ANONYMOUS_USERNAME } from '../../../api/user/user';\nimport { logEventAsync } from '../../../utils/analytics/rudderstackClient';\nimport {\n CodeSigningInfo,\n getCodeSigningInfoAsync,\n signManifestString,\n} from '../../../utils/codesigning';\nimport { CommandError } from '../../../utils/errors';\nimport { stripPort } from '../../../utils/url';\n\nconst debug = require('debug')('expo:start:server:middleware:ExpoGoManifestHandlerMiddleware');\n\nexport enum ResponseContentType {\n TEXT_PLAIN,\n APPLICATION_JSON,\n APPLICATION_EXPO_JSON,\n MULTIPART_MIXED,\n}\n\ninterface ExpoGoManifestRequestInfo extends ManifestRequestInfo {\n responseContentType: ResponseContentType;\n expectSignature: string | null;\n}\n\nexport class ExpoGoManifestHandlerMiddleware extends ManifestMiddleware<ExpoGoManifestRequestInfo> {\n public getParsedHeaders(req: ServerRequest): ExpoGoManifestRequestInfo {\n let platform = parsePlatformHeader(req);\n\n if (!platform) {\n debug(\n `No \"expo-platform\" header or \"platform\" query parameter specified. Falling back to \"ios\".`\n );\n platform = 'ios';\n }\n\n assertRuntimePlatform(platform);\n\n // Expo Updates clients explicitly accept \"multipart/mixed\" responses while browsers implicitly\n // accept them with \"accept: */*\". To make it easier to debug manifest responses by visiting their\n // URLs in a browser, we denote the response as \"text/plain\" if the user agent appears not to be\n // an Expo Updates client.\n const accept = accepts(req);\n const acceptedType = accept.types([\n 'unknown/unknown',\n 'multipart/mixed',\n 'application/json',\n 'application/expo+json',\n 'text/plain',\n ]);\n\n let responseContentType;\n switch (acceptedType) {\n case 'multipart/mixed':\n responseContentType = ResponseContentType.MULTIPART_MIXED;\n break;\n case 'application/json':\n responseContentType = ResponseContentType.APPLICATION_JSON;\n break;\n case 'application/expo+json':\n responseContentType = ResponseContentType.APPLICATION_EXPO_JSON;\n break;\n default:\n responseContentType = ResponseContentType.TEXT_PLAIN;\n break;\n }\n\n const expectSignature = req.headers['expo-expect-signature'];\n\n return {\n responseContentType,\n platform,\n expectSignature: expectSignature ? String(expectSignature) : null,\n hostname: stripPort(req.headers['host']),\n };\n }\n\n private getDefaultResponseHeaders(): ServerHeaders {\n const headers = new Map<string, number | string | readonly string[]>();\n // set required headers for Expo Updates manifest specification\n headers.set('expo-protocol-version', 0);\n headers.set('expo-sfv-version', 0);\n headers.set('cache-control', 'private, max-age=0');\n return headers;\n }\n\n public async _getManifestResponseAsync(requestOptions: ExpoGoManifestRequestInfo): Promise<{\n body: string;\n version: string;\n headers: ServerHeaders;\n }> {\n const { exp, hostUri, expoGoConfig, bundleUrl } = await this._resolveProjectSettingsAsync(\n requestOptions\n );\n\n const runtimeVersion = Updates.getRuntimeVersion(\n { ...exp, runtimeVersion: exp.runtimeVersion ?? { policy: 'sdkVersion' } },\n requestOptions.platform\n );\n if (!runtimeVersion) {\n throw new CommandError(\n 'MANIFEST_MIDDLEWARE',\n `Unable to determine runtime version for platform '${requestOptions.platform}'`\n );\n }\n\n const codeSigningInfo = await getCodeSigningInfoAsync(\n exp,\n requestOptions.expectSignature,\n this.options.privateKeyPath\n );\n\n const easProjectId = exp.extra?.eas?.projectId as string | undefined | null;\n const scopeKey = await ExpoGoManifestHandlerMiddleware.getScopeKeyAsync({\n slug: exp.slug,\n codeSigningInfo,\n });\n\n const expoUpdatesManifest: ExpoUpdatesManifest = {\n id: crypto.randomUUID(),\n createdAt: new Date().toISOString(),\n runtimeVersion,\n launchAsset: {\n key: 'bundle',\n contentType: 'application/javascript',\n url: bundleUrl,\n },\n assets: [], // assets are not used in development\n metadata: {}, // required for the client to detect that this is an expo-updates manifest\n extra: {\n eas: {\n projectId: easProjectId ?? undefined,\n },\n expoClient: {\n ...exp,\n hostUri,\n },\n expoGo: expoGoConfig,\n scopeKey,\n },\n };\n\n const stringifiedManifest = JSON.stringify(expoUpdatesManifest);\n\n let manifestPartHeaders: { 'expo-signature': string } | null = null;\n let certificateChainBody: string | null = null;\n if (codeSigningInfo) {\n const signature = signManifestString(stringifiedManifest, codeSigningInfo);\n manifestPartHeaders = {\n 'expo-signature': serializeDictionary(\n convertToDictionaryItemsRepresentation({\n keyid: codeSigningInfo.keyId,\n sig: signature,\n alg: 'rsa-v1_5-sha256',\n })\n ),\n };\n certificateChainBody = codeSigningInfo.certificateChainForResponse.join('\\n');\n }\n\n const headers = this.getDefaultResponseHeaders();\n\n switch (requestOptions.responseContentType) {\n case ResponseContentType.MULTIPART_MIXED: {\n const form = this.getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n });\n headers.set('content-type', `multipart/mixed; boundary=${form.getBoundary()}`);\n return {\n body: form.getBuffer().toString(),\n version: runtimeVersion,\n headers,\n };\n }\n case ResponseContentType.APPLICATION_EXPO_JSON:\n case ResponseContentType.APPLICATION_JSON:\n case ResponseContentType.TEXT_PLAIN: {\n headers.set(\n 'content-type',\n ExpoGoManifestHandlerMiddleware.getContentTypeForResponseContentType(\n requestOptions.responseContentType\n )\n );\n if (manifestPartHeaders) {\n Object.entries(manifestPartHeaders).forEach(([key, value]) => {\n headers.set(key, value);\n });\n }\n\n return {\n body: stringifiedManifest,\n version: runtimeVersion,\n headers,\n };\n }\n }\n }\n\n private static getContentTypeForResponseContentType(\n responseContentType: ResponseContentType\n ): string {\n switch (responseContentType) {\n case ResponseContentType.MULTIPART_MIXED:\n return 'multipart/mixed';\n case ResponseContentType.APPLICATION_EXPO_JSON:\n return 'application/expo+json';\n case ResponseContentType.APPLICATION_JSON:\n return 'application/json';\n case ResponseContentType.TEXT_PLAIN:\n return 'text/plain';\n }\n }\n\n private getFormData({\n stringifiedManifest,\n manifestPartHeaders,\n certificateChainBody,\n }: {\n stringifiedManifest: string;\n manifestPartHeaders: { 'expo-signature': string } | null;\n certificateChainBody: string | null;\n }): FormData {\n const form = new FormData();\n form.append('manifest', stringifiedManifest, {\n contentType: 'application/json',\n header: {\n ...manifestPartHeaders,\n },\n });\n if (certificateChainBody && certificateChainBody.length > 0) {\n form.append('certificate_chain', certificateChainBody, {\n contentType: 'application/x-pem-file',\n });\n }\n return form;\n }\n\n protected trackManifest(version?: string) {\n logEventAsync('Serve Expo Updates Manifest', {\n runtimeVersion: version,\n });\n }\n\n private static async getScopeKeyAsync({\n slug,\n codeSigningInfo,\n }: {\n slug: string;\n codeSigningInfo: CodeSigningInfo | null;\n }): Promise<string> {\n const scopeKeyFromCodeSigningInfo = codeSigningInfo?.scopeKey;\n if (scopeKeyFromCodeSigningInfo) {\n return scopeKeyFromCodeSigningInfo;\n }\n\n // Log.warn(\n // env.EXPO_OFFLINE\n // ? 'Using anonymous scope key in manifest for offline mode.'\n // : 'Using anonymous scope key in manifest.'\n // );\n return await getAnonymousScopeKeyAsync(slug);\n }\n}\n\nasync function getAnonymousScopeKeyAsync(slug: string): Promise<string> {\n const userAnonymousIdentifier = await UserSettings.getAnonymousIdentifierAsync();\n return `@${ANONYMOUS_USERNAME}/${slug}-${userAnonymousIdentifier}`;\n}\n\nfunction convertToDictionaryItemsRepresentation(obj: { [key: string]: string }): Dictionary {\n return new Map(\n Object.entries(obj).map(([k, v]) => {\n return [k, [v, new Map()]];\n })\n );\n}\n"],"names":["debug","require","ResponseContentType","TEXT_PLAIN","APPLICATION_JSON","APPLICATION_EXPO_JSON","MULTIPART_MIXED","ExpoGoManifestHandlerMiddleware","ManifestMiddleware","getParsedHeaders","req","platform","parsePlatformHeader","assertRuntimePlatform","accept","accepts","acceptedType","types","responseContentType","expectSignature","headers","String","hostname","stripPort","getDefaultResponseHeaders","Map","set","_getManifestResponseAsync","requestOptions","exp","hostUri","expoGoConfig","bundleUrl","_resolveProjectSettingsAsync","runtimeVersion","Updates","getRuntimeVersion","policy","CommandError","codeSigningInfo","getCodeSigningInfoAsync","options","privateKeyPath","easProjectId","extra","eas","projectId","scopeKey","getScopeKeyAsync","slug","expoUpdatesManifest","id","crypto","randomUUID","createdAt","Date","toISOString","launchAsset","key","contentType","url","assets","metadata","undefined","expoClient","expoGo","stringifiedManifest","JSON","stringify","manifestPartHeaders","certificateChainBody","signature","signManifestString","serializeDictionary","convertToDictionaryItemsRepresentation","keyid","keyId","sig","alg","certificateChainForResponse","join","form","getFormData","getBoundary","body","getBuffer","toString","version","getContentTypeForResponseContentType","Object","entries","forEach","value","FormData","append","header","length","trackManifest","logEventAsync","scopeKeyFromCodeSigningInfo","getAnonymousScopeKeyAsync","userAnonymousIdentifier","UserSettings","getAnonymousIdentifierAsync","ANONYMOUS_USERNAME","obj","map","k","v"],"mappings":"AAAA;;;;;AACwB,IAAA,cAAsB,WAAtB,sBAAsB,CAAA;AAC1B,IAAA,QAAS,kCAAT,SAAS,EAAA;AACV,IAAA,OAAQ,kCAAR,QAAQ,EAAA;AACN,IAAA,SAAW,kCAAX,WAAW,EAAA;AACgB,IAAA,kBAAoB,WAApB,oBAAoB,CAAA;AAEZ,IAAA,mBAAsB,WAAtB,sBAAsB,CAAA;AACnB,IAAA,gBAAmB,WAAnB,mBAAmB,CAAA;AAErD,IAAA,aAAgC,kCAAhC,gCAAgC,EAAA;AACtB,IAAA,KAAwB,WAAxB,wBAAwB,CAAA;AAC7B,IAAA,kBAA4C,WAA5C,4CAA4C,CAAA;AAKnE,IAAA,YAA4B,WAA5B,4BAA4B,CAAA;AACN,IAAA,OAAuB,WAAvB,uBAAuB,CAAA;AAC1B,IAAA,IAAoB,WAApB,oBAAoB,CAAA;;;;;;AAE9C,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,8DAA8D,CAAC,AAAC;IAExF,mBAKN;;UALWC,mBAAmB;IAAnBA,mBAAmB,CAAnBA,mBAAmB,CAC7BC,YAAU,IAAVA,CAAU,IAAVA,YAAU;IADAD,mBAAmB,CAAnBA,mBAAmB,CAE7BE,kBAAgB,IAAhBA,CAAgB,IAAhBA,kBAAgB;IAFNF,mBAAmB,CAAnBA,mBAAmB,CAG7BG,uBAAqB,IAArBA,CAAqB,IAArBA,uBAAqB;IAHXH,mBAAmB,CAAnBA,mBAAmB,CAI7BI,iBAAe,IAAfA,CAAe,IAAfA,iBAAe;GAJLJ,mBAAmB,mCAAnBA,mBAAmB;AAYxB,MAAMK,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OA,2BAA2B,CAAC;SACpC;QAED,YAAY;QACZ,qBAAqB;QACrB,kEAAkE;QAClE,iDAAiD;QACjD,KAAK;QACL,OAAO,MAAMC,yBAAyB,CAACnD,IAAI,CAAC,CAAC;KAC9C;CACF;QA/OY1C,+BAA+B,GAA/BA,+BAA+B;AAiP5C,eAAe6F,yBAAyB,CAACnD,IAAY,EAAmB;IACtE,MAAMoD,uBAAuB,GAAG,MAAMC,aAAY,QAAA,CAACC,2BAA2B,EAAE,AAAC;IACjF,OAAO,CAAC,CAAC,EAAEC,KAAkB,mBAAA,CAAC,CAAC,EAAEvD,IAAI,CAAC,CAAC,EAAEoD,uBAAuB,CAAC,CAAC,CAAC;CACpE;AAED,SAAS3B,sCAAsC,CAAC+B,GAA8B,EAAc;IAC1F,OAAO,IAAIhF,GAAG,CACZgE,MAAM,CAACC,OAAO,CAACe,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,CAACC,CAAC,EAAEC,CAAC,CAAC,GAAK;QAClC,OAAO;YAACD,CAAC;YAAE;gBAACC,CAAC;gBAAE,IAAInF,GAAG,EAAE;aAAC;SAAC,CAAC;KAC5B,CAAC,CACH,CAAC;CACH"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/middleware/ExpoMiddleware.ts"],"sourcesContent":["import { parse } from 'url';\n\nimport * as Log from '../../../log';\nimport { ServerNext, ServerRequest, ServerResponse } from './server.types';\n\n/** Base middleware creator for Expo dev servers. */\nexport abstract class ExpoMiddleware {\n constructor(protected projectRoot: string, protected supportedPaths: string[]) {}\n\n /**\n * Returns true when the middleware should handle the incoming server request.\n * Exposed for testing.\n */\n _shouldHandleRequest(req: ServerRequest): boolean {\n if (!req.url) {\n return false;\n }\n const parsed = parse(req.url);\n // Strip the query params\n if (!parsed.pathname) {\n return false;\n }\n\n return this.supportedPaths.includes(parsed.pathname);\n }\n\n abstract handleRequestAsync(\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ): Promise<void>;\n\n /** Create a server middleware handler. */\n public getHandler() {\n const internalMiddleware = async (\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ) => {\n try {\n return await this.handleRequestAsync(req, res, next);\n } catch (error: any) {\n Log.exception(error);\n // 5xx = Server Error HTTP code\n res.statusCode = 500;\n if (typeof error === 'object' && error !== null) {\n res.end(\n JSON.stringify({\n error: error.toString(),\n })\n );\n } else {\n res.end(`Unexpected error: ${error}`);\n }\n }\n };\n const middleware = async (req: ServerRequest, res: ServerResponse, next: ServerNext) => {\n if (!this._shouldHandleRequest(req)) {\n return next();\n }\n return internalMiddleware(req, res, next);\n };\n\n middleware.internal = internalMiddleware;\n\n return middleware;\n }\n}\n\nexport function disableResponseCache(res: ServerResponse): ServerResponse {\n res.setHeader('Cache-Control', 'private, no-cache, no-store, must-revalidate');\n res.setHeader('Expires', '-1');\n res.setHeader('Pragma', 'no-cache');\n return res;\n}\n"],"names":["disableResponseCache","Log","ExpoMiddleware","constructor","projectRoot","supportedPaths","_shouldHandleRequest","req","url","parsed","parse","pathname","includes","getHandler","internalMiddleware","res","next","handleRequestAsync","error","exception","statusCode","end","JSON","stringify","toString","middleware","internal","setHeader"],"mappings":"AAAA;;;;QAqEgBA,oBAAoB,GAApBA,oBAAoB;AArEd,IAAA,IAAK,WAAL,KAAK,CAAA;AAEfC,IAAAA,GAAG,mCAAM,cAAc,EAApB;;;;;;;;;;;;;;;;;;;;;;AAIR,MAAeC,cAAc;IAClCC,YAAsBC,WAAmB,EAAYC,cAAwB,CAAE;aAAzDD,WAAmB,GAAnBA,WAAmB;aAAYC,cAAwB,GAAxBA,cAAwB;KAAI;IAEjF;;;KAGG,CACHC,oBAAoB,CAACC,GAAkB,EAAW;QAChD,IAAI,CAACA,GAAG,CAACC,GAAG,EAAE;YACZ,OAAO,KAAK,CAAC;SACd;QACD,MAAMC,MAAM,GAAGC,CAAAA,GAAAA,IAAK,AAAS,CAAA,MAAT,CAACH,GAAG,CAACC,GAAG,CAAC,AAAC;QAC9B,y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SAASF,oBAAoB,CAACe,GAAmB,EAAkB;IACxEA,GAAG,CAACY,SAAS,CAAC,eAAe,EAAE,8CAA8C,CAAC,CAAC;IAC/EZ,GAAG,CAACY,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/BZ,GAAG,CAACY,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACpC,OAAOZ,GAAG,CAAC;CACZ"}
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/ExpoMiddleware.ts"],"sourcesContent":["import { parse } from 'url';\n\nimport { ServerNext, ServerRequest, ServerResponse } from './server.types';\nimport * as Log from '../../../log';\n\n/** Base middleware creator for Expo dev servers. */\nexport abstract class ExpoMiddleware {\n constructor(\n protected projectRoot: string,\n protected supportedPaths: string[]\n ) {}\n\n /**\n * Returns true when the middleware should handle the incoming server request.\n * Exposed for testing.\n */\n _shouldHandleRequest(req: ServerRequest): boolean {\n if (!req.url) {\n return false;\n }\n const parsed = parse(req.url);\n // Strip the query params\n if (!parsed.pathname) {\n return false;\n }\n\n return this.supportedPaths.includes(parsed.pathname);\n }\n\n abstract handleRequestAsync(\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ): Promise<void>;\n\n /** Create a server middleware handler. */\n public getHandler() {\n const internalMiddleware = async (\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ) => {\n try {\n return await this.handleRequestAsync(req, res, next);\n } catch (error: any) {\n Log.exception(error);\n // 5xx = Server Error HTTP code\n res.statusCode = 500;\n if (typeof error === 'object' && error !== null) {\n res.end(\n JSON.stringify({\n error: error.toString(),\n })\n );\n } else {\n res.end(`Unexpected error: ${error}`);\n }\n }\n };\n const middleware = async (req: ServerRequest, res: ServerResponse, next: ServerNext) => {\n if (!this._shouldHandleRequest(req)) {\n return next();\n }\n return internalMiddleware(req, res, next);\n };\n\n middleware.internal = internalMiddleware;\n\n return middleware;\n }\n}\n\nexport function disableResponseCache(res: ServerResponse): ServerResponse {\n res.setHeader('Cache-Control', 'private, no-cache, no-store, must-revalidate');\n res.setHeader('Expires', '-1');\n res.setHeader('Pragma', 'no-cache');\n return res;\n}\n"],"names":["disableResponseCache","Log","ExpoMiddleware","constructor","projectRoot","supportedPaths","_shouldHandleRequest","req","url","parsed","parse","pathname","includes","getHandler","internalMiddleware","res","next","handleRequestAsync","error","exception","statusCode","end","JSON","stringify","toString","middleware","internal","setHeader"],"mappings":"AAAA;;;;QAwEgBA,oBAAoB,GAApBA,oBAAoB;AAxEd,IAAA,IAAK,WAAL,KAAK,CAAA;AAGfC,IAAAA,GAAG,mCAAM,cAAc,EAApB;;;;;;;;;;;;;;;;;;;;;;AAGR,MAAeC,cAAc;IAClCC,YACYC,WAAmB,EACnBC,cAAwB,CAClC;aAFUD,WAAmB,GAAnBA,WAAmB;aACnBC,cAAwB,GAAxBA,cAAwB;KAChC;IAEJ;;;KAGG,CACHC,oBAAoB,CAACC,GAAkB,EAAW;QAChD,IAAI,CAACA,GAAG,CAACC,GAAG,EAAE;YACZ,OAAO,KAAK,CAAC;SACd;QACD,MAAMC,MAAM,GAAGC,CAAAA,GAAAA,IAAK,AAAS,CAAA,MAAT,CAACH,GAAG,CAACC,GAAG,CAAC,AAAC;QAC9B,yBAAyB;QACzB,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAE;YACpB,OAAO,KAAK,CAAC;SACd;QAED,OAAO,IAAI,CAACN,cAAc,CAACO,QAAQ,CAACH,MAAM,CAACE,QAAQ,CAAC,CAAC;KACtD;IAQD,0CAA0C,CAC1C,AAAOE,UAAU,GAAG;QAClB,MAAMC,kBAAkB,GAAG,OACzBP,GAAkB,EAClBQ,GAAmB,EACnBC,IAAgB,GACb;YACH,IAAI;gBACF,OAAO,MAAM,IAAI,CAACC,kBAAkB,CAACV,GAAG,EAAEQ,GAAG,EAAEC,IAAI,CAAC,CAAC;aACtD,CAAC,OAAOE,KAAK,EAAO;gBACnBjB,GAAG,CAACkB,SAAS,CAACD,KAAK,CAAC,CAAC;gBACrB,+BAA+B;gBAC/BH,GAAG,CAACK,UAAU,GAAG,GAAG,CAAC;gBACrB,IAAI,OAAOF,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI,EAAE;oBAC/CH,GAAG,CAACM,GAAG,CACLC,IAAI,CAACC,SAAS,CAAC;wBACbL,KAAK,EAAEA,KAAK,CAACM,QAAQ,EAAE;qBACxB,CAAC,CACH,CAAC;iBACH,MAAM;oBACLT,GAAG,CAACM,GAAG,CAAC,CAAC,kBAAkB,EAAEH,KAAK,CAAC,CAAC,CAAC,CAAC;iBACvC;aACF;SACF,AAAC;QACF,MAAMO,UAAU,GAAG,OAAOlB,GAAkB,EAAEQ,GAAmB,EAAEC,IAAgB,GAAK;YACtF,IAAI,CAAC,IAAI,CAACV,oBAAoB,CAACC,GAAG,CAAC,EAAE;gBACnC,OAAOS,IAAI,EAAE,CAAC;aACf;YACD,OAAOF,kBAAkB,CAACP,GAAG,EAAEQ,GAAG,EAAEC,IAAI,CAAC,CAAC;SAC3C,AAAC;QAEFS,UAAU,CAACC,QAAQ,GAAGZ,kBAAkB,CAAC;QAEzC,OAAOW,UAAU,CAAC;KACnB;CACF;QAhEqBvB,cAAc,GAAdA,cAAc;AAkE7B,SAASF,oBAAoB,CAACe,GAAmB,EAAkB;IACxEA,GAAG,CAACY,SAAS,CAAC,eAAe,EAAE,8CAA8C,CAAC,CAAC;IAC/EZ,GAAG,CAACY,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC/BZ,GAAG,CAACY,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACpC,OAAOZ,GAAG,CAAC;CACZ"}
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- var _favicon = require("../../../export/favicon");
6
5
  var _expoMiddleware = require("./ExpoMiddleware");
6
+ var _favicon = require("../../../export/favicon");
7
7
  const debug = require("debug")("expo:start:server:middleware:favicon");
8
8
  class FaviconMiddleware extends _expoMiddleware.ExpoMiddleware {
9
9
  constructor(projectRoot){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/start/server/middleware/FaviconMiddleware.ts"],"sourcesContent":["import { getFaviconFromExpoConfigAsync } from '../../../export/favicon';\nimport { ExpoMiddleware } from './ExpoMiddleware';\nimport { ServerNext, ServerRequest, ServerResponse } from './server.types';\n\nconst debug = require('debug')('expo:start:server:middleware:favicon') as typeof console.log;\n\n/**\n * Middleware for generating a favicon.ico file for the current project if one doesn't exist.\n *\n * Test by making a get request with:\n * curl -v http://localhost:8081/favicon.ico\n */\nexport class FaviconMiddleware extends ExpoMiddleware {\n constructor(protected projectRoot: string) {\n super(projectRoot, ['/favicon.ico']);\n }\n\n async handleRequestAsync(\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ): Promise<void> {\n if (!['GET', 'HEAD'].includes(req.method || '')) {\n return next();\n }\n\n let faviconImageData: Buffer | null;\n try {\n const data = await getFaviconFromExpoConfigAsync(this.projectRoot);\n if (!data) {\n debug('No favicon defined in the Expo Config, skipping generation.');\n return next();\n }\n faviconImageData = data.source;\n debug('✅ Generated favicon successfully.');\n } catch (error: any) {\n debug('Failed to generate favicon from Expo config:', error);\n return next(error);\n }\n // Respond with the generated favicon file\n res.setHeader('Content-Type', 'image/x-icon');\n res.end(faviconImageData);\n }\n}\n"],"names":["debug","require","FaviconMiddleware","ExpoMiddleware","constructor","projectRoot","handleRequestAsync","req","res","next","includes","method","faviconImageData","data","getFaviconFromExpoConfigAsync","source","error","setHeader","end"],"mappings":"AAAA;;;;AAA8C,IAAA,QAAyB,WAAzB,yBAAyB,CAAA;AACxC,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAGjD,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,sCAAsC,CAAC,AAAsB,AAAC;AAQtF,MAAMC,iBAAiB,SAASC,eAAc,eAAA;IACnDC,YAAsBC,WAAmB,CAAE;QACzC,KAAK,CAACA,WAAW,EAAE;YAAC,cAAc;SAAC,CAAC,CAAC;aADjBA,WAAmB,GAAnBA,WAAmB;KAExC;IAED,MAAMC,kBAAkB,CACtBC,GAAkB,EAClBC,GAAmB,EACnBC,IAAgB,EACD;QACf,IAAI,CAAC;YAAC,KAAK;YAAE,MAAM;SAAC,CAACC,QAAQ,CAACH,GAAG,CAACI,MAAM,IAAI,EAAE,CAAC,EAAE;YAC/C,OAAOF,IAAI,EAAE,CAAC;SACf;QAED,IAAIG,gBAAgB,AAAe,AAAC;QACpC,IAAI;YACF,MAAMC,IAAI,GAAG,MAAMC,CAAAA,GAAAA,QAA6B,AAAkB,CAAA,8BAAlB,CAAC,IAAI,CAACT,WAAW,CAAC,AAAC;YACnE,IAAI,CAACQ,IAAI,EAAE;gBACTb,KAAK,CAAC,6DAA6D,CAAC,CAAC;gBACrE,OAAOS,IAAI,EAAE,CAAC;aACf;YACDG,gBAAgB,GAAGC,IAAI,CAACE,MAAM,CAAC;YAC/Bf,KAAK,CAAC,wCAAmC,CAAC,CAAC;SAC5C,CAAC,OAAOgB,KAAK,EAAO;YACnBhB,KAAK,CAAC,8CAA8C,EAAEgB,KAAK,CAAC,CAAC;YAC7D,OAAOP,IAAI,CAACO,KAAK,CAAC,CAAC;SACpB;QACD,0CAA0C;QAC1CR,GAAG,CAACS,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QAC9CT,GAAG,CAACU,GAAG,CAACN,gBAAgB,CAAC,CAAC;KAC3B;CACF;QA/BYV,iBAAiB,GAAjBA,iBAAiB"}
1
+ {"version":3,"sources":["../../../../../src/start/server/middleware/FaviconMiddleware.ts"],"sourcesContent":["import { ExpoMiddleware } from './ExpoMiddleware';\nimport { ServerNext, ServerRequest, ServerResponse } from './server.types';\nimport { getFaviconFromExpoConfigAsync } from '../../../export/favicon';\n\nconst debug = require('debug')('expo:start:server:middleware:favicon') as typeof console.log;\n\n/**\n * Middleware for generating a favicon.ico file for the current project if one doesn't exist.\n *\n * Test by making a get request with:\n * curl -v http://localhost:8081/favicon.ico\n */\nexport class FaviconMiddleware extends ExpoMiddleware {\n constructor(protected projectRoot: string) {\n super(projectRoot, ['/favicon.ico']);\n }\n\n async handleRequestAsync(\n req: ServerRequest,\n res: ServerResponse,\n next: ServerNext\n ): Promise<void> {\n if (!['GET', 'HEAD'].includes(req.method || '')) {\n return next();\n }\n\n let faviconImageData: Buffer | null;\n try {\n const data = await getFaviconFromExpoConfigAsync(this.projectRoot);\n if (!data) {\n debug('No favicon defined in the Expo Config, skipping generation.');\n return next();\n }\n faviconImageData = data.source;\n debug('✅ Generated favicon successfully.');\n } catch (error: any) {\n debug('Failed to generate favicon from Expo config:', error);\n return next(error);\n }\n // Respond with the generated favicon file\n res.setHeader('Content-Type', 'image/x-icon');\n res.end(faviconImageData);\n }\n}\n"],"names":["debug","require","FaviconMiddleware","ExpoMiddleware","constructor","projectRoot","handleRequestAsync","req","res","next","includes","method","faviconImageData","data","getFaviconFromExpoConfigAsync","source","error","setHeader","end"],"mappings":"AAAA;;;;AAA+B,IAAA,eAAkB,WAAlB,kBAAkB,CAAA;AAEH,IAAA,QAAyB,WAAzB,yBAAyB,CAAA;AAEvE,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAO,CAAC,CAAC,sCAAsC,CAAC,AAAsB,AAAC;AAQtF,MAAMC,iBAAiB,SAASC,eAAc,eAAA;IACnDC,YAAsBC,WAAmB,CAAE;QACzC,KAAK,CAACA,WAAW,EAAE;YAAC,cAAc;SAAC,CAAC,CAAC;aADjBA,WAAmB,GAAnBA,WAAmB;KAExC;IAED,MAAMC,kBAAkB,CACtBC,GAAkB,EAClBC,GAAmB,EACnBC,IAAgB,EACD;QACf,IAAI,CAAC;YAAC,KAAK;YAAE,MAAM;SAAC,CAACC,QAAQ,CAACH,GAAG,CAACI,MAAM,IAAI,EAAE,CAAC,EAAE;YAC/C,OAAOF,IAAI,EAAE,CAAC;SACf;QAED,IAAIG,gBAAgB,AAAe,AAAC;QACpC,IAAI;YACF,MAAMC,IAAI,GAAG,MAAMC,CAAAA,GAAAA,QAA6B,AAAkB,CAAA,8BAAlB,CAAC,IAAI,CAACT,WAAW,CAAC,AAAC;YACnE,IAAI,CAACQ,IAAI,EAAE;gBACTb,KAAK,CAAC,6DAA6D,CAAC,CAAC;gBACrE,OAAOS,IAAI,EAAE,CAAC;aACf;YACDG,gBAAgB,GAAGC,IAAI,CAACE,MAAM,CAAC;YAC/Bf,KAAK,CAAC,wCAAmC,CAAC,CAAC;SAC5C,CAAC,OAAOgB,KAAK,EAAO;YACnBhB,KAAK,CAAC,8CAA8C,EAAEgB,KAAK,CAAC,CAAC;YAC7D,OAAOP,IAAI,CAACO,KAAK,CAAC,CAAC;SACpB;QACD,0CAA0C;QAC1CR,GAAG,CAACS,SAAS,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QAC9CT,GAAG,CAACU,GAAG,CAACN,gBAAgB,CAAC,CAAC;KAC3B;CACF;QA/BYV,iBAAiB,GAAjBA,iBAAiB"}
@@ -14,16 +14,16 @@ var _findYarnWorkspaceRoot = _interopRequireDefault(require("find-yarn-workspace
14
14
  var _path = _interopRequireDefault(require("path"));
15
15
  var _resolveFrom = _interopRequireDefault(require("resolve-from"));
16
16
  var _url = require("url");
17
+ var _expoMiddleware = require("./ExpoMiddleware");
18
+ var _resolveAssets = require("./resolveAssets");
19
+ var _resolveEntryPoint = require("./resolveEntryPoint");
20
+ var _resolvePlatform = require("./resolvePlatform");
17
21
  var Log = _interopRequireWildcard(require("../../../log"));
18
22
  var _env = require("../../../utils/env");
19
23
  var _url1 = require("../../../utils/url");
20
24
  var ProjectDevices = _interopRequireWildcard(require("../../project/devices"));
21
25
  var _platformBundlers = require("../platformBundlers");
22
26
  var _webTemplate = require("../webTemplate");
23
- var _expoMiddleware = require("./ExpoMiddleware");
24
- var _resolveAssets = require("./resolveAssets");
25
- var _resolveEntryPoint = require("./resolveEntryPoint");
26
- var _resolvePlatform = require("./resolvePlatform");
27
27
  function _interopRequireDefault(obj) {
28
28
  return obj && obj.__esModule ? obj : {
29
29
  default: obj
@@ -86,7 +86,7 @@ function shouldEnableAsyncImports(projectRoot) {
86
86
  // Expo Router automatically pulls this in, so we can check for it.
87
87
  return _resolveFrom.default.silent(projectRoot, "@expo/metro-runtime") != null;
88
88
  }
89
- function createBundleUrlPath({ platform , mainModuleName , mode , minify =mode === "production" , environment , serializerOutput , lazy }) {
89
+ function createBundleUrlPath({ platform , mainModuleName , mode , minify =mode === "production" , environment , serializerOutput , serializerIncludeMaps , lazy }) {
90
90
  const queryParams = new URLSearchParams({
91
91
  platform: encodeURIComponent(platform),
92
92
  dev: String(mode !== "production"),
@@ -106,6 +106,9 @@ function createBundleUrlPath({ platform , mainModuleName , mode , minify =mode =
106
106
  if (serializerOutput) {
107
107
  queryParams.append("serializer.output", serializerOutput);
108
108
  }
109
+ if (serializerIncludeMaps) {
110
+ queryParams.append("serializer.map", String(serializerIncludeMaps));
111
+ }
109
112
  return `/${encodeURI(mainModuleName)}.bundle?${queryParams.toString()}`;
110
113
  }
111
114
  const DEVELOPER_TOOL = "expo-cli";
@@ -210,12 +213,6 @@ class ManifestMiddleware extends _expoMiddleware.ExpoMiddleware {
210
213
  scheme: "",
211
214
  hostname
212
215
  }),
213
- // http://localhost:8081/logs -- used to send logs to the CLI for displaying in the terminal.
214
- // This is deprecated in favor of the WebSocket connection setup in Metro.
215
- logUrl: this.options.constructUrl({
216
- scheme: "http",
217
- hostname
218
- }) + "/logs",
219
216
  // Required for Expo Go to function.
220
217
  developer: {
221
218
  tool: DEVELOPER_TOOL,