Skip to content

Commit edf85bc

Browse files
authored
fix(codegen): read platform-specific config file (#3966)
1 parent 58b3f48 commit edf85bc

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-codegen": patch
3+
---
4+
5+
Read platform-specific configuration files when generating code without the `TAURI_CONFIG` env var.

‎core/tauri-codegen/src/lib.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub enum CodegenConfigError {
2828
#[error("unable to parse inline JSON TAURI_CONFIG env var: {0}")]
2929
FormatInline(serde_json::Error),
3030

31+
#[error(transparent)]
32+
Json(#[from] serde_json::Error),
33+
3134
#[error("{0}")]
3235
ConfigError(#[from] ConfigError),
3336
}
@@ -44,21 +47,21 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
4447
Cow::Borrowed(path)
4548
};
4649

50+
// this should be impossible because of the use of `current_dir()` above, but handle it anyways
51+
let parent = path
52+
.parent()
53+
.map(ToOwned::to_owned)
54+
.ok_or_else(|| CodegenConfigError::Parent(path.into_owned()))?;
55+
4756
// in the future we may want to find a way to not need the TAURI_CONFIG env var so that
4857
// it is impossible for the content of two separate configs to get mixed up. The chances are
4958
// already unlikely unless the developer goes out of their way to run the cli on a different
5059
// project than the target crate.
5160
let config = if let Ok(env) = std::env::var("TAURI_CONFIG") {
5261
serde_json::from_str(&env).map_err(CodegenConfigError::FormatInline)?
5362
} else {
54-
tauri_utils::config::parse(path.to_path_buf())?
63+
serde_json::from_value(tauri_utils::config::parse::read_from(parent.clone())?)?
5564
};
5665

57-
// this should be impossible because of the use of `current_dir()` above, but handle it anyways
58-
let parent = path
59-
.parent()
60-
.map(ToOwned::to_owned)
61-
.ok_or_else(|| CodegenConfigError::Parent(path.into_owned()))?;
62-
6366
Ok((config, parent))
6467
}

0 commit comments

Comments
 (0)