Skip to content

Commit

Permalink
Got the web ui working e2e! Implements the sending and creates a basi…
Browse files Browse the repository at this point in the history
…c web ui app
  • Loading branch information
NicholasLYang committed Jul 31, 2024
1 parent 7c152be commit bd20f77
Show file tree
Hide file tree
Showing 25 changed files with 15,990 additions and 7,960 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/turbopack-cli/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-ecmascript-runtime": "*"
"@vercel/turbopack-ecmascript-runtime": "workspace:*"
},
"devDependencies": {
"@types/node": "^18.11.11"
Expand Down
13 changes: 7 additions & 6 deletions crates/turborepo-lib/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::future::Future;

use tracing::error;

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on ubuntu

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, self-hosted, linux, x64, metal)

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

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

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on macos

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

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

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-12)

unused import: `tracing::error`

Check warning on line 3 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused import: `tracing::error`
use turborepo_telemetry::events::command::CommandEventBuilder;
use turborepo_ui::sender::UISender;

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on ubuntu

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, self-hosted, linux, x64, metal)

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

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

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on macos

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

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

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-12)

unused import: `turborepo_ui::sender::UISender`

Check warning on line 5 in crates/turborepo-lib/src/commands/run.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused import: `turborepo_ui::sender::UISender`

use crate::{commands::CommandBase, run, run::builder::RunBuilder, signal::SignalHandler};

Expand Down Expand Up @@ -52,12 +53,12 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3
analytics_handle.close_with_timeout().await;
}

if let (Some(handle), Some(sender)) = (handle, sender) {
//sender.stop();
if let Err(e) = handle.await.expect("render thread panicked") {
error!("error encountered rendering tui: {e}");
}
}
// if let (Some(handle), Some(sender)) = (handle, sender) {
// //sender.stop();
// if let Err(e) = handle.await.expect("render thread panicked") {
// error!("error encountered rendering tui: {e}");
// }
// }

result
};
Expand Down
4 changes: 3 additions & 1 deletion crates/turborepo-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ workspace = true

[dependencies]
atty = { workspace = true }
base64 = "0.22"
axum = { workspace = true, features = ["ws"] }
axum-server = { workspace = true }
base64 = "0.22"
chrono = { workspace = true }
console = { workspace = true }
crossterm = "0.27.0"
Expand All @@ -31,6 +31,8 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }

tower-http = { version = "0.5.2", features = ["cors"] }
tracing = { workspace = true }
tui-term = { workspace = true }
turbopath = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-ui/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub trait UISender: Clone + Send + Sync + 'static {
fn set_stdin(&self, task: String, stdin: Box<dyn std::io::Write + Send>);

fn output(&self, task: String, output: Vec<u8>) -> Result<(), Self::Error>;

/// Construct a sender configured for a specific task
fn task(&self, task: String) -> TaskSender<Self>
where
Self: Sized;
Expand Down
73 changes: 41 additions & 32 deletions crates/turborepo-ui/src/wui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ use axum::{
ws::{Message, WebSocket},
State, WebSocketUpgrade,
},
http::Method,
response::IntoResponse,
routing::get,
Router,
};
use serde::Serialize;
use thiserror::Error;
use tower_http::cors::{Any, CorsLayer};
use tracing::log::warn;

use crate::{
sender::{TaskSender, UISender},
Expand All @@ -37,38 +40,58 @@ impl UISender for WebUISender {
type Error = std::io::Error;

fn start_task(&self, task: String, output_logs: OutputLogs) {
todo!()
self.tx
.send(WebUIEvent::StartTask { task, output_logs })
.ok();
}

fn end_task(&self, task: String, result: TaskResult) {
todo!()
self.tx.send(WebUIEvent::EndTask { task, result }).ok();
}

fn status(&self, task: String, status: String, result: CacheResult) {
todo!()
self.tx
.send(WebUIEvent::Status {
task,
status,
result,
})
.ok();
}

fn set_stdin(&self, task: String, stdin: Box<dyn Write + Send>) {

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust check

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on ubuntu

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on ubuntu

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, self-hosted, linux, x64, metal)

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Build Turborepo (ubuntu, self-hosted, linux, x64, metal)

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

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

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

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

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on macos

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on macos

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

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

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

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

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (ubuntu-latest)

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-12)

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (macos-12)

unused variable: `stdin`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused variable: `task`

Check warning on line 62 in crates/turborepo-ui/src/wui/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo Integration (windows-latest)

unused variable: `stdin`
todo!()
warn!("stdin is not supported (yet) in web ui");
}

fn task(&self, task: String) -> TaskSender<Self>
where
Self: Sized,
{
todo!()
TaskSender {
name: task,
handle: self.clone(),
logs: Default::default(),
}
}

fn stop(&self) {
todo!()
self.tx.send(WebUIEvent::Stop).ok();
}

fn update_tasks(&self, tasks: Vec<String>) -> Result<(), Self::Error> {
todo!()
self.tx
.send(WebUIEvent::UpdateTasks { tasks })
.map_err(|_| std::io::Error::new(std::io::ErrorKind::BrokenPipe, "WebUI is closed"))?;

Ok(())
}

fn output(&self, task: String, output: Vec<u8>) -> Result<(), Self::Error> {
todo!()
self.tx
.send(WebUIEvent::TaskOutput { task, output })
.map_err(|_| std::io::Error::new(std::io::ErrorKind::BrokenPipe, "WebUI is closed"))?;

Ok(())
}
}

Expand Down Expand Up @@ -96,29 +119,7 @@ pub enum WebUIEvent {
UpdateTasks {
tasks: Vec<String>,
},
}

impl WebUIEvent {
fn from_event(event: Event) -> Option<Self> {
match event {
Event::StartTask { task, output_logs } => {
Some(WebUIEvent::StartTask { task, output_logs })
}
Event::TaskOutput { task, output } => Some(WebUIEvent::TaskOutput { task, output }),
Event::EndTask { task, result } => Some(WebUIEvent::EndTask { task, result }),
Event::Status {
task,
status,
result,
} => Some(WebUIEvent::Status {
task,
status,
result,
}),
Event::UpdateTasks { tasks } => Some(WebUIEvent::UpdateTasks { tasks }),
_ => None,
}
}
Stop,
}

struct AppState {
Expand Down Expand Up @@ -151,11 +152,19 @@ async fn handle_socket(mut socket: WebSocket, state: AppState) {
pub async fn start_ws_server(
rx: tokio::sync::broadcast::Receiver<WebUIEvent>,
) -> Result<(), Error> {
let cors = CorsLayer::new()
// allow `GET` and `POST` when accessing the resource
.allow_methods([Method::GET, Method::POST])
// allow requests from any origin
.allow_origin(Any);

let app = Router::new()
.route("/ws", get(handler))
.layer(cors)
.with_state(AppState { rx });

let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
let listener = tokio::net::TcpListener::bind("127.0.0.1:1337").await?;
println!("Web UI listening on port 1337");
axum::serve(listener, app).await?;

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions packages/turbo-repository/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* auto-generated by NAPI-RS */

export class Package {
export declare class Package {
name: string;
/** The absolute path to the package root. */
readonly absolutePath: string;
Expand All @@ -14,17 +14,17 @@ export class Package {
* Wrapper for dependents and dependencies.
* Each are a list of package paths, relative to the workspace root.
*/
export class PackageDetails {
export declare class PackageDetails {
/** the package's dependencies */
readonly dependencies: Array<string>;
/** the packages that depend on this package */
readonly dependents: Array<string>;
}
export class PackageManager {
export declare class PackageManager {
/** The package manager name in lower case. */
readonly name: string;
}
export class Workspace {
export declare class Workspace {
/** The absolute path to the workspace root. */
readonly absolutePath: string;
/** `true` when the workspace is a multi-package workspace. */
Expand Down
Loading

0 comments on commit bd20f77

Please sign in to comment.