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

Add support for out-of-tree platform plugins #20825

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add support for out-of-tree platform plugins
  • Loading branch information
empyrical committed Aug 30, 2018
commit cd79e08dc97d5c88eede47ad97e676b2210246f0
19 changes: 15 additions & 4 deletions jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@
'use strict';

const path = require('path');
const findPlugins = require('../local-cli/core/findPlugins');

const plugins = findPlugins([path.resolve(__dirname, '../../../')]);

// Detect out-of-tree platforms and add them to the whitelists
const pluginRoots /*: Array<string> */ = plugins.haste.providesModuleNodeModules.map(
name => path.resolve(__dirname, '../../', name) + path.sep);

const pluginNameReducers /*: Array<[RegExp, string]> */ = plugins.haste.platforms.map(
name => [new RegExp(`^(.*)\.(${name})$`), '$1']);

const ROOTS = [
path.resolve(__dirname, '..') + path.sep,
path.resolve(__dirname, '../../react-native-windows') + path.sep,
path.resolve(__dirname, '../../react-native-dom') + path.sep,
...pluginRoots
];

const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
Expand All @@ -36,8 +45,10 @@ const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
[/^(?:.*[\\\/])?([a-zA-Z0-9$_.-]+)$/, '$1'],
// strip .js/.js.flow suffix
[/^(.*)\.js(\.flow)?$/, '$1'],
// strip .android/.ios/.native/.web suffix
[/^(.*)\.(android|ios|native|web|windows|dom)$/, '$1'],
// strip platform suffix
[/^(.*)\.(android|ios|native)$/, '$1'],
// strip plugin platform suffixes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Insert ,

...pluginNameReducers
];

const haste = {
Expand Down
38 changes: 35 additions & 3 deletions local-cli/core/findPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,37 @@ const findPlatformsInPackage = pjson => {
return path.join(pjson.name, pjson.rnpm.platform);
};

const getEmptyPluginConfig = () => ({
commands: [],
platforms: [],
haste: {
platforms: [],
providesModuleNodeModules: []
}
});

const findHasteConfigInPackageAndConcat = (pjson, haste) => {
if (!pjson.rnpm || !pjson.rnpm.haste) {
return;
}
let pkgHaste = pjson.rnpm.haste;

if (pkgHaste.platforms) {
haste.platforms = haste.platforms.concat(pkgHaste.platforms);
}

if (pkgHaste.providesModuleNodeModules) {
haste.providesModuleNodeModules =
haste.providesModuleNodeModules.concat(pkgHaste.providesModuleNodeModules);
}
};


const findPluginInFolder = folder => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Replace flatten(plugins.map(p·=>·p.haste.providesModuleNodeModules)) with ⏎········flatten(plugins.map(p·=>·p.haste.providesModuleNodeModules)),⏎······

const pjson = readPackage(folder);

if (!pjson) {
return {commands: [], platforms: []};
return getEmptyPluginConfig();
}

const deps = union(
Expand All @@ -63,6 +89,7 @@ const findPluginInFolder = folder => {
(acc, pkg) => {
let commands = acc.commands;
let platforms = acc.platforms;
let haste = acc.haste;
if (isRNPMPlugin(pkg)) {
commands = commands.concat(pkg);
}
Expand All @@ -71,11 +98,12 @@ const findPluginInFolder = folder => {
if (pkgJson) {
commands = commands.concat(findPluginsInReactNativePackage(pkgJson));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Delete ··

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely sure what this means

platforms = platforms.concat(findPlatformsInPackage(pkgJson));
findHasteConfigInPackageAndConcat(pkgJson, haste);
}
}
return {commands: commands, platforms: platforms};
return {commands: commands, platforms: platforms, haste: haste};
},
{commands: [], platforms: []},
getEmptyPluginConfig(),
);
};

Expand All @@ -89,5 +117,9 @@ module.exports = function findPlugins(folders) {
return {
commands: uniq(flatten(plugins.map(p => p.commands))),
platforms: uniq(flatten(plugins.map(p => p.platforms))),
haste: {
platforms: uniq(flatten(plugins.map(p => p.haste.platforms))),
providesModuleNodeModules: uniq(flatten(plugins.map(p => p.haste.providesModuleNodeModules)))
}
};
};
10 changes: 6 additions & 4 deletions local-cli/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ const defaultConfig = {
hasteImplModulePath: require.resolve('../../jest/hasteImpl'),

getPlatforms(): Array<string> {
return ['ios', 'android', 'windows', 'web', 'dom'];
return ['ios', 'android', 'native', ...plugins.haste.platforms];
},

getProvidesModuleNodeModules(): Array<string> {
return ['react-native', 'react-native-windows', 'react-native-dom'];
return ['react-native', ...plugins.haste.providesModuleNodeModules];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Insert ⏎···

},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Replace ·config.resolver.providesModuleNodeModules·|| with ⏎····config.resolver.providesModuleNodeModules·||⏎···

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier/prettier: Replace ·config.resolver.providesModuleNodeModules·|| with ⏎····config.resolver.providesModuleNodeModules·||⏎···

};

Expand Down Expand Up @@ -133,8 +133,10 @@ async function getCliConfig(): Promise<RNConfig> {

config.transformer.assetRegistryPath = ASSET_REGISTRY_PATH;
config.resolver.hasteImplModulePath = config.resolver.hasteImplModulePath || defaultConfig.hasteImplModulePath;
config.resolver.platforms = config.resolver.platforms || defaultConfig.getPlatforms();
config.resolver.providesModuleNodeModules = config.resolver.providesModuleNodeModules || defaultConfig.getProvidesModuleNodeModules();
config.resolver.platforms = config.resolver.platforms ?
config.resolver.platforms.concat(defaultConfig.getPlatforms()) : defaultConfig.getPlatforms();
config.resolver.providesModuleNodeModules = config.resolver.providesModuleNodeModules ?
config.resolver.providesModuleNodeModules.concat(defaultConfig.getProvidesModuleNodeModules()) : defaultConfig.getProvidesModuleNodeModules();

return {...defaultRNConfig, ...config};
}
Expand Down