Skip to content

Commit a201041

Browse files
committed
apply review feedback
1 parent ca046de commit a201041

File tree

8 files changed

+42
-47
lines changed

8 files changed

+42
-47
lines changed

crates/volta-core/src/error/kind.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,6 @@ pub enum ErrorKind {
429429
name: String,
430430
},
431431

432-
/// Thrown when Volta is unable to find the shimmed command.
433-
ShimResolveError {
434-
name: String,
435-
},
436-
437432
/// Thrown when serializnig a bin config to JSON fails
438433
StringifyBinConfigError,
439434

@@ -1265,13 +1260,6 @@ at {}
12651260
{}"#,
12661261
name, PERMISSIONS_CTA
12671262
),
1268-
ErrorKind::ShimResolveError { name } => write!(
1269-
f,
1270-
r#"Could not find shim for "{}"
1271-
1272-
{}"#,
1273-
name, PERMISSIONS_CTA,
1274-
),
12751263
ErrorKind::StringifyBinConfigError => write!(
12761264
f,
12771265
"Could not serialize executable configuration.
@@ -1524,7 +1512,6 @@ impl ErrorKind {
15241512
ErrorKind::SetToolExecutable { .. } => ExitCode::FileSystemError,
15251513
ErrorKind::ShimCreateError { .. } => ExitCode::FileSystemError,
15261514
ErrorKind::ShimRemoveError { .. } => ExitCode::FileSystemError,
1527-
ErrorKind::ShimResolveError { .. } => ExitCode::FileSystemError,
15281515
ErrorKind::StringifyBinConfigError => ExitCode::UnknownError,
15291516
ErrorKind::StringifyPackageConfigError => ExitCode::UnknownError,
15301517
ErrorKind::StringifyPlatformError => ExitCode::UnknownError,

crates/volta-core/src/shim.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::error::{Context, ErrorKind, Fallible, VoltaError};
99
use crate::fs::{read_dir_eager, symlink_file};
1010
use crate::layout::{volta_home, volta_install};
1111
use crate::sync::VoltaLock;
12-
use log::{debug, warn};
12+
use log::debug;
1313

1414
pub fn regenerate_shims_for_dir(dir: &Path) -> Fallible<()> {
1515
// Acquire a lock on the Volta directory, if possible, to prevent concurrent changes
@@ -89,23 +89,6 @@ pub fn create(shim_name: &str) -> Fallible<ShimResult> {
8989
}
9090
}
9191

92-
pub fn check_reachable(shim_name: &str) -> Fallible<()> {
93-
let shim = volta_home()?.shim_file(shim_name);
94-
let resolved = which::which(shim_name).map_err(|e| {
95-
VoltaError::from_source(
96-
e,
97-
ErrorKind::ShimResolveError {
98-
name: shim_name.to_string(),
99-
},
100-
)
101-
})?;
102-
if resolved != shim {
103-
warn!("{} is shadowed by another binary of the same name at {}. Please ensure that {} is at the front of your PATH.", shim_name, resolved.display(), shim.display());
104-
}
105-
106-
Ok(())
107-
}
108-
10992
pub fn delete(shim_name: &str) -> Fallible<ShimResult> {
11093
let shim = volta_home()?.shim_file(shim_name);
11194

crates/volta-core/src/tool/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::{self, Display};
22

33
use crate::error::{ErrorKind, Fallible};
4+
use crate::layout::volta_home;
45
use crate::session::Session;
56
use crate::style::{note_prefix, success_prefix, tool_version};
67
use crate::sync::VoltaLock;
@@ -192,3 +193,26 @@ fn registry_fetch_error(
192193
let from_url = from_url.as_ref().to_string();
193194
|| ErrorKind::RegistryFetchError { tool, from_url }
194195
}
196+
197+
pub fn check_shim_reachable(shim_name: &str) {
198+
let home = match volta_home() {
199+
Ok(home) => home,
200+
Err(_) => return,
201+
};
202+
203+
let shim = home.shim_file(shim_name);
204+
let resolved = match which::which(shim_name) {
205+
Ok(resolved) => resolved,
206+
Err(_) => {
207+
info!(
208+
"Cannot find command {}. Please ensure that {} is at the front of your PATH.",
209+
shim_name,
210+
shim.display()
211+
);
212+
return;
213+
}
214+
};
215+
if resolved != shim {
216+
info!("{} is shadowed by another binary of the same name at {}. Please ensure that {} is at the front of your PATH.", shim_name, resolved.display(), shim.display());
217+
}
218+
}

crates/volta-core/src/tool/node/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::fmt::{self, Display};
22

33
use super::{
4-
check_fetched, debug_already_fetched, info_fetched, info_installed, info_pinned,
5-
info_project_version, FetchStatus, Tool,
4+
check_fetched, check_shim_reachable, debug_already_fetched, info_fetched, info_installed,
5+
info_pinned, info_project_version, FetchStatus, Tool,
66
};
77
use crate::error::{ErrorKind, Fallible};
88
use crate::inventory::node_available;
99
use crate::session::Session;
10-
use crate::shim;
1110
use crate::style::{note_prefix, tool_version};
1211
use crate::sync::VoltaLock;
1312
use cfg_if::cfg_if;
@@ -208,7 +207,7 @@ impl Tool for Node {
208207
info_installed(node_version); // includes node and npm version
209208
}
210209

211-
shim::check_reachable("node")?;
210+
check_shim_reachable("node");
212211

213212
if let Ok(Some(project)) = session.project_platform() {
214213
info_project_version(tool_version("node", &project.node));

crates/volta-core/src/tool/npm/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use std::fmt::{self, Display};
22

33
use super::node::load_default_npm_version;
44
use super::{
5-
check_fetched, debug_already_fetched, info_fetched, info_installed, info_pinned,
6-
info_project_version, FetchStatus, Tool,
5+
check_fetched, check_shim_reachable, debug_already_fetched, info_fetched, info_installed,
6+
info_pinned, info_project_version, FetchStatus, Tool,
77
};
88
use crate::error::{Context, ErrorKind, Fallible};
99
use crate::inventory::npm_available;
1010
use crate::session::Session;
11-
use crate::shim;
1211
use crate::style::{success_prefix, tool_version};
1312
use crate::sync::VoltaLock;
1413
use log::info;
@@ -65,7 +64,7 @@ impl Tool for Npm {
6564
.set_active_npm(Some(self.version.clone()))?;
6665

6766
info_installed(self);
68-
shim::check_reachable("npm")?;
67+
check_shim_reachable("npm");
6968

7069
if let Ok(Some(project)) = session.project_platform() {
7170
if let Some(npm) = &project.npm {

crates/volta-core/src/tool/package/configure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::error::{ErrorKind, Fallible};
66
use crate::layout::volta_home;
77
use crate::platform::{Image, PlatformSpec};
88
use crate::shim;
9+
use crate::tool::check_shim_reachable;
910

1011
/// Read the manifest for the package being installed
1112
pub(super) fn parse_manifest(
@@ -37,7 +38,7 @@ pub(super) fn write_config_and_shims(
3738
// Generate the shims and bin configs for each bin provided by the package
3839
for bin_name in &manifest.bin {
3940
shim::create(bin_name)?;
40-
shim::check_reachable(bin_name)?;
41+
check_shim_reachable(bin_name);
4142

4243
BinConfig {
4344
name: bin_name.clone(),

crates/volta-core/src/tool/yarn/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::fmt::{self, Display};
22

33
use super::{
4-
check_fetched, debug_already_fetched, info_fetched, info_installed, info_pinned,
5-
info_project_version, FetchStatus, Tool,
4+
check_fetched, check_shim_reachable, debug_already_fetched, info_fetched, info_installed,
5+
info_pinned, info_project_version, FetchStatus, Tool,
66
};
77
use crate::error::{ErrorKind, Fallible};
88
use crate::inventory::yarn_available;
99
use crate::session::Session;
10-
use crate::shim;
1110
use crate::style::tool_version;
1211
use crate::sync::VoltaLock;
1312
use semver::Version;
@@ -64,7 +63,7 @@ impl Tool for Yarn {
6463
.set_active_yarn(Some(self.version.clone()))?;
6564

6665
info_installed(self);
67-
shim::check_reachable("yarn")?;
66+
check_shim_reachable("yarn");
6867

6968
if let Ok(Some(project)) = session.project_platform() {
7069
if let Some(yarn) = &project.yarn {

tests/acceptance/support/sandbox.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,12 @@ impl SandboxBuilder {
460460
self.add_exec_dir_to_path()
461461
}
462462

463-
/// Add an arbitrary file to the test project within the sandbox,
464-
/// give it executable permissions,
465-
/// and add its directory to the *front* of PATH, shadowing any volta binaries.
463+
/// Prepend executable directory to the beginning of the PATH (chainable)
464+
///
465+
/// This is useful to test binaries shadowing volta shims.
466+
///
467+
/// Cannot be used in combination with `add_exec_dir_to_path`, and will panic if called twice.
468+
/// No particular reason except it's likely a programming error.
466469
pub fn prepend_exec_dir_to_path(mut self) -> Self {
467470
if self.has_exec_path {
468471
panic!("need to call prepend_exec_dir_to_path before anything else");

0 commit comments

Comments
 (0)