rn-cli.config.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @noflow
  3. */
  4. const fs = require('fs');
  5. const path = require('path');
  6. const blacklist = require('metro/src/blacklist');
  7. module.exports = {
  8. getBlacklistRE() {
  9. return blacklist([
  10. /react\-navigation\/examples\/(?!ReduxExample).*/,
  11. /react\-navigation\/node_modules\/react-native\/(.*)/,
  12. /react\-navigation\/node_modules\/react\/(.*)/
  13. ]);
  14. },
  15. extraNodeModules: getNodeModulesForDirectory(path.resolve('.')),
  16. };
  17. function getNodeModulesForDirectory(rootPath) {
  18. const nodeModulePath = path.join(rootPath, 'node_modules');
  19. const folders = fs.readdirSync(nodeModulePath);
  20. return folders.reduce((modules, folderName) => {
  21. const folderPath = path.join(nodeModulePath, folderName);
  22. if (folderName.startsWith('@')) {
  23. const scopedModuleFolders = fs.readdirSync(folderPath);
  24. const scopedModules = scopedModuleFolders.reduce(
  25. (scopedModules, scopedFolderName) => {
  26. scopedModules[
  27. `${folderName}/${scopedFolderName}`
  28. ] = maybeResolveSymlink(path.join(folderPath, scopedFolderName));
  29. return scopedModules;
  30. },
  31. {}
  32. );
  33. return Object.assign({}, modules, scopedModules);
  34. }
  35. modules[folderName] = maybeResolveSymlink(folderPath);
  36. return modules;
  37. }, {});
  38. }
  39. function maybeResolveSymlink(maybeSymlinkPath) {
  40. if (fs.lstatSync(maybeSymlinkPath).isSymbolicLink()) {
  41. const resolved = path.resolve(
  42. path.dirname(maybeSymlinkPath),
  43. fs.readlinkSync(maybeSymlinkPath)
  44. );
  45. return resolved;
  46. }
  47. return maybeSymlinkPath;
  48. }