Skip to content

Commit 5494274

Browse files
rubennortefacebook-github-bot
authored andcommittedJul 2, 2018
Hotfix to include react-native-windows in hasteImpl accepted paths (#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
1 parent fdce938 commit 5494274

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
 

‎jest/hasteImpl.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
const path = require('path');
1414

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

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

3942
const haste = {
@@ -63,11 +66,12 @@ function isHastePath(filePath /*: string */) /*: boolean */ {
6366
return false;
6467
}
6568

66-
if (!filePath.startsWith(ROOT)) {
69+
const root = ROOTS.find(r => filePath.startsWith(r));
70+
if (!root) {
6771
return false;
6872
}
6973

70-
filePath = filePath.substr(ROOT.length + 1);
74+
filePath = filePath.substr(root.length);
7175
if (BLACKLISTED_PATTERNS.some(pattern => pattern.test(filePath))) {
7276
return false;
7377
}

‎local-cli/core/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ const pluginPlatforms = plugins.platforms.reduce((acc, pathToPlatforms) => {
7272
const defaultRNConfig = {
7373
hasteImplModulePath: require.resolve('../../jest/hasteImpl'),
7474

75+
getPlatforms(): Array<string> {
76+
return ['ios', 'android', 'windows', 'web'];
77+
},
78+
79+
getProvidesModuleNodeModules(): Array<string> {
80+
return ['react-native', 'react-native-windows'];
81+
},
82+
7583
getProjectCommands(): Array<CommandT> {
7684
const commands = plugins.commands.map(pathToCommands => {
7785
const name = pathToCommands.split(path.sep)[0];

0 commit comments

Comments
 (0)
Please sign in to comment.