Skip to content

Commit 640a665

Browse files
empyricalfacebook-github-bot
authored andcommitted
Give RNPM the ability to look for plugins in @scoped modules (#21082)
Summary: This PR gives RNPM the ability to look for plugins in `scoped` modules. The regexes for finding RNPM plugins will match these hypothetical examples: * `rnpm-plugin-foo` * `org/rnpm-plugin-foo` The regexes for finding React Native plugins will match these hypothetical examples: * `react-native-foo` * `org/react-native-foo` * `The controller you requested could not be found./module` (will be useful in the slimmening) * `The controller you requested could not be found./module` RNPM plugins will be able to benefit from this immediately, but React Native plugins will run into this Metro issue currently: react/metro#241 Pull Request resolved: react/react-native#21082 Differential Revision: D9809094 Pulled By: hramos fbshipit-source-id: 4b0694ad4119b37dd5664af52c48e48ebe4d7404
1 parent abf592f commit 640a665

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

core/__tests__/findPlugins.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,19 @@ describe('findPlugins', () => {
6666
}));
6767
expect(findPlugins([ROOT]).commands).toHaveLength(1);
6868
});
69+
70+
it('returns plugins in scoped modules', () => {
71+
jest.mock(pjsonPath, () => ({
72+
dependencies: {
73+
'@org/rnpm-plugin-test': '*',
74+
'@org/react-native-test': '*',
75+
'@react-native/test': '*',
76+
'@react-native-org/test': '*',
77+
},
78+
}));
79+
80+
expect(findPlugins([ROOT])).toHaveProperty('commands');
81+
expect(findPlugins([ROOT])).toHaveProperty('platforms');
82+
expect(findPlugins([ROOT]).commands[0]).toBe('@org/rnpm-plugin-test');
83+
});
6984
});

core/findPlugins.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,23 @@ const union = require('lodash').union;
1414
const uniq = require('lodash').uniq;
1515
const flatten = require('lodash').flatten;
1616

17+
const RNPM_PLUGIN_PATTERNS = [/^rnpm-plugin-/, /^@(.*)\/rnpm-plugin-/];
18+
19+
const REACT_NATIVE_PLUGIN_PATTERNS = [
20+
/^react-native-/,
21+
/^@(.*)\/react-native-/,
22+
/^@react-native(.*)\/(?!rnpm-plugin-)/,
23+
];
24+
1725
/**
1826
* Filter dependencies by name pattern
1927
* @param {String} dependency Name of the dependency
2028
* @return {Boolean} If dependency is a rnpm plugin
2129
*/
22-
const isRNPMPlugin = dependency => dependency.indexOf('rnpm-plugin-') === 0;
30+
const isRNPMPlugin = dependency =>
31+
RNPM_PLUGIN_PATTERNS.some(pattern => pattern.test(dependency));
2332
const isReactNativePlugin = dependency =>
24-
dependency.indexOf('react-native-') === 0;
33+
REACT_NATIVE_PLUGIN_PATTERNS.some(pattern => pattern.test(dependency));
2534

2635
const readPackage = folder => {
2736
try {

core/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ async function getCliConfig(): Promise<RNConfig> {
152152
*/
153153
function getProjectCommands(): Array<CommandT> {
154154
const commands = plugins.commands.map(pathToCommands => {
155-
const name = pathToCommands.split(path.sep)[0];
155+
const name =
156+
pathToCommands[0] === '@'
157+
? pathToCommands
158+
.split(path.sep)
159+
.slice(0, 2)
160+
.join(path.sep)
161+
: pathToCommands.split(path.sep)[0];
156162

157163
return attachPackage(
158164
require(path.join(appRoot, 'node_modules', pathToCommands)),

0 commit comments

Comments
 (0)