Allow excluding custom native modules with the `exclude` option for autolinking.
B
Bo Bramer
Right now, I can manually add a native directory for autolinking using the
expo.nativeModulesDir
entry in package.json
. However, this autolinks every module in the directory. There is normally an option (for expo modules only) to exclude modules using the expo.exclude
entry in package.json
.Based on this code, it seems that this is arbitrarily not allowed for custom native modules. (https://github.com/expo/expo/blob/main/packages/expo-modules-autolinking/src/autolinking/findModules.ts#L54-L60) This means that there is no way currently to selectively prevent custom native modules from being included, as
react-native.config.js
is not respected by expo autolinking.Wade Wilkey
This is particularly useful/necessary for monorepo setups. I have a common modules directory with my custom native modules, however not every app uses every module. I'm currently using this workaround with patch-package
diff --git a/node_modules/expo-modules-autolinking/build/autolinking/findModules.js b/node_modules/expo-modules-autolinking/build/autolinking/findModules.js
index b974691..bb7676e 100644
--- a/node_modules/expo-modules-autolinking/build/autolinking/findModules.js
+++ b/node_modules/expo-modules-autolinking/build/autolinking/findModules.js
@@ -39,8 +39,8 @@ async function findModulesAsync(providedOptions) {
if (maybeIsolatedModulesPath) {
searchPaths.add(maybeIsolatedModulesPath);
}
- // we ignore the `exclude` option for custom native modules
- if ((!isNativeModulesDir && options.exclude?.includes(name)) ||
+ // apply exclude options to both custom native modules and regular modules
+ if ((options.exclude?.includes(name)) ||
!expoModuleConfig.supportsPlatform(options.platform)) {
continue;
}