Skip to content

Commit

Permalink
chore(core): add new Rust crates for Nx core functionality
Browse files Browse the repository at this point in the history
- Added new Rust crates for core Nx functionality:
  - nx_cache
  - nx_db
  - nx_hasher
  - nx_machine
  - nx_project_graph
  - nx_tasks
  - nx_terminal
  - nx_walker
  - nx_watch
  - nx_workspace

- Updated Cargo.toml and Cargo.lock to include new crates
- Refactored existing code to use new crate modules
- Prepared infrastructure for future Nx core improvements
  • Loading branch information
Cammisuli committed Jan 28, 2025
1 parent 474012b commit d49ec0d
Show file tree
Hide file tree
Showing 50 changed files with 707 additions and 242 deletions.
182 changes: 182 additions & 0 deletions Cargo.lock

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

19 changes: 13 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[workspace]
resolver = "2"
members = [
"crates/*",
"packages/nx",
]
members = ["crates/*", "packages/nx"]

[workspace.package]
edition = "2021"
Expand All @@ -12,6 +9,16 @@ version = "0.1.0"

[workspace.dependencies]
nx_glob = { path = "crates/nx_glob" }
nx_walker = { path = "crates/nx_walker" }
nx_db = { path = "crates/nx_db" }
nx_hasher = { path = "crates/nx_hasher" }
nx_tasks = { path = "crates/nx_tasks" }
nx_workspace = { path = "crates/nx_workspace" }
nx_project_graph = { path = "crates/nx_project_graph" }
nx_cache = { path = "crates/nx_cache" }
nx_terminal = { path = "crates/nx_terminal" }
nx_watch = { path = "crates/nx_watch" }
nx_machine = { path = "crates/nx_machine" }

anyhow = "1.0.95"
colored = "2"
Expand Down Expand Up @@ -44,6 +51,8 @@ swc_common = "0.31.16"
swc_ecma_parser = { version = "0.137.1", features = ["typescript"] }
swc_ecma_visit = "0.93.0"
swc_ecma_ast = "0.107.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

#windows dependencies
winapi = { version = "0.3", features = ["fileapi"] }
Expand Down Expand Up @@ -72,5 +81,3 @@ tempfile = "3.13.0"

[profile.release]
lto = true


23 changes: 23 additions & 0 deletions crates/nx_cache/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "nx_cache"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }

[dependencies]
anyhow = { workspace = true }
tracing = { workspace = true }
nx_hasher = { workspace = true }
nx_walker = { workspace = true }
nx_glob = { workspace = true }
nx_db = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
parking_lot = { workspace = true }
rayon = { workspace = true }
rkyv = { workspace = true }

[dev-dependencies]
assert_fs = { workspace = true }
tempfile = { workspace = true }
4 changes: 4 additions & 0 deletions crates/nx_cache/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Placeholder function for cache operations
pub fn cache_task_result(_task_id: &str, _result: &[u8]) -> anyhow::Result<()> {
Ok(())
}
17 changes: 17 additions & 0 deletions crates/nx_db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "nx_db"
version.workspace = true
edition.workspace = true
license.workspace = true

[dependencies]
rusqlite = { workspace = true }
anyhow = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
parking_lot = { workspace = true }
fs4 = { workspace = true }

[dev-dependencies]
assert_fs = { workspace = true }
tempfile = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use anyhow::Result;

use rusqlite::{Connection, DatabaseName, Error, OptionalExtension, Params, Row, Statement, ToSql};
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -53,7 +52,7 @@ macro_rules! retry_db_operation_when_busy {
}

impl NxDbConnection {
pub fn new(connection: Connection) -> Self {
pub(crate) fn new(connection: Connection) -> Self {
Self {
conn: Some(connection),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::native::db::connection::NxDbConnection;
use crate::connection::NxDbConnection;
use fs4::fs_std::FileExt;
use rusqlite::{Connection, OpenFlags};
use std::fs::{remove_file, File};
use std::path::{Path, PathBuf};
use tracing::{debug, trace};

pub(super) struct LockFile {
pub(crate) struct LockFile {
file: File,
path: PathBuf,
}

pub(super) fn unlock_file(lock_file: &LockFile) {
pub(crate) fn unlock_file(lock_file: &LockFile) {
if lock_file.path.exists() {
lock_file
.file
Expand All @@ -20,7 +20,7 @@ pub(super) fn unlock_file(lock_file: &LockFile) {
}
}

pub(super) fn create_lock_file(db_path: &Path) -> anyhow::Result<LockFile> {
pub(crate) fn create_lock_file(db_path: &Path) -> anyhow::Result<LockFile> {
let lock_file_path = db_path.with_extension("lock");
let lock_file = File::create(&lock_file_path)
.map_err(|e| anyhow::anyhow!("Unable to create db lock file: {:?}", e))?;
Expand All @@ -36,7 +36,7 @@ pub(super) fn create_lock_file(db_path: &Path) -> anyhow::Result<LockFile> {
})
}

pub(super) fn initialize_db(nx_version: String, db_path: &Path) -> anyhow::Result<NxDbConnection> {
pub(crate) fn initialize_db(nx_version: String, db_path: &Path) -> anyhow::Result<NxDbConnection> {
match open_database_connection(db_path) {
Ok(mut c) => {
trace!(
Expand Down Expand Up @@ -77,7 +77,10 @@ pub(super) fn initialize_db(nx_version: String, db_path: &Path) -> anyhow::Resul
Ok(c)
}
Err(reason) => {
trace!("Unable to connect to existing database because: {:?}", reason);
trace!(
"Unable to connect to existing database because: {:?}",
reason
);
trace!("Removing existing incompatible database");
remove_file(db_path)?;

Expand Down Expand Up @@ -136,8 +139,6 @@ fn configure_database(connection: &NxDbConnection) -> anyhow::Result<()> {

#[cfg(test)]
mod tests {
use crate::native::logger::enable_logger;

use super::*;

#[test]
Expand Down Expand Up @@ -182,10 +183,9 @@ mod tests {

#[test]
fn initialize_db_recreates_incompatible_db() -> anyhow::Result<()> {
enable_logger();
let temp_dir = tempfile::tempdir()?;
let db_path = temp_dir.path().join("test.db");
//

// Create initial db
let _ = initialize_db("1.0.0".to_string(), &db_path)?;

Expand Down
Loading

0 comments on commit d49ec0d

Please sign in to comment.