From 02b2f964a70c61ff08b5052bd9fcde472d706d9c Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 27 Aug 2024 11:02:14 -0300 Subject: [PATCH] fix(cli): `add` command version requirement for known plugin npm (#10795) small regression from #10699 - NPM install is now prompting users to select the version --- .changes/fix-add-plugin-npm-version-req.md | 6 ++++++ tooling/cli/src/add.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changes/fix-add-plugin-npm-version-req.md diff --git a/.changes/fix-add-plugin-npm-version-req.md b/.changes/fix-add-plugin-npm-version-req.md new file mode 100644 index 000000000000..0b24609460f5 --- /dev/null +++ b/.changes/fix-add-plugin-npm-version-req.md @@ -0,0 +1,6 @@ +--- +'tauri-cli': 'patch:bug' +'@tauri-apps/cli': 'patch:bug' +--- + +Fix the `add` command NPM version specifier for known plugins from `2.0.0-rc` (unknown version requirement) to `^2.0.0-rc`. diff --git a/tooling/cli/src/add.rs b/tooling/cli/src/add.rs index 7b488b5fcc54..e6efc5a3c557 100644 --- a/tooling/cli/src/add.rs +++ b/tooling/cli/src/add.rs @@ -68,11 +68,14 @@ pub fn run(options: Options) -> Result<()> { .then_some(r#"cfg(any(target_os = "android", target_os = "ios"))"#) }); - let version = version.or(metadata.version_req.as_deref()); + let cargo_version_req = version.or(metadata.version_req.as_deref()); + let npm_version_req = version + .map(ToString::to_string) + .or(metadata.version_req.as_ref().map(|v| format!("^{v}"))); cargo::install_one(cargo::CargoInstallOptions { name: &crate_name, - version, + version: cargo_version_req, branch: options.branch.as_deref(), rev: options.rev.as_deref(), tag: options.tag.as_deref(), @@ -85,7 +88,7 @@ pub fn run(options: Options) -> Result<()> { .map(PackageManager::from_project) .and_then(|managers| managers.into_iter().next()) { - let npm_spec = match (version, options.tag, options.rev, options.branch) { + let npm_spec = match (npm_version_req, options.tag, options.rev, options.branch) { (Some(version), _, _, _) => { format!("{npm_name}@{version}") }