Skip to content

Commit 2e18c6c

Browse files
committed
Add a podspec to weak-node-api
1 parent 29c0f1c commit 2e18c6c

File tree

6 files changed

+103
-8
lines changed

6 files changed

+103
-8
lines changed

apps/test-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"react": "19.1.0",
4343
"react-native": "0.81.4",
4444
"react-native-node-api": "*",
45-
"react-native-test-app": "^4.4.7"
45+
"react-native-test-app": "^4.4.7",
46+
"weak-node-api": "*"
4647
}
4748
}

package-lock.json

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

packages/host/scripts/generate-weak-node-api-injector.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ const IMPLEMENTED_RUNTIME_FUNCTIONS = [
2828
export function generateSource(functions: FunctionDecl[]) {
2929
return `
3030
// This file is generated by react-native-node-api
31-
#include <Logger.hpp>
3231
#include <dlfcn.h>
3332
#include <weak_node_api.hpp>
33+
34+
#include <Logger.hpp>
3435
#include <RuntimeNodeApi.hpp>
3536
#include <RuntimeNodeApiAsync.hpp>
3637

packages/weak-node-api/package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"!dist/**/*.test.d.ts",
1616
"!dist/**/*.test.d.ts.map",
1717
"include",
18-
"weak-node-api/**",
19-
"!weak-node-api/build/"
18+
"build/Release",
19+
"*.podspec",
20+
"*.cmake"
2021
],
2122
"scripts": {
2223
"build": "tsc --build",
@@ -45,6 +46,17 @@
4546
"buildtools",
4647
"cmake"
4748
],
49+
"author": {
50+
"name": "Callstack",
51+
"url": "https://github.com/callstackincubator"
52+
},
53+
"contributors": [
54+
{
55+
"name": "Kræn Hansen",
56+
"url": "https://github.com/kraenhansen"
57+
}
58+
],
59+
"license": "MIT",
4860
"devDependencies": {
4961
"node-api-headers": "^1.5.0",
5062
"zod": "^4.1.11"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import assert from "node:assert/strict";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
5+
async function restoreVersionedFrameworkSymlinks(frameworkPath: string) {
6+
const currentLinkPath = path.join(frameworkPath, "Versions", "Current");
7+
8+
if (!fs.existsSync(currentLinkPath)) {
9+
await fs.promises.symlink("A", currentLinkPath);
10+
}
11+
12+
const binaryLinkPath = path.join(frameworkPath, "weak-node-api");
13+
14+
if (!fs.existsSync(binaryLinkPath)) {
15+
await fs.promises.symlink("Versions/Current/weak-node-api", binaryLinkPath);
16+
}
17+
18+
const resourcesLinkPath = path.join(frameworkPath, "Resources");
19+
20+
if (!fs.existsSync(resourcesLinkPath)) {
21+
await fs.promises.symlink("Versions/Current/Resources", resourcesLinkPath);
22+
}
23+
}
24+
25+
if (process.platform === "darwin") {
26+
const xcframeworkPath = path.join(
27+
import.meta.dirname,
28+
"..",
29+
"build",
30+
"Release",
31+
"weak-node-api.xcframework",
32+
);
33+
34+
assert(
35+
fs.existsSync(xcframeworkPath),
36+
`Expected an Xcframework at ${xcframeworkPath}`,
37+
);
38+
39+
const macosFrameworkPath = path.join(
40+
xcframeworkPath,
41+
"macos-arm64_x86_64",
42+
"weak-node-api.framework",
43+
);
44+
45+
if (fs.existsSync(macosFrameworkPath)) {
46+
await restoreVersionedFrameworkSymlinks(macosFrameworkPath);
47+
}
48+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "json"
2+
3+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4+
5+
# We need to restore symlinks in the versioned framework directories,
6+
# as these are not preserved when in the archive uploaded to NPM
7+
unless defined?(@restored)
8+
RESTORE_COMMAND = "node '#{File.join(__dir__, "dist/restore-xcframework-symlinks.js")}'"
9+
Pod::UI.info("[weak-node-api] ".green + "Restoring symbolic links in Xcframework")
10+
system(RESTORE_COMMAND) or raise "Failed to restore symlinks in Xcframework"
11+
# Setting a flag to avoid running this command on every require
12+
@restored = true
13+
end
14+
15+
Pod::Spec.new do |s|
16+
s.name = package["name"]
17+
s.version = package["version"]
18+
s.summary = package["description"]
19+
s.homepage = package["homepage"]
20+
s.license = package["license"]
21+
s.authors = package["author"]
22+
23+
s.source = { :git => "https://github.com/callstackincubator/react-native-node-api.git", :tag => "#{s.version}" }
24+
25+
s.source_files = "generated/*.{hpp,cpp}", "include/*.h"
26+
s.public_header_files = "generated/*.hpp", "include/*.h"
27+
28+
s.vendored_frameworks = "build/Release/weak-node-api.xcframework"
29+
30+
# Avoiding the header dir to allow for idiomatic Node-API includes
31+
s.header_dir = nil
32+
end

0 commit comments

Comments
 (0)