From fe31dc87dbf5500ae6df85f56106d1de5247eb53 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 --- packages/nx/src/command-line/report/report.ts | 28 +++++++++++------ 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 ----- 7 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 packages/nx/src/native/metadata.rs delete mode 100644 packages/nx/src/native/wasm.rs diff --git a/packages/nx/src/command-line/report/report.ts b/packages/nx/src/command-line/report/report.ts index 1f1703c780daf..257f87600595c 100644 --- a/packages/nx/src/command-line/report/report.ts +++ b/packages/nx/src/command-line/report/report.ts @@ -64,16 +64,23 @@ 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], ]; + let padding = Math.max(...fields.map((f) => f[0].length)); + const bodyLines = fields.map( + ([field, value]) => `${field.padEnd(padding)} : ${value}` + ); + + bodyLines.push(''); - let padding = + padding = Math.max(...packageVersionsWeCareAbout.map((x) => x.package.length)) + 1; packageVersionsWeCareAbout.forEach((p) => { bodyLines.push( @@ -156,6 +163,7 @@ export interface ReportData { migrateTarget: string; }; projectGraphError?: Error | null; + nativeTarget: string | null; } export async function getReportData(): Promise { @@ -183,6 +191,8 @@ export async function getReportData(): Promise { const outOfSyncPackageGroup = findMisalignedPackagesForPackage(nxPackageJson); + const native = isNativeAvailable(); + return { pm, pmVersion, @@ -192,6 +202,7 @@ export async function getReportData(): Promise { packageVersionsWeCareAbout, outOfSyncPackageGroup, projectGraphError, + nativeTarget: native ? native.getBinaryTarget() : null, }; } @@ -351,10 +362,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;