Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give RNPM the ability to look for plugins in @scoped modules #21082

Closed
Closed
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions local-cli/core/__tests__/findPlugins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
13 changes: 11 additions & 2 deletions local-cli/core/findPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion local-cli/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down