From 4ea593b7562e9c1b90458d4499b36953da1646cc Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 28 Apr 2022 07:48:40 -0700 Subject: [PATCH 0001/1655] Fix release infrastructure failures discovered during .69 release Summary: During the release of .69, we (fortmarek and me) discovered a couple of bits that needed some intervention. - `sdks/.hermesversion` was gitignored, so we could not commit that. - `scripts/bump-hermes-version.js` was not executable, so we had to chmod +x to make it runnable. Here I'm fixing it. Changelog: [Internal] [Changed] - Fix release infrastructure failures discovered during .69 release Reviewed By: cipolleschi Differential Revision: D36003808 fbshipit-source-id: c4d82ed5e2c63988699035ac84b0e87ed8894540 --- .gitignore | 1 - scripts/bump-hermes-version.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/bump-hermes-version.js diff --git a/.gitignore b/.gitignore index 18328754723b..0fbaf6880328 100644 --- a/.gitignore +++ b/.gitignore @@ -115,7 +115,6 @@ package-lock.json /packages/rn-tester/NativeModuleExample/ScreenshotManagerSpec* # Additional SDKs -/sdks/.hermesversion /sdks/hermes /sdks/download diff --git a/scripts/bump-hermes-version.js b/scripts/bump-hermes-version.js old mode 100644 new mode 100755 index 67ed4f2be357..2c9086226d8a --- a/scripts/bump-hermes-version.js +++ b/scripts/bump-hermes-version.js @@ -12,6 +12,7 @@ /** * This script walks a releaser through bumping the Hermes version for a release. + * It needs be executed on a release branch. */ const {exit} = require('shelljs'); const yargs = require('yargs'); From eb2a83b0be4658654fc6ca6f4671e45f1898798d Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Thu, 28 Apr 2022 07:48:54 -0700 Subject: [PATCH 0002/1655] Allow ReactInstrumentationTest to use custom JSIModules Summary: Update ReactInstrumentationTest to allow passing in custom JSIModules Also: 'Fixed' some improper ordering of Nullable annotations Changelog: Internal Reviewed By: cortinico Differential Revision: D35961806 fbshipit-source-id: aa1513bee34e04ac3aae37f794d9d2771e7cc501 --- .../react/testing/ReactAppTestActivity.java | 9 ++++++-- .../testing/ReactInstanceSpecForTest.java | 21 ++++++++++++++++++- .../testing/ReactInstrumentationTest.java | 9 +++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java index 7d89ab5b2ec3..0134b1057734 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java @@ -37,7 +37,7 @@ import com.facebook.react.testing.idledetection.ReactBridgeIdleSignaler; import com.facebook.react.testing.idledetection.ReactIdleDetectionUtil; import com.facebook.react.uimanager.ViewManagerRegistry; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -250,7 +250,8 @@ public void loadBundle( public List getJSIModules( final ReactApplicationContext reactApplicationContext, final JavaScriptContextHolder jsContext) { - return Arrays.asList( + List packages = new ArrayList<>(); + packages.add( new JSIModuleSpec() { @Override public JSIModuleType getJSIModuleType() { @@ -276,6 +277,10 @@ public UIManager get() { }; } }); + if (spec.getJSIModuleBuilder() != null) { + packages.addAll(spec.getJSIModuleBuilder().build(reactApplicationContext)); + } + return packages; } }); diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstanceSpecForTest.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstanceSpecForTest.java index 8422eb53729e..6b96c8232b9d 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstanceSpecForTest.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstanceSpecForTest.java @@ -11,10 +11,12 @@ import androidx.annotation.Nullable; import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackageTurboModuleManagerDelegate; +import com.facebook.react.bridge.JSIModuleSpec; import com.facebook.react.bridge.JavaScriptExecutorFactory; import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.NativeModuleCallExceptionHandler; +import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; import java.util.ArrayList; import java.util.Arrays; @@ -28,6 +30,11 @@ @SuppressLint("JavatestsIncorrectFolder") public class ReactInstanceSpecForTest { + public abstract static class JSIModuleBuilder { + @Nullable + protected abstract List build(ReactApplicationContext context); + } + private final List mNativeModules = new ArrayList(Arrays.asList(new FakeWebSocketModule())); private final List> mJSModuleSpecs = new ArrayList<>(); @@ -37,6 +44,7 @@ public class ReactInstanceSpecForTest { @Nullable private FabricUIManagerFactory mFabricUIManagerFactory = null; @Nullable private JavaScriptExecutorFactory mJavaScriptExecutorFactory = null; @Nullable private ReactPackageTurboModuleManagerDelegate.Builder mTMMDelegateBuilder = null; + @Nullable private JSIModuleBuilder mJSIModuleBuilder = null; public ReactInstanceSpecForTest addNativeModule(NativeModule module) { mNativeModules.add(module); @@ -85,11 +93,22 @@ public ReactInstanceSpecForTest setReactPackageTurboModuleManagerDelegateBuilder return this; } - protected @Nullable ReactPackageTurboModuleManagerDelegate.Builder + @Nullable + protected ReactPackageTurboModuleManagerDelegate.Builder getReactPackageTurboModuleManagerDelegateBuilder() { return mTMMDelegateBuilder; } + public ReactInstanceSpecForTest setJSIModuleBuilder(@Nullable JSIModuleBuilder builder) { + mJSIModuleBuilder = builder; + return this; + } + + @Nullable + protected JSIModuleBuilder getJSIModuleBuilder() { + return mJSIModuleBuilder; + } + public ReactInstanceSpecForTest addPackages(List reactPackages) { mReactPackages.addAll(reactPackages); return this; diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstrumentationTest.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstrumentationTest.java index 40699a74e4f4..a5ac40a93d9e 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstrumentationTest.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstrumentationTest.java @@ -96,11 +96,17 @@ protected T getJSModule(Class jsInterface) { return getReactContext().getJSModule(jsInterface); } - protected @Nullable ReactPackageTurboModuleManagerDelegate.Builder + @Nullable + protected ReactPackageTurboModuleManagerDelegate.Builder getReactPackageTurboModuleManagerDelegateBuilder() { return null; } + @Nullable + protected ReactInstanceSpecForTest.JSIModuleBuilder getJSIModuleBuilder() { + return null; + } + /** Override this method to provide extra native modules to be loaded before the app starts */ protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { ReactInstanceSpecForTest reactInstanceSpecForTest = @@ -113,6 +119,7 @@ protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { } reactInstanceSpecForTest.setReactPackageTurboModuleManagerDelegateBuilder( getReactPackageTurboModuleManagerDelegateBuilder()); + reactInstanceSpecForTest.setJSIModuleBuilder(getJSIModuleBuilder()); return reactInstanceSpecForTest; } From fdbe4719e2e2b599e86d42c49d42c4da97ef431a Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 28 Apr 2022 08:53:24 -0700 Subject: [PATCH 0003/1655] fix: Make WebSocketTests work in CI (#33721) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This PR reestablish the WebSocketTest in CI which is making the `test_ios_unit` fail. **Note:** the test_ios_unit is actually running integration tests... ## Changelog [iOS] [Changed] - Fix the test_ios_unit test Pull Request resolved: https://github.com/facebook/react-native/pull/33721 Test Plan: The CI of this PR is green. 😬 Reviewed By: cortinico Differential Revision: D36002823 Pulled By: cipolleschi fbshipit-source-id: 20eeb08bfd02658ad6579085241f81654f74c1af --- .circleci/config.yml | 8 +++--- ...erver.command => launchWebSocketServer.sh} | 12 +++------ scripts/objc-test.sh | 26 ++++++++++++++++--- 3 files changed, 30 insertions(+), 16 deletions(-) rename IntegrationTests/{launchWebSocketServer.command => launchWebSocketServer.sh} (67%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8f1dc1809bb3..1ba961dfdab4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -432,7 +432,7 @@ jobs: # ------------------------- # JOBS: iOS Unit Tests # ------------------------- - test_ios_unit: + test_ios: executor: reactnativeios parameters: use_frameworks: @@ -1237,7 +1237,7 @@ workflows: - build_npm_package - test_ios_rntester - build_ios - - test_ios_unit: + - test_ios: run_unit_tests: true requires: - build_ios @@ -1245,8 +1245,8 @@ workflows: # - build_ios: # name: build_ios_frameworks # use_frameworks: true - # - test_ios_unit: - # name: test_ios_unit_frameworks + # - test_ios: + # name: test_ios_frameworks # use_frameworks: true # run_unit_tests: true # requires: diff --git a/IntegrationTests/launchWebSocketServer.command b/IntegrationTests/launchWebSocketServer.sh similarity index 67% rename from IntegrationTests/launchWebSocketServer.command rename to IntegrationTests/launchWebSocketServer.sh index 31bb3496df33..cc736a5ceffd 100755 --- a/IntegrationTests/launchWebSocketServer.command +++ b/IntegrationTests/launchWebSocketServer.sh @@ -1,18 +1,12 @@ #!/bin/bash - # Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -# Set terminal title -echo -en "\033]0;Web Socket Test Server\a" -clear - THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) -pushd "$THIS_DIR" +pushd "$THIS_DIR" || exit ./websocket_integration_test_server.js -popd +popd || exit -echo "Process terminated. Press to close the window" -read +echo "Process terminated." diff --git a/scripts/objc-test.sh b/scripts/objc-test.sh index d2d6ecaa0075..a787bab59890 100755 --- a/scripts/objc-test.sh +++ b/scripts/objc-test.sh @@ -55,6 +55,24 @@ waitForPackager() { echo "Packager is ready!" } +waitForWebSocketServer() { + local -i max_attempts=60 + local -i attempt_num=1 + + until curl -s http://localhost:5555 | grep "Upgrade Required" -q; do + if (( attempt_num == max_attempts )); then + echo "WebSocket Server did not respond in time. No more attempts left." + exit 1 + else + (( attempt_num++ )) + echo "WebSocket Server did not respond. Retrying for attempt number $attempt_num..." + sleep 1 + fi + done + + echo "WebSocket Server is ready!" +} + runTests() { # shellcheck disable=SC1091 source "./scripts/.tests.env" @@ -102,11 +120,13 @@ main() { # Otherwise, just build RNTester and exit if [ "$1" = "test" ]; then - # Start the packager - yarn start --max-workers=1 || echo "Can't start packager automatically" & # Start the WebSocket test server - open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically" + echo "Launch WebSocket Server" + sh "./IntegrationTests/launchWebSocketServer.sh" & + waitForWebSocketServer + # Start the packager + yarn start --max-workers=1 || echo "Can't start packager automatically" & waitForPackager preloadBundles From b873a4f4f7316dae926abd5d56e81313dd59f0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Thu, 28 Apr 2022 10:03:32 -0700 Subject: [PATCH 0004/1655] Hermes: Include sdks/hermes-engine.podspec in release Summary: This file was added in D35300595 (https://github.com/facebook/react-native/commit/ada6c7166b507b950e63723f78bd550cb8303211) and it needs to be part of the `react-native` release. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D35983108 fbshipit-source-id: 0a1c437b953e575c0229b0382743c72b6c91bd0b --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index d679c8a82c2b..3ceb9cd4ebf0 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "scripts/react_native_pods.rb", "scripts/react-native-xcode.sh", "sdks/hermesc", + "sdks/hermes-engine.podspec", "template.config.js", "template", "third-party-podspecs" From 07a63a2376ed2423ce3e854c6cecad0cb29e4a74 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 28 Apr 2022 10:44:06 -0700 Subject: [PATCH 0005/1655] Fix publish_release not running on release tags correctly. Summary: During RN 0.69 we realized that we're failing to publish a version. The reason is that only the `prepare_hermes_workspace` was executed after a TAG got published. The problem is a missing `filter:` key which made CircleCI skipping some steps for a tag. Here I'm fixing it. Run for 0.69.0-rc0 (broken) https://app.circleci.com/pipelines/github/facebook/react-native/13123/workflows/3cb781d2-f81c-4856-9686-2260c020c3bd Run for 0.68.1 https://app.circleci.com/pipelines/github/facebook/react-native/12938/workflows/a1bcf306-9d81-4149-9d4a-bc7b988fb53f Changelog: [Internal] [Changed] - Fix publish_release not running on release tags correctly Reviewed By: hramos Differential Revision: D36005374 fbshipit-source-id: 5664369f008e60e334c1db5fa2e7c3089369d7ad --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1ba961dfdab4..6f213d3ee822 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1273,12 +1273,15 @@ workflows: - prepare_hermes_workspace: filters: *only_release_tags - build_hermesc_linux: + filters: *only_release_tags requires: - prepare_hermes_workspace - build_hermesc_macos: + filters: *only_release_tags requires: - prepare_hermes_workspace - build_hermesc_windows: + filters: *only_release_tags requires: - prepare_hermes_workspace # This job will trigger when a version tag is pushed (by package_release) From d992ae0448d2a032e1b65057fb8cb7d4725aa00d Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Thu, 28 Apr 2022 19:40:55 -0700 Subject: [PATCH 0006/1655] Codemod `Object.assign` with object literal first argument to object spread in Xplat Summary: Codemod `Object.assign` with object literal first argument (e.g. `Object.assign({}, foo)`) to object spread. This adds several suppressions for exposed errors. The codemod produces errors as `Object.assign` is more unsafe than object spread. For example, `Object.assign` doesn't handle indexers, nor does it handle inexact objects properly, and when the (currently unsealed) empty object is supplied as the first argument, it also leads to unsafe behaviour: https://flow.org/try/#0FAehAIGJwSQOwCYFMAeSBOBnYyDGAbAQ3SXADdjwBbQgBwC5wBvAbUwBd0BLOAcwF1GHbnwC+AbmDAAFAHkARgCskudgDpCmTF15xpTQowCMogDTU6ASkbyA9rfxJCcS+PBhwAfm8ymwcAGG4Eam-gFqETS0oaKu7hAAyrQkhAjgGOi2WOCa6Si0KuxICFIe0PCohKo5AGZF6HlV7DgqRCTklDyVqowGQpw8vOYRahJSCsqqGlo6en3gAEQAFlwL5vLGZuBdKE1xHjtN4Li2AK74abZkGVzI4AAG8vfgUvphOYzLq6EB4BvBP3CEUOqhi+0SyScaQyWUwOThqAKqmKpQg0AAqnBME5HGkalwsOwcuheDIJoVptpdPotvMTNZmDV7Iw4KcqPIMLE3B5vN4gA The codemod is safe to do, despite some Flow errors, as `Object.assign` and object spread are equivalent at runtime, with the exception that `Object.assign` triggers setters on the target object. However the codemod [does not run](https://github.com/eslint/eslint/blob/938dbdd6c310784cc8a7329efaeb0e34321b9e1f/lib/rules/prefer-object-spread.js#L283-L285) if the first argument (object literal) has getters/setters, so we are fine. ``` ag -l 'Object.assign\(' | xargs ag -l 'flow' | xargs js1 lint --rule '{"prefer-object-spread":2}' --fix ``` Some manual fixes ``` arc f ``` Reviewed By: SamChou19815 Differential Revision: D36023786 fbshipit-source-id: b682562e670410acf4175ba59ab285c7bdcfe052 --- Libraries/Components/StatusBar/StatusBar.js | 17 ++--- Libraries/Inspector/ElementBox.js | 2 +- .../LogBox/Data/__tests__/LogBoxData-test.js | 62 ++++++++----------- Libraries/Utilities/truncate.js | 2 +- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/Libraries/Components/StatusBar/StatusBar.js b/Libraries/Components/StatusBar/StatusBar.js index 628bd67b6dea..e07389c97231 100644 --- a/Libraries/Components/StatusBar/StatusBar.js +++ b/Libraries/Components/StatusBar/StatusBar.js @@ -112,14 +112,17 @@ function mergePropsStack( propsStack: Array, defaultValues: Object, ): Object { - return propsStack.reduce((prev, cur) => { - for (const prop in cur) { - if (cur[prop] != null) { - prev[prop] = cur[prop]; + return propsStack.reduce( + (prev, cur) => { + for (const prop in cur) { + if (cur[prop] != null) { + prev[prop] = cur[prop]; + } } - } - return prev; - }, Object.assign({}, defaultValues)); + return prev; + }, + {...defaultValues}, + ); } /** diff --git a/Libraries/Inspector/ElementBox.js b/Libraries/Inspector/ElementBox.js index 8c12ca73ebd4..001effee47c7 100644 --- a/Libraries/Inspector/ElementBox.js +++ b/Libraries/Inspector/ElementBox.js @@ -102,7 +102,7 @@ type Style = { * @return a modified copy */ function resolveRelativeSizes(style: $ReadOnly