Skip to content

Commit

Permalink
Allow publishing packages without a module
Browse files Browse the repository at this point in the history
Removes the check that requires a module to be specified when publishing
a package.

Removed because modules should not be mandatory - packages with just a
file system, or with a command that uses the module of a dependency are
perfectly valid.
  • Loading branch information
theduke committed Mar 27, 2023
1 parent 3a99963 commit 74921fd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ pub struct Publish {

#[derive(Debug, Error)]
enum PublishError {
#[error("Cannot publish without a module.")]
NoModule,
#[error("Unable to publish the \"{module}\" module because \"{}\" is not a file", path.display())]
SourceMustBeFile { module: String, path: PathBuf },
#[error("Unable to load the bindings for \"{module}\" because \"{}\" doesn't exist", path.display())]
Expand Down Expand Up @@ -115,7 +113,10 @@ impl Publish {
builder
.finish()
.map_err(|e| anyhow::anyhow!("failed to finish .tar.gz builder: {e}"))?;
let tar_archive_data = builder.into_inner().map_err(|_| PublishError::NoModule)?;
let tar_archive_data = builder
.into_inner()
// NOTE: only fails if `Builder::finish()` was not called.
.expect("tar archive .finish() was not called");
let archive_name = "package.tar.gz".to_string();
let archive_dir = tempfile::TempDir::new()?;
let archive_dir_path: &std::path::Path = archive_dir.as_ref();
Expand Down Expand Up @@ -172,7 +173,7 @@ fn construct_tar_gz(
cwd: &Path,
) -> Result<(Option<String>, Option<String>), anyhow::Error> {
let package = &manifest.package;
let modules = manifest.module.as_ref().ok_or(PublishError::NoModule)?;
let modules = manifest.module.as_deref().unwrap_or_default();

let readme = match package.readme.as_ref() {
None => None,
Expand Down

0 comments on commit 74921fd

Please sign in to comment.