I want to share components of one app with the other and therefore moved them to a separate NPM package. The structure of this package looks like this:
- src
--- components
----- component A
----- component B
- package.json
Some components use other 3rd party libraries and they are listed in the package.json
.
Now when installing that shared package to the second project these 3rd party dependencies are not auto linked. For example, when calling pod install
they're not installed.
Is it possible somehow install these 3rd party dependencies?
We can patch function findDependencies in @react-native-community/cli as follow to enable auto link dependencies of dependency
function findDependencies(root) {
let pjson;
try {
pjson = JSON.parse(_fs().default.readFileSync(_path().default.join(root, 'package.json'), 'UTF-8'));
} catch (e) {
return [];
}
const dependencies = Object.keys(pjson.dependencies || []);
const subDeps = dependencies.reduce(function(accumulator, currentValue) {
if (!currentValue.includes('your_dependency')) {
return accumulator;
}
const subRoot = `${root}/node_modules/${currentValue}`;
return accumulator.concat(findDependencies(subRoot));
}, []);
const deps = [...Object.keys(pjson.dependencies || {}), ...Object.keys(pjson.devDependencies || {}), ...subDeps];
return deps;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With