Skip to content

Commit

Permalink
fix(sourcemaps): Add .cjs and .mjs to default sourcemaps upload
Browse files Browse the repository at this point in the history
… extensions (#1961)

Fixes GH-1959
  • Loading branch information
szokeasaurusrex authored Feb 29, 2024
1 parent 5657d86 commit 5708458
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/commands/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;
use anyhow::Result;
use clap::{Arg, ArgAction, ArgMatches, Command};
use glob::{glob_with, MatchOptions};
use itertools::Itertools;
use log::{debug, warn};

use crate::api::{Api, ChunkUploadCapability};
Expand All @@ -16,6 +17,8 @@ use crate::utils::file_upload::UploadContext;
use crate::utils::fs::path_as_url;
use crate::utils::sourcemaps::SourceMapProcessor;

const DEFAULT_EXTENSIONS: &[&str] = &["js", "cjs", "mjs", "map", "jsbundle", "bundle"];

pub fn make_command(command: Command) -> Command {
command
.about("Upload sourcemaps for a release.")
Expand Down Expand Up @@ -200,12 +203,16 @@ pub fn make_command(command: Command) -> Command {
.short('x')
.value_name("EXT")
.action(ArgAction::Append)
.help(
.help(format!(
"Set the file extensions that are considered for upload. \
This overrides the default extensions. To add an extension, all default \
extensions must be repeated. Specify once per extension.{n}\
Defaults to: `--ext=js --ext=map --ext=jsbundle --ext=bundle`",
),
extensions must be repeated. Specify once per extension.\n\
Defaults to: `{}`",
DEFAULT_EXTENSIONS
.iter()
.map(|ext| format!("--ext={ext}"))
.join(" ")
)),
)
.arg(
Arg::new("strict")
Expand Down Expand Up @@ -338,7 +345,7 @@ fn process_sources_from_paths(
let extensions = matches
.get_many::<String>("extensions")
.map(|extensions| extensions.map(|ext| ext.trim_start_matches('.')).collect())
.unwrap_or_else(|| vec!["js", "map", "jsbundle", "bundle"]);
.unwrap_or_else(|| DEFAULT_EXTENSIONS.to_vec());
let ignores: Vec<_> = matches
.get_many::<String>("ignore")
.map(|ignores| ignores.map(|i| format!("!{i}")).collect())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```
$ sentry-cli sourcemaps upload tests/integration/_fixtures/upload_cjs_mjs
? success
...
Source Map Upload Report
[..]Scripts
~/test.cjs[..]
[..]
~/test.mjs[..]
[..]

```
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Options:
Set the file extensions that are considered for upload. This overrides the default
extensions. To add an extension, all default extensions must be repeated. Specify once per
extension.
Defaults to: `--ext=js --ext=map --ext=jsbundle --ext=bundle`
Defaults to: `--ext=js --ext=cjs --ext=mjs --ext=map --ext=jsbundle --ext=bundle`
-s, --strict
Fail with a non-zero exit code if the specified source map file cannot be uploaded.
-h, --help
Expand Down
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions tests/integration/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,10 @@ fn command_sourcemaps_upload_hermes_bundle_with_referencing_debug_id() {
mock_common_upload_endpoints(ServerBehavior::Modern, Default::default());
register_test("sourcemaps/sourcemaps-upload-file-hermes-bundle-reference-debug-id.trycmd");
}

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

0 comments on commit 5708458

Please sign in to comment.