diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 946e8612b6..5a4c0cee46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,7 +94,7 @@ jobs: pnpm nx run-many -t check-imports check-commit check-lock-files check-codeowners --parallel=1 --no-dte & pids+=($!) - pnpm nx affected --targets=lint,test,build,e2e,e2e-ci & + pnpm nx affected --targets=lint,test,build,e2e,e2e-ci,format-native & pids+=($!) for pid in "${pids[@]}"; do diff --git a/.husky/pre-push b/.husky/pre-push index 43c708f9b5..f5cdcc252a 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -2,3 +2,4 @@ pnpm check-lock-files pnpm check-commit pnpm documentation pnpm pretty-quick --check +pnpm nx format-native nx \ No newline at end of file diff --git a/packages/nx/project.json b/packages/nx/project.json index 768fa44bc2..714b7ac15b 100644 --- a/packages/nx/project.json +++ b/packages/nx/project.json @@ -139,6 +139,19 @@ "parallel": false } }, - "test-native": {} + "test-native": {}, + "format-native": { + "command": "cargo fmt", + "cache": true, + "options": { + "cwd": "{projectRoot}/src/native", + "args": ["--all", "--check"] + }, + "configurations": { + "fix": { + "args": ["--all"] + } + } + } } } diff --git a/packages/nx/src/native/glob/glob_transform.rs b/packages/nx/src/native/glob/glob_transform.rs index 2644f72feb..ed5dc70fc4 100644 --- a/packages/nx/src/native/glob/glob_transform.rs +++ b/packages/nx/src/native/glob/glob_transform.rs @@ -1,9 +1,9 @@ +use super::contains_glob_pattern; use crate::native::glob::glob_group::GlobGroup; use crate::native::glob::glob_parser::parse_glob; +use itertools::Either::{Left, Right}; use itertools::Itertools; use std::collections::HashSet; -use itertools::Either::{Left, Right}; -use super::contains_glob_pattern; #[derive(Debug)] enum GlobType { @@ -120,15 +120,13 @@ pub fn partition_glob(glob: &str) -> anyhow::Result<(String, Vec)> { let (leading_dir_segments, pattern_segments): (Vec, _) = groups .into_iter() .filter(|group| !group.is_empty()) - .partition_map(|group| { - match &group[0] { - GlobGroup::NonSpecial(value) if !contains_glob_pattern(&value) && !has_patterns => { - Left(value.to_string()) - } - _ => { - has_patterns = true; - Right(group) - } + .partition_map(|group| match &group[0] { + GlobGroup::NonSpecial(value) if !contains_glob_pattern(&value) && !has_patterns => { + Left(value.to_string()) + } + _ => { + has_patterns = true; + Right(group) } }); @@ -267,7 +265,8 @@ mod test { #[test] fn should_partition_glob_with_leading_dirs() { - let (leading_dirs, globs) = super::partition_glob("dist/app/**/!(README|LICENSE).(js|ts)").unwrap(); + let (leading_dirs, globs) = + super::partition_glob("dist/app/**/!(README|LICENSE).(js|ts)").unwrap(); assert_eq!(leading_dirs, "dist/app"); assert_eq!(globs, ["!**/{README,LICENSE}.{js,ts}", "**/*.{js,ts}",]); } diff --git a/packages/nx/src/native/hasher.rs b/packages/nx/src/native/hasher.rs index 872ff65cbb..0426b8a98b 100644 --- a/packages/nx/src/native/hasher.rs +++ b/packages/nx/src/native/hasher.rs @@ -9,12 +9,16 @@ pub fn hash(content: &[u8]) -> String { #[napi] pub fn hash_array(input: Vec>) -> String { - let joined = input.iter().filter_map(|s| { - if s.is_none() { - trace!("Encountered None value in hash_array input: {:?}", input); - } - s.as_deref() - }).collect::>().join(","); + let joined = input + .iter() + .filter_map(|s| { + if s.is_none() { + trace!("Encountered None value in hash_array input: {:?}", input); + } + s.as_deref() + }) + .collect::>() + .join(","); let content = joined.as_bytes(); hash(content) } @@ -41,7 +45,7 @@ pub fn hash_file_path>(path: P) -> Option { #[cfg(test)] mod tests { - use crate::native::hasher::{hash_file, hash_array}; + use crate::native::hasher::{hash_array, hash_file}; use assert_fs::prelude::*; use assert_fs::TempDir; diff --git a/packages/nx/src/native/project_graph/transfer_project_graph.rs b/packages/nx/src/native/project_graph/transfer_project_graph.rs index b68bc78a07..33de1f5605 100644 --- a/packages/nx/src/native/project_graph/transfer_project_graph.rs +++ b/packages/nx/src/native/project_graph/transfer_project_graph.rs @@ -8,4 +8,3 @@ use crate::native::project_graph::types::ProjectGraph; pub fn transfer_project_graph(project_graph: ProjectGraph) -> External { External::new(project_graph) } - diff --git a/packages/nx/src/native/pseudo_terminal/mac.rs b/packages/nx/src/native/pseudo_terminal/mac.rs index 22f83a233c..ded8d0fe47 100644 --- a/packages/nx/src/native/pseudo_terminal/mac.rs +++ b/packages/nx/src/native/pseudo_terminal/mac.rs @@ -32,14 +32,8 @@ impl RustPseudoTerminal { quiet: Option, tty: Option, ) -> napi::Result { - self.pseudo_terminal.run_command( - command, - command_dir, - js_env, - exec_argv, - quiet, - tty, - ) + self.pseudo_terminal + .run_command(command, command_dir, js_env, exec_argv, quiet, tty) } /// This allows us to run a pseudoterminal with a fake node ipc channel diff --git a/packages/nx/src/native/pseudo_terminal/non_mac.rs b/packages/nx/src/native/pseudo_terminal/non_mac.rs index f90cc04904..9aa2853dfb 100644 --- a/packages/nx/src/native/pseudo_terminal/non_mac.rs +++ b/packages/nx/src/native/pseudo_terminal/non_mac.rs @@ -33,14 +33,8 @@ impl RustPseudoTerminal { quiet: Option, tty: Option, ) -> napi::Result { - self.pseudo_terminal.run_command( - command, - command_dir, - js_env, - exec_argv, - quiet, - tty, - ) + self.pseudo_terminal + .run_command(command, command_dir, js_env, exec_argv, quiet, tty) } /// This allows us to run a pseudoterminal with a fake node ipc channel diff --git a/packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs b/packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs index 67cf2b4d83..636f4e074b 100644 --- a/packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs +++ b/packages/nx/src/native/pseudo_terminal/pseudo_terminal.rs @@ -117,7 +117,9 @@ impl PseudoTerminal { let mut content = String::from_utf8_lossy(&buf[0..len]).to_string(); if content.contains("\x1B[6n") { - trace!("Prevented terminal escape sequence ESC[6n from being printed."); + trace!( + "Prevented terminal escape sequence ESC[6n from being printed." + ); content = content.replace("\x1B[6n", ""); } diff --git a/packages/nx/src/native/tasks/hashers.rs b/packages/nx/src/native/tasks/hashers.rs index 796e002a8e..f8cbff0906 100644 --- a/packages/nx/src/native/tasks/hashers.rs +++ b/packages/nx/src/native/tasks/hashers.rs @@ -4,8 +4,8 @@ mod hash_project_config; mod hash_project_files; mod hash_runtime; mod hash_task_output; -mod hash_workspace_files; mod hash_tsconfig; +mod hash_workspace_files; pub use hash_env::*; pub use hash_external::*; @@ -13,5 +13,5 @@ pub use hash_project_config::*; pub use hash_project_files::*; pub use hash_runtime::*; pub use hash_task_output::*; +pub use hash_tsconfig::*; pub use hash_workspace_files::*; -pub use hash_tsconfig::*; \ No newline at end of file diff --git a/packages/nx/src/native/tasks/hashers/hash_project_files.rs b/packages/nx/src/native/tasks/hashers/hash_project_files.rs index 0da62150e6..d524b4d173 100644 --- a/packages/nx/src/native/tasks/hashers/hash_project_files.rs +++ b/packages/nx/src/native/tasks/hashers/hash_project_files.rs @@ -158,12 +158,15 @@ mod tests { let hash_result = hash_project_files(proj_name, proj_root, file_sets, &file_map).unwrap(); assert_eq!( hash_result, - hash(&[ - file_data1.hash.as_bytes(), - file_data1.file.as_bytes(), - file_data3.hash.as_bytes(), - file_data3.file.as_bytes() - ].concat()) + hash( + &[ + file_data1.hash.as_bytes(), + file_data1.file.as_bytes(), + file_data3.hash.as_bytes(), + file_data3.file.as_bytes() + ] + .concat() + ) ); } @@ -205,12 +208,15 @@ mod tests { let hash_result = hash_project_files(proj_name, proj_root, file_sets, &file_map).unwrap(); assert_eq!( hash_result, - hash(&[ - file_data1.hash.as_bytes(), - file_data1.file.as_bytes(), - file_data3.hash.as_bytes(), - file_data3.file.as_bytes(), - ].concat()) + hash( + &[ + file_data1.hash.as_bytes(), + file_data1.file.as_bytes(), + file_data3.hash.as_bytes(), + file_data3.file.as_bytes(), + ] + .concat() + ) ); } } diff --git a/packages/nx/src/native/tasks/hashers/hash_task_output.rs b/packages/nx/src/native/tasks/hashers/hash_task_output.rs index f4ccf3d300..914f605910 100644 --- a/packages/nx/src/native/tasks/hashers/hash_task_output.rs +++ b/packages/nx/src/native/tasks/hashers/hash_task_output.rs @@ -1,9 +1,9 @@ -use std::path::Path; use crate::native::cache::expand_outputs::get_files_for_outputs; use crate::native::glob::build_glob_set; use crate::native::hasher::{hash_array, hash_file}; use anyhow::*; use rayon::prelude::*; +use std::path::Path; use tracing::trace; pub fn hash_task_output(workspace_root: &str, glob: &str, outputs: &[String]) -> Result { @@ -14,7 +14,15 @@ pub fn hash_task_output(workspace_root: &str, glob: &str, outputs: &[String]) -> let hashes = output_files .into_par_iter() .filter(|file| glob.is_match(file)) - .filter_map(|file| hash_file(Path::new(workspace_root).join(file).to_str().expect("path contains invalid utf-8").to_owned())) + .filter_map(|file| { + hash_file( + Path::new(workspace_root) + .join(file) + .to_str() + .expect("path contains invalid utf-8") + .to_owned(), + ) + }) .collect::>(); Ok(hash_array(hashes.into_iter().map(Some).collect())) } diff --git a/packages/nx/src/native/tasks/mod.rs b/packages/nx/src/native/tasks/mod.rs index 7150b8eb8f..20af6ddb82 100644 --- a/packages/nx/src/native/tasks/mod.rs +++ b/packages/nx/src/native/tasks/mod.rs @@ -9,6 +9,6 @@ mod utils; #[cfg(not(target_arch = "wasm32"))] pub mod details; #[cfg(not(target_arch = "wasm32"))] -pub mod task_history; -#[cfg(not(target_arch = "wasm32"))] pub mod running_tasks_service; +#[cfg(not(target_arch = "wasm32"))] +pub mod task_history; diff --git a/packages/nx/src/native/tui/components/countdown_popup.rs b/packages/nx/src/native/tui/components/countdown_popup.rs index 81ec72d193..afba177dd9 100644 --- a/packages/nx/src/native/tui/components/countdown_popup.rs +++ b/packages/nx/src/native/tui/components/countdown_popup.rs @@ -99,10 +99,12 @@ impl CountdownPopup { pub fn render(&mut self, f: &mut Frame<'_>, area: Rect) { // Add a safety check to prevent rendering outside buffer bounds (this can happen if the user resizes the window a lot before it stabilizes it seems) - if area.height == 0 || area.width == 0 || - area.x >= f.area().width || - area.y >= f.area().height { - return; // Area is out of bounds, don't try to render + if area.height == 0 + || area.width == 0 + || area.x >= f.area().width + || area.y >= f.area().height + { + return; // Area is out of bounds, don't try to render } // Ensure area is entirely within frame bounds @@ -112,7 +114,7 @@ impl CountdownPopup { width: area.width.min(f.area().width.saturating_sub(area.x)), height: area.height.min(f.area().height.saturating_sub(area.y)), }; - + let popup_height = 9; let popup_width = 70; diff --git a/packages/nx/src/native/tui/components/help_text.rs b/packages/nx/src/native/tui/components/help_text.rs index 073cee8b30..534d5d2be0 100644 --- a/packages/nx/src/native/tui/components/help_text.rs +++ b/packages/nx/src/native/tui/components/help_text.rs @@ -27,10 +27,12 @@ impl HelpText { pub fn render(&self, f: &mut Frame<'_>, area: Rect) { // Add a safety check to prevent rendering outside buffer bounds (this can happen if the user resizes the window a lot before it stabilizes it seems) - if area.height == 0 || area.width == 0 || - area.x >= f.area().width || - area.y >= f.area().height { - return; // Area is out of bounds, don't try to render + if area.height == 0 + || area.width == 0 + || area.x >= f.area().width + || area.y >= f.area().height + { + return; // Area is out of bounds, don't try to render } // Ensure area is entirely within frame bounds diff --git a/packages/nx/src/native/tui/components/layout_manager.rs b/packages/nx/src/native/tui/components/layout_manager.rs index 540a24defc..5c4b258eeb 100644 --- a/packages/nx/src/native/tui/components/layout_manager.rs +++ b/packages/nx/src/native/tui/components/layout_manager.rs @@ -195,7 +195,7 @@ impl LayoutManager { terminal_panes: Vec::new(), }; } - + match self.task_list_visibility { TaskListVisibility::Hidden => self.calculate_layout_hidden_task_list(area), TaskListVisibility::Visible => self.calculate_layout_visible_task_list(area), @@ -252,19 +252,15 @@ impl LayoutManager { } // Prevent divide-by-zero - let task_list_height = if area.height < 3 { - 1 - } else { - area.height / 3 - }; - + let task_list_height = if area.height < 3 { 1 } else { area.height / 3 }; + // Apply padding only if there's enough space let padding_height = if area.height > task_list_height + self.vertical_padding { self.vertical_padding } else { 0 }; - + // Ensure terminal pane has at least 1 row let available_height = area.height.saturating_sub(task_list_height); let terminal_pane_height = available_height.saturating_sub(padding_height); @@ -311,19 +307,15 @@ impl LayoutManager { } // Prevent divide-by-zero - let task_list_width = if area.width < 3 { - 1 - } else { - area.width / 3 - }; - + let task_list_width = if area.width < 3 { 1 } else { area.width / 3 }; + // Apply padding only if there's enough space let padding_width = if area.width > task_list_width + self.horizontal_padding { self.horizontal_padding } else { 0 }; - + // Ensure terminal pane has at least 1 column let available_width = area.width.saturating_sub(task_list_width); let terminal_pane_width = available_width.saturating_sub(padding_width); @@ -440,7 +432,10 @@ mod tests { fn test_default_properties() { let layout_manager = LayoutManager::new(5); assert_eq!(layout_manager.get_pane_arrangement(), PaneArrangement::None); - assert_eq!(layout_manager.get_task_list_visibility(), TaskListVisibility::Visible); + assert_eq!( + layout_manager.get_task_list_visibility(), + TaskListVisibility::Visible + ); assert_eq!(layout_manager.get_task_count(), 5); } @@ -689,43 +684,43 @@ mod tests { fn test_padding_between_components() { let mut layout_manager = LayoutManager::new(5); let area = create_test_area(100, 60); - + // Test with default horizontal padding (2) layout_manager.set_mode(LayoutMode::Horizontal); layout_manager.set_task_list_visibility(TaskListVisibility::Visible); layout_manager.set_pane_arrangement(PaneArrangement::Single); - + let layout = layout_manager.calculate_layout(area); let task_list = layout.task_list.unwrap(); let terminal_pane = layout.terminal_panes[0]; - + // The gap between task list and terminal pane should equal the horizontal padding assert_eq!(terminal_pane.x - (task_list.x + task_list.width), 2); - + // Test with increased horizontal padding layout_manager.set_horizontal_padding(3); let layout = layout_manager.calculate_layout(area); let task_list = layout.task_list.unwrap(); let terminal_pane = layout.terminal_panes[0]; - + // The gap should now be 3 assert_eq!(terminal_pane.x - (task_list.x + task_list.width), 3); - + // Test with vertical layout and default vertical padding (1) layout_manager.set_mode(LayoutMode::Vertical); let layout = layout_manager.calculate_layout(area); let task_list = layout.task_list.unwrap(); let terminal_pane = layout.terminal_panes[0]; - + // The gap should be vertical and equal to the vertical padding assert_eq!(terminal_pane.y - (task_list.y + task_list.height), 1); - + // Test with increased vertical padding layout_manager.set_vertical_padding(2); let layout = layout_manager.calculate_layout(area); let task_list = layout.task_list.unwrap(); let terminal_pane = layout.terminal_panes[0]; - + // The gap should now be 2 assert_eq!(terminal_pane.y - (task_list.y + task_list.height), 2); } diff --git a/packages/nx/src/native/tui/components/terminal_pane.rs b/packages/nx/src/native/tui/components/terminal_pane.rs index 7dc7a2bc56..15ac489336 100644 --- a/packages/nx/src/native/tui/components/terminal_pane.rs +++ b/packages/nx/src/native/tui/components/terminal_pane.rs @@ -297,7 +297,7 @@ impl<'a> StatefulWidget for TerminalPane<'a> { width: area.width.min(buf.area().width.saturating_sub(area.x)), height: area.height.min(buf.area().height.saturating_sub(area.y)), }; - + if safe_area.width > 0 && safe_area.height > 0 { // Only attempt to render if we have a valid area let text = "..."; @@ -308,7 +308,7 @@ impl<'a> StatefulWidget for TerminalPane<'a> { } return; } - + // Ensure the area doesn't extend beyond buffer boundaries let safe_area = Rect { x: area.x, @@ -316,7 +316,7 @@ impl<'a> StatefulWidget for TerminalPane<'a> { width: area.width.min(buf.area().width.saturating_sub(area.x)), height: area.height.min(buf.area().height.saturating_sub(area.y)), }; - + let base_style = self.get_base_style(state.task_status); let border_style = if state.is_focused { base_style diff --git a/packages/nx/src/native/utils/atomics/default.rs b/packages/nx/src/native/utils/atomics/default.rs index e8fd1a7132..9b12d988ad 100644 --- a/packages/nx/src/native/utils/atomics/default.rs +++ b/packages/nx/src/native/utils/atomics/default.rs @@ -2,7 +2,7 @@ use parking_lot::{Condvar, Mutex, MutexGuard}; pub struct NxMutex(Mutex); -impl NxMutex { +impl NxMutex { pub fn new(value: T) -> Self { Self(Mutex::new(value)) } @@ -18,9 +18,13 @@ impl NxCondvar { Self(Condvar::new()) } - pub fn wait<'a, T, F>(&'a self, mut guard: MutexGuard<'a, T>, condition: F) -> anyhow::Result> - where - F: Fn(&MutexGuard<'a, T>) -> bool + pub fn wait<'a, T, F>( + &'a self, + mut guard: MutexGuard<'a, T>, + condition: F, + ) -> anyhow::Result> + where + F: Fn(&MutexGuard<'a, T>) -> bool, { if condition(&guard) { self.0.wait(&mut guard); diff --git a/packages/nx/src/native/utils/atomics/wasm.rs b/packages/nx/src/native/utils/atomics/wasm.rs index e2360acfc0..e79ca45c99 100644 --- a/packages/nx/src/native/utils/atomics/wasm.rs +++ b/packages/nx/src/native/utils/atomics/wasm.rs @@ -2,7 +2,7 @@ use std::sync::{Condvar, LockResult, Mutex, MutexGuard}; pub struct NxMutex(Mutex); -impl NxMutex { +impl NxMutex { pub fn new(value: T) -> Self { Self(Mutex::new(value)) } @@ -18,9 +18,13 @@ impl NxCondvar { Self(Condvar::new()) } - pub fn wait<'a, T, F>(&self, mutex_guard: MutexGuard<'a, T>, condition: F) -> LockResult> + pub fn wait<'a, T, F>( + &self, + mutex_guard: MutexGuard<'a, T>, + condition: F, + ) -> LockResult> where - F: Fn(&mut T) -> bool + F: Fn(&mut T) -> bool, { self.0.wait_while(mutex_guard, condition) } diff --git a/packages/nx/src/native/utils/ci.rs b/packages/nx/src/native/utils/ci.rs index e040d6991b..951b691817 100644 --- a/packages/nx/src/native/utils/ci.rs +++ b/packages/nx/src/native/utils/ci.rs @@ -16,4 +16,4 @@ pub fn is_ci() -> bool { || env::var("BUILD_ID").is_ok() || env::var("BUILD_BUILDID").is_ok() || env::var("TEAMCITY_VERSION").is_ok() -} \ No newline at end of file +} diff --git a/packages/nx/src/native/utils/path.rs b/packages/nx/src/native/utils/path.rs index 409f70a78a..2c0815fa34 100644 --- a/packages/nx/src/native/utils/path.rs +++ b/packages/nx/src/native/utils/path.rs @@ -1,4 +1,4 @@ -use crate::native::{utils::normalize_trait::Normalize, types::FileData}; +use crate::native::{types::FileData, utils::normalize_trait::Normalize}; use std::path::{Path, PathBuf}; impl Normalize for Path { @@ -65,13 +65,9 @@ mod test { FileData { file: "foo-other/not-child".into(), hash: "123".into(), - } + }, ]; let child_files = get_child_files(&directory, files); - assert_eq!(child_files, [ - "foo/bar", - "foo/baz", - "foo/child/bar", - ]); + assert_eq!(child_files, ["foo/bar", "foo/baz", "foo/child/bar",]); } -} \ No newline at end of file +} diff --git a/packages/nx/src/native/walker.rs b/packages/nx/src/native/walker.rs index 0a1fe49be1..97ee40ae79 100644 --- a/packages/nx/src/native/walker.rs +++ b/packages/nx/src/native/walker.rs @@ -50,14 +50,13 @@ where !ignore_glob_set.is_match(path.as_ref()) }) .filter_map(move |entry| { - entry - .ok() - .and_then(|e| - e.path() - .strip_prefix(&base_dir).ok() + entry.ok().and_then(|e| { + e.path() + .strip_prefix(&base_dir) + .ok() .filter(|p| !p.to_string_lossy().is_empty()) .map(|p| p.to_owned()) - ) + }) }) } diff --git a/packages/nx/src/native/workspace/files_hashing.rs b/packages/nx/src/native/workspace/files_hashing.rs index 087d4cedd4..3df3a986cb 100644 --- a/packages/nx/src/native/workspace/files_hashing.rs +++ b/packages/nx/src/native/workspace/files_hashing.rs @@ -61,7 +61,11 @@ fn hash_files(files: Vec) -> Vec<(String, NxFileHashed)> { }) .collect::>() } else { - trace!("hashing workspace files in {} chunks of {}", num_parallelism, chunks); + trace!( + "hashing workspace files in {} chunks of {}", + num_parallelism, + chunks + ); files .par_chunks(chunks) .flat_map_iter(|chunks| {