Skip to content

Commit 98f62e6

Browse files
marcomqlucasfernog
andauthored
fix(cli): tauri add NPM packages for community plugins (#12246)
It currently isn't possible to simply add a community plugin the same was as adding official plugins. Trying to perform `npm run tauri add tauri-plugin-python` is trying to install npm package `@tauri-apps/plugin-python`. But the npm scope `@tauri-apps/` is reserved for official tauri plugins. The official documentation recommends to name the npm package `tauri-plugin-{name}-api` and it should be possible to have a parameter that makes it possible to install that package. - closes #12217 This changes the command to check if the plugin is an official tauri plugin or not, using the appropriate npm package name format --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent c130af6 commit 98f62e6

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.changes/add-community-plugins.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Properly add NPM packages for community plugins when using the `tauri add` command.

crates/tauri-cli/src/add.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,25 @@ pub fn run(options: Options) -> Result<()> {
4949
.map(|(p, v)| (p, Some(v)))
5050
.unwrap_or((&options.plugin, None));
5151

52+
let mut plugins = crate::helpers::plugins::known_plugins();
53+
let (metadata, is_known) = plugins
54+
.remove(plugin)
55+
.map(|metadata| (metadata, true))
56+
.unwrap_or_default();
57+
5258
let plugin_snake_case = plugin.replace('-', "_");
5359
let crate_name = format!("tauri-plugin-{plugin}");
54-
let npm_name = format!("@tauri-apps/plugin-{plugin}");
60+
let npm_name = if is_known {
61+
format!("tauri-apps/plugin-{plugin}")
62+
} else {
63+
format!("tauri-plugin-{plugin}-api")
64+
};
5565

56-
let mut plugins = crate::helpers::plugins::known_plugins();
57-
let metadata = plugins.remove(plugin).unwrap_or_default();
66+
if !is_known && (options.tag.is_some() || options.rev.is_some() || options.branch.is_some()) {
67+
anyhow::bail!(
68+
"Git options --tag, --rev and --branch can only be used with official Tauri plugins"
69+
);
70+
}
5871

5972
let frontend_dir = resolve_frontend_dir();
6073
let tauri_dir = tauri_dir();

crates/tauri-cli/src/helpers/plugins.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub fn known_plugins() -> HashMap<&'static str, PluginMetadata> {
6969
"shell",
7070
"upload",
7171
"websocket",
72+
"opener",
7273
] {
7374
plugins.entry(p).or_default();
7475
}

0 commit comments

Comments
 (0)