Skip to content

Commit 16f6e64

Browse files
committed
Merge branch 'main' of github.com:dougg0k/react-native-node-api into generate-project
2 parents c386a0c + a7cc35a commit 16f6e64

File tree

15 files changed

+705
-4199
lines changed

15 files changed

+705
-4199
lines changed

.changeset/kind-forks-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": patch
3+
---
4+
5+
Added implementation of napi_fatal_error, napi_get_node_version and napi_get_version. Improved the Logger functionalities

.changeset/strong-eggs-yell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@react-native-node-api/ferric-example": patch
3+
"ferric-cli": patch
4+
---
5+
6+
Updated napi packages.

.github/workflows/check.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ jobs:
132132
- name: Build weak-node-api for all architectures
133133
run: npm run build-weak-node-api -- --android
134134
working-directory: packages/host
135-
- name: Build ferric-example for all architectures
136-
run: npm run build -- --android
137-
working-directory: packages/ferric-example
138135
- name: Run tests (Android)
139136
timeout-minutes: 75
140137
uses: reactivecircus/android-emulator-runner@v2

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ node_modules/
44
dist/
55

66
*.tsbuildinfo
7-
8-
TODO.md

apps/test-app/App.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ function loadTests({
4444
});
4545
}
4646
});
47-
48-
describeIf(ferricExample, "ferric-example", () => {
49-
it("exports a callable sum function", () => {
50-
const exampleAddon = require("ferric-example");
51-
const result = exampleAddon.sum(1, 3);
52-
if (result !== 4) {
53-
throw new Error(`Expected 1 + 3 to equal 4, but got ${result}`);
54-
}
55-
});
56-
});
5747
}
5848

5949
export default function App() {

apps/test-app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"@types/mocha": "^10.0.10",
3131
"@types/react": "^19.0.0",
3232
"concurrently": "^9.1.2",
33-
"ferric-example": "^0.1.0",
3433
"mocha": "^11.6.0",
3534
"mocha-remote-cli": "^1.13.2",
3635
"mocha-remote-react-native": "^1.13.2",

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"packages/cmake-rn",
1010
"packages/ferric",
1111
"packages/host",
12-
"packages/node-addon-examples",
13-
"packages/ferric-example"
12+
"packages/node-addon-examples"
1413
],
1514
"homepage": "https://github.com/callstackincubator/react-native-node-api#readme",
1615
"scripts": {

packages/ferric/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {
2020
"@commander-js/extra-typings": "14.0.0",
21-
"@napi-rs/cli": "3.0.4",
21+
"@napi-rs/cli": "~3.0.4",
2222
"bufout": "0.3.4",
2323
"chalk": "^5.4.1",
2424
"commander": "14.0.0",

packages/host/cpp/Logger.cpp

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,77 @@
99
#include <TargetConditionals.h>
1010
#endif
1111

12-
namespace callstack::nodeapihost {
13-
void log_debug(const char *format, ...) {
14-
// TODO: Disable logging in release builds
12+
namespace {
13+
constexpr auto LineFormat = "[%s] [NodeApiHost] ";
1514

16-
va_list args;
17-
va_start(args, format);
15+
enum class LogLevel { Debug, Warning, Error };
16+
17+
constexpr std::string_view levelToString(LogLevel level) {
18+
switch (level) {
19+
case LogLevel::Debug:
20+
return "DEBUG";
21+
case LogLevel::Warning:
22+
return "WARNING";
23+
case LogLevel::Error:
24+
return "ERROR";
25+
default:
26+
return "UNKNOWN";
27+
}
28+
}
1829

1930
#if defined(__ANDROID__)
20-
__android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, args);
31+
constexpr int androidLogLevel(LogLevel level) {
32+
switch (level) {
33+
case LogLevel::Debug:
34+
return ANDROID_LOG_DEBUG;
35+
case LogLevel::Warning:
36+
return ANDROID_LOG_WARN;
37+
case LogLevel::Error:
38+
return ANDROID_LOG_ERROR;
39+
default:
40+
return ANDROID_LOG_UNKNOWN;
41+
}
42+
}
43+
#endif
44+
45+
void log_message_internal(LogLevel level, const char* format, va_list args) {
46+
#if defined(__ANDROID__)
47+
__android_log_vprint(androidLogLevel(level), LOG_TAG, format, args);
2148
#elif defined(__APPLE__)
2249
// iOS or macOS
23-
fprintf(stderr, "[NodeApiHost] ");
50+
const auto level_str = levelToString(level);
51+
fprintf(stderr, LineFormat, level_str.data());
2452
vfprintf(stderr, format, args);
2553
fprintf(stderr, "\n");
2654
#else
2755
// Fallback for other platforms
28-
fprintf(stdout, "[NodeApiHost] ");
56+
const auto level_str = levelToString(level);
57+
fprintf(stdout, LineFormat, level_str.data());
2958
vfprintf(stdout, format, args);
3059
fprintf(stdout, "\n");
3160
#endif
61+
}
62+
} // anonymous namespace
63+
64+
namespace callstack::nodeapihost {
3265

66+
void log_debug(const char* format, ...) {
67+
// TODO: Disable logging in release builds
68+
va_list args;
69+
va_start(args, format);
70+
log_message_internal(LogLevel::Debug, format, args);
71+
va_end(args);
72+
}
73+
void log_warning(const char* format, ...) {
74+
va_list args;
75+
va_start(args, format);
76+
log_message_internal(LogLevel::Warning, format, args);
77+
va_end(args);
78+
}
79+
void log_error(const char* format, ...) {
80+
va_list args;
81+
va_start(args, format);
82+
log_message_internal(LogLevel::Error, format, args);
3383
va_end(args);
3484
}
35-
} // namespace callstack::nodeapihost
85+
} // namespace callstack::nodeapihost

0 commit comments

Comments
 (0)