From 187432a6bb7b5bc4fc5857ea99aa256933749484 Mon Sep 17 00:00:00 2001 From: Nathan Hammond Date: Fri, 24 Feb 2023 16:48:56 +0800 Subject: [PATCH] Remove turbo.json checks. --- .../inference/nested-workspaces.t | 46 ++++++------------- crates/turborepo-lib/src/lib.rs | 1 - crates/turborepo-lib/src/shim.rs | 34 +------------- crates/turborepo-lib/src/turbo_json.rs | 33 ------------- 4 files changed, 16 insertions(+), 98 deletions(-) delete mode 100644 crates/turborepo-lib/src/turbo_json.rs diff --git a/cli/integration_tests/inference/nested-workspaces.t b/cli/integration_tests/inference/nested-workspaces.t index a85ca3a265e1e7..1495af8e909dc8 100644 --- a/cli/integration_tests/inference/nested-workspaces.t +++ b/cli/integration_tests/inference/nested-workspaces.t @@ -91,47 +91,29 @@ Setup $ cd $TARGET_DIR/outer/inner-no-turbo && ${TURBO} run build --filter=nothing -vv [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Global turbo version: .* (re) [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: No local turbo binary found at: .+node_modules/\.bin/turbo (re) - [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Repository Root: .*/nested-workspaces\.t/outer (re) + [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Repository Root: .*/nested-workspaces\.t/outer/inner-no-turbo (re) [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Running command as global turbo (re) - [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::cli: pkg_inference_root set to "inner-no-turbo" (re) + [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::cli: pkg_inference_root set to "" (re) [-0-9:.TWZ+]+ \[DEBUG] turbo: Found go binary at "[\-\w\/]+" (re) [-0-9:.TWZ+]+ \[INFO] turbo: skipping turbod since we appear to be in a non-interactive context (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: Using inner-no-turbo as a basis for selecting packages (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: global hash env vars: vars=\["VERCEL_ANALYTICS_ID"] (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: global hash: value=c1fb8f74a026cdb8 (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: local cache folder: path="" (re) - \xe2\x80\xa2 Packages in scope: (esc) - \xe2\x80\xa2 Running build in 0 packages (esc) - \xe2\x80\xa2 Remote caching disabled (esc) - - No tasks were executed as part of this run. - - Tasks: 0 successful, 0 total - Cached: 0 cached, 0 total - Time:\s*[\.0-9]+m?s (re) - + [-0-9:.TWZ+]+ \[ERROR] turbo: error: EXTRA_VALUE_AT_END="run failed: Could not find turbo.json. Follow directions at https://turbo.build/repo/docs to create one: file does not exist" (re) + ERROR run failed: Could not find turbo.json. Follow directions at https://turbo.build/repo/docs to create one: file does not exist + Turbo error: Could not find turbo.json. Follow directions at https://turbo.build/repo/docs to create one: file does not exist + [1] + $ cd $TARGET_DIR/outer/inner-no-turbo/apps && ${TURBO} run build --filter=nothing -vv [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Global turbo version: .* (re) [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: No local turbo binary found at: .+node_modules/\.bin/turbo (re) - [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Repository Root: .*/nested-workspaces\.t/outer (re) + [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Repository Root: .*/nested-workspaces\.t/outer/inner-no-turbo (re) [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Running command as global turbo (re) - [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::cli: pkg_inference_root set to "inner-no-turbo/apps" (re) + [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::cli: pkg_inference_root set to "apps" (re) [-0-9:.TWZ+]+ \[DEBUG] turbo: Found go binary at "[\-\w\/]+" (re) [-0-9:.TWZ+]+ \[INFO] turbo: skipping turbod since we appear to be in a non-interactive context (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: Using inner-no-turbo/apps as a basis for selecting packages (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: global hash env vars: vars=\["VERCEL_ANALYTICS_ID"] (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: global hash: value=c1fb8f74a026cdb8 (re) - [-0-9:.TWZ+]+ \[DEBUG] turbo: local cache folder: path="" (re) - \xe2\x80\xa2 Packages in scope: (esc) - \xe2\x80\xa2 Running build in 0 packages (esc) - \xe2\x80\xa2 Remote caching disabled (esc) - - No tasks were executed as part of this run. - - Tasks: 0 successful, 0 total - Cached: 0 cached, 0 total - Time:\s*[\.0-9]+m?s (re) - + [-0-9:.TWZ+]+ \[ERROR] turbo: error: EXTRA_VALUE_AT_END="run failed: Could not find turbo.json. Follow directions at https://turbo.build/repo/docs to create one: file does not exist" (re) + ERROR run failed: Could not find turbo.json. Follow directions at https://turbo.build/repo/docs to create one: file does not exist + Turbo error: Could not find turbo.json. Follow directions at https://turbo.build/repo/docs to create one: file does not exist + [1] + $ cd $TARGET_DIR/outer-no-turbo && ${TURBO} run build --filter=nothing -vv [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: Global turbo version: .* (re) [-0-9:.TWZ+]+ \[DEBUG] turborepo_lib::shim: No local turbo binary found at: .+node_modules/\.bin/turbo (re) diff --git a/crates/turborepo-lib/src/lib.rs b/crates/turborepo-lib/src/lib.rs index dfe3068a3beca0..ca9d8ba0b4250e 100644 --- a/crates/turborepo-lib/src/lib.rs +++ b/crates/turborepo-lib/src/lib.rs @@ -5,7 +5,6 @@ mod config; mod package_manager; mod retry; mod shim; -mod turbo_json; mod ui; use anyhow::Result; diff --git a/crates/turborepo-lib/src/shim.rs b/crates/turborepo-lib/src/shim.rs index c2d20db4532807..9f1c684c02f94f 100644 --- a/crates/turborepo-lib/src/shim.rs +++ b/crates/turborepo-lib/src/shim.rs @@ -19,7 +19,7 @@ use serde::{Deserialize, Serialize}; use tiny_gradient::{GradientStr, RGB}; use turbo_updater::check_for_updates; -use crate::{cli, get_version, turbo_json::TurboJson, PackageManager, Payload}; +use crate::{cli, get_version, PackageManager, Payload}; static TURBO_JSON: &str = "turbo.json"; // all arguments that result in a stdout that much be directly parsable and @@ -235,36 +235,7 @@ impl RepoState { /// /// returns: Result pub fn infer(current_dir: &Path) -> Result { - // First we look for a `turbo.json`. This iterator returns the first ancestor - // that contains a `turbo.json` file. - let root_path = current_dir - .ancestors() - .find(|p| TurboJson::open(p.join(TURBO_JSON)).map_or(false, |t| t.no_extends())); - - // If that directory exists, then we figure out if there are workspaces defined - // in it NOTE: This may change with multiple `turbo.json` files - if let Some(root_path) = root_path { - let pnpm = PackageManager::Pnpm; - let npm = PackageManager::Npm; - let is_workspace = pnpm.get_workspace_globs(root_path).is_ok() - || npm.get_workspace_globs(root_path).is_ok(); - - let mode = if is_workspace { - RepoMode::MultiPackage - } else { - RepoMode::SinglePackage - }; - - let local_turbo_state = LocalTurboState::infer(root_path); - - return Ok(Self { - root: root_path.to_path_buf(), - mode, - local_turbo_state, - }); - } - - // What we look for next is a directory that contains a `package.json`. + // What we look for first are all directories that contain a `package.json`. let potential_roots = current_dir .ancestors() .filter(|path| fs::metadata(path.join("package.json")).is_ok()); @@ -284,7 +255,6 @@ impl RepoState { if is_workspace { let local_turbo_state = LocalTurboState::infer(dir); - return Ok(Self { root: dir.to_path_buf(), mode: RepoMode::MultiPackage, diff --git a/crates/turborepo-lib/src/turbo_json.rs b/crates/turborepo-lib/src/turbo_json.rs deleted file mode 100644 index f803a11ae19fbe..00000000000000 --- a/crates/turborepo-lib/src/turbo_json.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::{fs::File, path::Path}; - -use anyhow::Result; -use serde::Deserialize; - -#[derive(Debug, Deserialize)] -pub struct TurboJson { - extends: Option>, -} - -impl TurboJson { - pub fn open(path: impl AsRef) -> Result { - Ok(serde_json::from_reader(File::open(path)?)?) - } - pub fn no_extends(&self) -> bool { - self.extends.is_none() - } -} - -#[test] -fn test_turbo_json() { - let turbo_json: TurboJson = serde_json::from_str("{}").unwrap(); - assert_eq!(turbo_json.extends, None); - - let turbo_json: TurboJson = serde_json::from_str(r#"{ "extends": ["//"] }"#).unwrap(); - assert_eq!(turbo_json.extends, Some(vec!["//".to_string()])); - - let turbo_json: TurboJson = serde_json::from_str(r#"{ "extends": ["//", "~"] }"#).unwrap(); - assert_eq!( - turbo_json.extends, - Some(vec!["//".to_string(), "~".to_string()]) - ); -}