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

Use latest React Native CLI #24517

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ watchman shutdown-server

# integration tests
# build JS bundle for instrumentation tests
node cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js --reactNativePath .
node cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js

# build test APK
# shellcheck disable=SC1091
Expand Down
5 changes: 2 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,8 @@ jobs:
# Build JavaScript Bundle for instrumentation tests
- run:
name: Build JavaScript Bundle
command: node cli.js bundle --max-workers 2 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js --reactNativePath .


command: node cli.js bundle --max-workers 2 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js

# Wait for AVD to finish booting before running tests
- run:
name: Wait for Android Virtual Device
Expand Down
2 changes: 1 addition & 1 deletion RNTester/RNTester.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export EXTRA_PACKAGER_ARGS=\"--reactNativePath $SRCROOT/../\"\nexport NODE_BINARY=node\n$SRCROOT/../scripts/react-native-xcode.sh RNTester/js/RNTesterApp.ios.js\n";
shellScript = "export NODE_BINARY=node\n$SRCROOT/../scripts/react-native-xcode.sh RNTester/js/RNTesterApp.ios.js\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
3 changes: 1 addition & 2 deletions RNTester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ project.ext.react = [
bundleAssetName: "RNTesterApp.android.bundle",
entryFile: file("../../js/RNTesterApp.android.js"),
root: "$rootDir",
inputExcludes: ["android/**", "./**", ".gradle/**"],
extraPackagerArgs: ["--reactNativePath", "$rootDir"]
inputExcludes: ["android/**", "./**", ".gradle/**"]
]

apply from: "../../../react.gradle"
Expand Down
80 changes: 26 additions & 54 deletions jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,18 @@
'use strict';

const path = require('path');
const cli = require('@react-native-community/cli');

const REACT_NATIVE_CI = process.cwd() === path.resolve(__dirname, '..');

let pluginsPath;

if (REACT_NATIVE_CI) {
pluginsPath = '..';
} else {
pluginsPath = '../../../';
}

function getPlugins() {
try {
const {findPlugins} = require('@react-native-community/cli');
return findPlugins(path.resolve(__dirname, pluginsPath));
} catch (e) {
return {
haste: {
providesModuleNodeModules: [],
platforms: [],
},
};
}
}

const plugins = getPlugins();
const {haste} = cli.loadConfig();

// Detect out-of-tree platforms and add them to the whitelists
const pluginRoots /*: Array<string> */ = plugins.haste.providesModuleNodeModules.map(
const pluginRoots /*: Array<string> */ = 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 pluginNameReducers /*: Array<[RegExp, string]> */ = haste.platforms.map(
name => [new RegExp(`^(.*)\.(${name})$`), '$1'],
);

const ROOTS = [path.resolve(__dirname, '..') + path.sep, ...pluginRoots];

Expand All @@ -71,13 +45,30 @@ const NAME_REDUCERS /*: Array<[RegExp, string]> */ = [
[/^(?:.*[\\\/])?([a-zA-Z0-9$_.-]+)$/, '$1'],
// strip .js/.js.flow suffix
[/^(.*)\.js(\.flow)?$/, '$1'],
// strip platform suffix
[/^(.*)\.(android|ios|native)$/, '$1'],
// strip native suffix
[/^(.*)\.(native)$/, '$1'],
// strip plugin platform suffixes
...pluginNameReducers,
];

const haste = {
function isHastePath(filePath /*: string */) /*: boolean */ {
if (!filePath.endsWith('.js') && !filePath.endsWith('.js.flow')) {
return false;
}

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

filePath = filePath.substr(root.length);
if (BLACKLISTED_PATTERNS.some(pattern => pattern.test(filePath))) {
return false;
}
return WHITELISTED_PREFIXES.some(prefix => filePath.startsWith(prefix));
}

module.exports = {
/*
* @return {string|void} hasteName for module at filePath; or undefined if
* filePath is not a haste module
Expand All @@ -98,22 +89,3 @@ const haste = {
return hasteName;
},
};

function isHastePath(filePath /*: string */) /*: boolean */ {
if (!filePath.endsWith('.js') && !filePath.endsWith('.js.flow')) {
return false;
}

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

filePath = filePath.substr(root.length);
if (BLACKLISTED_PATTERNS.some(pattern => pattern.test(filePath))) {
return false;
}
return WHITELISTED_PREFIXES.some(prefix => filePath.startsWith(prefix));
}

module.exports = haste;
File renamed without changes.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"!template/package-lock.json"
],
"scripts": {
"start": "react-native start --reactNativePath .",
"start": "react-native start",
"test": "jest",
"test-ci": "jest --maxWorkers=2 --ci --reporters=\"default\" --reporters=\"jest-junit\"",
"flow": "flow",
Expand Down Expand Up @@ -87,7 +87,9 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@react-native-community/cli": "^2.0.0",
"@react-native-community/cli": "2.0.0-alpha.12",
"@react-native-community/cli-platform-ios": "2.0.0-alpha.9",
"@react-native-community/cli-platform-android": "2.0.0-alpha.9",
orta marked this conversation as resolved.
Show resolved Hide resolved
"abort-controller": "^3.0.0",
"art": "^0.10.0",
"base64-js": "^1.1.2",
Expand Down
33 changes: 33 additions & 0 deletions react-native.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';

const {
commands: commandsIOS,
...ios
} = require('@react-native-community/cli-platform-ios');
const {
commands: commandsAndroid,
...android
} = require('@react-native-community/cli-platform-android');

module.exports = {
reactNativePath: '.',
commands: [...commandsIOS, ...commandsAndroid],
platforms: {ios, android},
grabbou marked this conversation as resolved.
Show resolved Hide resolved
project: {
ios: {
project: './RNTester/RNTester.xcodeproj',
},
android: {
sourceDir: './RNTester',
},
},
};
2 changes: 1 addition & 1 deletion scripts/launchPackager.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@echo off
title Metro Bundler
call .packager.bat
node "%~dp0..\cli.js" --reactNativePath ../ --projectRoot ../../../ start
node "%~dp0..\cli.js" --projectRoot ../../../ start
pause
exit
2 changes: 1 addition & 1 deletion scripts/run-android-local-integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Compiling native code..."
./gradlew :ReactAndroid:packageReactNdkLibsForBuck

echo "Building JS bundle..."
node cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js --reactNativePath .
node cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js

echo "Installing test app on the device..."
buck fetch ReactAndroid/src/androidTest/buck-runner:instrumentation-tests
Expand Down
Loading