Skip to content

Commit

Permalink
Fall back to co-location heuristic if sourcemap url appears remote (#…
Browse files Browse the repository at this point in the history
…1871)

Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
  • Loading branch information
brettdh and szokeasaurusrex authored Jul 31, 2024
1 parent d0e8717 commit 4ab584d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/utils/sourcemaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ fn is_remote_url(url: &str) -> bool {
};
}

/// Return true if url appears to be a URL path.
/// Most often, a URL path will begin with `/`,
/// particularly in the case of static asset collection and hosting,
/// but such a path is very unlikely to exist in the local filesystem.
fn is_url_path(url: &str) -> bool {
url.starts_with('/') && !Path::new(url).exists()
}

/// Return true iff url is probably not a local file path.
fn is_remote_sourcemap(url: &str) -> bool {
is_remote_url(url) || is_url_path(url)
}

impl SourceMapProcessor {
/// Creates a new sourcemap validator.
pub fn new() -> SourceMapProcessor {
Expand Down Expand Up @@ -362,7 +375,8 @@ impl SourceMapProcessor {
// that can't be resolved to a source map file.
// Instead, we pretend we failed to discover the location, and we fall back to
// guessing the source map location based on the source location.
let location = discover_sourcemaps_location(contents).filter(|loc| !is_remote_url(loc));
let location =
discover_sourcemaps_location(contents).filter(|loc| !is_remote_sourcemap(loc));
let sourcemap_reference = match location {
Some(url) => SourceMapReference::from_url(url.to_string()),
None => match guess_sourcemap_reference(&sourcemaps, &source.url) {
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/_cases/sourcemaps/sourcemaps-inject.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
$ sentry-cli sourcemaps inject ./server ./static
? success
> Searching ./server
> Found 14 files
> Found 16 files
> Searching ./static
> Found 8 files
> Analyzing 22 sources
> Analyzing 24 sources
> Injecting debug ids

Source Map Debug ID Injection Report
Expand All @@ -15,6 +15,7 @@ Source Map Debug ID Injection Report
[..]-[..]-[..]-[..]-[..] - ./server/chunks/flight-server-css-manifest.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_embedded.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted_full.js
[..]-[..]-[..]-[..]-[..] - ./server/flight-manifest.js
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js
[..]-[..]-[..]-[..]-[..] - ./server/pages/api/hello.js
Expand All @@ -24,6 +25,7 @@ Source Map Debug ID Injection Report
[..]-[..]-[..]-[..]-[..] - ./static/chunks/pages/asdf-05b39167abbe433b.js
Modified: The following sourcemap files have been modified to have debug ids
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted.js.map
[..]-[..]-[..]-[..]-[..] - ./server/dummy_hosted_full.js.map
[..]-[..]-[..]-[..]-[..] - ./server/pages/_document.js.map
[..]-[..]-[..]-[..]-[..] - ./static/chunks/575-bb7d7e0e6de8d623.js.map
Ignored: The following source files already have debug ids
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/_fixtures/inject/server/dummy_hosted.js

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

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

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

0 comments on commit 4ab584d

Please sign in to comment.