From 4fce8ea4f4435f34fa8e5b5baecc8f11b3cde5c9 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Wed, 3 Aug 2016 01:49:40 -0700 Subject: [PATCH] Fixes #9168 Summary: Imports missing commit from the rnpm master. Closes https://github.com/facebook/react-native/pull/9179 Differential Revision: D3661909 fbshipit-source-id: 23ebd3b96f236ab140f91eb4ed9f456d7c925027 --- local-cli/rnpm/core/src/findPlugins.js | 43 ++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/local-cli/rnpm/core/src/findPlugins.js b/local-cli/rnpm/core/src/findPlugins.js index 95bb2b20d..c07c143a1 100644 --- a/local-cli/rnpm/core/src/findPlugins.js +++ b/local-cli/rnpm/core/src/findPlugins.js @@ -8,13 +8,29 @@ const flatten = require('lodash').flatten; * @param {String} dependency Name of the dependency * @return {Boolean} If dependency is a rnpm plugin */ -const isPlugin = (dependency) => dependency.indexOf('rnpm-plugin-') === 0; +const isRNPMPlugin = (dependency) => dependency.indexOf('rnpm-plugin-') === 0; +const isReactNativePlugin = (dependency) => dependency.indexOf('react-native-') === 0; + +const readPackage = (folder) => { + try { + return require(path.join(folder, 'package.json')); + } catch (e) { + return null; + } +}; + +const findPluginsInReactNativePackage = (pjson) => { + if (!pjson.rnpm || !pjson.rnpm.plugin) { + return []; + } + + return path.join(pjson.name, pjson.rnpm.plugin); +}; const findPluginInFolder = (folder) => { - var pjson; - try { - pjson = require(path.join(folder, 'package.json')); - } catch (e) { + const pjson = readPackage(folder); + + if (!pjson) { return []; } @@ -23,7 +39,22 @@ const findPluginInFolder = (folder) => { Object.keys(pjson.devDependencies || {}) ); - return deps.filter(isPlugin); + return deps.reduce( + (acc, pkg) => { + if (isRNPMPlugin(pkg)) { + return acc.concat(pkg); + } + if (isReactNativePlugin(pkg)) { + const pkgJson = readPackage(path.join(folder, 'node_modules', pkg)); + if (!pkgJson) { + return acc; + } + return acc.concat(findPluginsInReactNativePackage(pkgJson)); + } + return acc; + }, + [] + ); }; /**