Skip to content

Commit accbc5e

Browse files
authored
fix(codegen): fix relative paths in version field of tauri.config.json, closes #4723 (#4725)
1 parent 679abc6 commit accbc5e

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎.changes/issue-4723.md‎

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+
Fix relative paths in `version` field of `tauri.config.json` not being correctly parsed by `generate_context!()`.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,14 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
6464
json_patch::merge(&mut config, &merge_config);
6565
}
6666

67-
Ok((serde_json::from_value(config)?, parent))
67+
let old_cwd = std::env::current_dir().map_err(CodegenConfigError::CurrentDir)?;
68+
// Set working directory to where `tauri.config.json` is, so that relative paths in it are parsed correctly.
69+
std::env::set_current_dir(parent.clone()).map_err(CodegenConfigError::CurrentDir)?;
70+
71+
let config = serde_json::from_value(config)?;
72+
73+
// Reset workding directory.
74+
std::env::set_current_dir(old_cwd).map_err(CodegenConfigError::CurrentDir)?;
75+
76+
Ok((config, parent))
6877
}

0 commit comments

Comments
 (0)