From a38df9bcaa3eacdd58843b8fee9f575455887f94 Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Wed, 24 Jul 2024 11:18:33 -0400 Subject: [PATCH] feat(core): include target architecture in nx report --- Cargo.lock | 27 +++++++++++++++++ packages/nx/Cargo.toml | 1 + packages/nx/src/command-line/report/report.ts | 24 ++++++++++----- packages/nx/src/native/index.d.ts | 2 ++ packages/nx/src/native/metadata.rs | 30 +++++++++++++++++++ packages/nx/src/native/mod.rs | 10 +++---- packages/nx/src/native/native-bindings.js | 1 + packages/nx/src/native/utils/mod.rs | 1 - packages/nx/src/native/wasm.rs | 7 ----- 9 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 packages/nx/src/native/metadata.rs delete mode 100644 packages/nx/src/native/wasm.rs diff --git a/Cargo.lock b/Cargo.lock index 90f34b362bcfb..7065c2462ce48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,6 +277,26 @@ dependencies = [ "winapi", ] +[[package]] +name = "const_format" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "convert_case" version = "0.6.0" @@ -1366,6 +1386,7 @@ dependencies = [ "anyhow", "assert_fs", "colored", + "const_format", "crossbeam-channel", "crossterm", "dashmap", @@ -2495,6 +2516,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "url" version = "2.5.0" diff --git a/packages/nx/Cargo.toml b/packages/nx/Cargo.toml index 194ea94708029..6f83fad4555e9 100644 --- a/packages/nx/Cargo.toml +++ b/packages/nx/Cargo.toml @@ -14,6 +14,7 @@ strip = "none" [dependencies] anyhow = "1.0.71" colored = "2" +const_format = "0.2.32" crossbeam-channel = '0.5' dashmap = { version = "5.5.3", features = ["rayon"] } dunce = "1" diff --git a/packages/nx/src/command-line/report/report.ts b/packages/nx/src/command-line/report/report.ts index 1f1703c780daf..cbd348128c5ad 100644 --- a/packages/nx/src/command-line/report/report.ts +++ b/packages/nx/src/command-line/report/report.ts @@ -64,14 +64,19 @@ export async function reportHandler() { packageVersionsWeCareAbout, outOfSyncPackageGroup, projectGraphError, + nativeTarget, } = await getReportData(); - const bodyLines = [ - `Node : ${process.versions.node}`, - `OS : ${process.platform}-${process.arch}`, - `${pm.padEnd(7)}: ${pmVersion}`, - ``, + const fields = [ + ['Node', process.versions.node], + ['OS', `${process.platform}-${process.arch}`], + ['NATIVE TARGET', nativeTarget ?? 'Unavailable'], + [pm, pmVersion], ]; + const maxFieldLength = Math.max(...fields.map((f) => f[0].length)); + const bodyLines = fields.map( + ([field, value]) => `${field.padEnd(maxFieldLength)} : ${value}` + ); let padding = Math.max(...packageVersionsWeCareAbout.map((x) => x.package.length)) + 1; @@ -156,6 +161,7 @@ export interface ReportData { migrateTarget: string; }; projectGraphError?: Error | null; + nativeTarget: string | null; } export async function getReportData(): Promise { @@ -183,6 +189,8 @@ export async function getReportData(): Promise { const outOfSyncPackageGroup = findMisalignedPackagesForPackage(nxPackageJson); + const native = isNativeAvailable(); + return { pm, pmVersion, @@ -192,6 +200,7 @@ export async function getReportData(): Promise { packageVersionsWeCareAbout, outOfSyncPackageGroup, projectGraphError, + nativeTarget: native ? native.getBinaryTarget() : null, }; } @@ -351,10 +360,9 @@ export function findInstalledPackagesWeCareAbout() { })); } -function isNativeAvailable() { +function isNativeAvailable(): typeof import('../../native') | false { try { - require('../../native'); - return true; + return require('../../native'); } catch { return false; } diff --git a/packages/nx/src/native/index.d.ts b/packages/nx/src/native/index.d.ts index 828f54fb9c8fd..1e1575490411d 100644 --- a/packages/nx/src/native/index.d.ts +++ b/packages/nx/src/native/index.d.ts @@ -116,6 +116,8 @@ export interface FileSetInput { export declare export function findImports(projectFileMap: Record>): Array +export declare export function getBinaryTarget(): string + /** * Expands the given outputs into a list of existing files. * This is used when hashing outputs diff --git a/packages/nx/src/native/metadata.rs b/packages/nx/src/native/metadata.rs new file mode 100644 index 0000000000000..6b0b3b0ceeb65 --- /dev/null +++ b/packages/nx/src/native/metadata.rs @@ -0,0 +1,30 @@ +#[napi] +#[cfg(target_arch = "wasm32")] +pub const IS_WASM: bool = true; + +#[napi] +#[cfg(not(target_arch = "wasm32"))] +pub const IS_WASM: bool = false; + +use std::env::consts; + +#[napi] +pub fn get_binary_target() -> String { + let arch = consts::ARCH; + let os = consts::OS; + + let mut binary_target = String::new(); + + if !arch.is_empty() { + binary_target.push_str(&arch); + } + + if !os.is_empty() { + if !binary_target.is_empty() { + binary_target.push('-'); + } + binary_target.push_str(&os); + } + + binary_target +} diff --git a/packages/nx/src/native/mod.rs b/packages/nx/src/native/mod.rs index d0ccd186ae3e9..49e8482edb4d7 100644 --- a/packages/nx/src/native/mod.rs +++ b/packages/nx/src/native/mod.rs @@ -2,16 +2,16 @@ pub mod cache; pub mod glob; pub mod hasher; mod logger; +pub mod metadata; pub mod plugins; pub mod project_graph; -#[cfg(not(target_arch = "wasm32"))] -pub mod pseudo_terminal; pub mod tasks; mod types; mod utils; mod walker; -#[cfg(not(target_arch = "wasm32"))] -pub mod watch; pub mod workspace; -pub mod wasm; +#[cfg(not(target_arch = "wasm32"))] +pub mod pseudo_terminal; +#[cfg(not(target_arch = "wasm32"))] +pub mod watch; diff --git a/packages/nx/src/native/native-bindings.js b/packages/nx/src/native/native-bindings.js index 5d7cd477077d3..9c34dc6eefb7a 100644 --- a/packages/nx/src/native/native-bindings.js +++ b/packages/nx/src/native/native-bindings.js @@ -372,6 +372,7 @@ module.exports.copy = nativeBinding.copy module.exports.EventType = nativeBinding.EventType module.exports.expandOutputs = nativeBinding.expandOutputs module.exports.findImports = nativeBinding.findImports +module.exports.getBinaryTarget = nativeBinding.getBinaryTarget module.exports.getFilesForOutputs = nativeBinding.getFilesForOutputs module.exports.hashArray = nativeBinding.hashArray module.exports.hashFile = nativeBinding.hashFile diff --git a/packages/nx/src/native/utils/mod.rs b/packages/nx/src/native/utils/mod.rs index 618c081745aa5..f537bc14cba83 100644 --- a/packages/nx/src/native/utils/mod.rs +++ b/packages/nx/src/native/utils/mod.rs @@ -7,7 +7,6 @@ pub use find_matching_projects::*; pub use get_mod_time::*; pub use normalize_trait::Normalize; - #[cfg_attr(not(target_arch = "wasm32"), path = "atomics/default.rs")] #[cfg_attr(target_arch = "wasm32", path = "atomics/wasm.rs")] pub mod atomics; diff --git a/packages/nx/src/native/wasm.rs b/packages/nx/src/native/wasm.rs deleted file mode 100644 index d7686c23acf10..0000000000000 --- a/packages/nx/src/native/wasm.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[napi] -#[cfg(target_arch = "wasm32")] -pub const IS_WASM: bool = true; - -#[napi] -#[cfg(not(target_arch = "wasm32"))] -pub const IS_WASM: bool = false;