Skip to content

Commit

Permalink
Move logic to set current directory before loading other config
Browse files Browse the repository at this point in the history
Fixes jdx#1843
  • Loading branch information
joshbode committed Mar 31, 2024
1 parent 1abc50d commit 3991cca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/cli/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,13 @@ mod tests {
fn test_env_json() {
assert_cli_snapshot!("env", "-J");
}

#[test]
fn test_env_cd() {
let cwd = env::current_dir().unwrap();
let path = dirs::HOME.join("fixtures");
let stdout = assert_cli!("env", "-C", path.into_os_string().into_string().unwrap());
assert!(stdout.contains("export NODE_ENV=production"));
env::set_current_dir(cwd).unwrap();
}
}
19 changes: 13 additions & 6 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,28 @@ impl Settings {
if let Some(settings) = SETTINGS.read().unwrap().as_ref() {
return Ok(settings.clone());
}

let mut sb = Self::builder()
.preloaded(CLI_SETTINGS.lock().unwrap().clone().unwrap_or_default())
.preloaded(DEFAULT_SETTINGS.clone())
.env();
for file in Self::all_settings_files() {
sb = sb.preloaded(file);
}
let mut settings = sb.preloaded(DEFAULT_SETTINGS.clone()).load()?;
if let Some(cd) = &settings.cd {

if let Some(mut cd) = sb.load()?.cd {
static ORIG_PATH: Lazy<std::io::Result<PathBuf>> = Lazy::new(env::current_dir);
let mut cd = PathBuf::from(cd);
if cd.is_relative() {
cd = ORIG_PATH.as_ref()?.join(cd);
}
env::set_current_dir(cd)?;
}

sb = Self::builder()
.preloaded(CLI_SETTINGS.lock().unwrap().clone().unwrap_or_default())
.env();
for file in Self::all_settings_files() {
sb = sb.preloaded(file);
}
let mut settings = sb.preloaded(DEFAULT_SETTINGS.clone()).load()?;

if settings.raw {
settings.jobs = 1;
}
Expand Down

0 comments on commit 3991cca

Please sign in to comment.