Skip to content

Commit

Permalink
Merge branch 'main' into bump-semver
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew authored Nov 10, 2024
2 parents 0aa996c + deb9ae1 commit 0f653cf
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 47 deletions.
5 changes: 4 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,10 @@ pub async fn run(
let base = CommandBase::new(cli_args, repo_root, version, color_config);

let mut client = WatchClient::new(base, event).await?;
client.start().await?;
if let Err(e) = client.start().await {
client.shutdown().await;
return Err(e.into());
}
// We only exit if we get a signal, so we return a non-zero exit code
return Ok(1);
}
Expand Down
8 changes: 7 additions & 1 deletion crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, io};
use std::{env, io, path::Path};

use sysinfo::{System, SystemExt};
use thiserror::Error;
Expand All @@ -13,6 +13,11 @@ pub enum Error {
NoCurrentExe(#[from] io::Error),
}

// https://superuser.com/questions/1749781/how-can-i-check-if-the-environment-is-wsl-from-a-shell-script/1749811#1749811
fn is_wsl() -> bool {
Path::new("/proc/sys/fs/binfmt_misc/WSLInterop").exists()
}

pub async fn run(base: CommandBase) {
let system = System::new_all();
let connector = DaemonConnector::new(false, false, &base.repo_root);
Expand Down Expand Up @@ -44,6 +49,7 @@ pub async fn run(base: CommandBase) {
println!("Platform:");
println!(" Architecture: {}", std::env::consts::ARCH);
println!(" Operating system: {}", std::env::consts::OS);
println!(" WSL: {}", is_wsl());
println!(
" Available memory (MB): {}",
system.available_memory() / 1024 / 1024
Expand Down
75 changes: 65 additions & 10 deletions crates/turborepo-lib/src/engine/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ use crate::{
};

#[derive(Debug, thiserror::Error, Diagnostic)]
#[error("could not find task `{name}` in project")]
pub struct MissingTaskError {
name: String,
#[label]
span: Option<SourceSpan>,
#[source_code]
text: NamedSource,
pub enum MissingTaskError {
#[error("could not find task `{name}` in project")]
MissingTaskDefinition {
name: String,
#[label]
span: Option<SourceSpan>,
#[source_code]
text: NamedSource,
},
#[error("could not find package `{name}` in project")]
MissingPackage { name: String },
}

#[derive(Debug, thiserror::Error, Diagnostic)]
Expand Down Expand Up @@ -253,6 +257,17 @@ impl<'a> EngineBuilder<'a> {
}

if !missing_tasks.is_empty() {
let missing_pkgs: HashMap<_, _> = missing_tasks
.iter()
.filter_map(|(task, _)| {
let pkg = task.package()?;
let missing_pkg = self
.package_graph
.package_info(&PackageName::from(pkg))
.is_none();
missing_pkg.then(|| (task.to_string(), pkg.to_string()))
})
.collect();
let mut missing_tasks = missing_tasks
.into_iter()
.map(|(task_name, span)| (task_name.to_string(), span))
Expand All @@ -262,8 +277,12 @@ impl<'a> EngineBuilder<'a> {
let errors = missing_tasks
.into_iter()
.map(|(name, span)| {
let (span, text) = span.span_and_text("turbo.json");
MissingTaskError { name, span, text }
if let Some(pkg) = missing_pkgs.get(&name) {
MissingTaskError::MissingPackage { name: pkg.clone() }
} else {
let (span, text) = span.span_and_text("turbo.json");
MissingTaskError::MissingTaskDefinition { name, span, text }
}
})
.collect();

Expand Down Expand Up @@ -561,7 +580,7 @@ fn validate_task_name(task: Spanned<&str>) -> Result<(), Error> {
mod test {
use std::assert_matches::assert_matches;

use insta::assert_json_snapshot;
use insta::{assert_json_snapshot, assert_snapshot};
use pretty_assertions::assert_eq;
use serde_json::json;
use tempfile::TempDir;
Expand Down Expand Up @@ -1372,4 +1391,40 @@ mod test {
.unwrap();
assert_json_snapshot!(msg);
}

#[test]
fn test_run_package_task_invalid_package() {
let repo_root_dir = TempDir::with_prefix("repo").unwrap();
let repo_root = AbsoluteSystemPathBuf::new(repo_root_dir.path().to_str().unwrap()).unwrap();
let package_graph = mock_package_graph(
&repo_root,
package_jsons! {
repo_root,
"app1" => ["libA"],
"libA" => []
},
);
let turbo_jsons = vec![(
PackageName::Root,
turbo_json(json!({
"tasks": {
"build": { "dependsOn": ["^build"] },
}
})),
)]
.into_iter()
.collect();
let loader = TurboJsonLoader::noop(turbo_jsons);
let engine = EngineBuilder::new(&repo_root, &package_graph, loader.clone(), false)
.with_tasks(vec![Spanned::new(TaskName::from("app2#bad-task"))])
.with_workspaces(vec![PackageName::from("app1"), PackageName::from("libA")])
.build();
assert!(engine.is_err());
let report = miette::Report::new(engine.unwrap_err());
let mut msg = String::new();
miette::NarratableReportHandler::new()
.render_report(&mut msg, report.as_ref())
.unwrap();
assert_snapshot!(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: crates/turborepo-lib/src/engine/builder.rs
expression: msg
---
missing tasks in project
Diagnostic severity: error

Error: could not find package `app2` in project
Diagnostic severity: error
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/process/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl Child {
// On Windows it is important that this gets dropped once the child process
// exits
let controller = controller;
debug!("waiting for task");
debug!("waiting for task: {pid:?}");
let manager = ChildStateManager {
shutdown_style,
task_state,
Expand Down
21 changes: 14 additions & 7 deletions crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,6 @@ impl WatchClient {
biased;
_ = signal_subscriber.listen() => {
tracing::info!("shutting down");
if let Some(RunHandle { stopper, run_task }) = self.persistent_tasks_handle.take() {
// Shut down the tasks for the run
stopper.stop().await;
// Run should exit shortly after we stop all child tasks, wait for it to finish
// to ensure all messages are flushed.
let _ = run_task.await;
}
Err(Error::SignalInterrupt)
}
result = event_fut => {
Expand Down Expand Up @@ -267,6 +260,20 @@ impl WatchClient {
Ok(())
}

/// Shut down any resources that run as part of watch.
pub async fn shutdown(&mut self) {
if let Some(sender) = &self.ui_sender {
sender.stop().await;
}
if let Some(RunHandle { stopper, run_task }) = self.persistent_tasks_handle.take() {
// Shut down the tasks for the run
stopper.stop().await;
// Run should exit shortly after we stop all child tasks, wait for it to finish
// to ensure all messages are flushed.
let _ = run_task.await;
}
}

/// Executes a run with the given changed packages. Splits the run into two
/// parts:
/// 1. The persistent tasks that are not allowed to be interrupted
Expand Down
27 changes: 16 additions & 11 deletions crates/turborepo-ui/src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,24 @@ impl<W> App<W> {
#[tracing::instrument(skip(self))]
pub fn next(&mut self) {
let num_rows = self.tasks_by_status.count_all();
let next_index = (self.selected_task_index + 1).clamp(0, num_rows - 1);
self.selected_task_index = next_index;
self.scroll.select(Some(next_index));
self.has_user_scrolled = true;
if num_rows > 0 {
self.selected_task_index = (self.selected_task_index + 1) % num_rows;
self.scroll.select(Some(self.selected_task_index));
self.has_user_scrolled = true;
}
}

#[tracing::instrument(skip(self))]
pub fn previous(&mut self) {
let i = match self.selected_task_index {
0 => 0,
i => i - 1,
};
self.selected_task_index = i;
self.scroll.select(Some(i));
self.has_user_scrolled = true;
let num_rows = self.tasks_by_status.count_all();
if num_rows > 0 {
self.selected_task_index = self
.selected_task_index
.checked_sub(1)
.unwrap_or(num_rows - 1);
self.scroll.select(Some(self.selected_task_index));
self.has_user_scrolled = true;
}
}

#[tracing::instrument(skip_all)]
Expand Down Expand Up @@ -886,6 +889,8 @@ mod test {
app.next();
assert_eq!(app.scroll.selected(), Some(2), "scroll moves forwards");
app.next();
assert_eq!(app.scroll.selected(), Some(0), "scroll wraps");
app.previous();
assert_eq!(app.scroll.selected(), Some(2), "scroll stays in bounds");
}

Expand Down
2 changes: 1 addition & 1 deletion packages/create-turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-turbo",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "Create a new Turborepo",
"homepage": "https://turbo.build/repo",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-turbo",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "ESLint config for Turborepo",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-turbo",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "ESLint plugin for Turborepo",
"keywords": [
"turbo",
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turbo/codemod",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "Provides Codemod transformations to help upgrade your Turborepo codebase when a feature is deprecated.",
"homepage": "https://turbo.build/repo",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-gen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turbo/gen",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "Extend a Turborepo",
"homepage": "https://turbo.build/repo",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-ignore/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-ignore",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "",
"homepage": "https://turbo.build/repo",
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turbo/types",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "Turborepo types",
"homepage": "https://turbo.build/repo",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@turbo/workspaces",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "Tools for working with package managers",
"homepage": "https://turbo.build/repo",
"license": "MIT",
Expand Down
14 changes: 7 additions & 7 deletions packages/turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo",
"version": "2.2.4-canary.8",
"version": "2.2.4-canary.9",
"description": "Turborepo is a high-performance build system for JavaScript and TypeScript codebases.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand All @@ -17,11 +17,11 @@
"bin"
],
"optionalDependencies": {
"turbo-darwin-64": "2.2.4-canary.8",
"turbo-darwin-arm64": "2.2.4-canary.8",
"turbo-linux-64": "2.2.4-canary.8",
"turbo-linux-arm64": "2.2.4-canary.8",
"turbo-windows-64": "2.2.4-canary.8",
"turbo-windows-arm64": "2.2.4-canary.8"
"turbo-darwin-64": "2.2.4-canary.9",
"turbo-darwin-arm64": "2.2.4-canary.9",
"turbo-linux-64": "2.2.4-canary.9",
"turbo-linux-arm64": "2.2.4-canary.9",
"turbo-windows-64": "2.2.4-canary.9",
"turbo-windows-arm64": "2.2.4-canary.9"
}
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
2.2.4-canary.8
2.2.4-canary.9
canary

0 comments on commit 0f653cf

Please sign in to comment.