Skip to content

Commit f3837d5

Browse files
authored
fix(cli): broken v1 updater migration, add TOML support, closes #10508 (#10539)
- make the v1 config migration more resilient by checking null values - fix "targets: all" incorrectly migrating createUpdaterArtifacts when there's no updater configuration (this is problematic because this targets config is the default) - migrate Tauri.toml - add more tests
1 parent 71d0064 commit f3837d5

File tree

4 files changed

+361
-24
lines changed

4 files changed

+361
-24
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Improve migration tooling by supporting TOML configs, handle nulls and properly check for updater migration.

tooling/cli/src/migrate/migrations/v1/config.rs

Lines changed: 154 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ pub fn migrate(tauri_dir: &Path) -> Result<MigratedConfig> {
2121
tauri_utils_v1::config::parse::parse_value(tauri_dir.join("tauri.conf.json"))
2222
{
2323
let migrated = migrate_config(&mut config)?;
24-
fs::write(&config_path, serde_json::to_string_pretty(&config)?)?;
24+
if config_path.extension().map_or(false, |ext| ext == "toml") {
25+
fs::write(&config_path, toml::to_string_pretty(&config)?)?;
26+
} else {
27+
fs::write(&config_path, serde_json::to_string_pretty(&config)?)?;
28+
}
2529

2630
let mut permissions: Vec<PermissionEntry> = vec!["core:default"]
2731
.into_iter()
@@ -101,8 +105,12 @@ fn migrate_config(config: &mut Value) -> Result<MigratedConfig> {
101105
}
102106

103107
// system tray
104-
if let Some(tray) = tauri_config.remove("systemTray") {
105-
tauri_config.insert("trayIcon".into(), tray);
108+
if let Some((tray, key)) = tauri_config
109+
.remove("systemTray")
110+
.map(|v| (v, "trayIcon"))
111+
.or_else(|| tauri_config.remove("system-tray").map(|v| (v, "tray-icon")))
112+
{
113+
tauri_config.insert(key.into(), tray);
106114
}
107115

108116
// cli
@@ -114,9 +122,21 @@ fn migrate_config(config: &mut Value) -> Result<MigratedConfig> {
114122
process_updater(tauri_config, &mut plugins, &mut migrated)?;
115123
}
116124

117-
config.insert("plugins".into(), plugins.into());
125+
process_bundle(config, &migrated);
126+
127+
// if we have migrated the updater config, let's ensure createUpdaterArtifacts is set
128+
if plugins.contains_key("updater") {
129+
let bundle_config = config
130+
.entry("bundle")
131+
.or_insert_with(|| Value::Object(Default::default()))
132+
.as_object_mut()
133+
.unwrap();
134+
if !bundle_config.contains_key("createUpdaterArtifacts") {
135+
bundle_config.insert("createUpdaterArtifacts".to_owned(), "v1Compatible".into());
136+
}
137+
}
118138

119-
process_bundle(config);
139+
config.insert("plugins".into(), plugins.into());
120140

121141
if let Some(tauri_config) = config.remove("tauri") {
122142
config.insert("app".into(), tauri_config);
@@ -129,8 +149,16 @@ fn migrate_config(config: &mut Value) -> Result<MigratedConfig> {
129149
fn process_package_metadata(config: &mut Map<String, Value>) {
130150
if let Some(mut package_config) = config.remove("package") {
131151
if let Some(package_config) = package_config.as_object_mut() {
132-
if let Some(product_name) = package_config.remove("productName") {
133-
config.insert("productName".into(), product_name);
152+
if let Some((product_name, key)) = package_config
153+
.remove("productName")
154+
.map(|v| (v, "productName"))
155+
.or_else(|| {
156+
package_config
157+
.remove("product-name")
158+
.map(|v| (v, "product-name"))
159+
})
160+
{
161+
config.insert(key.into(), product_name);
134162
}
135163

136164
if let Some(version) = package_config.remove("version") {
@@ -152,25 +180,45 @@ fn process_package_metadata(config: &mut Map<String, Value>) {
152180

153181
fn process_build(config: &mut Map<String, Value>) {
154182
if let Some(build_config) = config.get_mut("build").and_then(|b| b.as_object_mut()) {
155-
if let Some(dist_dir) = build_config.remove("distDir") {
156-
build_config.insert("frontendDist".into(), dist_dir);
183+
if let Some((dist_dir, key)) = build_config
184+
.remove("distDir")
185+
.map(|v| (v, "frontendDist"))
186+
.or_else(|| {
187+
build_config
188+
.remove("dist-dir")
189+
.map(|v| (v, "frontend-dist"))
190+
})
191+
{
192+
build_config.insert(key.into(), dist_dir);
157193
}
158-
if let Some(dev_path) = build_config.remove("devPath") {
194+
if let Some((dev_path, key)) = build_config
195+
.remove("devPath")
196+
.map(|v| (v, "devUrl"))
197+
.or_else(|| build_config.remove("dev-path").map(|v| (v, "dev-url")))
198+
{
159199
let is_url = url::Url::parse(dev_path.as_str().unwrap_or_default()).is_ok();
160200
if is_url {
161-
build_config.insert("devUrl".into(), dev_path);
201+
build_config.insert(key.into(), dev_path);
162202
}
163203
}
164-
if let Some(with_global_tauri) = build_config.remove("withGlobalTauri") {
204+
if let Some((with_global_tauri, key)) = build_config
205+
.remove("withGlobalTauri")
206+
.map(|v| (v, "withGlobalTauri"))
207+
.or_else(|| {
208+
build_config
209+
.remove("with-global-tauri")
210+
.map(|v| (v, "with-global-tauri"))
211+
})
212+
{
165213
config
166214
.get_mut("tauri")
167215
.and_then(|t| t.as_object_mut())
168-
.map(|t| t.insert("withGlobalTauri".into(), with_global_tauri));
216+
.map(|t| t.insert(key.into(), with_global_tauri));
169217
}
170218
}
171219
}
172220

173-
fn process_bundle(config: &mut Map<String, Value>) {
221+
fn process_bundle(config: &mut Map<String, Value>, migrated: &MigratedConfig) {
174222
let mut license_file = None;
175223

176224
if let Some(mut bundle_config) = config
@@ -196,19 +244,22 @@ fn process_bundle(config: &mut Map<String, Value>) {
196244
}
197245

198246
// license file
199-
if let Some(macos) = bundle_config.get_mut("macOS") {
200-
if let Some(license) = macos.as_object_mut().unwrap().remove("license") {
247+
if let Some(macos) = bundle_config
248+
.get_mut("macOS")
249+
.and_then(|v| v.as_object_mut())
250+
{
251+
if let Some(license) = macos.remove("license") {
201252
license_file = Some(license);
202253
}
203254
}
204255
if let Some(windows) = bundle_config.get_mut("windows") {
205-
if let Some(wix) = windows.get_mut("wix") {
206-
if let Some(license_path) = wix.as_object_mut().unwrap().remove("license") {
256+
if let Some(wix) = windows.get_mut("wix").and_then(|v| v.as_object_mut()) {
257+
if let Some(license_path) = wix.remove("license") {
207258
license_file = Some(license_path);
208259
}
209260
}
210-
if let Some(nsis) = windows.get_mut("nsis") {
211-
if let Some(license_path) = nsis.as_object_mut().unwrap().remove("license") {
261+
if let Some(nsis) = windows.get_mut("nsis").and_then(|v| v.as_object_mut()) {
262+
if let Some(license_path) = nsis.remove("license") {
212263
license_file = Some(license_path);
213264
}
214265
}
@@ -219,7 +270,7 @@ fn process_bundle(config: &mut Map<String, Value>) {
219270

220271
// Migrate updater from targets to update field
221272
if let Some(targets) = bundle_config.get_mut("targets") {
222-
let shuold_migrate = if let Some(targets) = targets.as_array_mut() {
273+
let should_migrate = if let Some(targets) = targets.as_array_mut() {
223274
// targets: ["updater", ...]
224275
if let Some(index) = targets
225276
.iter()
@@ -232,17 +283,19 @@ fn process_bundle(config: &mut Map<String, Value>) {
232283
}
233284
} else if let Some(target) = targets.as_str() {
234285
// targets: "updater"
235-
// targets: "all"
236286
if target == "updater" {
237287
bundle_config.remove("targets");
238288
true
239289
} else {
240-
target == "all"
290+
// note that target == "all" is the default from the v1 tauri CLI
291+
// so we shouldn't bindly force updater bundles to be created
292+
// instead we only migrate if the updater has been migrated
293+
target == "all" && migrated.plugins.contains("updater")
241294
}
242295
} else {
243296
false
244297
};
245-
if shuold_migrate {
298+
if should_migrate {
246299
bundle_config.insert("createUpdaterArtifacts".to_owned(), "v1Compatible".into());
247300
}
248301
}
@@ -287,6 +340,18 @@ fn process_security(security: &mut Map<String, Value>) -> Result<()> {
287340

288341
security.insert("csp".into(), csp);
289342
}
343+
344+
// dangerous_remote_domain_ipc_access no longer exists
345+
if let Some(dangerous_remote_domain_ipc_access) = security
346+
.remove("dangerousRemoteDomainIpcAccess")
347+
.or_else(|| security.remove("dangerous-remote-domain-ipc-access"))
348+
{
349+
println!("dangerous remote domain IPC access config ({dangerous_remote_domain_ipc_access:?}) no longer exists, see documentation for capabilities and remote access: https://v2.tauri.app/security/capabilities/#remote-api-access")
350+
}
351+
security
352+
.remove("dangerousUseHttpScheme")
353+
.or_else(|| security.remove("dangerous-use-http-scheme"));
354+
290355
Ok(())
291356
}
292357

@@ -797,8 +862,47 @@ mod test {
797862
);
798863
}
799864

865+
#[test]
866+
fn can_migrate_default_config() {
867+
let original = serde_json::to_value(tauri_utils_v1::config::Config::default()).unwrap();
868+
migrate(&original);
869+
}
870+
871+
#[test]
872+
fn can_migrate_api_example_config() {
873+
let original =
874+
serde_json::from_str(include_str!("./fixtures/api-example.tauri.conf.json")).unwrap();
875+
migrate(&original);
876+
}
877+
878+
#[test]
879+
fn can_migrate_cli_template_config() {
880+
let original =
881+
serde_json::from_str(include_str!("./fixtures/cli-template.tauri.conf.json")).unwrap();
882+
migrate(&original);
883+
}
884+
800885
#[test]
801886
fn migrate_updater_target() {
887+
let original = serde_json::json!({});
888+
889+
let migrated = migrate(&original);
890+
assert_eq!(
891+
migrated["bundle"]["createUpdaterArtifacts"],
892+
serde_json::Value::Null
893+
);
894+
895+
let original = serde_json::json!({
896+
"tauri": {
897+
"updater": {
898+
"active": true
899+
}
900+
}
901+
});
902+
903+
let migrated = migrate(&original);
904+
assert_eq!(migrated["bundle"]["createUpdaterArtifacts"], "v1Compatible");
905+
802906
let original = serde_json::json!({
803907
"tauri": {
804908
"bundle": {
@@ -814,6 +918,14 @@ mod test {
814918
Some(&vec!["nsis".into()])
815919
);
816920

921+
let original =
922+
serde_json::from_str(include_str!("./fixtures/cli-template.tauri.conf.json")).unwrap();
923+
let migrated = migrate(&original);
924+
assert_eq!(
925+
migrated["bundle"]["createUpdaterArtifacts"],
926+
serde_json::Value::Null
927+
);
928+
817929
let original = serde_json::json!({
818930
"tauri": {
819931
"bundle": {
@@ -822,6 +934,24 @@ mod test {
822934
}
823935
});
824936

937+
let migrated = migrate(&original);
938+
assert_eq!(
939+
migrated["bundle"]["createUpdaterArtifacts"],
940+
serde_json::Value::Null
941+
);
942+
assert_eq!(migrated["bundle"]["targets"], "all");
943+
944+
let original = serde_json::json!({
945+
"tauri": {
946+
"bundle": {
947+
"targets": "all"
948+
},
949+
"updater": {
950+
"active": true
951+
}
952+
}
953+
});
954+
825955
let migrated = migrate(&original);
826956
assert_eq!(migrated["bundle"]["createUpdaterArtifacts"], "v1Compatible");
827957
assert_eq!(migrated["bundle"]["targets"], "all");

0 commit comments

Comments
 (0)