@datadog/mobile-react-native 2.8.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +15 -4
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-sourcemaps.gradle +101 -3
- package/ios/Sources/DdSdk.mm +4 -1
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/metro/debugIdResolver.js +35 -0
- package/lib/commonjs/metro/debugIdResolver.js.map +1 -0
- package/lib/commonjs/metro/metro.d.js +2 -0
- package/lib/commonjs/metro/metro.d.js.map +1 -0
- package/lib/commonjs/metro/plugin/debugIdHelper.js +244 -0
- package/lib/commonjs/metro/plugin/debugIdHelper.js.map +1 -0
- package/lib/commonjs/metro/plugin/metroConfig.js +68 -0
- package/lib/commonjs/metro/plugin/metroConfig.js.map +1 -0
- package/lib/commonjs/metro/plugin/metroSerializer.js +143 -0
- package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -0
- package/lib/commonjs/metro/plugin/types/expoTypes.js +6 -0
- package/lib/commonjs/metro/plugin/types/expoTypes.js.map +1 -0
- package/lib/commonjs/metro/plugin/types/metroTypes.js +6 -0
- package/lib/commonjs/metro/plugin/types/metroTypes.js.map +1 -0
- package/lib/commonjs/metro/plugin/utils.js +153 -0
- package/lib/commonjs/metro/plugin/utils.js.map +1 -0
- package/lib/commonjs/metro.js +19 -0
- package/lib/commonjs/metro.js.map +1 -0
- package/lib/commonjs/rum/DdRum.js +2 -1
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/utils/errorUtils.js +13 -1
- package/lib/commonjs/utils/errorUtils.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/metro/debugIdResolver.js +30 -0
- package/lib/module/metro/debugIdResolver.js.map +1 -0
- package/lib/module/metro/metro.d.js +2 -0
- package/lib/module/metro/metro.d.js.map +1 -0
- package/lib/module/metro/plugin/debugIdHelper.js +225 -0
- package/lib/module/metro/plugin/debugIdHelper.js.map +1 -0
- package/lib/module/metro/plugin/metroConfig.js +61 -0
- package/lib/module/metro/plugin/metroConfig.js.map +1 -0
- package/lib/module/metro/plugin/metroSerializer.js +131 -0
- package/lib/module/metro/plugin/metroSerializer.js.map +1 -0
- package/lib/module/metro/plugin/types/expoTypes.js +2 -0
- package/lib/module/metro/plugin/types/expoTypes.js.map +1 -0
- package/lib/module/metro/plugin/types/metroTypes.js +2 -0
- package/lib/module/metro/plugin/types/metroTypes.js.map +1 -0
- package/lib/module/metro/plugin/utils.js +139 -0
- package/lib/module/metro/plugin/utils.js.map +1 -0
- package/lib/module/metro.js +8 -0
- package/lib/module/metro.js.map +1 -0
- package/lib/module/rum/DdRum.js +2 -1
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +2 -2
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/utils/errorUtils.js +11 -0
- package/lib/module/utils/errorUtils.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/metro/debugIdResolver.d.ts +3 -0
- package/lib/typescript/metro/debugIdResolver.d.ts.map +1 -0
- package/lib/typescript/metro/plugin/debugIdHelper.d.ts +99 -0
- package/lib/typescript/metro/plugin/debugIdHelper.d.ts.map +1 -0
- package/lib/typescript/metro/plugin/metroConfig.d.ts +35 -0
- package/lib/typescript/metro/plugin/metroConfig.d.ts.map +1 -0
- package/lib/typescript/metro/plugin/metroSerializer.d.ts +29 -0
- package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -0
- package/lib/typescript/metro/plugin/types/expoTypes.d.ts +31 -0
- package/lib/typescript/metro/plugin/types/expoTypes.d.ts.map +1 -0
- package/lib/typescript/metro/plugin/types/metroTypes.d.ts +33 -0
- package/lib/typescript/metro/plugin/types/metroTypes.d.ts.map +1 -0
- package/lib/typescript/metro/plugin/utils.d.ts +36 -0
- package/lib/typescript/metro/plugin/utils.d.ts.map +1 -0
- package/lib/typescript/metro.d.ts +6 -0
- package/lib/typescript/metro.d.ts.map +1 -0
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts.map +1 -1
- package/lib/typescript/utils/errorUtils.d.ts +1 -0
- package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +17 -3
- package/scripts/copy-debug-id.js +52 -0
- package/src/metro/__tests__/__utils__/serializerUtils.ts +100 -0
- package/src/metro/__tests__/metro.test.ts +382 -0
- package/src/metro/debugIdResolver.ts +36 -0
- package/src/metro/metro.d.ts +73 -0
- package/src/metro/plugin/debugIdHelper.ts +279 -0
- package/src/metro/plugin/metroConfig.ts +97 -0
- package/src/metro/plugin/metroSerializer.ts +173 -0
- package/src/metro/plugin/types/expoTypes.ts +64 -0
- package/src/metro/plugin/types/metroTypes.ts +94 -0
- package/src/metro/plugin/utils.ts +177 -0
- package/src/metro.ts +14 -0
- package/src/rum/DdRum.ts +2 -1
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +8 -2
- package/src/utils/errorUtils.ts +13 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
|
+
import countLines from 'metro/src/lib/countLines';
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
MetroSerializer,
|
|
12
|
+
MixedOutput,
|
|
13
|
+
Module,
|
|
14
|
+
MetroVirtualModuleOutput
|
|
15
|
+
} from '../../plugin/types/metroTypes';
|
|
16
|
+
import { createCountingSet } from '../../plugin/utils';
|
|
17
|
+
|
|
18
|
+
export const mockSerializerArgsForEmptyModule = (): Parameters<MetroSerializer> => {
|
|
19
|
+
return [
|
|
20
|
+
'index.js',
|
|
21
|
+
[],
|
|
22
|
+
{
|
|
23
|
+
entryPoints: new Set(),
|
|
24
|
+
dependencies: new Map(),
|
|
25
|
+
transformOptions: {
|
|
26
|
+
hot: false,
|
|
27
|
+
dev: false,
|
|
28
|
+
minify: false,
|
|
29
|
+
type: 'script',
|
|
30
|
+
unstable_transformProfile: 'hermes-stable'
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
asyncRequireModulePath: 'asyncRequire',
|
|
35
|
+
createModuleId: (_filePath: string): number => 0,
|
|
36
|
+
dev: false,
|
|
37
|
+
getRunModuleStatement: (_moduleId: string | number): string => '',
|
|
38
|
+
includeAsyncPaths: false,
|
|
39
|
+
modulesOnly: false,
|
|
40
|
+
processModuleFilter: (_module: Module<MixedOutput>) => true,
|
|
41
|
+
projectRoot: '/project/root',
|
|
42
|
+
runBeforeMainModule: [],
|
|
43
|
+
runModule: false,
|
|
44
|
+
serverRoot: '/server/root',
|
|
45
|
+
shouldAddToIgnoreList: (_module: Module<MixedOutput>) => false
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const mockSerializerArgsForSourceMappingURLModule = (): Parameters<MetroSerializer> => {
|
|
51
|
+
const mockedCode = '//# sourceMappingURL=index.android.bundle.map';
|
|
52
|
+
return [
|
|
53
|
+
'index.js',
|
|
54
|
+
[
|
|
55
|
+
<Module<MetroVirtualModuleOutput>>{
|
|
56
|
+
dependencies: new Map(),
|
|
57
|
+
inverseDependencies: createCountingSet(),
|
|
58
|
+
output: [
|
|
59
|
+
{
|
|
60
|
+
type: 'js/script/virtual',
|
|
61
|
+
data: {
|
|
62
|
+
code: mockedCode,
|
|
63
|
+
lineCount: countLines(mockedCode),
|
|
64
|
+
map: []
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
path: 'index.js',
|
|
69
|
+
getSource: () => {
|
|
70
|
+
return Buffer.from(mockedCode, 'utf-8');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
{
|
|
75
|
+
entryPoints: new Set(),
|
|
76
|
+
dependencies: new Map(),
|
|
77
|
+
transformOptions: {
|
|
78
|
+
hot: false,
|
|
79
|
+
dev: false,
|
|
80
|
+
minify: false,
|
|
81
|
+
type: 'script',
|
|
82
|
+
unstable_transformProfile: 'hermes-stable'
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
asyncRequireModulePath: 'asyncRequire',
|
|
87
|
+
createModuleId: (_filePath: string): number => 0,
|
|
88
|
+
dev: false,
|
|
89
|
+
getRunModuleStatement: (_moduleId: string | number): string => '',
|
|
90
|
+
includeAsyncPaths: false,
|
|
91
|
+
modulesOnly: false,
|
|
92
|
+
processModuleFilter: (_module: Module<MixedOutput>) => true,
|
|
93
|
+
projectRoot: '/project/root',
|
|
94
|
+
runBeforeMainModule: [],
|
|
95
|
+
runModule: false,
|
|
96
|
+
serverRoot: '/server/root',
|
|
97
|
+
shouldAddToIgnoreList: (_module: Module<MixedOutput>) => false
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
};
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
import { createHash } from 'crypto';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
createDebugIdFromString,
|
|
10
|
+
_replaceDebugIdInBundle,
|
|
11
|
+
_insertDebugIdCommentInBundle,
|
|
12
|
+
_isDebugIdInBundle,
|
|
13
|
+
getDebugIdFromBundleSource
|
|
14
|
+
} from '../plugin/debugIdHelper';
|
|
15
|
+
import { createDatadogMetroSerializer } from '../plugin/metroSerializer';
|
|
16
|
+
import type { MetroSerializerOutput } from '../plugin/types/metroTypes';
|
|
17
|
+
import { convertSerializerOutput } from '../plugin/utils';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
mockSerializerArgsForEmptyModule,
|
|
21
|
+
mockSerializerArgsForSourceMappingURLModule
|
|
22
|
+
} from './__utils__/serializerUtils';
|
|
23
|
+
|
|
24
|
+
const DEBUG_ID_CODE_SNIPPET =
|
|
25
|
+
'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){}';
|
|
26
|
+
|
|
27
|
+
describe('Datadog Metro Plugin', () => {
|
|
28
|
+
describe('Datadog Metro Serializer', () => {
|
|
29
|
+
test('generates bundle and source map with UUID v5 Debug ID', async () => {
|
|
30
|
+
const codeSnippetHash = createHash('md5');
|
|
31
|
+
codeSnippetHash.update(DEBUG_ID_CODE_SNIPPET);
|
|
32
|
+
const expectedDebugId = createDebugIdFromString(
|
|
33
|
+
codeSnippetHash.digest('hex')
|
|
34
|
+
);
|
|
35
|
+
const serializer = createDatadogMetroSerializer();
|
|
36
|
+
|
|
37
|
+
const bundle = await serializer(
|
|
38
|
+
...mockSerializerArgsForEmptyModule()
|
|
39
|
+
);
|
|
40
|
+
if (typeof bundle === 'string') {
|
|
41
|
+
fail('Expected bundle to be an object with a "code" property');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const expectedCode = DEBUG_ID_CODE_SNIPPET.replaceAll(
|
|
45
|
+
'__datadog_debug_id_placeholder__',
|
|
46
|
+
expectedDebugId
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(bundle.code).toEqual(
|
|
50
|
+
`${expectedCode}\n//# debugId=${expectedDebugId}`
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const expectedMap = `{"version":3,"sources":["__datadog_debugid__"],"sourcesContent":["var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds&&(_datadogDebugIds={});try{var stack=(new Error).stack;stack&&(_datadogDebugIds[stack]=\\"${expectedDebugId}\\",_datadogDebugIdMeta=\\"datadog-debug-id-${expectedDebugId}\\")}catch(e){}"],"names":[],"mappings":"","debugId":"${expectedDebugId}"}`;
|
|
54
|
+
expect(bundle.map).toEqual(expectedMap);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('debug ID comment is placed before sourceMappingURL in bundle', async () => {
|
|
58
|
+
const sourceMappingComment =
|
|
59
|
+
'//# sourceMappingURL=index.android.bundle.map';
|
|
60
|
+
const codeSnippetHash = createHash('md5');
|
|
61
|
+
codeSnippetHash.update(
|
|
62
|
+
`${DEBUG_ID_CODE_SNIPPET}\n${sourceMappingComment}`
|
|
63
|
+
);
|
|
64
|
+
const expectedDebugId = createDebugIdFromString(
|
|
65
|
+
codeSnippetHash.digest('hex')
|
|
66
|
+
);
|
|
67
|
+
const serializer = createDatadogMetroSerializer();
|
|
68
|
+
|
|
69
|
+
const bundle = await serializer(
|
|
70
|
+
...mockSerializerArgsForSourceMappingURLModule()
|
|
71
|
+
);
|
|
72
|
+
if (typeof bundle === 'string') {
|
|
73
|
+
fail('Expected bundle to be an object with a "code" property');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const expectedCode = [
|
|
77
|
+
DEBUG_ID_CODE_SNIPPET.replaceAll(
|
|
78
|
+
'__datadog_debug_id_placeholder__',
|
|
79
|
+
expectedDebugId
|
|
80
|
+
),
|
|
81
|
+
`//# debugId=${expectedDebugId}`,
|
|
82
|
+
sourceMappingComment
|
|
83
|
+
].join('\n');
|
|
84
|
+
|
|
85
|
+
expect(bundle.code).toEqual(expectedCode);
|
|
86
|
+
|
|
87
|
+
const expectedMap = `{"version":3,"sources":["__datadog_debugid__","index.js"],"sourcesContent":["var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds&&(_datadogDebugIds={});try{var stack=(new Error).stack;stack&&(_datadogDebugIds[stack]=\\"${expectedDebugId}\\",_datadogDebugIdMeta=\\"datadog-debug-id-${expectedDebugId}\\")}catch(e){}","//# sourceMappingURL=index.android.bundle.map"],"names":[],"mappings":"","debugId":"${expectedDebugId}"}`;
|
|
88
|
+
expect(bundle.map).toEqual(expectedMap);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('Debug ID Helper', () => {
|
|
93
|
+
test('M createDebugIdFromString generates same UUID v5 Debug ID for same string', async () => {
|
|
94
|
+
for (let i = 0; i < 100; i++) {
|
|
95
|
+
const randomStr = `test-${Math.random()
|
|
96
|
+
.toString(36)
|
|
97
|
+
.substring(2, 15)}`;
|
|
98
|
+
const debugId1 = createDebugIdFromString(randomStr);
|
|
99
|
+
const debugId2 = createDebugIdFromString(randomStr);
|
|
100
|
+
expect(debugId1).toMatch(debugId2);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('M createDebugIdFromString generates a valid UUID v5 Debug ID', async () => {
|
|
105
|
+
// https://www.rfc-editor.org/rfc/rfc9562.html#name-uuid-version-5
|
|
106
|
+
const uuidV5Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < 100; i++) {
|
|
109
|
+
const randomStr = `test-${Math.random()
|
|
110
|
+
.toString(36)
|
|
111
|
+
.substring(2, 15)}`;
|
|
112
|
+
const debugId = createDebugIdFromString(randomStr);
|
|
113
|
+
expect(debugId).toMatch(uuidV5Regex);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('M _replaceDebugIdInBundle replaces existing Debug ID in bundle W { symbol = #, 1 space }', () => {
|
|
118
|
+
// GIVEN
|
|
119
|
+
const mockCode = [
|
|
120
|
+
'"use strict"',
|
|
121
|
+
'console.log("Test");',
|
|
122
|
+
'// # debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
123
|
+
].join('\n');
|
|
124
|
+
|
|
125
|
+
// WHEN
|
|
126
|
+
const code = _replaceDebugIdInBundle('correct-debug-id', mockCode);
|
|
127
|
+
|
|
128
|
+
// THEN
|
|
129
|
+
expect(code).toBe(
|
|
130
|
+
[
|
|
131
|
+
'"use strict"',
|
|
132
|
+
'console.log("Test");',
|
|
133
|
+
'//# debugId=correct-debug-id'
|
|
134
|
+
].join('\n')
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('M _replaceDebugIdInBundle replaces existing Debug ID in bundle W { symbol = @, no spaces }', () => {
|
|
139
|
+
// GIVEN
|
|
140
|
+
const mockCode = [
|
|
141
|
+
'"use strict"',
|
|
142
|
+
'console.log("Test");',
|
|
143
|
+
'//@debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
144
|
+
].join('\n');
|
|
145
|
+
|
|
146
|
+
// WHEN
|
|
147
|
+
const code = _replaceDebugIdInBundle('correct-debug-id', mockCode);
|
|
148
|
+
|
|
149
|
+
// THEN
|
|
150
|
+
expect(code).toBe(
|
|
151
|
+
[
|
|
152
|
+
'"use strict"',
|
|
153
|
+
'console.log("Test");',
|
|
154
|
+
'//# debugId=correct-debug-id'
|
|
155
|
+
].join('\n')
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('M _insertDebugIdCommentInBundle adds Debug ID comment at the end of bundle W { no sourcemap comment } ', () => {
|
|
160
|
+
// GIVEN
|
|
161
|
+
const mockCode = ['"use strict"', 'console.log("Test");'].join(
|
|
162
|
+
'\n'
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
// WHEN
|
|
166
|
+
const code = _insertDebugIdCommentInBundle(
|
|
167
|
+
'test-debug-id',
|
|
168
|
+
mockCode
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// THEN
|
|
172
|
+
expect(code).toBe(
|
|
173
|
+
[
|
|
174
|
+
'"use strict"',
|
|
175
|
+
'console.log("Test");',
|
|
176
|
+
'//# debugId=test-debug-id'
|
|
177
|
+
].join('\n')
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('M _insertDebugIdCommentInBundle adds Debug ID comment before sourcemap comment', () => {
|
|
182
|
+
// GIVEN
|
|
183
|
+
const mockCode = [
|
|
184
|
+
'"use strict"',
|
|
185
|
+
'console.log("Test");',
|
|
186
|
+
'//# sourceMappingURL=index.android.bundle'
|
|
187
|
+
].join('\n');
|
|
188
|
+
|
|
189
|
+
// WHEN
|
|
190
|
+
const code = _insertDebugIdCommentInBundle(
|
|
191
|
+
'test-debug-id',
|
|
192
|
+
mockCode
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// THEN
|
|
196
|
+
expect(code).toBe(
|
|
197
|
+
[
|
|
198
|
+
'"use strict"',
|
|
199
|
+
'console.log("Test");',
|
|
200
|
+
'//# debugId=test-debug-id',
|
|
201
|
+
'//# sourceMappingURL=index.android.bundle'
|
|
202
|
+
].join('\n')
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('M _isDebugIdInBundle returns true if a debug ID is in bundle', () => {
|
|
207
|
+
// GIVEN
|
|
208
|
+
const mocks: string[] = [
|
|
209
|
+
// Case #0
|
|
210
|
+
[
|
|
211
|
+
'"use strict"',
|
|
212
|
+
'console.log("Test");',
|
|
213
|
+
'//#debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
214
|
+
].join('\n'),
|
|
215
|
+
|
|
216
|
+
// Case #1
|
|
217
|
+
[
|
|
218
|
+
'"use strict"',
|
|
219
|
+
'console.log("Test");',
|
|
220
|
+
'// #debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
221
|
+
].join('\n'),
|
|
222
|
+
|
|
223
|
+
// Case #2
|
|
224
|
+
[
|
|
225
|
+
'"use strict"',
|
|
226
|
+
'console.log("Test");',
|
|
227
|
+
'//# debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
228
|
+
].join('\n'),
|
|
229
|
+
|
|
230
|
+
// Case #3
|
|
231
|
+
[
|
|
232
|
+
'"use strict"',
|
|
233
|
+
'console.log("Test");',
|
|
234
|
+
'// # debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
235
|
+
].join('\n'),
|
|
236
|
+
|
|
237
|
+
// Case #4
|
|
238
|
+
[
|
|
239
|
+
'"use strict"',
|
|
240
|
+
'console.log("Test");',
|
|
241
|
+
'// @ debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
242
|
+
].join('\n')
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
// WHEN
|
|
246
|
+
const checks = mocks.map(mockCode =>
|
|
247
|
+
_isDebugIdInBundle(
|
|
248
|
+
'81094632-176f-2bd3-a143-768f1e98cb20',
|
|
249
|
+
mockCode
|
|
250
|
+
)
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// THEN
|
|
254
|
+
expect(checks[0]).toBe(true);
|
|
255
|
+
expect(checks[1]).toBe(true);
|
|
256
|
+
expect(checks[2]).toBe(true);
|
|
257
|
+
expect(checks[3]).toBe(true);
|
|
258
|
+
expect(checks[4]).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('M _isDebugIdInBundle returns true if the debug ID is different from provided and prints warning', () => {
|
|
262
|
+
const warnSpy = jest
|
|
263
|
+
.spyOn(console, 'warn')
|
|
264
|
+
.mockImplementation(() => {
|
|
265
|
+
/* empty */
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// GIVEN
|
|
269
|
+
const mockCode = [
|
|
270
|
+
'"use strict"',
|
|
271
|
+
'console.log("Test");',
|
|
272
|
+
'//#debugId=81094632-176f-2bd3-a143-768f1e98cb20'
|
|
273
|
+
].join('\n');
|
|
274
|
+
|
|
275
|
+
// WHEN
|
|
276
|
+
const check = _isDebugIdInBundle('different-debug-id', mockCode);
|
|
277
|
+
|
|
278
|
+
// THEN
|
|
279
|
+
expect(check).toBe(true);
|
|
280
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
281
|
+
'[DATADOG METRO PLUGIN] The debug ID found in the file does not match the calculated debug ID.'
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('M _isDebugIdInBundle returns false if the debug ID is not found', () => {
|
|
286
|
+
// GIVEN
|
|
287
|
+
const mockCode = ['"use strict"', 'console.log("Test");'].join(
|
|
288
|
+
'\n'
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
// WHEN
|
|
292
|
+
const check = _isDebugIdInBundle('different-debug-id', mockCode);
|
|
293
|
+
|
|
294
|
+
// THEN
|
|
295
|
+
expect(check).toBe(false);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('M getDebugIdFromBundleSource finds the debug ID in bundle code if present', () => {
|
|
299
|
+
// GIVEN
|
|
300
|
+
const debugId = 'a422b269-0dba-4341-93c2-73e1bcf71fbb';
|
|
301
|
+
const mockCode = `var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds&&(_datadogDebugIds={});try{var stack=(new Error).stack;stack&&(_datadogDebugIds[stack]="${debugId}",_datadogDebugIdMeta="datadog-debug-id-${debugId}")}catch(e){}`;
|
|
302
|
+
|
|
303
|
+
// WHEN
|
|
304
|
+
const debugIdMatch = getDebugIdFromBundleSource(mockCode);
|
|
305
|
+
|
|
306
|
+
// THEN
|
|
307
|
+
expect(debugIdMatch).toBe('a422b269-0dba-4341-93c2-73e1bcf71fbb');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('M getDebugIdFromBundleSource returns undefined if the debug ID in bundle code is not present', () => {
|
|
311
|
+
// GIVEN
|
|
312
|
+
const mockCode =
|
|
313
|
+
'var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds';
|
|
314
|
+
|
|
315
|
+
// WHEN
|
|
316
|
+
const debugIdMatch = getDebugIdFromBundleSource(mockCode);
|
|
317
|
+
|
|
318
|
+
// THEN
|
|
319
|
+
expect(debugIdMatch).toBeUndefined();
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('Debug ID Utils', () => {
|
|
324
|
+
test('M convertSerializerOutput returns bundle with map W { input type = string }', async () => {
|
|
325
|
+
// GIVEN
|
|
326
|
+
const output: MetroSerializerOutput = 'test-code';
|
|
327
|
+
|
|
328
|
+
// WHEN
|
|
329
|
+
const result = await convertSerializerOutput(output);
|
|
330
|
+
|
|
331
|
+
// THEN
|
|
332
|
+
expect(result.code).toBe('test-code');
|
|
333
|
+
expect(result.map).toBe('{}');
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('M convertSerializerOutput returns bundle with map W { input type = { code, map } }', async () => {
|
|
337
|
+
// GIVEN
|
|
338
|
+
const output: MetroSerializerOutput = {
|
|
339
|
+
code: 'test-code',
|
|
340
|
+
map: '{"testMap":"test"}'
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
// WHEN
|
|
344
|
+
const result = await convertSerializerOutput(output);
|
|
345
|
+
|
|
346
|
+
// THEN
|
|
347
|
+
expect(result.code).toBe('test-code');
|
|
348
|
+
expect(result.map).toBe('{"testMap":"test"}');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test('M convertSerializerOutput returns bundle with map W { input type = Promise<string> }', async () => {
|
|
352
|
+
// GIVEN
|
|
353
|
+
const output: MetroSerializerOutput = new Promise(resolve => {
|
|
354
|
+
resolve('test-code-from-promise');
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// WHEN
|
|
358
|
+
const result = await convertSerializerOutput(output);
|
|
359
|
+
|
|
360
|
+
// THEN
|
|
361
|
+
expect(result.code).toBe('test-code-from-promise');
|
|
362
|
+
expect(result.map).toBe('{}');
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test('M convertSerializerOutput returns bundle with map W { input type = Promise<{ code, map }> }', async () => {
|
|
366
|
+
// GIVEN
|
|
367
|
+
const output: MetroSerializerOutput = new Promise(resolve => {
|
|
368
|
+
resolve({
|
|
369
|
+
code: 'test-code-from-promise',
|
|
370
|
+
map: '{"testMap":"test"}'
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// WHEN
|
|
375
|
+
const result = await convertSerializerOutput(output);
|
|
376
|
+
|
|
377
|
+
// THEN
|
|
378
|
+
expect(result.code).toBe('test-code-from-promise');
|
|
379
|
+
expect(result.map).toBe('{"testMap":"test"}');
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
8
|
+
let debugId: any | null = null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Loads the Datadog Debug ID dynamically
|
|
12
|
+
*/
|
|
13
|
+
function loadDebugId() {
|
|
14
|
+
if (typeof globalThis === 'undefined') {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const debugIds = (globalThis as any)._datadogDebugIds;
|
|
19
|
+
if (!debugIds || Object.keys(debugIds).length === 0) {
|
|
20
|
+
console.warn(
|
|
21
|
+
'[Datadog SDK] Debug ID not found. Are you using @datadog/mobile-react-native/metro config?'
|
|
22
|
+
);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
debugId = debugIds[Object.keys(debugIds)[0]];
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.warn(
|
|
29
|
+
'[Datadog SDK] Error while retrieving Debug ID. Are you using @datadog/mobile-react-native/metro config?'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
loadDebugId();
|
|
35
|
+
|
|
36
|
+
export { debugId };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
|
|
3
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
|
|
23
|
+
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro-runtime/src/modules/types.flow.js#L16
|
|
24
|
+
declare type Bundle = {
|
|
25
|
+
modules: [number, string][];
|
|
26
|
+
post: string;
|
|
27
|
+
pre: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/DeltaBundler/Serializers/baseJSBundle.js#L25
|
|
31
|
+
declare module 'metro/src/DeltaBundler/Serializers/baseJSBundle' {
|
|
32
|
+
const baseJSBundle: (
|
|
33
|
+
entryPoint: string,
|
|
34
|
+
preModules: ReadonlyArray<Module>,
|
|
35
|
+
graph: ReadOnlyGraph,
|
|
36
|
+
options: SerializerOptions
|
|
37
|
+
) => Bundle;
|
|
38
|
+
export = baseJSBundle;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/lib/bundleToString.js#L22
|
|
42
|
+
declare module 'metro/src/lib/bundleToString' {
|
|
43
|
+
const bundleToString: (
|
|
44
|
+
bundle: Bundle
|
|
45
|
+
) => {
|
|
46
|
+
code: string;
|
|
47
|
+
metadata: BundleMetadata;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export = bundleToString;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/DeltaBundler/Serializers/sourceMapString.js#L22
|
|
54
|
+
declare module 'metro/src/DeltaBundler/Serializers/sourceMapString' {
|
|
55
|
+
import type { MixedOutput, Module } from 'metro';
|
|
56
|
+
|
|
57
|
+
const sourceMapString: (
|
|
58
|
+
modules: Module<MixedOutput>[],
|
|
59
|
+
options: {
|
|
60
|
+
excludeSource?: boolean;
|
|
61
|
+
processModuleFilter?: (module: Module<MixedOutput>) => boolean;
|
|
62
|
+
shouldAddToIgnoreList?: (module: Module<MixedOutput>) => boolean;
|
|
63
|
+
getSourceUrl?: (module: Module<MixedOutput>) => string;
|
|
64
|
+
}
|
|
65
|
+
) => string;
|
|
66
|
+
export = sourceMapString;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// https://github.com/facebook/metro/blob/a3d021a0d021b5706372059f472715c63019e044/packages/metro/src/lib/countLines.js#L16
|
|
70
|
+
declare module 'metro/src/lib/countLines' {
|
|
71
|
+
const countLines: (code: string) => number;
|
|
72
|
+
export = countLines;
|
|
73
|
+
}
|