@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
package/android/build.gradle
CHANGED
|
@@ -192,10 +192,21 @@ dependencies {
|
|
|
192
192
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
193
193
|
compileOnly "com.squareup.okhttp3:okhttp:3.12.13"
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
// dd-sdk-android-rum requires androidx.metrics:metrics-performance.
|
|
196
|
+
// From 2.21.0, it uses 1.0.0-beta02, which requires Gradle 8.6.0.
|
|
197
|
+
// This breaks builds if the React Native target is below 0.76.0. as it relies on Gradle 8.5.0.
|
|
198
|
+
// To avoid this, we enforce 1.0.0-beta01 on RN < 0.76.0
|
|
199
|
+
if (reactNativeMinorVersion < 76) {
|
|
200
|
+
implementation("com.datadoghq:dd-sdk-android-rum:2.21.0") {
|
|
201
|
+
exclude group: "androidx.metrics", module: "metrics-performance"
|
|
202
|
+
}
|
|
203
|
+
implementation "androidx.metrics:metrics-performance:1.0.0-beta01"
|
|
204
|
+
} else {
|
|
205
|
+
implementation "com.datadoghq:dd-sdk-android-rum:2.21.0"
|
|
206
|
+
}
|
|
207
|
+
implementation "com.datadoghq:dd-sdk-android-logs:2.21.0"
|
|
208
|
+
implementation "com.datadoghq:dd-sdk-android-trace:2.21.0"
|
|
209
|
+
implementation "com.datadoghq:dd-sdk-android-webview:2.21.0"
|
|
199
210
|
implementation "com.google.code.gson:gson:2.10.0"
|
|
200
211
|
testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
|
|
201
212
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
|
|
@@ -49,15 +49,15 @@ afterEvaluate {
|
|
|
49
49
|
logger.info("Service name used for the upload of variant=${targetName} is ${serviceName}.")
|
|
50
50
|
|
|
51
51
|
def bundleAssetName = reactConfig.bundleAssetName
|
|
52
|
-
|
|
53
52
|
def jsSourceMapsDir = file("$buildDir/generated/sourcemaps/react/${targetPath}")
|
|
54
53
|
def jsOutputSourceMapFile = file("$jsSourceMapsDir/${bundleAssetName}.map")
|
|
54
|
+
def packagerOutputSourceMapFile = file("$buildDir/intermediates/sourcemaps/react/${targetPath}/${bundleAssetName}.packager.map")
|
|
55
55
|
|
|
56
56
|
def uploadTask = tasks.create("upload${targetName}Sourcemaps") {
|
|
57
57
|
group = "datadog"
|
|
58
58
|
description = "Uploads sourcemaps to Datadog."
|
|
59
59
|
|
|
60
|
-
def
|
|
60
|
+
def uploadSourcemap = { jsBundleFile ->
|
|
61
61
|
return [
|
|
62
62
|
"${getDatadogCiExecPath(reactConfig)}",
|
|
63
63
|
"react-native",
|
|
@@ -87,14 +87,42 @@ afterEvaluate {
|
|
|
87
87
|
throw new GradleException("JS sourcemap file doesn't exist, aborting upload.")
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
// Copy Debug ID from packager sourcemap to composed sourcemap (Hermes)
|
|
91
|
+
if (packagerOutputSourceMapFile.exists()) {
|
|
92
|
+
logger.info("Copying Debug ID from ${packagerOutputSourceMapFile.absolutePath} to ${jsOutputSourceMapFile.absolutePath}")
|
|
93
|
+
copyDebugId(packagerOutputSourceMapFile.absolutePath, jsOutputSourceMapFile.absolutePath, reactRoot)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
runShellCommand(uploadSourcemap(jsBundleFile), reactRoot)
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
uploadTask.dependsOn bundleTask
|
|
95
101
|
bundleTask.finalizedBy uploadTask
|
|
102
|
+
}
|
|
103
|
+
}
|
|
96
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Copies the Debug ID from the packager sourcemap to the composed sourcemap (Hermes).
|
|
107
|
+
*/
|
|
108
|
+
private def copyDebugId(String packagerSourceMapPath, String jsSourceMapPath, File workingDirectory) {
|
|
109
|
+
def ddReactNativePath = getDatadogReactNativePath(workingDirectory)
|
|
110
|
+
def copyDebugIdScript = new File("$ddReactNativePath/scripts/copy-debug-id.js")
|
|
111
|
+
if (!copyDebugIdScript.exists()) {
|
|
112
|
+
println("ERROR: copy Debug ID script does not exist at ${copyDebugIdScript.absolutePath}")
|
|
113
|
+
return
|
|
97
114
|
}
|
|
115
|
+
|
|
116
|
+
def nodeExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? 'node.exe' : 'node'
|
|
117
|
+
|
|
118
|
+
def copyDebugIdCommand = [
|
|
119
|
+
nodeExecutable,
|
|
120
|
+
copyDebugIdScript,
|
|
121
|
+
packagerSourceMapPath,
|
|
122
|
+
jsSourceMapPath
|
|
123
|
+
]
|
|
124
|
+
|
|
125
|
+
runShellCommand(copyDebugIdCommand, workingDirectory)
|
|
98
126
|
}
|
|
99
127
|
|
|
100
128
|
/**
|
|
@@ -148,6 +176,76 @@ private def getDatadogCiExecPath(reactConfig) {
|
|
|
148
176
|
return defaultPath
|
|
149
177
|
}
|
|
150
178
|
|
|
179
|
+
/**
|
|
180
|
+
* We use a function here to resolve the Datadog React Native package path.
|
|
181
|
+
* If DATADOG_REACT_NATIVE_PATH env variable is defined, it will be returned (if valid).
|
|
182
|
+
*/
|
|
183
|
+
private def getDatadogReactNativePath(File workingDirectory) {
|
|
184
|
+
def defaultPath = "${workingDirectory.absolutePath}/node_modules/@datadog/mobile-react-native"
|
|
185
|
+
|
|
186
|
+
// Try to retrieve the path from ENV variable
|
|
187
|
+
def envPath = System.getenv('DATADOG_REACT_NATIVE_PATH')
|
|
188
|
+
if (envPath != null) {
|
|
189
|
+
if (isValidDatadogPackagePath(envPath)) {
|
|
190
|
+
return envPath
|
|
191
|
+
} else {
|
|
192
|
+
println("WARNING: Ignoring DATADOG_REACT_NATIVE_PATH as it does not point to a valid @datadog/mobile-react-native package (${envPath})")
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
def nodeExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? 'node.exe' : 'node'
|
|
197
|
+
def nodeScript = '''
|
|
198
|
+
const path = require('path');
|
|
199
|
+
const libModulePath = require.resolve('@datadog/mobile-react-native');
|
|
200
|
+
const packagePath = path.resolve(path.dirname(libModulePath), '../..')
|
|
201
|
+
console.log(packagePath);
|
|
202
|
+
'''
|
|
203
|
+
|
|
204
|
+
def stdout = new ByteArrayOutputStream()
|
|
205
|
+
def process = new ProcessBuilder(nodeExecutable)
|
|
206
|
+
.redirectErrorStream(true)
|
|
207
|
+
.start()
|
|
208
|
+
|
|
209
|
+
process.outputStream.withWriter { writer ->
|
|
210
|
+
writer << nodeScript
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
process.inputStream.eachLine { line ->
|
|
214
|
+
stdout << line << '\n'
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
process.waitFor()
|
|
218
|
+
|
|
219
|
+
def resolvedPath = stdout.toString().trim()
|
|
220
|
+
if (isValidDatadogPackagePath(resolvedPath)) {
|
|
221
|
+
return resolvedPath
|
|
222
|
+
} else {
|
|
223
|
+
println("WARNING: Could not resolve @datadog/mobile-react-native path, falling back to default: ${defaultPath}")
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return defaultPath
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Function to validate @datadog/mobile-react-native path
|
|
231
|
+
*/
|
|
232
|
+
private def isValidDatadogPackagePath(String path) {
|
|
233
|
+
def packageJsonFile = new File(path, "package.json")
|
|
234
|
+
|
|
235
|
+
// Check package.json exists
|
|
236
|
+
if (!packageJsonFile.exists()) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Check if it is @datadog/mobile-react-native
|
|
241
|
+
def packageContent = packageJsonFile.text
|
|
242
|
+
if (!packageContent.contains('"name": "@datadog/mobile-react-native"')) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
|
|
151
249
|
/**
|
|
152
250
|
* Function to validate datadog-ci executable path.
|
|
153
251
|
*/
|
package/ios/Sources/DdSdk.mm
CHANGED
|
@@ -211,16 +211,19 @@ RCT_REMAP_METHOD(clearAllData, withResolver:(RCTPromiseResolveBlock)resolve
|
|
|
211
211
|
[strongSelf sendEventWithName:@"RUMSessionStarted" body: sessionId];
|
|
212
212
|
}];
|
|
213
213
|
}
|
|
214
|
+
|
|
214
215
|
#else
|
|
215
216
|
- (void)registerNativeBridge {
|
|
216
217
|
[DdSdkSessionStartedListener.instance setRCTBridge: _bridge];
|
|
217
218
|
}
|
|
219
|
+
#endif
|
|
218
220
|
|
|
219
221
|
- (void)setBridge:(RCTBridge *)bridge {
|
|
220
222
|
[super setBridge:bridge];
|
|
221
223
|
_bridge = bridge;
|
|
224
|
+
#ifndef RCT_NEW_ARCH_ENABLED
|
|
222
225
|
[self registerNativeBridge];
|
|
226
|
+
#endif
|
|
223
227
|
}
|
|
224
|
-
#endif
|
|
225
228
|
|
|
226
229
|
@end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.debugId = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
9
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
10
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
14
|
+
let debugId = exports.debugId = null;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Loads the Datadog Debug ID dynamically
|
|
18
|
+
*/
|
|
19
|
+
function loadDebugId() {
|
|
20
|
+
if (typeof globalThis === 'undefined') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const debugIds = globalThis._datadogDebugIds;
|
|
25
|
+
if (!debugIds || Object.keys(debugIds).length === 0) {
|
|
26
|
+
console.warn('[Datadog SDK] Debug ID not found. Are you using @datadog/mobile-react-native/metro config?');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
exports.debugId = debugId = debugIds[Object.keys(debugIds)[0]];
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.warn('[Datadog SDK] Error while retrieving Debug ID. Are you using @datadog/mobile-react-native/metro config?');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
loadDebugId();
|
|
35
|
+
//# sourceMappingURL=debugIdResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["debugId","exports","loadDebugId","globalThis","debugIds","_datadogDebugIds","Object","keys","length","console","warn","error"],"sourceRoot":"../../../src","sources":["metro/debugIdResolver.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA,IAAIA,OAAmB,GAAAC,OAAA,CAAAD,OAAA,GAAG,IAAI;;AAE9B;AACA;AACA;AACA,SAASE,WAAWA,CAAA,EAAG;EACnB,IAAI,OAAOC,UAAU,KAAK,WAAW,EAAE;IACnC;EACJ;EACA,IAAI;IACA,MAAMC,QAAQ,GAAID,UAAU,CAASE,gBAAgB;IACrD,IAAI,CAACD,QAAQ,IAAIE,MAAM,CAACC,IAAI,CAACH,QAAQ,CAAC,CAACI,MAAM,KAAK,CAAC,EAAE;MACjDC,OAAO,CAACC,IAAI,CACR,4FACJ,CAAC;MACD;IACJ;IAEAT,OAAA,CAAAD,OAAA,GAAAA,OAAO,GAAGI,QAAQ,CAACE,MAAM,CAACC,IAAI,CAACH,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;EAChD,CAAC,CAAC,OAAOO,KAAK,EAAE;IACZF,OAAO,CAACC,IAAI,CACR,yGACJ,CAAC;EACL;AACJ;AAEAR,WAAW,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["metro/metro.d.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.injectDebugIdInCodeAndSourceMap = exports.injectDebugIdInCode = exports.getDebugIdFromBundleSource = exports.createDebugIdSnippet = exports.createDebugIdModule = exports.createDebugIdFromString = exports.createDebugIdFromBundle = exports.checkIfDebugIdModuleExists = exports.addDebugIdModule = exports._replaceDebugIdInBundle = exports._isDebugIdInBundle = exports._insertDebugIdCommentInBundle = exports.SOURCE_MAP_COMMENT = exports.DEBUG_ID_PLACEHOLDER = exports.DEBUG_ID_MODULE_PATH = exports.DEBUG_ID_COMMENT = void 0;
|
|
7
|
+
var _crypto = require("crypto");
|
|
8
|
+
var _countLines = _interopRequireDefault(require("metro/src/lib/countLines"));
|
|
9
|
+
var _utils = require("./utils");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
/*
|
|
12
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
13
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
14
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
15
|
+
*
|
|
16
|
+
* Portions of this code are adapted from Sentry's Metro configuration:
|
|
17
|
+
* https://github.com/getsentry/sentry-react-native/blob/17c0c2e8913030e4826d055284a735efad637312/packages/core/src/js/tools/sentryMetroSerializer.ts
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Regex to match the Debug ID comment in the bundle.
|
|
24
|
+
*/
|
|
25
|
+
const DEBUG_ID_BUNDLE_REGEX = /\/\/\s?([#@])\s?debugId=([\d\-a-zA-Z]*$)/m;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Path name for the Debug ID Metro Virtual Module.
|
|
29
|
+
*/
|
|
30
|
+
const DEBUG_ID_MODULE_PATH = exports.DEBUG_ID_MODULE_PATH = '__datadog_debugid__';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The initial placeholder for the injected Debug ID in the virtual module, replaced
|
|
34
|
+
* later by the actual Debug ID.
|
|
35
|
+
*/
|
|
36
|
+
const DEBUG_ID_PLACEHOLDER = exports.DEBUG_ID_PLACEHOLDER = '__datadog_debug_id_placeholder__';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A comment that can be found at the end of the JS bundle, to specify the URL of the sourcemap.
|
|
40
|
+
* Ref: https://tc39.es/ecma426/#sec-linking-inline
|
|
41
|
+
*/
|
|
42
|
+
const SOURCE_MAP_COMMENT = exports.SOURCE_MAP_COMMENT = '//# sourceMappingURL=';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The comment that will be appended at the end of the JS bundle, to specify the Debug ID.
|
|
46
|
+
* Ref: https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md
|
|
47
|
+
*/
|
|
48
|
+
const DEBUG_ID_COMMENT = exports.DEBUG_ID_COMMENT = '//# debugId=';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The Debug ID is injected in the virtual module as a plain string, using this prefix.
|
|
52
|
+
* It is later retrieved by searching it in the bundle, using the same prefix.
|
|
53
|
+
*/
|
|
54
|
+
const DEBUG_ID_METADATA_PREFIX = 'datadog-debug-id-';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a virtual module to embed a debug ID into the bundle.
|
|
58
|
+
* @param debugId - the debug ID to inject into the bundle, or a placeholder.
|
|
59
|
+
* @returns The Debug ID virtual module.
|
|
60
|
+
*/
|
|
61
|
+
const createDebugIdModule = debugId => {
|
|
62
|
+
let debugIdCode = createDebugIdSnippet(debugId);
|
|
63
|
+
return {
|
|
64
|
+
setSource: code => {
|
|
65
|
+
debugIdCode = code;
|
|
66
|
+
},
|
|
67
|
+
dependencies: new Map(),
|
|
68
|
+
getSource: () => Buffer.from(debugIdCode),
|
|
69
|
+
inverseDependencies: (0, _utils.createCountingSet)(),
|
|
70
|
+
path: DEBUG_ID_MODULE_PATH,
|
|
71
|
+
output: [{
|
|
72
|
+
type: 'js/script/virtual',
|
|
73
|
+
data: {
|
|
74
|
+
code: debugIdCode,
|
|
75
|
+
lineCount: (0, _countLines.default)(debugIdCode),
|
|
76
|
+
map: []
|
|
77
|
+
}
|
|
78
|
+
}]
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Injects the debug ID module into the list of pre-modules,
|
|
84
|
+
* ensuring that the prelude module (if present) stays at the top
|
|
85
|
+
* to correctly measure bundle startup time.
|
|
86
|
+
*/
|
|
87
|
+
exports.createDebugIdModule = createDebugIdModule;
|
|
88
|
+
const addDebugIdModule = (preModules, debugIdModule) => {
|
|
89
|
+
const result = [...preModules];
|
|
90
|
+
const hasPrelude = result.length > 0 && result[0]?.path === '__prelude__';
|
|
91
|
+
if (hasPrelude) {
|
|
92
|
+
result.splice(1, 0, debugIdModule);
|
|
93
|
+
} else {
|
|
94
|
+
result.unshift(debugIdModule);
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Creates a minified JavaScript snippet that exposes the provided Debug ID
|
|
101
|
+
* on the global scope at runtime.
|
|
102
|
+
*
|
|
103
|
+
* @param debugId - The Debug ID to be injected into the global scope.
|
|
104
|
+
* @returns A minified JavaScript string that performs the injection.
|
|
105
|
+
*/
|
|
106
|
+
exports.addDebugIdModule = addDebugIdModule;
|
|
107
|
+
const createDebugIdSnippet = debugId => {
|
|
108
|
+
return `var _datadogDebugIds,_datadogDebugIdMeta;void 0===_datadogDebugIds&&(_datadogDebugIds={});try{var stack=(new Error).stack;stack&&(_datadogDebugIds[stack]="${debugId}",_datadogDebugIdMeta="${DEBUG_ID_METADATA_PREFIX}${debugId}")}catch(e){}`;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Extracts the Debug ID from a bundle source string by locating the pattern
|
|
113
|
+
* "{@link DEBUG_ID_METADATA_PREFIX}`[DEBUG-ID]`"
|
|
114
|
+
*
|
|
115
|
+
* @param code - The source code of the bundle to search within.
|
|
116
|
+
* @returns The extracted Debug ID, or `undefined` if not found.
|
|
117
|
+
*/
|
|
118
|
+
exports.createDebugIdSnippet = createDebugIdSnippet;
|
|
119
|
+
const getDebugIdFromBundleSource = code => {
|
|
120
|
+
const match = code.match(new RegExp(`${DEBUG_ID_METADATA_PREFIX}([0-9a-fA-F]{8}\\b-(?:[0-9a-fA-F]{4}\\b-){3}[0-9a-fA-F]{12})`));
|
|
121
|
+
return match ? match[1] : undefined;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Creates a unique Debug ID from the given bundle, by using the content of its modules.
|
|
126
|
+
* @param bundle The bundle to create the Debug ID from.
|
|
127
|
+
* @returns The computed Debug ID.
|
|
128
|
+
*/
|
|
129
|
+
exports.getDebugIdFromBundleSource = getDebugIdFromBundleSource;
|
|
130
|
+
const createDebugIdFromBundle = bundle => {
|
|
131
|
+
const hash = (0, _crypto.createHash)('md5');
|
|
132
|
+
hash.update(bundle.pre);
|
|
133
|
+
for (const [, code] of bundle.modules) {
|
|
134
|
+
hash.update(code);
|
|
135
|
+
}
|
|
136
|
+
hash.update(bundle.post);
|
|
137
|
+
return createDebugIdFromString(hash.digest('hex'));
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Creates a unique Debug ID from the given string.
|
|
142
|
+
* Ref: https://github.com/expo/expo/blob/94a124894a355ad6e24f4bac5144986380686157/packages/%40expo/metro-config/src/serializer/debugId.ts#L15
|
|
143
|
+
* @param str The string to create the Debug ID from.
|
|
144
|
+
* @returns The computed Debug ID.
|
|
145
|
+
*/
|
|
146
|
+
exports.createDebugIdFromBundle = createDebugIdFromBundle;
|
|
147
|
+
const createDebugIdFromString = str => {
|
|
148
|
+
const md5sum = (0, _crypto.createHash)('md5');
|
|
149
|
+
md5sum.update(str);
|
|
150
|
+
const md5Hash = md5sum.digest('hex');
|
|
151
|
+
|
|
152
|
+
// Position 16 is fixed to either 8, 9, a, or b in the uuid v4 spec (10xx in binary)
|
|
153
|
+
// RFC 4122 section 4.4
|
|
154
|
+
const v4variant = ['8', '9', 'a', 'b'][md5Hash.substring(16, 17).charCodeAt(0) % 4];
|
|
155
|
+
return `${md5Hash.substring(0, 8)}-${md5Hash.substring(8, 12)}-4${md5Hash.substring(13, 16)}-${v4variant}${md5Hash.substring(17, 20)}-${md5Hash.substring(20)}`.toLowerCase();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Injects the given debug ID in the given code, and returns the modified code.
|
|
160
|
+
*
|
|
161
|
+
* It looks for a specific placeholder defined in {@link DEBUG_ID_PLACEHOLDER}, and replaces
|
|
162
|
+
* all its occurences with the given Debug ID.
|
|
163
|
+
* @param code The code to inject the Debug ID into.
|
|
164
|
+
* @param debugId The Debug ID to inject.
|
|
165
|
+
* @returns The modified code with the injected Debug ID.
|
|
166
|
+
*/
|
|
167
|
+
exports.createDebugIdFromString = createDebugIdFromString;
|
|
168
|
+
const injectDebugIdInCode = (code, debugId) => {
|
|
169
|
+
return code.replace(new RegExp(DEBUG_ID_PLACEHOLDER, 'g'), debugId);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Injects the given Debug ID in the given code (as a comment at the end of the file), and in the
|
|
174
|
+
* given sourcemap (as a top-level JSON property).
|
|
175
|
+
* @param debugId The Debug ID to inject.
|
|
176
|
+
* @param code The code to inject the Debug ID in.
|
|
177
|
+
* @param sourcemap The sourcemap to inject the Debug ID in.
|
|
178
|
+
* @returns The modified {@link MetroBundleWithMap} with the Debug ID
|
|
179
|
+
*/
|
|
180
|
+
exports.injectDebugIdInCode = injectDebugIdInCode;
|
|
181
|
+
const injectDebugIdInCodeAndSourceMap = (debugId, code, sourcemap) => {
|
|
182
|
+
let codeWithDebugId = code;
|
|
183
|
+
if (_isDebugIdInBundle(debugId, code)) {
|
|
184
|
+
codeWithDebugId = _replaceDebugIdInBundle(debugId, code);
|
|
185
|
+
} else {
|
|
186
|
+
codeWithDebugId = _insertDebugIdCommentInBundle(debugId, code);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Insert the Debug ID as a top-level property of the sourcemap
|
|
190
|
+
const bundleMap = JSON.parse(sourcemap);
|
|
191
|
+
bundleMap['debugId'] = debugId;
|
|
192
|
+
return {
|
|
193
|
+
code: codeWithDebugId,
|
|
194
|
+
map: JSON.stringify(bundleMap)
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* [INTERNAL] Checks if the debug ID is in the bundle, and prints a warning if it does not match the given one.
|
|
200
|
+
*/
|
|
201
|
+
exports.injectDebugIdInCodeAndSourceMap = injectDebugIdInCodeAndSourceMap;
|
|
202
|
+
const _isDebugIdInBundle = (debugId, bundleCode) => {
|
|
203
|
+
const match = bundleCode.match(DEBUG_ID_BUNDLE_REGEX);
|
|
204
|
+
if (!match || match.length < 2) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
if (match[2] !== debugId) {
|
|
208
|
+
console.warn('[DATADOG METRO PLUGIN] The debug ID found in the file does not match the calculated debug ID.');
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Checks if the virtual Debug ID module exists in the given modules.
|
|
215
|
+
* @param modules - The list of modules in which to look for the Debug ID.
|
|
216
|
+
* @returns `true` if the Debug ID module exists, `false` otherwise.
|
|
217
|
+
*/
|
|
218
|
+
exports._isDebugIdInBundle = _isDebugIdInBundle;
|
|
219
|
+
const checkIfDebugIdModuleExists = modules => modules.findIndex(module => module.path === DEBUG_ID_MODULE_PATH) !== -1;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* [INTERNAL] Replaces the existing Debug ID comment in the bundle with a new one, containing the given Debug ID.
|
|
223
|
+
*/
|
|
224
|
+
exports.checkIfDebugIdModuleExists = checkIfDebugIdModuleExists;
|
|
225
|
+
const _replaceDebugIdInBundle = (debugId, bundleCode) => {
|
|
226
|
+
return bundleCode.replace(DEBUG_ID_BUNDLE_REGEX, `${DEBUG_ID_COMMENT}${debugId}`);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* [INTERNAL] Inserts the Debug ID comment in the bundle in the correct position.
|
|
231
|
+
*/
|
|
232
|
+
exports._replaceDebugIdInBundle = _replaceDebugIdInBundle;
|
|
233
|
+
const _insertDebugIdCommentInBundle = (debugId, bundleCode) => {
|
|
234
|
+
const debugIdComment = `${DEBUG_ID_COMMENT}${debugId}`;
|
|
235
|
+
const indexOfSourceMapComment = bundleCode.lastIndexOf(SOURCE_MAP_COMMENT);
|
|
236
|
+
if (indexOfSourceMapComment === -1) {
|
|
237
|
+
return `${bundleCode}\n${debugIdComment}`;
|
|
238
|
+
}
|
|
239
|
+
const before = bundleCode.substring(0, indexOfSourceMapComment);
|
|
240
|
+
const after = bundleCode.substring(indexOfSourceMapComment);
|
|
241
|
+
return `${before}${debugIdComment}\n${after}`;
|
|
242
|
+
};
|
|
243
|
+
exports._insertDebugIdCommentInBundle = _insertDebugIdCommentInBundle;
|
|
244
|
+
//# sourceMappingURL=debugIdHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_crypto","require","_countLines","_interopRequireDefault","_utils","e","__esModule","default","DEBUG_ID_BUNDLE_REGEX","DEBUG_ID_MODULE_PATH","exports","DEBUG_ID_PLACEHOLDER","SOURCE_MAP_COMMENT","DEBUG_ID_COMMENT","DEBUG_ID_METADATA_PREFIX","createDebugIdModule","debugId","debugIdCode","createDebugIdSnippet","setSource","code","dependencies","Map","getSource","Buffer","from","inverseDependencies","createCountingSet","path","output","type","data","lineCount","countLines","map","addDebugIdModule","preModules","debugIdModule","result","hasPrelude","length","splice","unshift","getDebugIdFromBundleSource","match","RegExp","undefined","createDebugIdFromBundle","bundle","hash","createHash","update","pre","modules","post","createDebugIdFromString","digest","str","md5sum","md5Hash","v4variant","substring","charCodeAt","toLowerCase","injectDebugIdInCode","replace","injectDebugIdInCodeAndSourceMap","sourcemap","codeWithDebugId","_isDebugIdInBundle","_replaceDebugIdInBundle","_insertDebugIdCommentInBundle","bundleMap","JSON","parse","stringify","bundleCode","console","warn","checkIfDebugIdModuleExists","findIndex","module","debugIdComment","indexOfSourceMapComment","lastIndexOf","before","after"],"sourceRoot":"../../../../src","sources":["metro/plugin/debugIdHelper.ts"],"mappings":";;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AASA,IAAAG,MAAA,GAAAH,OAAA;AAA4C,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AApB5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;;AAYA;AACA;AACA;AACA,MAAMG,qBAAqB,GAAG,2CAA2C;;AAEzE;AACA;AACA;AACO,MAAMC,oBAAoB,GAAAC,OAAA,CAAAD,oBAAA,GAAG,qBAAqB;;AAEzD;AACA;AACA;AACA;AACO,MAAME,oBAAoB,GAAAD,OAAA,CAAAC,oBAAA,GAAG,kCAAkC;;AAEtE;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAAF,OAAA,CAAAE,kBAAA,GAAG,uBAAuB;;AAEzD;AACA;AACA;AACA;AACO,MAAMC,gBAAgB,GAAAH,OAAA,CAAAG,gBAAA,GAAG,cAAc;;AAE9C;AACA;AACA;AACA;AACA,MAAMC,wBAAwB,GAAG,mBAAmB;;AAEpD;AACA;AACA;AACA;AACA;AACO,MAAMC,mBAAmB,GAAIC,OAAe,IAA2B;EAC1E,IAAIC,WAAW,GAAGC,oBAAoB,CAACF,OAAO,CAAC;EAE/C,OAAO;IACHG,SAAS,EAAGC,IAAY,IAAK;MACzBH,WAAW,GAAGG,IAAI;IACtB,CAAC;IACDC,YAAY,EAAE,IAAIC,GAAG,CAAC,CAAC;IACvBC,SAAS,EAAEA,CAAA,KAAMC,MAAM,CAACC,IAAI,CAACR,WAAW,CAAC;IACzCS,mBAAmB,EAAE,IAAAC,wBAAiB,EAAC,CAAC;IACxCC,IAAI,EAAEnB,oBAAoB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
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDatadogExpoConfig = getDatadogExpoConfig;
|
|
7
|
+
exports.withDatadogDebugId = withDatadogDebugId;
|
|
8
|
+
exports.withDatadogMetroConfig = withDatadogMetroConfig;
|
|
9
|
+
var _metroSerializer = require("./metroSerializer");
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
/*
|
|
12
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
13
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
14
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Custom Datadog Metro Configuration.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Extends the Metro bundler configuration to integrate with Datadog.
|
|
23
|
+
*
|
|
24
|
+
* *Note: If a custom serializer is used and `config.useDebugId` is set to `true` (as it is by default),
|
|
25
|
+
* you must manually invoke `options.datadogBundleCallback` within the serializer.*
|
|
26
|
+
*/
|
|
27
|
+
function withDatadogMetroConfig(config) {
|
|
28
|
+
let newConfig = config;
|
|
29
|
+
if (config.useDebugId ?? true) {
|
|
30
|
+
newConfig = withDatadogDebugId(config);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
...newConfig,
|
|
34
|
+
transformer: {
|
|
35
|
+
...newConfig.transformer
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Extends the Expo configuration to integrate with Datadog.
|
|
42
|
+
* @param config
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
function getDatadogExpoConfig(projectRoot, options = {}) {
|
|
46
|
+
const plugins = options.unstable_beforeAssetSerializationPlugins ?? [];
|
|
47
|
+
const datadogOptions = {
|
|
48
|
+
...options,
|
|
49
|
+
unstable_beforeAssetSerializationPlugins: [...plugins, _metroSerializer.unstable_beforeAssetSerializationPlugin]
|
|
50
|
+
};
|
|
51
|
+
return (options.getDefaultConfig ?? _utils.getDefaultExpoConfig)(projectRoot, datadogOptions);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Extends the Metro bundler configuration by enabling Debug ID injection.
|
|
56
|
+
* Ref: https://github.com/tc39/ecma426/blob/main/proposals/debug-id.md
|
|
57
|
+
*/
|
|
58
|
+
function withDatadogDebugId(config) {
|
|
59
|
+
const customSerializer = (0, _metroSerializer.createDatadogMetroSerializer)(config.serializer?.customSerializer || undefined);
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
serializer: {
|
|
63
|
+
...config.serializer,
|
|
64
|
+
customSerializer
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=metroConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_metroSerializer","require","_utils","withDatadogMetroConfig","config","newConfig","useDebugId","withDatadogDebugId","transformer","getDatadogExpoConfig","projectRoot","options","plugins","unstable_beforeAssetSerializationPlugins","datadogOptions","unstable_beforeAssetSerializationPlugin","getDefaultConfig","getDefaultExpoConfig","customSerializer","createDatadogMetroSerializer","serializer","undefined"],"sourceRoot":"../../../../src","sources":["metro/plugin/metroConfig.ts"],"mappings":";;;;;;;;AAOA,IAAAA,gBAAA,GAAAC,OAAA;AASA,IAAAC,MAAA,GAAAD,OAAA;AAhBA;AACA;AACA;AACA;AACA;;AAcA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,sBAAsBA,CAClCC,MAA+C,EACpC;EACX,IAAIC,SAAS,GAAGD,MAAM;EAEtB,IAAIA,MAAM,CAACE,UAAU,IAAI,IAAI,EAAE;IAC3BD,SAAS,GAAGE,kBAAkB,CAACH,MAAM,CAAC;EAC1C;EAEA,OAAO;IACH,GAAGC,SAAS;IACZG,WAAW,EAAE;MACT,GAAGH,SAAS,CAACG;IACjB;EACJ,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,oBAAoBA,CAChCC,WAAmB,EACnBC,OAAwD,GAAG,CAAC,CAAC,EACzC;EACpB,MAAMC,OAAO,GAAGD,OAAO,CAACE,wCAAwC,IAAI,EAAE;EACtE,MAAMC,cAAoC,GAAG;IACzC,GAAGH,OAAO;IACVE,wCAAwC,EAAE,CACtC,GAAGD,OAAO,EACVG,wDAAuC;EAE/C,CAAC;EAED,OAAO,CAACJ,OAAO,CAACK,gBAAgB,IAAIC,2BAAoB,EACpDP,WAAW,EACXI,cACJ,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACO,SAASP,kBAAkBA,CAACH,MAAmB,EAAe;EACjE,MAAMc,gBAAgB,GAAG,IAAAC,6CAA4B,EACjDf,MAAM,CAACgB,UAAU,EAAEF,gBAAgB,IAAIG,SAC3C,CAA2B;EAE3B,OAAO;IACH,GAAGjB,MAAM;IACTgB,UAAU,EAAE;MACR,GAAGhB,MAAM,CAACgB,UAAU;MACpBF;IACJ;EACJ,CAAC;AACL","ignoreList":[]}
|