Skip to content

Commit 9a6f91b

Browse files
fix(sourcemaps): allow complex file extensions (#1976)
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
1 parent 35bf497 commit 9a6f91b

File tree

8 files changed

+41
-12
lines changed

8 files changed

+41
-12
lines changed

src/utils/file_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl ReleaseFileSearch {
130130
if !&self.extensions.is_empty() {
131131
let mut types_builder = TypesBuilder::new();
132132
for ext in &self.extensions {
133-
let ext_name = ext.replace('.', "__");
133+
let ext_name = ext.replace('.', "");
134134
types_builder.add(&ext_name, &format!("*.{ext}"))?;
135135
}
136136
builder.types(types_builder.select("all").build()?);

src/utils/sourcemaps.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,13 @@ fn url_matches_extension(url: &str, extensions: &[&str]) -> bool {
211211
if extensions.is_empty() {
212212
return true;
213213
}
214-
url.rsplit('/')
215-
.next()
216-
.and_then(|filename| {
217-
let mut splitter = filename.rsplit('.');
218-
let rv = splitter.next();
219-
// need another segment
220-
splitter.next()?;
221-
rv
222-
})
223-
.map(|ext| extensions.contains(&ext))
224-
.unwrap_or(false)
214+
215+
match url.rsplit('/').next() {
216+
Some(filename) => extensions
217+
.iter()
218+
.any(|ext| filename.ends_with(&format!(".{ext}"))),
219+
None => false,
220+
}
225221
}
226222

227223
/// Return true iff url is a remote url (not a local path or embedded sourcemap).
@@ -1208,5 +1204,6 @@ mod tests {
12081204
assert!(!url_matches_extension("foo.mjs", &["js"][..]));
12091205
assert!(url_matches_extension("foo.mjs", &["js", "mjs"][..]));
12101206
assert!(!url_matches_extension("js", &["js"][..]));
1207+
assert!(url_matches_extension("foo.test.js", &["test.js"][..]));
12111208
}
12121209
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```
2+
$ sentry-cli sourcemaps inject --ext="complex.js" --dry-run tests/integration/_fixtures/inject_complex_extension
3+
? success
4+
...
5+
Source Map Debug ID Injection Report
6+
Modified: [..]
7+
[..] - tests/integration/_fixtures/inject_complex_extension/hello.complex.js
8+
9+
10+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
```
2+
$ sentry-cli sourcemaps upload --ext="complex.js" tests/integration/_fixtures/inject_complex_extension
3+
? success
4+
...
5+
Source Map Upload Report
6+
Scripts
7+
~/hello.complex.js[..]
8+
- warning: [..]
9+
10+
```

tests/integration/_fixtures/inject_complex_extension/hello.complex.js

Whitespace-only changes.

tests/integration/_fixtures/inject_complex_extension/hello.js

Whitespace-only changes.

tests/integration/sourcemaps/inject.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,8 @@ fn command_sourcemaps_inject_not_compiled() {
165165
let file_contents = fs::read_to_string(format!("{testcase_cwd_path}not-compiled.js")).unwrap();
166166
assert!(file_contents.contains("//# debugId="));
167167
}
168+
169+
#[test]
170+
fn command_sourcemaps_inject_complex_extension() {
171+
register_test("sourcemaps/sourcemaps-inject-complex-extension.trycmd");
172+
}

tests/integration/sourcemaps/upload.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,10 @@ fn command_sourcemaps_upload_cjs_mjs() {
169169
mock_common_upload_endpoints(ServerBehavior::Modern, Default::default());
170170
register_test("sourcemaps/sourcemaps-upload-cjs-mjs.trycmd");
171171
}
172+
173+
#[test]
174+
fn command_sourcemaps_upload_complex_extension() {
175+
let _upload_endpoints =
176+
mock_common_upload_endpoints(ServerBehavior::Modern, Default::default());
177+
register_test("sourcemaps/sourcemaps-upload-complex-extension.trycmd");
178+
}

0 commit comments

Comments
 (0)