Browse Source

fix: --install-if-missing when using version alias (#484)

remotes/origin/add-with-shims
Alex Munoz 4 years ago committed by GitHub
parent
commit
79ded8f6be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      src/commands/use.rs
  2. 18
      tests/feature_tests/mod.rs
  3. 11
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__Bash.snap
  4. 8
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__Fish.snap
  5. 9
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__PowerShell.snap
  6. 9
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__Zsh.snap
  7. 10
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__Bash.snap
  8. 7
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__Fish.snap
  9. 8
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__PowerShell.snap
  10. 8
      tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__Zsh.snap

42
src/commands/use.rs

@ -42,14 +42,13 @@ impl Command for Use {
system_version::path() system_version::path()
} else if let Some(alias_name) = requested_version.alias_name() { } else if let Some(alias_name) = requested_version.alias_name() {
let alias_path = config.aliases_dir().join(&alias_name); let alias_path = config.aliases_dir().join(&alias_name);
ensure!( if alias_path.exists() {
alias_path.exists(),
CantFindVersion {
version: requested_version
}
);
outln!(config#Info, "Using Node for alias {}", alias_name.cyan()); outln!(config#Info, "Using Node for alias {}", alias_name.cyan());
alias_path alias_path
} else {
install_new_version(requested_version, config, self.install_if_missing)?;
return Ok(());
}
} else { } else {
let current_version = requested_version.to_version(&all_versions, &config); let current_version = requested_version.to_version(&all_versions, &config);
match current_version { match current_version {
@ -61,8 +60,25 @@ impl Command for Use {
.join("installation") .join("installation")
} }
None => { None => {
install_new_version(requested_version, config, self.install_if_missing)?;
return Ok(());
}
}
};
replace_symlink(&version_path, &multishell_path).context(SymlinkingCreationIssue)?;
Ok(())
}
}
fn install_new_version(
requested_version: UserVersion,
config: &FnmConfig,
install_if_missing: bool,
) -> Result<(), Error> {
ensure!( ensure!(
self.install_if_missing || should_install_interactively(&requested_version), install_if_missing || should_install_interactively(&requested_version),
CantFindVersion { CantFindVersion {
version: requested_version version: requested_version
} }
@ -75,21 +91,13 @@ impl Command for Use {
.apply(config) .apply(config)
.context(InstallError)?; .context(InstallError)?;
Self { Use {
version: Some(UserVersionReader::Direct(requested_version)), version: Some(UserVersionReader::Direct(requested_version)),
install_if_missing: self.install_if_missing, install_if_missing: true,
} }
.apply(config)?; .apply(config)?;
return Ok(()); return Ok(());
}
}
};
replace_symlink(&version_path, &multishell_path).context(SymlinkingCreationIssue)?;
Ok(())
}
} }
/// Tries to delete `from`, and then tries to symlink `from` to `to` anyway. /// Tries to delete `from`, and then tries to symlink `from` to `to` anyway.

18
tests/feature_tests/mod.rs

@ -200,3 +200,21 @@ mod matching_dotfiles {
.then(test_node_version("v11.10.0")) .then(test_node_version("v11.10.0"))
}); });
} }
mod use_alias_install_if_missing {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(WriteFile::new(".node-version", "lts/*"))
.then(Call::new("fnm", vec!["use", "--install-if-missing"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "lts-latest"))
});
}
mod use_alias_not_installed {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.log_level(Some("error"))
.then(WriteFile::new(".node-version", "lts/*"))
.then(OutputContains::new(IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["use"]))), "Requested version lts-latest is not currently installed"))
});
}

11
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__Bash.snap

@ -0,0 +1,11 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
echo 'lts/*' > .node-version
fnm use --install-if-missing
fnm ls | grep lts-latest

8
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__Fish.snap

@ -0,0 +1,8 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
echo 'lts/*' > .node-version
fnm use --install-if-missing
fnm ls | grep lts-latest

9
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__PowerShell.snap

@ -0,0 +1,9 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
echo 'lts/*' > '.node-version'
fnm use --install-if-missing
$($__out__ = $(fnm ls | Select-String 'lts-latest'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })

9
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_install_if_missing__Zsh.snap

@ -0,0 +1,9 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
echo 'lts/*' > .node-version
fnm use --install-if-missing
fnm ls | grep lts-latest

10
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__Bash.snap

@ -0,0 +1,10 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm --log-level='error' env)"
echo 'lts/*' > .node-version
fnm use 2>&1 | grep 'Requested version lts-latest is not currently installed'

7
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__Fish.snap

@ -0,0 +1,7 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm --log-level='error' env | source
echo 'lts/*' > .node-version
fnm use 2>&1 | grep 'Requested version lts-latest is not currently installed'

8
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__PowerShell.snap

@ -0,0 +1,8 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm --log-level='error' env | Out-String | Invoke-Expression
echo 'lts/*' > '.node-version'
$($__out__ = $($($_tmp_err_action = $ErrorActionPreference;$ErrorActionPreference = "Continue";fnm use 2>&1;$ErrorActionPreference = $_tmp_err_action) | Select-String 'Requested version lts-latest is not currently installed'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })

8
tests/feature_tests/snapshots/e2e__feature_tests__use_alias_not_installed__Zsh.snap

@ -0,0 +1,8 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm --log-level='error' env)"
echo 'lts/*' > .node-version
fnm use 2>&1 | grep 'Requested version lts-latest is not currently installed'
Loading…
Cancel
Save