diff --git a/lib/cli/src/commands/package/build.rs b/lib/cli/src/commands/package/build.rs index 2fbbf708450..6f4e5648fb2 100644 --- a/lib/cli/src/commands/package/build.rs +++ b/lib/cli/src/commands/package/build.rs @@ -20,6 +20,10 @@ pub struct PackageBuild { /// /// Defaults to current directory. package: Option, + + /// Only checks whether the package could be built successfully + #[clap(long)] + check: bool, } static READING_MANIFEST_EMOJI: Emoji<'_, '_> = Emoji("📖 ", ""); @@ -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)?; @@ -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,); @@ -169,6 +188,7 @@ description = "hello" package: Some(path.to_owned()), out: Some(path.to_owned()), quiet: true, + check: false, }; cmd.execute().unwrap(); diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs index 040af89bd0c..4c129d08c22 100644 --- a/lib/cli/src/commands/publish.rs +++ b/lib/cli/src/commands/publish.rs @@ -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 { @@ -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()