Browse Source

fix(cli): always read custom config file from CWD, closes #4067 (#4074)

Lucas Fernandes Nogueira 3 years ago
parent
commit
a1929c6dac
3 changed files with 11 additions and 3 deletions
  1. 6 0
      .changes/dev-cmd-config-arg.md
  2. 1 1
      tooling/cli/src/build.rs
  3. 4 2
      tooling/cli/src/dev.rs

+ 6 - 0
.changes/dev-cmd-config-arg.md

@@ -0,0 +1,6 @@
+---
+"cli.rs": patch
+"cli.js": patch
+---
+
+**Breaking change:** The `dev` command now reads the custom config file from CWD instead of the Tauri folder.

+ 1 - 1
tooling/cli/src/build.rs

@@ -50,7 +50,7 @@ pub fn command(options: Options) -> Result<()> {
     Some(if config.starts_with('{') {
       config.to_string()
     } else {
-      std::fs::read_to_string(&config)?
+      std::fs::read_to_string(&config).with_context(|| "failed to read custom configuration")?
     })
   } else {
     None

+ 4 - 2
tooling/cli/src/dev.rs

@@ -79,16 +79,18 @@ pub fn command(options: Options) -> Result<()> {
 
 fn command_internal(options: Options) -> Result<()> {
   let tauri_path = tauri_dir();
-  set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
   let merge_config = if let Some(config) = &options.config {
     Some(if config.starts_with('{') {
       config.to_string()
     } else {
-      std::fs::read_to_string(&config)?
+      std::fs::read_to_string(&config).with_context(|| "failed to read custom configuration")?
     })
   } else {
     None
   };
+
+  set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
+
   let config = get_config(merge_config.as_deref())?;
 
   if let Some(before_dev) = &config