Skip to content

Commit

Permalink
fix(sourcemaps): allow complex file extensions (#1976)
Browse files Browse the repository at this point in the history
This PR enables users to pass a complex extension (e.g. .min.js or .arbitrary.string.here.myfiletype) to the sourcemaps inject command's --ext argument.

Fixes GH-1975
  • Loading branch information
szokeasaurusrex authored Mar 12, 2024
1 parent 35bf497 commit 9a6f91b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/utils/file_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl ReleaseFileSearch {
if !&self.extensions.is_empty() {
let mut types_builder = TypesBuilder::new();
for ext in &self.extensions {
let ext_name = ext.replace('.', "__");
let ext_name = ext.replace('.', "");
types_builder.add(&ext_name, &format!("*.{ext}"))?;
}
builder.types(types_builder.select("all").build()?);
Expand Down
19 changes: 8 additions & 11 deletions src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,13 @@ fn url_matches_extension(url: &str, extensions: &[&str]) -> bool {
if extensions.is_empty() {
return true;
}
url.rsplit('/')
.next()
.and_then(|filename| {
let mut splitter = filename.rsplit('.');
let rv = splitter.next();
// need another segment
splitter.next()?;
rv
})
.map(|ext| extensions.contains(&ext))
.unwrap_or(false)

match url.rsplit('/').next() {
Some(filename) => extensions
.iter()
.any(|ext| filename.ends_with(&format!(".{ext}"))),
None => false,
}
}

/// Return true iff url is a remote url (not a local path or embedded sourcemap).
Expand Down Expand Up @@ -1208,5 +1204,6 @@ mod tests {
assert!(!url_matches_extension("foo.mjs", &["js"][..]));
assert!(url_matches_extension("foo.mjs", &["js", "mjs"][..]));
assert!(!url_matches_extension("js", &["js"][..]));
assert!(url_matches_extension("foo.test.js", &["test.js"][..]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```
$ sentry-cli sourcemaps inject --ext="complex.js" --dry-run tests/integration/_fixtures/inject_complex_extension
? success
...
Source Map Debug ID Injection Report
Modified: [..]
[..] - tests/integration/_fixtures/inject_complex_extension/hello.complex.js


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```
$ sentry-cli sourcemaps upload --ext="complex.js" tests/integration/_fixtures/inject_complex_extension
? success
...
Source Map Upload Report
Scripts
~/hello.complex.js[..]
- warning: [..]

```
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions tests/integration/sourcemaps/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,8 @@ fn command_sourcemaps_inject_not_compiled() {
let file_contents = fs::read_to_string(format!("{testcase_cwd_path}not-compiled.js")).unwrap();
assert!(file_contents.contains("//# debugId="));
}

#[test]
fn command_sourcemaps_inject_complex_extension() {
register_test("sourcemaps/sourcemaps-inject-complex-extension.trycmd");
}
7 changes: 7 additions & 0 deletions tests/integration/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,10 @@ fn command_sourcemaps_upload_cjs_mjs() {
mock_common_upload_endpoints(ServerBehavior::Modern, Default::default());
register_test("sourcemaps/sourcemaps-upload-cjs-mjs.trycmd");
}

#[test]
fn command_sourcemaps_upload_complex_extension() {
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Modern, Default::default());
register_test("sourcemaps/sourcemaps-upload-complex-extension.trycmd");
}

0 comments on commit 9a6f91b

Please sign in to comment.