Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Update sourcemap to 7.0.0 to improve injection performance #1736

Merged
merged 7 commits into from Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions src/utils/sourcemaps.rs
Expand Up @@ -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
Expand All @@ -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}");
Expand Down Expand Up @@ -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(
Expand All @@ -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());

Expand Down
@@ -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"}
{"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"}
@@ -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"}
{"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"}
4 changes: 2 additions & 2 deletions tests/integration/sourcemaps/inject.rs
Expand Up @@ -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.
Expand All @@ -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}");
}
}