mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
This commit is contained in:
committed by
GitHub
parent
c3acbd68ec
commit
df8bdcf063
5
.changes/support-dep-formats.md
Normal file
5
.changes/support-dep-formats.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"cli.rs": patch
|
||||
---
|
||||
|
||||
Adds support to `tauri` dependency as string and table on `Cargo.toml`.
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use super::{app_paths::tauri_dir, config::ConfigHandle};
|
||||
|
||||
use toml_edit::{Array, Document, Value};
|
||||
use toml_edit::{Array, Document, InlineTable, Item, Value};
|
||||
|
||||
use std::{
|
||||
fs::File,
|
||||
@@ -23,47 +23,63 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<()> {
|
||||
.as_table_mut()
|
||||
.expect("manifest dependencies isn't a table");
|
||||
|
||||
let entry = dependencies.entry("tauri");
|
||||
let tauri = entry.as_value_mut();
|
||||
let tauri_entry = dependencies.entry("tauri");
|
||||
|
||||
let config_guard = config.lock().unwrap();
|
||||
let config = config_guard.as_ref().unwrap();
|
||||
|
||||
if let Some(tauri) = tauri {
|
||||
let allowlist_features = config.tauri.features();
|
||||
let mut features = Array::default();
|
||||
for feature in allowlist_features {
|
||||
features.push(feature).unwrap();
|
||||
}
|
||||
if config.tauri.cli.is_some() {
|
||||
features.push("cli").unwrap();
|
||||
}
|
||||
if config.tauri.updater.active {
|
||||
features.push("updater").unwrap();
|
||||
}
|
||||
let allowlist_features = config.tauri.features();
|
||||
let mut features = Array::default();
|
||||
for feature in allowlist_features {
|
||||
features.push(feature).unwrap();
|
||||
}
|
||||
if config.tauri.cli.is_some() {
|
||||
features.push("cli").unwrap();
|
||||
}
|
||||
if config.tauri.updater.active {
|
||||
features.push("updater").unwrap();
|
||||
}
|
||||
|
||||
if let Some(tauri) = tauri_entry.as_table_mut() {
|
||||
let manifest_features = tauri.entry("features");
|
||||
*manifest_features = Item::Value(Value::Array(features));
|
||||
} else if let Some(tauri) = tauri_entry.as_value_mut() {
|
||||
match tauri {
|
||||
Value::InlineTable(tauri_def) => {
|
||||
let manifest_features =
|
||||
tauri_def.get_or_insert("features", Value::Array(Default::default()));
|
||||
Value::InlineTable(table) => {
|
||||
let manifest_features = table.get_or_insert("features", Value::Array(Default::default()));
|
||||
*manifest_features = Value::Array(features);
|
||||
}
|
||||
Value::String(version) => {
|
||||
let mut def = InlineTable::default();
|
||||
def.get_or_insert(
|
||||
"version",
|
||||
version.to_string().replace("\"", "").replace(" ", ""),
|
||||
);
|
||||
def.get_or_insert("features", Value::Array(features));
|
||||
*tauri = Value::InlineTable(def);
|
||||
}
|
||||
_ => {
|
||||
return Err(anyhow::anyhow!(
|
||||
"Unsupported tauri dependency format on Cargo.toml"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
let mut manifest_file = File::create(&manifest_path)?;
|
||||
manifest_file.write_all(
|
||||
manifest
|
||||
.to_string_in_original_order()
|
||||
.replace(r#"" ,features =["#, r#"", features = ["#)
|
||||
.as_bytes(),
|
||||
)?;
|
||||
manifest_file.flush()?;
|
||||
} else {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut manifest_file = File::create(&manifest_path)?;
|
||||
manifest_file.write_all(
|
||||
manifest
|
||||
.to_string_in_original_order()
|
||||
// apply some formatting fixes
|
||||
.replace(r#"" ,features =["#, r#"", features = ["#)
|
||||
.replace("]}", "] }")
|
||||
.replace("={", "= {")
|
||||
.replace("=[", "= [")
|
||||
.as_bytes(),
|
||||
)?;
|
||||
manifest_file.flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user