Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-suits-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@faststats/sourcemap-uploader-plugin": patch
---

fix: add javascript as mapping type
34 changes: 0 additions & 34 deletions .github/workflows/backend.yml

This file was deleted.

1 change: 1 addition & 0 deletions apps/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod auth;
mod config;
mod crypto;
mod error;
mod mappings;
mod routes;
mod storage;

Expand Down
54 changes: 54 additions & 0 deletions apps/backend/src/mappings/javascript.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use uuid::Uuid;

use crate::error::AppError;
use crate::storage::Storage;

use super::{OriginalPosition, s3_key};

pub async fn ingest(
storage: &Storage,
project_id: Uuid,
build_id: &str,
sourcemaps: &[(String, String)], // (file_name, sourcemap_content)
) -> Result<(), AppError> {
for (file_name, content) in sourcemaps {
let key = s3_key(project_id, build_id, file_name);
storage.put(&key, content.as_bytes()).await?;
}
Ok(())
}

pub fn apply(
data: &[u8],
_file_name: &str,
line: u32,
column: u32,
) -> Result<OriginalPosition, AppError> {
let source_map = sourcemap::SourceMap::from_slice(data)
.map_err(|e| AppError::BadRequest(format!("invalid sourcemap: {e}")))?;
let token = source_map
.lookup_token(line.saturating_sub(1), column.saturating_sub(1))
.ok_or(AppError::NotFound)?;
let source = token.get_source().ok_or(AppError::NotFound)?;
let src_line = token.get_src_line();
let src_col = token.get_src_col();

if src_line == u32::MAX || src_col == u32::MAX {
return Err(AppError::NotFound);
}

Ok(OriginalPosition {
source: source.to_string(),
line: src_line.saturating_add(1),
column: src_col.saturating_add(1),
name: token.get_name().map(ToString::to_string),
})
}

pub fn map_file_name(file_name: &str) -> String {
if file_name.ends_with(".map") {
file_name.to_string()
} else {
format!("{file_name}.map")
}
}
27 changes: 27 additions & 0 deletions apps/backend/src/mappings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pub mod javascript;
pub mod proguard;

use serde::Serialize;
use uuid::Uuid;

use crate::error::AppError;

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OriginalPosition {
pub source: String,
pub line: u32,
pub column: u32,
pub name: Option<String>,
}

pub(crate) fn require_non_empty(field: &str, value: &str) -> Result<(), AppError> {
if value.trim().is_empty() {
return Err(AppError::BadRequest(format!("{field} is required")));
}
Ok(())
}

pub(crate) fn s3_key(project_id: Uuid, build_id: &str, file_name: &str) -> String {
format!("{project_id}/{build_id}/{file_name}")
}
Loading