mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
refactor: do not pass entire config from CLI to core, send patch instead (#4598)
This commit is contained in:
committed by
GitHub
parent
2e61abaa9a
commit
fa028ebf3c
8
.changes/tauri-config-refactor.md
Normal file
8
.changes/tauri-config-refactor.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"cli.rs": patch
|
||||
"cli.js": patch
|
||||
"tauri-build": patch
|
||||
"tauri-codegen": patch
|
||||
---
|
||||
|
||||
The `TAURI_CONFIG` environment variable now represents the configuration to be merged instead of the entire JSON.
|
||||
@@ -24,6 +24,7 @@ tauri-utils = { version = "1.0.2", path = "../tauri-utils", features = [ "build"
|
||||
cargo_toml = "0.11"
|
||||
serde_json = "1"
|
||||
heck = "0.4"
|
||||
json-patch = "0.2"
|
||||
|
||||
[target."cfg(windows)".dependencies]
|
||||
winres = "0.1"
|
||||
|
||||
@@ -185,13 +185,14 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
|
||||
#[cfg(feature = "config-json5")]
|
||||
println!("cargo:rerun-if-changed=tauri.conf.json5");
|
||||
|
||||
let config: Config = if let Ok(env) = std::env::var("TAURI_CONFIG") {
|
||||
serde_json::from_str(&env)?
|
||||
} else {
|
||||
serde_json::from_value(tauri_utils::config::parse::read_from(
|
||||
std::env::current_dir().unwrap(),
|
||||
)?)?
|
||||
};
|
||||
let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
|
||||
std::env::current_dir().unwrap(),
|
||||
)?)?;
|
||||
if let Ok(env) = std::env::var("TAURI_CONFIG") {
|
||||
let merge_config: serde_json::Value = serde_json::from_str(&env)?;
|
||||
json_patch::merge(&mut config, &merge_config);
|
||||
}
|
||||
let config: Config = serde_json::from_value(config)?;
|
||||
|
||||
cfg_alias("dev", !has_feature("custom-protocol"));
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ uuid = { version = "1", features = [ "v4" ] }
|
||||
semver = "1"
|
||||
ico = "0.1"
|
||||
png = "0.17"
|
||||
json-patch = "0.2"
|
||||
|
||||
[target."cfg(target_os = \"macos\")".dependencies]
|
||||
plist = "1"
|
||||
|
||||
@@ -57,11 +57,12 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
|
||||
// it is impossible for the content of two separate configs to get mixed up. The chances are
|
||||
// already unlikely unless the developer goes out of their way to run the cli on a different
|
||||
// project than the target crate.
|
||||
let config = if let Ok(env) = std::env::var("TAURI_CONFIG") {
|
||||
serde_json::from_str(&env).map_err(CodegenConfigError::FormatInline)?
|
||||
} else {
|
||||
serde_json::from_value(tauri_utils::config::parse::read_from(parent.clone())?)?
|
||||
};
|
||||
let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(parent.clone())?)?;
|
||||
if let Ok(env) = std::env::var("TAURI_CONFIG") {
|
||||
let merge_config: serde_json::Value =
|
||||
serde_json::from_str(&env).map_err(CodegenConfigError::FormatInline)?;
|
||||
json_patch::merge(&mut config, &merge_config);
|
||||
}
|
||||
|
||||
Ok((config, parent))
|
||||
Ok((serde_json::from_value(config)?, parent))
|
||||
}
|
||||
|
||||
2
examples/api/src-tauri/Cargo.lock
generated
2
examples/api/src-tauri/Cargo.lock
generated
@@ -3199,6 +3199,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"cargo_toml",
|
||||
"heck 0.4.0",
|
||||
"json-patch",
|
||||
"semver 1.0.10",
|
||||
"serde_json",
|
||||
"tauri-codegen",
|
||||
@@ -3213,6 +3214,7 @@ dependencies = [
|
||||
"base64",
|
||||
"brotli",
|
||||
"ico",
|
||||
"json-patch",
|
||||
"plist",
|
||||
"png 0.17.5",
|
||||
"proc-macro2",
|
||||
|
||||
@@ -118,6 +118,7 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
|
||||
}
|
||||
|
||||
if let Some(merge_config) = merge_config {
|
||||
set_var("TAURI_CONFIG", merge_config);
|
||||
let merge_config: JsonValue =
|
||||
serde_json::from_str(merge_config).with_context(|| "failed to parse config to merge")?;
|
||||
merge(&mut config, &merge_config);
|
||||
@@ -145,7 +146,6 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
|
||||
}
|
||||
|
||||
let config: Config = serde_json::from_value(config)?;
|
||||
set_var("TAURI_CONFIG", serde_json::to_string(&config)?);
|
||||
|
||||
*config_handle().lock().unwrap() = Some(ConfigMetadata {
|
||||
inner: config,
|
||||
|
||||
Reference in New Issue
Block a user