Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/volta-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! The main implementation crate for the core of Volta.

use std::{env, ffi::OsString};

mod command;
pub mod error;
pub mod event;
Expand All @@ -22,3 +24,8 @@ pub mod toolchain;
pub mod version;

const VOLTA_FEATURE_PNPM: &str = "VOLTA_FEATURE_PNPM";
const VOLTA_FEATURE_YARN: &str = "VOLTA_FEATURE_YARN";

pub fn is_yarn_enabled() -> bool {
env::var_os(VOLTA_FEATURE_YARN) != Some(OsString::from("0"))
}
9 changes: 6 additions & 3 deletions crates/volta-core/src/platform/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;

use super::{build_path_error, Sourced};
use crate::error::{Context, Fallible};
use crate::is_yarn_enabled;
use crate::layout::volta_home;
use crate::tool::load_default_npm_version;
use node_semver::Version;
Expand Down Expand Up @@ -34,9 +35,11 @@ impl Image {
bins.push(home.pnpm_image_bin_dir(&pnpm_str));
}

if let Some(yarn) = &self.yarn {
let yarn_str = yarn.value.to_string();
bins.push(home.yarn_image_bin_dir(&yarn_str));
if is_yarn_enabled() {
if let Some(yarn) = &self.yarn {
let yarn_str = yarn.value.to_string();
bins.push(home.yarn_image_bin_dir(&yarn_str));
}
}

// Add Node path to the bins last, so that any custom version of npm will be earlier in the PATH
Expand Down
8 changes: 5 additions & 3 deletions crates/volta-core/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use crate::error::{ErrorKind, Fallible};
use crate::session::Session;
use crate::tool::{Node, Npm, Pnpm, Yarn};
use crate::VOLTA_FEATURE_PNPM;
use crate::{is_yarn_enabled, VOLTA_FEATURE_PNPM};
use node_semver::Version;

mod image;
Expand Down Expand Up @@ -290,8 +290,10 @@ impl Platform {
}
}

if let Some(Sourced { value: version, .. }) = &self.yarn {
Yarn::new(version.clone()).ensure_fetched(session)?;
if is_yarn_enabled() {
if let Some(Sourced { value: version, .. }) = &self.yarn {
Yarn::new(version.clone()).ensure_fetched(session)?;
}
}

Ok(Image {
Expand Down
15 changes: 13 additions & 2 deletions crates/volta-core/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::process::ExitStatus;
use crate::error::{ErrorKind, Fallible};
use crate::platform::{CliPlatform, Image, Sourced};
use crate::session::Session;
use crate::VOLTA_FEATURE_PNPM;
use crate::{is_yarn_enabled, VOLTA_FEATURE_PNPM};
use log::debug;
use node_semver::Version;

Expand Down Expand Up @@ -86,6 +86,7 @@ fn get_executor(
Some("node") => node::command(args, session),
Some("npm") => npm::command(args, session),
Some("npx") => npx::command(args, session),

Some("pnpm") => {
// If the pnpm feature flag variable is set, delegate to the pnpm handler
// If not, use the binary handler as a fallback (prior to pnpm support, installing
Expand All @@ -96,7 +97,17 @@ fn get_executor(
binary::command(exe, args, session)
}
}
Some("yarn") | Some("yarnpkg") => yarn::command(args, session),

Some("yarn") | Some("yarnpkg") => {
println!("is_yarn_enabled: {:?}", is_yarn_enabled());
if is_yarn_enabled() {
yarn::command(args, session)
} else {
println!("using binary");
binary::command(exe, args, session)
}
}

_ => binary::command(exe, args, session),
}
}
Expand Down
11 changes: 8 additions & 3 deletions crates/volta-core/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::session::Session;
use crate::style::{note_prefix, success_prefix, tool_version};
use crate::sync::VoltaLock;
use crate::version::VersionSpec;
use crate::VOLTA_FEATURE_PNPM;
use crate::{is_yarn_enabled, VOLTA_FEATURE_PNPM};
use cfg_if::cfg_if;
use log::{debug, info};

Expand Down Expand Up @@ -104,8 +104,13 @@ impl Spec {
}
}
Spec::Yarn(version) => {
let version = yarn::resolve(version, session)?;
Ok(Box::new(Yarn::new(version)))
if is_yarn_enabled() {
let version = yarn::resolve(version, session)?;
Ok(Box::new(Yarn::new(version)))
} else {
let package = Package::new("yarn".to_owned(), version)?;
Ok(Box::new(package))
}
}
// When using global package install, we allow the package manager to perform the version resolution
Spec::Package(name, version) => {
Expand Down