Skip to content

Commit

Permalink
fix(push): ensure version is non-empty when pushing to registry (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon authored Feb 13, 2025
1 parent 355a3e9 commit 5c8fc5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/commands/src/commands/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::utils::{info, remark, success, warning};
use clap::Parser;
use soldeer_core::{
errors::PublishError,
push::{filter_ignored_files, push_version, validate_name},
push::{filter_ignored_files, push_version, validate_name, validate_version},
utils::check_dotfiles,
Result,
};
Expand Down Expand Up @@ -75,6 +75,7 @@ pub(crate) async fn push_command(cmd: Push) -> Result<()> {
cmd.dependency.split_once('~').expect("dependency string should have name and version");

validate_name(dependency_name)?;
validate_version(dependency_version)?;

if let Some(zip_path) =
push_version(dependency_name, dependency_version, path, &files_to_copy, cmd.dry_run).await?
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ pub enum PublishError {
#[error("invalid package name, only alphanumeric characters, `-` and `@` are allowed. Length must be between 3 and 100 characters")]
InvalidName,

#[error("package version cannot be empty")]
EmptyVersion,

#[error("user cancelled operation")]
UserAborted,

Expand Down
12 changes: 12 additions & 0 deletions crates/core/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pub fn validate_name(name: &str) -> Result<()> {
Ok(())
}

pub fn validate_version(version: &str) -> Result<()> {
if version.is_empty() {
return Err(PublishError::EmptyVersion);
}
Ok(())
}

/// Create a zip file from a list of files.
///
/// The zip file will be created in the root directory, with the provided name and the `.zip`
Expand Down Expand Up @@ -277,6 +284,11 @@ mod tests {
assert!(validate_name(&"a".repeat(101)).is_err());
}

#[test]
fn test_empty_version() {
assert!(validate_version("").is_err());
}

#[test]
fn test_filter_files_to_copy() {
let dir = testdir!();
Expand Down

0 comments on commit 5c8fc5e

Please sign in to comment.