Procházet zdrojové kódy

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

shniubobo před 3 roky
rodič
revize
accbc5e880
2 změnil soubory, kde provedl 15 přidání a 1 odebrání
  1. 5 0
      .changes/issue-4723.md
  2. 10 1
      core/tauri-codegen/src/lib.rs

+ 5 - 0
.changes/issue-4723.md

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

+ 10 - 1
core/tauri-codegen/src/lib.rs

@@ -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))
 }