Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aaa332c

Browse files
fix(cli/migrate): migrate only known plugins (tauri-apps#9540)
* fix(cli/migrate): migrate only known plugins closes tauri-apps#9533 * use tuple --------- Co-authored-by: Lucas Nogueira <[email protected]>
1 parent 35b25f7 commit aaa332c

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-cli": "patch:bug"
3+
"@tauri-apps/cli": "patch:bug"
4+
---
5+
6+
Fix `tauri migrate` trying to migrate to a non-existing plugin.
7+

tooling/cli/src/migrate/frontend.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,22 @@ use anyhow::Context;
1010

1111
use std::{fs, path::Path};
1212

13-
const CORE_API_MODULES: &[&str] = &["dpi", "event", "path", "core", "window", "mocks"];
14-
const JS_EXTENSIONS: &[&str] = &["js", "jsx", "ts", "tsx", "mjs"];
13+
// (from, to)
14+
const RENAMED_MODULES: &[(&str, &str)] = &[("tauri", "core"), ("window", "webviewWindow")];
15+
const PLUGINIFIED_MODULES: &[&str] = &[
16+
"cli",
17+
"clipboard",
18+
"dialog",
19+
"fs",
20+
"globalShortcut",
21+
"http",
22+
"notification",
23+
"os",
24+
"process",
25+
"shell",
26+
"updater",
27+
];
28+
const JS_EXTENSIONS: &[&str] = &["js", "mjs", "jsx", "ts", "mts", "tsx"];
1529

1630
/// Returns a list of paths that could not be migrated
1731
pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> {
@@ -39,23 +53,12 @@ pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> {
3953
let original = cap.get(0).unwrap().as_bytes();
4054
let original = String::from_utf8_lossy(original).to_string();
4155

42-
if module == "tauri" {
43-
let new = "@tauri-apps/api/core".to_string();
44-
log::info!("Replacing `{original}` with `{new}` on {}", path.display());
45-
new
46-
} else if module == "window" {
47-
let new = "@tauri-apps/api/webviewWindow".to_string();
48-
log::info!("Replacing `{original}` with `{new}` on {}", path.display());
49-
new
50-
} else if CORE_API_MODULES.contains(&module.as_str()) {
51-
original
52-
} else {
56+
let new = if let Some((_, renamed_to)) =
57+
RENAMED_MODULES.iter().find(|(from, _to)| *from == module)
58+
{
59+
renamed_to.to_string()
60+
} else if PLUGINIFIED_MODULES.contains(&module.as_str()) {
5361
let plugin = format!("@tauri-apps/plugin-{module}");
54-
log::info!(
55-
"Replacing `{original}` with `{plugin}` on {}",
56-
path.display()
57-
);
58-
5962
new_npm_packages.push(plugin.clone());
6063
new_cargo_packages.push(format!(
6164
"tauri-plugin-{}",
@@ -65,9 +68,13 @@ pub fn migrate(app_dir: &Path, tauri_dir: &Path) -> Result<()> {
6568
&module
6669
}
6770
));
68-
6971
plugin
70-
}
72+
} else {
73+
return original;
74+
};
75+
76+
log::info!("Replacing `{original}` with `{new}` on {}", path.display());
77+
new
7178
});
7279

7380
if new_contents != js_contents {

0 commit comments

Comments
 (0)