Skip to content

Commit

Permalink
fix(cli/migrate): migrate only known plugins (#9540)
Browse files Browse the repository at this point in the history
* fix(cli/migrate): migrate only known plugins

closes #9533

* use tuple

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
  • Loading branch information
amrbashir and lucasfernog committed Apr 22, 2024
1 parent 35b25f7 commit aaa332c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
7 changes: 7 additions & 0 deletions .changes/cli-migrate-unknown-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri-cli": "patch:bug"
"@tauri-apps/cli": "patch:bug"
---

Fix `tauri migrate` trying to migrate to a non-existing plugin.

47 changes: 27 additions & 20 deletions tooling/cli/src/migrate/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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-{}",
Expand All @@ -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 {
Expand Down

0 comments on commit aaa332c

Please sign in to comment.