Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "bufout";

export * from "./actions.js";
export * from "./errors.js";
export * from "./paths.js";
8 changes: 8 additions & 0 deletions packages/cli-utils/src/paths.ts
Original file line number Diff line number Diff line change
@@ -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"),
);
}
10 changes: 6 additions & 4 deletions packages/cmake-rn/src/platforms/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -177,9 +181,7 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
}),
{
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}`,
},
Expand Down
10 changes: 6 additions & 4 deletions packages/cmake-rn/src/platforms/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -187,9 +191,7 @@ export const platform: Platform<Triplet[], AppleOpts> = {
}),
{
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}`,
},
Expand Down
6 changes: 2 additions & 4 deletions packages/ferric/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
oraPromise,
assertFixable,
wrapAction,
prettyPath,
} from "@react-native-node-api/cli-utils";

import {
Expand All @@ -19,7 +20,6 @@ import {
createXCframework,
createUniversalAppleLibrary,
determineLibraryBasename,
prettyPath,
} from "react-native-node-api";

import { ensureCargo, build } from "./cargo.js";
Expand Down Expand Up @@ -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}`,
},
Expand Down
16 changes: 11 additions & 5 deletions packages/gyp-to-cmake/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import fs from "node:fs";
import path from "node:path";

import { Command, wrapAction } from "@react-native-node-api/cli-utils";
import {
Command,
prettyPath,
wrapAction,
} from "@react-native-node-api/cli-utils";

import { readBindingFile } from "./gyp.js";
import {
Expand Down Expand Up @@ -29,15 +32,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);
Comment on lines +37 to +41
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cmakeListsPath is now computed before reading the gyp file, but it's only used after the transformation. If readBindingFile throws an error, the user will see the transformation message without any transformation actually being attempted. Consider moving the log statement after readBindingFile to ensure the file can be read before announcing the transformation.

Suggested change
console.log(
`Transforming ${prettyPath(gypPath)}${prettyPath(cmakeListsPath)}`,
);
const gyp = readBindingFile(gypPath, disallowUnknownProperties);
const gyp = readBindingFile(gypPath, disallowUnknownProperties);
console.log(
`Transforming ${prettyPath(gypPath)}${prettyPath(cmakeListsPath)}`,
);

Copilot uses AI. Check for mistakes.
const result = bindingGypToCmakeLists({
gyp,
projectName,
...restOfOptions,
});
const cmakeListsPath = path.join(parentPath, "CMakeLists.txt");
fs.writeFileSync(cmakeListsPath, result, "utf-8");
}

Expand Down
3 changes: 1 addition & 2 deletions packages/host/src/node/cli/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 5 additions & 2 deletions packages/host/src/node/cli/link-modules.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +14,6 @@ import {
logModulePaths,
NamingStrategy,
PlatformName,
prettyPath,
} from "../path-utils";

export type ModuleLinker = (
Expand Down
2 changes: 1 addition & 1 deletion packages/host/src/node/cli/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SpawnFailure,
oraPromise,
wrapAction,
prettyPath,
} from "@react-native-node-api/cli-utils";

import {
Expand All @@ -19,7 +20,6 @@ import {
normalizeModulePath,
PlatformName,
PLATFORMS,
prettyPath,
} from "../path-utils";

import { command as vendorHermes } from "./hermes";
Expand Down
2 changes: 1 addition & 1 deletion packages/host/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 1 addition & 7 deletions packages/host/src/node/path-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
Expand Down
Loading