Skip to content

Commit ae6ba19

Browse files
author
Mariusz Pasinski
committed
feat: add support for custom package-specific resolvers
1 parent 3e5f57d commit ae6ba19

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

packages/react-native-node-api-modules/cpp/CxxNodeApiHostModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ CxxNodeApiHostModule::requireNodeAddon(jsi::Runtime &rt,
166166
}
167167
}
168168

169+
// Check, if this package has been overridden
170+
if (auto handler = packageOverrides_.find(requiredPackageName); packageOverrides_.end() != handler) {
171+
// This package has a custom resolver, invoke it
172+
return (handler->second)(rt, strippedPath, requiredPackageName, requiredFrom);
173+
}
174+
169175
const std::string &libraryNameStr = strippedPath;
170176
auto [it, inserted] = nodeAddons_.emplace(libraryNameStr, NodeAddon());
171177
NodeAddon &addon = it->second;

packages/react-native-node-api-modules/cpp/CxxNodeApiHostModule.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class JSI_EXPORT CxxNodeApiHostModule : public facebook::react::TurboModule {
4343
};
4444
std::unordered_map<std::string, NodeAddon> nodeAddons_;
4545
std::unordered_map<std::string, ResolverFunc> prefixResolvers_;
46+
std::unordered_map<std::string, ResolverFunc> packageOverrides_;
4647
using LoaderPolicy = PosixLoader; // FIXME: HACK: This is temporary workaround
4748
// for my lazyness (work on iOS and Android)
4849

0 commit comments

Comments
 (0)