Skip to content

Commit

Permalink
terminal improvements (vercel/turbo#133)
Browse files Browse the repository at this point in the history
* Adds next-like event type styling
* No tasks in logs

Closes:
- vercel/web-tooling-internal#58

Screenshot: 
![CleanShot 2022-10-20 at 17 59
45@2x](https://user-images.githubusercontent.com/8146736/196999636-dcf3757d-6c5f-4c52-9257-86caabf6a5d6.png)

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
  • Loading branch information
4 people committed Oct 21, 2022
1 parent a442eab commit b1caa9e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/next-swc/crates/next-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ console-subscriber = { version = "0.1.6", optional = true }
futures = "0.3.21"
mime = "0.3.16"
next-core = { path = "../next-core" }
owo-colors = "3"
portpicker = "0.1.1"
serde = "1.0.136"
serde_json = "1.0.85"
Expand Down
13 changes: 11 additions & 2 deletions packages/next-swc/crates/next-dev/benches/util/prepared_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use chromiumoxide::{
Browser, Page,
};
use futures::{FutureExt, StreamExt};
use owo_colors::OwoColorize;
use tokio::task::spawn_blocking;
use url::Url;

Expand Down Expand Up @@ -181,12 +182,20 @@ fn stop_process(proc: &mut Child) -> Result<()> {
std::thread::sleep(KILL_DEADLINE / KILL_DEADLINE_CHECK_STEPS);
}
if let Ok(None) = proc.try_wait() {
eprintln!("Process {} did not exit after SIGINT, sending SIGKILL", pid);
eprintln!(
"{event_type} - process {pid} did not exit after SIGINT, sending SIGKILL",
event_type = "error".red(),
pid = pid
);
kill_process(proc)?;
}
}
Err(_) => {
eprintln!("Failed to send SIGINT to process {}, sending SIGKILL", pid);
eprintln!(
"{event_type} - failed to send SIGINT to process {pid}, sending SIGKILL",
event_type = "error".red(),
pid = pid
);
kill_process(proc)?;
}
}
Expand Down
20 changes: 12 additions & 8 deletions packages/next-swc/crates/next-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
use anyhow::{Context, Result};
use clap::Parser;
use next_dev::{register, NextDevServerBuilder};
use owo_colors::OwoColorize;
use turbo_tasks::{util::FormatDuration, TurboTasks};
use turbo_tasks_memory::MemoryBackend;
use turbopack_cli_utils::issue::IssueSeverityCliOption;
Expand Down Expand Up @@ -114,7 +115,8 @@ async fn main() -> Result<()> {
format!("http://{}", server.addr)
};
println!(
"started server on {}:{}, url: {}",
"{event_type} - started server on {}:{}, url: {}",
event_type = "ready".green(),
server.addr.ip(),
server.addr.port(),
index_uri
Expand All @@ -125,19 +127,21 @@ async fn main() -> Result<()> {
}

let stats_future = async move {
let (elapsed, count) = tt_clone.get_or_wait_update_info(Duration::ZERO).await;
println!(
"initial compilation {} ({} task execution, {} tasks)",
FormatDuration(start.elapsed()),
FormatDuration(elapsed),
count
"{event_type} - initial compilation {start}",
event_type = "event".purple(),
start = FormatDuration(start.elapsed()),
);

loop {
let (elapsed, count) = tt_clone
let (elapsed, _count) = tt_clone
.get_or_wait_update_info(Duration::from_millis(100))
.await;
println!("updated in {} ({} tasks)", FormatDuration(elapsed), count);
println!(
"{event_type} - updated in {elapsed}",
event_type = "event".purple(),
elapsed = FormatDuration(elapsed),
);
}
};

Expand Down
7 changes: 6 additions & 1 deletion packages/next-swc/crates/next-dev/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use chromiumoxide::{
use futures::StreamExt;
use lazy_static::lazy_static;
use next_dev::{register, NextDevServerBuilder};
use owo_colors::OwoColorize;
use serde::Deserialize;
use test_generator::test_resources;
use tokio::{net::TcpSocket, task::JoinHandle};
Expand Down Expand Up @@ -141,7 +142,11 @@ async fn run_test(resource: &str) -> JestRunResult {
.await
.unwrap();

println!("server started at http://{}", server.addr);
println!(
"{event_type} - server started at http://{address}",
event_type = "ready".green(),
address = server.addr
);

tokio::select! {
r = run_browser(server.addr) => r.unwrap(),
Expand Down

0 comments on commit b1caa9e

Please sign in to comment.