Skip to content

Commit d4ade49

Browse files
handle subdirectories correcty
1 parent 6fc0961 commit d4ade49

24 files changed

Lines changed: 79 additions & 18 deletions

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ with_crash_reporting = []
9696

9797
[workspace.lints.clippy]
9898
allow-attributes = "warn"
99+
dbg-macro = "warn"
99100
str-to-string = "warn"
100101
string-to-string = "warn"
101102
tests-outside-test-module = "warn"

src/utils/sourcemaps.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::utils::file_search::ReleaseFileMatch;
2525
use crate::utils::file_upload::{
2626
initialize_legacy_release_upload, FileUpload, SourceFile, SourceFiles, UploadContext,
2727
};
28+
use crate::utils::fs;
2829
use crate::utils::logging::is_quiet_mode;
2930
use crate::utils::progress::ProgressBar;
3031
use crate::utils::sourcemaps::inject::{InjectReportBuilder, ReportItem};
@@ -172,7 +173,7 @@ fn guess_sourcemap_reference(
172173
/// and original url with which the file was added to the processor.
173174
/// This enable us to look up the source map file based on the original url.
174175
/// Which can be used for example for debug id referencing.
175-
#[derive(Eq, Hash, PartialEq)]
176+
#[derive(Eq, Hash, PartialEq, Debug)]
176177
pub struct SourceMapReference {
177178
url: String,
178179
original_url: Option<String>,
@@ -288,7 +289,6 @@ impl SourceMapProcessor {
288289
/// Collect references to sourcemaps in minified source files
289290
/// and saves them in `self.sourcemap_references`.
290291
fn collect_sourcemap_references(&mut self) {
291-
dbg!(&self.sources.iter().map(|x| x.0.clone()).collect::<Vec<_>>());
292292
// Collect available sourcemaps
293293
let sourcemaps: HashSet<_> = self
294294
.sources
@@ -325,7 +325,16 @@ impl SourceMapProcessor {
325325
.filter_map(|(source, location)| location.as_ref().map(|location| (source, location)))
326326
.for_each(|(source, location)| {
327327
// Add location to already associated sourcemaps, so we cannot guess it again.
328-
explicitly_associated_sourcemaps.insert(location.to_owned(), source.url.clone());
328+
explicitly_associated_sourcemaps.insert(
329+
fs::path_as_url(
330+
&source
331+
.path
332+
.parent()
333+
.expect("source path has a parent")
334+
.join(location),
335+
),
336+
source.url.clone(),
337+
);
329338

330339
self.sourcemap_references.insert(
331340
source.url.clone(),
@@ -347,12 +356,16 @@ impl SourceMapProcessor {
347356
source.warn(format!(
348357
"could not determine a source map reference ({err})"
349358
));
350-
self.sourcemap_references.insert(source.url.clone(), None);
351359
})
352360
.ok()
353361
.filter(|sourcemap_reference| {
354362
explicitly_associated_sourcemaps
355-
.get(&sourcemap_reference.url)
363+
.get(
364+
sourcemap_reference
365+
.original_url
366+
.as_ref()
367+
.expect("original url set in guess_sourcemap_reference"),
368+
)
356369
.inspect(|url| {
357370
source.warn(format!(
358371
"based on the file name, we guessed a source map \
@@ -370,7 +383,10 @@ impl SourceMapProcessor {
370383
.entry(sourcemap_reference)
371384
.or_insert_with(Vec::new)
372385
.push(source);
386+
} else {
387+
self.sourcemap_references.insert(source.url.clone(), None);
373388
}
389+
374390
sources_associated_with_sm
375391
},
376392
)

tests/integration/_cases/sourcemaps/sourcemaps-inject-double-association.trycmd

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@
22
$ sentry-cli sourcemaps inject ./
33
? success
44
> Searching ./
5-
> Found 3 files
6-
> Analyzing 3 sources
5+
> Found 11 files
6+
> Analyzing 11 sources
77
> Injecting debug ids
88

99
Source Map Debug ID Injection Report
1010
Modified: The following source files have been modified to have debug ids
11-
d577e31d-376c-5043-b751-add9ec84b7bc - ./app.min.js
12-
f3aa1477-a45c-540a-9905-f6d9f6d1d7e1 - ./references_app.min.js
11+
0fb38a98-fdda-5fd2-8e58-d8370f1596fb - ./app.min.js
12+
- warning: based on the file name, we guessed a source map reference (app.min.js.map), which is already associated with source ./references_app.min.js. Please explicitly set the sourcemap URL with a `//# sourceMappingURL=...` comment in the source file.
13+
2de47eef-a93e-5d79-8c45-afb649b15f9e - ./mapInSubdirectory.min.js
14+
f369af08-3e09-58d4-92a9-7f432f7d51cb - ./otherApp.js
15+
- warning: Could not associate this source with a source map. We guessed the sourcemap reference otherApp.map for multiple sources, including this one. Please explicitly set the sourcemap URL with a `//# sourceMappingURL=...` comment in the source file, to make the association clear.
16+
4ee42454-c84d-5d2a-b0b9-8cda74c57838 - ./otherApp.min.js
17+
- warning: Could not associate this source with a source map. We guessed the sourcemap reference otherApp.map for multiple sources, including this one. Please explicitly set the sourcemap URL with a `//# sourceMappingURL=...` comment in the source file, to make the association clear.
18+
44931b59-c632-5017-a624-3bb0ac2a0317 - ./references_app.min.js
19+
edefb3dc-9f7a-5540-9db0-270bbd81b8fd - ./subdirectory/app.min.js
20+
228cdb31-bb0a-533c-ac4c-c2ab111ab148 - ./subdirectory/mapForFileInParentDirectory.min.js
21+
- warning: based on the file name, we guessed a source map reference (mapForFileInParentDirectory.min.js.map), which is already associated with source ./mapInSubdirectory.min.js. Please explicitly set the sourcemap URL with a `//# sourceMappingURL=...` comment in the source file.
1322
Modified: The following sourcemap files have been modified to have debug ids
14-
f3aa1477-a45c-540a-9905-f6d9f6d1d7e1 - ./app.min.js.map
23+
44931b59-c632-5017-a624-3bb0ac2a0317 - ./app.min.js.map
24+
edefb3dc-9f7a-5540-9db0-270bbd81b8fd - ./subdirectory/app.min.js.map
25+
2de47eef-a93e-5d79-8c45-afb649b15f9e - ./subdirectory/mapForFileInParentDirectory.min.js.map
1526

1627

1728
```

tests/integration/_expected_outputs/sourcemaps/sourcemaps-inject-double-association/app.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/_expected_outputs/sourcemaps/sourcemaps-inject-double-association/app.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2de47eef-a93e-5d79-8c45-afb649b15f9e")}catch(e){}}();
3+
!function(e,t){"use strict";function n(e){return document.getElementById(e)}function r(e,t){e.addEventListener("click",t)}var o=n("btn");r(o,function(){console.log("mapInSubdirectory.min.js!")})}(window,document);
4+
5+
//# sourceMappingURL=subdirectory/mapForFileInParentDirectory.min.js.map
6+
//# debugId=2de47eef-a93e-5d79-8c45-afb649b15f9e

tests/integration/_expected_outputs/sourcemaps/sourcemaps-inject-double-association/otherApp.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/_expected_outputs/sourcemaps/sourcemaps-inject-double-association/otherApp.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/_expected_outputs/sourcemaps/sourcemaps-inject-double-association/otherApp.min.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f3aa1477-a45c-540a-9905-f6d9f6d1d7e1")}catch(e){}}();
2+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="44931b59-c632-5017-a624-3bb0ac2a0317")}catch(e){}}();
33
!function(e,t){"use strict";function n(e){return document.querySelector(e)}function r(e,t){e.textContent=t}var o=n("#message");r(o,"Hello World!")}(window,document);
44
//# sourceMappingURL=app.min.js.map
55

6-
//# debugId=f3aa1477-a45c-540a-9905-f6d9f6d1d7e1
6+
//# debugId=44931b59-c632-5017-a624-3bb0ac2a0317

0 commit comments

Comments
 (0)