Skip to content

Commit

Permalink
fix(cli): migrate v1 plugin dependencies, prevent dup, closes #10650 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Aug 16, 2024
1 parent 255d64e commit 10fb027
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/migrate-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
---

Migrate v1 plugins to their v2 releases.
6 changes: 6 additions & 0 deletions .changes/migrate-prevent-duplications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch:bug
"@tauri-apps/cli": patch:bug
---

Prevent duplicate permissions on v1 migration.
3 changes: 3 additions & 0 deletions tooling/cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('@')
Expand Down
14 changes: 10 additions & 4 deletions tooling/cli/src/migrate/migrations/v1/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -474,8 +477,11 @@ fn allowlist_to_permissions(

// shell
if allowlist.shell.scope.0.is_empty() {
permissions!(allowlist, permissions, shell, execute => "shell:allow-execute");
permissions!(allowlist, permissions, shell, sidecar => "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
Expand Down
20 changes: 20 additions & 0 deletions tooling/cli/src/migrate/migrations/v1/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/migrate/migrations/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 10fb027

Please sign in to comment.