diff --git a/Cargo.lock b/Cargo.lock index e5031db895..7f2403d680 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1326,6 +1326,19 @@ dependencies = [ "cc", ] +[[package]] +name = "magic_string" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8033ce8c43f7ccb207e4699f30eed50d7526379ee08fab47159f80b7934e18" +dependencies = [ + "base64", + "regex", + "serde", + "serde_json", + "vlq", +] + [[package]] name = "match_cfg" version = "0.1.0" @@ -2221,6 +2234,7 @@ dependencies = [ "libc", "log", "mac-process-info", + "magic_string", "might-be-minified", "mockito", "open", @@ -2468,9 +2482,9 @@ dependencies = [ [[package]] name = "sourcemap" -version = "6.3.0" +version = "6.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8df03d85f2767c45e61b4453eb6144153c80399e4fdd6407a6d16cb87cc0347" +checksum = "e9221a6bba3e9cfa7decfe64edf5233311e1bf837ea3234df6e7f35836e1093d" dependencies = [ "data-encoding", "debugid", @@ -2947,6 +2961,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vlq" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65dd7eed29412da847b0f78bcec0ac98588165988a8cfe41d4ea1d429f8ccfff" + [[package]] name = "wait-timeout" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index c8c9ca96a2..e37a7c449d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,7 @@ sentry = { version = "0.31.2", default-features = false, features = [ serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.93" sha1_smol = { version = "1.0.0", features = ["serde"] } -sourcemap = { version = "6.3.0", features = ["ram_bundle"] } +sourcemap = { version = "6.4.0", features = ["ram_bundle"] } symbolic = { version = "12.1.5", features = ["debuginfo-serde", "il2cpp"] } thiserror = "1.0.38" url = "2.3.1" @@ -75,6 +75,7 @@ walkdir = "2.3.2" which = "4.4.0" zip = "0.6.4" data-encoding = "2.3.3" +magic_string = "0.3.4" [dev-dependencies] insta = { version = "1.26.0", features = ["redactions", "yaml"] } diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index feed673959..e7905a7787 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -13,12 +13,12 @@ use indicatif::ProgressStyle; use log::{debug, info, warn}; use sentry::types::DebugId; use sha1_smol::Digest; +use sourcemap::SourceMap; use symbolic::debuginfo::js::{ discover_debug_id, discover_sourcemap_embedded_debug_id, discover_sourcemaps_location, }; use symbolic::debuginfo::sourcebundle::SourceFileType; use url::Url; -use uuid::Uuid; use crate::api::Api; use crate::utils::enc::decode_unknown_string; @@ -790,134 +790,166 @@ impl SourceMapProcessor { continue; } - // Find or generate a debug id and determine whether we can inject the - // code snippet at the start of the source file. This is determined by whether - // we are able to adjust the sourcemap accordingly. - let (debug_id, inject_at_start) = { - match sourcemap_url { - None => { - // no source map at all, try a deterministic debug id from the contents - let debug_id = self - .sources - .get(source_url) - .map(|s| inject::debug_id_from_bytes_hashed(&s.contents)) - .unwrap_or_else(|| DebugId::from_uuid(Uuid::new_v4())); - (debug_id, false) - } - Some(sourcemap_url) => { - if let Some(encoded) = sourcemap_url.strip_prefix(DATA_PREAMBLE) { - // Handle embedded sourcemaps - - // Update the embedded sourcemap and write it back to the source file - let Ok(mut decoded) = data_encoding::BASE64.decode(encoded.as_bytes()) else { - bail!("Invalid embedded sourcemap in source file {source_url}"); - }; - - inject::insert_empty_mapping(&mut decoded)?; - let encoded = data_encoding::BASE64.encode(&decoded); - let new_sourcemap_url = format!("{DATA_PREAMBLE}{encoded}"); + // Modify the source file and the sourcemap. + // There are several cases to consider according to whether we have a sourcemap for the source file and + // whether it's embedded or external. + let debug_id = match sourcemap_url { + None => { + // Case 1: We have no sourcemap for the source file. Hash the file contents for the debug id. + let source_file = self.sources.get_mut(source_url).unwrap(); + let debug_id = inject::debug_id_from_bytes_hashed(&source_file.contents); + + // If we don't have a sourcemap, it's not safe to inject the code snippet at the beginning, + // because that would throw off all the mappings. Instead, inject the snippet at the very end. + // This isn't ideal, but it's the best we can do in this case. + inject::fixup_js_file_end(&mut source_file.contents, debug_id) + .context(format!("Failed to process {}", source_file.path.display()))?; + debug_id + } + Some(sourcemap_url) => { + if let Some(encoded) = sourcemap_url.strip_prefix(DATA_PREAMBLE) { + // Case 2: The source file has an embedded sourcemap. + + let Ok(mut decoded) = data_encoding::BASE64.decode(encoded.as_bytes()) + else { + bail!("Invalid embedded sourcemap in source file {source_url}"); + }; + + let sourcemap = SourceMap::from_slice(&decoded) + .context("Invalid embedded sourcemap in source file {source_url}")?; + + let debug_id = sourcemap + .get_debug_id() + .unwrap_or_else(|| inject::debug_id_from_bytes_hashed(&decoded)); + + let source_file = self.sources.get_mut(source_url).unwrap(); + let adjustment_map = + inject::fixup_js_file(&mut source_file.contents, debug_id).context( + format!("Failed to process {}", source_file.path.display()), + )?; + let mut adjusted_map = + SourceMap::adjust_mappings(&sourcemap, &adjustment_map); + adjusted_map.set_debug_id(Some(debug_id)); - let source_file = self.sources.get_mut(source_url).unwrap(); + decoded.clear(); + adjusted_map.to_writer(&mut decoded)?; - // hash the new source map url for the debug id - let debug_id = - inject::debug_id_from_bytes_hashed(new_sourcemap_url.as_bytes()); + let encoded = data_encoding::BASE64.encode(&decoded); + let new_sourcemap_url = format!("{DATA_PREAMBLE}{encoded}"); - inject::replace_sourcemap_url( - &mut source_file.contents, - &new_sourcemap_url, - )?; - *sourcemap_url = new_sourcemap_url; + inject::replace_sourcemap_url( + &mut source_file.contents, + &new_sourcemap_url, + )?; + *sourcemap_url = new_sourcemap_url; - (debug_id, true) - } else { - // Handle external sourcemaps - - let normalized = - inject::normalize_sourcemap_url(source_url, sourcemap_url); - let matches = inject::find_matching_paths(&sourcemaps, &normalized); - - let sourcemap_url = match &matches[..] { - [] => normalized, - [x] => x.to_string(), - _ => { - warn!("Ambiguous matches for sourcemap path {normalized}:"); - for path in matches { - warn!("{path}"); + debug_id + } else { + // Handle external sourcemaps + + let normalized = inject::normalize_sourcemap_url(source_url, sourcemap_url); + let matches = inject::find_matching_paths(&sourcemaps, &normalized); + + let sourcemap_url = match &matches[..] { + [] => normalized, + [x] => x.to_string(), + _ => { + warn!("Ambiguous matches for sourcemap path {normalized}:"); + for path in matches { + warn!("{path}"); + } + normalized + } + }; + + if self.sources.contains_key(&sourcemap_url) { + // Case 3: We have an external sourcemap for the source file. + + // We need to do a bit of a dance here because we can't mutably + // borrow the source file and the sourcemap at the same time. + let (sourcemap, debug_id, debug_id_fresh) = { + let sourcemap_file = &self.sources[&sourcemap_url]; + + let sm = SourceMap::from_slice(&sourcemap_file.contents).context( + format!("Invalid sourcemap at {}", sourcemap_file.url), + )?; + + match sm.get_debug_id() { + Some(debug_id) => (sm, debug_id, false), + None => { + let debug_id = inject::debug_id_from_bytes_hashed( + &sourcemap_file.contents, + ); + (sm, debug_id, true) } - normalized } }; - match self.sources.get_mut(&sourcemap_url) { - None => { - debug!("Sourcemap file {} not found", sourcemap_url); - // source map cannot be found, fall back to hashing the contents if - // available. The v4 fallback should not happen. - let debug_id = self - .sources - .get(source_url) - .map(|s| inject::debug_id_from_bytes_hashed(&s.contents)) - .unwrap_or_else(|| DebugId::from_uuid(Uuid::new_v4())); - (debug_id, false) - } - Some(sourcemap_file) => { - inject::insert_empty_mapping(&mut sourcemap_file.contents) - .context(format!( - "Failed to process {}", - sourcemap_file.path.display() - ))?; - - let (debug_id, sourcemap_modified) = - inject::fixup_sourcemap(&mut sourcemap_file.contents) - .context(format!( - "Failed to process {}", - sourcemap_file.path.display() - ))?; - - sourcemap_file - .headers - .push(("debug-id".to_string(), debug_id.to_string())); - - if !dry_run { - let mut file = std::fs::File::create(&sourcemap_file.path)?; - file.write_all(&sourcemap_file.contents).context( - format!( - "Failed to write sourcemap file {}", - sourcemap_file.path.display() - ), - )?; - } - - if sourcemap_modified { - report - .sourcemaps - .push((sourcemap_file.path.clone(), debug_id)); - } else { - report - .skipped_sourcemaps - .push((sourcemap_file.path.clone(), debug_id)); - } + let source_file = self.sources.get_mut(source_url).unwrap(); + let adjustment_map = + inject::fixup_js_file(&mut source_file.contents, debug_id) + .context(format!( + "Failed to process {}", + source_file.path.display() + ))?; + let mut adjusted_map = + SourceMap::adjust_mappings(&sourcemap, &adjustment_map); + adjusted_map.set_debug_id(Some(debug_id)); + + let sourcemap_file = self.sources.get_mut(&sourcemap_url).unwrap(); + sourcemap_file.contents.clear(); + adjusted_map.to_writer(&mut sourcemap_file.contents)?; + + sourcemap_file + .headers + .push(("debug-id".to_string(), debug_id.to_string())); + + if !dry_run { + let mut file = std::fs::File::create(&sourcemap_file.path)?; + file.write_all(&sourcemap_file.contents).context(format!( + "Failed to write sourcemap file {}", + sourcemap_file.path.display() + ))?; + } - (debug_id, true) - } + if debug_id_fresh { + report + .sourcemaps + .push((sourcemap_file.path.clone(), debug_id)); + } else { + report + .skipped_sourcemaps + .push((sourcemap_file.path.clone(), debug_id)); } + + debug_id + } else { + // Case 4: We have a URL for the external sourcemap, but we can't find it. + // This is substantially the same as case 1. + debug!("Sourcemap file {} not found", sourcemap_url); + // source map cannot be found, fall back to hashing the contents. + let source_file = self.sources.get_mut(source_url).unwrap(); + let debug_id = + inject::debug_id_from_bytes_hashed(&source_file.contents); + + // If we don't have a sourcemap, it's not safe to inject the code snippet at the beginning, + // because that would throw off all the mappings. Instead, inject the snippet at the very end. + // This isn't ideal, but it's the best we can do in this case. + inject::fixup_js_file_end(&mut source_file.contents, debug_id) + .context(format!( + "Failed to process {}", + source_file.path.display() + ))?; + + debug_id } } } }; - // Finally, inject the debug id and the code snippet into the source file + // Finally, some housekeeping. let source_file = self.sources.get_mut(source_url).unwrap(); - if inject_at_start { - inject::fixup_js_file(&mut source_file.contents, debug_id) - .context(format!("Failed to process {}", source_file.path.display()))?; - } else { - inject::fixup_js_file_end(&mut source_file.contents, debug_id) - .context(format!("Failed to process {}", source_file.path.display()))?; - } - source_file .headers .push(("debug-id".to_string(), debug_id.to_string())); diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index ce0d377d55..caecd9560a 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -7,18 +7,26 @@ use std::fmt; use std::io::{BufRead, Write}; use std::path::PathBuf; -use anyhow::{bail, Context, Result}; +use anyhow::Result; use lazy_static::lazy_static; -use log::debug; + +use magic_string::{GenerateDecodedMapOptions, MagicString}; use sentry::types::DebugId; -use serde_json::Value; +use sourcemap::SourceMap; const CODE_SNIPPET_TEMPLATE: &str = r#"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="__SENTRY_DEBUG_ID__")}catch(e){}}();"#; const DEBUGID_PLACEHOLDER: &str = "__SENTRY_DEBUG_ID__"; const DEBUGID_COMMENT_PREFIX: &str = "//# debugId"; lazy_static! { - static ref USE_PRAGMA_RE: Regex = Regex::new(r#"^"use \w+";|^'use \w+';"#).unwrap(); + // A regex that captures + // 1. an optional initial hashbang, + // 2. a block of line comments, block comments, and empty lines, + // 3. and an optional `"use strict";` statement.` + static ref PRE_INJECT_RE: Regex = Regex::new( + r#"^(#!.*[\n\r])?(?:\s*|/\*(?:.|\r|\n)*?\*/|//.*[\n\r])*(?:"[^"]*";|'[^']*';[\n\r]?)?"# + ) + .unwrap(); } fn print_section_with_debugid( @@ -105,110 +113,48 @@ impl fmt::Display for InjectReport { /// `[]` /// is inserted at the earliest possible position, which is after an /// optional hashbang, followed by a -/// block of comments, empty lines, and `"use […]";` or `'use […]';` pragmas. +/// block of comments, empty lines, and an optional `"use […]";` or `'use […]';` pragma. /// 2. A comment of the form `//# debugId=` is appended to the file. -/// 3. The last source mapping comment (a comment starting with -/// `//# sourceMappingURL=` or `//@ sourceMappingURL=`) is moved to -/// the very end of the file, after the debug id comment from 2. -/// -/// This function will naturally mess with the correspondence between a source file -/// and its sourcemap. Use [`insert_empty_mapping`] on the sourcemap to fix this. -/// # Example -/// ``` -/// let file = " -/// // a -/// // comment -/// // block -/// -/// // another -/// // comment -/// // block -/// -/// 'use strict'; -/// function t(t) { -/// return '[object Object]' === Object.prototype.toString.call(t); -/// } -/// //# sourceMappingURL=/path/to/sourcemap -/// "; -/// -/// let mut file = file.as_bytes().to_vec(); -/// fixup_js_file(&mut file, DebugId::default()).unwrap(); -/// -/// assert_eq!( -/// std::str::from_utf8(&file).unwrap(), -/// r#" -/// // a -/// // comment -/// // block -/// -/// // another -/// // comment -/// // block /// -/// 'use strict'; -/// !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); -/// function t(t) { -/// return '[object Object]' === Object.prototype.toString.call(t); -/// } -/// //# debugId=00000000-0000-0000-0000-000000000000 -/// //# sourceMappingURL=/path/to/sourcemap -/// "# -/// ); -/// ``` -pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result<()> { - let mut js_lines = js_contents.lines().collect::, _>>()?; +/// This function returns a [`SourceMap`] that maps locations in the injected file +/// to their corresponding places in the original file. +pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result { + let contents = std::str::from_utf8(js_contents)?; - js_contents.clear(); + let m = PRE_INJECT_RE + .find(contents) + .expect("regex is infallible") + .range(); - // Find the last source mapping URL comment, it's the only one that matters - let sourcemap_comment_idx = js_lines - .iter() - .enumerate() - .rev() - .find(|(_idx, line)| { - line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=") - }) - .map(|(idx, _)| idx); - - let sourcemap_comment = sourcemap_comment_idx.map(|idx| js_lines.remove(idx)); + let code_snippet = format!( + "\n{}\n", + CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()) + ); - let mut js_lines = js_lines.into_iter().peekable(); - - // Handle initial hashbang - if let Some(hashbang) = js_lines.next_if(|line| line.trim().starts_with("#!")) { - writeln!(js_contents, "{hashbang}")?; - } - - // Write comments and empty lines at the start back to the file - while let Some(comment_or_empty) = - js_lines.next_if(|line| line.trim().is_empty() || line.trim().starts_with("//")) - { - writeln!(js_contents, "{comment_or_empty}")?; - } + let debug_id_comment = format!("\n{DEBUGID_COMMENT_PREFIX}={debug_id}\n"); - // Write use statements back to the file - while let Some(use_pragma) = js_lines.next_if(|line| USE_PRAGMA_RE.is_match(line)) { - writeln!(js_contents, "{use_pragma}")?; - } + let mut magic = MagicString::new(contents); - // Inject the code snippet - let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()); - writeln!(js_contents, "{to_inject}")?; + magic + .append_left(m.end as u32, &code_snippet) + .unwrap() + .append(&debug_id_comment) + .unwrap(); - // Write other lines - for line in js_lines { - writeln!(js_contents, "{line}")?; - } + js_contents.clear(); + write!(js_contents, "{}", magic.to_string())?; - // Write the debug id comment - writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; + let map = magic + .generate_map(GenerateDecodedMapOptions { + source: Some("pre_injection.js".to_string()), + include_content: true, + ..Default::default() + }) + .unwrap(); - // Lastly, write the source mapping URL comment, if there was one - if let Some(sourcemap_comment) = sourcemap_comment { - writeln!(js_contents, "{sourcemap_comment}")?; - } + let map = map.to_string().unwrap(); - Ok(()) + Ok(SourceMap::from_slice(map.as_bytes()).unwrap()) } /// Fixes up a minified JS source file with a debug id without messing with mappings. @@ -231,14 +177,9 @@ pub fn fixup_js_file_end(js_contents: &mut Vec, debug_id: DebugId) -> Result js_contents.clear(); - let sourcemap_comment_idx = js_lines - .iter() - .enumerate() - .rev() - .find(|(_idx, line)| { - line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=") - }) - .map(|(idx, _)| idx); + let sourcemap_comment_idx = js_lines.iter().rposition(|line| { + line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=") + }); let sourcemap_comment = sourcemap_comment_idx.map(|idx| js_lines.remove(idx)); @@ -248,11 +189,10 @@ pub fn fixup_js_file_end(js_contents: &mut Vec, debug_id: DebugId) -> Result let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()); writeln!(js_contents, "{to_inject}")?; - writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; - if let Some(sourcemap_comment) = sourcemap_comment { writeln!(js_contents, "{sourcemap_comment}")?; } + writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; Ok(()) } @@ -264,11 +204,10 @@ pub fn fixup_js_file_end(js_contents: &mut Vec, debug_id: DebugId) -> Result pub fn replace_sourcemap_url(js_contents: &mut Vec, new_url: &str) -> Result<()> { let js_lines = js_contents.lines().collect::, _>>()?; - let sourcemap_comment_idx = match js_lines.iter().enumerate().rev().find(|(_idx, line)| { + let Some(sourcemap_comment_idx) = js_lines.iter().rposition(|line| { line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=") - }) { - Some((idx, _)) => idx, - None => return Ok(()), + }) else { + return Ok(()); }; js_contents.clear(); @@ -295,74 +234,6 @@ pub fn debug_id_from_bytes_hashed(bytes: &[u8]) -> DebugId { DebugId::from_uuid(uuid::Builder::from_sha1_bytes(sha1_bytes).into_uuid()) } -/// Fixes up a sourcemap file with a debug id. -/// -/// If the file already contains a debug id under the `debug_id` key, it is left unmodified. -/// Otherwise, a fresh debug id is inserted under that key. -/// -/// In either case, the value of the `debug_id` key is returned. -pub fn fixup_sourcemap(sourcemap_contents: &mut Vec) -> Result<(DebugId, bool)> { - match sourcemap::decode_slice(sourcemap_contents).context("Invalid sourcemap")? { - sourcemap::DecodedMap::Regular(mut sm) => { - if let Some(debug_id) = sm.get_debug_id() { - debug!("Sourcemap already has a debug id"); - Ok((debug_id, false)) - } else { - let debug_id = debug_id_from_bytes_hashed(sourcemap_contents); - sm.set_debug_id(Some(debug_id)); - - sourcemap_contents.clear(); - sm.to_writer(sourcemap_contents)?; - Ok((debug_id, true)) - } - } - sourcemap::DecodedMap::Hermes(mut smh) => { - if let Some(debug_id) = smh.get_debug_id() { - debug!("Sourcemap already has a debug id"); - Ok((debug_id, false)) - } else { - let debug_id = debug_id_from_bytes_hashed(sourcemap_contents); - smh.set_debug_id(Some(debug_id)); - - sourcemap_contents.clear(); - smh.to_writer(sourcemap_contents)?; - Ok((debug_id, true)) - } - } - sourcemap::DecodedMap::Index(_) => { - bail!("DebugId injection is not supported for sourcemap indexes") - } - } -} - -/// This adds an empty mapping at the start of a sourcemap. -/// -/// This is used to adjust a sourcemap when the corresponding source file has a -/// new line injected near the top (see [`fixup_js_file`]). -pub fn insert_empty_mapping(sourcemap_contents: &mut Vec) -> Result<()> { - let mut sourcemap: Value = serde_json::from_slice(sourcemap_contents)?; - - let Some(map) = sourcemap.as_object_mut() else { - bail!("Invalid sourcemap"); - }; - - let Some(mappings) = map.get_mut("mappings") else { - bail!("Invalid sourcemap"); - }; - - let Value::String(mappings) = mappings else { - bail!("Invalid sourcemap"); - }; - - // Insert empty mapping at the start - *mappings = format!(";{mappings}"); - - sourcemap_contents.clear(); - serde_json::to_writer(sourcemap_contents, &sourcemap)?; - - Ok(()) -} - /// Computes a normalized sourcemap URL from a source file's own URL und the relative URL of its sourcemap. /// /// Roughly, this will combine a source URL of `some/dir/source.js` and a sourcemap URL of `path/to/source.min.js` @@ -441,44 +312,12 @@ pub fn find_matching_paths(candidate_paths: &[String], expected_path: &str) -> V #[cfg(test)] mod tests { - use std::io::Write; - use sentry::types::DebugId; use crate::utils::fs::TempFile; use super::*; - #[test] - fn test_fixup_sourcemap() { - for sourcemap_path in &[ - "server/chunks/1.js.map", - "server/edge-runtime-webpack.js.map", - "server/pages/_document.js.map", - "server/pages/asdf.js.map", - "static/chunks/575-bb7d7e0e6de8d623.js.map", - "static/chunks/app/client/page-d5742c254d9533f8.js.map", - "static/chunks/pages/asdf-05b39167abbe433b.js.map", - ] { - let mut sourcemap_contents = std::fs::read(format!( - "tests/integration/_fixtures/inject/{sourcemap_path}" - )) - .unwrap(); - - assert!( - sourcemap::decode_slice(&sourcemap_contents).is_ok(), - "sourcemap is valid before injection" - ); - - fixup_sourcemap(&mut sourcemap_contents).unwrap(); - - assert!( - sourcemap::decode_slice(&sourcemap_contents).is_ok(), - "sourcemap is valid after injection" - ); - } - } - #[test] fn test_fixup_js_file() { let source = r#"//# sourceMappingURL=fake1 @@ -494,12 +333,13 @@ something else"#; fixup_js_file(&mut source, debug_id).unwrap(); let expected = r#"//# sourceMappingURL=fake1 + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); some line //# sourceMappingURL=fake2 +//# sourceMappingURL=real something else //# debugId=00000000-0000-0000-0000-000000000000 -//# sourceMappingURL=real "#; assert_eq!(std::str::from_utf8(&source).unwrap(), expected); @@ -547,6 +387,7 @@ something else"#; let expected = r#"//# sourceMappingURL=fake + !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); some line //# sourceMappingURL=fake @@ -562,9 +403,9 @@ some line //# sourceMappingURL=fake //# sourceMappingURL=fake //# sourceMappingURL=fake +//# sourceMappingURL=real something else //# debugId=00000000-0000-0000-0000-000000000000 -//# sourceMappingURL=real "#; println!("{}", result); @@ -594,14 +435,15 @@ something else"#; //# sourceMappingURL=fake1 // some other comment -"use strict"; rest of the line -'use strict'; +"use strict"; !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); + rest of the line +'use strict'; some line //# sourceMappingURL=fake2 +//# sourceMappingURL=real something else //# debugId=00000000-0000-0000-0000-000000000000 -//# sourceMappingURL=real "#; assert_eq!(std::str::from_utf8(&source).unwrap(), expected); @@ -630,14 +472,15 @@ something else"#; //# sourceMappingURL=fake1 // some other comment -"use strict"; rest of the line +"use strict"; !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="00000000-0000-0000-0000-000000000000")}catch(e){}}(); + rest of the line (this.foo=this.bar||[]).push([[2],[function(e,t,n){"use strict"; […] } some line //# sourceMappingURL=fake2 +//# sourceMappingURL=real something else //# debugId=00000000-0000-0000-0000-000000000000 -//# sourceMappingURL=real "#; assert_eq!(std::str::from_utf8(&source).unwrap(), expected); diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd new file mode 100644 index 0000000000..adcd32fa2a --- /dev/null +++ b/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd @@ -0,0 +1,32 @@ +``` +$ sentry-cli sourcemaps inject . +? success +> Searching . +> Found 18 files +> Analyzing 18 sources +> Injecting debug ids + +Source Map Debug ID Injection Report + Modified: The following source files have been modified to have debug ids + [..]-[..]-[..]-[..]-[..] - ./esbuild/cjs.js + [..]-[..]-[..]-[..]-[..] - ./esbuild/iife.js + [..]-[..]-[..]-[..]-[..] - ./rollup/cjs.js + [..]-[..]-[..]-[..]-[..] - ./rollup/iife.js + [..]-[..]-[..]-[..]-[..] - ./rspack/iife.js + [..]-[..]-[..]-[..]-[..] - ./vite/cjs.js + [..]-[..]-[..]-[..]-[..] - ./vite/iife.js + [..]-[..]-[..]-[..]-[..] - ./webpack/cjs.js + [..]-[..]-[..]-[..]-[..] - ./webpack/iife.js + Modified: The following sourcemap files have been modified to have debug ids + [..]-[..]-[..]-[..]-[..] - ./esbuild/cjs.js.map + [..]-[..]-[..]-[..]-[..] - ./esbuild/iife.js.map + [..]-[..]-[..]-[..]-[..] - ./rollup/cjs.js.map + [..]-[..]-[..]-[..]-[..] - ./rollup/iife.js.map + [..]-[..]-[..]-[..]-[..] - ./rspack/iife.js.map + [..]-[..]-[..]-[..]-[..] - ./vite/cjs.js.map + [..]-[..]-[..]-[..]-[..] - ./vite/iife.js.map + [..]-[..]-[..]-[..]-[..] - ./webpack/cjs.js.map + [..]-[..]-[..]-[..]-[..] - ./webpack/iife.js.map + + +``` diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js new file mode 100644 index 0000000000..4cefd96ce3 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js @@ -0,0 +1,2 @@ +"use strict";function t(r,o){r(o)}function n(r,o){t(r,o)}function f(r,o){n(r,o)}f(function(o){throw new Error(o)},"boop"); +//# sourceMappingURL=cjs.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.expected b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.expected new file mode 100644 index 0000000000..37df167818 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.expected @@ -0,0 +1,6 @@ +"use strict"; +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a9f9a996-4e6c-5119-b8b8-e64559a6554c")}catch(e){}}(); +function t(r,o){r(o)}function n(r,o){t(r,o)}function f(r,o){n(r,o)}f(function(o){throw new Error(o)},"boop"); +//# sourceMappingURL=cjs.js.map + +//# debugId=a9f9a996-4e6c-5119-b8b8-e64559a6554c diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map new file mode 100644 index 0000000000..0bed964c81 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../src/bar.js", "../src/foo.js", "../src/index.js"], + "sourcesContent": ["export function bar(fn, msg) {\n fn(msg);\n}\n", "import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n", "\"use strict\";\nimport { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"], + "mappings": "aAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIC,EAAIC,EAAK,CAC3BC,EAAIF,EAAIC,CAAG,CACb,CCDA,SAASE,EAAIC,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAF,EAAI,SAAeE,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM", + "names": ["bar", "fn", "msg", "foo", "fn", "msg", "bar", "wat", "fn", "msg", "foo"] +} diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected new file mode 100644 index 0000000000..23d0396923 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected @@ -0,0 +1 @@ +{"version":3,"sources":["../src/bar.js","../src/foo.js","../src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","\"use strict\";\nimport { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","wat"],"mappings":";;AAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIF,EAAIC,EAAK,CAC3BF,EAAIC,EAAIC,CAAG,CACb,CCDA,SAASE,EAAIH,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAE,EAAI,SAAeF,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM","debug_id":"a9f9a996-4e6c-5119-b8b8-e64559a6554c"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js new file mode 100644 index 0000000000..5a2e8ddc4f --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js @@ -0,0 +1,2 @@ +(()=>{function t(r,o){r(o)}function n(r,o){t(r,o)}function f(r,o){n(r,o)}f(function(o){throw new Error(o)},"boop");})(); +//# sourceMappingURL=iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.expected b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.expected new file mode 100644 index 0000000000..d71c244aa9 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.expected @@ -0,0 +1,6 @@ + +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="dd751360-5eae-531d-87f4-5e00c846a9a3")}catch(e){}}(); +(()=>{function t(r,o){r(o)}function n(r,o){t(r,o)}function f(r,o){n(r,o)}f(function(o){throw new Error(o)},"boop");})(); +//# sourceMappingURL=iife.js.map + +//# debugId=dd751360-5eae-531d-87f4-5e00c846a9a3 diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map new file mode 100644 index 0000000000..1abf784ae5 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../src/bar.js", "../src/foo.js", "../src/index.js"], + "sourcesContent": ["export function bar(fn, msg) {\n fn(msg);\n}\n", "import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n", "import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"], + "mappings": "MAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIC,EAAIC,EAAK,CAC3BC,EAAIF,EAAIC,CAAG,CACb,CCFA,SAASE,EAAIC,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAF,EAAI,SAAeE,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM", + "names": ["bar", "fn", "msg", "foo", "fn", "msg", "bar", "wat", "fn", "msg", "foo"] +} diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected new file mode 100644 index 0000000000..fdb4ae06b3 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected @@ -0,0 +1 @@ +{"version":3,"sources":["../src/bar.js","../src/foo.js","../src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","wat"],"mappings":";;MAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIF,EAAIC,EAAK,CAC3BF,EAAIC,EAAIC,CAAG,CACb,CCFA,SAASE,EAAIH,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAE,EAAI,SAAeF,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM","debug_id":"dd751360-5eae-531d-87f4-5e00c846a9a3"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js new file mode 100644 index 0000000000..d82bf1700b --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js @@ -0,0 +1,2 @@ +"use strict";var n;n=function(n){throw new Error(n)},function(n,o){!function(n,o){n(o)}(n,o)}(n,"boop"); +//# sourceMappingURL=cjs.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.expected b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.expected new file mode 100644 index 0000000000..e33c27ab41 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.expected @@ -0,0 +1,6 @@ +"use strict"; +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="0b6cf2c0-b31e-5bb4-9e50-a0c0fd4837db")}catch(e){}}(); +var n;n=function(n){throw new Error(n)},function(n,o){!function(n,o){n(o)}(n,o)}(n,"boop"); +//# sourceMappingURL=cjs.js.map + +//# debugId=0b6cf2c0-b31e-5bb4-9e50-a0c0fd4837db diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map new file mode 100644 index 0000000000..e56f18ee4a --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rollup.bundle.js","sources":["../src/index.js","../src/foo.js","../src/bar.js"],"sourcesContent":["import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","export function bar(fn, msg) {\n fn(msg);\n}\n"],"names":["fn","msg","Error","bar","foo"],"mappings":"aAEA,IAAaA,IAIT,SAAeC,GACjB,MAAM,IAAIC,MAAMD,EAClB,ECNO,SAAaD,EAAIC,ICFjB,SAAaD,EAAIC,GACtBD,EAAGC,EACL,CDCEE,CAAIH,EAAIC,EACV,CDDEG,CAAIJ,EAKH"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map.expected new file mode 100644 index 0000000000..cf3fe4552a --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"rollup.bundle.js","sources":["../src/index.js","../src/foo.js","../src/bar.js"],"sourcesContent":["import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","export function bar(fn, msg) {\n fn(msg);\n}\n"],"names":["fn","msg","Error","bar","foo"],"mappings":";;AAEA,IAAaA,IAIT,SAAeC,GACjB,MAAM,IAAIC,MAAMD,EAClB,ECNO,SAAaD,EAAIC,ICFjB,SAAaD,EAAIC,GACtBD,EAAGC,EACL,CDCEE,CAAIH,EAAIC,EACV,CDDEG,CAAIJ,EAKH","debug_id":"0b6cf2c0-b31e-5bb4-9e50-a0c0fd4837db"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/iife.js b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js new file mode 100644 index 0000000000..494c5d5c65 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js @@ -0,0 +1,2 @@ +!function(){"use strict";var n;n=function(n){throw new Error(n)},function(n,o){!function(n,o){n(o)}(n,o)}(n,"boop")}(); +//# sourceMappingURL=iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.expected b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.expected new file mode 100644 index 0000000000..7faa91814a --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.expected @@ -0,0 +1,6 @@ + +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6cde0fde-8646-5aa5-90be-6540abac2d15")}catch(e){}}(); +!function(){"use strict";var n;n=function(n){throw new Error(n)},function(n,o){!function(n,o){n(o)}(n,o)}(n,"boop")}(); +//# sourceMappingURL=iife.js.map + +//# debugId=6cde0fde-8646-5aa5-90be-6540abac2d15 diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map new file mode 100644 index 0000000000..24a810b6f8 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rollup.bundle.js","sources":["../src/index.js","../src/foo.js","../src/bar.js"],"sourcesContent":["import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","export function bar(fn, msg) {\n fn(msg);\n}\n"],"names":["fn","msg","Error","bar","foo"],"mappings":"yBAEA,IAAaA,IAIT,SAAeC,GACjB,MAAM,IAAIC,MAAMD,EAClB,ECNO,SAAaD,EAAIC,ICFjB,SAAaD,EAAIC,GACtBD,EAAGC,EACL,CDCEE,CAAIH,EAAIC,EACV,CDDEG,CAAIJ,EAKH"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map.expected new file mode 100644 index 0000000000..9596026461 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"rollup.bundle.js","sources":["../src/index.js","../src/foo.js","../src/bar.js"],"sourcesContent":["import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","export function bar(fn, msg) {\n fn(msg);\n}\n"],"names":["fn","msg","Error","bar","foo"],"mappings":";;yBAEA,IAAaA,IAIT,SAAeC,GACjB,MAAM,IAAIC,MAAMD,EAClB,ECNO,SAAaD,EAAIC,ICFjB,SAAaD,EAAIC,GACtBD,EAAGC,EACL,CDCEE,CAAIH,EAAIC,EACV,CDDEG,CAAIJ,EAKH","debug_id":"6cde0fde-8646-5aa5-90be-6540abac2d15"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/iife.js b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js new file mode 100644 index 0000000000..395f28e153 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js @@ -0,0 +1,2 @@ +!function(){var e={62:function(e,r,t){"use strict";function n(e,r){e(r)}Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"bar",{enumerable:!0,get:function(){return n}})},447:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"foo",{enumerable:!0,get:function(){return o}});var n=t("62");function o(e,r){(0,n.bar)(e,r)}},151:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n,o,u=t("447");n=function(e){throw Error(e)},o="boop",(0,u.foo)(n,o)}},r={};!function t(n){var o=r[n];if(void 0!==o)return o.exports;var u=r[n]={exports:{}};return e[n](u,u.exports,t),u.exports}("151")}(); +//# sourceMappingURL=iife.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.expected b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.expected new file mode 100644 index 0000000000..8f5664f371 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.expected @@ -0,0 +1,5 @@ + +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d50bd339-0bfa-5b90-9c5f-479cf9c0c40c")}catch(e){}}(); +!function(){var e={62:function(e,r,t){"use strict";function n(e,r){e(r)}Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"bar",{enumerable:!0,get:function(){return n}})},447:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"foo",{enumerable:!0,get:function(){return o}});var n=t("62");function o(e,r){(0,n.bar)(e,r)}},151:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n,o,u=t("447");n=function(e){throw Error(e)},o="boop",(0,u.foo)(n,o)}},r={};!function t(n){var o=r[n];if(void 0!==o)return o.exports;var u=r[n]={exports:{}};return e[n](u,u.exports,t),u.exports}("151")}(); +//# sourceMappingURL=iife.js.map +//# debugId=d50bd339-0bfa-5b90-9c5f-479cf9c0c40c diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map new file mode 100644 index 0000000000..2b0f39cf8e --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map @@ -0,0 +1 @@ +{"version":3,"file":"rspack.bundle.js","sources":["./src/bar.js","./src/foo.js","./src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","Error"],"mappings":"mDAAO,SAASA,EAAIC,CAAE,CAAEC,CAAG,EACzBD,EAAGC,EACL,C,yEAFgB,O,oCAAAF,C,+GCEA,O,oCAAAG,C,kBAAT,SAASA,EAAIF,CAAE,CAAEC,CAAG,EACzB,KAAAF,GAAA,EAAIC,EAAIC,EACV,C,wFCFaD,EAAIC,E,WAAJD,EAIT,SAAeC,CAAG,EACpB,MAAM,AAAIE,MAAMF,EAClB,EANiBA,EAMd,OALD,KAAAC,GAAA,EAAIF,EAAIC,E"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map.expected new file mode 100644 index 0000000000..2d96546c22 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"rspack.bundle.js","sources":["./src/bar.js","./src/foo.js","./src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","Error"],"mappings":";;mDAAO,SAASA,EAAIC,CAAE,CAAEC,CAAG,EACzBD,EAAGC,EACL,C,yEAFgB,O,oCAAAF,C,+GCEA,O,oCAAAG,C,kBAAT,SAASA,EAAIF,CAAE,CAAEC,CAAG,EACzB,KAAAF,GAAA,EAAIC,EAAIC,EACV,C,wFCFaD,EAAIC,E,WAAJD,EAIT,SAAeC,CAAG,EACpB,MAAM,AAAIE,MAAMF,EAClB,EANiBA,EAMd,OALD,KAAAC,GAAA,EAAIF,EAAIC,E","debug_id":"d50bd339-0bfa-5b90-9c5f-479cf9c0c40c"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/vite/cjs.js b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js new file mode 100644 index 0000000000..a45ce18ef9 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js @@ -0,0 +1,2 @@ +"use strict";function t(n,o){n(o)}function r(n,o){t(n,o)}function c(n,o){r(n,o)}c(function(o){throw new Error(o)},"boop"); +//# sourceMappingURL=cjs.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.expected b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.expected new file mode 100644 index 0000000000..bfb4ba0827 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.expected @@ -0,0 +1,6 @@ +"use strict"; +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c2fca958-c33e-5626-90a1-c6ce633b1f55")}catch(e){}}(); +function t(n,o){n(o)}function r(n,o){t(n,o)}function c(n,o){r(n,o)}c(function(o){throw new Error(o)},"boop"); +//# sourceMappingURL=cjs.js.map + +//# debugId=c2fca958-c33e-5626-90a1-c6ce633b1f55 diff --git a/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map new file mode 100644 index 0000000000..c15d0dd0ee --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"vite.bundle.js","sources":["../src/bar.js","../src/foo.js","../src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","wat"],"mappings":"aAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIF,EAAIC,EAAK,CAC3BF,EAAIC,EAAIC,CAAG,CACb,CCFA,SAASE,EAAIH,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAE,EAAI,SAAeF,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map.expected b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map.expected new file mode 100644 index 0000000000..2b542ccac4 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"vite.bundle.js","sources":["../src/bar.js","../src/foo.js","../src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","wat"],"mappings":";;AAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIF,EAAIC,EAAK,CAC3BF,EAAIC,EAAIC,CAAG,CACb,CCFA,SAASE,EAAIH,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAE,EAAI,SAAeF,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM","debug_id":"c2fca958-c33e-5626-90a1-c6ce633b1f55"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/vite/iife.js b/tests/integration/_fixtures/inject_bundlers/vite/iife.js new file mode 100644 index 0000000000..9338ed0f5c --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/iife.js @@ -0,0 +1,2 @@ +(function(){"use strict";function t(n,o){n(o)}function c(n,o){t(n,o)}function f(n,o){c(n,o)}f(function(o){throw new Error(o)},"boop")})(); +//# sourceMappingURL=iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/vite/iife.js.expected b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.expected new file mode 100644 index 0000000000..35fc4c78d4 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.expected @@ -0,0 +1,6 @@ + +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="61108b96-d9cb-5d14-a1a1-cc066b34c428")}catch(e){}}(); +(function(){"use strict";function t(n,o){n(o)}function c(n,o){t(n,o)}function f(n,o){c(n,o)}f(function(o){throw new Error(o)},"boop")})(); +//# sourceMappingURL=iife.js.map + +//# debugId=61108b96-d9cb-5d14-a1a1-cc066b34c428 diff --git a/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map new file mode 100644 index 0000000000..3ebd65a71f --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map @@ -0,0 +1 @@ +{"version":3,"file":"vite.bundle.js","sources":["../src/bar.js","../src/foo.js","../src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","wat"],"mappings":"yBAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIF,EAAIC,EAAK,CAC3BF,EAAIC,EAAIC,CAAG,CACb,CCFA,SAASE,EAAIH,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAE,EAAI,SAAeF,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map.expected b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map.expected new file mode 100644 index 0000000000..38a4f2eaa6 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"vite.bundle.js","sources":["../src/bar.js","../src/foo.js","../src/index.js"],"sourcesContent":["export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["bar","fn","msg","foo","wat"],"mappings":";;yBAAO,SAASA,EAAIC,EAAIC,EAAK,CAC3BD,EAAGC,CAAG,CACR,CCAO,SAASC,EAAIF,EAAIC,EAAK,CAC3BF,EAAIC,EAAIC,CAAG,CACb,CCFA,SAASE,EAAIH,EAAIC,EAAK,CACpBC,EAAIF,EAAIC,CAAG,CACb,CAEAE,EAAI,SAAeF,EAAK,CACtB,MAAM,IAAI,MAAMA,CAAG,CACrB,EAAG,MAAM","debug_id":"61108b96-d9cb-5d14-a1a1-cc066b34c428"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js new file mode 100644 index 0000000000..1f05989cf3 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js @@ -0,0 +1,2 @@ +"use strict";var __webpack_require__={r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},__webpack_exports__={};function bar(e,o){e(o)}function foo(e,o){bar(e,o)}function wat(e,o){foo(e,o)}__webpack_require__.r(__webpack_exports__),wat((function(e){throw new Error(e)}),"boop"),module.exports=__webpack_exports__; +//# sourceMappingURL=cjs.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.expected b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.expected new file mode 100644 index 0000000000..de95a0bbc1 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.expected @@ -0,0 +1,5 @@ +"use strict"; +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="feff3330-3acf-5df7-9a95-97b3da52cb8a")}catch(e){}}(); +var __webpack_require__={r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},__webpack_exports__={};function bar(e,o){e(o)}function foo(e,o){bar(e,o)}function wat(e,o){foo(e,o)}__webpack_require__.r(__webpack_exports__),wat((function(e){throw new Error(e)}),"boop"),module.exports=__webpack_exports__; +//# sourceMappingURL=cjs.js.map +//# debugId=feff3330-3acf-5df7-9a95-97b3da52cb8a diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map new file mode 100644 index 0000000000..67972f9e22 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"webpack.bundle.js","mappings":"aACA,IAAIA,oBAAsB,CCA1BA,EAAyBC,IACH,oBAAXC,QAA0BA,OAAOC,aAC1CC,OAAOC,eAAeJ,EAASC,OAAOC,YAAa,CAAEG,MAAO,WAE7DF,OAAOC,eAAeJ,EAAS,aAAc,CAAEK,OAAO,GAAO,G,uBCLvD,SAASC,IAAIC,EAAIC,GACtBD,EAAGC,EACL,CCAO,SAASC,IAAIF,EAAIC,GACtBF,IAAIC,EAAIC,EACV,CCFA,SAASE,IAAIH,EAAIC,GACfC,IAAIF,EAAIC,EACV,C,2CAEAE,KAAI,SAAeF,GACjB,MAAM,IAAIG,MAAMH,EAClB,GAAG,Q","sources":["webpack://sourcemaps-playground/webpack/bootstrap","webpack://sourcemaps-playground/webpack/runtime/make namespace object","webpack://sourcemaps-playground/./src/bar.js","webpack://sourcemaps-playground/./src/foo.js","webpack://sourcemaps-playground/./src/index.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["__webpack_require__","exports","Symbol","toStringTag","Object","defineProperty","value","bar","fn","msg","foo","wat","Error"],"sourceRoot":""} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map.expected b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map.expected new file mode 100644 index 0000000000..c4140e9d1c --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"webpack.bundle.js","sources":["webpack://sourcemaps-playground/webpack/bootstrap","webpack://sourcemaps-playground/webpack/runtime/make namespace object","webpack://sourcemaps-playground/./src/bar.js","webpack://sourcemaps-playground/./src/foo.js","webpack://sourcemaps-playground/./src/index.js"],"sourceRoot":"","sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export function bar(fn, msg) {\n fn(msg);\n}\n","import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["__webpack_require__","exports","Symbol","toStringTag","Object","defineProperty","value","bar","fn","msg","foo","wat","Error"],"mappings":";;AACA,IAAIA,oBAAsB,CCA1BA,EAAyBC,IACH,oBAAXC,QAA0BA,OAAOC,aAC1CC,OAAOC,eAAeJ,EAASC,OAAOC,YAAa,CAAEG,MAAO,WAE7DF,OAAOC,eAAeJ,EAAS,aAAc,CAAEK,OAAO,GAAO,G,uBCLvD,SAASC,IAAIC,EAAIC,GACtBD,EAAGC,EACL,CCAO,SAASC,IAAIF,EAAIC,GACtBF,IAAIC,EAAIC,EACV,CCFA,SAASE,IAAIH,EAAIC,GACfC,IAAIF,EAAIC,EACV,C,2CAEAE,KAAI,SAAeF,GACjB,MAAM,IAAIG,MAAMH,EAClB,GAAG,Q","debug_id":"feff3330-3acf-5df7-9a95-97b3da52cb8a"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/iife.js b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js new file mode 100644 index 0000000000..17191dfcbd --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js @@ -0,0 +1,2 @@ +(()=>{"use strict";(function(n,o){!function(n,o){n(o)}(n,"boop")})((function(n){throw new Error(n)}))})(); +//# sourceMappingURL=iife.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.expected b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.expected new file mode 100644 index 0000000000..ec194a3e44 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.expected @@ -0,0 +1,5 @@ + +!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="397f1037-b958-54cc-bc62-267d5b7aff25")}catch(e){}}(); +(()=>{"use strict";(function(n,o){!function(n,o){n(o)}(n,"boop")})((function(n){throw new Error(n)}))})(); +//# sourceMappingURL=iife.js.map +//# debugId=397f1037-b958-54cc-bc62-267d5b7aff25 diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map new file mode 100644 index 0000000000..2c478f2c4e --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map @@ -0,0 +1 @@ +{"version":3,"file":"webpack.bundle.js","mappings":"oBAEO,SAAaA,EAAIC,ICFjB,SAAaD,EAAIC,GACtBD,EAAGC,EACL,CDCEC,CAAIF,EEKH,OFJH,EEDEG,EAGE,SAAeF,GACjB,MAAM,IAAIG,MAAMH,EAClB,G","sources":["webpack://sourcemaps-playground/./src/foo.js","webpack://sourcemaps-playground/./src/bar.js","webpack://sourcemaps-playground/./src/index.js"],"sourcesContent":["import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","export function bar(fn, msg) {\n fn(msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["fn","msg","bar","foo","Error"],"sourceRoot":""} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map.expected b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map.expected new file mode 100644 index 0000000000..fb7c700e79 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map.expected @@ -0,0 +1 @@ +{"version":3,"file":"webpack.bundle.js","sources":["webpack://sourcemaps-playground/./src/foo.js","webpack://sourcemaps-playground/./src/bar.js","webpack://sourcemaps-playground/./src/index.js"],"sourceRoot":"","sourcesContent":["import { bar } from './bar.js';\n\nexport function foo(fn, msg) {\n bar(fn, msg);\n}\n","export function bar(fn, msg) {\n fn(msg);\n}\n","import { foo } from './foo.js';\n\nfunction wat(fn, msg) {\n foo(fn, msg);\n}\n\nwat(function hello(msg) {\n throw new Error(msg);\n}, 'boop');\n"],"names":["fn","msg","bar","foo","Error"],"mappings":";;oBAEO,SAAaA,EAAIC,ICFjB,SAAaD,EAAIC,GACtBD,EAAGC,EACL,CDCEC,CAAIF,EEKH,OFJH,EEDEG,EAGE,SAAeF,GACjB,MAAM,IAAIG,MAAMH,EAClB,G","debug_id":"397f1037-b958-54cc-bc62-267d5b7aff25"} \ No newline at end of file diff --git a/tests/integration/sourcemaps/inject.rs b/tests/integration/sourcemaps/inject.rs index 92af1d47ee..ceb1ea9348 100644 --- a/tests/integration/sourcemaps/inject.rs +++ b/tests/integration/sourcemaps/inject.rs @@ -58,33 +58,7 @@ fn command_sourcemaps_inject_output_embedded() { ) .unwrap(); - // Check mappings before injection - let contents = std::fs::read_to_string(testcase_cwd_path.join("dummy_embedded.js")).unwrap(); - let encoded_sourcemap = contents - .lines() - .find_map(|line| line.strip_prefix("//# sourceMappingURL=data:application/json;base64,")) - .unwrap(); - - let decoded = data_encoding::BASE64 - .decode(encoded_sourcemap.as_bytes()) - .unwrap(); - let parsed: serde_json::Value = serde_json::from_slice(&decoded).unwrap(); - assert_eq!(parsed["mappings"], ";;;"); - register_test("sourcemaps/sourcemaps-inject-embedded.trycmd"); - - // Check mappings after injection - let contents = std::fs::read_to_string(testcase_cwd_path.join("dummy_embedded.js")).unwrap(); - let encoded_sourcemap = contents - .lines() - .find_map(|line| line.strip_prefix("//# sourceMappingURL=data:application/json;base64,")) - .unwrap(); - - let decoded = data_encoding::BASE64 - .decode(encoded_sourcemap.as_bytes()) - .unwrap(); - let parsed: serde_json::Value = serde_json::from_slice(&decoded).unwrap(); - assert_eq!(parsed["mappings"], ";;;;"); } #[test] @@ -117,3 +91,57 @@ fn command_sourcemaps_inject_output_split_ambiguous() { register_test("sourcemaps/sourcemaps-inject-split-ambiguous.trycmd"); } + +#[test] +fn command_sourcemaps_inject_bundlers() { + let testcase_cwd_path = "tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.in/"; + if std::path::Path::new(testcase_cwd_path).exists() { + remove_dir_all(testcase_cwd_path).unwrap(); + } + copy_recursively( + "tests/integration/_fixtures/inject_bundlers/", + testcase_cwd_path, + ) + .unwrap(); + + register_test("sourcemaps/sourcemaps-inject-bundlers.trycmd"); + + // IIFE tests + for bundler in ["esbuild", "rollup", "rspack", "vite", "webpack"] { + let actual_code = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/iife.js")).unwrap(); + let expected_code = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/iife.js.expected")) + .unwrap(); + + assert_eq!(actual_code, expected_code); + + let actual_map = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/iife.js.map")).unwrap(); + let expected_map = std::fs::read_to_string(format!( + "{testcase_cwd_path}/{bundler}/iife.js.map.expected" + )) + .unwrap(); + + assert_eq!(actual_map, expected_map); + } + + // CJS tests. Not sure how to make this happen for rspack. + for bundler in ["esbuild", "rollup", "vite", "webpack"] { + let actual_code = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/cjs.js")).unwrap(); + let expected_code = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/cjs.js.expected")) + .unwrap(); + + assert_eq!(actual_code, expected_code); + + let actual_map = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/cjs.js.map")).unwrap(); + let expected_map = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/cjs.js.map.expected")) + .unwrap(); + + assert_eq!(actual_map, expected_map); + } +}