From ed6a7552b3cc62b677f1a3e8404b69c12c7525a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 20 Oct 2025 11:29:18 +0200 Subject: [PATCH 1/3] Move prettyPath to cli-utils --- packages/cli-utils/src/index.ts | 1 + packages/cli-utils/src/paths.ts | 8 ++++++++ packages/ferric/src/build.ts | 2 +- packages/gyp-to-cmake/src/cli.ts | 17 ++++++++++++----- packages/host/src/node/cli/hermes.ts | 3 +-- packages/host/src/node/cli/link-modules.ts | 7 +++++-- packages/host/src/node/cli/program.ts | 2 +- packages/host/src/node/index.ts | 2 +- packages/host/src/node/path-utils.ts | 8 +------- 9 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 packages/cli-utils/src/paths.ts diff --git a/packages/cli-utils/src/index.ts b/packages/cli-utils/src/index.ts index bf9232fa..0fa6ff4a 100644 --- a/packages/cli-utils/src/index.ts +++ b/packages/cli-utils/src/index.ts @@ -5,3 +5,4 @@ export * from "bufout"; export * from "./actions.js"; export * from "./errors.js"; +export * from "./paths.js"; diff --git a/packages/cli-utils/src/paths.ts b/packages/cli-utils/src/paths.ts new file mode 100644 index 00000000..6ff8bd2e --- /dev/null +++ b/packages/cli-utils/src/paths.ts @@ -0,0 +1,8 @@ +import chalk from "chalk"; +import path from "node:path"; + +export function prettyPath(p: string) { + return chalk.dim( + path.relative(process.cwd(), p) || chalk.italic("current directory"), + ); +} diff --git a/packages/ferric/src/build.ts b/packages/ferric/src/build.ts index 2bd0bded..791c80c5 100644 --- a/packages/ferric/src/build.ts +++ b/packages/ferric/src/build.ts @@ -8,6 +8,7 @@ import { oraPromise, assertFixable, wrapAction, + prettyPath, } from "@react-native-node-api/cli-utils"; import { @@ -19,7 +20,6 @@ import { createXCframework, createUniversalAppleLibrary, determineLibraryBasename, - prettyPath, } from "react-native-node-api"; import { ensureCargo, build } from "./cargo.js"; diff --git a/packages/gyp-to-cmake/src/cli.ts b/packages/gyp-to-cmake/src/cli.ts index 52d14984..9d289b92 100644 --- a/packages/gyp-to-cmake/src/cli.ts +++ b/packages/gyp-to-cmake/src/cli.ts @@ -1,7 +1,11 @@ import fs from "node:fs"; import path from "node:path"; - -import { Command, wrapAction } from "@react-native-node-api/cli-utils"; +import { + Command, + prettyPath, + wrapAction, + Option, +} from "@react-native-node-api/cli-utils"; import { readBindingFile } from "./gyp.js"; import { @@ -29,15 +33,18 @@ export function transformBindingGypFile( ...restOfOptions }: TransformOptions, ) { - console.log("Transforming", gypPath); - const gyp = readBindingFile(gypPath, disallowUnknownProperties); const parentPath = path.dirname(gypPath); + const cmakeListsPath = path.join(parentPath, "CMakeLists.txt"); + console.log( + `Transforming ${prettyPath(gypPath)} → ${prettyPath(cmakeListsPath)}`, + ); + + const gyp = readBindingFile(gypPath, disallowUnknownProperties); const result = bindingGypToCmakeLists({ gyp, projectName, ...restOfOptions, }); - const cmakeListsPath = path.join(parentPath, "CMakeLists.txt"); fs.writeFileSync(cmakeListsPath, result, "utf-8"); } diff --git a/packages/host/src/node/cli/hermes.ts b/packages/host/src/node/cli/hermes.ts index 817b7524..541a324e 100644 --- a/packages/host/src/node/cli/hermes.ts +++ b/packages/host/src/node/cli/hermes.ts @@ -9,11 +9,10 @@ import { spawn, UsageError, wrapAction, + prettyPath, } from "@react-native-node-api/cli-utils"; import { packageDirectorySync } from "pkg-dir"; -import { prettyPath } from "../path-utils"; - const HOST_PACKAGE_ROOT = path.resolve(__dirname, "../../.."); // FIXME: make this configurable with reasonable fallback before public release const HERMES_GIT_URL = "https://github.com/kraenhansen/hermes.git"; diff --git a/packages/host/src/node/cli/link-modules.ts b/packages/host/src/node/cli/link-modules.ts index 9b44d921..8b3bf2e0 100644 --- a/packages/host/src/node/cli/link-modules.ts +++ b/packages/host/src/node/cli/link-modules.ts @@ -1,7 +1,11 @@ import path from "node:path"; import fs from "node:fs"; -import { chalk, SpawnFailure } from "@react-native-node-api/cli-utils"; +import { + chalk, + SpawnFailure, + prettyPath, +} from "@react-native-node-api/cli-utils"; import { findNodeApiModulePathsByDependency, @@ -10,7 +14,6 @@ import { logModulePaths, NamingStrategy, PlatformName, - prettyPath, } from "../path-utils"; export type ModuleLinker = ( diff --git a/packages/host/src/node/cli/program.ts b/packages/host/src/node/cli/program.ts index 37950d6d..cba9994a 100644 --- a/packages/host/src/node/cli/program.ts +++ b/packages/host/src/node/cli/program.ts @@ -8,6 +8,7 @@ import { SpawnFailure, oraPromise, wrapAction, + prettyPath, } from "@react-native-node-api/cli-utils"; import { @@ -19,7 +20,6 @@ import { normalizeModulePath, PlatformName, PLATFORMS, - prettyPath, } from "../path-utils"; import { command as vendorHermes } from "./hermes"; diff --git a/packages/host/src/node/index.ts b/packages/host/src/node/index.ts index 878eeb01..dd914402 100644 --- a/packages/host/src/node/index.ts +++ b/packages/host/src/node/index.ts @@ -22,6 +22,6 @@ export { determineXCFrameworkFilename, } from "./prebuilds/apple.js"; -export { determineLibraryBasename, prettyPath } from "./path-utils.js"; +export { determineLibraryBasename } from "./path-utils.js"; export { weakNodeApiPath } from "./weak-node-api.js"; diff --git a/packages/host/src/node/path-utils.ts b/packages/host/src/node/path-utils.ts index 1fe6170e..9ac1da93 100644 --- a/packages/host/src/node/path-utils.ts +++ b/packages/host/src/node/path-utils.ts @@ -5,7 +5,7 @@ import { packageDirectorySync } from "pkg-dir"; import { readPackageSync } from "read-pkg"; import { createRequire } from "node:module"; -import { chalk } from "@react-native-node-api/cli-utils"; +import { chalk, prettyPath } from "@react-native-node-api/cli-utils"; import { findDuplicates } from "./duplicates"; @@ -194,12 +194,6 @@ export function getLibraryName(modulePath: string, naming: NamingStrategy) { )}`; } -export function prettyPath(p: string) { - return chalk.dim( - path.relative(process.cwd(), p) || chalk.italic("current directory"), - ); -} - export function resolvePackageRoot( requireFromPackageRoot: NodeJS.Require, packageName: string, From d0af9f84ca014008bab9eeb38c7a5fa592cafce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 21 Oct 2025 11:57:41 +0200 Subject: [PATCH 2/3] Use prettyPath more --- packages/cmake-rn/src/platforms/android.ts | 10 ++++++---- packages/cmake-rn/src/platforms/apple.ts | 10 ++++++---- packages/ferric/src/build.ts | 4 +--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/cmake-rn/src/platforms/android.ts b/packages/cmake-rn/src/platforms/android.ts index dbf9d887..b7b758c3 100644 --- a/packages/cmake-rn/src/platforms/android.ts +++ b/packages/cmake-rn/src/platforms/android.ts @@ -2,7 +2,11 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; -import { Option, oraPromise, chalk } from "@react-native-node-api/cli-utils"; +import { + Option, + oraPromise, + prettyPath, +} from "@react-native-node-api/cli-utils"; import { createAndroidLibsDirectory, AndroidTriplet as Triplet, @@ -177,9 +181,7 @@ export const platform: Platform = { }), { text: `Assembling Android libs directory (${libraryName})`, - successText: `Android libs directory (${libraryName}) assembled into ${chalk.dim( - path.relative(process.cwd(), prebuildOutputPath), - )}`, + successText: `Android libs directory (${libraryName}) assembled into ${prettyPath(prebuildOutputPath)}`, failText: ({ message }) => `Failed to assemble Android libs directory (${libraryName}): ${message}`, }, diff --git a/packages/cmake-rn/src/platforms/apple.ts b/packages/cmake-rn/src/platforms/apple.ts index 849ccfe5..91f5e7fd 100644 --- a/packages/cmake-rn/src/platforms/apple.ts +++ b/packages/cmake-rn/src/platforms/apple.ts @@ -2,7 +2,11 @@ import assert from "node:assert/strict"; import path from "node:path"; import fs from "node:fs"; -import { Option, oraPromise, chalk } from "@react-native-node-api/cli-utils"; +import { + Option, + oraPromise, + prettyPath, +} from "@react-native-node-api/cli-utils"; import { AppleTriplet as Triplet, createAppleFramework, @@ -187,9 +191,7 @@ export const platform: Platform = { }), { text: `Assembling XCFramework (${libraryName})`, - successText: `XCFramework (${libraryName}) assembled into ${chalk.dim( - path.relative(process.cwd(), xcframeworkOutputPath), - )}`, + successText: `XCFramework (${libraryName}) assembled into ${prettyPath(xcframeworkOutputPath)}`, failText: ({ message }) => `Failed to assemble XCFramework (${libraryName}): ${message}`, }, diff --git a/packages/ferric/src/build.ts b/packages/ferric/src/build.ts index 791c80c5..fdf961e3 100644 --- a/packages/ferric/src/build.ts +++ b/packages/ferric/src/build.ts @@ -258,9 +258,7 @@ export const buildCommand = new Command("build") }), { text: "Assembling XCFramework", - successText: `XCFramework assembled into ${chalk.dim( - path.relative(process.cwd(), xcframeworkOutputPath), - )}`, + successText: `XCFramework assembled into ${prettyPath(xcframeworkOutputPath)}`, failText: ({ message }) => `Failed to assemble XCFramework: ${message}`, }, From 65f88a3d59dcfbc07d5ef22f73008fea4d30bb78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 21 Oct 2025 11:59:03 +0200 Subject: [PATCH 3/3] Removed unused Option --- packages/gyp-to-cmake/src/cli.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gyp-to-cmake/src/cli.ts b/packages/gyp-to-cmake/src/cli.ts index 9d289b92..1045ba45 100644 --- a/packages/gyp-to-cmake/src/cli.ts +++ b/packages/gyp-to-cmake/src/cli.ts @@ -4,7 +4,6 @@ import { Command, prettyPath, wrapAction, - Option, } from "@react-native-node-api/cli-utils"; import { readBindingFile } from "./gyp.js";