Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions local-cli/rnpm/core/src/findPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 findPluginInFolder = (folder) => {
var pjson;
const readPackage = (folder) => {
try {
pjson = require(path.join(folder, 'package.json'));
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) => {
const pjson = readPackage(folder);

if (!pjson) {
return [];
}

Expand All @@ -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;
},
[]
);
};

/**
Expand Down