From aaa332c6e78c956debd11efda021a0406621a01d Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 22 Apr 2024 15:28:19 +0200 Subject: [PATCH] fix(cli/migrate): migrate only known plugins (#9540) * fix(cli/migrate): migrate only known plugins closes #9533 * use tuple --------- Co-authored-by: Lucas Nogueira --- .changes/cli-migrate-unknown-plugins.md | 7 ++++ tooling/cli/src/migrate/frontend.rs | 47 ++++++++++++++----------- 2 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 .changes/cli-migrate-unknown-plugins.md diff --git a/.changes/cli-migrate-unknown-plugins.md b/.changes/cli-migrate-unknown-plugins.md new file mode 100644 index 000000000..afa03f525 --- /dev/null +++ b/.changes/cli-migrate-unknown-plugins.md @@ -0,0 +1,7 @@ +--- +"tauri-cli": "patch:bug" +"@tauri-apps/cli": "patch:bug" +--- + +Fix `tauri migrate` trying to migrate to a non-existing plugin. + diff --git a/tooling/cli/src/migrate/frontend.rs b/tooling/cli/src/migrate/frontend.rs index 57bcb8292..23317e01b 100644 --- a/tooling/cli/src/migrate/frontend.rs +++ b/tooling/cli/src/migrate/frontend.rs @@ -10,8 +10,22 @@ use anyhow::Context; use std::{fs, path::Path}; -const CORE_API_MODULES: &[&str] = &["dpi", "event", "path", "core", "window", "mocks"]; -const JS_EXTENSIONS: &[&str] = &["js", "jsx", "ts", "tsx", "mjs"]; +// (from, to) +const RENAMED_MODULES: &[(&str, &str)] = &[("tauri", "core"), ("window", "webviewWindow")]; +const PLUGINIFIED_MODULES: &[&str] = &[ + "cli", + "clipboard", + "dialog", + "fs", + "globalShortcut", + "http", + "notification", + "os", + "process", + "shell", + "updater", +]; +const JS_EXTENSIONS: &[&str] = &["js", "mjs", "jsx", "ts", "mts", "tsx"]; /// Returns a list of paths that could not be migrated pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> { @@ -39,23 +53,12 @@ pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> { let original = cap.get(0).unwrap().as_bytes(); let original = String::from_utf8_lossy(original).to_string(); - if module == "tauri" { - let new = "@tauri-apps/api/core".to_string(); - log::info!("Replacing `{original}` with `{new}` on {}", path.display()); - new - } else if module == "window" { - let new = "@tauri-apps/api/webviewWindow".to_string(); - log::info!("Replacing `{original}` with `{new}` on {}", path.display()); - new - } else if CORE_API_MODULES.contains(&module.as_str()) { - original - } else { + let new = if let Some((_, renamed_to)) = + RENAMED_MODULES.iter().find(|(from, _to)| *from == module) + { + renamed_to.to_string() + } else if PLUGINIFIED_MODULES.contains(&module.as_str()) { let plugin = format!("@tauri-apps/plugin-{module}"); - log::info!( - "Replacing `{original}` with `{plugin}` on {}", - path.display() - ); - new_npm_packages.push(plugin.clone()); new_cargo_packages.push(format!( "tauri-plugin-{}", @@ -65,9 +68,13 @@ pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> { &module } )); - plugin - } + } else { + return original; + }; + + log::info!("Replacing `{original}` with `{new}` on {}", path.display()); + new }); if new_contents != js_contents {