@dynatrace/react-native-plugin 2.339.1 → 2.343.1

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 (62) hide show
  1. package/README.md +149 -23
  2. package/android/build.gradle +11 -2
  3. package/android/src/main/java/com/dynatrace/android/agent/DynatraceAppStartModule.kt +9 -31
  4. package/android/src/main/java/com/dynatrace/android/agent/DynatraceConfigurationModule.kt +1 -0
  5. package/android/src/main/java/com/dynatrace/android/agent/DynatraceRNBridgeImpl.kt +41 -1
  6. package/android/src/main/java/com/dynatrace/android/agent/DynatraceUtils.kt +1 -0
  7. package/android/src/main/java/com/dynatrace/android/agent/ScreenshotSelfMonitor.kt +175 -0
  8. package/android/src/main/java/com/dynatrace/android/agent/UIChangeScreenshotListener.kt +124 -0
  9. package/android/src/new/java/com/dynatrace/android/agent/DynatraceRNBridge.kt +33 -0
  10. package/android/src/old/java/com/dynatrace/android/agent/DynatraceRNBridge.kt +40 -0
  11. package/files/plugin.gradle +1 -1
  12. package/instrumentation/BabelPluginDynatrace.js +1 -1
  13. package/instrumentation/DynatraceInstrumentation.js +1 -1
  14. package/instrumentation/jsx/CreateElement.js +5 -9
  15. package/instrumentation/jsx/ElementHelper.js +5 -6
  16. package/instrumentation/jsx/JsxDevRuntime.js +33 -31
  17. package/instrumentation/jsx/JsxRuntime.js +30 -30
  18. package/instrumentation/jsx/JsxRuntimeHelpers.js +14 -0
  19. package/instrumentation/jsx/components/ClassComponent.js +4 -8
  20. package/instrumentation/jsx/components/ComponentUtil.js +24 -25
  21. package/instrumentation/libs/UserInteraction.js +27 -24
  22. package/instrumentation/libs/react-native/RefreshControl.js +5 -9
  23. package/instrumentation/libs/withOnPressMonitoring.js +66 -57
  24. package/ios/DTXScreenshotSelfMonitor.h +29 -0
  25. package/ios/DTXScreenshotSelfMonitor.mm +213 -0
  26. package/ios/DTXScreenshotSelfMonitorSwizzler.h +15 -0
  27. package/ios/DTXScreenshotSelfMonitorSwizzler.mm +68 -0
  28. package/ios/DynatraceRNBridge.h +6 -0
  29. package/ios/DynatraceRNBridge.mm +53 -0
  30. package/lib/core/Dynatrace.js +2 -0
  31. package/lib/core/DynatraceAction.js +1 -3
  32. package/lib/core/DynatraceInternal.js +38 -40
  33. package/lib/core/ErrorHandler.js +41 -21
  34. package/lib/core/NullAction.js +1 -3
  35. package/lib/core/logging/LogMessages.js +42 -0
  36. package/lib/core/util/JsonUtils.js +6 -0
  37. package/lib/features/ui-interaction/IUserInteractionEvent.js +1 -1
  38. package/lib/features/ui-interaction/Runtime.js +1 -1
  39. package/lib/features/ui-interaction/TouchMetaResolver.js +4 -3
  40. package/lib/next/Dynatrace.js +26 -1
  41. package/lib/next/events/EventPipeline.js +48 -31
  42. package/lib/next/events/HttpRequestEventData.js +3 -3
  43. package/lib/next/events/interface/HttpRequestEventDataTypes.js +2 -0
  44. package/lib/next/events/modifier/ModifyEventValidation.js +79 -51
  45. package/lib/next/events/spec/EventSpecContstants.js +1 -1
  46. package/lib/next/userAction/NullUserAction.js +15 -0
  47. package/lib/next/userAction/UserAction.js +2 -0
  48. package/lib/next/userAction/UserActionConfiguration.js +10 -0
  49. package/lib/next/userAction/UserActionImpl.js +70 -0
  50. package/lib/next/util/TraceContextUtils.js +8 -14
  51. package/lib/next/util/Utils.js +13 -0
  52. package/package.json +11 -6
  53. package/public.js +3 -1
  54. package/react-native-dynatrace.podspec +10 -3
  55. package/scripts/Config.js +22 -4
  56. package/scripts/DebugFlag.js +20 -0
  57. package/scripts/FileOperationHelper.js +15 -39
  58. package/scripts/Logger.js +2 -3
  59. package/scripts/core/InstrumentCall.js +110 -81
  60. package/scripts/util/CustomArgumentUtil.js +8 -6
  61. package/src/lib/core/interface/NativeDynatraceBridge.ts +34 -1
  62. package/types.d.ts +187 -9
@@ -0,0 +1,124 @@
1
+ package com.dynatrace.android.agent
2
+
3
+ import android.app.Activity
4
+ import android.os.Handler
5
+ import android.os.Looper
6
+ import android.os.SystemClock
7
+ import android.util.Log
8
+ import android.view.ViewTreeObserver
9
+ import java.lang.ref.WeakReference
10
+ import java.util.concurrent.atomic.AtomicBoolean
11
+
12
+ private const val TAG = "dtxScreenshotSelfMonitor"
13
+ private const val DEBOUNCE_MS = 500L
14
+ private const val MAX_DEBOUNCE_MS = 2000L
15
+
16
+ /**
17
+ * Self-monitoring listener that mirrors the Session Replay UI-change detection, but instead of
18
+ * capturing a screenshot it only increments the cross-platform screenshot counter via
19
+ * [HybridBridge.trackCrossPlatformScreenshot].
20
+ *
21
+ * The purpose is to estimate how many screenshots the Session Replay UI-change listener *would*
22
+ * take in production, without shipping the (not yet published) Session Replay package.
23
+ *
24
+ * It observes [ViewTreeObserver.OnDrawListener] on the current activity's decor view and debounces
25
+ * bursts of draws (a settled UI is reported once). Both [lastDrawTime] and [firstDrawTime] are only
26
+ * touched on the main thread (`onDraw` and the Handler-posted [captureRunnable]).
27
+ */
28
+ internal class UIChangeScreenshotListener : ViewTreeObserver.OnDrawListener {
29
+
30
+ private val pending = AtomicBoolean(false)
31
+ private val handler = Handler(Looper.getMainLooper())
32
+ private var registeredActivity: WeakReference<Activity>? = null
33
+
34
+ private var lastDrawTime = 0L
35
+ private var firstDrawTime = 0L
36
+
37
+ private val captureRunnable = Runnable { performCapture() }
38
+
39
+ override fun onDraw() {
40
+ val now = SystemClock.uptimeMillis()
41
+ lastDrawTime = now
42
+ if (pending.compareAndSet(false, true)) {
43
+ firstDrawTime = now
44
+ handler.postDelayed(captureRunnable, DEBOUNCE_MS)
45
+ }
46
+ }
47
+
48
+ fun registerOn(activity: Activity): Boolean {
49
+ if (registeredActivity?.get() === activity) return true
50
+
51
+ // Clean up previous registration if switching activities
52
+ unregister()
53
+
54
+ val decorView = activity.window?.decorView
55
+ if (decorView == null) {
56
+ Log.w(TAG, "Cannot register: decorView is null")
57
+ return false
58
+ }
59
+ val observer = decorView.viewTreeObserver
60
+ if (!observer.isAlive) {
61
+ Log.w(TAG, "Cannot register: ViewTreeObserver is not alive")
62
+ return false
63
+ }
64
+
65
+ observer.addOnDrawListener(this)
66
+ registeredActivity = WeakReference(activity)
67
+ Log.d(TAG, "Registered OnDrawListener on DecorView")
68
+ return true
69
+ }
70
+
71
+ fun unregister() {
72
+ val activity = registeredActivity?.get()
73
+ if (activity != null) {
74
+ try {
75
+ val decorView = activity.window?.decorView
76
+ val observer = decorView?.viewTreeObserver
77
+ if (observer != null && observer.isAlive) {
78
+ observer.removeOnDrawListener(this)
79
+ }
80
+ } catch (e: IllegalStateException) {
81
+ Log.w(TAG, "Expected cleanup issue removing OnDrawListener", e)
82
+ } catch (e: Exception) {
83
+ Log.e(TAG, "Unexpected error removing OnDrawListener", e)
84
+ }
85
+ }
86
+ registeredActivity = null
87
+ dispose()
88
+ }
89
+
90
+ private fun performCapture() {
91
+ if (registeredActivity?.get() == null) {
92
+ // Leave pending=true so onDraw won't schedule further captures
93
+ Log.w(TAG, "Activity reference lost (GC'd) — capture abandoned")
94
+ handler.removeCallbacks(captureRunnable)
95
+ return
96
+ }
97
+
98
+ val now = SystemClock.uptimeMillis()
99
+ val elapsed = now - lastDrawTime
100
+ val sinceFirst = now - firstDrawTime
101
+
102
+ // Reschedule if UI still active, unless max wait exceeded
103
+ if (elapsed < DEBOUNCE_MS && sinceFirst < MAX_DEBOUNCE_MS) {
104
+ val remaining = DEBOUNCE_MS - elapsed
105
+ Log.d(TAG, "UI still active, rescheduling in ${remaining}ms")
106
+ handler.postDelayed(captureRunnable, remaining)
107
+ return
108
+ }
109
+
110
+ pending.set(false)
111
+
112
+ try {
113
+ Log.d(TAG, "Tracking cross-platform screenshot (self-monitoring)")
114
+ HybridBridge.trackCrossPlatformScreenshot()
115
+ } catch (e: Exception) {
116
+ Log.e(TAG, "trackCrossPlatformScreenshot failed during UI change capture", e)
117
+ }
118
+ }
119
+
120
+ fun dispose() {
121
+ handler.removeCallbacks(captureRunnable)
122
+ pending.set(false)
123
+ }
124
+ }
@@ -179,6 +179,39 @@ class DynatraceRNBridge(
179
179
  impl.forwardAppStartEvent(attributes, appStartKeys)
180
180
  }
181
181
 
182
+ override fun setAutomaticUserActionDetection(enabled: Boolean) {
183
+ impl.setAutomaticUserActionDetection(enabled)
184
+ }
185
+
186
+ override fun createUserAction(
187
+ actionId: String,
188
+ name: String,
189
+ completeAutomatically: Boolean,
190
+ properties: ReadableMap?
191
+ ) {
192
+ impl.createUserAction(actionId, name, completeAutomatically, properties)
193
+ }
194
+
195
+ override fun addEventStringPropertyToUserAction(actionId: String, key: String, value: String) {
196
+ impl.addEventStringPropertyToUserAction(actionId, key, value)
197
+ }
198
+
199
+ override fun addEventDoublePropertyToUserAction(actionId: String, key: String, value: Double) {
200
+ impl.addEventDoublePropertyToUserAction(actionId, key, value)
201
+ }
202
+
203
+ override fun addEventBooleanPropertyToUserAction(actionId: String, key: String, value: Boolean) {
204
+ impl.addEventBooleanPropertyToUserAction(actionId, key, value)
205
+ }
206
+
207
+ override fun completeUserAction(actionId: String) {
208
+ impl.completeUserAction(actionId)
209
+ }
210
+
211
+ override fun setCompleteUserActionAutomatically(actionId: String, enabled: Boolean) {
212
+ impl.setCompleteUserActionAutomatically(actionId, enabled)
213
+ }
214
+
182
215
  override fun startView(name: String) {
183
216
  impl.startView(name)
184
217
  }
@@ -197,6 +197,46 @@ class DynatraceRNBridge(
197
197
  impl.forwardAppStartEvent(attributes, appStartKeys)
198
198
  }
199
199
 
200
+ @ReactMethod
201
+ fun setAutomaticUserActionDetection(enabled: Boolean) {
202
+ impl.setAutomaticUserActionDetection(enabled)
203
+ }
204
+
205
+ @ReactMethod
206
+ fun createUserAction(
207
+ actionId: String,
208
+ name: String,
209
+ completeAutomatically: Boolean,
210
+ properties: ReadableMap?
211
+ ) {
212
+ impl.createUserAction(actionId, name, completeAutomatically, properties)
213
+ }
214
+
215
+ @ReactMethod
216
+ fun addEventStringPropertyToUserAction(actionId: String, key: String, value: String) {
217
+ impl.addEventStringPropertyToUserAction(actionId, key, value)
218
+ }
219
+
220
+ @ReactMethod
221
+ fun addEventDoublePropertyToUserAction(actionId: String, key: String, value: Double) {
222
+ impl.addEventDoublePropertyToUserAction(actionId, key, value)
223
+ }
224
+
225
+ @ReactMethod
226
+ fun addEventBooleanPropertyToUserAction(actionId: String, key: String, value: Boolean) {
227
+ impl.addEventBooleanPropertyToUserAction(actionId, key, value)
228
+ }
229
+
230
+ @ReactMethod
231
+ fun completeUserAction(actionId: String) {
232
+ impl.completeUserAction(actionId)
233
+ }
234
+
235
+ @ReactMethod
236
+ fun setCompleteUserActionAutomatically(actionId: String, enabled: Boolean) {
237
+ impl.setCompleteUserActionAutomatically(actionId, enabled)
238
+ }
239
+
200
240
  @ReactMethod
201
241
  fun startView(name: String) {
202
242
  impl.startView(name)
@@ -1,4 +1,4 @@
1
1
  // TEMPLATE: plugin-gradle.template
2
2
  dependencies {
3
- classpath 'com.dynatrace.tools.android:gradle-plugin:8.339.1.1004'
3
+ classpath 'com.dynatrace.tools.android:gradle-plugin:8.343.1.1038'
4
4
  }
@@ -1 +1 @@
1
- var _templateObject,_templateObject2,_templateObject3,_templateObject4,_templateObject5,_templateObject6,_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_taggedTemplateLiteral2=_interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));function _createForOfIteratorHelper(e,t){var n,r,a,i,o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return a=!(r=!0),{s:function(){o=o.call(e)},n:function(){var e=o.next();return r=e.done,e},e:function(e){a=!0,n=e},f:function(){try{r||null==o.return||o.return()}finally{if(a)throw n}}};if(Array.isArray(e)||(o=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return o&&(e=o),i=0,{s:t=function(){},n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0});var reactOptions,fspath=require("path"),fs=require("fs"),core_1=require("@babel/core"),generator_1=require("@babel/generator"),PathsConstants_1=require("../scripts/PathsConstants"),Config_1=require("../scripts/Config"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),Types_1=require("./model/Types"),INSTRUMENTATION_LIBS="@dynatrace/react-native-plugin/instrumentation/libs",hasJSX=function(e){var t=!1;return e.traverse({"JSXElement|JSXFragment":function(){t=!0}}),t},instrumentUserInteraction=function(e){e.traverse({"FunctionDeclaration|ObjectMethod":function(e){var e=e.node,t=core_1.types.isFunctionDeclaration(e)?e.id:e.key;core_1.types.isIdentifier(t,{name:"registerComponent"})&&(t="".concat(INSTRUMENTATION_LIBS,"/UserInteraction"),e.body.body.unshift(core_1.template.statement('componentProvider = require("'.concat(t,'").wrapProvider(componentProvider);'))()))}})},instrumentAppRegistry=function(e){e.traverse({"FunctionDeclaration|ObjectMethod":function(e){var e=e.node,t=core_1.types.isFunctionDeclaration(e)?e.id:e.key;core_1.types.isIdentifier(t,{name:"runApplication"})&&e.body.body.unshift(core_1.template.statement(_templateObject=_templateObject||(0,_taggedTemplateLiteral2.default)(['require("@dynatrace/react-native-plugin").ApplicationHandler.startup();']))())}})},instrumentExceptionsManager=function(e){var t,n=null!=(t=null==(t=null==reactOptions?void 0:reactOptions.errorHandler)?void 0:t.reportFatalErrorAsCrash)&&t,r=(null==reactOptions?void 0:reactOptions.autoStart)&&(null==(t=null==reactOptions?void 0:reactOptions.errorHandler)?void 0:t.enabled);e.traverse({FunctionDeclaration:function(e){var t;core_1.types.isIdentifier(e.node.id,{name:"handleException"})&&(t=core_1.template.statement(_templateObject2=_templateObject2||(0,_taggedTemplateLiteral2.default)(['\n setTimeout(() => BODY, require("@dynatrace/react-native-plugin/lib/core/ErrorHandler")\n .reportErrorToDynatrace(e, isFatal, CRASH, AUTO));\n ']))({BODY:core_1.types.cloneNode(e.node.body),CRASH:core_1.types.booleanLiteral(n),AUTO:core_1.types.booleanLiteral(!!r)}),e.node.body.body=[t])}})},instrumentCssInterop=function(e){e.traverse({CallExpression:function(e){core_1.types.isIdentifier(e.node.callee,{name:"require"})&&(e=e.node.arguments[0],core_1.types.isStringLiteral(e))&&("react/jsx-runtime"===e.value?e.value="@dynatrace/react-native-plugin/jsx-runtime":"react/jsx-dev-runtime"===e.value&&(e.value="@dynatrace/react-native-plugin/jsx-dev-runtime"))}})},instrumentNavigation=function(e){e.traverse({VariableDeclarator:function(e){var t;core_1.types.isIdentifier(e.node.id,{name:"getRootState"})&&(t=core_1.template.statement(_templateObject3=_templateObject3||(0,_taggedTemplateLiteral2.default)(["\n require(PATH).monitorNavigation(getRootState);\n "]))({PATH:core_1.types.stringLiteral("".concat(INSTRUMENTATION_LIBS,"/react-navigation/ReactNavigation"))}),e.parentPath.insertAfter(t))}})},instrumentReactCreateElement=function(e){var t=core_1.template.statement(_templateObject4=_templateObject4||(0,_taggedTemplateLiteral2.default)(["\n require(PATH).instrumentCreateElement(module.exports);\n "]))({PATH:core_1.types.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")});e.pushContainer("body",t)},instrumentComponents=function(e,n){e.traverse({FunctionDeclaration:function(e){var t;hasJSX(e)&&(t=e.node,core_1.types.isIdentifier(t.id))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t.id.name,Types_1.Types.FunctionalComponent))},ClassDeclaration:function(e){var t;hasJSX(e)&&(t=e.node,core_1.types.isIdentifier(t.id))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t.id.name,Types_1.Types.ClassComponent))},"FunctionExpression|ArrowFunctionExpression":function(e){var t;hasJSX(e)&&(t=e.parent,void 0!==(t=core_1.types.isVariableDeclarator(t)&&core_1.types.isIdentifier(t.id)?t.id.name:core_1.types.isAssignmentExpression(t)&&core_1.types.isIdentifier(t.left)?t.left.name:void 0))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t,Types_1.Types.FunctionalComponent))}})},instrumentLifecycle=function(e){instrumentComponents(e,function(e,t){return core_1.template.statement(_templateObject5=_templateObject5||(0,_taggedTemplateLiteral2.default)(["NAME._dtInfo = { type: TYPE, name: 'NAME_STR' }"]))({NAME:core_1.types.identifier(e),TYPE:core_1.types.numericLiteral(t),NAME_STR:core_1.types.stringLiteral(e)})})},instrumentComponentNames=function(e){instrumentComponents(e,function(e){return core_1.template.statement(_templateObject6=_templateObject6||(0,_taggedTemplateLiteral2.default)(["NAME.dtName = 'NAME_STR'"]))({NAME:core_1.types.identifier(e),NAME_STR:core_1.types.stringLiteral(e)})})},instrumentInput=function(e){var l=new Map([["react-native",{proxy:"".concat(INSTRUMENTATION_LIBS,"/react-native/"),components:new Set(["TouchableHighlight","TouchableNativeFeedback","TouchableOpacity","TouchableWithoutFeedback","Button","RefreshControl","Text","Pressable","Switch"])}],["react-native-gesture-handler",{proxy:"".concat(INSTRUMENTATION_LIBS,"/community/gesture-handler/"),components:new Set(["TouchableHighlight","TouchableNativeFeedback","TouchableOpacity","TouchableWithoutFeedback","RectButton","BorderlessButton","BaseButton"])}],["@react-native-picker/picker",{proxy:"".concat(INSTRUMENTATION_LIBS,"/community/Picker"),components:new Set(["Picker","PickerIOS"])}]]);e.traverse({ImportDeclaration:function(e){if(void 0===e.node.processed){var t=e.node.source;if(l.has(t.value)){var r=l.get(t.value),n=e.node.specifiers,a=[],i=[];if(n.forEach(function(e,t){var n;core_1.types.isImportSpecifier(e)&&(n=core_1.types.isIdentifier(e.imported)?e.imported.name:e.imported.value,r.components.has(n)||(a.push(e),i.push(t)))}),a.length!==n.length){var o,s=_createForOfIteratorHelper(i.reverse());try{for(s.s();!(o=s.n()).done;){var c=o.value;n.splice(c,1)}}catch(e){s.e(e)}finally{s.f()}0<a.length&&((t=core_1.types.importDeclaration(a,core_1.types.stringLiteral(t.value))).processed=!0,e.insertBefore(t)),e.node.source=core_1.types.stringLiteral(r.proxy),e.scope.crawl()}}}},CallExpression:function(e){core_1.types.isIdentifier(e.node.callee,{name:"require"})&&(e=e.node.arguments[0],core_1.types.isStringLiteral(e))&&l.has(e.value)&&(e.value=l.get(e.value).proxy)}})},instrumentJsxNames=function(e){e.traverse({JSXOpeningElement:function(e){var t=e.node.name,t=core_1.types.isJSXIdentifier(t)?t.name:core_1.types.isJSXMemberExpression(t)?(0,generator_1.default)(t).code:void 0;t&&e.node.attributes.push(core_1.types.jsxAttribute(core_1.types.jsxIdentifier("dtName"),core_1.types.stringLiteral(t)))}})},instrumentConfigurationPreset=function(e){var t,n=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),r={getLifecycleUpdate:reactOptions.lifecycle.includeUpdate,getLogLevel:reactOptions.debug?0:1,getBundleName:null!=(t=reactOptions.bundleName)?t:null==n?void 0:n.name,getBundleVersion:null!=(t=reactOptions.bundleVersion)?t:null==n?void 0:n.version,getActionNamePrivacy:reactOptions.input.actionNamePrivacy,getActionNamePreference:reactOptions.input.actionNamePreference,getActionNameAlgorithm:reactOptions.input.actionNameAlgorithm,isErrorHandlerEnabled:reactOptions.errorHandler.enabled,isReportFatalErrorAsCrash:reactOptions.errorHandler.reportFatalErrorAsCrash,isAutoStartupEnabled:reactOptions.autoStart};e.traverse({ClassMethod:function(e){var t;core_1.types.isIdentifier(e.node.key)&&void 0!==(t=r[e.node.key.name])&&(e=e.node.body.body[0],core_1.types.isReturnStatement(e))&&(e.argument=core_1.types.valueToNode(t))}})};exports.default=function(){return{visitor:{Program:function(e,t){reactOptions=(0,Config_1.readConfigDefault)().react;var n,r,a,i,o,s,c=t.filename;void 0!==c&&(a=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.some(function(e){return c.includes(fspath.join("node_modules",e)+fspath.sep)})},s=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.some(function(e){return c.endsWith(e)})},!(i="")===reactOptions.debugBabelPlugin&&(i=(0,generator_1.default)(e.node).code),a("@dynatrace")&&s("ConfigurationPreset.js")&&instrumentConfigurationPreset(e),a("react-native")&&s("AppRegistry.js","AppRegistryImpl.js")&&(reactOptions.autoStart&&instrumentAppRegistry(e),reactOptions.userInteraction)&&instrumentUserInteraction(e),a("react-native")&&s("ExceptionsManager.js")&&instrumentExceptionsManager(e),a("react-native-css-interop")&&s("jsx-runtime.js","jsx-dev-runtime.js")&&instrumentCssInterop(e),reactOptions.navigation.enabled&&a("@react-navigation")&&s("BaseNavigationContainer.js","BaseNavigationContainer.tsx")&&instrumentNavigation(e),a("react")&&s("index.js")&&instrumentReactCreateElement(e),null!=(n=null==(r=reactOptions.lifecycle)?void 0:r.instrument)&&n.call(r,c)&&(!c.includes("node_modules")||a("react-native")&&s("renderApplication.js"))&&hasJSX(e)&&instrumentLifecycle(e),null==(r=null==(n=reactOptions.input)?void 0:n.instrument)||!r.call(n,c)||c.includes("node_modules")&&!a("@react-navigation","react-native-drawer-layout")||instrumentInput(e),reactOptions.userInteraction&&!c.includes("node_modules")&&(instrumentJsxNames(e),instrumentComponentNames(e)),!0===reactOptions.debugBabelPlugin)&&(o=(0,generator_1.default)(e.node).code)!==i&&(s=fspath.join(PathsConstants_1.default.getBuildPath(),fspath.relative(PathsConstants_1.default.getApplicationPath(),c)+".dtx"),fs.mkdirSync(fspath.dirname(s),{recursive:!0}),fs.writeFileSync(s,o),t.set("fileDidChange",!0))}},post:function(e){var t;!0===reactOptions.debugBabelPlugin&&!0===this.get("fileDidChange")&&(t=(0,generator_1.default)(e.ast).code,e=fspath.join(PathsConstants_1.default.getBuildPath(),fspath.relative(PathsConstants_1.default.getApplicationPath(),e.opts.filename)+".dtx.downstream"),fs.mkdirSync(fspath.dirname(e),{recursive:!0}),fs.writeFileSync(e,t))}}};
1
+ var _templateObject,_templateObject2,_templateObject3,_templateObject4,_templateObject5,_templateObject6,_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_taggedTemplateLiteral2=_interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));function _createForOfIteratorHelper(e,t){var n,r,a,i,o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return a=!(r=!0),{s:function(){o=o.call(e)},n:function(){var e=o.next();return r=e.done,e},e:function(e){a=!0,n=e},f:function(){try{r||null==o.return||o.return()}finally{if(a)throw n}}};if(Array.isArray(e)||(o=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return o&&(e=o),i=0,{s:t=function(){},n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0});var reactOptions,fspath=require("path"),fs=require("fs"),core_1=require("@babel/core"),generator_1=require("@babel/generator"),PathsConstants_1=require("../scripts/PathsConstants"),Config_1=require("../scripts/Config"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),Types_1=require("./model/Types"),INSTRUMENTATION_LIBS="@dynatrace/react-native-plugin/instrumentation/libs",COMPONENTS_EXCLUDED_FROM_UIA=new Set(["Fragment","React.Fragment"]),hasJSX=function(e){var t=!1;return e.traverse({"JSXElement|JSXFragment":function(){t=!0}}),t},instrumentUserInteraction=function(e){e.traverse({"FunctionDeclaration|ObjectMethod":function(e){var e=e.node,t=core_1.types.isFunctionDeclaration(e)?e.id:e.key;core_1.types.isIdentifier(t,{name:"registerComponent"})&&(t="".concat(INSTRUMENTATION_LIBS,"/UserInteraction"),e.body.body.unshift(core_1.template.statement('componentProvider = require("'.concat(t,'").wrapProvider(componentProvider);'))()))}})},instrumentAppRegistry=function(e){e.traverse({"FunctionDeclaration|ObjectMethod":function(e){var e=e.node,t=core_1.types.isFunctionDeclaration(e)?e.id:e.key;core_1.types.isIdentifier(t,{name:"runApplication"})&&e.body.body.unshift(core_1.template.statement(_templateObject=_templateObject||(0,_taggedTemplateLiteral2.default)(['require("@dynatrace/react-native-plugin").ApplicationHandler.startup();']))())}})},instrumentExceptionsManager=function(e){var t,n=null!=(t=null==(t=null==reactOptions?void 0:reactOptions.errorHandler)?void 0:t.reportFatalErrorAsCrash)&&t,r=(null==reactOptions?void 0:reactOptions.autoStart)&&(null==(t=null==reactOptions?void 0:reactOptions.errorHandler)?void 0:t.enabled);e.traverse({FunctionDeclaration:function(e){var t;core_1.types.isIdentifier(e.node.id,{name:"handleException"})&&(t=core_1.template.statement(_templateObject2=_templateObject2||(0,_taggedTemplateLiteral2.default)(['\n setTimeout(() => BODY, require("@dynatrace/react-native-plugin/lib/core/ErrorHandler")\n .reportErrorToDynatrace(e, isFatal, CRASH, AUTO));\n ']))({BODY:core_1.types.cloneNode(e.node.body),CRASH:core_1.types.booleanLiteral(n),AUTO:core_1.types.booleanLiteral(!!r)}),e.node.body.body=[t])}})},instrumentCssInterop=function(e){e.traverse({CallExpression:function(e){core_1.types.isIdentifier(e.node.callee,{name:"require"})&&(e=e.node.arguments[0],core_1.types.isStringLiteral(e))&&("react/jsx-runtime"===e.value?e.value="@dynatrace/react-native-plugin/jsx-runtime":"react/jsx-dev-runtime"===e.value&&(e.value="@dynatrace/react-native-plugin/jsx-dev-runtime"))}})},instrumentNavigation=function(e){e.traverse({VariableDeclarator:function(e){var t;core_1.types.isIdentifier(e.node.id,{name:"getRootState"})&&(t=core_1.template.statement(_templateObject3=_templateObject3||(0,_taggedTemplateLiteral2.default)(["\n require(PATH).monitorNavigation(getRootState);\n "]))({PATH:core_1.types.stringLiteral("".concat(INSTRUMENTATION_LIBS,"/react-navigation/ReactNavigation"))}),e.parentPath.insertAfter(t))}})},instrumentReactCreateElement=function(e){var t=core_1.template.statement(_templateObject4=_templateObject4||(0,_taggedTemplateLiteral2.default)(["\n require(PATH).instrumentCreateElement(module.exports);\n "]))({PATH:core_1.types.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")});e.pushContainer("body",t)},instrumentComponents=function(e,n){e.traverse({FunctionDeclaration:function(e){var t;hasJSX(e)&&(t=e.node,core_1.types.isIdentifier(t.id))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t.id.name,Types_1.Types.FunctionalComponent))},ClassDeclaration:function(e){var t;hasJSX(e)&&(t=e.node,core_1.types.isIdentifier(t.id))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t.id.name,Types_1.Types.ClassComponent))},"FunctionExpression|ArrowFunctionExpression":function(e){var t;hasJSX(e)&&(t=e.parent,void 0!==(t=core_1.types.isVariableDeclarator(t)&&core_1.types.isIdentifier(t.id)?t.id.name:core_1.types.isAssignmentExpression(t)&&core_1.types.isIdentifier(t.left)?t.left.name:void 0))&&null!=(e=e.getStatementParent())&&e.insertAfter(n(t,Types_1.Types.FunctionalComponent))}})},instrumentLifecycle=function(e){instrumentComponents(e,function(e,t){return core_1.template.statement(_templateObject5=_templateObject5||(0,_taggedTemplateLiteral2.default)(["NAME._dtInfo = { type: TYPE, name: 'NAME_STR' }"]))({NAME:core_1.types.identifier(e),TYPE:core_1.types.numericLiteral(t),NAME_STR:core_1.types.stringLiteral(e)})})},instrumentComponentNames=function(e){instrumentComponents(e,function(e){return core_1.template.statement(_templateObject6=_templateObject6||(0,_taggedTemplateLiteral2.default)(["NAME.dtName = 'NAME_STR'"]))({NAME:core_1.types.identifier(e),NAME_STR:core_1.types.stringLiteral(e)})})},instrumentInput=function(e){var u=new Map([["react-native",{proxy:"".concat(INSTRUMENTATION_LIBS,"/react-native/"),components:new Set(["TouchableHighlight","TouchableNativeFeedback","TouchableOpacity","TouchableWithoutFeedback","Button","RefreshControl","Text","Pressable","Switch"])}],["react-native-gesture-handler",{proxy:"".concat(INSTRUMENTATION_LIBS,"/community/gesture-handler/"),components:new Set(["TouchableHighlight","TouchableNativeFeedback","TouchableOpacity","TouchableWithoutFeedback","RectButton","BorderlessButton","BaseButton"])}],["@react-native-picker/picker",{proxy:"".concat(INSTRUMENTATION_LIBS,"/community/Picker"),components:new Set(["Picker","PickerIOS"])}]]);e.traverse({ImportDeclaration:function(e){if(void 0===e.node.processed){var t=e.node.source;if(u.has(t.value)){var r=u.get(t.value),n=e.node.specifiers,a=[],i=[];if(n.forEach(function(e,t){var n;core_1.types.isImportSpecifier(e)&&(n=core_1.types.isIdentifier(e.imported)?e.imported.name:e.imported.value,r.components.has(n)||(a.push(e),i.push(t)))}),a.length!==n.length){var o,s=_createForOfIteratorHelper([].concat(i).reverse());try{for(s.s();!(o=s.n()).done;){var c=o.value;n.splice(c,1)}}catch(e){s.e(e)}finally{s.f()}0<a.length&&((t=core_1.types.importDeclaration(a,core_1.types.stringLiteral(t.value))).processed=!0,e.insertBefore(t)),e.node.source=core_1.types.stringLiteral(r.proxy),e.scope.crawl()}}}},CallExpression:function(e){core_1.types.isIdentifier(e.node.callee,{name:"require"})&&(e=e.node.arguments[0],core_1.types.isStringLiteral(e))&&u.has(e.value)&&(e.value=u.get(e.value).proxy)}})},instrumentJsxNames=function(e){e.traverse({JSXOpeningElement:function(e){var t=e.node.name,t=core_1.types.isJSXIdentifier(t)?t.name:core_1.types.isJSXMemberExpression(t)?(0,generator_1.default)(t).code:void 0;t&&!COMPONENTS_EXCLUDED_FROM_UIA.has(t)&&e.node.attributes.unshift(core_1.types.jsxAttribute(core_1.types.jsxIdentifier("dtName"),core_1.types.stringLiteral(t)))}})},instrumentConfigurationPreset=function(e){var t,n=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),r={getLifecycleUpdate:reactOptions.lifecycle.includeUpdate,getLogLevel:reactOptions.debug?0:1,getBundleName:null!=(t=reactOptions.bundleName)?t:null==n?void 0:n.name,getBundleVersion:null!=(t=reactOptions.bundleVersion)?t:null==n?void 0:n.version,getActionNamePrivacy:reactOptions.input.actionNamePrivacy,getActionNamePreference:reactOptions.input.actionNamePreference,getActionNameAlgorithm:reactOptions.input.actionNameAlgorithm,isErrorHandlerEnabled:reactOptions.errorHandler.enabled,isReportFatalErrorAsCrash:reactOptions.errorHandler.reportFatalErrorAsCrash,isAutoStartupEnabled:reactOptions.autoStart};e.traverse({ClassMethod:function(e){var t;core_1.types.isIdentifier(e.node.key)&&void 0!==(t=r[e.node.key.name])&&(e=e.node.body.body[0],core_1.types.isReturnStatement(e))&&(e.argument=core_1.types.valueToNode(t))}})},createFilenameMatcher=function(r){return{isModule:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.some(function(e){return r.includes(fspath.join("node_modules",e)+fspath.sep)})},isFile:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.some(function(e){return r.endsWith(e)})}}},captureOriginalCode=function(e){return!0!==reactOptions.debugBabelPlugin?"":(0,generator_1.default)(e.node).code},isConfigurationPresetTarget=function(e){return e.isModule("@dynatrace")&&e.isFile("ConfigurationPreset.js")},isAppRegistryTarget=function(e){return e.isModule("react-native")&&e.isFile("AppRegistry.js","AppRegistryImpl.js")},isExceptionsManagerTarget=function(e){return e.isModule("react-native")&&e.isFile("ExceptionsManager.js")},isCssInteropTarget=function(e){return e.isModule("react-native-css-interop")&&e.isFile("jsx-runtime.js","jsx-dev-runtime.js")},isNavigationTarget=function(e){return reactOptions.navigation.enabled&&e.isModule("@react-navigation")&&e.isFile("BaseNavigationContainer.js","BaseNavigationContainer.tsx")},isReactIndexTarget=function(e){return e.isModule("react")&&e.isFile("index.js")},shouldInstrumentLifecycleForFile=function(e,t,n){var r,a,n=n.isModule("react-native")&&n.isFile("renderApplication.js");return(null==(a=null==(r=reactOptions.lifecycle)?void 0:r.instrument)?void 0:a.call(r,t))&&(!t.includes("node_modules")||n)&&hasJSX(e)},shouldInstrumentInputForFile=function(e,t){var n,r,t=t.isModule("@react-navigation","react-native-drawer-layout");return(null==(r=null==(n=reactOptions.input)?void 0:n.instrument)?void 0:r.call(n,e))&&(!e.includes("node_modules")||t)},shouldInstrumentUserInteractionNames=function(e){return reactOptions.userInteraction&&!e.includes("node_modules")},instrumentByModuleAndFile=function(e,t,n){isConfigurationPresetTarget(n)&&instrumentConfigurationPreset(e),isAppRegistryTarget(n)&&(reactOptions.autoStart&&instrumentAppRegistry(e),reactOptions.userInteraction)&&instrumentUserInteraction(e),isExceptionsManagerTarget(n)&&instrumentExceptionsManager(e),isCssInteropTarget(n)&&instrumentCssInterop(e),isNavigationTarget(n)&&instrumentNavigation(e),isReactIndexTarget(n)&&instrumentReactCreateElement(e),shouldInstrumentLifecycleForFile(e,t,n)&&instrumentLifecycle(e),shouldInstrumentInputForFile(t,n)&&instrumentInput(e),shouldInstrumentUserInteractionNames(t)&&(instrumentJsxNames(e),instrumentComponentNames(e))},writeDebugOutputIfChanged=function(e,t,n,r){!0===reactOptions.debugBabelPlugin&&(e=(0,generator_1.default)(e.node).code)!==r&&(r=fspath.join(PathsConstants_1.default.getBuildPath(),fspath.relative(PathsConstants_1.default.getApplicationPath(),n)+".dtx"),fs.mkdirSync(fspath.dirname(r),{recursive:!0}),fs.writeFileSync(r,e),t.set("fileDidChange",!0))};exports.default=function(){return{visitor:{Program:function(e,t){reactOptions=(0,Config_1.readConfigDefault)().react;var n,r,a=t.filename;void 0!==a&&(n=createFilenameMatcher(a),r=captureOriginalCode(e),instrumentByModuleAndFile(e,a,n),writeDebugOutputIfChanged(e,t,a,r))}},post:function(e){var t;!0===reactOptions.debugBabelPlugin&&!0===this.get("fileDidChange")&&(t=(0,generator_1.default)(e.ast).code,e=fspath.join(PathsConstants_1.default.getBuildPath(),fspath.relative(PathsConstants_1.default.getApplicationPath(),e.opts.filename)+".dtx.downstream"),fs.mkdirSync(fspath.dirname(e),{recursive:!0}),fs.writeFileSync(e,t))}}};
@@ -1 +1 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));function _createForOfIteratorHelper(e,t){var n,r,i,o,a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(a)return i=!(r=!0),{s:function(){a=a.call(e)},n:function(){var e=a.next();return r=e.done,e},e:function(e){i=!0,n=e},f:function(){try{r||null==a.return||a.return()}finally{if(i)throw n}}};if(Array.isArray(e)||(a=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return a&&(e=a),o=0,{s:t=function(){},n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.instrument=void 0;var FileType,nodePath=require("path"),jscodeshift=require("jscodeshift"),Collection_1=require("jscodeshift/src/Collection"),FileOperationHelper_1=require("../scripts/FileOperationHelper"),PathsConstants_1=require("../scripts/PathsConstants"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),InstrumentUtil_1=require("../scripts/util/InstrumentUtil"),Run_1=require("../lib/features/ui-interaction/Run"),Touchables_InstrInfo_1=require("./libs/react-native/Touchables.InstrInfo"),RefreshControl_InstrInfo_1=require("./libs/react-native/RefreshControl.InstrInfo"),Switch_InstrInfo_1=require("./libs/react-native/Switch.InstrInfo"),Touchables_InstrInfo_2=require("./libs/community/gesture-handler/Touchables.InstrInfo"),Picker_InstrInfo_1=require("./libs/community/Picker.InstrInfo"),Types_1=require("./model/Types"),ParserUtil_1=require("./parser/ParserUtil"),referenceListInput=((e=>{e[e.Filtered=-1]="Filtered",e[e.Normal=0]="Normal",e[e.ReactNative=1]="ReactNative",e[e.React=2]="React",e[e.ReactNativeCssInterop=3]="ReactNativeCssInterop"})(FileType=FileType||{}),[]),whiteList=(referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(RefreshControl_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Switch_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_2.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Picker_InstrInfo_1.instrumentationInfo)),new Set(["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"])),instrumentationLibraryFolder="@dynatrace/react-native-plugin/instrumentation/libs",instrument=function(e,t,n){t=correctFilename(t);var r=shouldInstrumentFile(t);if(r!==FileType.Filtered){var i=!1,o=parseSource(t,e);if(r===FileType.React)addCreateElementInstrumentation(o),i=!0;else if(r===FileType.ReactNative)t.endsWith("AppRegistryImpl.js")?null!=n&&n.autoStart&&addStartupCallRegistryImpl(o)&&(i=!0):t.endsWith("AppRegistry.js")?null!=n&&n.autoStart&&addStartupCallRegistry(o)&&(i=!0):t.endsWith("renderApplication.js")?(addInfoToComponent(o),i=!0):t.endsWith("ExceptionsManager.js")&&(a=void 0!==n&&n.autoStart&&n.errorHandler.enabled,addReportErrorToDynatraceCall(o,n.errorHandler.reportFatalErrorAsCrash,a),i=!0);else if(r===FileType.ReactNativeCssInterop)i=replaceReactWithDynatraceJsxRuntime(o)||i;else{var a=getInstrumentationList(t,n),r=[{isEnabled:function(e,t){return!0===(null==t?void 0:t.userInteraction)},run:function(e,t,n){return(0,Run_1.runDTUserInteraction)(e,t,n)}}].filter(function(e){return e.isEnabled(t,n)});if(n.navigation.enabled&&instrumentReactNavigation(t,o))i=!0;else{if(!a.input&&!a.lifecycle&&0===r.length)return null!=n&&n.debug&&console.log("Dynatrace - Filtered All: ".concat(t)),deleteTransformation(t),e;a.lifecycle&&addInfoToComponent(o)&&(i=!0),a.input&&referenceListInput.forEach(function(e){e=swapReferences(o,e);o=e.root,i=i||e.modified})}var s,l=_createForOfIteratorHelper(r);try{for(l.s();!(s=l.n()).done;){var c=s.value;try{var u=c.run(o,t,n),o=u.root;u.modified&&(i=!0)}catch(e){var f=e instanceof Error?e.stack||e.message:String(e);null!=n&&n.debug&&console.log("[DynatraceInstrumentationRaw]: Feature instrumentation failed for ".concat(t,": ").concat(f))}}}catch(e){l.e(e)}finally{l.f()}}var a=i?o.toSource({quote:"single"}):e;i?writeTransformation(e=a,t):deleteTransformation(t),null!=n&&n.debug&&i&&console.log("Dynatrace - Modified Filename: "+t)}else t.includes(nodePath.join("@dynatrace","react-native-plugin"))&&t.endsWith(nodePath.join("lib","core","configuration","ConfigurationPreset.js"))&&void 0!==n&&(r=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),a=parseSource(t,e),void 0!==n.lifecycle&&changeConfigurationValue(a,"getLifecycleUpdate",n.lifecycle.includeUpdate),void 0!==n.debug&&changeConfigurationValue(a,"getLogLevel",n.debug?0:1),void 0!==n.bundleName?changeConfigurationValue(a,"getBundleName",n.bundleName):null!==r&&changeConfigurationValue(a,"getBundleName",null==r?void 0:r.name),void 0!==n.bundleVersion?changeConfigurationValue(a,"getBundleVersion",n.bundleVersion):null!==r&&changeConfigurationValue(a,"getBundleVersion",null==r?void 0:r.version),void 0!==(null==(r=n.input)?void 0:r.actionNamePrivacy)&&changeConfigurationValue(a,"getActionNamePrivacy",n.input.actionNamePrivacy),void 0!==(null==(r=n.input)?void 0:r.actionNamePreference)&&changeConfigurationValue(a,"getActionNamePreference",n.input.actionNamePreference),void 0!==(null==(r=n.input)?void 0:r.actionNameAlgorithm)&&changeConfigurationValue(a,"getActionNameAlgorithm",n.input.actionNameAlgorithm),void 0!==n.errorHandler&&(changeConfigurationValue(a,"isErrorHandlerEnabled",n.errorHandler.enabled),changeConfigurationValue(a,"isReportFatalErrorAsCrash",n.errorHandler.reportFatalErrorAsCrash)),n.autoStart&&changeConfigurationValue(a,"isAutoStartupEnabled",n.autoStart),e=a.toSource({quote:"single"}),writeTransformation(e,t));return e},instrumentReactNavigation=(exports.instrument=instrument,function(e,t){return!!instrumentReactBaseNavigationContainer(e,t)&&(e="import { monitorNavigation } from '".concat(instrumentationLibraryFolder,"/react-navigation/ReactNavigation';"),t.find(jscodeshift.ImportDeclaration).at(0).insertBefore(e),!0)}),instrumentReactBaseNavigationContainer=function(e,t){var n=!1;return e.includes("@react-navigation")&&e.includes("core")&&(e.includes("BaseNavigationContainer.js")||e.includes("BaseNavigationContainer.tsx"))&&t.find(jscodeshift.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(e){n=!0,e.parent.insertAfter("monitorNavigation(getRootState);")}),n},addInfoToComponent=function(e){var t=e.findJSXElements(),r=!1;return 0<t.length&&(e.find(jscodeshift.FunctionDeclaration).forEach(function(e){var t,n=(0,Collection_1.fromPaths)([e]);0<n.findJSXElements().length&&null!=e&&null!=e.value&&null!=e.value.id&&e.value.id.name.toString()&&(t=n.find(jscodeshift.ClassDeclaration),n=n.find(jscodeshift.ClassExpression),0===t.length)&&0===n.length&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.value.id.name.toString()),r=!0)}),e.find(jscodeshift.ClassDeclaration).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e&&null!=e.value&&e.value.id&&e.value.id.name.toString()&&(insertExpressionIntoNextBody(e,Types_1.Types.ClassComponent,e.value.id.name.toString()),r=!0)}),e.find(jscodeshift.ArrowFunctionExpression).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e.parent&&null!=e.parent.value&&null!=e.parent.value.id&&null!=e.parent.value.id.name&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.parent.value.id.name),r=!0)}),e.find(jscodeshift.FunctionExpression).forEach(function(e){0<(0,Collection_1.fromPaths)([e]).findJSXElements().length&&null!=e.parent&&null!=e.parent.value&&null!=e.parent.value.id&&null!=e.parent.value.id.name&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,e.parent.value.id.name),r=!0)})),r},insertExpressionIntoNextBody=function(e,t,n){for(t=jscodeshift.expressionStatement(jscodeshift.assignmentExpression("=",jscodeshift.memberExpression(jscodeshift.identifier(n),jscodeshift.identifier("_dtInfo")),createComponentInfo(t,n)));"body"!==(null==e?void 0:e.parentPath.name);)e=e.parentPath;void 0!==e.parentPath&&e.insertAfter(t)},createComponentInfo=function(e,t){return jscodeshift.objectExpression([jscodeshift.objectProperty(jscodeshift.identifier("type"),jscodeshift.numericLiteral(e)),jscodeshift.objectProperty(jscodeshift.identifier("name"),jscodeshift.stringLiteral(t))])},changeConfigurationValue=function(e,t,n){var e=e.find(jscodeshift.Identifier).filter(function(e){return e.node.name===t});1===e.length&&"ReturnStatement"===(e=e.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof n&&(e.argument=jscodeshift.booleanLiteral(n)),"string"==typeof n&&(e.argument=jscodeshift.stringLiteral(n)),"number"==typeof n)&&(e.argument=jscodeshift.numericLiteral(n))},parseSource=function(e,t){return jscodeshift.withParser((0,ParserUtil_1.chooseParser)(e,t))(t)},correctFilename=function(e){return nodePath.isAbsolute(e)?e.replace(PathsConstants_1.default.getApplicationPath()+nodePath.sep,""):e},deleteTransformation=function(e){try{var t=nodePath.join(PathsConstants_1.default.getBuildPath(),e+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION);FileOperationHelper_1.default.checkIfFileExistsSync(t),FileOperationHelper_1.default.deleteFileSync(t)}catch(e){}},writeTransformation=function(e,t){t=nodePath.join(PathsConstants_1.default.getBuildPath(),t);try{FileOperationHelper_1.default.checkIfFileExistsSync(nodePath.dirname(t))}catch(e){FileOperationHelper_1.default.createDirectorySync(nodePath.dirname(t))}FileOperationHelper_1.default.writeTextToFileSync(t+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION,e)},getInstrumentationList=function(e,t){var n={input:!1,lifecycle:!1};return void 0!==t&&(void 0!==t.lifecycle&&void 0!==t.lifecycle.instrument&&t.lifecycle.instrument(e)&&(n.lifecycle=!0),void 0!==t.input)&&void 0!==t.input.instrument&&t.input.instrument(e)&&(n.input=!0),n},addCreateElementInstrumentation=function(e){var t,e=e.find(jscodeshift.Program);1===e.length&&(t=jscodeshift.expressionStatement(jscodeshift.callExpression(jscodeshift.memberExpression(jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),jscodeshift.identifier("instrumentCreateElement")),[jscodeshift.memberExpression(jscodeshift.identifier("module"),jscodeshift.identifier("exports"))])),e.paths()[0].node.body.push(t))},addStartupCallRegistryImpl=function(e){var t=e.find(jscodeshift.FunctionDeclaration,{id:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addStartupCallRegistry=function(e){var t=e.find(jscodeshift.ObjectMethod,{key:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addReportErrorToDynatraceCall=function(e,n,r){var i=jscodeshift;e.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(e){var t=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(n),i.literal(r)]),t=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(e.node.body.body)),t]));e.node.body.body=[t]})},replaceReactWithDynatraceJsxRuntime=function(e){var t=!1,e=e.find(jscodeshift.CallExpression,{callee:{name:"require"}});return e.find(jscodeshift.Literal,{value:"react/jsx-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-runtime",t=!0,e}),e.find(jscodeshift.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-dev-runtime",t=!0,e}),t},insertInArray=function(e,t){for(var n=arguments.length,r=new Array(2<n?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];return e.splice.apply(e,[t,0].concat(r))},shouldInstrumentFile=function(e){if(e.includes("@dynatrace"))return FileType.Filtered;var t=nodePath.extname(e);if(".js"!==t&&".ts"!==t&&".tsx"!==t&&".jsx"!==t)return FileType.Filtered;for(var n=nodePath.parse(e),r=n.dir.split(nodePath.sep),i=0;i<r.length;i++)if("node_modules"===r[i]){if("react-native"===r[i+1]||"create-react-class"===r[i+1]||"react-clone-referenced-element"===r[i+1])return whiteList.has(n.name)?FileType.ReactNative:FileType.Filtered;if("react"===r[i+1]&&"index"===n.name)return FileType.React;if("react-native-css-interop"===r[i+1]&&("jsx-runtime"===n.name||"jsx-dev-runtime"===n.name))return FileType.ReactNativeCssInterop}return FileType.Normal},handleImports=function(e,t,n){var r=handleDestructuredImport(e,t,n);return handleDefaultImport(e,t,n)||r},handleDestructuredImport=function(e,t,n){var r=findImportSpecifier(e,t);return 0<r.length&&(void 0!==(r=removeImportSpecifier(r,t.reference,!1))&&(n.customName=r.localName),addReference(e,n),!0)},handleDefaultImport=function(e,t,n){var r=findImportDeclaration(e,t.module);if(1===r.length){r=removeImportSpecifier(r,t.reference,!0);if(void 0!==r)return addDefaultImport(e,n.defaultImport,r.localName,"ImportNamespaceSpecifier"===r.type),!0}return!1},swapReferences=function(e,t){var n=JSON.parse(JSON.stringify(t.new));return{root:e,modified:handleImports(e,t.old,n)||modifyRequireModule(e,t.old,t.new.defaultImport)}},findImportSpecifier=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module&&null!=e.node.specifiers&&e.node.specifiers.some(function(e){return isImportSpecifier(e)&&e.imported.name===t.reference||e.local&&e.local.name===t.reference})})},isImportSpecifier=function(e){return void 0!==e.imported},modifyRequireModule=function(e,t,n){var r=!1;return e.find(jscodeshift.CallExpression).filter(function(e){return isRequire(e.node.callee)&&isArgumentALiteral(e.node.arguments[0])&&e.node.arguments[0].value===t.module&&void 0!==e.parent}).forEach(function(e){(void 0===e.parent.value.property||void 0!==e.parent.value.property&&void 0!==e.parent.value.property.name&&e.parent.value.property.name===t.reference)&&(e.node.arguments[0].value=n,r=r||!0)}),r},isRequire=function(e){return"require"===e.name},isArgumentALiteral=function(e){return"StringLiteral"===e.type||"Literal"===e.type},findImportDeclaration=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t})},removeImportSpecifier=function(e,n,r){var i;return e.forEach(function(e){void 0!==e.node.specifiers&&(e.node.specifiers=e.node.specifiers.filter(function(e){var t;return isImportSpecifier(e)&&!r?((t=e.imported.name!==n)||null==e.local||e.imported.name===e.local.name||(i={localName:e.local.name.toString(),type:e.type}),t):!(!isImportSpecifier(e)&&r&&(null!=e.local&&(i={localName:e.local.name.toString(),type:e.type}),1))}),0===e.node.specifiers.length)&&e.prune()}),i},insertImportSpecifier=function(e,t){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(importSpecifier(t))})},insertImportDefaultSpecifier=function(e,t,n){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(n)})},insertImportDeclaration=function(e,t,n){var r=e.find(jscodeshift.ImportDeclaration);0<r.length?jscodeshift(r.paths()[0]).insertAfter(importDeclaration(t,n)):1===(r=e.find(jscodeshift.Program)).length&&r.paths()[0].node.body.unshift(importDeclaration(t,n))},addReference=function(e,t){0<findImportDeclaration(e,t.module).length?insertImportSpecifier(e,t):insertImportDeclaration(e,t.module,[importSpecifier(t)])},addDefaultImport=function(e,t,n,r){var i=findImportDeclaration(e,t),r=(r?importNamespaceSpecifier:importDefaultSpecifier)(n);0<i.length?insertImportDefaultSpecifier(e,t,r):insertImportDeclaration(e,t,[r])},addRequire=function(e,t){e=e.find(jscodeshift.VariableDeclaration);0<e.length&&jscodeshift(e.paths()[0]).insertAfter(requireDeclaration(t))},expressionStatement=function(e,t,n){return jscodeshift.expressionStatement(callExpression(e,t,n))},callExpression=function(e,t,n){return jscodeshift.callExpression(memberExpression(e,t),n)},requireDeclaration=function(e){return jscodeshift.variableDeclaration("var",[requireDeclarator(e)])},requireDeclarator=function(e){return jscodeshift.variableDeclarator(void 0!==e.customName?jscodeshift.identifier(e.customName):jscodeshift.identifier(e.reference),(0<e.reference.length?memberExpressionRequire:requireExpression)(e))},memberExpressionRequire=function(e){return jscodeshift.memberExpression(requireExpression(e),jscodeshift.identifier(e.reference))},memberExpression=function(e,t){return jscodeshift.memberExpression(jscodeshift.identifier(e),jscodeshift.identifier(t))},requireExpression=function(e){return jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.literal(e.module)])},importDeclaration=function(e,t){return jscodeshift.importDeclaration(t,jscodeshift.literal(e))},importSpecifier=function(e){return void 0!==e.customName?jscodeshift.importSpecifier(jscodeshift.identifier(e.reference),jscodeshift.identifier(e.customName)):jscodeshift.importSpecifier(jscodeshift.identifier(e.reference))},importDefaultSpecifier=function(e){return jscodeshift.importDefaultSpecifier(jscodeshift.identifier(e))},importNamespaceSpecifier=function(e){return jscodeshift.importNamespaceSpecifier(jscodeshift.identifier(e))};
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));function _createForOfIteratorHelper(e,t){var n,r,i,o,a="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(a)return i=!(r=!0),{s:function(){a=a.call(e)},n:function(){var e=a.next();return r=e.done,e},e:function(e){i=!0,n=e},f:function(){try{r||null==a.return||a.return()}finally{if(i)throw n}}};if(Array.isArray(e)||(a=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return a&&(e=a),o=0,{s:t=function(){},n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var n;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(n="Object"===(n={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:n)||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.instrument=void 0;var FileType,nodePath=require("path"),jscodeshift=require("jscodeshift"),Collection_1=require("jscodeshift/src/Collection"),FileOperationHelper_1=require("../scripts/FileOperationHelper"),PathsConstants_1=require("../scripts/PathsConstants"),GetValuesFromPackage_1=require("../lib/core/util/GetValuesFromPackage"),InstrumentUtil_1=require("../scripts/util/InstrumentUtil"),Run_1=require("../lib/features/ui-interaction/Run"),Touchables_InstrInfo_1=require("./libs/react-native/Touchables.InstrInfo"),RefreshControl_InstrInfo_1=require("./libs/react-native/RefreshControl.InstrInfo"),Switch_InstrInfo_1=require("./libs/react-native/Switch.InstrInfo"),Touchables_InstrInfo_2=require("./libs/community/gesture-handler/Touchables.InstrInfo"),Picker_InstrInfo_1=require("./libs/community/Picker.InstrInfo"),Types_1=require("./model/Types"),ParserUtil_1=require("./parser/ParserUtil"),referenceListInput=((e=>{e[e.Filtered=-1]="Filtered",e[e.Normal=0]="Normal",e[e.ReactNative=1]="ReactNative",e[e.React=2]="React",e[e.ReactNativeCssInterop=3]="ReactNativeCssInterop"})(FileType=FileType||{}),[]),whiteList=(referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(RefreshControl_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Switch_InstrInfo_1.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Touchables_InstrInfo_2.instrumentationInfo)),referenceListInput.push.apply(referenceListInput,(0,_toConsumableArray2.default)(Picker_InstrInfo_1.instrumentationInfo)),new Set(["AppRegistry","AppRegistryImpl","renderApplication","ExceptionsManager"])),instrumentationLibraryFolder="@dynatrace/react-native-plugin/instrumentation/libs",getRegisteredFeatures=function(){return[{isEnabled:function(e,t){return!0===(null==t?void 0:t.userInteraction)},run:function(e,t,n){return(0,Run_1.runDTUserInteraction)(e,t,n)}}]},getEnabledFeatures=function(t,n){return getRegisteredFeatures().filter(function(e){return e.isEnabled(t,n)})},applyInputInstrumentation=function(e){var t=e,n=!1;return referenceListInput.forEach(function(e){e=swapReferences(t,e);t=e.root,n=n||e.modified}),{root:t,modified:n}},applyEnabledFeatures=function(e,t,n,r){var i,o=e,a=!1,s=_createForOfIteratorHelper(r);try{for(s.s();!(i=s.n()).done;){var l=i.value;try{var u=l.run(o,t,n),o=u.root;u.modified&&(a=!0)}catch(e){var c=e instanceof Error?e.stack||e.message:String(e);null!=n&&n.debug&&console.log("[DynatraceInstrumentationRaw]: Feature instrumentation failed for ".concat(t,": ").concat(c))}}}catch(e){s.e(e)}finally{s.f()}return{root:o,modified:a}},applyReactNativeInstrumentation=function(e,t,n){return t.endsWith("AppRegistryImpl.js")?{root:e,modified:(null==n?void 0:n.autoStart)&&addStartupCallRegistryImpl(e)}:t.endsWith("AppRegistry.js")?{root:e,modified:(null==n?void 0:n.autoStart)&&addStartupCallRegistry(e)}:t.endsWith("renderApplication.js")?(addInfoToComponent(e),{root:e,modified:!0}):t.endsWith("ExceptionsManager.js")?(t=void 0!==n&&n.autoStart&&n.errorHandler.enabled,addReportErrorToDynatraceCall(e,n.errorHandler.reportFatalErrorAsCrash,t),{root:e,modified:!0}):{root:e,modified:!1}},applyNormalInstrumentation=function(e,t,n,r){var i=!1,o=getInstrumentationList(n,r),a=getEnabledFeatures(n,r);if(r.navigation.enabled&&instrumentReactNavigation(n,t))i=!0;else{if(!o.input&&!o.lifecycle&&0===a.length)return null!=r&&r.debug&&console.log("Dynatrace - Filtered All: ".concat(n)),deleteTransformation(n),{root:t,modified:!1,filteredOut:!0};o.lifecycle&&addInfoToComponent(t)&&(i=!0),o.input&&(t=(o=applyInputInstrumentation(t)).root,i=i||o.modified)}o=applyEnabledFeatures(t,n,r,a);return{root:t=o.root,modified:i=i||o.modified,filteredOut:!1}},finalizeInstrumentation=function(e,t,n,r,i){return i?(i=t.toSource({quote:"single"}),writeTransformation(i,n),null!=r&&r.debug&&console.log("Dynatrace - Modified Filename: "+n),i):(deleteTransformation(n),e)},isOwnConfigurationPresetFile=function(e){return!!e.includes(nodePath.join("@dynatrace","react-native-plugin"))&&e.endsWith(nodePath.join("lib","core","configuration","ConfigurationPreset.js"))},applyConfigurationPresetInstrumentation=function(e,t,n){var r;return void 0===n?e:(r=(0,GetValuesFromPackage_1.getHostAppBundleInfo)(PathsConstants_1.default.getPackageJsonFile()),e=parseSource(t,e),void 0!==n.lifecycle&&changeConfigurationValue(e,"getLifecycleUpdate",n.lifecycle.includeUpdate),void 0!==n.debug&&changeConfigurationValue(e,"getLogLevel",n.debug?0:1),void 0!==n.bundleName?changeConfigurationValue(e,"getBundleName",n.bundleName):null!==r&&changeConfigurationValue(e,"getBundleName",null==r?void 0:r.name),void 0!==n.bundleVersion?changeConfigurationValue(e,"getBundleVersion",n.bundleVersion):null!==r&&changeConfigurationValue(e,"getBundleVersion",null==r?void 0:r.version),void 0!==(null==(r=n.input)?void 0:r.actionNamePrivacy)&&changeConfigurationValue(e,"getActionNamePrivacy",n.input.actionNamePrivacy),void 0!==(null==(r=n.input)?void 0:r.actionNamePreference)&&changeConfigurationValue(e,"getActionNamePreference",n.input.actionNamePreference),void 0!==(null==(r=n.input)?void 0:r.actionNameAlgorithm)&&changeConfigurationValue(e,"getActionNameAlgorithm",n.input.actionNameAlgorithm),void 0!==n.errorHandler&&(changeConfigurationValue(e,"isErrorHandlerEnabled",n.errorHandler.enabled),changeConfigurationValue(e,"isReportFatalErrorAsCrash",n.errorHandler.reportFatalErrorAsCrash)),n.autoStart&&changeConfigurationValue(e,"isAutoStartupEnabled",n.autoStart),r=e.toSource({quote:"single"}),writeTransformation(r,t),r)},applyGeneralInstrumentation=function(e,t,n){var r,i,o=shouldInstrumentFile(t);return o===FileType.Filtered?e:(r=parseSource(t,e),o===FileType.React?(addCreateElementInstrumentation(r),finalizeInstrumentation(e,r,t,n,!0)):o===FileType.ReactNative?(i=applyReactNativeInstrumentation(r,t,n),finalizeInstrumentation(e,i.root,t,n,i.modified)):o===FileType.ReactNativeCssInterop?(i=replaceReactWithDynatraceJsxRuntime(r),finalizeInstrumentation(e,r,t,n,i)):(o=applyNormalInstrumentation(e,r,t,n)).filteredOut?e:finalizeInstrumentation(e,o.root,t,n,o.modified))},instrument=function(e,t,n){t=correctFilename(t),e=applyGeneralInstrumentation(e,t,n);return isOwnConfigurationPresetFile(t)?applyConfigurationPresetInstrumentation(e,t,n):e},instrumentReactNavigation=(exports.instrument=instrument,function(e,t){return!!instrumentReactBaseNavigationContainer(e,t)&&(e="import { monitorNavigation } from '".concat(instrumentationLibraryFolder,"/react-navigation/ReactNavigation';"),t.find(jscodeshift.ImportDeclaration).at(0).insertBefore(e),!0)}),instrumentReactBaseNavigationContainer=function(e,t){var n=!1;return e.includes("@react-navigation")&&e.includes("core")&&(e.includes("BaseNavigationContainer.js")||e.includes("BaseNavigationContainer.tsx"))&&t.find(jscodeshift.VariableDeclarator,{id:{name:"getRootState"}}).forEach(function(e){n=!0,e.parent.insertAfter("monitorNavigation(getRootState);")}),n},addInfoToComponent=function(e){var t=e.findJSXElements(),i=!1;return 0<t.length&&(e.find(jscodeshift.FunctionDeclaration).forEach(function(e){var t=(0,Collection_1.fromPaths)([e]),n=t.findJSXElements(),r="string"==typeof(null==(r=null==(r=e.value)?void 0:r.id)?void 0:r.name)?e.value.id.name:void 0;0<n.length&&void 0!==r&&""!==r&&(n=t.find(jscodeshift.ClassDeclaration),t=t.find(jscodeshift.ClassExpression),0===n.length)&&0===t.length&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,r),i=!0)}),e.find(jscodeshift.ClassDeclaration).forEach(function(e){var t=(0,Collection_1.fromPaths)([e]).findJSXElements(),n="string"==typeof(null==(n=null==(n=e.value)?void 0:n.id)?void 0:n.name)?e.value.id.name:void 0;0<t.length&&void 0!==n&&""!==n&&(insertExpressionIntoNextBody(e,Types_1.Types.ClassComponent,n),i=!0)}),e.find(jscodeshift.ArrowFunctionExpression).forEach(function(e){var t=(0,Collection_1.fromPaths)([e]).findJSXElements(),n="string"==typeof(null==(n=null==(n=null==(n=e.parent)?void 0:n.value)?void 0:n.id)?void 0:n.name)?e.parent.value.id.name:void 0;0<t.length&&void 0!==n&&""!==n&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,n),i=!0)}),e.find(jscodeshift.FunctionExpression).forEach(function(e){var t=(0,Collection_1.fromPaths)([e]).findJSXElements(),n="string"==typeof(null==(n=null==(n=null==(n=e.parent)?void 0:n.value)?void 0:n.id)?void 0:n.name)?e.parent.value.id.name:void 0;0<t.length&&void 0!==n&&""!==n&&(insertExpressionIntoNextBody(e,Types_1.Types.FunctionalComponent,n),i=!0)})),i},insertExpressionIntoNextBody=function(e,t,n){for(t=jscodeshift.expressionStatement(jscodeshift.assignmentExpression("=",jscodeshift.memberExpression(jscodeshift.identifier(n),jscodeshift.identifier("_dtInfo")),createComponentInfo(t,n)));"body"!==(null==e?void 0:e.parentPath.name);)e=e.parentPath;void 0!==e.parentPath&&e.insertAfter(t)},createComponentInfo=function(e,t){return jscodeshift.objectExpression([jscodeshift.objectProperty(jscodeshift.identifier("type"),jscodeshift.numericLiteral(e)),jscodeshift.objectProperty(jscodeshift.identifier("name"),jscodeshift.stringLiteral(t))])},changeConfigurationValue=function(e,t,n){var e=e.find(jscodeshift.Identifier).filter(function(e){return e.node.name===t});1===e.length&&"ReturnStatement"===(e=e.paths()[0].parent.value.body.body[0]).type&&("boolean"==typeof n&&(e.argument=jscodeshift.booleanLiteral(n)),"string"==typeof n&&(e.argument=jscodeshift.stringLiteral(n)),"number"==typeof n)&&(e.argument=jscodeshift.numericLiteral(n))},parseSource=function(e,t){return jscodeshift.withParser((0,ParserUtil_1.chooseParser)(e,t))(t)},correctFilename=function(e){return nodePath.isAbsolute(e)?e.replace(PathsConstants_1.default.getApplicationPath()+nodePath.sep,""):e},deleteTransformation=function(e){try{var t=nodePath.join(PathsConstants_1.default.getBuildPath(),e+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION);FileOperationHelper_1.default.checkIfFileExistsSync(t),FileOperationHelper_1.default.deleteFileSync(t)}catch(e){}},writeTransformation=function(e,t){t=nodePath.join(PathsConstants_1.default.getBuildPath(),t);try{FileOperationHelper_1.default.checkIfFileExistsSync(nodePath.dirname(t))}catch(e){FileOperationHelper_1.default.createDirectorySync(nodePath.dirname(t))}FileOperationHelper_1.default.writeTextToFileSync(t+InstrumentUtil_1.INSTRUMENTED_FILE_EXTENSION,e)},getInstrumentationList=function(e,t){var n,r,i={input:!1,lifecycle:!1};return!0===(null==(n=null==(r=null==t?void 0:t.lifecycle)?void 0:r.instrument)?void 0:n.call(r,e))&&(i.lifecycle=!0),!0===(null==(r=null==(n=null==t?void 0:t.input)?void 0:n.instrument)?void 0:r.call(n,e))&&(i.input=!0),i},addCreateElementInstrumentation=function(e){var t,e=e.find(jscodeshift.Program);1===e.length&&(t=jscodeshift.expressionStatement(jscodeshift.callExpression(jscodeshift.memberExpression(jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.stringLiteral("@dynatrace/react-native-plugin/instrumentation/jsx/ElementHelper")]),jscodeshift.identifier("instrumentCreateElement")),[jscodeshift.memberExpression(jscodeshift.identifier("module"),jscodeshift.identifier("exports"))])),e.paths()[0].node.body.push(t))},addStartupCallRegistryImpl=function(e){var t=e.find(jscodeshift.FunctionDeclaration,{id:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addStartupCallRegistry=function(e){var t=e.find(jscodeshift.ObjectMethod,{key:{name:"runApplication"}});return 1===t.length&&(addRequire(e,{customName:"_DynatraceApplicationHandler",module:"@dynatrace/react-native-plugin",reference:"ApplicationHandler"}),insertInArray(t.get().value.body.body,0,expressionStatement("_DynatraceApplicationHandler","startup",[])),!0)},addReportErrorToDynatraceCall=function(e,n,r){var i=jscodeshift;e.find(i.FunctionDeclaration,{id:{name:"handleException"}}).forEach(function(e){var t=i.callExpression(i.memberExpression(i.callExpression(i.identifier("require"),[i.literal("@dynatrace/react-native-plugin/lib/core/ErrorHandler")]),i.identifier("reportErrorToDynatrace")),[i.identifier("e"),i.identifier("isFatal"),i.literal(n),i.literal(r)]),t=i.expressionStatement(i.callExpression(i.identifier("setTimeout"),[i.arrowFunctionExpression([],i.blockStatement(e.node.body.body)),t]));e.node.body.body=[t]})},replaceReactWithDynatraceJsxRuntime=function(e){var t=!1,e=e.find(jscodeshift.CallExpression,{callee:{name:"require"}});return e.find(jscodeshift.Literal,{value:"react/jsx-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-runtime",t=!0,e}),e.find(jscodeshift.Literal,{value:"react/jsx-dev-runtime"}).replaceWith(function(e){e=e.node;return e.value="@dynatrace/react-native-plugin/jsx-dev-runtime",t=!0,e}),t},insertInArray=function(e,t){for(var n=arguments.length,r=new Array(2<n?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];return e.splice.apply(e,[t,0].concat(r))},getNodeModulesFileType=function(e,t){return"react-native"===e||"create-react-class"===e||"react-clone-referenced-element"===e?whiteList.has(t)?FileType.ReactNative:FileType.Filtered:"react"===e&&"index"===t?FileType.React:"react-native-css-interop"!==e||"jsx-runtime"!==t&&"jsx-dev-runtime"!==t?void 0:FileType.ReactNativeCssInterop},shouldInstrumentFile=function(e){if(e.includes("@dynatrace"))return FileType.Filtered;var t=nodePath.extname(e);if(".js"!==t&&".ts"!==t&&".tsx"!==t&&".jsx"!==t)return FileType.Filtered;for(var n=nodePath.parse(e),r=n.dir.split(nodePath.sep),i=0;i<r.length;i++)if("node_modules"===r[i]){var o=getNodeModulesFileType(r[i+1],n.name);if(void 0!==o)return o}return FileType.Normal},handleImports=function(e,t,n){var r=handleDestructuredImport(e,t,n);return handleDefaultImport(e,t,n)||r},handleDestructuredImport=function(e,t,n){var r=findImportSpecifier(e,t);return 0<r.length&&(void 0!==(r=removeImportSpecifier(r,t.reference,!1))&&(n.customName=r.localName),addReference(e,n),!0)},handleDefaultImport=function(e,t,n){var r=findImportDeclaration(e,t.module);if(1===r.length){r=removeImportSpecifier(r,t.reference,!0);if(void 0!==r)return addDefaultImport(e,n.defaultImport,r.localName,"ImportNamespaceSpecifier"===r.type),!0}return!1},swapReferences=function(e,t){var n=JSON.parse(JSON.stringify(t.new));return{root:e,modified:handleImports(e,t.old,n)||modifyRequireModule(e,t.old,t.new.defaultImport)}},findImportSpecifier=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module&&null!=e.node.specifiers&&e.node.specifiers.some(function(e){return isImportSpecifier(e)&&e.imported.name===t.reference||e.local&&e.local.name===t.reference})})},isImportSpecifier=function(e){return void 0!==e.imported},modifyRequireModule=function(e,t,n){var r=!1;return e.find(jscodeshift.CallExpression).filter(function(e){return isRequire(e.node.callee)&&isArgumentALiteral(e.node.arguments[0])&&e.node.arguments[0].value===t.module&&void 0!==e.parent}).forEach(function(e){(void 0===e.parent.value.property||void 0!==e.parent.value.property&&void 0!==e.parent.value.property.name&&e.parent.value.property.name===t.reference)&&(e.node.arguments[0].value=n,r=r||!0)}),r},isRequire=function(e){return"require"===e.name},isArgumentALiteral=function(e){return"StringLiteral"===e.type||"Literal"===e.type},findImportDeclaration=function(e,t){return e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t})},removeImportSpecifier=function(e,n,r){var i;return e.forEach(function(e){void 0!==e.node.specifiers&&(e.node.specifiers=e.node.specifiers.filter(function(e){var t;return isImportSpecifier(e)&&!r?((t=e.imported.name!==n)||null==e.local||e.imported.name===e.local.name||(i={localName:e.local.name.toString(),type:e.type}),t):!(!isImportSpecifier(e)&&r&&(null!=e.local&&(i={localName:e.local.name.toString(),type:e.type}),1))}),0===e.node.specifiers.length)&&e.prune()}),i},insertImportSpecifier=function(e,t){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t.module}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(importSpecifier(t))})},insertImportDefaultSpecifier=function(e,t,n){e.find(jscodeshift.ImportDeclaration).filter(function(e){return e.node.source.value===t}).forEach(function(e){null!=e.node.specifiers&&e.node.specifiers.push(n)})},insertImportDeclaration=function(e,t,n){var r=e.find(jscodeshift.ImportDeclaration);0<r.length?jscodeshift(r.paths()[0]).insertAfter(importDeclaration(t,n)):1===(r=e.find(jscodeshift.Program)).length&&r.paths()[0].node.body.unshift(importDeclaration(t,n))},addReference=function(e,t){0<findImportDeclaration(e,t.module).length?insertImportSpecifier(e,t):insertImportDeclaration(e,t.module,[importSpecifier(t)])},addDefaultImport=function(e,t,n,r){var i=findImportDeclaration(e,t),r=(r?importNamespaceSpecifier:importDefaultSpecifier)(n);0<i.length?insertImportDefaultSpecifier(e,t,r):insertImportDeclaration(e,t,[r])},addRequire=function(e,t){e=e.find(jscodeshift.VariableDeclaration);0<e.length&&jscodeshift(e.paths()[0]).insertAfter(requireDeclaration(t))},expressionStatement=function(e,t,n){return jscodeshift.expressionStatement(callExpression(e,t,n))},callExpression=function(e,t,n){return jscodeshift.callExpression(memberExpression(e,t),n)},requireDeclaration=function(e){return jscodeshift.variableDeclaration("var",[requireDeclarator(e)])},requireDeclarator=function(e){return jscodeshift.variableDeclarator(void 0!==e.customName?jscodeshift.identifier(e.customName):jscodeshift.identifier(e.reference),(0<e.reference.length?memberExpressionRequire:requireExpression)(e))},memberExpressionRequire=function(e){return jscodeshift.memberExpression(requireExpression(e),jscodeshift.identifier(e.reference))},memberExpression=function(e,t){return jscodeshift.memberExpression(jscodeshift.identifier(e),jscodeshift.identifier(t))},requireExpression=function(e){return jscodeshift.callExpression(jscodeshift.identifier("require"),[jscodeshift.literal(e.module)])},importDeclaration=function(e,t){return jscodeshift.importDeclaration(t,jscodeshift.literal(e))},importSpecifier=function(e){return void 0!==e.customName?jscodeshift.importSpecifier(jscodeshift.identifier(e.reference),jscodeshift.identifier(e.customName)):jscodeshift.importSpecifier(jscodeshift.identifier(e.reference))},importDefaultSpecifier=function(e){return jscodeshift.importDefaultSpecifier(jscodeshift.identifier(e))},importNamespaceSpecifier=function(e){return jscodeshift.importNamespaceSpecifier(jscodeshift.identifier(e))};
@@ -22,16 +22,14 @@ const getGlobalPressHook = () => {
22
22
  return g === null || g === void 0 ? void 0 : g.__DT_UI_PLUGIN_PRESS_HOOK__;
23
23
  };
24
24
  const getDisplayName = (type) => {
25
+ var _a;
25
26
  if (!type) {
26
27
  return 'Unknown';
27
28
  }
28
29
  if (typeof type === 'string') {
29
30
  return type;
30
31
  }
31
- return (type.displayName ||
32
- type.name ||
33
- (type.constructor && type.constructor.name) ||
34
- 'Anonymous');
32
+ return (type.displayName || type.name || ((_a = type.constructor) === null || _a === void 0 ? void 0 : _a.name) || 'Anonymous');
35
33
  };
36
34
  const guessTouchableName = (type, props) => {
37
35
  if (!props) {
@@ -104,18 +102,16 @@ const attachPressHookToProps = (type, props) => {
104
102
  return cloned || props;
105
103
  };
106
104
  const createElement = (type, props, ...children) => {
105
+ var _a;
107
106
  const patchedProps = attachPressHookToProps(type, props);
108
- if (type != null &&
109
- type._dtInfo != null &&
110
- !(0, ElementHelper_1.isDtActionIgnore)(patchedProps)) {
107
+ if ((type === null || type === void 0 ? void 0 : type._dtInfo) != null && !(0, ElementHelper_1.isDtActionIgnore)(patchedProps)) {
111
108
  if (type._dtInfo.type === Types_1.Types.FunctionalComponent) {
112
109
  return (0, react_1.createElement)(FunctionalComponent_1.DynatraceFunctionalComponent, {
113
110
  children: (0, react_1.createElement)(type, patchedProps, ...children),
114
111
  });
115
112
  }
116
113
  else if (type._dtInfo.type === Types_1.Types.ClassComponent &&
117
- type.prototype !== undefined &&
118
- type.prototype.isReactComponent !== undefined) {
114
+ ((_a = type.prototype) === null || _a === void 0 ? void 0 : _a.isReactComponent) !== undefined) {
119
115
  return (0, react_1.createElement)(ClassComponent_1.DynatraceClassComponent, {
120
116
  children: (0, react_1.createElement)(type, patchedProps, ...children),
121
117
  });
@@ -8,12 +8,10 @@ const RefreshControl_1 = require("./components/RefreshControl");
8
8
  const FunctionalComponent_1 = require("./components/FunctionalComponent");
9
9
  const ClassComponent_1 = require("./components/ClassComponent");
10
10
  const instrumentCreateElement = (reactModule) => {
11
- if (reactModule != null && reactModule.createElement != null) {
11
+ if ((reactModule === null || reactModule === void 0 ? void 0 : reactModule.createElement) != null) {
12
12
  const reactCreateElement = reactModule.createElement;
13
13
  reactModule.createElement = (type, props, ...children) => {
14
- if (type != null &&
15
- type._dtInfo != null &&
16
- !(0, exports.isDtActionIgnore)(props)) {
14
+ if ((type === null || type === void 0 ? void 0 : type._dtInfo) != null && !(0, exports.isDtActionIgnore)(props)) {
17
15
  if (type._dtInfo.type === Types_1.Types.FunctionalComponent) {
18
16
  return reactCreateElement(FunctionalComponent_1.DynatraceFunctionalComponent, {}, reactCreateElement(type, props, ...children));
19
17
  }
@@ -33,11 +31,12 @@ const instrumentCreateElement = (reactModule) => {
33
31
  exports.instrumentCreateElement = instrumentCreateElement;
34
32
  const modifyElement = (type, props) => {
35
33
  if (props != null) {
34
+ const elementProps = props;
36
35
  if (type._dtInfo.type === Types_1.Types.RefreshControl &&
37
- props.onRefresh != null) {
36
+ elementProps.onRefresh != null) {
38
37
  (0, RefreshControl_1.RefreshControlHelper)(Dynatrace_1.Dynatrace).attachOnRefresh(props);
39
38
  }
40
- else if (props.onValueChange != null &&
39
+ else if (elementProps.onValueChange != null &&
41
40
  type._dtInfo.type === Types_1.Types.Picker) {
42
41
  (0, Picker_1.PickerHelper)(Dynatrace_1.Dynatrace).attachOnValueChange(props);
43
42
  }
@@ -1,45 +1,47 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ReactDevRuntime = require("react/jsx-dev-runtime");
4
- const Types_1 = require("../model/Types");
5
4
  const FunctionalComponent_1 = require("./components/FunctionalComponent");
6
5
  const ClassComponent_1 = require("./components/ClassComponent");
7
6
  const ElementHelper_1 = require("./ElementHelper");
7
+ const JsxRuntimeHelpers_1 = require("./JsxRuntimeHelpers");
8
8
  try {
9
+ const renderOriginal = (args) => ReactDevRuntime.jsxDEV(...args);
10
+ const createWrapperProps = (args) => (Object.assign(Object.assign({}, args[1]), { children: renderOriginal(args) }));
11
+ const wrapWithComponent = (args, wrapperComponent, wrapperProps) => {
12
+ if ((0, JsxRuntimeHelpers_1.hasKey)(args)) {
13
+ return ReactDevRuntime.jsxDEV(wrapperComponent, wrapperProps, args[2] + '_dt');
14
+ }
15
+ return ReactDevRuntime.jsxDEV(wrapperComponent, wrapperProps);
16
+ };
17
+ const wrapFunctionalComponent = (args) => {
18
+ const wrapperProps = createWrapperProps(args);
19
+ wrapperProps.dtActionName =
20
+ args[1] !== undefined && args[1].dtActionName !== undefined
21
+ ? args[1].dtActionName
22
+ : args[0]._dtInfo.name;
23
+ return wrapWithComponent(args, FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps);
24
+ };
25
+ const wrapClassComponent = (args) => {
26
+ const wrapperProps = createWrapperProps(args);
27
+ return wrapWithComponent(args, ClassComponent_1.DynatraceClassComponent, wrapperProps);
28
+ };
9
29
  const jsxDEV = (...args) => {
10
- if (args[0] !== undefined &&
11
- args[0]._dtInfo !== undefined &&
12
- !(0, ElementHelper_1.isDtActionIgnore)(args[1])) {
13
- if (args[0]._dtInfo.type === Types_1.Types.FunctionalComponent) {
14
- const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: ReactDevRuntime.jsxDEV(...args) });
15
- wrapperProps.dtActionName =
16
- args[1] !== undefined && args[1].dtActionName !== undefined
17
- ? args[1].dtActionName
18
- : args[0]._dtInfo.name;
19
- if (args[2] !== undefined) {
20
- return ReactDevRuntime.jsxDEV(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps, args[2] + '_dt');
21
- }
22
- else {
23
- return ReactDevRuntime.jsxDEV(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps);
24
- }
25
- }
26
- else if (args[0]._dtInfo.type === Types_1.Types.ClassComponent &&
27
- args[0].prototype !== undefined &&
28
- args[0].prototype.isReactComponent !== undefined) {
29
- const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: ReactDevRuntime.jsxDEV(...args) });
30
- if (args[2] !== undefined) {
31
- return ReactDevRuntime.jsxDEV(ClassComponent_1.DynatraceClassComponent, wrapperProps, args[2] + '_dt');
32
- }
33
- else {
34
- return ReactDevRuntime.jsxDEV(ClassComponent_1.DynatraceClassComponent, wrapperProps);
35
- }
36
- }
37
- (0, ElementHelper_1.modifyElement)(args[0], args[1]);
30
+ const type = args[0];
31
+ if (!(0, JsxRuntimeHelpers_1.isInstrumentedType)(type) || (0, ElementHelper_1.isDtActionIgnore)(args[1])) {
32
+ return renderOriginal(args);
33
+ }
34
+ if ((0, JsxRuntimeHelpers_1.isFunctionalComponentType)(type)) {
35
+ return wrapFunctionalComponent(args);
36
+ }
37
+ if ((0, JsxRuntimeHelpers_1.isClassComponentType)(type)) {
38
+ return wrapClassComponent(args);
38
39
  }
39
- return ReactDevRuntime.jsxDEV(...args);
40
+ (0, ElementHelper_1.modifyElement)(type, args[1]);
41
+ return renderOriginal(args);
40
42
  };
41
43
  module.exports = Object.assign(Object.assign({}, ReactDevRuntime), { jsxDEV });
42
44
  }
43
- catch (error) {
45
+ catch (_error) {
44
46
  module.exports = {};
45
47
  }
@@ -1,40 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ReactRuntime = require("react/jsx-runtime");
4
- const Types_1 = require("../model/Types");
5
4
  const FunctionalComponent_1 = require("./components/FunctionalComponent");
6
5
  const ClassComponent_1 = require("./components/ClassComponent");
7
6
  const ElementHelper_1 = require("./ElementHelper");
7
+ const JsxRuntimeHelpers_1 = require("./JsxRuntimeHelpers");
8
+ const createWrapperProps = (jsxFunction, args) => (Object.assign(Object.assign({}, args[1]), { children: jsxFunction(...args) }));
9
+ const wrapWithComponent = (wrapperComponent, wrapperProps, args) => {
10
+ if ((0, JsxRuntimeHelpers_1.hasKey)(args)) {
11
+ return ReactRuntime.jsx(wrapperComponent, wrapperProps, args[2] + '_dt');
12
+ }
13
+ return ReactRuntime.jsx(wrapperComponent, wrapperProps);
14
+ };
15
+ const wrapFunctionalComponent = (jsxFunction, args) => {
16
+ const wrapperProps = createWrapperProps(jsxFunction, args);
17
+ wrapperProps.dtActionName =
18
+ args[1] !== undefined && args[1].dtActionName !== undefined
19
+ ? args[1].dtActionName
20
+ : args[0]._dtInfo.name;
21
+ return wrapWithComponent(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps, args);
22
+ };
23
+ const wrapClassComponent = (jsxFunction, args) => {
24
+ const wrapperProps = createWrapperProps(jsxFunction, args);
25
+ return wrapWithComponent(ClassComponent_1.DynatraceClassComponent, wrapperProps, args);
26
+ };
8
27
  const instrumentJsxCall = (jsxFunction) => (...args) => {
9
- if (args[0] !== undefined &&
10
- args[0]._dtInfo !== undefined &&
11
- !(0, ElementHelper_1.isDtActionIgnore)(args[1])) {
12
- if (args[0]._dtInfo.type === Types_1.Types.FunctionalComponent) {
13
- const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: jsxFunction(...args) });
14
- wrapperProps.dtActionName =
15
- args[1] !== undefined && args[1].dtActionName !== undefined
16
- ? args[1].dtActionName
17
- : args[0]._dtInfo.name;
18
- if (args[2] !== undefined) {
19
- return ReactRuntime.jsx(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps, args[2] + '_dt');
20
- }
21
- else {
22
- return ReactRuntime.jsx(FunctionalComponent_1.DynatraceFunctionalComponent, wrapperProps);
23
- }
24
- }
25
- else if (args[0]._dtInfo.type === Types_1.Types.ClassComponent &&
26
- args[0].prototype !== undefined &&
27
- args[0].prototype.isReactComponent !== undefined) {
28
- const wrapperProps = Object.assign(Object.assign({}, args[1]), { children: jsxFunction(...args) });
29
- if (args[2] !== undefined) {
30
- return ReactRuntime.jsx(ClassComponent_1.DynatraceClassComponent, wrapperProps, args[2] + '_dt');
31
- }
32
- else {
33
- return ReactRuntime.jsx(ClassComponent_1.DynatraceClassComponent, wrapperProps);
34
- }
35
- }
36
- (0, ElementHelper_1.modifyElement)(args[0], args[1]);
28
+ if (!(0, JsxRuntimeHelpers_1.isInstrumentedType)(args[0]) || (0, ElementHelper_1.isDtActionIgnore)(args[1])) {
29
+ return jsxFunction(...args);
30
+ }
31
+ if ((0, JsxRuntimeHelpers_1.isFunctionalComponentType)(args[0])) {
32
+ return wrapFunctionalComponent(jsxFunction, args);
33
+ }
34
+ if ((0, JsxRuntimeHelpers_1.isClassComponentType)(args[0])) {
35
+ return wrapClassComponent(jsxFunction, args);
37
36
  }
37
+ (0, ElementHelper_1.modifyElement)(args[0], args[1]);
38
38
  return jsxFunction(...args);
39
39
  };
40
40
  try {
@@ -43,6 +43,6 @@ try {
43
43
  module.exports = Object.assign(Object.assign({}, ReactRuntime), { jsx,
44
44
  jsxs });
45
45
  }
46
- catch (error) {
46
+ catch (_a) {
47
47
  module.exports = {};
48
48
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isClassComponentType = exports.isFunctionalComponentType = exports.isInstrumentedType = exports.hasKey = void 0;
4
+ const Types_1 = require("../model/Types");
5
+ const hasKey = (args) => args[2] !== undefined;
6
+ exports.hasKey = hasKey;
7
+ const isInstrumentedType = (type) => type !== undefined && type._dtInfo !== undefined;
8
+ exports.isInstrumentedType = isInstrumentedType;
9
+ const isFunctionalComponentType = (type) => type._dtInfo.type === Types_1.Types.FunctionalComponent;
10
+ exports.isFunctionalComponentType = isFunctionalComponentType;
11
+ const isClassComponentType = (type) => type._dtInfo.type === Types_1.Types.ClassComponent &&
12
+ type.prototype !== undefined &&
13
+ type.prototype.isReactComponent !== undefined;
14
+ exports.isClassComponentType = isClassComponentType;