Skip to content

Commit

Permalink
Merge branch 'main' into nicholasyang/add-task-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang authored Sep 30, 2024
2 parents c22a4b2 + c793376 commit d1502eb
Show file tree
Hide file tree
Showing 40 changed files with 196 additions and 126 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Token {
/// * `valid_message_fn` - An optional callback that gets called if the
/// token is valid. It will be passed the user's email.
// TODO(voz): This should do a `get_user` or `get_teams` instead of the caller
// doing it. The reason we don't do it here is becuase the caller
// doing it. The reason we don't do it here is because the caller
// needs to do printing and requires the user struct, which we don't want to
// return here.
pub async fn is_valid<T: Client + TokenClient + CacheClient>(
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-filewatch/src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl FsEventWatcher {
// We need to associate the stream context with our callback in order to
// propagate events to the rest of the system. This will be owned by the
// stream, and will be freed when the stream is closed. This means we
// will leak the context if we panic before reacing
// will leak the context if we panic before reaching
// `FSEventStreamRelease`.
let stream_context_info = Box::into_raw(Box::new(StreamContextInfo {
event_handler: self.event_handler.clone(),
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-globwalk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ fn visit_file(
Err(e) => {
let io_err = std::io::Error::from(e);
match io_err.kind() {
// Ignore DNE and permission errors
// Ignore missing file and permission errors
std::io::ErrorKind::NotFound | std::io::ErrorKind::PermissionDenied => None,
_ => Some(Err(io_err.into())),
}
Expand Down Expand Up @@ -463,10 +463,10 @@ mod test {
#[test_case("/a/b/.", "/a/b", 2 ; "test path with leading / and ending with dot segment")]
#[test_case("/a/.././b", "/b", 0 ; "test path with leading / and mixed and consecutive dot and dotdot segments")]
#[test_case("/a/b/c/../../d/e/f/g/h/i/../j", "/a/d/e/f/g/h/j", 1 ; "leading collapse followed by shorter one")]
fn test_collapse_path(glob: &str, expected: &str, earliest_collapsed_segement: usize) {
fn test_collapse_path(glob: &str, expected: &str, earliest_collapsed_segment: usize) {
let (glob, segment) = collapse_path(glob).unwrap();
assert_eq!(glob, expected);
assert_eq!(segment, earliest_collapsed_segement);
assert_eq!(segment, earliest_collapsed_segment);
}

#[test_case("../a/b" ; "test path starting with ../ segment should return None")]
Expand Down
22 changes: 11 additions & 11 deletions crates/turborepo-globwatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl GlobWatcher {
Either::Left(mut e) => {
// if we receive an event for a file in the flush dir, we need to
// remove it from the events list, and send a signal to the flush
// requestor. flushes should not be considered as events.
// requester. flushes should not be considered as events.
for flush_id in e
.paths
.extract_if(|p| p.starts_with(flush_dir.as_path()))
Expand All @@ -228,7 +228,7 @@ impl GlobWatcher {
.expect("only fails if holder panics")
.remove(&flush_id)
{
// if this fails, it just means the requestor has gone away
// if this fails, it just means the requester has gone away
// and we can ignore it
tx.send(()).ok();
}
Expand Down Expand Up @@ -363,7 +363,7 @@ impl<T: Watcher> WatchConfig<T> {
// we watch the parent directory instead.
// More information at https://github.com/notify-rs/notify/issues/403
#[cfg(windows)]
let watched_path = path.parent().expect("turbo is unusable at filesytem root");
let watched_path = path.parent().expect("turbo is unusable at filesystem root");
#[cfg(not(windows))]
let watched_path = path;

Expand Down Expand Up @@ -424,7 +424,7 @@ enum GlobSymbol<'a> {
DoubleStar,
Question,
Negation,
PathSeperator,
PathSeparator,
}

/// Gets the minimum set of paths that can be watched for a given glob,
Expand Down Expand Up @@ -456,8 +456,8 @@ enum GlobSymbol<'a> {
/// note: it is currently extremely conservative, handling only `**`, braces,
/// and `?`. any other case watches the entire directory.
fn glob_to_paths(glob: &str) -> Vec<PathBuf> {
// get all the symbols and chunk them by path seperator
let chunks = glob_to_symbols(glob).group_by(|s| s != &GlobSymbol::PathSeperator);
// get all the symbols and chunk them by path separator
let chunks = glob_to_symbols(glob).group_by(|s| s != &GlobSymbol::PathSeparator);
let chunks = chunks
.into_iter()
.filter_map(|(not_sep, chunk)| (not_sep).then_some(chunk));
Expand Down Expand Up @@ -508,7 +508,7 @@ fn symbols_to_combinations<'a, T: Iterator<Item = GlobSymbol<'a>>>(
GlobSymbol::DoubleStar => return None,
GlobSymbol::Question => return None,
GlobSymbol::Negation => return None,
GlobSymbol::PathSeperator => return None,
GlobSymbol::PathSeparator => return None,
}
}

Expand Down Expand Up @@ -570,7 +570,7 @@ fn glob_to_symbols(glob: &str) -> impl Iterator<Item = GlobSymbol> {
}
b'?' => Some(GlobSymbol::Question),
b'!' => Some(GlobSymbol::Negation),
b'/' => Some(GlobSymbol::PathSeperator),
b'/' => Some(GlobSymbol::PathSeparator),
_ => Some(GlobSymbol::Char(&glob_bytes[start..end])),
}
} else {
Expand Down Expand Up @@ -611,9 +611,9 @@ mod test {
);
}

#[test_case("🇳🇴/🇳🇴", vec![Char("🇳🇴".as_bytes()), PathSeperator, Char("🇳🇴".as_bytes())])]
#[test_case("foo/**", vec![Char(b"f"), Char(b"o"), Char(b"o"), PathSeperator, DoubleStar])]
#[test_case("foo/{a,b}", vec![Char(b"f"), Char(b"o"), Char(b"o"), PathSeperator, OpenBrace, Char(b"a"), Char(b","), Char(b"b"), CloseBrace])]
#[test_case("🇳🇴/🇳🇴", vec![Char("🇳🇴".as_bytes()), PathSeparator, Char("🇳🇴".as_bytes())])]
#[test_case("foo/**", vec![Char(b"f"), Char(b"o"), Char(b"o"), PathSeparator, DoubleStar])]
#[test_case("foo/{a,b}", vec![Char(b"f"), Char(b"o"), Char(b"o"), PathSeparator, OpenBrace, Char(b"a"), Char(b","), Char(b"b"), CloseBrace])]
#[test_case("\\f", vec![Char(b"f")])]
#[test_case("\\\\f", vec![Char(b"\\"), Char(b"f")])]
#[test_case("\\🇳🇴", vec![Char("🇳🇴".as_bytes())])]
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn spawn_child(mut command: Command) -> Result<Arc<SharedChild>, io::Error>

ctrlc::set_handler(move || {
// on windows, we can't send signals so just kill
// we are quiting anyways so just ignore
// we are quitting anyways so just ignore
#[cfg(target_os = "windows")]
handler_shared_child.kill().ok();

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn run(
}
}
} else {
query::run_server(run, handler).await?;
query::run_query_server(run, handler).await?;
}

Ok(0)
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ mod test {
match strategy {
"stop" => manager.stop().await,
"wait" => manager.wait().await,
_ => panic!("unknown strat"),
_ => panic!("unknown strategy"),
}

// tasks return proper exit code
Expand Down
27 changes: 15 additions & 12 deletions crates/turborepo-lib/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
mod file;
mod package;
mod task;
mod server;

use std::{io, sync::Arc};

use async_graphql::{http::GraphiQLSource, *};
use async_graphql_axum::GraphQL;
use axum::{response, response::IntoResponse, routing::get, Router};
use axum::{response, response::IntoResponse};
use itertools::Itertools;
use miette::Diagnostic;
use package::Package;
pub use server::run_server;
use thiserror::Error;
use tokio::{net::TcpListener, select};
use tokio::select;
use turbo_trace::TraceError;
use turbopath::AbsoluteSystemPathBuf;
use turborepo_repository::package_graph::PackageName;

use crate::{
query::{file::File, task::Task},
get_version,
run::{builder::RunBuilder, Run},
signal::SignalHandler,
};
Expand All @@ -42,6 +44,8 @@ pub enum Error {
#[error(transparent)]
#[diagnostic(transparent)]
Path(#[from] turbopath::PathError),
#[error(transparent)]
UI(#[from] turborepo_ui::Error),
}

pub struct RepositoryQuery {
Expand Down Expand Up @@ -292,6 +296,7 @@ impl RepositoryQuery {
&self,
base: Option<String>,
head: Option<String>,
filter: Option<PackagePredicate>,
) -> Result<Array<Package>, Error> {
let mut opts = self.run.opts().clone();
opts.scope_opts.affected_range = Some((base, head));
Expand All @@ -308,6 +313,7 @@ impl RepositoryQuery {
run: self.run.clone(),
name: package,
})
.filter(|package| filter.as_ref().map_or(true, |f| f.check(package)))
.sorted_by(|a, b| a.name.cmp(&b.name))
.collect())
}
Expand All @@ -320,6 +326,10 @@ impl RepositoryQuery {
})
}

async fn version(&self) -> &'static str {
get_version()
}

async fn file(&self, path: String) -> Result<File, Error> {
let abs_path = AbsoluteSystemPathBuf::from_unknown(self.run.repo_root(), path);

Expand Down Expand Up @@ -363,14 +373,7 @@ pub async fn graphiql() -> impl IntoResponse {
response::Html(GraphiQLSource::build().endpoint("/").finish())
}

pub async fn run_server(run: Run, signal: SignalHandler) -> Result<(), Error> {
let schema = Schema::new(
RepositoryQuery::new(Arc::new(run)),
EmptyMutation,
EmptySubscription,
);
let app = Router::new().route("/", get(graphiql).post_service(GraphQL::new(schema)));

pub async fn run_query_server(run: Run, signal: SignalHandler) -> Result<(), Error> {
let subscriber = signal.subscribe().ok_or(Error::NoSignalHandler)?;
println!("GraphiQL IDE: http://localhost:8000");
webbrowser::open("http://localhost:8000")?;
Expand All @@ -380,7 +383,7 @@ pub async fn run_server(run: Run, signal: SignalHandler) -> Result<(), Error> {
println!("Shutting down GraphQL server");
return Ok(());
}
result = axum::serve(TcpListener::bind("127.0.0.1:8000").await?, app) => {
result = server::run_server(None, Arc::new(run)) => {
result?;
}
}
Expand Down
45 changes: 45 additions & 0 deletions crates/turborepo-lib/src/query/server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std::sync::Arc;

use async_graphql::{EmptyMutation, EmptySubscription, MergedObject, Schema};
use async_graphql_axum::GraphQL;
use axum::{http::Method, routing::get, Router};
use tokio::net::TcpListener;
use tower_http::cors::{Any, CorsLayer};
use turborepo_ui::wui::query::SharedState;

use crate::{query, query::graphiql, run::Run};

#[derive(MergedObject)]
struct Query(turborepo_ui::wui::RunQuery, query::RepositoryQuery);

pub async fn run_server(
state: Option<SharedState>,
run: Arc<Run>,
) -> Result<(), turborepo_ui::Error> {
let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST])
.allow_headers(Any)
// allow requests from any origin
.allow_origin(Any);

let web_ui_query = turborepo_ui::wui::RunQuery::new(state.clone());
let turbo_query = query::RepositoryQuery::new(run);
let combined_query = Query(web_ui_query, turbo_query);

let schema = Schema::new(combined_query, EmptyMutation, EmptySubscription);
let app = Router::new()
.route("/", get(graphiql).post_service(GraphQL::new(schema)))
.layer(cors);

axum::serve(
TcpListener::bind("127.0.0.1:8000")
.await
.map_err(turborepo_ui::wui::Error::Server)?,
app,
)
.await
.map_err(turborepo_ui::wui::Error::Server)?;

Ok(())
}
43 changes: 3 additions & 40 deletions crates/turborepo-lib/src/run/ui.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use std::sync::Arc;

use async_graphql::{EmptyMutation, EmptySubscription, MergedObject, Schema};
use async_graphql_axum::GraphQL;
use axum::{http::Method, routing::get, Router};
use tokio::net::TcpListener;
use tower_http::cors::{Any, CorsLayer};
use turborepo_ui::wui::{event::WebUIEvent, server::SharedState};
use turborepo_ui::wui::{event::WebUIEvent, query::SharedState};

use crate::{query, query::graphiql, run::Run};
use crate::{query, run::Run};

pub async fn start_web_ui_server(
rx: tokio::sync::mpsc::UnboundedReceiver<WebUIEvent>,
Expand All @@ -17,39 +12,7 @@ pub async fn start_web_ui_server(
let subscriber = turborepo_ui::wui::subscriber::Subscriber::new(rx);
tokio::spawn(subscriber.watch(state.clone()));

run_server(state.clone(), run).await?;

Ok(())
}

#[derive(MergedObject)]
struct Query(turborepo_ui::wui::RunQuery, query::RepositoryQuery);

async fn run_server(state: SharedState, run: Arc<Run>) -> Result<(), turborepo_ui::Error> {
let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST])
.allow_headers(Any)
// allow requests from any origin
.allow_origin(Any);

let web_ui_query = turborepo_ui::wui::RunQuery::new(state.clone());
let turbo_query = query::RepositoryQuery::new(run);
let combined_query = Query(web_ui_query, turbo_query);

let schema = Schema::new(combined_query, EmptyMutation, EmptySubscription);
let app = Router::new()
.route("/", get(graphiql).post_service(GraphQL::new(schema)))
.layer(cors);

axum::serve(
TcpListener::bind("127.0.0.1:8000")
.await
.map_err(turborepo_ui::wui::Error::Server)?,
app,
)
.await
.map_err(turborepo_ui::wui::Error::Server)?;
query::run_server(Some(state.clone()), run).await?;

Ok(())
}
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/shim/local_turbo_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl LocalTurboConfig {
}

// If there isn't a package manager, just try to parse all known lockfiles
// This isn't the most effecient, but since we'll be hitting network to download
// This isn't the most efficient, but since we'll be hitting network to download
// the correct binary the unnecessary file reads aren't costly relative to the
// download.
PackageManager::supported_managers().iter().find_map(|pm| {
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/shim/local_turbo_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn turbo_version_has_shim(version: &str) -> bool {
version.major > 1
} else {
// In the case that we don't get passed a valid semver we should avoid a panic.
// We shouldn't hit this we introduce back infering package version from schema
// We shouldn't hit this we introduce back inferring package version from schema
// or package.json.
true
}
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl TurboSubscriber {
/// - If the `TURBO_LOG_VERBOSITY` env var is set, it will be used to set
/// the verbosity level. Otherwise, the default is `WARN`. See the
/// documentation on the RUST_LOG env var for syntax.
/// - If the verbosity argument (usually detemined by a flag) is provided,
/// - If the verbosity argument (usually determined by a flag) is provided,
/// it overrides the default global log level. This means it overrides the
/// `TURBO_LOG_VERBOSITY` global setting, but not per-module settings.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lockfiles/src/berry/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod test {
.cloned()
.collect(),
};
let serailized = lockfile.to_string();
assert!(serailized.contains(&format!("? {long_key}\n")));
let serialized = lockfile.to_string();
assert!(serialized.contains(&format!("? {long_key}\n")));
}
}
2 changes: 1 addition & 1 deletion crates/turborepo-lockfiles/src/pnpm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub struct PackageSnapshot {
version: Option<String>,

// In lockfile v7, this portion of package is stored in the top level
// `shapshots` map as opposed to being stored inline.
// `snapshots` map as opposed to being stored inline.
#[serde(flatten)]
snapshot: PackageSnapshotV7,

Expand Down
Loading

0 comments on commit d1502eb

Please sign in to comment.