Skip to content

Commit 67826f6

Browse files
Sourcemap upload strict mode (#1829)
1 parent bd0fbaa commit 67826f6

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/commands/sourcemaps/upload.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ pub fn make_command(command: Command) -> Command {
207207
Defaults to: `--ext=js --ext=map --ext=jsbundle --ext=bundle`",
208208
),
209209
)
210+
.arg(
211+
Arg::new("strict")
212+
.long("strict")
213+
.short('s')
214+
.action(ArgAction::SetTrue)
215+
.help(
216+
"Fail with a non-zero exit code if the specified source map file cannot be \
217+
uploaded.",
218+
),
219+
)
210220
// NOTE: Hidden until we decide to expose it publicly
211221
.arg(
212222
Arg::new("use_artifact_bundle")
@@ -428,8 +438,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
428438
let wait_for_secs = matches.get_one::<u64>("wait_for").copied();
429439
let wait = matches.get_flag("wait") || wait_for_secs.is_some();
430440
let max_wait = wait_for_secs.map_or(DEFAULT_MAX_WAIT, Duration::from_secs);
431-
432-
processor.upload(&UploadContext {
441+
let upload_context = UploadContext {
433442
org: &org,
434443
project: Some(&project),
435444
release: version.as_deref(),
@@ -439,7 +448,13 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
439448
max_wait,
440449
dedupe: !matches.get_flag("no_dedupe"),
441450
chunk_upload_options: chunk_upload_options.as_ref(),
442-
})?;
451+
};
452+
453+
if matches.get_flag("strict") {
454+
processor.upload_strict(&upload_context)?;
455+
} else {
456+
processor.upload(&upload_context)?;
457+
}
443458

444459
Ok(())
445460
}

src/utils/sourcemaps.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
77
use std::str;
88
use std::str::FromStr;
99

10-
use anyhow::{bail, Context, Error, Result};
10+
use anyhow::{anyhow, bail, Context, Error, Result};
1111
use console::style;
1212
use indicatif::ProgressStyle;
1313
use log::{debug, info, warn};
@@ -805,8 +805,9 @@ impl SourceMapProcessor {
805805
files_needing_upload
806806
}
807807

808-
/// Uploads all files
809-
pub fn upload(&mut self, context: &UploadContext<'_>) -> Result<()> {
808+
/// Uploads all files, and on success, returns the number of files that were
809+
/// uploaded, wrapped in Ok()
810+
pub fn upload(&mut self, context: &UploadContext<'_>) -> Result<usize> {
810811
initialize_legacy_release_upload(context)?;
811812
self.flush_pending_sources();
812813

@@ -852,7 +853,19 @@ impl SourceMapProcessor {
852853
} else {
853854
println!("{} Nothing to upload", style(">").dim());
854855
}
855-
Ok(())
856+
Ok(files_needing_upload)
857+
}
858+
859+
/// Upload all files in "strict" mode. Strict mode differs from a normal upload
860+
/// only when there are no files to upload. In strict mode, having no files to
861+
/// upload results in an error, whereas such an upload is successful in normal
862+
/// (non-strict) mode. On success, the number of uploaded files is returned in
863+
/// an Ok()
864+
pub fn upload_strict(&mut self, context: &UploadContext<'_>) -> Result<usize> {
865+
match self.upload(context) {
866+
Ok(0) => Err(anyhow!("No files to upload (strict mode).")),
867+
other => other,
868+
}
856869
}
857870

858871
/// Injects debug ids into minified source files and sourcemaps.

tests/integration/_cases/sourcemaps/sourcemaps-upload-help.trycmd

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Options:
8282
extensions. To add an extension, all default extensions must be repeated. Specify once per
8383
extension.
8484
Defaults to: `--ext=js --ext=map --ext=jsbundle --ext=bundle`
85+
-s, --strict
86+
Fail with a non-zero exit code if the specified source map file cannot be uploaded.
8587
-h, --help
8688
Print help
8789

0 commit comments

Comments
 (0)