Skip to content

Commit 4fce8ea

Browse files
grabbouFacebook Github Bot 4
authored andcommitted
Fixes #9168
Summary: Imports missing commit from the rnpm master. Closes #9179 Differential Revision: D3661909 fbshipit-source-id: 23ebd3b96f236ab140f91eb4ed9f456d7c925027
1 parent cb778aa commit 4fce8ea

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

local-cli/rnpm/core/src/findPlugins.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,29 @@ const flatten = require('lodash').flatten;
88
* @param {String} dependency Name of the dependency
99
* @return {Boolean} If dependency is a rnpm plugin
1010
*/
11-
const isPlugin = (dependency) => dependency.indexOf('rnpm-plugin-') === 0;
11+
const isRNPMPlugin = (dependency) => dependency.indexOf('rnpm-plugin-') === 0;
12+
const isReactNativePlugin = (dependency) => dependency.indexOf('react-native-') === 0;
1213

13-
const findPluginInFolder = (folder) => {
14-
var pjson;
14+
const readPackage = (folder) => {
1515
try {
16-
pjson = require(path.join(folder, 'package.json'));
16+
return require(path.join(folder, 'package.json'));
1717
} catch (e) {
18+
return null;
19+
}
20+
};
21+
22+
const findPluginsInReactNativePackage = (pjson) => {
23+
if (!pjson.rnpm || !pjson.rnpm.plugin) {
24+
return [];
25+
}
26+
27+
return path.join(pjson.name, pjson.rnpm.plugin);
28+
};
29+
30+
const findPluginInFolder = (folder) => {
31+
const pjson = readPackage(folder);
32+
33+
if (!pjson) {
1834
return [];
1935
}
2036

@@ -23,7 +39,22 @@ const findPluginInFolder = (folder) => {
2339
Object.keys(pjson.devDependencies || {})
2440
);
2541

26-
return deps.filter(isPlugin);
42+
return deps.reduce(
43+
(acc, pkg) => {
44+
if (isRNPMPlugin(pkg)) {
45+
return acc.concat(pkg);
46+
}
47+
if (isReactNativePlugin(pkg)) {
48+
const pkgJson = readPackage(path.join(folder, 'node_modules', pkg));
49+
if (!pkgJson) {
50+
return acc;
51+
}
52+
return acc.concat(findPluginsInReactNativePackage(pkgJson));
53+
}
54+
return acc;
55+
},
56+
[]
57+
);
2758
};
2859

2960
/**

0 commit comments

Comments
 (0)