Skip to content

Commit d4a1827

Browse files
committed
chore(core): review changes
1 parent b0cd87c commit d4a1827

File tree

9 files changed

+60
-88
lines changed

9 files changed

+60
-88
lines changed

Cargo.lock

Lines changed: 0 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nx.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@
244244
"serveStaticTargetName": "serve-static"
245245
}
246246
},
247-
"@nx/enterprise-cloud",
248247
{
249248
"plugin": "@nx/storybook/plugin",
250249
"options": {

packages/nx/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ vt100-ctt = { git = "https://github.com/JamesHenry/vt100-rust", rev = "b15dc3b0f
6868
serde = "1.0.219"
6969
serde_json = "1.0.140"
7070

71-
sha2 = "0.10.8"
72-
7371
[target.'cfg(windows)'.dependencies]
7472
winapi = { version = "0.3", features = ["fileapi", "psapi", "shellapi"] }
7573

packages/nx/src/native/tui/action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ pub enum Action {
3636
EndTasks(Vec<TaskResult>),
3737
ToggleDebugMode,
3838
SendConsoleMessage(String),
39-
ConsoleMessagesAvailable(bool),
39+
ConsoleMessengerAvailable(bool),
4040
}

packages/nx/src/native/tui/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ impl App {
15621562
.as_ref()
15631563
.is_some_and(|c| c.is_connected())
15641564
{
1565-
self.dispatch_action(Action::ConsoleMessagesAvailable(true));
1565+
self.dispatch_action(Action::ConsoleMessengerAvailable(true));
15661566
}
15671567
}
15681568
}

packages/nx/src/native/tui/components/help_popup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl Component for HelpPopup {
388388
Action::Resize(w, h) => {
389389
self.handle_resize(w, h);
390390
}
391-
Action::ConsoleMessagesAvailable(available) => {
391+
Action::ConsoleMessengerAvailable(available) => {
392392
self.set_console_available(available);
393393
}
394394
_ => {}

packages/nx/src/native/tui/components/terminal_pane.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tui_term::widget::PseudoTerminal;
1515

1616
use crate::native::tui::components::tasks_list::TaskStatus;
1717
use crate::native::tui::theme::THEME;
18-
use crate::native::tui::{action::Action, nx_console, pty::PtyInstance};
18+
use crate::native::tui::{action::Action, pty::PtyInstance};
1919

2020
pub struct TerminalPaneData {
2121
pub pty: Option<Arc<PtyInstance>>,
@@ -509,16 +509,14 @@ impl<'a> StatefulWidget for TerminalPane<'a> {
509509
),
510510
])
511511
} else {
512-
let spans = vec![
512+
Line::from(vec![
513513
Span::raw(" "),
514514
Span::styled("i", Style::default().fg(THEME.info)),
515515
Span::styled(
516516
" to make interactive ",
517517
Style::default().fg(THEME.secondary_fg),
518518
),
519-
];
520-
521-
Line::from(spans)
519+
])
522520
};
523521

524522
let text_width = bottom_text

packages/nx/src/native/utils/socket_path.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
use sha2::{Digest, Sha256};
21
use std::env;
32
use std::fs;
43
use std::path::PathBuf;
54

5+
use crate::native::hasher::hash;
6+
67
const DAEMON_DIR_FOR_CURRENT_WORKSPACE: &str = "./nx/workspace-data/d";
78

89
fn socket_dir_name(workspace_root: &str, unique_name: Option<&'static str>) -> PathBuf {
9-
let mut hasher = Sha256::new();
10-
hasher.update(workspace_root.to_lowercase());
10+
let mut hashing_string = workspace_root.to_lowercase();
1111
if let Some(name) = unique_name {
12-
hasher.update(name)
12+
hashing_string.push(',');
13+
hashing_string.push_str(name);
1314
}
14-
let result = hasher.finalize();
15-
16-
let result_hex = format!("{:x}", result);
17-
let unique = result_hex.chars().take(20).collect::<String>();
18-
15+
let result = hash(hashing_string.as_bytes());
1916
let temp_dir = std::env::temp_dir();
20-
temp_dir.join(unique)
17+
temp_dir.join(result)
2118
}
2219

2320
fn get_socket_dir(workspace_root: &str, unique_name: Option<&'static str>) -> PathBuf {
@@ -31,7 +28,7 @@ fn get_socket_dir(workspace_root: &str, unique_name: Option<&'static str>) -> Pa
3128
} else {
3229
match fs::create_dir_all(&dir_path) {
3330
Ok(_) => dir_path,
34-
Err(_) => PathBuf::from(DAEMON_DIR_FOR_CURRENT_WORKSPACE),
31+
Err(_) => PathBuf::from(workspace_root).join(DAEMON_DIR_FOR_CURRENT_WORKSPACE),
3532
}
3633
};
3734

@@ -50,3 +47,49 @@ pub fn get_full_os_socket_path(workspace_root: &str) -> PathBuf {
5047
pub fn get_full_nx_console_socket_path(workspace_root: &str) -> PathBuf {
5148
get_socket_dir(workspace_root, Some("nx-console")).join("nx-console.sock")
5249
}
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use super::*;
54+
use std::env;
55+
56+
#[test]
57+
fn test_socket_dir_name_basic() {
58+
let root = "/tmp/test_workspace";
59+
let dir = socket_dir_name(root, None);
60+
assert_eq!(dir.to_string_lossy(), "/tmp/17684150229889955837");
61+
assert!(dir.is_absolute());
62+
}
63+
64+
#[test]
65+
fn test_socket_dir_name_with_unique_name() {
66+
let root = "/tmp/test_workspace";
67+
let dir = socket_dir_name(root, Some("unique"));
68+
assert_eq!(dir.to_string_lossy(), "/tmp/10757852796479033769");
69+
assert!(dir.is_absolute());
70+
}
71+
72+
#[test]
73+
fn test_get_socket_dir_env_var() {
74+
let root = "/tmp/test_workspace";
75+
let temp_dir = std::env::temp_dir().join("nx_test_socket_dir");
76+
unsafe { env::set_var("NX_SOCKET_DIR", &temp_dir) };
77+
let dir = get_socket_dir(root, None);
78+
assert_eq!(dir.to_string_lossy(), "/tmp/nx_test_socket_dir");
79+
unsafe { env::remove_var("NX_SOCKET_DIR") };
80+
}
81+
82+
#[test]
83+
fn test_get_full_os_socket_path() {
84+
let root = "/tmp/test_workspace";
85+
let path = get_full_os_socket_path(root);
86+
assert!(path.is_absolute() || path.starts_with("./nx/workspace-data/d"));
87+
}
88+
89+
#[test]
90+
fn test_get_full_nx_console_socket_path() {
91+
let root = "/tmp/test_workspace";
92+
let path = get_full_nx_console_socket_path(root);
93+
assert!(path.to_string_lossy().contains("nx-console.sock"));
94+
}
95+
}

packages/nx/src/native/utils/socket_path_test.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)