@datadog/mobile-react-native 2.11.1 → 2.12.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.
- package/README.md +2 -2
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-sourcemaps.gradle +5 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +1 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/metro/plugin/debugIdHelper.js +4 -5
- package/lib/commonjs/metro/plugin/debugIdHelper.js.map +1 -1
- package/lib/commonjs/metro/plugin/metroSerializer.js +7 -11
- package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
- package/lib/commonjs/metro/plugin/utils.js +145 -66
- package/lib/commonjs/metro/plugin/utils.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +43 -21
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -2
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/ddBabelUtils.js +120 -0
- package/lib/commonjs/rum/instrumentation/interactionTracking/ddBabelUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +1 -0
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/metro/plugin/debugIdHelper.js +3 -3
- package/lib/module/metro/plugin/debugIdHelper.js.map +1 -1
- package/lib/module/metro/plugin/metroSerializer.js +6 -8
- package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
- package/lib/module/metro/plugin/utils.js +134 -60
- package/lib/module/metro/plugin/utils.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +43 -21
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -2
- package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/ddBabelUtils.js +113 -0
- package/lib/module/rum/instrumentation/interactionTracking/ddBabelUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/debugIdHelper.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/utils.d.ts +62 -11
- package/lib/typescript/metro/plugin/utils.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts +19 -5
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/ddBabelUtils.d.ts +9 -0
- package/lib/typescript/rum/instrumentation/interactionTracking/ddBabelUtils.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +2 -0
- package/src/index.tsx +3 -1
- package/src/metro/__tests__/__utils__/serializerUtils.ts +6 -4
- package/src/metro/__tests__/metro.test.ts +254 -0
- package/src/metro/metro.d.ts +4 -4
- package/src/metro/plugin/debugIdHelper.ts +3 -3
- package/src/metro/plugin/metroSerializer.ts +8 -9
- package/src/metro/plugin/utils.ts +189 -86
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +83 -33
- package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +2 -2
- package/src/rum/instrumentation/interactionTracking/ddBabelUtils.ts +146 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/utils/telemetry.js +0 -23
- package/lib/commonjs/utils/telemetry.js.map +0 -1
- package/lib/module/utils/telemetry.js +0 -16
- package/lib/module/utils/telemetry.js.map +0 -1
- package/lib/typescript/utils/telemetry.d.ts +0 -7
- package/lib/typescript/utils/telemetry.d.ts.map +0 -1
- package/src/utils/telemetry.ts +0 -17
|
@@ -1,30 +1,49 @@
|
|
|
1
|
+
import type baseJSBundle from 'metro/private/DeltaBundler/Serializers/baseJSBundle';
|
|
2
|
+
import type sourceMapString from 'metro/private/DeltaBundler/Serializers/sourceMapString';
|
|
3
|
+
import type bundleToString from 'metro/private/lib/bundleToString';
|
|
4
|
+
import type countLines from 'metro/private/lib/countLines';
|
|
1
5
|
import type CountingSet from 'metro/src/lib/CountingSet';
|
|
2
6
|
import type { ReadOnlyGraph, Module, MixedOutput } from 'metro';
|
|
3
7
|
import type { DefaultConfigOptions } from './types/expoTypes';
|
|
4
|
-
import type { MetroSerializerOutput, MetroBundleWithMap
|
|
8
|
+
import type { MetroSerializerOutput, MetroBundleWithMap } from './types/metroTypes';
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* https://github.com/facebook/metro/blob/76413561abb3757285e0cb0305f1f9f616fa2b6c/packages/metro/src/Server.js#L1086C1-L1095C7
|
|
10
|
+
* Safely loads and returns the `baseJSBundle` function from Metro's internal modules.
|
|
11
|
+
* Supports multiple Metro versions with different internal paths.
|
|
10
12
|
*/
|
|
11
|
-
export declare
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
export declare const getBaseJSBundleFunction: () => typeof baseJSBundle;
|
|
14
|
+
/**
|
|
15
|
+
* Safely loads and returns the `countLines` function from Metro's internal modules.
|
|
16
|
+
* Supports multiple Metro versions with different internal paths.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getCountLinesFunction: () => typeof countLines;
|
|
19
|
+
/**
|
|
20
|
+
* Safely loads and returns the `bundleToString` function from Metro's internal modules.
|
|
21
|
+
* Supports multiple Metro versions with different internal paths.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getBundleToStringFunction: () => typeof bundleToString;
|
|
14
24
|
/**
|
|
15
25
|
* CountingSet was added in Metro 0.71.2 - a modified `Set` that only deletes items when the
|
|
16
26
|
* number of `delete(item)` calls matches the number of `add(item)` calls.
|
|
17
27
|
*
|
|
18
28
|
* https://github.com/facebook/metro/commit/fc29a1177f883144674cf85a813b58567f69d545
|
|
19
29
|
*/
|
|
20
|
-
export declare const
|
|
30
|
+
export declare const getCreateCountingSetFunction: () => () => CountingSet<string>;
|
|
21
31
|
/**
|
|
22
32
|
* In Metro versions prior to v0.80.10, `sourceMapString` was exported as a default export.
|
|
23
33
|
* Starting with v0.80.10, it became a named export.
|
|
24
34
|
*
|
|
25
|
-
* @returns The resolved `sourceMapString` function, of type {@link
|
|
35
|
+
* @returns The resolved `sourceMapString` function, of type {@link sourceMapString}
|
|
36
|
+
*/
|
|
37
|
+
export declare const getSourceMapStringFunction: () => typeof sourceMapString;
|
|
38
|
+
/**
|
|
39
|
+
* This function ensures that modules in source maps are sorted in the same
|
|
40
|
+
* order as in a plain JS bundle.
|
|
41
|
+
*
|
|
42
|
+
* https://github.com/facebook/metro/blob/76413561abb3757285e0cb0305f1f9f616fa2b6c/packages/metro/src/Server.js#L1086C1-L1095C7
|
|
26
43
|
*/
|
|
27
|
-
export declare
|
|
44
|
+
export declare function getSortedModules(graph: ReadOnlyGraph, { createModuleId }: {
|
|
45
|
+
createModuleId: (file: string) => number;
|
|
46
|
+
}): readonly Module<MixedOutput>[];
|
|
28
47
|
/**
|
|
29
48
|
* Converts the serializer result of type {@link MetroSerializerOutput} to {@link MetroBundleWithMap}.
|
|
30
49
|
*/
|
|
@@ -33,4 +52,36 @@ export declare const convertSerializerOutput: (output: MetroSerializerOutput) =>
|
|
|
33
52
|
* Gets the default Expo configuration options.
|
|
34
53
|
*/
|
|
35
54
|
export declare const getDefaultExpoConfig: (projectRoot: string, options: DefaultConfigOptions) => DefaultConfigOptions;
|
|
55
|
+
/**
|
|
56
|
+
* Safely requires a module from multiple possible paths, returning its default export if found.
|
|
57
|
+
* Caches the result to avoid redundant requires.
|
|
58
|
+
* Useful for supporting multiple Metro versions with different internal paths.
|
|
59
|
+
* @param modulePaths The list of possible module paths to try.
|
|
60
|
+
* @returns the default export of the first successfully required module.
|
|
61
|
+
* @throws if none of the module paths could be resolved.
|
|
62
|
+
*/
|
|
63
|
+
export declare const lazyRequireDefaultExport: <T>(modulePaths: string[]) => T;
|
|
64
|
+
/**
|
|
65
|
+
* Safely requires a module from multiple possible paths, returning its default export if found.
|
|
66
|
+
* Caches the result to avoid redundant requires.
|
|
67
|
+
* Useful for supporting multiple Metro versions with different internal paths.
|
|
68
|
+
* @param modulePaths The list of possible module paths to try.
|
|
69
|
+
* @returns the default export of the first successfully required module, or `undefined` if none could be resolved.
|
|
70
|
+
*/
|
|
71
|
+
export declare const safeLazyRequireDefaultExport: <T>(modulePaths: string[]) => T | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Safely requires a module from multiple possible paths, returning its default export if found.
|
|
74
|
+
* Useful for supporting multiple Metro versions with different internal paths.
|
|
75
|
+
* @param modulePaths The list of possible module paths to try.
|
|
76
|
+
* @returns the default export of the first successfully required module, or `undefined` if none could be resolved.
|
|
77
|
+
*/
|
|
78
|
+
export declare function safeRequireDefaultExport<T>(modulePaths: string[]): T | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Safely extracts the default export from a module, if it exists.
|
|
81
|
+
* Useful for supporting both CommonJS and ESM-syntax exports.
|
|
82
|
+
* Supports upcoming Metro v0.83.2 https://github.com/facebook/metro/commit/5d301d7177af455fc6a94a0ba464639677cdf4b4.
|
|
83
|
+
*/
|
|
84
|
+
export declare function getDefaultExport<T>(module: {
|
|
85
|
+
default: T;
|
|
86
|
+
} | T): T | undefined;
|
|
36
87
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/metro/plugin/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/metro/plugin/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,YAAY,MAAM,qDAAqD,CAAC;AACpF,OAAO,KAAK,eAAe,MAAM,wDAAwD,CAAC;AAC1F,OAAO,KAAK,cAAc,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EACR,qBAAqB,EACrB,kBAAkB,EACrB,MAAM,oBAAoB,CAAC;AAY5B;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAO,mBAIrC,CAAC;AAEP;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAO,iBAInC,CAAC;AAEP;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QAAO,qBAIvC,CAAC;AAEP;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAM,MAAM,WAAW,CAAC,MAAM,CASxE,CAAC;AAYF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAO,sBA+B7C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,aAAa,EACpB,EAAE,cAAc,EAAE,EAAE;IAAE,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CAAE,GACjE,SAAS,MAAM,CAAC,WAAW,CAAC,EAAE,CAYhC;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,WACxB,qBAAqB,KAC9B,QAAQ,kBAAkB,CAqB5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,gBAChB,MAAM,WACV,oBAAoB,KAC9B,oBAcF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,mBAAoB,MAAM,EAAE,MAUhE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,mBACxB,MAAM,EAAE,kBAWxB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACtC,WAAW,EAAE,MAAM,EAAE,GACtB,CAAC,GAAG,SAAS,CAgBf;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAU7E"}
|
package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
+
import type { DdRum } from '../../DdRum';
|
|
1
2
|
import type { RumActionType } from '../../types';
|
|
2
3
|
type BabelConfig = {
|
|
3
4
|
trackInteractions: boolean;
|
|
4
5
|
useAccessibilityLabel: boolean;
|
|
5
6
|
};
|
|
6
7
|
type TargetObject = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
getContent: (() => string[]) | undefined;
|
|
9
|
+
options: {
|
|
10
|
+
useContent: boolean;
|
|
11
|
+
useNamePrefix: boolean;
|
|
12
|
+
};
|
|
13
|
+
handlerArgs: any[];
|
|
14
|
+
componentName: string;
|
|
15
|
+
'dd-action-name': string[];
|
|
16
|
+
accessibilityLabel: string[];
|
|
17
|
+
[key: string]: any;
|
|
11
18
|
};
|
|
12
19
|
export declare class DdBabelInteractionTracking {
|
|
13
20
|
private static instance;
|
|
14
21
|
static config: BabelConfig;
|
|
15
22
|
private timeProvider;
|
|
16
23
|
private telemetrySent;
|
|
24
|
+
private ddRum;
|
|
17
25
|
isInitialized: boolean;
|
|
18
26
|
private constructor();
|
|
19
|
-
static getInstance(): DdBabelInteractionTracking;
|
|
27
|
+
static getInstance(ddRum?: typeof DdRum): DdBabelInteractionTracking;
|
|
28
|
+
static getTelemetryConfig(): {
|
|
29
|
+
babel_plugin: {
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
track_interactions: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
20
34
|
private getTargetName;
|
|
21
35
|
wrapRumAction(func: (...args: any[]) => any, action: RumActionType, targetObject: TargetObject): (...args: any[]) => any;
|
|
22
36
|
}
|
package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DdBabelInteractionTracking.d.ts","sourceRoot":"","sources":["../../../../../src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DdBabelInteractionTracking.d.ts","sourceRoot":"","sources":["../../../../../src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQjD,KAAK,WAAW,GAAG;IACf,iBAAiB,EAAE,OAAO,CAAC;IAC3B,qBAAqB,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,UAAU,EAAE,CAAC,MAAM,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC;IACzC,OAAO,EAAE;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,aAAa,EAAE,OAAO,CAAA;KAAE,CAAC;IACzD,WAAW,EAAE,GAAG,EAAE,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB,CAAC;AAEF,qBAAa,0BAA0B;IACnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2C;IAElE,MAAM,CAAC,MAAM,EAAE,WAAW,CAGxB;IAEF,OAAO,CAAC,YAAY,CAA2C;IAE/D,OAAO,CAAC,aAAa,CAAkB;IAEvC,OAAO,CAAC,KAAK,CAA6B;IAE1C,aAAa,EAAE,OAAO,CAAS;IAE/B,OAAO;IAYP,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK;IAUvC,MAAM,CAAC,kBAAkB;;;;;;IAUzB,OAAO,CAAC,aAAa;IAqDrB,aAAa,CACT,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC7B,MAAM,EAAE,aAAa,EACrB,YAAY,EAAE,YAAY,GAC3B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;CAwC7B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts readable text from arbitrary values commonly found in React trees.
|
|
3
|
+
*
|
|
4
|
+
* @param node - Any value: primitives, arrays, iterables, functions, or React elements.
|
|
5
|
+
* @param prefer - Optional list of preferred values (e.g., title/label) to attempt first.
|
|
6
|
+
* @returns Array of strings.
|
|
7
|
+
*/
|
|
8
|
+
export declare function __ddExtractText(node: any, prefer?: any[]): string[];
|
|
9
|
+
//# sourceMappingURL=ddBabelUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ddBabelUtils.d.ts","sourceRoot":"","sources":["../../../../../src/rum/instrumentation/interactionTracking/ddBabelUtils.ts"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,CA4HnE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.12.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.1",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"dependencies": {
|
|
119
119
|
"big-integer": "^1.6.52"
|
|
120
120
|
},
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "5bc4b0ee2893f83f53aba08337765b4e0d9748e3"
|
|
122
122
|
}
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -367,6 +367,8 @@ export class DdSdkReactNative {
|
|
|
367
367
|
trackInteractions: configuration.trackInteractions,
|
|
368
368
|
useAccessibilityLabel: configuration.useAccessibilityLabel
|
|
369
369
|
};
|
|
370
|
+
|
|
371
|
+
DdBabelInteractionTracking.getInstance(DdRum);
|
|
370
372
|
}
|
|
371
373
|
|
|
372
374
|
if (DdSdkReactNative.wasAutoInstrumented) {
|
package/src/index.tsx
CHANGED
|
@@ -24,6 +24,7 @@ import { TrackingConsent } from './TrackingConsent';
|
|
|
24
24
|
import { DdLogs } from './logs/DdLogs';
|
|
25
25
|
import { DdRum } from './rum/DdRum';
|
|
26
26
|
import { DdBabelInteractionTracking } from './rum/instrumentation/interactionTracking/DdBabelInteractionTracking';
|
|
27
|
+
import { __ddExtractText } from './rum/instrumentation/interactionTracking/ddBabelUtils';
|
|
27
28
|
import { DatadogTracingContext } from './rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingContext';
|
|
28
29
|
import { DatadogTracingIdentifier } from './rum/instrumentation/resourceTracking/distributedTracing/DatadogTracingIdentifier';
|
|
29
30
|
import {
|
|
@@ -77,7 +78,8 @@ export {
|
|
|
77
78
|
TracingIdFormat,
|
|
78
79
|
DatadogTracingIdentifier,
|
|
79
80
|
DatadogTracingContext,
|
|
80
|
-
DdBabelInteractionTracking
|
|
81
|
+
DdBabelInteractionTracking,
|
|
82
|
+
__ddExtractText
|
|
81
83
|
};
|
|
82
84
|
export type {
|
|
83
85
|
Timestamp,
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
|
-
import countLines from 'metro/src/lib/countLines';
|
|
9
|
-
|
|
10
7
|
import type {
|
|
11
8
|
MetroSerializer,
|
|
12
9
|
MixedOutput,
|
|
13
10
|
Module,
|
|
14
11
|
MetroVirtualModuleOutput
|
|
15
12
|
} from '../../plugin/types/metroTypes';
|
|
16
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
getCreateCountingSetFunction,
|
|
15
|
+
getCountLinesFunction
|
|
16
|
+
} from '../../plugin/utils';
|
|
17
17
|
|
|
18
18
|
export const mockSerializerArgsForEmptyModule = (): Parameters<MetroSerializer> => {
|
|
19
19
|
return [
|
|
@@ -48,6 +48,8 @@ export const mockSerializerArgsForEmptyModule = (): Parameters<MetroSerializer>
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export const mockSerializerArgsForSourceMappingURLModule = (): Parameters<MetroSerializer> => {
|
|
51
|
+
const countLines = getCountLinesFunction();
|
|
52
|
+
const createCountingSet = getCreateCountingSetFunction();
|
|
51
53
|
const mockedCode = '//# sourceMappingURL=index.android.bundle.map';
|
|
52
54
|
return [
|
|
53
55
|
'index.js',
|
|
@@ -27,6 +27,10 @@ const DEBUG_ID_CODE_SNIPPET =
|
|
|
27
27
|
'var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds&&(_datadogDebugIds={});try{var stack=(new Error).stack;stack&&(_datadogDebugIds[stack]="__datadog_debug_id_placeholder__",_datadogDebugIdMeta="datadog-debug-id-__datadog_debug_id_placeholder__")}catch(e){}';
|
|
28
28
|
|
|
29
29
|
describe('Datadog Metro Plugin', () => {
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
jest.resetModules();
|
|
32
|
+
});
|
|
33
|
+
|
|
30
34
|
describe('Datadog Metro Serializer', () => {
|
|
31
35
|
test('generates bundle and source map with UUID v5 Debug ID', async () => {
|
|
32
36
|
const codeSnippetHash = createHash('md5');
|
|
@@ -404,4 +408,254 @@ describe('Datadog Metro Plugin', () => {
|
|
|
404
408
|
expect(result.map).toBe('{"testMap":"test"}');
|
|
405
409
|
});
|
|
406
410
|
});
|
|
411
|
+
|
|
412
|
+
describe('Import Utils', () => {
|
|
413
|
+
test('M getDefaultExport extracts the default export if it exists', () => {
|
|
414
|
+
// GIVEN
|
|
415
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
416
|
+
const getDefaultExport = require('../plugin/utils')
|
|
417
|
+
.getDefaultExport;
|
|
418
|
+
|
|
419
|
+
const exampleModuleWithDefault = {
|
|
420
|
+
default: 'default export',
|
|
421
|
+
namedExport: 'named export'
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// WHEN
|
|
425
|
+
const result = getDefaultExport(exampleModuleWithDefault);
|
|
426
|
+
|
|
427
|
+
// THEN
|
|
428
|
+
expect(result).toBe('default export');
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test('M getDefaultExport returns the module as it is if default does not exist', () => {
|
|
432
|
+
// GIVEN
|
|
433
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
434
|
+
const getDefaultExport = require('../plugin/utils')
|
|
435
|
+
.getDefaultExport;
|
|
436
|
+
|
|
437
|
+
const exampleModule1 = {
|
|
438
|
+
namedExport: 'named export'
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
const exampleModule2 = 'just a string';
|
|
442
|
+
|
|
443
|
+
// WHEN
|
|
444
|
+
const result1 = getDefaultExport(exampleModule1);
|
|
445
|
+
const result2 = getDefaultExport(exampleModule2);
|
|
446
|
+
|
|
447
|
+
// THEN
|
|
448
|
+
expect(result1).toEqual({ namedExport: 'named export' });
|
|
449
|
+
expect(result2).toBe('just a string');
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test('M getDefaultExport returns undefined if the module is null or undefined', () => {
|
|
453
|
+
// GIVEN
|
|
454
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
455
|
+
const getDefaultExport = require('../plugin/utils')
|
|
456
|
+
.getDefaultExport;
|
|
457
|
+
|
|
458
|
+
const exampleModule1 = null;
|
|
459
|
+
const exampleModule2 = undefined;
|
|
460
|
+
|
|
461
|
+
// WHEN
|
|
462
|
+
const result1 = getDefaultExport(exampleModule1);
|
|
463
|
+
const result2 = getDefaultExport(exampleModule2);
|
|
464
|
+
|
|
465
|
+
// THEN
|
|
466
|
+
expect(result1).toBeUndefined();
|
|
467
|
+
expect(result2).toBeUndefined();
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test('M createCountingSet correctly imports function from metro/src when metro/private is not available', () => {
|
|
471
|
+
// GIVEN
|
|
472
|
+
jest.isolateModules(() => {
|
|
473
|
+
// GIVEN
|
|
474
|
+
jest.doMock('metro/private/lib/CountingSet', () => {
|
|
475
|
+
throw new Error('Module not found');
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
jest.doMock(
|
|
479
|
+
'metro/src/lib/CountingSet',
|
|
480
|
+
() => ({
|
|
481
|
+
default: class CountingSetMock {
|
|
482
|
+
test: string = 'constructor_not_called';
|
|
483
|
+
constructor() {
|
|
484
|
+
this.test = 'constructor_called';
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}),
|
|
488
|
+
{ virtual: true }
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
// WHEN
|
|
492
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
493
|
+
const utils = require('../plugin/utils');
|
|
494
|
+
const createCountingSet = utils.getCreateCountingSetFunction();
|
|
495
|
+
const result = createCountingSet();
|
|
496
|
+
|
|
497
|
+
// THEN
|
|
498
|
+
expect(result).toHaveProperty('test');
|
|
499
|
+
expect(result.test).toBe('constructor_called');
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
test('M sourcemapString correctly imports function from metro/src when metro/private is not available', () => {
|
|
504
|
+
// GIVEN
|
|
505
|
+
jest.isolateModules(() => {
|
|
506
|
+
// GIVEN
|
|
507
|
+
jest.doMock(
|
|
508
|
+
'metro/private/DeltaBundler/Serializers/sourceMapString',
|
|
509
|
+
() => {
|
|
510
|
+
throw new Error('Module not found');
|
|
511
|
+
}
|
|
512
|
+
);
|
|
513
|
+
|
|
514
|
+
jest.doMock(
|
|
515
|
+
'metro/src/DeltaBundler/Serializers/sourceMapString',
|
|
516
|
+
() => ({
|
|
517
|
+
default: (
|
|
518
|
+
modules: unknown[],
|
|
519
|
+
options: object
|
|
520
|
+
): string =>
|
|
521
|
+
`test-modules_length:${
|
|
522
|
+
modules.length
|
|
523
|
+
},options_keys:${Object.keys(options).length}`
|
|
524
|
+
}),
|
|
525
|
+
{ virtual: true }
|
|
526
|
+
);
|
|
527
|
+
|
|
528
|
+
// WHEN
|
|
529
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
530
|
+
const utils = require('../plugin/utils');
|
|
531
|
+
const metroSourceMapString = utils.getSourceMapStringFunction();
|
|
532
|
+
const result = metroSourceMapString([{}, {}, {}], {
|
|
533
|
+
excludeSource: true,
|
|
534
|
+
shouldAddToIgnoreList: () => true
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// THEN
|
|
538
|
+
expect(result).toBe('test-modules_length:3,options_keys:2');
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
test('M sourcemapString returns the correct function when retrieved as named export', () => {
|
|
543
|
+
// GIVEN
|
|
544
|
+
jest.isolateModules(() => {
|
|
545
|
+
// GIVEN
|
|
546
|
+
jest.doMock(
|
|
547
|
+
'metro/private/DeltaBundler/Serializers/sourceMapString',
|
|
548
|
+
() => ({
|
|
549
|
+
sourceMapString: (
|
|
550
|
+
modules: unknown[],
|
|
551
|
+
options: object
|
|
552
|
+
): string =>
|
|
553
|
+
`test-modules_length:${
|
|
554
|
+
modules.length
|
|
555
|
+
},options_keys:${Object.keys(options).length}`
|
|
556
|
+
})
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
// WHEN
|
|
560
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
561
|
+
const utils = require('../plugin/utils');
|
|
562
|
+
const metroSourceMapString = utils.getSourceMapStringFunction();
|
|
563
|
+
const result = metroSourceMapString([{}, {}, {}], {
|
|
564
|
+
excludeSource: true,
|
|
565
|
+
shouldAddToIgnoreList: () => true
|
|
566
|
+
});
|
|
567
|
+
// THEN
|
|
568
|
+
expect(result).toBe('test-modules_length:3,options_keys:2');
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test('M sourcemapString returns the correct function when retrieved as default export', () => {
|
|
573
|
+
// GIVEN
|
|
574
|
+
jest.isolateModules(() => {
|
|
575
|
+
// GIVEN
|
|
576
|
+
jest.doMock(
|
|
577
|
+
'metro/private/DeltaBundler/Serializers/sourceMapString',
|
|
578
|
+
() => ({
|
|
579
|
+
default: (
|
|
580
|
+
modules: unknown[],
|
|
581
|
+
options: object
|
|
582
|
+
): string =>
|
|
583
|
+
`test-modules_length:${
|
|
584
|
+
modules.length
|
|
585
|
+
},options_keys:${Object.keys(options).length}`
|
|
586
|
+
})
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
// WHEN
|
|
590
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
591
|
+
const utils = require('../plugin/utils');
|
|
592
|
+
const metroSourceMapString = utils.getSourceMapStringFunction();
|
|
593
|
+
const result = metroSourceMapString([{}, {}, {}], {
|
|
594
|
+
excludeSource: true,
|
|
595
|
+
shouldAddToIgnoreList: () => true
|
|
596
|
+
});
|
|
597
|
+
// THEN
|
|
598
|
+
expect(result).toBe('test-modules_length:3,options_keys:2');
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test('M getBaseJSBundle correctly imports function from metro/src when metro/private is not available', () => {
|
|
603
|
+
// GIVEN
|
|
604
|
+
jest.isolateModules(() => {
|
|
605
|
+
// GIVEN
|
|
606
|
+
jest.doMock(
|
|
607
|
+
'metro/private/DeltaBundler/Serializers/baseJSBundle',
|
|
608
|
+
() => {
|
|
609
|
+
throw new Error('Module not found');
|
|
610
|
+
}
|
|
611
|
+
);
|
|
612
|
+
|
|
613
|
+
jest.doMock(
|
|
614
|
+
'metro/src/DeltaBundler/Serializers/baseJSBundle',
|
|
615
|
+
() => () => ({
|
|
616
|
+
test: 'ok'
|
|
617
|
+
}),
|
|
618
|
+
{ virtual: true }
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
// WHEN
|
|
622
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
623
|
+
const utils = require('../plugin/utils');
|
|
624
|
+
const baseJSBundle = utils.getBaseJSBundleFunction();
|
|
625
|
+
const result = baseJSBundle();
|
|
626
|
+
|
|
627
|
+
// THEN
|
|
628
|
+
expect(result).toHaveProperty('test');
|
|
629
|
+
expect(result.test).toBe('ok');
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
test('M getCountLines correctly imports function from metro/src when metro/private is not available', () => {
|
|
634
|
+
// GIVEN
|
|
635
|
+
jest.isolateModules(() => {
|
|
636
|
+
// GIVEN
|
|
637
|
+
jest.doMock('metro/private/lib/countLines', () => {
|
|
638
|
+
throw new Error('Module not found');
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
// Random int between 10 and 100 to ensure the mock is used
|
|
642
|
+
const randomInt = Math.floor(Math.random() * 90) + 10;
|
|
643
|
+
|
|
644
|
+
jest.doMock(
|
|
645
|
+
'metro/src/lib/countLines',
|
|
646
|
+
() => (str: string): number => str.length + randomInt,
|
|
647
|
+
{ virtual: true }
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
// WHEN
|
|
651
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
652
|
+
const utils = require('../plugin/utils');
|
|
653
|
+
const getCountLines = utils.getCountLinesFunction();
|
|
654
|
+
const result = getCountLines('test-string');
|
|
655
|
+
|
|
656
|
+
// THEN
|
|
657
|
+
expect(result).toBe('test-string'.length + randomInt);
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
});
|
|
407
661
|
});
|
package/src/metro/metro.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ declare type Bundle = {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/DeltaBundler/Serializers/baseJSBundle.js#L25
|
|
31
|
-
declare module 'metro/
|
|
31
|
+
declare module 'metro/private/DeltaBundler/Serializers/baseJSBundle' {
|
|
32
32
|
const baseJSBundle: (
|
|
33
33
|
entryPoint: string,
|
|
34
34
|
preModules: ReadonlyArray<Module>,
|
|
@@ -39,7 +39,7 @@ declare module 'metro/src/DeltaBundler/Serializers/baseJSBundle' {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/lib/bundleToString.js#L22
|
|
42
|
-
declare module 'metro/
|
|
42
|
+
declare module 'metro/private/lib/bundleToString' {
|
|
43
43
|
const bundleToString: (
|
|
44
44
|
bundle: Bundle
|
|
45
45
|
) => {
|
|
@@ -51,7 +51,7 @@ declare module 'metro/src/lib/bundleToString' {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js#L22
|
|
54
|
-
declare module 'metro/
|
|
54
|
+
declare module 'metro/private/DeltaBundler/Serializers/sourceMapString' {
|
|
55
55
|
import type { MixedOutput, Module } from 'metro';
|
|
56
56
|
|
|
57
57
|
const sourceMapString: (
|
|
@@ -67,7 +67,7 @@ declare module 'metro/src/DeltaBundler/Serializers/sourceMapString' {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/lib/countLines.js#L16
|
|
70
|
-
declare module 'metro/
|
|
70
|
+
declare module 'metro/private/lib/countLines' {
|
|
71
71
|
const countLines: (code: string) => number;
|
|
72
72
|
export = countLines;
|
|
73
73
|
}
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
import { createHash } from 'crypto';
|
|
11
11
|
import { existsSync, mkdirSync, writeFileSync, unlinkSync } from 'fs';
|
|
12
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
13
|
-
import countLines from 'metro/src/lib/countLines';
|
|
14
12
|
import path from 'path';
|
|
15
13
|
|
|
16
14
|
import type {
|
|
@@ -20,7 +18,7 @@ import type {
|
|
|
20
18
|
MetroBundleWithMap,
|
|
21
19
|
DatadogDebugIdModule
|
|
22
20
|
} from './types/metroTypes';
|
|
23
|
-
import {
|
|
21
|
+
import { getCreateCountingSetFunction, getCountLinesFunction } from './utils';
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
24
|
* Regex to match the Debug ID comment in the bundle.
|
|
@@ -63,6 +61,8 @@ const DEBUG_ID_METADATA_PREFIX = 'datadog-debug-id-';
|
|
|
63
61
|
*/
|
|
64
62
|
export const createDebugIdModule = (debugId: string): DatadogDebugIdModule => {
|
|
65
63
|
let debugIdCode = createDebugIdSnippet(debugId);
|
|
64
|
+
const countLines = getCountLinesFunction();
|
|
65
|
+
const createCountingSet = getCreateCountingSetFunction();
|
|
66
66
|
|
|
67
67
|
return {
|
|
68
68
|
setSource: (code: string) => {
|
|
@@ -6,12 +6,6 @@
|
|
|
6
6
|
* Portions of this code are adapted from Sentry's Metro configuration:
|
|
7
7
|
* https://github.com/getsentry/sentry-react-native/blob/17c0c2e8913030e4826d055284a735efad637312/packages/core/src/js/tools/sentryMetroSerializer.ts
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
|
-
import baseJSBundle from 'metro/src/DeltaBundler/Serializers/baseJSBundle';
|
|
12
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
13
|
-
import bundleToString from 'metro/src/lib/bundleToString';
|
|
14
|
-
|
|
15
9
|
import {
|
|
16
10
|
DEBUG_ID_PLACEHOLDER,
|
|
17
11
|
addDebugIdModule,
|
|
@@ -32,9 +26,11 @@ import type {
|
|
|
32
26
|
ReadOnlyGraph
|
|
33
27
|
} from './types/metroTypes';
|
|
34
28
|
import {
|
|
29
|
+
getBaseJSBundleFunction,
|
|
30
|
+
getBundleToStringFunction,
|
|
35
31
|
convertSerializerOutput as getMetroBundleWithMap,
|
|
36
32
|
getSortedModules,
|
|
37
|
-
|
|
33
|
+
getSourceMapStringFunction
|
|
38
34
|
} from './utils';
|
|
39
35
|
|
|
40
36
|
/**
|
|
@@ -105,8 +101,9 @@ export const createDatadogMetroSerializer = (
|
|
|
105
101
|
*/
|
|
106
102
|
export const createDefaultMetroSerializer = (): MetroSerializer => {
|
|
107
103
|
return (entryPoint, preModules, graph, options) => {
|
|
108
|
-
//
|
|
104
|
+
// Creates the default metro bundle
|
|
109
105
|
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/DeltaBundler/Serializers/baseJSBundle.js#L25
|
|
106
|
+
const baseJSBundle = getBaseJSBundleFunction();
|
|
110
107
|
let bundle = baseJSBundle(entryPoint, preModules, graph, options);
|
|
111
108
|
|
|
112
109
|
// Modify the bundle through the datadogBundleCallback, if we are not in hot-reload mode
|
|
@@ -118,6 +115,7 @@ export const createDefaultMetroSerializer = (): MetroSerializer => {
|
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
// Retrieves the processed code from the bundle
|
|
118
|
+
const bundleToString = getBundleToStringFunction();
|
|
121
119
|
const { code } = bundleToString(bundle);
|
|
122
120
|
|
|
123
121
|
// If we are in hot-reload mode, we skip sourcemaps generation, and only return the code.
|
|
@@ -126,7 +124,8 @@ export const createDefaultMetroSerializer = (): MetroSerializer => {
|
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
// Force generation of sourcemaps
|
|
129
|
-
const
|
|
127
|
+
const sourceMapString = getSourceMapStringFunction();
|
|
128
|
+
const map = sourceMapString(
|
|
130
129
|
[...preModules, ...getSortedModules(graph, options)],
|
|
131
130
|
{
|
|
132
131
|
processModuleFilter: options.processModuleFilter,
|