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
5 changes: 5 additions & 0 deletions .changeset/slimy-parts-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"weak-node-api": minor
---

Renamed WeakNodeApiHost to NodeApiHost
8 changes: 4 additions & 4 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- run: npm ci
- run: npm run build
- name: Prepare weak-node-api
run: npm run prepare-weak-node-api --workspace weak-node-api
run: npm run prebuild:prepare --workspace weak-node-api
- name: Build and run weak-node-api C++ tests
run: |
cmake -S . -B build -DBUILD_TESTS=ON
Expand Down Expand Up @@ -215,7 +215,7 @@ jobs:
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Build weak-node-api for all Android architectures
run: npm run build-weak-node-api:android --workspace weak-node-api
run: npm run prebuild:build:android --workspace weak-node-api
- name: Build ferric-example for all architectures
run: npm run build -- --android
working-directory: packages/ferric-example
Expand Down Expand Up @@ -270,8 +270,8 @@ jobs:
- run: npm run build
- name: Build weak-node-api for all Apple architectures
run: |
npm run prepare-weak-node-api --workspace weak-node-api
npm run build-weak-node-api:apple --workspace weak-node-api
npm run prebuild:prepare --workspace weak-node-api
npm run prebuild:build:apple --workspace weak-node-api
# Build Ferric example for all Apple architectures
- run: npx ferric --apple
working-directory: packages/ferric-example
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"prettier:write": "prettier --experimental-cli --write .",
"test": "npm test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples",
"bootstrap": "node --run build && npm run bootstrap --workspaces --if-present",
"prerelease": "node --run build && npm run prerelease --workspaces --if-present",
"changeset": "changeset",
"release": "changeset publish",
"init-macos-test-app": "node scripts/init-macos-test-app.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/host/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def supportsNamespace() {

android {
if (supportsNamespace()) {
namespace "com.callstack.node_api_modules"
namespace "com.callstack.react_native_node_api"

sourceSets {
main {
Expand Down
2 changes: 1 addition & 1 deletion packages/host/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.callstack.node_api_modules">
package="com.callstack.react_native_node_api">
</manifest>
8 changes: 4 additions & 4 deletions packages/host/android/src/main/cpp/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

// Called when the library is loaded
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
callstack::nodeapihost::injectIntoWeakNodeApi();
callstack::react_native_node_api::injectIntoWeakNodeApi();
// Register the C++ TurboModule
facebook::react::registerCxxModuleToGlobalModuleMap(
callstack::nodeapihost::CxxNodeApiHostModule::kModuleName,
callstack::react_native_node_api::CxxNodeApiHostModule::kModuleName,
[](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<callstack::nodeapihost::CxxNodeApiHostModule>(
jsInvoker);
return std::make_shared<
callstack::react_native_node_api::CxxNodeApiHostModule>(jsInvoker);
});
return JNI_VERSION_1_6;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.callstack.node_api_modules
package com.callstack.react_native_node_api

import com.facebook.hermes.reactexecutor.HermesExecutor
import com.facebook.react.BaseReactPackage
Expand All @@ -10,7 +10,7 @@ import com.facebook.soloader.SoLoader

import java.util.HashMap

class NodeApiModulesPackage : BaseReactPackage() {
class NodeApiHostPackage : BaseReactPackage() {
init {
SoLoader.loadLibrary("node-api-host")
}
Expand Down
12 changes: 6 additions & 6 deletions packages/host/apple/NodeApiHostModuleProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#import "WeakNodeApiInjector.hpp"

#import <ReactCommon/CxxTurboModuleUtils.h>
@interface NodeApiHost : NSObject
@interface NodeApiHostPackage : NSObject

@end

@implementation NodeApiHost
@implementation NodeApiHostPackage
+ (void)load {
callstack::nodeapihost::injectIntoWeakNodeApi();
callstack::react_native_node_api::injectIntoWeakNodeApi();

facebook::react::registerCxxModuleToGlobalModuleMap(
callstack::nodeapihost::CxxNodeApiHostModule::kModuleName,
callstack::react_native_node_api::CxxNodeApiHostModule::kModuleName,
[](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<callstack::nodeapihost::CxxNodeApiHostModule>(
jsInvoker);
return std::make_shared<
callstack::react_native_node_api::CxxNodeApiHostModule>(jsInvoker);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/host/cpp/AddonLoaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <dlfcn.h>
#include <stdio.h>

using callstack::nodeapihost::log_debug;
using callstack::react_native_node_api::log_debug;

struct PosixLoader {
using Module = void *;
Expand Down
6 changes: 3 additions & 3 deletions packages/host/cpp/CxxNodeApiHostModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace facebook;

namespace callstack::nodeapihost {
namespace callstack::react_native_node_api {

CxxNodeApiHostModule::CxxNodeApiHostModule(
std::shared_ptr<react::CallInvoker> jsInvoker)
Expand Down Expand Up @@ -127,8 +127,8 @@ bool CxxNodeApiHostModule::initializeNodeModule(jsi::Runtime &rt,
napi_set_named_property(env, global, addon.generatedName.data(), exports);
assert(status == napi_ok);

callstack::nodeapihost::setCallInvoker(env, callInvoker_);
callstack::react_native_node_api::setCallInvoker(env, callInvoker_);
return true;
}

} // namespace callstack::nodeapihost
} // namespace callstack::react_native_node_api
4 changes: 2 additions & 2 deletions packages/host/cpp/CxxNodeApiHostModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "AddonLoaders.hpp"

namespace callstack::nodeapihost {
namespace callstack::react_native_node_api {

class JSI_EXPORT CxxNodeApiHostModule : public facebook::react::TurboModule {
public:
Expand Down Expand Up @@ -37,4 +37,4 @@ class JSI_EXPORT CxxNodeApiHostModule : public facebook::react::TurboModule {
bool initializeNodeModule(facebook::jsi::Runtime &rt, NodeAddon &addon);
};

} // namespace callstack::nodeapihost
} // namespace callstack::react_native_node_api
46 changes: 23 additions & 23 deletions packages/host/cpp/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ enum class LogLevel { Debug, Warning, Error };

constexpr std::string_view levelToString(LogLevel level) {
switch (level) {
case LogLevel::Debug:
return "DEBUG";
case LogLevel::Warning:
return "WARNING";
case LogLevel::Error:
return "ERROR";
default:
return "UNKNOWN";
case LogLevel::Debug:
return "DEBUG";
case LogLevel::Warning:
return "WARNING";
case LogLevel::Error:
return "ERROR";
default:
return "UNKNOWN";
}
}

#if defined(__ANDROID__)
constexpr int androidLogLevel(LogLevel level) {
switch (level) {
case LogLevel::Debug:
return ANDROID_LOG_DEBUG;
case LogLevel::Warning:
return ANDROID_LOG_WARN;
case LogLevel::Error:
return ANDROID_LOG_ERROR;
default:
return ANDROID_LOG_UNKNOWN;
case LogLevel::Debug:
return ANDROID_LOG_DEBUG;
case LogLevel::Warning:
return ANDROID_LOG_WARN;
case LogLevel::Error:
return ANDROID_LOG_ERROR;
default:
return ANDROID_LOG_UNKNOWN;
}
}
#endif

void log_message_internal(LogLevel level, const char* format, va_list args) {
void log_message_internal(LogLevel level, const char *format, va_list args) {
#if defined(__ANDROID__)
__android_log_vprint(androidLogLevel(level), LOG_TAG, format, args);
#elif defined(__APPLE__)
Expand All @@ -59,27 +59,27 @@ void log_message_internal(LogLevel level, const char* format, va_list args) {
fprintf(stdout, "\n");
#endif
}
} // anonymous namespace
} // anonymous namespace

namespace callstack::nodeapihost {
namespace callstack::react_native_node_api {

void log_debug(const char* format, ...) {
void log_debug(const char *format, ...) {
// TODO: Disable logging in release builds
va_list args;
va_start(args, format);
log_message_internal(LogLevel::Debug, format, args);
va_end(args);
}
void log_warning(const char* format, ...) {
void log_warning(const char *format, ...) {
va_list args;
va_start(args, format);
log_message_internal(LogLevel::Warning, format, args);
va_end(args);
}
void log_error(const char* format, ...) {
void log_error(const char *format, ...) {
va_list args;
va_start(args, format);
log_message_internal(LogLevel::Error, format, args);
va_end(args);
}
} // namespace callstack::nodeapihost
} // namespace callstack::react_native_node_api
10 changes: 5 additions & 5 deletions packages/host/cpp/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <string>

namespace callstack::nodeapihost {
void log_debug(const char* format, ...);
void log_warning(const char* format, ...);
void log_error(const char* format, ...);
} // namespace callstack::nodeapihost
namespace callstack::react_native_node_api {
void log_debug(const char *format, ...);
void log_warning(const char *format, ...);
void log_error(const char *format, ...);
} // namespace callstack::react_native_node_api
63 changes: 27 additions & 36 deletions packages/host/cpp/RuntimeNodeApi.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "RuntimeNodeApi.hpp"
#include <string>
#include "Logger.hpp"
#include "Versions.hpp"
#include <string>

auto ArrayType = napi_uint8_array;

namespace callstack::nodeapihost {
namespace callstack::react_native_node_api {

napi_status napi_create_buffer(
napi_env env, size_t length, void** data, napi_value* result) {
napi_status napi_create_buffer(napi_env env, size_t length, void **data,
napi_value *result) {
napi_value buffer;
if (const auto status = napi_create_arraybuffer(env, length, data, &buffer);
status != napi_ok) {
Expand All @@ -22,17 +22,15 @@ napi_status napi_create_buffer(
return napi_create_typedarray(env, ArrayType, length, buffer, 0, result);
}

napi_status napi_create_buffer_copy(napi_env env,
size_t length,
const void* data,
void** result_data,
napi_value* result) {
napi_status napi_create_buffer_copy(napi_env env, size_t length,
const void *data, void **result_data,
napi_value *result) {
if (!length || !data || !result) {
return napi_invalid_arg;
}

void *buffer = nullptr;
if (const auto status = callstack::nodeapihost::napi_create_buffer(
if (const auto status = callstack::react_native_node_api::napi_create_buffer(
env, length, &buffer, result);
status != napi_ok) {
return status;
Expand All @@ -42,7 +40,7 @@ napi_status napi_create_buffer_copy(napi_env env,
return napi_ok;
}

napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) {
napi_status napi_is_buffer(napi_env env, napi_value value, bool *result) {
if (!result) {
return napi_invalid_arg;
}
Expand Down Expand Up @@ -77,8 +75,8 @@ napi_status napi_is_buffer(napi_env env, napi_value value, bool* result) {
return napi_ok;
}

napi_status napi_get_buffer_info(
napi_env env, napi_value value, void** data, size_t* length) {
napi_status napi_get_buffer_info(napi_env env, napi_value value, void **data,
size_t *length) {
if (!data || !length) {
return napi_invalid_arg;
}
Expand All @@ -97,19 +95,17 @@ napi_status napi_get_buffer_info(
auto isTypedArray{false};
if (const auto status = napi_is_typedarray(env, value, &isTypedArray);
status == napi_ok && isTypedArray) {
return napi_get_typedarray_info(
env, value, &ArrayType, length, data, nullptr, nullptr);
return napi_get_typedarray_info(env, value, &ArrayType, length, data,
nullptr, nullptr);
}

return napi_ok;
}

napi_status napi_create_external_buffer(napi_env env,
size_t length,
void* data,
node_api_basic_finalize basic_finalize_cb,
void* finalize_hint,
napi_value* result) {
napi_status
napi_create_external_buffer(napi_env env, size_t length, void *data,
node_api_basic_finalize basic_finalize_cb,
void *finalize_hint, napi_value *result) {
napi_value buffer;
if (const auto status = napi_create_external_arraybuffer(
env, data, length, basic_finalize_cb, finalize_hint, &buffer);
Expand All @@ -124,25 +120,20 @@ napi_status napi_create_external_buffer(napi_env env,
return napi_create_typedarray(env, ArrayType, length, buffer, 0, result);
}

void napi_fatal_error(const char* location,
size_t location_len,
const char* message,
size_t message_len) {
void napi_fatal_error(const char *location, size_t location_len,
const char *message, size_t message_len) {
if (location && location_len) {
log_error("Fatal Node-API error: %.*s %.*s",
static_cast<int>(location_len),
location,
static_cast<int>(message_len),
message);
log_error("Fatal Node-API error: %.*s %.*s", static_cast<int>(location_len),
location, static_cast<int>(message_len), message);
} else {
log_error(
"Fatal Node-API error: %.*s", static_cast<int>(message_len), message);
log_error("Fatal Node-API error: %.*s", static_cast<int>(message_len),
message);
}
abort();
}

napi_status napi_get_node_version(
node_api_basic_env env, const napi_node_version** result) {
napi_status napi_get_node_version(node_api_basic_env env,
const napi_node_version **result) {
if (!result) {
return napi_invalid_arg;
}
Expand All @@ -151,7 +142,7 @@ napi_status napi_get_node_version(
return napi_generic_failure;
}

napi_status napi_get_version(node_api_basic_env env, uint32_t* result) {
napi_status napi_get_version(node_api_basic_env env, uint32_t *result) {
if (!result) {
return napi_invalid_arg;
}
Expand All @@ -160,4 +151,4 @@ napi_status napi_get_version(node_api_basic_env env, uint32_t* result) {
return napi_ok;
}

} // namespace callstack::nodeapihost
} // namespace callstack::react_native_node_api
Loading
Loading