From a9903e777f7dbe13ab579133c56d0f8e67a6ce07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Wold=C5=99ich?= <31292499+krystofwoldrich@users.noreply.github.com> Date: Fri, 15 Sep 2023 13:42:08 +0200 Subject: [PATCH] fix(rn): Upload root bundle source map for ram bundles (#1743) --- src/utils/sourcemaps.rs | 40 ++++++++++++++----- .../sourcemaps-upload-file-ram-bundle.trycmd | 3 +- ...ourcemaps-upload-indexed-ram-bundle.trycmd | 3 +- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index 2f5ce66578..1a88f7dae0 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -529,16 +529,14 @@ impl SourceMapProcessor { bundle_source_url, sourcemap_url ); - let sourcemap_content = match self.sources.get(&sourcemap_url) { - Some(source) => &source.contents, - None => { - warn!( - "Cannot find the sourcemap for the RAM bundle using the URL: {}, skipping", - sourcemap_url - ); - return Ok(()); - } + let Some(sourcemap_source) = self.sources.get(&sourcemap_url) else { + warn!( + "Cannot find the sourcemap for the RAM bundle using the URL: {}, skipping", + sourcemap_url + ); + return Ok(()); }; + let sourcemap_content = &sourcemap_source.contents; let sourcemap_index = match sourcemap::decode_slice(sourcemap_content)? { sourcemap::DecodedMap::Index(sourcemap_index) => sourcemap_index, @@ -548,8 +546,28 @@ impl SourceMapProcessor { } }; - // We don't need the RAM bundle sourcemap itself - self.sources.remove(&sourcemap_url); + // We have to include the bundle sourcemap which is the first section + // in the bundle source map before the modules maps + if let Some(index_section) = &sourcemap_index + .sections() + .nth(0) + .and_then(|index_section| index_section.get_sourcemap()) + { + let mut index_sourcemap_content: Vec = vec![]; + index_section.to_writer(&mut index_sourcemap_content)?; + self.sources.insert( + sourcemap_url.clone(), + SourceFile { + url: sourcemap_source.url.clone(), + path: sourcemap_source.path.clone(), + contents: index_sourcemap_content, + ty: SourceFileType::SourceMap, + headers: sourcemap_source.headers.clone(), + messages: sourcemap_source.messages.clone(), + already_uploaded: false, + }, + ); + } let ram_bundle_iter = sourcemap::ram_bundle::split_ram_bundle(ram_bundle, &sourcemap_index).unwrap(); diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-upload-file-ram-bundle.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-upload-file-ram-bundle.trycmd index 0574ddb2f6..16aaa40519 100644 --- a/tests/integration/_cases/sourcemaps/sourcemaps-upload-file-ram-bundle.trycmd +++ b/tests/integration/_cases/sourcemaps/sourcemaps-upload-file-ram-bundle.trycmd @@ -4,7 +4,7 @@ $ sentry-cli sourcemaps upload --bundle tests/integration/_fixtures/file-ram-bun > Analyzing 2 sources > Rewriting sources > Adding source map references -> Bundled 13 files for upload +> Bundled 14 files for upload > Bundle ID: [..]-[..]-[..]-[..]-[..] > Uploaded files to Sentry > File upload complete (processing pending on server) @@ -30,5 +30,6 @@ Source Map Upload Report ~/7.js.map ~/8.js.map ~/9.js.map + ~/index.android.bundle.packager.map ``` diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-upload-indexed-ram-bundle.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-upload-indexed-ram-bundle.trycmd index 9eb18d0db2..54a45b6ab1 100644 --- a/tests/integration/_cases/sourcemaps/sourcemaps-upload-indexed-ram-bundle.trycmd +++ b/tests/integration/_cases/sourcemaps/sourcemaps-upload-indexed-ram-bundle.trycmd @@ -4,7 +4,7 @@ $ sentry-cli sourcemaps upload --bundle tests/integration/_fixtures/indexed-ram- > Analyzing 2 sources > Rewriting sources > Adding source map references -> Bundled 2106 files for upload +> Bundled 2107 files for upload > Bundle ID: [..]-[..]-[..]-[..]-[..] > Uploaded files to Sentry > File upload complete (processing pending on server) @@ -2123,5 +2123,6 @@ Source Map Upload Report ~/997.js.map ~/998.js.map ~/999.js.map + ~/main.jsbundle.packager.map ```