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: https://github.com/facebook/metro/issues/241 Pull Request resolved: https://github.com/facebook/react-native/pull/21082 Differential Revision: D9809094 Pulled By: hramos fbshipit-source-id: 4b0694ad4119b37dd5664af52c48e48ebe4d7404
This commit is contained in:
parent
7f1fcb67e5
commit
4b106be477
|
@ -66,4 +66,19 @@ describe('findPlugins', () => {
|
|||
}));
|
||||
expect(findPlugins([ROOT]).commands).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('returns plugins in scoped modules', () => {
|
||||
jest.mock(pjsonPath, () => ({
|
||||
dependencies: {
|
||||
'@org/rnpm-plugin-test': '*',
|
||||
'@org/react-native-test': '*',
|
||||
'@react-native/test': '*',
|
||||
'@react-native-org/test': '*',
|
||||
},
|
||||
}));
|
||||
|
||||
expect(findPlugins([ROOT])).toHaveProperty('commands');
|
||||
expect(findPlugins([ROOT])).toHaveProperty('platforms');
|
||||
expect(findPlugins([ROOT]).commands[0]).toBe('@org/rnpm-plugin-test');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,14 +14,23 @@ const union = require('lodash').union;
|
|||
const uniq = require('lodash').uniq;
|
||||
const flatten = require('lodash').flatten;
|
||||
|
||||
const RNPM_PLUGIN_PATTERNS = [/^rnpm-plugin-/, /^@(.*)\/rnpm-plugin-/];
|
||||
|
||||
const REACT_NATIVE_PLUGIN_PATTERNS = [
|
||||
/^react-native-/,
|
||||
/^@(.*)\/react-native-/,
|
||||
/^@react-native(.*)\/(?!rnpm-plugin-)/,
|
||||
];
|
||||
|
||||
/**
|
||||
* Filter dependencies by name pattern
|
||||
* @param {String} dependency Name of the dependency
|
||||
* @return {Boolean} If dependency is a rnpm plugin
|
||||
*/
|
||||
const isRNPMPlugin = dependency => dependency.indexOf('rnpm-plugin-') === 0;
|
||||
const isRNPMPlugin = dependency =>
|
||||
RNPM_PLUGIN_PATTERNS.some(pattern => pattern.test(dependency));
|
||||
const isReactNativePlugin = dependency =>
|
||||
dependency.indexOf('react-native-') === 0;
|
||||
REACT_NATIVE_PLUGIN_PATTERNS.some(pattern => pattern.test(dependency));
|
||||
|
||||
const readPackage = folder => {
|
||||
try {
|
||||
|
|
|
@ -152,7 +152,13 @@ async function getCliConfig(): Promise<RNConfig> {
|
|||
*/
|
||||
function getProjectCommands(): Array<CommandT> {
|
||||
const commands = plugins.commands.map(pathToCommands => {
|
||||
const name = pathToCommands.split(path.sep)[0];
|
||||
const name =
|
||||
pathToCommands[0] === '@'
|
||||
? pathToCommands
|
||||
.split(path.sep)
|
||||
.slice(0, 2)
|
||||
.join(path.sep)
|
||||
: pathToCommands.split(path.sep)[0];
|
||||
|
||||
return attachPackage(
|
||||
require(path.join(appRoot, 'node_modules', pathToCommands)),
|
||||
|
|
Loading…
Reference in New Issue