Skip to content
Open
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/social-peaches-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-native-node-api": minor
---

Modify Xcode project to add a build phase to the main project app to link Node-API frameworks directly
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/host/bin/react-native-node-api.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
#!/usr/bin/env -S node --enable-source-maps
import "../dist/node/cli/run.js";
2 changes: 2 additions & 0 deletions packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
],
"license": "MIT",
"dependencies": {
"@bacons/xcode": "^1.0.0-alpha.29",
"@expo/plist": "^0.4.7",
"@xmldom/xmldom": "^0.8.11",
"@react-native-node-api/cli-utils": "0.1.4",
"pkg-dir": "^8.0.0",
"read-pkg": "^9.0.1",
Expand Down
24 changes: 1 addition & 23 deletions packages/host/react-native-node-api.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@ require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))

require_relative "./scripts/patch-hermes"

NODE_PATH ||= `which node`.strip
CLI_COMMAND ||= "'#{NODE_PATH}' '#{File.join(__dir__, "dist/node/cli/run.js")}'"
COPY_FRAMEWORKS_COMMAND ||= "#{CLI_COMMAND} link --apple '#{Pod::Config.instance.installation_root}'"

# We need to run this now to ensure the xcframeworks are copied vendored_frameworks are considered
XCFRAMEWORKS_DIR ||= File.join(__dir__, "xcframeworks")
unless defined?(@xcframeworks_copied)
puts "Executing #{COPY_FRAMEWORKS_COMMAND}"
system(COPY_FRAMEWORKS_COMMAND) or raise "Failed to copy xcframeworks"
# Setting a flag to avoid running this command on every require
@xcframeworks_copied = true
end
require_relative "./scripts/patch-xcode-project"

if ENV['RCT_NEW_ARCH_ENABLED'] == '0'
Pod::UI.warn "React Native Node-API doesn't support the legacy architecture (but RCT_NEW_ARCH_ENABLED == '0')"
Expand All @@ -35,16 +23,6 @@ Pod::Spec.new do |s|

s.dependency "weak-node-api"

s.vendored_frameworks = "auto-linked/apple/*.xcframework"
s.script_phase = {
:name => 'Copy Node-API xcframeworks',
:execution_position => :before_compile,
:script => <<-CMD
set -e
#{COPY_FRAMEWORKS_COMMAND}
CMD
}

# Use install_modules_dependencies helper to install the dependencies (requires React Native version >=0.71.0).
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
Expand Down
13 changes: 13 additions & 0 deletions packages/host/scripts/patch-xcode-project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
unless defined?(@exit_hooks_installed)
# Setting a flag to avoid running this command on every require
@exit_hooks_installed = true

NODE_PATH ||= `which node`.strip
CLI_COMMAND ||= "'#{NODE_PATH}' '#{File.join(__dir__, "../dist/node/cli/run.js")}'"
PATCH_XCODE_PROJECT_COMMAND ||= "#{CLI_COMMAND} patch-xcode-project '#{Pod::Config.instance.installation_root}'"

# Using an at_exit hook to ensure the command is executed after the pod install is complete
at_exit do
system(PATCH_XCODE_PROJECT_COMMAND) or raise "Failed to patch the Xcode project"
end
end
19 changes: 2 additions & 17 deletions packages/host/src/node/cli/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

import { getLatestMtime, getLibraryName, MAGIC_FILENAME } from "../path-utils";
import { getLibraryName, MAGIC_FILENAME } from "../path-utils";
import {
getLinkedModuleOutputPath,
LinkModuleResult,
Expand All @@ -17,26 +17,11 @@ const ANDROID_ARCHITECTURES = [
] as const;

export async function linkAndroidDir({
incremental,
modulePath,
naming,
platform,
}: LinkModuleOptions): Promise<LinkModuleResult> {
const libraryName = getLibraryName(modulePath, naming);
const outputPath = getLinkedModuleOutputPath(platform, modulePath, naming);

if (incremental && fs.existsSync(outputPath)) {
const moduleModified = getLatestMtime(modulePath);
const outputModified = getLatestMtime(outputPath);
if (moduleModified < outputModified) {
return {
originalPath: modulePath,
libraryName,
outputPath,
skipped: true,
};
}
}
const outputPath = getLinkedModuleOutputPath("android", modulePath, naming);

await fs.promises.rm(outputPath, { recursive: true, force: true });
await fs.promises.cp(modulePath, outputPath, { recursive: true });
Expand Down
Loading
Loading