Skip to content

Commit 7dfaafa

Browse files
committed
address PR feedback, maintain hot path perf
1 parent 5b9ac58 commit 7dfaafa

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,10 @@ impl Project {
171171
})
172172
}
173173

174-
/// Does this project use Plug-n-Play?
175-
// (Do either of the files '.pnp.js' or '.pnp.cjs' exist?)
176-
pub fn is_plug_n_play(&self) -> bool {
174+
/// Does this project use Yarn Plug'n'Play?
175+
// (project uses Yarn, and either of the files '.pnp.js' or '.pnp.cjs' exist)
176+
pub fn is_yarn_pnp(&self) -> bool {
177+
self.platform().map_or(false, |platform| platform.yarn.is_some()) &&
177178
self.manifest_file.parent().map_or(false, |base_dir| {
178179
base_dir.join(".pnp.js").exists() || base_dir.join(".pnp.cjs").exists()
179180
})

crates/volta-core/src/project/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,20 @@ mod plug_n_play {
225225
fn project_is_not_pnp() {
226226
let project_path = fixture_path(&["basic"]);
227227
let test_project = Project::for_dir(project_path).unwrap().unwrap();
228-
assert_eq!(test_project.is_plug_n_play(), false);
228+
assert_eq!(test_project.is_yarn_pnp(), false);
229229
}
230230

231231
#[test]
232232
fn project_has_pnp_js() {
233233
let project_path = fixture_path(&["plug-n-play", "pnp-js"]);
234234
let test_project = Project::for_dir(project_path).unwrap().unwrap();
235-
assert_eq!(test_project.is_plug_n_play(), true);
235+
assert_eq!(test_project.is_yarn_pnp(), true);
236236
}
237237

238238
#[test]
239239
fn project_has_pnp_cjs() {
240240
let project_path = fixture_path(&["plug-n-play", "pnp-cjs"]);
241241
let test_project = Project::for_dir(project_path).unwrap().unwrap();
242-
assert_eq!(test_project.is_plug_n_play(), true);
242+
assert_eq!(test_project.is_yarn_pnp(), true);
243243
}
244244
}

crates/volta-core/src/run/binary.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@ pub(super) fn command(exe: &OsStr, args: &[OsString], session: &mut Session) ->
2020
if let Some(project) = session.project()? {
2121
// Check if the executable is a direct dependency
2222
if project.has_direct_bin(exe)? {
23-
if project
24-
.platform()
25-
.map_or(false, |platform| platform.yarn.is_some())
26-
&& project.is_plug_n_play()
27-
{
28-
debug!("Project uses Yarn PnP, calling {} with 'yarn'", bin);
29-
let platform = Platform::current(session)?;
30-
let mut exe_and_args = vec![exe.to_os_string()];
31-
exe_and_args.extend_from_slice(args);
32-
return Ok(ToolCommand::new("yarn", exe_and_args, platform, ToolKind::Yarn).into());
23+
match project.find_bin(exe) {
24+
Some(path_to_bin) => {
25+
debug!("Found {} in project at '{}'", bin, path_to_bin.display());
26+
27+
let platform = Platform::current(session)?;
28+
return Ok(ToolCommand::new(
29+
path_to_bin,
30+
args,
31+
platform,
32+
ToolKind::ProjectLocalBinary(bin),
33+
)
34+
.into());
35+
},
36+
None => {
37+
if project.is_yarn_pnp()
38+
{
39+
debug!("Project uses Yarn PnP, calling {} with 'yarn'", bin);
40+
let platform = Platform::current(session)?;
41+
let mut exe_and_args = vec![exe.to_os_string()];
42+
exe_and_args.extend_from_slice(args);
43+
return Ok(ToolCommand::new("yarn", exe_and_args, platform, ToolKind::Yarn).into());
44+
} else {
45+
return Err(ErrorKind::ProjectLocalBinaryNotFound {
46+
command: exe.to_string_lossy().to_string(),
47+
}.into());
48+
}
49+
}
3350
}
34-
let path_to_bin =
35-
project
36-
.find_bin(exe)
37-
.ok_or_else(|| ErrorKind::ProjectLocalBinaryNotFound {
38-
command: exe.to_string_lossy().to_string(),
39-
})?;
40-
41-
debug!("Found {} in project at '{}'", bin, path_to_bin.display());
42-
43-
let platform = Platform::current(session)?;
44-
return Ok(ToolCommand::new(
45-
path_to_bin,
46-
args,
47-
platform,
48-
ToolKind::ProjectLocalBinary(bin),
49-
)
50-
.into());
5151
}
5252
}
5353

tests/acceptance/execute_binary.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ fn project_local_binary_pnp() {
296296
.setup_npm_binary("6.7.0", &npm_bin("6.7.0"))
297297
.setup_yarn_binary("1.23.483", &yarn_bin("1.23.483"))
298298
.setup_yarn_binary("3.12.1092", &yarn_bin("3.12.1092"))
299-
.project_bins(cowsay_bin_info("1.5.0"))
300299
.project_pnp()
301300
.add_dir_to_path(PathBuf::from("/bin"))
302301
.build();

0 commit comments

Comments
 (0)