mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
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>
This commit is contained in:
6
.changes/add-community-plugins.md
Normal file
6
.changes/add-community-plugins.md
Normal file
@@ -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.
|
||||
@@ -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();
|
||||
|
||||
@@ -69,6 +69,7 @@ pub fn known_plugins() -> HashMap<&'static str, PluginMetadata> {
|
||||
"shell",
|
||||
"upload",
|
||||
"websocket",
|
||||
"opener",
|
||||
] {
|
||||
plugins.entry(p).or_default();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user