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
Prev Previous commit
Run prettier on platform support files
  • Loading branch information
empyrical committed Aug 30, 2018
commit a73d9910d4ed77ed66686e85e5c0f7ca77fe6fd8
24 changes: 14 additions & 10 deletions jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ 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,
...pluginRoots,
];
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, ...pluginRoots];

const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
/.*[\\\/]__(mocks|tests)__[\\\/].*/,
Expand Down
44 changes: 22 additions & 22 deletions local-cli/core/findPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ const findHasteConfigInPackageAndConcat = (pjson, haste) => {
}

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

Expand All @@ -84,26 +85,23 @@ const findPluginInFolder = folder => {
Object.keys(pjson.devDependencies || {}),
);

return deps.reduce(
(acc, pkg) => {
let commands = acc.commands;
let platforms = acc.platforms;
let haste = acc.haste;
if (isRNPMPlugin(pkg)) {
commands = commands.concat(pkg);
return deps.reduce((acc, pkg) => {
let commands = acc.commands;
let platforms = acc.platforms;
let haste = acc.haste;
if (isRNPMPlugin(pkg)) {
commands = commands.concat(pkg);
}
if (isReactNativePlugin(pkg)) {
const pkgJson = readPackage(path.join(folder, 'node_modules', pkg));
if (pkgJson) {
commands = commands.concat(findPluginsInReactNativePackage(pkgJson));
platforms = platforms.concat(findPlatformsInPackage(pkgJson));
findHasteConfigInPackageAndConcat(pkgJson, haste);
}
if (isReactNativePlugin(pkg)) {
const pkgJson = readPackage(path.join(folder, 'node_modules', pkg));
if (pkgJson) {
commands = commands.concat(findPluginsInReactNativePackage(pkgJson));
platforms = platforms.concat(findPlatformsInPackage(pkgJson));
findHasteConfigInPackageAndConcat(pkgJson, haste);
}
}
return {commands: commands, platforms: platforms, haste: haste};
},
getEmptyPluginConfig(),
);
}
return {commands: commands, platforms: platforms, haste: haste};
}, getEmptyPluginConfig());
};

/**
Expand All @@ -118,7 +116,9 @@ module.exports = function findPlugins(folders) {
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))),
providesModuleNodeModules: uniq(
flatten(plugins.map(p => p.haste.providesModuleNodeModules)),
),
},
};
};
16 changes: 11 additions & 5 deletions local-cli/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,17 @@ 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 ?
config.resolver.platforms.concat(defaultConfig.getPlatforms()) : defaultConfig.getPlatforms();
config.resolver.providesModuleNodeModules = config.resolver.providesModuleNodeModules ?
config.resolver.providesModuleNodeModules.concat(defaultConfig.getProvidesModuleNodeModules()) : defaultConfig.getProvidesModuleNodeModules();
config.resolver.hasteImplModulePath =
config.resolver.hasteImplModulePath || defaultConfig.hasteImplModulePath;
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