Skip to content

Commit

Permalink
try to build the package before publishing it
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed Jan 31, 2024
1 parent 290ab9f commit 4085e73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/cli/src/commands/package/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub struct PackageBuild {
///
/// Defaults to current directory.
package: Option<PathBuf>,

/// Only checks whether the package could be built successfully
#[clap(long)]
check: bool,
}

static READING_MANIFEST_EMOJI: Emoji<'_, '_> = Emoji("📖 ", "");
Expand All @@ -28,6 +32,15 @@ static WRITING_PACKAGE_EMOJI: Emoji<'_, '_> = Emoji("📦 ", "");
static SPARKLE: Emoji<'_, '_> = Emoji("✨ ", ":-)");

impl PackageBuild {
pub(crate) fn check(package_path: PathBuf) -> Self {
PackageBuild {
out: None,
quiet: true,
package: Some(package_path),
check: true,
}
}

pub(crate) fn execute(&self) -> Result<(), anyhow::Error> {
let manifest_path = self.manifest_path()?;
let pkg = webc::wasmer_package::Package::from_manifest(manifest_path)?;
Expand All @@ -51,6 +64,12 @@ impl PackageBuild {
.context("could not load package manifest")?
.context("package does not contain a Wasmer manifest")?;

// rest of the code writes the package to disk and is irrelevant
// to checking.
if self.check {
return Ok(());
}

let pkgname = manifest.name.replace('/', "-");
let name = format!("{}-{}.webc", pkgname, manifest.version,);

Expand Down Expand Up @@ -169,6 +188,7 @@ description = "hello"
package: Some(path.to_owned()),
out: Some(path.to_owned()),
quiet: true,
check: false,
};

cmd.execute().unwrap();
Expand Down
9 changes: 9 additions & 0 deletions lib/cli/src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use anyhow::Context as _;
use clap::Parser;
use wasmer_registry::{publish::PublishWait, wasmer_env::WasmerEnv};

use super::PackageBuild;

/// Publish a package to the package registry.
#[derive(Debug, Parser)]
pub struct Publish {
Expand Down Expand Up @@ -47,6 +49,13 @@ pub struct Publish {
impl Publish {
/// Executes `wasmer publish`
pub fn execute(&self) -> Result<(), anyhow::Error> {
// first check if the package could be built successfuly
let package_path = match self.package_path.as_ref() {
Some(s) => std::env::current_dir()?.join(s),
None => std::env::current_dir()?,
};
PackageBuild::check(package_path).execute()?;

let token = self
.env
.token()
Expand Down

0 comments on commit 4085e73

Please sign in to comment.