Skip to content

Commit

Permalink
Factor out turborepo-ui crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaslyang authored and nicholaslyang committed Aug 7, 2023
1 parent cdfb31e commit ebc4cb4
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 21 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ turborepo-ffi = { path = "crates/turborepo-ffi" }
turborepo-fs = { path = "crates/turborepo-fs" }
turborepo-lib = { path = "crates/turborepo-lib", default-features = false }
turborepo-lockfiles = { path = "crates/turborepo-lockfiles" }
turborepo-ui = { path = "crates/turborepo-ui" }
turborepo-scm = { path = "crates/turborepo-scm" }
wax = { path = "crates/turborepo-wax" }
vercel-api-mock = { path = "crates/turborepo-vercel-api-mock" }
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ turborepo-cache = { workspace = true }
turborepo-env = { workspace = true }
turborepo-lockfiles = { workspace = true }
turborepo-scm = { workspace = true }
turborepo-ui = { workspace = true }
wax = { workspace = true }
webbrowser = { workspace = true }
which = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use clap_complete::{generate, Shell};
use serde::Serialize;
use tracing::{debug, error};
use turbopath::AbsoluteSystemPathBuf;
use turborepo_ui::UI;

#[cfg(feature = "run-stub")]
use crate::commands::run;
Expand All @@ -15,7 +16,6 @@ use crate::{
get_version,
shim::{RepoMode, RepoState},
tracing::TurboSubscriber,
ui::UI,
Payload,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use anyhow::Result;
use turborepo_ui::GREY;

use crate::{
commands::CommandBase,
package_graph::{PackageGraph, WorkspaceName, WorkspaceNode},
package_json::PackageJson,
package_manager::PackageManager,
ui::GREY,
};

pub fn run(base: &mut CommandBase, workspace: Option<&str>) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions crates/turborepo-lib/src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use dirs_next::home_dir;
#[cfg(test)]
use rand::Rng;
use turborepo_api_client::{APIClient, CachingStatus, Space, Team};

#[cfg(not(test))]
use crate::ui::CYAN;
use turborepo_ui::CYAN;
use turborepo_ui::{BOLD, GREY, UNDERLINE};

use crate::{
cli::LinkTarget,
commands::CommandBase,
config::{RawTurboJSON, SpacesJson},
ui::{BOLD, GREY, UNDERLINE},
};

#[derive(Clone)]
Expand Down Expand Up @@ -478,13 +478,13 @@ mod test {
use tempfile::{NamedTempFile, TempDir};
use tokio::sync::OnceCell;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_ui::UI;
use vercel_api_mock::start_test_server;

use crate::{
cli::LinkTarget,
commands::{link, CommandBase},
config::{ClientConfigLoader, RawTurboJSON, RepoConfigLoader, UserConfigLoader},
ui::UI,
Args,
};

Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use tokio::sync::OnceCell;
use tracing::debug;
#[cfg(not(test))]
use tracing::warn;
use turborepo_ui::{start_spinner, BOLD, CYAN, GREY, UNDERLINE};

use crate::{
commands::{
link::{verify_caching_enabled, REMOTE_CACHING_INFO, REMOTE_CACHING_URL},
CommandBase,
},
get_version,
ui::{start_spinner, BOLD, CYAN, GREY, UNDERLINE},
};

const DEFAULT_HOST_NAME: &str = "127.0.0.1";
Expand Down Expand Up @@ -305,6 +305,7 @@ mod test {
use tempfile::{tempdir, NamedTempFile};
use tokio::sync::OnceCell;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_ui::UI;
use vercel_api_mock::start_test_server;

use crate::{
Expand All @@ -314,7 +315,6 @@ mod test {
CommandBase,
},
config::{ClientConfigLoader, RepoConfigLoader, UserConfigLoader},
ui::UI,
Args,
};

Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/commands/logout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use anyhow::Result;
use tracing::error;
use turborepo_ui::GREY;

use crate::{commands::CommandBase, ui::GREY};
use crate::commands::CommandBase;

pub fn logout(base: &mut CommandBase) -> Result<()> {
if let Err(err) = base.user_config_mut()?.set_token(None) {
Expand Down
5 changes: 3 additions & 2 deletions crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use sha2::{Digest, Sha256};
use tokio::sync::OnceCell;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_api_client::APIClient;
use turborepo_ui::UI;

use crate::{
config::{
default_user_config_path, get_repo_config_path, ClientConfig, ClientConfigLoader,
RepoConfig, RepoConfigLoader, UserConfig, UserConfigLoader,
},
ui::UI,
Args,
};

Expand Down Expand Up @@ -176,8 +176,9 @@ impl CommandBase {
mod test {
use test_case::test_case;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_ui::UI;

use crate::{get_version, ui::UI};
use crate::get_version;

#[cfg(not(target_os = "windows"))]
#[test_case("/tmp/turborepo", "6e0cfa616f75a61c"; "basic example")]
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use tracing::trace;
use turbopath::{
AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf, RelativeUnixPath,
};
use turborepo_ui::BOLD;

use super::CommandBase;
use crate::{
config::RawTurboJSON,
package_graph::{PackageGraph, WorkspaceName, WorkspaceNode},
package_json::PackageJson,
ui::BOLD,
};

#[derive(Debug, thiserror::Error)]
Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/commands/unlink.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{fs, fs::File};

use anyhow::{Context, Result};
use turborepo_ui::GREY;

use crate::{cli::LinkTarget, commands::CommandBase, config::RawTurboJSON, ui::GREY};
use crate::{cli::LinkTarget, commands::CommandBase, config::RawTurboJSON};

enum UnlinkSpacesResult {
Unlinked,
Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/daemon/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ mod test {

use tokio::select;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_ui::UI;

use super::DaemonServer;
use crate::{commands::CommandBase, ui::UI, Args};
use crate::{commands::CommandBase, Args};

// the windows runner starts a new thread to accept uds requests,
// so we need a multi-threaded runtime
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod run;
mod shim;
mod task_graph;
mod tracing;
mod ui;

use ::tracing::error;
use anyhow::Result;
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/package_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, RelativeUnixPath};
use turborepo_lockfiles::Lockfile;
use turborepo_ui::{UI, UNDERLINE};
use wax::{Any, Glob, Pattern};

use crate::{
package_json::PackageJson,
package_manager::{npm::NpmDetector, pnpm::PnpmDetector, yarn::YarnDetector},
ui::{UI, UNDERLINE},
};

#[derive(Debug, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/run/global_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use anyhow::Result;
use turbopath::{AbsoluteSystemPath, RelativeUnixPathBuf};
use turborepo_env::{BySource, DetailedMap, EnvironmentVariableMap};
use turborepo_lockfiles::Lockfile;
use turborepo_ui::UI;

use crate::{cli::EnvMode, package_json::PackageJson, package_manager::PackageManager, ui::UI};
use crate::{cli::EnvMode, package_json::PackageJson, package_manager::PackageManager};

static DEFAULT_ENV_VARS: [&str; 1] = ["VERCEL_ANALYTICS_ID"];

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ mod test {
use anyhow::Result;
use tempfile::tempdir;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_ui::UI;

use crate::{
cli::{Command, RunArgs},
commands::CommandBase,
get_version,
run::Run,
ui::UI,
Args,
};

Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use tiny_gradient::{GradientStr, RGB};
use tracing::debug;
use turbo_updater::check_for_updates;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf};
use turborepo_ui::UI;

use crate::{
cli, get_version, package_manager::WorkspaceGlobs, spawn_child, tracing::TurboSubscriber,
ui::UI, PackageManager, Payload,
PackageManager, Payload,
};

// all arguments that result in a stdout that much be directly parsable and
Expand Down
3 changes: 1 addition & 2 deletions crates/turborepo-lib/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use tracing_subscriber::{
reload::{self, Error, Handle},
EnvFilter, Layer, Registry,
};

use crate::ui::UI;
use turborepo_ui::UI;

type StdOutLog = Filtered<
tracing_subscriber::fmt::Layer<Registry, DefaultFields, TurboFormatter>,
Expand Down
18 changes: 18 additions & 0 deletions crates/turborepo-ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "turborepo-ui"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dev-dependencies]
anyhow = { workspace = true }
tempfile = { workspace = true }

[dependencies]
atty = { workspace = true }
console = { workspace = true }
indicatif = { workspace = true }
lazy_static = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
turbopath = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
mod log_replayer;

use std::{borrow::Cow, env, f64::consts::PI, time::Duration};

use console::{Style, StyledObject};
use indicatif::{ProgressBar, ProgressStyle};
use lazy_static::lazy_static;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("cannot read logs: {0}")]
CannotReadLogs(std::io::Error),
#[error("cannot write logs: {0}")]
CannotWriteLogs(std::io::Error),
}

pub fn start_spinner(message: &str) -> ProgressBar {
let pb = ProgressBar::new_spinner();
Expand Down
Loading

0 comments on commit ebc4cb4

Please sign in to comment.