Skip to content

Commit

Permalink
Use latest React Native CLI (#24517)
Browse files Browse the repository at this point in the history
Summary:
Updates React Native to use latest CLI.

Changes:
- No more `--reactNativePath`, define it once in the configuration file. This reverts the previous PR that added this flag
- Add `platforms` and `commands` - React Native now defines platform like any other package. There's no longer concept of "out-of-tree" platform. All are treated equally. If React Native works, any other platform will work too.
- Updates `jest/hasteImpl.js` to use public CLI interface (`loadConfig`) instead of `findPlugins` and removes a weird conditional that checks for CI presence.

[INTERNAL] - Update React Native CLI
Pull Request resolved: #24517

Differential Revision: D15044762

Pulled By: cpojer

fbshipit-source-id: 379b61e842e619312c542173219a7d326663cf24
  • Loading branch information
grabbou authored and facebook-github-bot committed Apr 24, 2019
1 parent 8d3e168 commit 706f67a
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 92 deletions.
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 @@ -1716,7 +1716,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
86 changes: 32 additions & 54 deletions jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,24 @@
'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();
// Use duck-typing because of Facebook-internal infra that doesn't have the cli package.
const {haste} = (cli.loadConfig && cli.loadConfig()) || {
haste: {
providesModuleNodeModules: [],
platforms: [],
},
};

// 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 +51,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 +95,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.16",
"@react-native-community/cli-platform-ios": "2.0.0-alpha.15",
"@react-native-community/cli-platform-android": "2.0.0-alpha.15",
"abort-controller": "^3.0.0",
"art": "^0.10.0",
"base64-js": "^1.1.2",
Expand Down
41 changes: 41 additions & 0 deletions react-native.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 ios = require('@react-native-community/cli-platform-ios');
const android = require('@react-native-community/cli-platform-android');

module.exports = {
commands: [...ios.commands, ...android.commands],
platforms: {
ios: {
linkConfig: ios.linkConfig,
projectConfig: ios.projectConfig,
dependencyConfig: ios.dependencyConfig,
},
android: {
linkConfig: android.linkConfig,
projectConfig: android.projectConfig,
dependencyConfig: android.dependencyConfig,
},
},
/**
* Used when running RNTester (with React Native from source)
*/
reactNativePath: '.',
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

0 comments on commit 706f67a

Please sign in to comment.