diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index f67f0e7b2..a17b1689c 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -267,7 +267,7 @@ fn try_run_package_or_file(args: &[String], r: &Run) -> Result<(), anyhow::Error } // else: local package not found - try to download and install package - try_autoinstall_package(args, &sv, package_download_info) + try_autoinstall_package(args, &sv, package_download_info, r.force_install) } fn try_lookup_command(sv: &mut SplitVersion) -> Result { @@ -317,10 +317,11 @@ fn try_autoinstall_package( args: &[String], sv: &SplitVersion, package: Option, + force_install: bool, ) -> Result<(), anyhow::Error> { let sp = start_spinner(format!("Installing package {} ...", sv.package)); let v = sv.version.as_deref(); - let result = wasmer_registry::install_package(&sv.package, v, package); + let result = wasmer_registry::install_package(&sv.package, v, package, force_install); sp.close(); print!("\r\n"); let (package, buf) = match result { diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 55f4f1aa6..a62a55c1e 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -25,6 +25,10 @@ use wasi::Wasi; /// Same as `wasmer run`, but without the required `path` argument (injected previously) #[derive(Debug, Parser, Clone, Default)] pub struct RunWithoutFile { + /// When installing packages with `wasmer $package`, force re-downloading the package + #[clap(long = "force", short = 'f')] + pub(crate) force_install: bool, + /// Disable the cache #[cfg(feature = "cache")] #[clap(long = "disable-cache")] @@ -147,6 +151,7 @@ impl RunWithoutFile { Run { path: pathbuf, options: RunWithoutFile { + force_install: self.force_install, #[cfg(feature = "cache")] disable_cache: self.disable_cache, invoke: self.invoke, diff --git a/lib/registry/src/lib.rs b/lib/registry/src/lib.rs index ee38798ee..43460f963 100644 --- a/lib/registry/src/lib.rs +++ b/lib/registry/src/lib.rs @@ -904,6 +904,7 @@ pub fn install_package( name: &str, version: Option<&str>, package_download_info: Option, + force_install: bool, ) -> Result<(LocalPackage, PathBuf), String> { let package_info = match package_download_info { Some(s) => s, @@ -932,17 +933,19 @@ pub fn install_package( continue; } - match get_if_package_has_new_version( - r, - name, - version.map(|s| s.to_string()), - Duration::from_secs(60 * 5), - ) { - Ok(Some(package)) => { - url_of_package = Some((r, package)); - break; + if !force_install { + match get_if_package_has_new_version( + r, + name, + version.map(|s| s.to_string()), + Duration::from_secs(60 * 5), + ) { + Ok(Some(package)) => { + url_of_package = Some((r, package)); + break; + } + _ => {} } - _ => {} } match query_package_from_registry(r, name, version) {