Skip to content

Commit 2357b5a

Browse files
authored
fix: react-native-worklets-core module resolution for pnpm (#3088)
* Fix react-native-worklets-core resolution * Handle react-native-worklets-core module not found error * Silenced nodejs error, when react-native-worklets-core package not found
1 parent b3f5ab6 commit 2357b5a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

package/VisionCamera.podspec

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ require "json"
22

33
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
44

5-
nodeModules = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
6-
75
Pod::UI.puts "[VisionCamera] Thank you for using VisionCamera ❤️"
86
Pod::UI.puts "[VisionCamera] If you enjoy using VisionCamera, please consider sponsoring this project: https://github.com/sponsors/mrousavy"
97

@@ -23,11 +21,20 @@ else
2321
Pod::UI.puts "[VisionCamera] $VCEnableFrameProcessors is not set, enabling Frame Processors if Worklets is installed..."
2422
end
2523

26-
Pod::UI.puts("[VisionCamera] node modules #{Dir.exist?(nodeModules) ? "found at #{nodeModules}" : "not found!"}")
27-
workletsPath = File.join(nodeModules, "react-native-worklets-core")
28-
hasWorklets = File.exist?(workletsPath)
24+
def Pod::getWorkletsLibraryPath
25+
output = `cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "try { require.resolve('react-native-worklets-core/package.json') } catch(e) { /* returning undefined, if package not found */ }"`
26+
27+
if output.strip == "undefined"
28+
return nil
29+
else
30+
return File.dirname(output)
31+
end
32+
end
33+
34+
workletsPath = getWorkletsLibraryPath()
35+
hasWorklets = workletsPath != nil && File.exist?(workletsPath)
2936
if hasWorklets
30-
Pod::UI.puts("[VisionCamera] react-native-worklets-core found, Frame Processors are #{enableFrameProcessors ? "enabled" : "disabled"}!")
37+
Pod::UI.puts("[VisionCamera] react-native-worklets-core found at #{workletsPath}, Frame Processors are #{enableFrameProcessors ? "enabled" : "disabled"}!")
3138
else
3239
Pod::UI.puts("[VisionCamera] react-native-worklets-core not found - Frame Processors are disabled!")
3340
enableFrameProcessors = false

0 commit comments

Comments
 (0)