Skip to content

Commit

Permalink
Hotfix to include react-native-windows in hasteImpl accepted paths (#…
Browse files Browse the repository at this point in the history
…20007)

Summary:
Closes #20007

We removed support for providesModule annotations and maintained support for Haste names in installed modules via `providesModuleNodeModules`, but our default `hasteImpl` doesn't take them into account. We need to find a better way to override core components from plugins but meanwhile this adds an exception for react-native-windows in the default `hasteImpl` to unblock their upgrade to the latest RC.

Fixes facebook/metro#188

Reviewed By: mjesun

Differential Revision: D8695207

fbshipit-source-id: 2ad6cb1e93e600880a148776ac45f6ebd7d205d3
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jul 2, 2018
1 parent fdce938 commit 5494274
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

const path = require('path');

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

const BLACKLISTED_PATTERNS /*: Array<RegExp> */ = [
/.*\/__(mocks|tests)__\/.*/,
Expand All @@ -33,7 +36,7 @@ const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
// strip .js/.js.flow suffix
[/^(.*)\.js(\.flow)?$/, '$1'],
// strip .android/.ios/.native/.web suffix
[/^(.*)\.(android|ios|native|web)$/, '$1'],
[/^(.*)\.(android|ios|native|web|windows)$/, '$1'],
];

const haste = {
Expand Down Expand Up @@ -63,11 +66,12 @@ function isHastePath(filePath /*: string */) /*: boolean */ {
return false;
}

if (!filePath.startsWith(ROOT)) {
const root = ROOTS.find(r => filePath.startsWith(r));
if (!root) {
return false;
}

filePath = filePath.substr(ROOT.length + 1);
filePath = filePath.substr(root.length);
if (BLACKLISTED_PATTERNS.some(pattern => pattern.test(filePath))) {
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions local-cli/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ const pluginPlatforms = plugins.platforms.reduce((acc, pathToPlatforms) => {
const defaultRNConfig = {
hasteImplModulePath: require.resolve('../../jest/hasteImpl'),

getPlatforms(): Array<string> {
return ['ios', 'android', 'windows', 'web'];
},

getProvidesModuleNodeModules(): Array<string> {
return ['react-native', 'react-native-windows'];
},

getProjectCommands(): Array<CommandT> {
const commands = plugins.commands.map(pathToCommands => {
const name = pathToCommands.split(path.sep)[0];
Expand Down

0 comments on commit 5494274

Please sign in to comment.