Skip to content

Commit

Permalink
fix(turborepo): Process single-package independently. (#6086)
Browse files Browse the repository at this point in the history
#6021 Removed the global `--single-package` flag, which was
_backwards_-compatible. But for forward-compatibility we need to make
sure that we don't try to parse it as an argument unless we're in `run`.

Closes TURBO-1401
  • Loading branch information
nathanhammond authored Oct 4, 2023
1 parent e595e9e commit a3913bf
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{anyhow, Result};
use camino::Utf8PathBuf;
use clap::{ArgAction, CommandFactory, Parser, Subcommand, ValueEnum};
use clap_complete::{generate, Shell};
use itertools::Itertools;

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, ubuntu-latest)

unused import: `itertools::Itertools`

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (macos, macos-latest)

unused import: `itertools::Itertools`

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (windows, windows-latest)

unused import: `itertools::Itertools`

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (ubuntu, ubuntu-latest)

unused import: `itertools::Itertools`

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (macos, macos-latest)

unused import: `itertools::Itertools`

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Turborepo E2E Tests (windows, windows-latest)

unused import: `itertools::Itertools`

Check warning on line 7 in crates/turborepo-lib/src/cli.rs

View workflow job for this annotation

GitHub Actions / Go Integration Tests (ubuntu, ubuntu-latest)

unused import: `itertools::Itertools`
use serde::{Deserialize, Serialize};
use tracing::{debug, error};
use turbopath::AbsoluteSystemPathBuf;
Expand Down Expand Up @@ -202,8 +203,42 @@ pub enum LinkTarget {

impl Args {
pub fn new() -> Result<Self> {
let mut clap_args = match Args::try_parse() {
Ok(args) => args,
// We always pass --single-package in from the shim.
// We need to omit it, and then add it in for run.
let arg_separator_position =
std::env::args_os().position(|input_token| input_token == "--");

let single_package_position =
std::env::args_os().position(|input_token| input_token == "--single-package");

let is_single_package = match (arg_separator_position, single_package_position) {
(_, None) => false,
(None, Some(_)) => true,
(Some(arg_separator_position), Some(single_package_position)) => {
single_package_position < arg_separator_position
}
};

// Clap supports arbitrary iterators as input.
// We can remove all instances of --single-package
let single_package_free = std::env::args_os()
.enumerate()
.filter(|(index, input_token)| {
arg_separator_position
.is_some_and(|arg_separator_position| index > &arg_separator_position)
|| input_token != "--single-package"
})
.map(|(_, input_token)| input_token);

let mut clap_args = match Args::try_parse_from(single_package_free) {
Ok(mut args) => {
// And then only add them back in when we're in `run`.
if let Some(ref mut run_args) = args.run_args {
run_args.single_package = is_single_package
}

args
}
// Don't use error logger when displaying help text
Err(e)
if matches!(
Expand Down

0 comments on commit a3913bf

Please sign in to comment.