From df21e07842482b321a865979d92aea9b10d21ad9 Mon Sep 17 00:00:00 2001 From: "marco.mengelkoch" Date: Sun, 5 Jan 2025 14:07:11 +0100 Subject: [PATCH 1/3] add "--inofficial" parameter to "tauri add {plugin}" --- crates/tauri-cli/src/add.rs | 24 ++++++++++++++----- .../src/migrate/migrations/v1/mod.rs | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/tauri-cli/src/add.rs b/crates/tauri-cli/src/add.rs index 56ad58ef0495..edc537be6913 100644 --- a/crates/tauri-cli/src/add.rs +++ b/crates/tauri-cli/src/add.rs @@ -35,6 +35,9 @@ pub struct Options { /// Don't format code with rustfmt #[clap(long)] pub no_fmt: bool, + /// Use npm package tauri-plugin-{name}-api + #[clap(long)] + pub inofficial: bool, } pub fn command(options: Options) -> Result<()> { @@ -89,18 +92,27 @@ pub fn run(options: Options) -> Result<()> { _ => format!("~{v}"), })); - let npm_spec = match (npm_version_req, options.tag, options.rev, options.branch) { - (Some(version_req), _, _, _) => format!("{npm_name}@{version_req}"), - (None, Some(tag), None, None) => { + let npm_spec = match ( + npm_version_req, + options.tag, + options.rev, + options.branch, + options.inofficial, + ) { + (Some(version_req), _, _, _, _) => format!("{npm_name}@{version_req}"), + (None, Some(tag), None, None, _) => { format!("tauri-apps/tauri-plugin-{plugin}#{tag}") } - (None, None, Some(rev), None) => { + (None, None, Some(rev), None, _) => { format!("tauri-apps/tauri-plugin-{plugin}#{rev}") } - (None, None, None, Some(branch)) => { + (None, None, None, Some(branch), _) => { format!("tauri-apps/tauri-plugin-{plugin}#{branch}") } - (None, None, None, None) => npm_name, + (None, None, None, None, true) => { + format!("tauri-plugin-{plugin}-api") + } + (None, None, None, None, false) => npm_name, _ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"), }; manager.install(&[npm_spec], tauri_dir)?; diff --git a/crates/tauri-cli/src/migrate/migrations/v1/mod.rs b/crates/tauri-cli/src/migrate/migrations/v1/mod.rs index 8be16e3e2b37..68464c894d63 100644 --- a/crates/tauri-cli/src/migrate/migrations/v1/mod.rs +++ b/crates/tauri-cli/src/migrate/migrations/v1/mod.rs @@ -31,6 +31,7 @@ pub fn run() -> Result<()> { tag: None, rev: None, no_fmt: false, + inofficial: false, }) .with_context(|| format!("Could not migrate plugin '{plugin}'"))?; } From bf255d88ab145981ae7fed2a084e3863fc452686 Mon Sep 17 00:00:00 2001 From: "marco.mengelkoch" Date: Sun, 5 Jan 2025 18:57:25 +0100 Subject: [PATCH 2/3] rename "--inofficial" to "--community" --- crates/tauri-cli/src/add.rs | 6 +++--- crates/tauri-cli/src/migrate/migrations/v1/mod.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/tauri-cli/src/add.rs b/crates/tauri-cli/src/add.rs index edc537be6913..61d0440ce003 100644 --- a/crates/tauri-cli/src/add.rs +++ b/crates/tauri-cli/src/add.rs @@ -36,8 +36,8 @@ pub struct Options { #[clap(long)] pub no_fmt: bool, /// Use npm package tauri-plugin-{name}-api - #[clap(long)] - pub inofficial: bool, + #[clap(short, long)] + pub community: bool, } pub fn command(options: Options) -> Result<()> { @@ -97,7 +97,7 @@ pub fn run(options: Options) -> Result<()> { options.tag, options.rev, options.branch, - options.inofficial, + options.community, ) { (Some(version_req), _, _, _, _) => format!("{npm_name}@{version_req}"), (None, Some(tag), None, None, _) => { diff --git a/crates/tauri-cli/src/migrate/migrations/v1/mod.rs b/crates/tauri-cli/src/migrate/migrations/v1/mod.rs index 68464c894d63..ef48400ca529 100644 --- a/crates/tauri-cli/src/migrate/migrations/v1/mod.rs +++ b/crates/tauri-cli/src/migrate/migrations/v1/mod.rs @@ -31,7 +31,7 @@ pub fn run() -> Result<()> { tag: None, rev: None, no_fmt: false, - inofficial: false, + community: false, }) .with_context(|| format!("Could not migrate plugin '{plugin}'"))?; } From adc96620b6c4369eaeb7b84e425f37b5b7a46272 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Tue, 7 Jan 2025 09:56:40 -0300 Subject: [PATCH 3/3] use tauri-plugin-{plugin}-api for unknown plugins --- .changes/add-community-plugins.md | 6 +++ crates/tauri-cli/src/add.rs | 43 ++++++++++--------- crates/tauri-cli/src/helpers/plugins.rs | 1 + .../src/migrate/migrations/v1/mod.rs | 1 - 4 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 .changes/add-community-plugins.md diff --git a/.changes/add-community-plugins.md b/.changes/add-community-plugins.md new file mode 100644 index 000000000000..afddc81d539d --- /dev/null +++ b/.changes/add-community-plugins.md @@ -0,0 +1,6 @@ +--- +"tauri-cli": patch:bug +"@tauri-apps/cli": patch:bug +--- + +Properly add NPM packages for community plugins when using the `tauri add` command. diff --git a/crates/tauri-cli/src/add.rs b/crates/tauri-cli/src/add.rs index 61d0440ce003..968cbd83ca62 100644 --- a/crates/tauri-cli/src/add.rs +++ b/crates/tauri-cli/src/add.rs @@ -35,9 +35,6 @@ pub struct Options { /// Don't format code with rustfmt #[clap(long)] pub no_fmt: bool, - /// Use npm package tauri-plugin-{name}-api - #[clap(short, long)] - pub community: bool, } pub fn command(options: Options) -> Result<()> { @@ -52,12 +49,25 @@ pub fn run(options: Options) -> Result<()> { .map(|(p, v)| (p, Some(v))) .unwrap_or((&options.plugin, None)); + let mut plugins = crate::helpers::plugins::known_plugins(); + let (metadata, is_known) = plugins + .remove(plugin) + .map(|metadata| (metadata, true)) + .unwrap_or_default(); + let plugin_snake_case = plugin.replace('-', "_"); let crate_name = format!("tauri-plugin-{plugin}"); - let npm_name = format!("@tauri-apps/plugin-{plugin}"); + let npm_name = if is_known { + format!("tauri-apps/plugin-{plugin}") + } else { + format!("tauri-plugin-{plugin}-api") + }; - let mut plugins = crate::helpers::plugins::known_plugins(); - let metadata = plugins.remove(plugin).unwrap_or_default(); + if !is_known && (options.tag.is_some() || options.rev.is_some() || options.branch.is_some()) { + anyhow::bail!( + "Git options --tag, --rev and --branch can only be used with official Tauri plugins" + ); + } let frontend_dir = resolve_frontend_dir(); let tauri_dir = tauri_dir(); @@ -92,27 +102,18 @@ pub fn run(options: Options) -> Result<()> { _ => format!("~{v}"), })); - let npm_spec = match ( - npm_version_req, - options.tag, - options.rev, - options.branch, - options.community, - ) { - (Some(version_req), _, _, _, _) => format!("{npm_name}@{version_req}"), - (None, Some(tag), None, None, _) => { + let npm_spec = match (npm_version_req, options.tag, options.rev, options.branch) { + (Some(version_req), _, _, _) => format!("{npm_name}@{version_req}"), + (None, Some(tag), None, None) => { format!("tauri-apps/tauri-plugin-{plugin}#{tag}") } - (None, None, Some(rev), None, _) => { + (None, None, Some(rev), None) => { format!("tauri-apps/tauri-plugin-{plugin}#{rev}") } - (None, None, None, Some(branch), _) => { + (None, None, None, Some(branch)) => { format!("tauri-apps/tauri-plugin-{plugin}#{branch}") } - (None, None, None, None, true) => { - format!("tauri-plugin-{plugin}-api") - } - (None, None, None, None, false) => npm_name, + (None, None, None, None) => npm_name, _ => anyhow::bail!("Only one of --tag, --rev and --branch can be specified"), }; manager.install(&[npm_spec], tauri_dir)?; diff --git a/crates/tauri-cli/src/helpers/plugins.rs b/crates/tauri-cli/src/helpers/plugins.rs index 9c676150aeb5..83201231b705 100644 --- a/crates/tauri-cli/src/helpers/plugins.rs +++ b/crates/tauri-cli/src/helpers/plugins.rs @@ -69,6 +69,7 @@ pub fn known_plugins() -> HashMap<&'static str, PluginMetadata> { "shell", "upload", "websocket", + "opener", ] { plugins.entry(p).or_default(); } diff --git a/crates/tauri-cli/src/migrate/migrations/v1/mod.rs b/crates/tauri-cli/src/migrate/migrations/v1/mod.rs index ef48400ca529..8be16e3e2b37 100644 --- a/crates/tauri-cli/src/migrate/migrations/v1/mod.rs +++ b/crates/tauri-cli/src/migrate/migrations/v1/mod.rs @@ -31,7 +31,6 @@ pub fn run() -> Result<()> { tag: None, rev: None, no_fmt: false, - community: false, }) .with_context(|| format!("Could not migrate plugin '{plugin}'"))?; }