Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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.

3 changes: 3 additions & 0 deletions packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"include",
"babel-plugin.js",
"scripts/patch-hermes.rb",
"scripts/patch-xcode-project.rb",
"weak-node-api/**",
"!weak-node-api/build/",
"*.js",
Expand Down Expand Up @@ -67,7 +68,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
}
Comment on lines -38 to -46
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is one of the most important changes of the PR - we no longer have to reference the addon xcframeworks from our podspec.


# 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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expo conventionally uses NODE_BINARY in ios/.xcode.env. Should we follow that convention?

And they evaluate it as:

export NODE_BINARY=$(command -v node)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agree, this seems like a good thing to align on 👍

  • Rename NODE_PATH to NODE_BINARY here in the local code
  • Read NODE_BINARY from environment if available
  • Call command -v node as a fallback

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Pushed 4be7486 with a fix for this 👍

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