mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
fix(codegen): read platform-specific config file (#3966)
This commit is contained in:
committed by
GitHub
parent
58b3f48ecb
commit
edf85bc1d1
5
.changes/codegen-platform-config.md
Normal file
5
.changes/codegen-platform-config.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-codegen": patch
|
||||
---
|
||||
|
||||
Read platform-specific configuration files when generating code without the `TAURI_CONFIG` env var.
|
||||
@@ -28,6 +28,9 @@ pub enum CodegenConfigError {
|
||||
#[error("unable to parse inline JSON TAURI_CONFIG env var: {0}")]
|
||||
FormatInline(serde_json::Error),
|
||||
|
||||
#[error(transparent)]
|
||||
Json(#[from] serde_json::Error),
|
||||
|
||||
#[error("{0}")]
|
||||
ConfigError(#[from] ConfigError),
|
||||
}
|
||||
@@ -44,6 +47,12 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
|
||||
Cow::Borrowed(path)
|
||||
};
|
||||
|
||||
// this should be impossible because of the use of `current_dir()` above, but handle it anyways
|
||||
let parent = path
|
||||
.parent()
|
||||
.map(ToOwned::to_owned)
|
||||
.ok_or_else(|| CodegenConfigError::Parent(path.into_owned()))?;
|
||||
|
||||
// in the future we may want to find a way to not need the TAURI_CONFIG env var so that
|
||||
// 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
|
||||
@@ -51,14 +60,8 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
|
||||
let config = if let Ok(env) = std::env::var("TAURI_CONFIG") {
|
||||
serde_json::from_str(&env).map_err(CodegenConfigError::FormatInline)?
|
||||
} else {
|
||||
tauri_utils::config::parse(path.to_path_buf())?
|
||||
serde_json::from_value(tauri_utils::config::parse::read_from(parent.clone())?)?
|
||||
};
|
||||
|
||||
// this should be impossible because of the use of `current_dir()` above, but handle it anyways
|
||||
let parent = path
|
||||
.parent()
|
||||
.map(ToOwned::to_owned)
|
||||
.ok_or_else(|| CodegenConfigError::Parent(path.into_owned()))?;
|
||||
|
||||
Ok((config, parent))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user