diff --git a/CHANGELOG.md b/CHANGELOG.md index a7479b07e5..454f0a901f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Various fixes & improvements - fix(sourcemaps): Query parameters and fragments are removed from source mapping URLs (#1735) by @loewenheim +- fix(sourcemaps): Debug ID injection is significantly faster (#1736) by @loewenheim ## 2.20.6 diff --git a/Cargo.lock b/Cargo.lock index 039a3a8601..304a18d0f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2492,9 +2492,9 @@ dependencies = [ [[package]] name = "sourcemap" -version = "6.4.1" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4cbf65ca7dc576cf50e21f8d0712d96d4fcfd797389744b7b222a85cdf5bd90" +checksum = "dbecc42a2b6131acc3bf9a25c9fe4161dba438eb52131bba83c5d781b5b70be3" dependencies = [ "data-encoding", "debugid", diff --git a/Cargo.toml b/Cargo.toml index 426f2804bb..96384a547f 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.4.1", features = ["ram_bundle"] } +sourcemap = { version = "7.0.0", features = ["ram_bundle"] } symbolic = { version = "12.4.0", 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 660cb89a11..fe756a2054 100644 --- a/src/utils/sourcemaps.rs +++ b/src/utils/sourcemaps.rs @@ -810,7 +810,7 @@ impl SourceMapProcessor { bail!("Invalid embedded sourcemap in source file {source_url}"); }; - let sourcemap = SourceMap::from_slice(&decoded) + let mut sourcemap = SourceMap::from_slice(&decoded) .context("Invalid embedded sourcemap in source file {source_url}")?; let debug_id = sourcemap @@ -822,12 +822,12 @@ impl SourceMapProcessor { 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)); + + sourcemap.adjust_mappings(&adjustment_map); + sourcemap.set_debug_id(Some(debug_id)); decoded.clear(); - adjusted_map.to_writer(&mut decoded)?; + sourcemap.to_writer(&mut decoded)?; let encoded = data_encoding::BASE64.encode(&decoded); let new_sourcemap_url = format!("{DATA_PREAMBLE}{encoded}"); @@ -862,7 +862,7 @@ impl SourceMapProcessor { // 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 (mut sourcemap, debug_id, debug_id_fresh) = { let sourcemap_file = &self.sources[&sourcemap_url]; let sm = SourceMap::from_slice(&sourcemap_file.contents).context( @@ -887,13 +887,13 @@ impl SourceMapProcessor { "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)); + + sourcemap.adjust_mappings(&adjustment_map); + sourcemap.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.to_writer(&mut sourcemap_file.contents)?; sourcemap_file.set_debug_id(debug_id.to_string()); diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected index 23d0396923..2f286f03ed 100644 --- a/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/cjs.js.map.expected @@ -1 +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 +{"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","fn","msg","bar","wat","fn","msg","foo"],"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","debug_id":"a9f9a996-4e6c-5119-b8b8-e64559a6554c"} \ No newline at end of file diff --git a/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected index fdb4ae06b3..ec6c183e79 100644 --- a/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected +++ b/tests/integration/_fixtures/inject_bundlers/esbuild/iife.js.map.expected @@ -1 +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 +{"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","fn","msg","bar","wat","fn","msg","foo"],"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","debug_id":"dd751360-5eae-531d-87f4-5e00c846a9a3"} \ No newline at end of file diff --git a/tests/integration/sourcemaps/inject.rs b/tests/integration/sourcemaps/inject.rs index ceb1ea9348..1d572f7ee6 100644 --- a/tests/integration/sourcemaps/inject.rs +++ b/tests/integration/sourcemaps/inject.rs @@ -123,7 +123,7 @@ fn command_sourcemaps_inject_bundlers() { )) .unwrap(); - assert_eq!(actual_map, expected_map); + assert_eq!(actual_map, expected_map, "IIFE, bundler: {bundler}"); } // CJS tests. Not sure how to make this happen for rspack. @@ -142,6 +142,6 @@ fn command_sourcemaps_inject_bundlers() { std::fs::read_to_string(format!("{testcase_cwd_path}/{bundler}/cjs.js.map.expected")) .unwrap(); - assert_eq!(actual_map, expected_map); + assert_eq!(actual_map, expected_map, "CJS, bundler: {bundler}"); } }