Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): tauri add NPM packages for community plugins #12246

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/add-community-plugins.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 16 additions & 3 deletions crates/tauri-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,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();
Expand Down
1 change: 1 addition & 0 deletions crates/tauri-cli/src/helpers/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub fn known_plugins() -> HashMap<&'static str, PluginMetadata> {
"shell",
"upload",
"websocket",
"opener",
] {
plugins.entry(p).or_default();
}
Expand Down
Loading