Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to blacklist specific node_modules of my package's dependencies in react-native's packager?

I'm putting together a streamlined development process with react and react-native that:

  • encourages packages,
  • uses babel to transform es6 to js (it compiles before publishing/installing),
  • has a playground that let's you play with both native and web components.

The web part of it is perfectly fine. It's the native one that's causing issues and it has to do with react-native's packager.

The bottom line is: if the package is either linked through npm link or required directly from the playground as in require('../../') react-native's dependency resolver will go forever trying to identify dependencies inside my package's node_modules, most times it never finishes doing it.

The temporary solution I've found is to install the package in playground but this involves re-installing it every time I do an update, which isn't great because you can't see your changes right away (even if it would be automated, it would take time).

I believe that a better solution would be to ask the dependency resolver to ignore those specific modules I don't need (those in devDependencies mainly!). I tried mangling react-native/packager/blacklist.js by adding paths to that list and even putting checks against the dependency resolver but none of that would work.

Can someone with more experience with the packager give me a hint as to how I'd go about making the dependency resolver pass? Alternatively, it would be great if the packager could be separated and the transform process left to choice but I don't know if that would be doable either.

like image 396
Darío Javier Cravero Avatar asked May 05 '15 09:05

Darío Javier Cravero


1 Answers

I found out the following solution, based on the comment in default.config.js:

* If you need to override any of this functions do so by defining the file
* `rn-cli.config.js` on the root of your project with the functions you need
* to tweak.

Create a rn-cli.config.js in the root of your project with the following contents:

var blacklist = require('react-native/packager/blacklist');

var config = {
  getBlacklistRE(platform) {
    return blacklist([
      /node_modules\/my-package\/excluded-dir\/.*/
    ]);
  }
};

module.exports = config;

The second argument to the blacklist function is an additional list of blacklisted paths, which can be regular expressions. See react-native/packager/blacklist.js for more examples.

like image 117
Albert Avatar answered Oct 31 '22 19:10

Albert