From 84fd0bfc6f0db3b40e569e72bf4087032337dfd6 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 7 Jul 2023 14:28:14 +0200 Subject: [PATCH 01/13] WIP --- src/utils/sourcemaps/inject.rs | 112 ++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 24 deletions(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 8ab44728ac..a02ab658a1 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -19,7 +19,15 @@ const SOURCEMAP_DEBUGID_KEY: &str = "debug_id"; const DEBUGID_COMMENT_PREFIX: &str = "//# debugId"; lazy_static! { +<<<<<<< Updated upstream static ref USE_PRAGMA_RE: Regex = Regex::new(r#"^"use \w+";|^'use \w+';"#).unwrap(); +======= + static ref USE_PRAGMA_RE: Regex = Regex::new(r#""use \w+";|'use \w+';"#).unwrap(); + static ref TEST_RE: Regex = Regex::new( + r#"^(#!.*[\n\r])?(?:\s*|/\*(?:.|\r|\n)*?\*/|//.*[\n\r])*(?:"[^"]*";|'[^']*';)?"# + ) + .unwrap(); +>>>>>>> Stashed changes } fn print_section_with_debugid( @@ -157,12 +165,26 @@ impl fmt::Display for InjectReport { /// ); /// ``` pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result<()> { - let mut js_lines = js_contents.lines().collect::, _>>()?; - + let contents = String::from_utf8(js_contents.clone())?; js_contents.clear(); + let m = TEST_RE + .find(&contents) + .expect("regex is infallible") + .range(); + + dbg!(&contents); + + write!(js_contents, "{}", &contents[m.clone()])?; + if ![b'\n', b'\r'].contains(&js_contents[js_contents.len() - 1]) { + writeln!(js_contents)?; + } + + let rest = &contents[m.end..]; + let mut rest_lines = rest.lines().map(String::from).collect::>(); + // Find the last source mapping URL comment, it's the only one that matters - let sourcemap_comment_idx = js_lines + let sourcemap_comment_idx = rest_lines .iter() .enumerate() .rev() @@ -171,45 +193,70 @@ pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result<()> }) .map(|(idx, _)| idx); - let sourcemap_comment = sourcemap_comment_idx.map(|idx| js_lines.remove(idx)); + let sourcemap_comment = sourcemap_comment_idx.map(|idx| rest_lines.remove(idx)); - 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}")?; - } - - // 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}")?; - } + dbg!(&sourcemap_comment); + println!("{}", std::str::from_utf8(js_contents).unwrap()); // Inject the code snippet let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()); writeln!(js_contents, "{to_inject}")?; + println!("{}", std::str::from_utf8(js_contents).unwrap()); - // Write other lines - for line in js_lines { + for line in rest_lines { writeln!(js_contents, "{line}")?; } + println!("{}", std::str::from_utf8(js_contents).unwrap()); // Write the debug id comment writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; + println!("{}", std::str::from_utf8(js_contents).unwrap()); // Lastly, write the source mapping URL comment, if there was one if let Some(sourcemap_comment) = sourcemap_comment { writeln!(js_contents, "{sourcemap_comment}")?; + println!("{}", std::str::from_utf8(js_contents).unwrap()); } Ok(()) + + // 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}")?; + // } + + // // 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}")?; + // } + + // // Inject the code snippet + // let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()); + // writeln!(js_contents, "{to_inject}")?; + + // // Write other lines + // for line in js_lines { + // writeln!(js_contents, "{line}")?; + // } + + // // Write the debug id comment + // writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; + + // // Lastly, write the source mapping URL comment, if there was one + // if let Some(sourcemap_comment) = sourcemap_comment { + // writeln!(js_contents, "{sourcemap_comment}")?; + // } + + // Ok(()) } /// Fixes up a minified JS source file with a debug id without messing with mappings. @@ -756,4 +803,21 @@ more text &["./project/maps/page/index.js.map"] ); } + + #[test] + fn test_regex() { + let source = r#"#!/bin/node +//# sourceMappingURL=fake1 + + // some other comment + "use strict"; rest of the line +'use strict'; +some line +//# sourceMappingURL=fake2 +//# sourceMappingURL=real +something else"#; + + let m = TEST_RE.find(source).unwrap(); + dbg!(&source[m.range()]); + } } From a75de258128f2a637a5f83bd2b2e76f7ea0d53b0 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Thu, 20 Jul 2023 14:30:04 +0200 Subject: [PATCH 02/13] WIP --- Cargo.lock | 20 +++++++ Cargo.toml | 1 + src/utils/sourcemaps/inject.rs | 103 ++++++++++++++------------------- 3 files changed, 65 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e9a354834..d75b2485a2 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", @@ -2946,6 +2960,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 1edac83a7f..1cb46095fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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/inject.rs b/src/utils/sourcemaps/inject.rs index a02ab658a1..86ed5ea7ff 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -10,6 +10,7 @@ use std::path::PathBuf; use anyhow::{bail, Result}; use lazy_static::lazy_static; use log::debug; +use magic_string::{GenerateDecodedMapOptions, MagicString}; use sentry::types::DebugId; use serde_json::Value; @@ -19,15 +20,11 @@ const SOURCEMAP_DEBUGID_KEY: &str = "debug_id"; const DEBUGID_COMMENT_PREFIX: &str = "//# debugId"; lazy_static! { -<<<<<<< Updated upstream static ref USE_PRAGMA_RE: Regex = Regex::new(r#"^"use \w+";|^'use \w+';"#).unwrap(); -======= - static ref USE_PRAGMA_RE: Regex = Regex::new(r#""use \w+";|'use \w+';"#).unwrap(); static ref TEST_RE: Regex = Regex::new( - r#"^(#!.*[\n\r])?(?:\s*|/\*(?:.|\r|\n)*?\*/|//.*[\n\r])*(?:"[^"]*";|'[^']*';)?"# + r#"^(#!.*[\n\r])?(?:\s*|/\*(?:.|\r|\n)*?\*/|//.*[\n\r])*(?:"[^"]*";|'[^']*';)?[\n\r]?"# ) .unwrap(); ->>>>>>> Stashed changes } fn print_section_with_debugid( @@ -164,7 +161,10 @@ impl fmt::Display for InjectReport { /// "# /// ); /// ``` -pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result<()> { +pub fn fixup_js_file( + js_contents: &mut Vec, + debug_id: DebugId, +) -> Result { let contents = String::from_utf8(js_contents.clone())?; js_contents.clear(); @@ -173,52 +173,27 @@ pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result<()> .expect("regex is infallible") .range(); - dbg!(&contents); - - write!(js_contents, "{}", &contents[m.clone()])?; - if ![b'\n', b'\r'].contains(&js_contents[js_contents.len() - 1]) { - writeln!(js_contents)?; - } - - let rest = &contents[m.end..]; - let mut rest_lines = rest.lines().map(String::from).collect::>(); - - // Find the last source mapping URL comment, it's the only one that matters - let sourcemap_comment_idx = rest_lines - .iter() - .enumerate() - .rev() - .find(|(_idx, line)| { - line.starts_with("//# sourceMappingURL=") || line.starts_with("//@ sourceMappingURL=") + let mut magic = MagicString::new(&contents); + + let to_inject = format!( + "\n{}\n", + CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()) + ); + magic + .append_left(m.end as u32, &to_inject) + .unwrap() + .append(&format!("\n{DEBUGID_COMMENT_PREFIX}={debug_id}\n")) + .unwrap(); + + write!(js_contents, "{}", magic.to_string())?; + + Ok(magic + .generate_map(GenerateDecodedMapOptions { + source: Some("pre_injection.js".to_string()), + include_content: true, + ..Default::default() }) - .map(|(idx, _)| idx); - - let sourcemap_comment = sourcemap_comment_idx.map(|idx| rest_lines.remove(idx)); - - dbg!(&sourcemap_comment); - - println!("{}", std::str::from_utf8(js_contents).unwrap()); - // Inject the code snippet - let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()); - writeln!(js_contents, "{to_inject}")?; - println!("{}", std::str::from_utf8(js_contents).unwrap()); - - for line in rest_lines { - writeln!(js_contents, "{line}")?; - } - println!("{}", std::str::from_utf8(js_contents).unwrap()); - - // Write the debug id comment - writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; - println!("{}", std::str::from_utf8(js_contents).unwrap()); - - // Lastly, write the source mapping URL comment, if there was one - if let Some(sourcemap_comment) = sourcemap_comment { - writeln!(js_contents, "{sourcemap_comment}")?; - println!("{}", std::str::from_utf8(js_contents).unwrap()); - } - - Ok(()) + .unwrap()) // let mut js_lines = js_lines.into_iter().peekable(); @@ -534,12 +509,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); @@ -587,6 +563,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 @@ -602,9 +579,9 @@ some line //# sourceMappingURL=fake //# sourceMappingURL=fake //# sourceMappingURL=fake +//# sourceMappingURL=real something else //# debugId=00000000-0000-0000-0000-000000000000 -//# sourceMappingURL=real "#; println!("{}", result); @@ -628,20 +605,27 @@ something else"#; let mut source = Vec::from(source); - fixup_js_file(&mut source, debug_id).unwrap(); + let map = fixup_js_file(&mut source, debug_id).unwrap(); + + let mut map_file = std::fs::File::create("converted.map").unwrap(); + write!(map_file, "{}", map.to_string().unwrap()).unwrap(); + + let mut min_file = std::fs::File::create("converted.js").unwrap(); + min_file.write_all(&source).unwrap(); let expected = r#"#!/bin/node //# 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); @@ -670,14 +654,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); From a82c7dcc023bde857e251742056e6dd463c31ac1 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 21 Jul 2023 12:34:46 +0200 Subject: [PATCH 03/13] Some documentation and cleanup --- src/utils/sourcemaps/inject.rs | 100 ++++----------------------------- 1 file changed, 10 insertions(+), 90 deletions(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 86ed5ea7ff..3cafbcc3c1 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -20,8 +20,11 @@ const SOURCEMAP_DEBUGID_KEY: &str = "debug_id"; const DEBUGID_COMMENT_PREFIX: &str = "//# debugId"; lazy_static! { - static ref USE_PRAGMA_RE: Regex = Regex::new(r#"^"use \w+";|^'use \w+';"#).unwrap(); - static ref TEST_RE: Regex = Regex::new( + // 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(); @@ -111,56 +114,11 @@ 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 -/// "# -/// ); -/// ``` +/// This function returns a [`magic_string::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, @@ -168,7 +126,7 @@ pub fn fixup_js_file( let contents = String::from_utf8(js_contents.clone())?; js_contents.clear(); - let m = TEST_RE + let m = PRE_INJECT_RE .find(&contents) .expect("regex is infallible") .range(); @@ -194,44 +152,6 @@ pub fn fixup_js_file( ..Default::default() }) .unwrap()) - - // 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}")?; - // } - - // // 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}")?; - // } - - // // Inject the code snippet - // let to_inject = CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()); - // writeln!(js_contents, "{to_inject}")?; - - // // Write other lines - // for line in js_lines { - // writeln!(js_contents, "{line}")?; - // } - - // // Write the debug id comment - // writeln!(js_contents, "{DEBUGID_COMMENT_PREFIX}={debug_id}")?; - - // // Lastly, write the source mapping URL comment, if there was one - // if let Some(sourcemap_comment) = sourcemap_comment { - // writeln!(js_contents, "{sourcemap_comment}")?; - // } - - // Ok(()) } /// Fixes up a minified JS source file with a debug id without messing with mappings. @@ -802,7 +722,7 @@ some line //# sourceMappingURL=real something else"#; - let m = TEST_RE.find(source).unwrap(); + let m = PRE_INJECT_RE.find(source).unwrap(); dbg!(&source[m.range()]); } } From 3f47bd176e16c975246174d719a00355e73256de Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 21 Jul 2023 14:25:19 +0200 Subject: [PATCH 04/13] Clean up fixup_js_file_end a bit --- src/utils/sourcemaps/inject.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 3cafbcc3c1..97cdd4eb4c 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -174,14 +174,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)); @@ -191,11 +186,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(()) } From 144db0524d1bde676610f73eb225aee209b0b4df Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 21 Jul 2023 14:34:50 +0200 Subject: [PATCH 05/13] Some more cleanup --- src/utils/sourcemaps/inject.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 97cdd4eb4c..34113bc309 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -123,26 +123,29 @@ pub fn fixup_js_file( js_contents: &mut Vec, debug_id: DebugId, ) -> Result { - let contents = String::from_utf8(js_contents.clone())?; - js_contents.clear(); + let contents = std::str::from_utf8(js_contents)?; let m = PRE_INJECT_RE - .find(&contents) + .find(contents) .expect("regex is infallible") .range(); - let mut magic = MagicString::new(&contents); - - let to_inject = format!( + let code_snippet = format!( "\n{}\n", CODE_SNIPPET_TEMPLATE.replace(DEBUGID_PLACEHOLDER, &debug_id.to_string()) ); + + let debug_id_comment = format!("\n{DEBUGID_COMMENT_PREFIX}={debug_id}\n"); + + let mut magic = MagicString::new(contents); + magic - .append_left(m.end as u32, &to_inject) + .append_left(m.end as u32, &code_snippet) .unwrap() - .append(&format!("\n{DEBUGID_COMMENT_PREFIX}={debug_id}\n")) + .append(&debug_id_comment) .unwrap(); + js_contents.clear(); write!(js_contents, "{}", magic.to_string())?; Ok(magic From ef99ae1077a6608420e11048d38f22735b0cc5eb Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 21 Jul 2023 14:50:52 +0200 Subject: [PATCH 06/13] fix regex --- src/utils/sourcemaps/inject.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index 34113bc309..dfc1592968 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -25,7 +25,7 @@ lazy_static! { // 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]?"# + r#"^(#!.*[\n\r])?(?:\s*|/\*(?:.|\r|\n)*?\*/|//.*[\n\r])*(?:"[^"]*";|'[^']*';[\n\r]?)?"# ) .unwrap(); } From 692a017b365bb3f06dc50b66cfe1c8e16ce4885d Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 2 Aug 2023 14:38:35 +0200 Subject: [PATCH 07/13] Rewrite injection using sourcemap composition --- Cargo.lock | 4 +- Cargo.toml | 2 +- src/utils/sourcemaps.rs | 245 ++++++++++++++----------- src/utils/sourcemaps/inject.rs | 136 ++------------ tests/integration/sourcemaps/inject.rs | 26 --- 5 files changed, 151 insertions(+), 262 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 626dfef795..d309605813 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2482,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", diff --git a/Cargo.toml b/Cargo.toml index de71e04747..ba513452a5 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" diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index feed673959..b7bdd01ced 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,155 @@ 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}"); - }; + // Modify the source file and the sourcemap. + // There are seveal 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 contetns 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); + + 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)); - inject::insert_empty_mapping(&mut decoded)?; - let encoded = data_encoding::BASE64.encode(&decoded); - let new_sourcemap_url = format!("{DATA_PREAMBLE}{encoded}"); + decoded.clear(); + adjusted_map.to_writer(&mut decoded)?; - let source_file = self.sources.get_mut(source_url).unwrap(); + let encoded = data_encoding::BASE64.encode(&decoded); + let new_sourcemap_url = format!("{DATA_PREAMBLE}{encoded}"); - // hash the new source map url for the debug id - let debug_id = - inject::debug_id_from_bytes_hashed(new_sourcemap_url.as_bytes()); + 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. + 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(); + 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); + + 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 5e719c5fa5..be940f048f 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -7,12 +7,12 @@ 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__"; @@ -116,12 +116,9 @@ impl fmt::Display for InjectReport { /// block of comments, empty lines, and an optional `"use […]";` or `'use […]';` pragma. /// 2. A comment of the form `//# debugId=` is appended to the file. /// -/// This function returns a [`magic_string::SourceMap`] that maps locations in the injected file +/// 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 { +pub fn fixup_js_file(js_contents: &mut Vec, debug_id: DebugId) -> Result { let contents = std::str::from_utf8(js_contents)?; let m = PRE_INJECT_RE @@ -147,13 +144,17 @@ pub fn fixup_js_file( js_contents.clear(); write!(js_contents, "{}", magic.to_string())?; - Ok(magic + let map = magic .generate_map(GenerateDecodedMapOptions { source: Some("pre_injection.js".to_string()), include_content: true, ..Default::default() }) - .unwrap()) + .unwrap(); + + let map = map.to_string().unwrap(); + + Ok(SourceMap::from_slice(map.as_bytes()).unwrap()) } /// Fixes up a minified JS source file with a debug id without messing with mappings. @@ -203,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(); @@ -234,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` @@ -380,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 @@ -529,13 +429,7 @@ something else"#; let mut source = Vec::from(source); - let map = fixup_js_file(&mut source, debug_id).unwrap(); - - let mut map_file = std::fs::File::create("converted.map").unwrap(); - write!(map_file, "{}", map.to_string().unwrap()).unwrap(); - - let mut min_file = std::fs::File::create("converted.js").unwrap(); - min_file.write_all(&source).unwrap(); + fixup_js_file(&mut source, debug_id).unwrap(); let expected = r#"#!/bin/node //# sourceMappingURL=fake1 diff --git a/tests/integration/sourcemaps/inject.rs b/tests/integration/sourcemaps/inject.rs index 92af1d47ee..745e18c60b 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] From 35739cb7ac22791f557593fff76e245773992fb3 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 2 Aug 2023 14:44:30 +0200 Subject: [PATCH 08/13] Add test cases for bundler injection --- .../sourcemaps-inject-bundlers.trycmd | 22 +++++++++++ .../inject_bundlers/rollup/rollup.bundle.js | 2 + .../rollup/rollup.bundle.js.expected | 6 +++ .../rollup/rollup.bundle.js.map | 1 + .../rollup/rollup.bundle.js.map.expected | 1 + .../inject_bundlers/rspack/rspack.bundle.js | 2 + .../rspack/rspack.bundle.js.expected | 5 +++ .../rspack/rspack.bundle.js.map | 1 + .../rspack/rspack.bundle.js.map.expected | 1 + .../inject_bundlers/vite/vite.bundle.js | 2 + .../vite/vite.bundle.js.expected | 6 +++ .../inject_bundlers/vite/vite.bundle.js.map | 1 + .../vite/vite.bundle.js.map.expected | 1 + .../inject_bundlers/webpack/webpack.bundle.js | 2 + .../webpack/webpack.bundle.js.expected | 5 +++ .../webpack/webpack.bundle.js.map | 1 + .../webpack/webpack.bundle.js.map.expected | 1 + tests/integration/sourcemaps/inject.rs | 38 +++++++++++++++++++ 18 files changed, 98 insertions(+) create mode 100644 tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js create mode 100644 tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map.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..09ad47b6d5 --- /dev/null +++ b/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd @@ -0,0 +1,22 @@ +``` +$ sentry-cli sourcemaps inject . +? success +> Searching . +> Found 8 files +> Analyzing 8 sources +> Injecting debug ids + +Source Map Debug ID Injection Report + Modified: The following source files have been modified to have debug ids + [..]-[..]-[..]-[..]-[..] - ./rollup/rollup.bundle.js + [..]-[..]-[..]-[..]-[..] - ./rspack/rspack.bundle.js + [..]-[..]-[..]-[..]-[..] - ./vite/vite.bundle.js + [..]-[..]-[..]-[..]-[..] - ./webpack/webpack.bundle.js + Modified: The following sourcemap files have been modified to have debug ids + [..]-[..]-[..]-[..]-[..] - ./rollup/rollup.bundle.js.map + [..]-[..]-[..]-[..]-[..] - ./rspack/rspack.bundle.js.map + [..]-[..]-[..]-[..]-[..] - ./vite/vite.bundle.js.map + [..]-[..]-[..]-[..]-[..] - ./webpack/webpack.bundle.js.map + + +``` diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js new file mode 100644 index 0000000000..21d7dd9e42 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.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=rollup.bundle.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.expected new file mode 100644 index 0000000000..655ff66205 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.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=rollup.bundle.js.map + +//# debugId=6cde0fde-8646-5aa5-90be-6540abac2d15 diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map new file mode 100644 index 0000000000..24a810b6f8 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.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/rollup.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map.expected new file mode 100644 index 0000000000..9596026461 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.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/rspack.bundle.js b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js new file mode 100644 index 0000000000..efd4c40c3e --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.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=rspack.bundle.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.expected new file mode 100644 index 0000000000..0dda87dd63 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.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=rspack.bundle.js.map +//# debugId=d50bd339-0bfa-5b90-9c5f-479cf9c0c40c diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map new file mode 100644 index 0000000000..2b0f39cf8e --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.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/rspack.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map.expected new file mode 100644 index 0000000000..2d96546c22 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.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/vite.bundle.js b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js new file mode 100644 index 0000000000..bfd2974755 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.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=vite.bundle.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.expected new file mode 100644 index 0000000000..d0e8f5dbf1 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.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=vite.bundle.js.map + +//# debugId=61108b96-d9cb-5d14-a1a1-cc066b34c428 diff --git a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map new file mode 100644 index 0000000000..3ebd65a71f --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.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/vite.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map.expected new file mode 100644 index 0000000000..38a4f2eaa6 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.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/webpack.bundle.js b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js new file mode 100644 index 0000000000..4462e0a8a2 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js @@ -0,0 +1,2 @@ +(()=>{"use strict";(function(n,o){!function(n,o){n(o)}(n,"boop")})((function(n){throw new Error(n)}))})(); +//# sourceMappingURL=webpack.bundle.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.expected new file mode 100644 index 0000000000..31f69af4eb --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.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=webpack.bundle.js.map +//# debugId=397f1037-b958-54cc-bc62-267d5b7aff25 diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map new file mode 100644 index 0000000000..2c478f2c4e --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.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/webpack.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map.expected new file mode 100644 index 0000000000..fb7c700e79 --- /dev/null +++ b/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.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 745e18c60b..9731140a5d 100644 --- a/tests/integration/sourcemaps/inject.rs +++ b/tests/integration/sourcemaps/inject.rs @@ -91,3 +91,41 @@ 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"); + + for bundler in ["rollup", "rspack", "vite", "webpack"] { + let actual_code = + std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/{bundler}.bundle.js")) + .unwrap(); + let expected_code = std::fs::read_to_string(format!( + "{testcase_cwd_path}/{bundler}/{bundler}.bundle.js.expected" + )) + .unwrap(); + + assert_eq!(actual_code, expected_code); + + let actual_map = std::fs::read_to_string(format!( + "{testcase_cwd_path}/{bundler}/{bundler}.bundle.js.map" + )) + .unwrap(); + let expected_map = std::fs::read_to_string(format!( + "{testcase_cwd_path}/{bundler}/{bundler}.bundle.js.map.expected" + )) + .unwrap(); + + assert_eq!(actual_map, expected_map); + } +} From e2bf96fb56da195cfc15796f01a9f54a3eb7c732 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 2 Aug 2023 15:09:07 +0200 Subject: [PATCH 09/13] Clear sourcemap before writing --- src/utils/sourcemaps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index b7bdd01ced..39bb5e317a 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -890,6 +890,7 @@ impl SourceMapProcessor { 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 From b0f4a0a0db090afee2414c9a5c15271d42b00091 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 2 Aug 2023 15:46:37 +0200 Subject: [PATCH 10/13] Some comments --- src/utils/sourcemaps.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index 39bb5e317a..9665aa76ed 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -799,6 +799,9 @@ impl SourceMapProcessor { 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 @@ -861,12 +864,16 @@ impl SourceMapProcessor { 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 => { @@ -925,6 +932,9 @@ impl SourceMapProcessor { 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 {}", From d2a974a6fa2d7eaed0b32d581dc02877b3efe048 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 2 Aug 2023 16:51:14 +0200 Subject: [PATCH 11/13] Update src/utils/sourcemaps.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil Ogórek --- src/utils/sourcemaps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index 9665aa76ed..bf29465950 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -791,7 +791,7 @@ impl SourceMapProcessor { } // Modify the source file and the sourcemap. - // There are seveal cases to consider according to whether we have a sourcemap for the source file and + // 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 => { From 70f99c5eec0f2acc53616d6704bdc19c9968b111 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 2 Aug 2023 16:51:20 +0200 Subject: [PATCH 12/13] Update src/utils/sourcemaps.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil Ogórek --- src/utils/sourcemaps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/sourcemaps.rs b/src/utils/sourcemaps.rs index bf29465950..e7905a7787 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -795,7 +795,7 @@ impl SourceMapProcessor { // 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 contetns for the debug id. + // 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); From f86e5502993319d27234b26552be968c458a7bb0 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Thu, 3 Aug 2023 11:54:23 +0200 Subject: [PATCH 13/13] WIP add more test cases --- src/utils/sourcemaps/inject.rs | 17 --------- .../sourcemaps-inject-bundlers.trycmd | 30 ++++++++++----- .../_fixtures/inject_bundlers/esbuild/cjs.js | 2 + .../inject_bundlers/esbuild/cjs.js.expected | 6 +++ .../inject_bundlers/esbuild/cjs.js.map | 7 ++++ .../esbuild/cjs.js.map.expected | 1 + .../_fixtures/inject_bundlers/esbuild/iife.js | 2 + .../inject_bundlers/esbuild/iife.js.expected | 6 +++ .../inject_bundlers/esbuild/iife.js.map | 7 ++++ .../esbuild/iife.js.map.expected | 1 + .../_fixtures/inject_bundlers/rollup/cjs.js | 2 + .../inject_bundlers/rollup/cjs.js.expected | 6 +++ .../inject_bundlers/rollup/cjs.js.map | 1 + .../rollup/cjs.js.map.expected | 1 + .../rollup/{rollup.bundle.js => iife.js} | 2 +- ...up.bundle.js.expected => iife.js.expected} | 2 +- .../{rollup.bundle.js.map => iife.js.map} | 0 ...e.js.map.expected => iife.js.map.expected} | 0 .../rspack/{rspack.bundle.js => iife.js} | 2 +- ...ck.bundle.js.expected => iife.js.expected} | 2 +- .../{rspack.bundle.js.map => iife.js.map} | 0 ...e.js.map.expected => iife.js.map.expected} | 0 .../_fixtures/inject_bundlers/vite/cjs.js | 2 + .../inject_bundlers/vite/cjs.js.expected | 6 +++ .../_fixtures/inject_bundlers/vite/cjs.js.map | 1 + .../inject_bundlers/vite/cjs.js.map.expected | 1 + .../vite/{vite.bundle.js => iife.js} | 2 +- ...te.bundle.js.expected => iife.js.expected} | 2 +- .../vite/{vite.bundle.js.map => iife.js.map} | 0 ...e.js.map.expected => iife.js.map.expected} | 0 .../_fixtures/inject_bundlers/webpack/cjs.js | 2 + .../inject_bundlers/webpack/cjs.js.expected | 5 +++ .../inject_bundlers/webpack/cjs.js.map | 1 + .../webpack/cjs.js.map.expected | 1 + .../webpack/{webpack.bundle.js => iife.js} | 2 +- ...ck.bundle.js.expected => iife.js.expected} | 2 +- .../{webpack.bundle.js.map => iife.js.map} | 0 ...e.js.map.expected => iife.js.map.expected} | 0 tests/integration/sourcemaps/inject.rs | 38 +++++++++++++------ 39 files changed, 116 insertions(+), 46 deletions(-) create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/iife.js create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/cjs.js create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/rollup/cjs.js.map.expected rename tests/integration/_fixtures/inject_bundlers/rollup/{rollup.bundle.js => iife.js} (74%) rename tests/integration/_fixtures/inject_bundlers/rollup/{rollup.bundle.js.expected => iife.js.expected} (91%) rename tests/integration/_fixtures/inject_bundlers/rollup/{rollup.bundle.js.map => iife.js.map} (100%) rename tests/integration/_fixtures/inject_bundlers/rollup/{rollup.bundle.js.map.expected => iife.js.map.expected} (100%) rename tests/integration/_fixtures/inject_bundlers/rspack/{rspack.bundle.js => iife.js} (94%) rename tests/integration/_fixtures/inject_bundlers/rspack/{rspack.bundle.js.expected => iife.js.expected} (95%) rename tests/integration/_fixtures/inject_bundlers/rspack/{rspack.bundle.js.map => iife.js.map} (100%) rename tests/integration/_fixtures/inject_bundlers/rspack/{rspack.bundle.js.map.expected => iife.js.map.expected} (100%) create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/cjs.js create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/cjs.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/vite/cjs.js.map.expected rename tests/integration/_fixtures/inject_bundlers/vite/{vite.bundle.js => iife.js} (77%) rename tests/integration/_fixtures/inject_bundlers/vite/{vite.bundle.js.expected => iife.js.expected} (91%) rename tests/integration/_fixtures/inject_bundlers/vite/{vite.bundle.js.map => iife.js.map} (100%) rename tests/integration/_fixtures/inject_bundlers/vite/{vite.bundle.js.map.expected => iife.js.map.expected} (100%) create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/cjs.js create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.expected create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map create mode 100644 tests/integration/_fixtures/inject_bundlers/webpack/cjs.js.map.expected rename tests/integration/_fixtures/inject_bundlers/webpack/{webpack.bundle.js => iife.js} (71%) rename tests/integration/_fixtures/inject_bundlers/webpack/{webpack.bundle.js.expected => iife.js.expected} (90%) rename tests/integration/_fixtures/inject_bundlers/webpack/{webpack.bundle.js.map => iife.js.map} (100%) rename tests/integration/_fixtures/inject_bundlers/webpack/{webpack.bundle.js.map.expected => iife.js.map.expected} (100%) diff --git a/src/utils/sourcemaps/inject.rs b/src/utils/sourcemaps/inject.rs index be940f048f..caecd9560a 100644 --- a/src/utils/sourcemaps/inject.rs +++ b/src/utils/sourcemaps/inject.rs @@ -606,21 +606,4 @@ more text &["./project/maps/page/index.js.map"] ); } - - #[test] - fn test_regex() { - let source = r#"#!/bin/node -//# sourceMappingURL=fake1 - - // some other comment - "use strict"; rest of the line -'use strict'; -some line -//# sourceMappingURL=fake2 -//# sourceMappingURL=real -something else"#; - - let m = PRE_INJECT_RE.find(source).unwrap(); - dbg!(&source[m.range()]); - } } diff --git a/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd b/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd index 09ad47b6d5..adcd32fa2a 100644 --- a/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd +++ b/tests/integration/_cases/sourcemaps/sourcemaps-inject-bundlers.trycmd @@ -2,21 +2,31 @@ $ sentry-cli sourcemaps inject . ? success > Searching . -> Found 8 files -> Analyzing 8 sources +> 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 - [..]-[..]-[..]-[..]-[..] - ./rollup/rollup.bundle.js - [..]-[..]-[..]-[..]-[..] - ./rspack/rspack.bundle.js - [..]-[..]-[..]-[..]-[..] - ./vite/vite.bundle.js - [..]-[..]-[..]-[..]-[..] - ./webpack/webpack.bundle.js + [..]-[..]-[..]-[..]-[..] - ./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 - [..]-[..]-[..]-[..]-[..] - ./rollup/rollup.bundle.js.map - [..]-[..]-[..]-[..]-[..] - ./rspack/rspack.bundle.js.map - [..]-[..]-[..]-[..]-[..] - ./vite/vite.bundle.js.map - [..]-[..]-[..]-[..]-[..] - ./webpack/webpack.bundle.js.map + [..]-[..]-[..]-[..]-[..] - ./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/rollup.bundle.js b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js similarity index 74% rename from tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js rename to tests/integration/_fixtures/inject_bundlers/rollup/iife.js index 21d7dd9e42..494c5d5c65 100644 --- a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js +++ b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js @@ -1,2 +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=rollup.bundle.js.map +//# sourceMappingURL=iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.expected similarity index 91% rename from tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.expected rename to tests/integration/_fixtures/inject_bundlers/rollup/iife.js.expected index 655ff66205..7faa91814a 100644 --- a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.expected +++ b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.expected @@ -1,6 +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=rollup.bundle.js.map +//# sourceMappingURL=iife.js.map //# debugId=6cde0fde-8646-5aa5-90be-6540abac2d15 diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map rename to tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map.expected similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/rollup/rollup.bundle.js.map.expected rename to tests/integration/_fixtures/inject_bundlers/rollup/iife.js.map.expected diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js similarity index 94% rename from tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js rename to tests/integration/_fixtures/inject_bundlers/rspack/iife.js index efd4c40c3e..395f28e153 100644 --- a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js +++ b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js @@ -1,2 +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=rspack.bundle.js.map \ No newline at end of file +//# sourceMappingURL=iife.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.expected similarity index 95% rename from tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.expected rename to tests/integration/_fixtures/inject_bundlers/rspack/iife.js.expected index 0dda87dd63..8f5664f371 100644 --- a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.expected +++ b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.expected @@ -1,5 +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=rspack.bundle.js.map +//# sourceMappingURL=iife.js.map //# debugId=d50bd339-0bfa-5b90-9c5f-479cf9c0c40c diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map rename to tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map.expected similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/rspack/rspack.bundle.js.map.expected rename to tests/integration/_fixtures/inject_bundlers/rspack/iife.js.map.expected 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/vite.bundle.js b/tests/integration/_fixtures/inject_bundlers/vite/iife.js similarity index 77% rename from tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js rename to tests/integration/_fixtures/inject_bundlers/vite/iife.js index bfd2974755..9338ed0f5c 100644 --- a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js +++ b/tests/integration/_fixtures/inject_bundlers/vite/iife.js @@ -1,2 +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=vite.bundle.js.map +//# sourceMappingURL=iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.expected similarity index 91% rename from tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.expected rename to tests/integration/_fixtures/inject_bundlers/vite/iife.js.expected index d0e8f5dbf1..35fc4c78d4 100644 --- a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.expected +++ b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.expected @@ -1,6 +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=vite.bundle.js.map +//# sourceMappingURL=iife.js.map //# debugId=61108b96-d9cb-5d14-a1a1-cc066b34c428 diff --git a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map rename to tests/integration/_fixtures/inject_bundlers/vite/iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/vite/iife.js.map.expected similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/vite/vite.bundle.js.map.expected rename to tests/integration/_fixtures/inject_bundlers/vite/iife.js.map.expected 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/webpack.bundle.js b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js similarity index 71% rename from tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js rename to tests/integration/_fixtures/inject_bundlers/webpack/iife.js index 4462e0a8a2..17191dfcbd 100644 --- a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js +++ b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js @@ -1,2 +1,2 @@ (()=>{"use strict";(function(n,o){!function(n,o){n(o)}(n,"boop")})((function(n){throw new Error(n)}))})(); -//# sourceMappingURL=webpack.bundle.js.map \ No newline at end of file +//# sourceMappingURL=iife.js.map \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.expected b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.expected similarity index 90% rename from tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.expected rename to tests/integration/_fixtures/inject_bundlers/webpack/iife.js.expected index 31f69af4eb..ec194a3e44 100644 --- a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.expected +++ b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.expected @@ -1,5 +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=webpack.bundle.js.map +//# sourceMappingURL=iife.js.map //# debugId=397f1037-b958-54cc-bc62-267d5b7aff25 diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map rename to tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map diff --git a/tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map.expected b/tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map.expected similarity index 100% rename from tests/integration/_fixtures/inject_bundlers/webpack/webpack.bundle.js.map.expected rename to tests/integration/_fixtures/inject_bundlers/webpack/iife.js.map.expected diff --git a/tests/integration/sourcemaps/inject.rs b/tests/integration/sourcemaps/inject.rs index 9731140a5d..ceb1ea9348 100644 --- a/tests/integration/sourcemaps/inject.rs +++ b/tests/integration/sourcemaps/inject.rs @@ -106,26 +106,42 @@ fn command_sourcemaps_inject_bundlers() { register_test("sourcemaps/sourcemaps-inject-bundlers.trycmd"); - for bundler in ["rollup", "rspack", "vite", "webpack"] { + // IIFE tests + for bundler in ["esbuild", "rollup", "rspack", "vite", "webpack"] { let actual_code = - std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/{bundler}.bundle.js")) + 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(); - let expected_code = std::fs::read_to_string(format!( - "{testcase_cwd_path}/{bundler}/{bundler}.bundle.js.expected" - )) - .unwrap(); assert_eq!(actual_code, expected_code); - let actual_map = std::fs::read_to_string(format!( - "{testcase_cwd_path}/{bundler}/{bundler}.bundle.js.map" - )) - .unwrap(); + 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}/{bundler}.bundle.js.map.expected" + "{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); + } }