fix(cli): migrate v1 plugin dependencies, prevent dup, closes #10650 (#10656)

This commit is contained in:
Lucas Fernandes Nogueira 2024-08-16 19:58:20 -03:00 committed by GitHub
parent 255d64e3dc
commit 10fb027b75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 46 additions and 5 deletions

View File

@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---
Migrate v1 plugins to their v2 releases.

View File

@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---
Prevent duplicate permissions on v1 migration.

View File

@ -39,7 +39,10 @@ pub struct Options {
pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
run(options)
}
pub fn run(options: Options) -> Result<()> {
let (plugin, version) = options
.plugin
.split_once('@')

View File

@ -386,13 +386,16 @@ fn allowlist_to_permissions(
allowlist: tauri_utils_v1::config::AllowlistConfig,
) -> Vec<PermissionEntry> {
macro_rules! permissions {
($allowlist: ident, $permissions_list: ident, $object: ident, $field: ident => $associated_permission: expr) => {
($allowlist: ident, $permissions_list: ident, $object: ident, $field: ident => $associated_permission: expr) => {{
if $allowlist.all || $allowlist.$object.all || $allowlist.$object.$field {
$permissions_list.push(PermissionEntry::PermissionRef(
$associated_permission.to_string().try_into().unwrap(),
));
true
} else {
false
}
};
}};
}
let mut permissions = Vec::new();
@ -474,8 +477,11 @@ fn allowlist_to_permissions(
// shell
if allowlist.shell.scope.0.is_empty() {
permissions!(allowlist, permissions, shell, execute => "shell:allow-execute");
let added = permissions!(allowlist, permissions, shell, execute => "shell:allow-execute");
// prevent duplicated permission
if !added {
permissions!(allowlist, permissions, shell, sidecar => "shell:allow-execute");
}
} else {
let allowed = allowlist
.shell

View File

@ -45,6 +45,22 @@ fn migrate_manifest(manifest: &mut Document) -> Result<()> {
("tauri-codegen", "dependencies"),
("tauri-macros", "dependencies"),
("tauri-runtime-wry", "dependencies"),
// normal deps - plugins
("tauri-plugin-authenticator", "dependencies"),
("tauri-plugin-autostart", "dependencies"),
("tauri-plugin-fs-extra", "dependencies"),
("tauri-plugin-fs-watch", "dependencies"),
("tauri-plugin-localhost", "dependencies"),
("tauri-plugin-log", "dependencies"),
("tauri-plugin-persisted-scope", "dependencies"),
("tauri-plugin-positioner", "dependencies"),
("tauri-plugin-single-instance", "dependencies"),
("tauri-plugin-sql", "dependencies"),
("tauri-plugin-store", "dependencies"),
("tauri-plugin-stronghold", "dependencies"),
("tauri-plugin-upload", "dependencies"),
("tauri-plugin-websocket", "dependencies"),
("tauri-plugin-window-state", "dependencies"),
// dev
("tauri", "dev-dependencies"),
("tauri-utils", "dev-dependencies"),
@ -207,6 +223,10 @@ fn migrate_dependency_table<D: TableLike>(
remove: &[&str],
rename: &[(&str, &str)],
) {
dep.remove("rev");
dep.remove("git");
dep.remove("branch");
dep.remove("tag");
*dep.entry("version").or_insert(Item::None) = Item::Value(version.into());
let manifest_features = dep.entry("features").or_insert(Item::None);
if let Some(features_array) = manifest_features.as_array_mut() {

View File

@ -25,7 +25,7 @@ pub fn run() -> Result<()> {
// Add plugins
for plugin in migrated.plugins {
crate::add::command(crate::add::Options {
crate::add::run(crate::add::Options {
plugin: plugin.clone(),
branch: None,
tag: None,