Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Updates] Remove 'volta activate' and 'volta deactivate' commands #559

Merged
merged 2 commits into from
Nov 12, 2019
Merged
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
2 changes: 2 additions & 0 deletions crates/volta-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![cfg_attr(feature = "cross-platform-docs", feature(doc_cfg))]

mod command;
#[cfg(not(feature = "volta-updates"))]
pub mod env;
pub mod error;
mod event;
Expand All @@ -19,6 +20,7 @@ pub mod platform;
pub mod project;
pub mod run;
pub mod session;
#[cfg(not(feature = "volta-updates"))]
pub mod shell;
pub mod shim;
pub mod signal;
Expand Down
7 changes: 5 additions & 2 deletions crates/volta-core/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl System {

/// Reproduces the Volta-enabled `PATH` environment variable for situations where
/// Volta has been deactivated
#[cfg(not(feature = "volta-updates"))]
pub fn enabled_path() -> Fallible<OsString> {
let old_path = envoy::path().unwrap_or_else(|| envoy::Var::from(""));
let mut new_path = old_path.split();
Expand Down Expand Up @@ -136,6 +137,7 @@ mod test {
use crate::layout::volta_install;
use semver::Version;
use std;
#[cfg(not(feature = "volta-updates"))]
use std::path::PathBuf;

// Since unit tests are run in parallel, tests that modify the PATH environment variable are subject to race conditions
Expand All @@ -144,6 +146,7 @@ mod test {
fn test_paths() {
test_image_path();
test_system_path();
#[cfg(not(feature = "volta-updates"))]
test_system_enabled_path();
}

Expand Down Expand Up @@ -322,7 +325,7 @@ mod test {
);
}

#[cfg(unix)]
#[cfg(all(unix, not(feature = "volta-updates")))]
fn test_system_enabled_path() {
let mut pathbufs: Vec<PathBuf> = Vec::new();
pathbufs.push(volta_home().unwrap().shim_dir().to_owned());
Expand All @@ -349,7 +352,7 @@ mod test {
);
}

#[cfg(windows)]
#[cfg(all(windows, not(feature = "volta-updates")))]
fn test_system_enabled_path() {
let mut pathbufs: Vec<PathBuf> = Vec::new();
pathbufs.push(volta_install().unwrap().bin_dir());
Expand Down
10 changes: 9 additions & 1 deletion crates/volta-core/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use std::path::Path;
use std::process::{Command, ExitStatus, Output};

use crate::command::create_command;
use crate::env::UNSAFE_GLOBAL;
use crate::error::ErrorDetails;
use crate::layout::ensure_volta_dirs_exist;
use crate::platform::System;
use crate::session::Session;
use crate::signal::pass_control_to_shim;
use cfg_if::cfg_if;
use volta_fail::{Fallible, ResultExt};

pub mod binary;
Expand All @@ -21,6 +21,14 @@ pub mod npm;
pub mod npx;
pub mod yarn;

cfg_if! {
if #[cfg(feature = "volta-updates")] {
const UNSAFE_GLOBAL: &str = "VOLTA_UNSAFE_GLOBAL";
} else {
use crate::env::UNSAFE_GLOBAL;
}
}

/// Distinguish global `add` commands in npm or yarn from all others.
enum CommandArg {
/// The command is a *global* add command.
Expand Down
4 changes: 4 additions & 0 deletions crates/volta-core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ pub enum ActivityKind {
Uninstall,
List,
Current,
#[cfg(not(feature = "volta-updates"))]
Deactivate,
#[cfg(not(feature = "volta-updates"))]
Activate,
Default,
Pin,
Expand All @@ -51,7 +53,9 @@ impl Display for ActivityKind {
ActivityKind::Uninstall => "uninstall",
ActivityKind::List => "list",
ActivityKind::Current => "current",
#[cfg(not(feature = "volta-updates"))]
ActivityKind::Deactivate => "deactivate",
#[cfg(not(feature = "volta-updates"))]
ActivityKind::Activate => "activate",
ActivityKind::Default => "default",
ActivityKind::Pin => "pin",
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub(crate) enum Subcommand {
Current(command::Current),

/// [DEPRECATED] Disables Volta in the current shell
#[cfg(not(feature = "volta-updates"))]
#[structopt(
name = "deactivate",
author = "",
Expand All @@ -106,6 +107,7 @@ pub(crate) enum Subcommand {
Deactivate(command::Deactivate),

/// [DEPRECATED] Re-enables Volta in the current shell
#[cfg(not(feature = "volta-updates"))]
#[structopt(
name = "activate",
author = "",
Expand Down Expand Up @@ -158,7 +160,9 @@ impl Subcommand {
Subcommand::Pin(pin) => pin.run(session),
Subcommand::List(list) => list.run(session),
Subcommand::Current(current) => current.run(session),
#[cfg(not(feature = "volta-updates"))]
Subcommand::Deactivate(deactivate) => deactivate.run(session),
#[cfg(not(feature = "volta-updates"))]
Subcommand::Activate(activate) => activate.run(session),
Subcommand::Completions(completions) => completions.run(session),
Subcommand::Which(which) => which.run(session),
Expand Down
4 changes: 4 additions & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(not(feature = "volta-updates"))]
pub(crate) mod activate;
pub(crate) mod completions;
pub(crate) mod current;
#[cfg(not(feature = "volta-updates"))]
pub(crate) mod deactivate;
pub(crate) mod fetch;
pub(crate) mod install;
Expand All @@ -12,9 +14,11 @@ pub(crate) mod r#use;
pub(crate) mod which;

pub(crate) use self::which::Which;
#[cfg(not(feature = "volta-updates"))]
pub(crate) use activate::Activate;
pub(crate) use completions::Completions;
pub(crate) use current::Current;
#[cfg(not(feature = "volta-updates"))]
pub(crate) use deactivate::Deactivate;
pub(crate) use fetch::Fetch;
pub(crate) use install::Install;
Expand Down
5 changes: 2 additions & 3 deletions tests/acceptance/intercept_global_installs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use hamcrest2::assert_that;
use hamcrest2::prelude::*;
use test_support::matchers::execs;

use volta_core::env::UNSAFE_GLOBAL;
use volta_fail::ExitCode;

const PACKAGE_JSON: &str = r#"{
Expand Down Expand Up @@ -72,7 +71,7 @@ fn npm_prevents_global_install() {
fn npm_allows_global_install_with_env_variable() {
let s = sandbox()
.package_json(PACKAGE_JSON)
.env(UNSAFE_GLOBAL, "1")
.env("VOLTA_UNSAFE_GLOBAL", "1")
.build();

// Since we are using a fake Node version, we expect to get an error about being unable to download
Expand Down Expand Up @@ -115,7 +114,7 @@ fn yarn_prevents_global_add() {
fn yarn_allows_global_add_with_env_variable() {
let s = sandbox()
.package_json(PACKAGE_JSON)
.env(UNSAFE_GLOBAL, "1")
.env("VOLTA_UNSAFE_GLOBAL", "1")
.build();

// Since we are using a fake Yarn/Node version, we expect to get an error about being unable to download
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod intercept_global_installs;
mod merged_platform;
mod verbose_errors;
mod volta_current;
#[cfg(not(feature = "volta-updates"))]
mod volta_deactivate;
mod volta_pin;
mod volta_uninstall;
4 changes: 2 additions & 2 deletions tests/acceptance/support/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl SandboxBuilder {
}

/// Set the shell for the sandbox (chainable)
#[cfg(unix)]
#[cfg(all(unix, not(feature = "volta-updates")))]
pub fn volta_shell(self, shell_name: &str) -> Self {
self.env("VOLTA_SHELL", shell_name)
}
Expand Down Expand Up @@ -600,7 +600,7 @@ impl Sandbox {
read_file_to_string(package_file)
}

#[cfg(unix)]
#[cfg(all(unix, not(feature = "volta-updates")))]
pub fn read_postscript(&self) -> String {
let postscript_file = volta_postscript();
read_file_to_string(postscript_file)
Expand Down