fix(codegen): fix relative paths in version field of tauri.config.json, closes #4723 (#4725)

This commit is contained in:
shniubobo
2022-07-24 20:41:14 +08:00
committed by GitHub
parent 679abc6a9a
commit accbc5e880
2 changed files with 15 additions and 1 deletions

5
.changes/issue-4723.md Normal file
View File

@@ -0,0 +1,5 @@
---
"tauri-codegen": patch
---
Fix relative paths in `version` field of `tauri.config.json` not being correctly parsed by `generate_context!()`.

View File

@@ -64,5 +64,14 @@ pub fn get_config(path: &Path) -> Result<(Config, PathBuf), CodegenConfigError>
json_patch::merge(&mut config, &merge_config);
}
Ok((serde_json::from_value(config)?, parent))
let old_cwd = std::env::current_dir().map_err(CodegenConfigError::CurrentDir)?;
// Set working directory to where `tauri.config.json` is, so that relative paths in it are parsed correctly.
std::env::set_current_dir(parent.clone()).map_err(CodegenConfigError::CurrentDir)?;
let config = serde_json::from_value(config)?;
// Reset workding directory.
std::env::set_current_dir(old_cwd).map_err(CodegenConfigError::CurrentDir)?;
Ok((config, parent))
}