Skip to content

Commit 8b508ae

Browse files
committed
Use CMake file API to read shared library target paths
1 parent 58d17e6 commit 8b508ae

File tree

8 files changed

+540
-49
lines changed

8 files changed

+540
-49
lines changed

.changeset/evil-vans-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cmake-rn": patch
3+
---
4+
5+
Use CMake file API to read shared library target paths

package-lock.json

Lines changed: 17 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cmake-rn/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
},
2424
"dependencies": {
2525
"@react-native-node-api/cli-utils": "0.1.0",
26-
"react-native-node-api": "0.5.1"
26+
"react-native-node-api": "0.5.1",
27+
"zod": "^4.1.11"
2728
},
2829
"peerDependencies": {
2930
"node-addon-api": "^8.3.1",

packages/cmake-rn/src/cli.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
platformHasTriplet,
2626
} from "./platforms.js";
2727
import { BaseOpts, TripletContext, Platform } from "./platforms/types.js";
28+
import * as cmakeFileApi from "./cmake-file-api.js";
2829

2930
// We're attaching a lot of listeners when spawning in parallel
3031
EventEmitter.defaultMaxListeners = 100;
@@ -327,6 +328,8 @@ async function configureProject<T extends string>(
327328
{ CMAKE_LIBRARY_OUTPUT_DIRECTORY: outputPath },
328329
];
329330

331+
await cmakeFileApi.createQuery(buildPath, "codemodel", "2");
332+
330333
await spawn(
331334
"cmake",
332335
[
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import assert from "node:assert/strict";
2+
import fs from "node:fs";
3+
import os from "node:os";
4+
import path from "node:path";
5+
import { after, before, describe, it } from "node:test";
6+
7+
import { findCurrentReplyIndexPath } from "./cmake-file-api.js";
8+
9+
function createMockReplyDirectory(
10+
replyFiles: [string, Record<string, unknown>][],
11+
) {
12+
const tmpPath = fs.mkdtempSync(path.join(os.tmpdir(), "test-"));
13+
14+
before(() => {
15+
for (const [fileName, content] of replyFiles) {
16+
const filePath = path.join(tmpPath, fileName);
17+
fs.writeFileSync(filePath, JSON.stringify(content), {
18+
encoding: "utf-8",
19+
});
20+
}
21+
});
22+
23+
after(() => {
24+
fs.rmSync(tmpPath, { recursive: true, force: true });
25+
});
26+
27+
return tmpPath;
28+
}
29+
30+
describe("findCurrentReplyIndexPath", () => {
31+
it("returns the correct path when only index files are present", async () => {
32+
const tmpPath = createMockReplyDirectory([
33+
["index-a.json", {}],
34+
["index-b.json", {}],
35+
]);
36+
const result = await findCurrentReplyIndexPath(tmpPath);
37+
assert.strictEqual(result, path.join(tmpPath, "index-b.json"));
38+
});
39+
it("returns the correct path when only error files are present", async () => {
40+
const tmpPath = createMockReplyDirectory([
41+
["error-a.json", {}],
42+
["error-b.json", {}],
43+
]);
44+
const result = await findCurrentReplyIndexPath(tmpPath);
45+
assert.strictEqual(result, path.join(tmpPath, "error-b.json"));
46+
});
47+
it("returns the correct path when both index and error files are present", async () => {
48+
const tmpPath = createMockReplyDirectory([
49+
["index-a.json", {}],
50+
["error-b.json", {}],
51+
]);
52+
const result = await findCurrentReplyIndexPath(tmpPath);
53+
assert.strictEqual(result, path.join(tmpPath, "error-b.json"));
54+
});
55+
it("returns the correct path when both index and error files are present (reversed)", async () => {
56+
const tmpPath = createMockReplyDirectory([
57+
["error-a.json", {}],
58+
["index-b.json", {}],
59+
]);
60+
const result = await findCurrentReplyIndexPath(tmpPath);
61+
assert.strictEqual(result, path.join(tmpPath, "index-b.json"));
62+
});
63+
});

0 commit comments

Comments
 (0)