@bugsee/react-native 0.0.0-stage → 7.0.0-beta1

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 (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +552 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +944 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,1066 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HERMES_COMMAND_UNREWRITABLE = exports.LEGACY_HERMES_COMMAND_EXPR = exports.HERMES_COMMAND_EXPR = exports.CHANGED_SYMBOL_BLOCK_NOTE = exports.CANNOT_EDIT = void 0;
4
+ exports.ensureMavenCentral = ensureMavenCentral;
5
+ exports.ensureGradlePluginDeclared = ensureGradlePluginDeclared;
6
+ exports.ensureAppAppliesPlugin = ensureAppAppliesPlugin;
7
+ exports.ensureSymbolUploads = ensureSymbolUploads;
8
+ exports.applyUploadSourcemapsProperty = applyUploadSourcemapsProperty;
9
+ // The rule for every edit here: a prebuild, clean or --no-clean, run any
10
+ // number of times, never removes or changes a byte of the user's own code.
11
+ // Every transform reads the file through one Groovy lexer, so a keyword, a
12
+ // brace or a Bugsee marker inside a comment or a string is never a target,
13
+ // and only Bugsee's own exact lines are ever replaced or removed. Where the
14
+ // file cannot be read or edited with certainty, the transform refuses with
15
+ // one error that names the file, the reason and the manual fix.
16
+ const PLUGIN_ID = 'com.bugsee.android.gradle';
17
+ const APP_GRADLE = 'android/app/build.gradle';
18
+ const ROOT_GRADLE = 'android/build.gradle';
19
+ const SETTINGS_GRADLE = 'android/settings.gradle';
20
+ /** Every refusal starts with this, then the file, the reason and the manual fix. */
21
+ exports.CANNOT_EDIT = '@bugsee/react-native cannot edit';
22
+ const BY_HAND = 'or make the Bugsee edits by hand (package README, "Android source maps")';
23
+ function refusal(file, reason, fix) {
24
+ return new Error(`${exports.CANNOT_EDIT} ${file}: ${reason}. ${fix}`);
25
+ }
26
+ function unreadable(file, reason) {
27
+ return refusal(file, reason, `Fix that line, ${BY_HAND}, then run expo prebuild again`);
28
+ }
29
+ /**
30
+ * Runs a transform; anything that is not already a refusal (a defect in the
31
+ * plugin) becomes one, so a prebuild never shows a raw TypeError and never
32
+ * writes a half-made edit.
33
+ */
34
+ function guarded(file, transform) {
35
+ try {
36
+ return transform();
37
+ }
38
+ catch (error) {
39
+ const message = error instanceof Error ? error.message : String(error);
40
+ if (message.startsWith(exports.CANNOT_EDIT)) {
41
+ throw error;
42
+ }
43
+ throw refusal(file, `the plugin hit an internal error while reading it (${message})`, `Report this with the file attached, ${BY_HAND}, then run expo prebuild again`);
44
+ }
45
+ }
46
+ /** A brace that shares its line with other code is not an anchor: refuse rather than split the line. */
47
+ function anchorRefusal(file, line, lineNo, what, alternative) {
48
+ const code = codeOf(line).trim();
49
+ if (line.openAtEnd) {
50
+ // A line added after this one would land inside the comment or string.
51
+ return refusal(file, `line ${lineNo}: \`${code}\` ends inside a block comment or string that is still open, so ${what} cannot be added after it`, `Close the comment on that line, or ${alternative}, then run expo prebuild again`);
52
+ }
53
+ if (code === '{') {
54
+ return refusal(file, `line ${lineNo}: the \`{\` is on a line of its own, so ${what} cannot be added without rewriting the line that names the block`, `Move the \`{\` up to the end of the line that names the block, or ${alternative}, then run expo prebuild again`);
55
+ }
56
+ return refusal(file, `line ${lineNo}: \`${code}\` shares its line with other code, so ${what} cannot be added without rewriting that line`, `Put the brace alone on its line, or ${alternative}, then run expo prebuild again`);
57
+ }
58
+ const KIND_CODE = 0;
59
+ const KIND_STRING = 1;
60
+ const KIND_COMMENT = 2;
61
+ /** Keywords after which Groovy reads `/` as the start of a slashy string. */
62
+ const BEFORE_EXPRESSION = new Set(['return', 'in', 'case', 'assert', 'throw', 'else', 'do']);
63
+ /** Characters after which `/` can only start a slashy string. */
64
+ const OPERATOR_BEFORE_SLASHY = '=([{,:;!?&|+-*<>~^%';
65
+ /** Stands for a string that just ended, as the previous code token. */
66
+ const STRING_END = '"';
67
+ const isWordChar = (ch) => /[A-Za-z0-9_]/.test(ch);
68
+ const isBlank = (ch) => ch === ' ' || ch === '\t' || ch === '\r';
69
+ /**
70
+ * Whether a `/` starts a slashy string (true), divides (false), or cannot be
71
+ * told apart (null). `last` is the previous code character on the line ('' at
72
+ * the start of the line), `word` the identifier it ends, `spaced` whether
73
+ * whitespace separates it from the slash, and `tight` whether the slash is
74
+ * followed by a non-space character.
75
+ */
76
+ function slashyAllowed(last, word, spaced, tight) {
77
+ if (last === ')' || last === ']' || last === STRING_END) {
78
+ return false;
79
+ }
80
+ if (isWordChar(last)) {
81
+ const identifier = word();
82
+ if (identifier === null) {
83
+ return null;
84
+ }
85
+ if (BEFORE_EXPRESSION.has(identifier)) {
86
+ return true;
87
+ }
88
+ // `a /b/` reads like a regex argument, `a / b` and `a/b` like division.
89
+ return spaced && tight ? null : false;
90
+ }
91
+ if (last !== '' && OPERATOR_BEFORE_SLASHY.includes(last)) {
92
+ return true;
93
+ }
94
+ return null;
95
+ }
96
+ /**
97
+ * A Groovy lexer deep enough to tell code from comments and strings, and to
98
+ * count braces in code only: `//` and block comments; '…', "…", '''…''' and
99
+ * """…""" with backslash escapes; slashy /…/ and dollar-slashy $/…/$ strings;
100
+ * `${…}` interpolation with nested code. Anything it cannot read with
101
+ * certainty — a string that does not close on its line, a construct still
102
+ * open at the end of the file, braces that do not balance, a `/` that may be
103
+ * a slashy string or a division — is a refusal, never a guess.
104
+ */
105
+ function scan(source, file) {
106
+ const masked = [];
107
+ const kinds = [];
108
+ const lines = [];
109
+ const stack = [];
110
+ const openBraces = [];
111
+ let depth = 0;
112
+ let lineNo = 1;
113
+ // Per-line state; startLine resets it for every line after the first.
114
+ let lineStart = 0;
115
+ let lineDepth = 0;
116
+ let lineOpenAtStart = false;
117
+ let commentAt = null;
118
+ /** The previous code character on the line, STRING_END for a string, '' at the line start. */
119
+ let last = '';
120
+ const top = () => stack[stack.length - 1];
121
+ const inString = () => stack.some((frame) => frame.kind === 'string');
122
+ const emit = (ch) => {
123
+ if (ch === '\n') {
124
+ masked.push('\n');
125
+ kinds.push(KIND_CODE);
126
+ }
127
+ else if (inString()) {
128
+ masked.push('S');
129
+ kinds.push(KIND_STRING);
130
+ }
131
+ else if (top()?.kind === 'comment') {
132
+ masked.push(' ');
133
+ kinds.push(KIND_COMMENT);
134
+ }
135
+ else {
136
+ masked.push(ch);
137
+ kinds.push(KIND_CODE);
138
+ }
139
+ };
140
+ const emitN = (from, count) => {
141
+ for (let k = 0; k < count; k += 1) {
142
+ emit(source[from + k]);
143
+ }
144
+ };
145
+ /** `ch` is the code character just read, or a sentinel for a string that just ended. */
146
+ const noteCode = (ch) => {
147
+ commentAt = null;
148
+ last = ch;
149
+ };
150
+ /** The identifier that ends right before `at`, when `last` is a word character; null when a comment sits between. */
151
+ const wordBefore = (at) => /[A-Za-z0-9_]+\s*$/.exec(source.slice(lineStart, at))?.[0].trimEnd() ?? null;
152
+ const endLine = (end) => {
153
+ lines.push({
154
+ start: lineStart,
155
+ raw: source.slice(lineStart, end),
156
+ code: masked.slice(lineStart, end).join(''),
157
+ depth: lineDepth,
158
+ depthAfter: depth,
159
+ openAtStart: lineOpenAtStart,
160
+ openAtEnd: stack.length > 0,
161
+ commentAt,
162
+ });
163
+ };
164
+ const startLine = (at) => {
165
+ lineStart = at;
166
+ lineDepth = depth;
167
+ lineOpenAtStart = stack.length > 0;
168
+ commentAt = null;
169
+ last = '';
170
+ };
171
+ let i = 0;
172
+ while (i < source.length) {
173
+ const ch = source[i];
174
+ const frame = top();
175
+ if (ch === '\n') {
176
+ if (frame?.kind === 'string' && frame.oneLine) {
177
+ throw unreadable(file, `line ${frame.line}: a string opened on this line does not close on it`);
178
+ }
179
+ if (frame?.kind === 'comment' && !frame.block) {
180
+ stack.pop();
181
+ }
182
+ endLine(i);
183
+ emit('\n');
184
+ i += 1;
185
+ lineNo += 1;
186
+ startLine(i);
187
+ continue;
188
+ }
189
+ if (frame?.kind === 'comment') {
190
+ if (frame.block && source.startsWith('*/', i)) {
191
+ emitN(i, 2);
192
+ i += 2;
193
+ stack.pop();
194
+ }
195
+ else {
196
+ emit(ch);
197
+ i += 1;
198
+ }
199
+ continue;
200
+ }
201
+ if (frame?.kind === 'string') {
202
+ const next = source[i + 1];
203
+ if (frame.escape === 'quoted' && ch === '\\' && (next ?? '\n') !== '\n') {
204
+ emitN(i, 2);
205
+ i += 2;
206
+ continue;
207
+ }
208
+ if (frame.escape === 'slashy' && ch === '\\' && next === '/') {
209
+ emitN(i, 2);
210
+ i += 2;
211
+ continue;
212
+ }
213
+ if (frame.escape === 'dollar' && ch === '$' && (next === '$' || next === '/')) {
214
+ emitN(i, 2);
215
+ i += 2;
216
+ continue;
217
+ }
218
+ if (frame.interpolates && ch === '$' && next === '{') {
219
+ emitN(i, 2);
220
+ i += 2;
221
+ stack.push({ kind: 'code', depth: 1, line: lineNo });
222
+ continue;
223
+ }
224
+ if (source.startsWith(frame.close, i)) {
225
+ // A fourth quote: the first one is content and the string closes on the last three.
226
+ if (frame.close.length === 3 && source[i + 3] === ch) {
227
+ emit(ch);
228
+ i += 1;
229
+ continue;
230
+ }
231
+ emitN(i, frame.close.length);
232
+ i += frame.close.length;
233
+ stack.pop();
234
+ continue;
235
+ }
236
+ emit(ch);
237
+ i += 1;
238
+ continue;
239
+ }
240
+ // Code, at the top level or inside an interpolation.
241
+ if (ch === '/') {
242
+ const next = source[i + 1];
243
+ if (next === '/' || next === '*') {
244
+ commentAt = commentAt ?? i - lineStart;
245
+ stack.push({ kind: 'comment', block: next === '*', line: lineNo });
246
+ emitN(i, 2);
247
+ i += 2;
248
+ continue;
249
+ }
250
+ const spaced = isBlank(source[i - 1] ?? '');
251
+ const after = next ?? '\n';
252
+ const tight = !isBlank(after) && after !== '\n';
253
+ const slashy = slashyAllowed(last, () => wordBefore(i), spaced, tight);
254
+ if (slashy === null) {
255
+ throw unreadable(file, `line ${lineNo}: cannot tell whether the / starts a slashy string or divides`);
256
+ }
257
+ noteCode(slashy ? STRING_END : ch);
258
+ if (slashy) {
259
+ stack.push({ kind: 'string', close: '/', interpolates: true, escape: 'slashy', oneLine: false, line: lineNo });
260
+ }
261
+ emit(ch);
262
+ i += 1;
263
+ continue;
264
+ }
265
+ // `$` is an identifier character too: `a$/2` is `a$` divided, not a dollar-slashy string.
266
+ if (ch === '$' && source[i + 1] === '/' && !isWordChar(last)) {
267
+ noteCode(STRING_END);
268
+ stack.push({ kind: 'string', close: '/$', interpolates: true, escape: 'dollar', oneLine: false, line: lineNo });
269
+ emitN(i, 2);
270
+ i += 2;
271
+ continue;
272
+ }
273
+ if (ch === '"' || ch === "'") {
274
+ const triple = source.startsWith(ch.repeat(3), i);
275
+ noteCode(STRING_END);
276
+ stack.push({
277
+ kind: 'string',
278
+ close: triple ? ch.repeat(3) : ch,
279
+ interpolates: ch === '"',
280
+ escape: 'quoted',
281
+ oneLine: !triple,
282
+ line: lineNo,
283
+ });
284
+ emitN(i, triple ? 3 : 1);
285
+ i += triple ? 3 : 1;
286
+ continue;
287
+ }
288
+ if (ch === '{') {
289
+ if (frame) {
290
+ frame.depth += 1;
291
+ }
292
+ else {
293
+ depth += 1;
294
+ openBraces.push(lineNo);
295
+ }
296
+ noteCode(ch);
297
+ emit(ch);
298
+ i += 1;
299
+ continue;
300
+ }
301
+ if (ch === '}') {
302
+ if (frame) {
303
+ frame.depth -= 1;
304
+ if (frame.depth === 0) {
305
+ stack.pop();
306
+ }
307
+ }
308
+ else {
309
+ if (depth === 0) {
310
+ throw unreadable(file, `line ${lineNo}: a closing brace has no opening brace`);
311
+ }
312
+ depth -= 1;
313
+ openBraces.pop();
314
+ }
315
+ noteCode(ch);
316
+ emit(ch);
317
+ i += 1;
318
+ continue;
319
+ }
320
+ if (!isBlank(ch)) {
321
+ noteCode(ch);
322
+ }
323
+ emit(ch);
324
+ i += 1;
325
+ }
326
+ const open = top();
327
+ if (open?.kind === 'comment' && open.block) {
328
+ throw unreadable(file, `line ${open.line}: a block comment opened on this line never closes`);
329
+ }
330
+ if (open?.kind === 'string') {
331
+ if (open.oneLine) {
332
+ throw unreadable(file, `line ${open.line}: a string opened on this line does not close on it`);
333
+ }
334
+ throw unreadable(file, `line ${open.line}: a string opened on this line never closes`);
335
+ }
336
+ if (open?.kind === 'code') {
337
+ throw unreadable(file, `line ${open.line}: a \${ interpolation opened on this line never closes`);
338
+ }
339
+ if (depth > 0) {
340
+ throw unreadable(file, `line ${openBraces[0]}: a brace opened on this line never closes`);
341
+ }
342
+ // A line comment may still be open here; the last line's openAtEnd is never read.
343
+ endLine(source.length);
344
+ const text = masked.join('');
345
+ if (text.length !== source.length) {
346
+ throw new Error(`the mask drifted from the source (${text.length} vs ${source.length})`);
347
+ }
348
+ return {
349
+ file,
350
+ source,
351
+ masked: text,
352
+ lines,
353
+ isCode: (index) => kinds[index] === KIND_CODE,
354
+ };
355
+ }
356
+ // ---------------------------------------------------------------------------
357
+ // Shared helpers
358
+ // ---------------------------------------------------------------------------
359
+ const eolOf = (source) => (source.includes('\r\n') ? '\r\n' : '\n');
360
+ const crOf = (eol) => (eol === '\r\n' ? '\r' : '');
361
+ const stripCr = (line) => line.replace(/\r$/, '');
362
+ /** The line's code as written, up to a trailing comment, carriage return excluded. */
363
+ function codeOf(line) {
364
+ return stripCr(line.raw.slice(0, line.commentAt ?? line.raw.length));
365
+ }
366
+ /** A line that is only a `//` comment in code context, at any indentation. */
367
+ function isLineComment(line) {
368
+ return !line.openAtStart && line.commentAt !== null && line.raw.slice(0, line.commentAt).trim() === '' && line.raw.slice(line.commentAt).startsWith('//');
369
+ }
370
+ /** Bugsee's own comment line, as the plugin writes it, at any indentation. */
371
+ function isMarker(line, marker) {
372
+ return isLineComment(line) && stripCr(line.raw).trim() === marker;
373
+ }
374
+ const indentOf = (raw) => raw.slice(0, raw.length - raw.trimStart().length);
375
+ /** The line opens a block with nothing but `keyword {` (a trailing comment allowed) on it. */
376
+ function isOpenerLine(line, keyword) {
377
+ return !line.openAtStart && keyword.test(codeOf(line).trim());
378
+ }
379
+ /** The line holds nothing but a closing brace (a trailing comment allowed). */
380
+ function isCloserLine(line) {
381
+ return !line.openAtStart && codeOf(line).trim() === '}';
382
+ }
383
+ /** The indentation of the block's first direct entry, or one level under the opener when it has none. */
384
+ function innerIndent(s, opener, closer) {
385
+ const inner = s.lines.slice(opener + 1, closer).find((line) => stripCr(line.raw).trim() !== '');
386
+ return inner !== undefined ? indentOf(inner.raw) : `${indentOf(s.lines[opener].raw)} `;
387
+ }
388
+ /** Inserts `added` (without EOLs) as whole lines at line index `at`, with the file's EOL. */
389
+ function insertLines(source, at, added) {
390
+ const lines = source.split('\n');
391
+ const cr = crOf(eolOf(source));
392
+ lines.splice(at, 0, ...added.map((line) => `${line}${cr}`));
393
+ return lines.join('\n');
394
+ }
395
+ /** Bugsee's own code line, exactly, alone as a statement, at the top level, nothing after it. */
396
+ function isOwnStatement(line, statement) {
397
+ return (line !== undefined &&
398
+ !line.openAtStart &&
399
+ line.depth === 0 &&
400
+ line.commentAt === null &&
401
+ codeOf(line).trim() === statement);
402
+ }
403
+ /**
404
+ * Appends a block after the content, separated by one blank line, keeping
405
+ * the file's own trailing whitespace. The block's lines use the file's EOL.
406
+ */
407
+ function appendBlock(source, block, eol) {
408
+ const body = block.split('\n').join(eol);
409
+ if (source === '') {
410
+ return `${body}${eol}`;
411
+ }
412
+ const lead = source.endsWith('\n') ? eol : `${eol}${eol}`;
413
+ return `${source}${lead}${body}${eol}`;
414
+ }
415
+ /**
416
+ * Removes lines `from` through `to`, with the blank line before them when
417
+ * there is one: the one appendBlock put there.
418
+ */
419
+ function removeBlock(lines, from, to) {
420
+ const blank = from > 0 && lines[from - 1].trim() === '' ? 1 : 0;
421
+ lines.splice(from - blank, to - from + 1 + blank);
422
+ }
423
+ /** Index of the first line of `block` written as consecutive own lines at the top level, or -1. */
424
+ function findOwnBlock(s, block) {
425
+ return s.lines.findIndex((first, i) => first.depth === 0 &&
426
+ block.every((text, k) => {
427
+ const line = s.lines[i + k];
428
+ return line !== undefined && !line.openAtStart && stripCr(line.raw) === text;
429
+ }));
430
+ }
431
+ /** Index of the matching `}` for the `{` at `open`, counting code braces only. */
432
+ function matchingBrace(masked, open) {
433
+ let depth = 0;
434
+ let i = open;
435
+ for (;; i += 1) {
436
+ const ch = masked[i];
437
+ if (ch === '{') {
438
+ depth += 1;
439
+ }
440
+ else if (ch === '}') {
441
+ depth -= 1;
442
+ if (depth === 0) {
443
+ return i;
444
+ }
445
+ }
446
+ }
447
+ }
448
+ /** The first `keyword {` block in code, searched within [from, to); with `topLevel`, only one at brace depth 0. */
449
+ function blockExtent(s, keyword, from = 0, to = s.masked.length, topLevel = false) {
450
+ // The mask has no keyword in a string or comment, so any match is code.
451
+ const re = new RegExp(`(?<![A-Za-z0-9_])${keyword}\\s*\\{`, 'g');
452
+ re.lastIndex = from;
453
+ const region = s.masked.slice(0, to);
454
+ for (let m = re.exec(region); m !== null; m = re.exec(region)) {
455
+ const open = m.index + m[0].length - 1;
456
+ if (!topLevel || depthAt(s, open) === 0) {
457
+ return { open, bodyStart: open + 1, bodyEnd: matchingBrace(s.masked, open) };
458
+ }
459
+ }
460
+ return null;
461
+ }
462
+ /** Index of the line holding the character at `index`. */
463
+ const lineIndexAt = (s, index) => s.source.slice(0, index).split('\n').length - 1;
464
+ /** Brace depth, code only, just before `index`. */
465
+ function depthAt(s, index) {
466
+ const line = s.lines[lineIndexAt(s, index)];
467
+ const before = s.masked.slice(line.start, index);
468
+ return line.depth + before.split('{').length - before.split('}').length;
469
+ }
470
+ /** Matches of `re` (global) in the source whose first character is code, within [from, to). */
471
+ function codeMatches(s, re, from = 0, to = s.source.length) {
472
+ const out = [];
473
+ const region = s.source.slice(0, to);
474
+ re.lastIndex = from;
475
+ for (let m = re.exec(region); m !== null; m = re.exec(region)) {
476
+ if (s.isCode(m.index)) {
477
+ out.push(m);
478
+ }
479
+ }
480
+ return out;
481
+ }
482
+ /** True when `needle` occurs in code or in a string, not only in comments. */
483
+ function occursLive(s, needle) {
484
+ for (let at = s.source.indexOf(needle); at !== -1; at = s.source.indexOf(needle, at + 1)) {
485
+ if (s.masked[at] !== ' ') {
486
+ return true;
487
+ }
488
+ }
489
+ return false;
490
+ }
491
+ // ---------------------------------------------------------------------------
492
+ // settings.gradle
493
+ // ---------------------------------------------------------------------------
494
+ /**
495
+ * The plugin marker is on Maven Central, not the Plugin Portal. Declaring
496
+ * any repositories block replaces Gradle's implicit Plugin Portal, so a
497
+ * missing block gets the portal, Google, and Maven Central together.
498
+ */
499
+ function ensureMavenCentral(settingsGradle) {
500
+ return guarded(SETTINGS_GRADLE, () => mavenCentral(settingsGradle));
501
+ }
502
+ const REPOSITORIES = ['repositories {', ' gradlePluginPortal()', ' google()', ' mavenCentral()', '}'];
503
+ function mavenCentral(settingsGradle) {
504
+ const s = scan(settingsGradle, SETTINGS_GRADLE);
505
+ const eol = eolOf(settingsGradle);
506
+ const extent = blockExtent(s, 'pluginManagement');
507
+ if (!extent) {
508
+ return `pluginManagement {${eol}${REPOSITORIES.map((line) => ` ${line}`).join(eol)}${eol}}${eol}${settingsGradle}`;
509
+ }
510
+ if (blockExtentCall(s, 'mavenCentral', extent.bodyStart, extent.bodyEnd)) {
511
+ return settingsGradle;
512
+ }
513
+ const repositories = blockExtent(s, 'repositories', extent.bodyStart, extent.bodyEnd);
514
+ if (repositories) {
515
+ // Before the closing brace, which must stand alone on its line.
516
+ const opener = lineIndexAt(s, repositories.open);
517
+ const closer = lineIndexAt(s, repositories.bodyEnd);
518
+ if (!isOpenerLine(s.lines[opener], /^repositories\s*\{$/) || !isCloserLine(s.lines[closer])) {
519
+ const at = isCloserLine(s.lines[closer]) ? opener : closer;
520
+ throw anchorRefusal(SETTINGS_GRADLE, s.lines[at], at + 1, 'mavenCentral()', 'add mavenCentral() to pluginManagement.repositories yourself');
521
+ }
522
+ return insertLines(settingsGradle, closer, [`${innerIndent(s, opener, closer)}mavenCentral()`]);
523
+ }
524
+ const opener = lineIndexAt(s, extent.open);
525
+ const closer = lineIndexAt(s, extent.bodyEnd);
526
+ if (!isOpenerLine(s.lines[opener], /^pluginManagement\s*\{$/) || !isCloserLine(s.lines[closer])) {
527
+ const at = isCloserLine(s.lines[closer]) ? opener : closer;
528
+ throw anchorRefusal(SETTINGS_GRADLE, s.lines[at], at + 1, 'a repositories block with mavenCentral()', 'add repositories { mavenCentral() } to pluginManagement yourself');
529
+ }
530
+ const indent = innerIndent(s, opener, closer);
531
+ return insertLines(settingsGradle, closer, ['', ...REPOSITORIES.map((line) => `${indent}${line}`)]);
532
+ }
533
+ /** A `name(` call in code within [from, to). */
534
+ function blockExtentCall(s, name, from, to) {
535
+ return codeMatches(s, new RegExp(`(?<![A-Za-z0-9_])${name}\\s*\\(`, 'g'), from, to).length > 0;
536
+ }
537
+ // ---------------------------------------------------------------------------
538
+ // Root build.gradle
539
+ // ---------------------------------------------------------------------------
540
+ const DECLARED_VERSION = /(id\s*\(?\s*['"]com\.bugsee\.android\.gradle['"]\s*\)?\s+version\s*\(?\s*['"])([^'"]*)(['"])/g;
541
+ /**
542
+ * Declares the plugin `apply false` on the root project. A declaration from
543
+ * an earlier prebuild gets this version written over its own, so a
544
+ * `--no-clean` prebuild after a wrapper bump does not keep the old pin.
545
+ */
546
+ function ensureGradlePluginDeclared(projectBuildGradle, version) {
547
+ if (!/^[0-9A-Za-z.+_-]+$/.test(version)) {
548
+ throw refusal(ROOT_GRADLE, `the gradlePluginVersion option "${version}" is not a plain version string`, 'Fix the option in the Expo config (the @bugsee/react-native plugin entry), then run expo prebuild again');
549
+ }
550
+ return guarded(ROOT_GRADLE, () => gradlePluginDeclared(projectBuildGradle, version));
551
+ }
552
+ function gradlePluginDeclared(projectBuildGradle, version) {
553
+ const s = scan(projectBuildGradle, ROOT_GRADLE);
554
+ const eol = eolOf(projectBuildGradle);
555
+ const declared = codeMatches(s, DECLARED_VERSION)[0];
556
+ if (declared) {
557
+ const end = declared.index + declared[0].length;
558
+ return `${projectBuildGradle.slice(0, declared.index)}${declared[1]}${version}${declared[3]}${projectBuildGradle.slice(end)}`;
559
+ }
560
+ // Another declaration form (in a string, so not the pattern above): left alone.
561
+ if (occursLive(s, PLUGIN_ID)) {
562
+ return projectBuildGradle;
563
+ }
564
+ // apply false: the plugin has to be applied on the application module.
565
+ // Applied to the root project it fails configuration, because it hangs
566
+ // its tasks off an Android variant.
567
+ const pin = `id '${PLUGIN_ID}' version '${version}' apply false`;
568
+ // Gradle allows one plugins {} block per script, so an existing top-level
569
+ // one takes the pin, before its closing brace; both braces must stand alone.
570
+ const re = /(?<![A-Za-z0-9_.])plugins\s*\{/g;
571
+ for (let m = re.exec(s.masked); m !== null; m = re.exec(s.masked)) {
572
+ const open = m.index + m[0].length - 1;
573
+ if (depthAt(s, open) !== 0) {
574
+ continue;
575
+ }
576
+ const opener = lineIndexAt(s, open);
577
+ const closer = lineIndexAt(s, matchingBrace(s.masked, open));
578
+ if (!isOpenerLine(s.lines[opener], /^plugins\s*\{$/) || !isCloserLine(s.lines[closer])) {
579
+ const at = isCloserLine(s.lines[closer]) ? opener : closer;
580
+ throw anchorRefusal(ROOT_GRADLE, s.lines[at], at + 1, 'the Bugsee Gradle plugin declaration', `add \`${pin}\` to that plugins block yourself`);
581
+ }
582
+ return insertLines(projectBuildGradle, closer, [`${innerIndent(s, opener, closer)}${pin}`]);
583
+ }
584
+ const declaration = ['plugins {', ` ${pin}`, '}'];
585
+ // plugins {} has to stay with the buildscript block. A later allprojects
586
+ // or apply statement makes Gradle reject the block.
587
+ const buildscript = blockExtent(s, 'buildscript', 0, s.masked.length, true);
588
+ if (buildscript) {
589
+ // After the closing brace's line, which must hold nothing else.
590
+ const closer = lineIndexAt(s, buildscript.bodyEnd);
591
+ const line = s.lines[closer];
592
+ if (!isCloserLine(line) || line.openAtEnd) {
593
+ throw anchorRefusal(ROOT_GRADLE, line, closer + 1, 'the plugins block that declares the Bugsee Gradle plugin', `declare \`id '${PLUGIN_ID}' version '${version}' apply false\` in a plugins block yourself`);
594
+ }
595
+ const indent = indentOf(line.raw);
596
+ return insertLines(projectBuildGradle, closer + 1, [...declaration.map((entry) => `${indent}${entry}`), '']);
597
+ }
598
+ return `${declaration.join(eol)}${eol}${eol}${projectBuildGradle}`;
599
+ }
600
+ // ---------------------------------------------------------------------------
601
+ // App build.gradle
602
+ // ---------------------------------------------------------------------------
603
+ const NDK_EXCLUDE = "exclude group: 'com.bugsee', module: 'bugsee-android-ndk'";
604
+ /**
605
+ * `ndkVersion` is the baked `android.sdk`, or null when native crash
606
+ * reporting is explicitly off. Null strips a direct
607
+ * `implementation "com.bugsee:bugsee-android-ndk"` line from an earlier
608
+ * prebuild and excludes the wrapper's transitive `api` artifact. A
609
+ * configuration exclude does not drop a direct dependency. A later run
610
+ * with the option omitted or on removes that exclude and adds the
611
+ * implementation line. The wrapper `api` itself is left in place.
612
+ *
613
+ * `ndk.debugSymbolLevel` is never written: Bugsee Gradle plugin 4.0.8 and
614
+ * later upload native symbols from the unstripped libraries in
615
+ * `merged_native_libs`, whatever the level, which only decides what AGP packs
616
+ * for Google Play (the app's own choice). The `debugSymbolLevel
617
+ * 'SYMBOL_TABLE'` block earlier versions wrote is removed, recognised by its
618
+ * marker and exact lines only; a level of the user's is left alone. The
619
+ * Hermes preserve command and the finish hook are the JS source-map path,
620
+ * so they are written either way. The hook
621
+ * applies the package's scripts/bugsee-sourcemaps.gradle, which injects the
622
+ * debug id and uploads the composed map unless `bugseeUploadSourcemaps=false`
623
+ * or no real token is configured.
624
+ */
625
+ function ensureAppAppliesPlugin(appBuildGradle, ndkVersion, log = console.warn) {
626
+ if (ndkVersion !== null && !/^[0-9A-Za-z.+_-]+$/.test(ndkVersion)) {
627
+ throw refusal(APP_GRADLE, `the NDK artifact version "${ndkVersion}" (native-versions.json android.sdk) is not a plain version string`, 'Fix the baked version, then run expo prebuild again');
628
+ }
629
+ return guarded(APP_GRADLE, () => {
630
+ // The steps that can refuse run first, on the file as the user wrote it,
631
+ // so their line numbers are the user's; the plugin apply line goes in last.
632
+ let next = appBuildGradle;
633
+ if (ndkVersion === null) {
634
+ next = ensureNdkExcluded(dropNdkImplementation(next, log));
635
+ }
636
+ else {
637
+ next = dropNdkExclude(next);
638
+ next = ensureNdkImplementation(next, ndkVersion, log);
639
+ }
640
+ next = removeInsertedSymbolTable(next, log);
641
+ return ensurePluginApplied(ensureHermesHooks(next));
642
+ });
643
+ }
644
+ const REACT_PLUGIN_LINE = /^\s*apply\s+plugin:\s*(["'])com\.facebook\.react\1\s*$/;
645
+ function ensurePluginApplied(source) {
646
+ const s = scan(source, APP_GRADLE);
647
+ if (occursLive(s, PLUGIN_ID)) {
648
+ return source;
649
+ }
650
+ const eol = eolOf(source);
651
+ const statement = `apply plugin: "${PLUGIN_ID}"${crOf(eol)}`;
652
+ const lines = source.split('\n');
653
+ const react = s.lines.findIndex((line) => !line.openAtStart && line.depth === 0 && REACT_PLUGIN_LINE.test(codeOf(line)));
654
+ if (react >= 0) {
655
+ const reactLine = s.lines[react];
656
+ if (reactLine.openAtEnd) {
657
+ throw anchorRefusal(APP_GRADLE, reactLine, react + 1, `\`apply plugin: "${PLUGIN_ID}"\``, `add \`apply plugin: "${PLUGIN_ID}"\` yourself`);
658
+ }
659
+ const raw = reactLine.raw;
660
+ const indent = raw.slice(0, raw.length - raw.trimStart().length);
661
+ lines.splice(react + 1, 0, `${indent}${statement}`);
662
+ }
663
+ else {
664
+ lines.unshift(statement);
665
+ }
666
+ return lines.join('\n');
667
+ }
668
+ /** Bugsee's NDK dependency carries this marker; without it, an NDK line is the user's. */
669
+ const NDK_MARKER = '// bugsee:ndk';
670
+ const NDK_ARTIFACT = 'com.bugsee:bugsee-android-ndk';
671
+ const NDK_OWN_CODE = /^(\s*implementation\s+"com\.bugsee:bugsee-android-ndk:)([^"]*)("\s*)$/;
672
+ /** The opener of the dependencies block the plugin appends when the file has none. */
673
+ const NDK_OPENER = `dependencies { ${NDK_MARKER}`;
674
+ const DEPENDENCIES_OPENER = /^dependencies\s*\{$/;
675
+ /** Bugsee's own NDK line: its exact statement with its marker as the trailing comment. */
676
+ function isOwnNdkLine(line) {
677
+ return (!line.openAtStart &&
678
+ line.commentAt !== null &&
679
+ stripCr(line.raw.slice(line.commentAt)).trim() === NDK_MARKER &&
680
+ NDK_OWN_CODE.test(codeOf(line)));
681
+ }
682
+ /** The user declares the NDK artifact themselves, in code or a string, on a line that is not Bugsee's. */
683
+ function userDeclaresNdk(s) {
684
+ return s.lines.some((line) => !isOwnNdkLine(line) && lineMentionsLive(s, line, NDK_ARTIFACT));
685
+ }
686
+ function lineMentionsLive(s, line, needle) {
687
+ for (let at = line.raw.indexOf(needle); at !== -1; at = line.raw.indexOf(needle, at + 1)) {
688
+ if (s.masked[line.start + at] !== ' ') {
689
+ return true;
690
+ }
691
+ }
692
+ return false;
693
+ }
694
+ const USER_NDK_NOTE = '@bugsee/react-native: android/app/build.gradle declares com.bugsee:bugsee-android-ndk itself; the plugin leaves that line alone and does not add or remove its own';
695
+ function ensureNdkImplementation(source, ndkVersion, log) {
696
+ const s = scan(source, APP_GRADLE);
697
+ const own = s.lines.findIndex(isOwnNdkLine);
698
+ if (own !== -1) {
699
+ const lines = source.split('\n');
700
+ const line = s.lines[own];
701
+ const code = codeOf(line);
702
+ lines[own] = `${code.replace(NDK_OWN_CODE, `$1${ndkVersion}$3`)}${line.raw.slice(code.length)}`;
703
+ return lines.join('\n');
704
+ }
705
+ if (userDeclaresNdk(s)) {
706
+ log(USER_NDK_NOTE);
707
+ return source;
708
+ }
709
+ const dep = `implementation "${NDK_ARTIFACT}:${ndkVersion}" ${NDK_MARKER}`;
710
+ // The first top-level dependencies block, wherever its opener sits on its
711
+ // line (the mask hides strings and comments); that line must hold nothing else.
712
+ const re = /(?<![A-Za-z0-9_.])dependencies\s*\{/g;
713
+ let opener = -1;
714
+ for (let m = re.exec(s.masked); m !== null && opener === -1; m = re.exec(s.masked)) {
715
+ const open = m.index + m[0].length - 1;
716
+ if (depthAt(s, open) === 0) {
717
+ opener = lineIndexAt(s, open);
718
+ }
719
+ }
720
+ if (opener === -1) {
721
+ return appendBlock(source, `${NDK_OPENER}\n ${dep}\n}`, eolOf(source));
722
+ }
723
+ const line = s.lines[opener];
724
+ if (!isOpenerLine(line, DEPENDENCIES_OPENER) || line.openAtEnd) {
725
+ throw anchorRefusal(APP_GRADLE, line, opener + 1, 'the Bugsee NDK dependency', `declare \`implementation "${NDK_ARTIFACT}:${ndkVersion}"\` yourself`);
726
+ }
727
+ const closer = s.lines.findIndex((entry, i) => i > opener && entry.depthAfter === line.depth);
728
+ return insertLines(source, opener + 1, [`${innerIndent(s, opener, closer)}${dep}`]);
729
+ }
730
+ /**
731
+ * Removes Bugsee's marked NDK line, and the dependencies block the plugin
732
+ * appended for it when nothing else is left inside. A user's own NDK line
733
+ * is left alone and noted.
734
+ */
735
+ function dropNdkImplementation(source, log) {
736
+ const s = scan(source, APP_GRADLE);
737
+ if (userDeclaresNdk(s)) {
738
+ log(USER_NDK_NOTE);
739
+ }
740
+ const lines = source.split('\n');
741
+ for (let i = s.lines.length - 1; i >= 0; i -= 1) {
742
+ const line = s.lines[i];
743
+ if (isOwnNdkLine(line)) {
744
+ lines.splice(i, 1);
745
+ }
746
+ }
747
+ const stripped = scan(lines.join('\n'), APP_GRADLE);
748
+ const opener = stripped.lines.findIndex((line) => !line.openAtStart && line.depth === 0 && stripCr(line.raw) === NDK_OPENER);
749
+ if (opener !== -1) {
750
+ // The block the plugin appended has no blank lines of its own: nothing left means the closer comes next.
751
+ const closer = stripped.lines.findIndex((entry, i) => i > opener && entry.depthAfter === 0);
752
+ if (closer === opener + 1 && isCloserLine(stripped.lines[closer])) {
753
+ const rest = lines;
754
+ removeBlock(rest, opener, closer);
755
+ return rest.join('\n');
756
+ }
757
+ }
758
+ return lines.join('\n');
759
+ }
760
+ const NDK_EXCLUDE_BLOCK = ['configurations.configureEach {', ` ${NDK_EXCLUDE}`, '}'];
761
+ function ensureNdkExcluded(source) {
762
+ const s = scan(source, APP_GRADLE);
763
+ if (findOwnBlock(s, NDK_EXCLUDE_BLOCK) !== -1) {
764
+ return source;
765
+ }
766
+ return appendBlock(source, NDK_EXCLUDE_BLOCK.join('\n'), eolOf(source));
767
+ }
768
+ function dropNdkExclude(source) {
769
+ const s = scan(source, APP_GRADLE);
770
+ const at = findOwnBlock(s, NDK_EXCLUDE_BLOCK);
771
+ if (at < 0) {
772
+ return source;
773
+ }
774
+ const lines = source.split('\n');
775
+ removeBlock(lines, at, at + NDK_EXCLUDE_BLOCK.length - 1);
776
+ return lines.join('\n');
777
+ }
778
+ /**
779
+ * The block earlier versions of this plugin wrote into the debug and release
780
+ * build types, kept verbatim so it can be recognised and removed. Its text is
781
+ * a fingerprint, not documentation: `libreactnative.so` is not pre-stripped
782
+ * (the Maven AAR ships it with DWARF), and with Gradle plugin 4.0.8 the
783
+ * native upload no longer depends on the level at all.
784
+ */
785
+ const SYMBOL_TABLE_BLOCK = [
786
+ "// bugsee-symbol-table: AGP defaults this to NONE, so the plugin's native upload finds",
787
+ '// nothing and skips. SYMBOL_TABLE emits symbols for code this app',
788
+ '// builds. Maven Hermes and libreactnative.so are pre-stripped;',
789
+ '// this level does not symbolicate those two.',
790
+ 'ndk {',
791
+ " debugSymbolLevel 'SYMBOL_TABLE'",
792
+ '}',
793
+ ];
794
+ /** How many of Bugsee's symbol-table block lines stand at `start`, in order, at the marker's indentation. */
795
+ function symbolBlockLinesAt(lines, start) {
796
+ const indent = indentOf(lines[start].raw);
797
+ let count = 0;
798
+ while (count < SYMBOL_TABLE_BLOCK.length) {
799
+ const line = lines[start + count];
800
+ // The first line is a marker in code, and no block line opens a string, so none of them starts inside one.
801
+ if (line === undefined || stripCr(line.raw) !== `${indent}${SYMBOL_TABLE_BLOCK[count]}`) {
802
+ break;
803
+ }
804
+ count += 1;
805
+ }
806
+ return count;
807
+ }
808
+ /** Index of the first line after `start` that is not a `//` comment line (may be lines.length). */
809
+ function afterLineComments(lines, start) {
810
+ let j = start + 1;
811
+ while (j < lines.length && isLineComment(lines[j])) {
812
+ j += 1;
813
+ }
814
+ return j;
815
+ }
816
+ exports.CHANGED_SYMBOL_BLOCK_NOTE = '@bugsee/react-native: android/app/build.gradle has the symbol-table block an earlier version of the plugin wrote, changed inside; it is left as you have it. Bugsee no longer needs ndk.debugSymbolLevel, so you can remove the block, or keep it for Google Play';
817
+ /**
818
+ * Removes exactly the symbol-table block earlier versions wrote, at whatever
819
+ * indentation it stands, and nothing after it. A block whose comment lines
820
+ * are intact but whose body was changed (a user added or edited a line
821
+ * inside) is the user's now: it is left alone and noted. A stray marker loses
822
+ * only its own matching comment lines.
823
+ */
824
+ function removeInsertedSymbolTable(source, log) {
825
+ const s = scan(source, APP_GRADLE);
826
+ const kept = [];
827
+ for (let i = 0; i < s.lines.length; i += 1) {
828
+ const line = s.lines[i];
829
+ const matched = isMarker(line, SYMBOL_TABLE_BLOCK[0]) ? symbolBlockLinesAt(s.lines, i) : 0;
830
+ if (matched === 0) {
831
+ kept.push(line.raw);
832
+ continue;
833
+ }
834
+ if (matched < SYMBOL_TABLE_BLOCK.length && matched >= 4) {
835
+ log(exports.CHANGED_SYMBOL_BLOCK_NOTE);
836
+ kept.push(line.raw);
837
+ continue;
838
+ }
839
+ i += matched - 1;
840
+ }
841
+ return kept.join('\n');
842
+ }
843
+ const BUGSEE_PACKAGE_DIR_EXPR = 'new File(["node", "--print", "require.resolve(\'@bugsee/react-native/package.json\')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath()';
844
+ /**
845
+ * The launcher for the host the build runs on: React Native runs
846
+ * hermesCommand through `cmd /c` on Windows, which cannot run a shell
847
+ * script. Chosen when Gradle configures, so one build.gradle serves a repo
848
+ * shared across macOS, Linux and Windows.
849
+ */
850
+ exports.HERMES_COMMAND_EXPR = `${BUGSEE_PACKAGE_DIR_EXPR} + "/scripts/hermesc-preserve-js" + (System.getProperty("os.name").startsWith("Windows") ? ".cmd" : ".sh")`;
851
+ /**
852
+ * The value earlier versions wrote: the shell launcher on every host, which
853
+ * a Windows build cannot run. Recognised only as this exact text, and moved
854
+ * to HERMES_COMMAND_EXPR.
855
+ */
856
+ exports.LEGACY_HERMES_COMMAND_EXPR = `${BUGSEE_PACKAGE_DIR_EXPR} + "/scripts/hermesc-preserve-js.sh"`;
857
+ const SOURCEMAPS_SCRIPT = 'scripts/bugsee-sourcemaps.gradle';
858
+ /** First line of the hook this plugin writes. */
859
+ const SOURCEMAPS_HOOK_MARKER = '// bugsee-sourcemaps: debug ids and source-map upload for release bundles (@bugsee/react-native).';
860
+ /**
861
+ * The hook is the package's own Gradle script, so the bare example and Expo
862
+ * apps run the same code: inject after compose, upload, fail the bundle
863
+ * task when Hermes skipped the preserve wrapper.
864
+ */
865
+ const SOURCEMAPS_APPLY = `apply from: new File(new File(["node", "--print", "require.resolve('@bugsee/react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile(), "${SOURCEMAPS_SCRIPT}")`;
866
+ /** First line of the inline hook earlier versions wrote. */
867
+ const LEGACY_HOOK_MARKER = '// After compose-source-maps.js. Release variants only; debug does not bundle.';
868
+ /** The line both earlier inline hooks have after their comments; user code does not. */
869
+ const LEGACY_HOOK_FINGERPRINT = 'def bugseeHermesSourcemaps = ';
870
+ exports.HERMES_COMMAND_UNREWRITABLE = `${exports.CANNOT_EDIT} ${APP_GRADLE}: react.hermesCommand spans several lines or shares its line with another statement, so it cannot be pointed at scripts/hermesc-preserve-js.sh (.cmd on Windows). Put it alone on one line, or delete it, and prebuild again`;
871
+ /** Brackets all close, something is there, and it does not end in an operator. */
872
+ function completeExpression(code) {
873
+ let depth = 0;
874
+ for (const ch of code) {
875
+ if ('([{'.includes(ch)) {
876
+ depth += 1;
877
+ }
878
+ else if (')]}'.includes(ch)) {
879
+ depth -= 1;
880
+ }
881
+ }
882
+ return depth === 0 && code.trim().length > 0 && !/[-+*/,([.?:&|=]$/.test(code.trimEnd());
883
+ }
884
+ /** The next code line starts by continuing the previous expression. */
885
+ const CONTINUATION = /^(\?\.|\.|\?|:|\+|-|\*|\/|&&|\|\|)/;
886
+ const HERMES_COMMAND = /^([ \t]*)hermesCommand(\s*=(?!=)|\.set\()/;
887
+ const REACT_BLOCK = /^\s*react\s*\{\s*$/;
888
+ /**
889
+ * Points react.hermesCommand at the preserve launcher for the host. Only the
890
+ * setting at the top level of the react block counts: one in a comment, a
891
+ * string, another block or a nested block is left alone. A value that already
892
+ * names hermesc-preserve-js is kept (this plugin's, or the user's own), except
893
+ * the exact value earlier versions wrote, which is moved to the per-host one.
894
+ * Any other one-line `hermesCommand = …` or `hermesCommand.set(…)` is
895
+ * rewritten, a trailing comment kept. Anything this cannot read with
896
+ * certainty (a value that
897
+ * continues on the next line, an open bracket or multi-line string, nothing
898
+ * after `=`, another statement after `;`) is refused. A react block without
899
+ * the setting gets one. With no react block the file is left alone, and the
900
+ * bundle task fails with the fix instead.
901
+ */
902
+ function rewriteHermesCommand(source) {
903
+ const s = scan(source, APP_GRADLE);
904
+ const lines = source.split('\n');
905
+ const eol = eolOf(source);
906
+ const react = s.lines.findIndex((line) => !line.openAtStart && line.depth === 0 && REACT_BLOCK.test(line.code));
907
+ if (react === -1) {
908
+ return source;
909
+ }
910
+ // The block's lines, up to its closing brace (braces balance, so it exists).
911
+ const end = s.lines.findIndex((line, i) => i > react && line.depthAfter === 0);
912
+ let found = false;
913
+ for (let i = react + 1; i < end; i += 1) {
914
+ const line = s.lines[i];
915
+ const match = line.openAtStart || line.depth !== 1 ? null : HERMES_COMMAND.exec(line.code);
916
+ if (!match) {
917
+ continue;
918
+ }
919
+ found = true;
920
+ // The value as written, up to a trailing comment.
921
+ const valueEnd = line.raw.slice(0, line.commentAt ?? line.raw.length).trimEnd().length;
922
+ const written = line.raw.slice(match[0].length, valueEnd).trim();
923
+ // A setter call never equals it: its value carries the closing bracket.
924
+ if (written === exports.LEGACY_HERMES_COMMAND_EXPR) {
925
+ lines[i] = `${match[1]}hermesCommand = ${exports.HERMES_COMMAND_EXPR}${line.raw.slice(valueEnd)}`;
926
+ continue;
927
+ }
928
+ if (line.raw.includes('hermesc-preserve-js')) {
929
+ continue;
930
+ }
931
+ // Comments are spaces in the mask, so the whole masked line is the value.
932
+ const value = `${match[2] === '.set(' ? '(' : ''}${line.code.slice(match[0].length)}`;
933
+ // The closing brace follows at the latest, so a next code line exists.
934
+ const next = s.lines.slice(i + 1).find((later) => later.code.trim().length > 0);
935
+ if (line.openAtEnd || value.includes(';') || !completeExpression(value) || CONTINUATION.test(next.code.trim())) {
936
+ throw new Error(exports.HERMES_COMMAND_UNREWRITABLE);
937
+ }
938
+ // The value is replaced; what follows it (whitespace, a comment, the CR) is kept.
939
+ lines[i] = `${match[1]}hermesCommand = ${exports.HERMES_COMMAND_EXPR}${line.raw.slice(valueEnd)}`;
940
+ }
941
+ if (!found) {
942
+ const reactLine = s.lines[react];
943
+ if (reactLine.openAtEnd) {
944
+ throw anchorRefusal(APP_GRADLE, reactLine, react + 1, 'react.hermesCommand', 'set react.hermesCommand yourself');
945
+ }
946
+ const opener = reactLine.raw;
947
+ const indent = opener.slice(0, opener.length - opener.trimStart().length);
948
+ lines.splice(react + 1, 0, `${indent} hermesCommand = ${exports.HERMES_COMMAND_EXPR}${crOf(eol)}`);
949
+ }
950
+ return lines.join('\n');
951
+ }
952
+ /**
953
+ * Index of the last line of an inline hook an earlier version wrote, which
954
+ * starts at `start` with its marker: comment lines, the
955
+ * `def bugseeHermesSourcemaps = ` line both old versions have, more
956
+ * `def bugsee…` lines, then `afterEvaluate {` through the brace that
957
+ * matches it, alone at column 0. Null when the lines after the marker are
958
+ * anything else, so a stray marker never takes user code with it.
959
+ */
960
+ function legacyHookEnd(lines, start) {
961
+ let j = afterLineComments(lines, start);
962
+ // A line after a line comment is never inside a string.
963
+ const fingerprint = lines[j];
964
+ if (fingerprint === undefined || !fingerprint.raw.startsWith(LEGACY_HOOK_FINGERPRINT)) {
965
+ return null;
966
+ }
967
+ while (j < lines.length && lines[j].raw.startsWith('def bugsee')) {
968
+ j += 1;
969
+ }
970
+ // An `afterEvaluate {` inside a string left open by a def line never counts:
971
+ // its brace is not code, so the depth after it is unchanged and the line
972
+ // itself would have to be the closing `}`.
973
+ const open = lines[j];
974
+ if (open === undefined || stripCr(open.raw) !== 'afterEvaluate {') {
975
+ return null;
976
+ }
977
+ // Braces balance, so some line from j on returns to the opener's depth.
978
+ const close = lines.findIndex((line, k) => k >= j && line.depthAfter === open.depth);
979
+ return stripCr(lines[close].raw) === '}' ? close : null;
980
+ }
981
+ /**
982
+ * Leaves exactly one hook: the marker and, on the very next line, the
983
+ * apply line. A complete hook (this version's or an earlier inline one)
984
+ * keeps its place; every other Bugsee leftover — a marker without its
985
+ * apply line, an apply line without its marker, a second hook — goes, one
986
+ * line at a time, and nothing else is touched. Only Bugsee's exact lines
987
+ * count: a user's fork of the script, an apply inside a block, or a line
988
+ * with more after it is user code. With no complete hook the new one is
989
+ * appended.
990
+ */
991
+ function ensureHermesHooks(source) {
992
+ const rewritten = rewriteHermesCommand(source);
993
+ const s = scan(rewritten, APP_GRADLE);
994
+ const eol = eolOf(rewritten);
995
+ const cr = crOf(eol);
996
+ const kept = [];
997
+ let hookAt = -1;
998
+ for (let i = 0; i < s.lines.length; i += 1) {
999
+ const line = s.lines[i];
1000
+ let end = null;
1001
+ if (isMarker(line, SOURCEMAPS_HOOK_MARKER)) {
1002
+ end = isOwnStatement(s.lines[i + 1], SOURCEMAPS_APPLY) ? i + 1 : null;
1003
+ }
1004
+ else if (isMarker(line, LEGACY_HOOK_MARKER)) {
1005
+ end = legacyHookEnd(s.lines, i);
1006
+ }
1007
+ else if (!isOwnStatement(line, SOURCEMAPS_APPLY)) {
1008
+ kept.push(line.raw);
1009
+ continue;
1010
+ }
1011
+ if (end !== null) {
1012
+ hookAt = hookAt < 0 ? kept.length : hookAt;
1013
+ i = end;
1014
+ }
1015
+ }
1016
+ if (hookAt >= 0) {
1017
+ kept.splice(hookAt, 0, `${SOURCEMAPS_HOOK_MARKER}${cr}`, `${SOURCEMAPS_APPLY}${cr}`);
1018
+ return kept.join('\n');
1019
+ }
1020
+ return appendBlock(kept.join('\n'), `${SOURCEMAPS_HOOK_MARKER}\n${SOURCEMAPS_APPLY}`, eol);
1021
+ }
1022
+ const UPLOADS_OFF_MARKER = '// bugsee-upload-symbols-off:';
1023
+ const UPLOADS_OFF_BLOCK = [
1024
+ `${UPLOADS_OFF_MARKER} uploadSymbols is false in the Expo config. The Bugsee`,
1025
+ '// Gradle plugin 4.0.7 has no switch for its mapping, NDK symbol and build',
1026
+ '// uploads, so their tasks are turned off here.',
1027
+ "tasks.matching { it.name.startsWith('uploadBugsee') }.configureEach { enabled = false }",
1028
+ ];
1029
+ /**
1030
+ * `uploadSymbols: false` on Android: disables every `uploadBugsee*` task
1031
+ * (mapping, NDK symbols, build info) inside a marked block. On again
1032
+ * removes exactly that block.
1033
+ */
1034
+ function ensureSymbolUploads(appBuildGradle, enabled) {
1035
+ return guarded(APP_GRADLE, () => symbolUploads(appBuildGradle, enabled));
1036
+ }
1037
+ function symbolUploads(appBuildGradle, enabled) {
1038
+ const s = scan(appBuildGradle, APP_GRADLE);
1039
+ const at = findOwnBlock(s, UPLOADS_OFF_BLOCK);
1040
+ if (enabled) {
1041
+ if (at < 0) {
1042
+ return appBuildGradle;
1043
+ }
1044
+ const lines = appBuildGradle.split('\n');
1045
+ removeBlock(lines, at, at + UPLOADS_OFF_BLOCK.length - 1);
1046
+ return lines.join('\n');
1047
+ }
1048
+ if (at >= 0) {
1049
+ return appBuildGradle;
1050
+ }
1051
+ return appendBlock(appBuildGradle, UPLOADS_OFF_BLOCK.join('\n'), eolOf(appBuildGradle));
1052
+ }
1053
+ const UPLOAD_SOURCEMAPS_KEY = 'bugseeUploadSourcemaps';
1054
+ /**
1055
+ * `uploadSourcemaps: false` writes `bugseeUploadSourcemaps=false` into
1056
+ * android/gradle.properties, which the finish hook reads. On (the default)
1057
+ * removes that key.
1058
+ */
1059
+ function applyUploadSourcemapsProperty(properties, enabled) {
1060
+ const kept = properties.filter((item) => !(item.type === 'property' && item.key === UPLOAD_SOURCEMAPS_KEY));
1061
+ if (enabled) {
1062
+ return kept;
1063
+ }
1064
+ return [...kept, { type: 'property', key: UPLOAD_SOURCEMAPS_KEY, value: 'false' }];
1065
+ }
1066
+ //# sourceMappingURL=gradle.js.map