Skip to content

Commit

Permalink
fix(codegen): fix relative paths in version field of `tauri.config.…
Browse files Browse the repository at this point in the history
…json`, closes #4723 (#4725)
  • Loading branch information
shniubobo committed Jul 24, 2022
1 parent 679abc6 commit accbc5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/issue-4723.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-codegen": patch
---

Fix relative paths in `version` field of `tauri.config.json` not being correctly parsed by `generate_context!()`.
11 changes: 10 additions & 1 deletion core/tauri-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit accbc5e

Please sign in to comment.