Permalink
Browse files

Breaking - remove unused registration of JS modules

Summary: It's now unnecessary to declare which JS modules you want to expose on your package. To upgrade, remove all overrides of `createJSModules` and keeping calling your JS modules as before.

Reviewed By: AaaChiuuu

Differential Revision: D5229259

fbshipit-source-id: 1160826c951433722f1fe0421c1200883ba1a348
  • Loading branch information...
javache authored and facebook-github-bot committed Jun 14, 2017
1 parent 71ea94b commit ce6fb337a146e6f261f2afb564aa19363774a7a8
Showing with 15 additions and 203 deletions.
  1. +1 −2 ReactAndroid/src/androidTest/java/com/facebook/react/testing/AbstractScrollViewTestCase.java
  2. +0 −5 ReactAndroid/src/androidTest/java/com/facebook/react/testing/InstanceSpecForTestPackage.java
  3. +0 −9 ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactInstanceSpecForTest.java
  4. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestFactory.java
  5. +2 −15 ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactTestHelper.java
  6. +2 −3 ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystMeasureLayoutTest.java
  7. +0 −1 ...droid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJSToJavaParametersTestCase.java
  8. +0 −1 ...ndroid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJavaToJSArgumentsTestCase.java
  9. +0 −1 ...oid/src/androidTest/java/com/facebook/react/tests/CatalystNativeJavaToJSReturnValuesTestCase.java
  10. +2 −4 ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystSubviewsClippingTestCase.java
  11. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java
  12. +1 −2 ReactAndroid/src/androidTest/java/com/facebook/react/tests/DatePickerDialogTestCase.java
  13. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/JSLocaleTest.java
  14. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ProgressBarTestCase.java
  15. +1 −2 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactPickerTestCase.java
  16. +1 −2 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactSwipeRefreshLayoutTestCase.java
  17. +1 −2 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ShareTestCase.java
  18. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/TextInputTestCase.java
  19. +1 −2 ReactAndroid/src/androidTest/java/com/facebook/react/tests/TimePickerDialogTestCase.java
  20. +0 −1 ReactAndroid/src/androidTest/java/com/facebook/react/tests/ViewRenderingTestCase.java
  21. +0 −14 ReactAndroid/src/main/java/com/facebook/react/CompositeReactPackage.java
  22. +0 −27 ReactAndroid/src/main/java/com/facebook/react/CoreModulesPackage.java
  23. +3 −9 ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java
  24. +0 −9 ReactAndroid/src/main/java/com/facebook/react/ReactPackage.java
  25. +0 −4 ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java
  26. +0 −10 ReactAndroid/src/main/java/com/facebook/react/bridge/JavaScriptModuleRegistry.java
  27. +0 −5 ReactAndroid/src/main/java/com/facebook/react/shell/MainReactPackage.java
  28. +0 −54 ReactAndroid/src/test/java/com/facebook/react/CompositeReactPackageTest.java
  29. +0 −6 docs/NativeModulesAndroid.md
  30. +0 −8 local-cli/core/__fixtures__/files/ReactPackage.java
@@ -40,8 +40,7 @@ protected void tearDown() throws Exception {
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
mScrollListenerModule = new ScrollListenerModule();
return super.createReactInstanceSpecForTest()
.addNativeModule(mScrollListenerModule)
.addJSModule(ScrollViewTestModule.class);
.addNativeModule(mScrollListenerModule);
}
// See ScrollViewListenerModule.js
@@ -36,11 +36,6 @@ public InstanceSpecForTestPackage(ReactInstanceSpecForTest specForTest) {
return mSpecForTest.getExtraNativeModulesForTest();
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return mSpecForTest.getExtraJSModulesForTest();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return mSpecForTest.getExtraViewManagers();
@@ -38,11 +38,6 @@ public ReactInstanceSpecForTest addNativeModule(NativeModule module) {
return this;
}
public ReactInstanceSpecForTest addJSModule(Class jsClass) {
mJSModuleSpecs.add(jsClass);
return this;
}
public ReactInstanceSpecForTest setPackage(ReactPackage reactPackage) {
mReactPackage = reactPackage;
return this;
@@ -57,10 +52,6 @@ public ReactInstanceSpecForTest addViewManager(ViewManager viewManager) {
return mNativeModules;
}
public List<Class<? extends JavaScriptModule>> getExtraJSModulesForTest() {
return mJSModuleSpecs;
}
public ReactPackage getAlternativeReactPackageForTest() {
return mReactPackage;
}
@@ -18,7 +18,6 @@
public static interface ReactInstanceEasyBuilder {
ReactInstanceEasyBuilder setContext(Context context);
ReactInstanceEasyBuilder addNativeModule(NativeModule module);
ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass);
CatalystInstance build();
}
@@ -16,6 +16,7 @@
import android.view.View;
import android.view.ViewGroup;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.NativeModuleRegistryBuilder;
import com.facebook.react.R;
import com.facebook.react.ReactInstanceManager;
@@ -39,8 +40,6 @@
private static class DefaultReactTestFactory implements ReactTestFactory {
private static class ReactInstanceEasyBuilderImpl implements ReactInstanceEasyBuilder {
private final JavaScriptModuleRegistry.Builder mJSModuleRegistryBuilder =
new JavaScriptModuleRegistry.Builder();
private NativeModuleRegistryBuilder mNativeModuleRegistryBuilder;
private @Nullable Context mContext;
@@ -59,16 +58,11 @@ public ReactInstanceEasyBuilder addNativeModule(NativeModule nativeModule) {
null,
false);
}
Assertions.assertNotNull(nativeModule);
mNativeModuleRegistryBuilder.addNativeModule(nativeModule);
return this;
}
@Override
public ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
mJSModuleRegistryBuilder.add(moduleInterfaceClass);
return this;
}
@Override
public CatalystInstance build() {
if (mNativeModuleRegistryBuilder == null) {
@@ -87,7 +81,6 @@ public CatalystInstance build() {
.setReactQueueConfigurationSpec(ReactQueueConfigurationSpec.createDefault())
.setJSExecutor(executor)
.setRegistry(mNativeModuleRegistryBuilder.build())
.setJSModuleRegistry(mJSModuleRegistryBuilder.build())
.setJSBundleLoader(JSBundleLoader.createAssetLoader(
mContext,
"assets://AndroidTestBundle.js",
@@ -141,12 +134,6 @@ public static ReactTestFactory getReactTestFactory() {
return this;
}
@Override
public ReactTestFactory.ReactInstanceEasyBuilder addJSModule(Class moduleInterfaceClass) {
builder.addJSModule(moduleInterfaceClass);
return this;
}
@Override
public CatalystInstance build() {
final CatalystInstance instance = builder.build();
@@ -74,9 +74,8 @@ protected String getReactApplicationKeyUnderTest() {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
mAssertModule = new AssertModule();
return new ReactInstanceSpecForTest()
.addNativeModule(mAssertModule)
.addJSModule(MeasureLayoutTestModule.class);
return super.createReactInstanceSpecForTest()
.addNativeModule(mAssertModule);
}
private void waitForBridgeIdleAndVerifyAsserts() {
@@ -109,7 +109,6 @@ public void run() {
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addNativeModule(mUIManager)
.addJSModule(TestJSToJavaParametersModule.class)
.build();
}
@@ -85,7 +85,6 @@ public void run() {
.addNativeModule(new DeviceInfoModule(getContext()))
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addJSModule(TestJavaToJSArgumentsModule.class)
.addNativeModule(mUIManager)
.build();
}
@@ -126,7 +126,6 @@ protected void setUp() throws Exception {
.addNativeModule(new DeviceInfoModule(getContext()))
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addJSModule(TestJavaToJSReturnValuesModule.class)
.addNativeModule(mUIManager)
.addNativeModule(new TestModule())
.build();
@@ -51,10 +51,8 @@ protected String getReactApplicationKeyUnderTest() {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
ReactInstanceSpecForTest instanceSpec = new ReactInstanceSpecForTest();
instanceSpec.addJSModule(SubviewsClippingTestModule.class);
instanceSpec.addViewManager(new ClippableViewManager(mEvents));
return instanceSpec;
return super.createReactInstanceSpecForTest()
.addViewManager(new ClippableViewManager(mEvents));
}
/**
@@ -99,7 +99,6 @@ public void run() {
.addNativeModule(new DeviceInfoModule(getContext()))
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addJSModule(UIManagerTestModule.class)
.build()
.getJSModule(UIManagerTestModule.class);
}
@@ -80,8 +80,7 @@ public int getErrors() {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
return super.createReactInstanceSpecForTest()
.addNativeModule(mRecordingModule)
.addJSModule(DatePickerDialogTestModule.class);
.addNativeModule(mRecordingModule);
}
@Override
@@ -66,7 +66,6 @@ public void run() {
.addNativeModule(new DeviceInfoModule(getContext()))
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addJSModule(TestJSLocaleModule.class)
.build();
}
@@ -90,7 +90,6 @@ public void run() {
.addNativeModule(new DeviceInfoModule(getContext()))
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addJSModule(ProgressBarTestModule.class)
.build();
mRootView = new ReactRootView(getContext());
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.tests;
import java.util.ArrayList;
@@ -68,7 +68,6 @@ protected String getReactApplicationKeyUnderTest() {
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
mRecordingModule = new PickerAndroidRecordingModule();
return super.createReactInstanceSpecForTest()
.addJSModule(PickerAndroidTestModule.class)
.addNativeModule(mRecordingModule);
}
@@ -55,8 +55,7 @@ protected String getReactApplicationKeyUnderTest() {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
return super.createReactInstanceSpecForTest()
.addNativeModule(mRecordingModule)
.addJSModule(SwipeRefreshLayoutTestModule.class);
.addNativeModule(mRecordingModule);
}
public void testRefreshNoScroll() {
@@ -73,8 +73,7 @@ public int getErrors() {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
return super.createReactInstanceSpecForTest()
.addNativeModule(mRecordingModule)
.addJSModule(ShareTestModule.class);
.addNativeModule(mRecordingModule);
}
@Override
@@ -248,7 +248,6 @@ public void testMetionsInputColors() throws Throwable {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
return super.createReactInstanceSpecForTest()
.addJSModule(TextInputTestModule.class)
.addNativeModule(mRecordingModule);
}
@@ -77,8 +77,7 @@ public int getErrors() {
@Override
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
return super.createReactInstanceSpecForTest()
.addNativeModule(mRecordingModule)
.addJSModule(TimePickerDialogTestModule.class);
.addNativeModule(mRecordingModule);
}
@Override
@@ -71,7 +71,6 @@ public void run() {
.addNativeModule(new DeviceInfoModule(getContext()))
.addNativeModule(new AppStateModule(getContext()))
.addNativeModule(new FakeWebSocketModule())
.addJSModule(ViewRenderingTestModule.class)
.build();
mRootView = new ReactRootView(getContext());
@@ -84,20 +84,6 @@ public CompositeReactPackage(ReactPackage arg1, ReactPackage arg2, ReactPackage.
return new ArrayList(moduleMap.values());
}
/**
* {@inheritDoc}
*/
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
final Set<Class<? extends JavaScriptModule>> moduleSet = new HashSet<>();
for (ReactPackage reactPackage: mChildReactPackages) {
for (Class<? extends JavaScriptModule> jsModule: reactPackage.createJSModules()) {
moduleSet.add(jsModule);
}
}
return new ArrayList(moduleSet);
}
/**
* {@inheritDoc}
*/
@@ -12,27 +12,21 @@
import javax.inject.Provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMarker;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.devsupport.HMRClient;
import com.facebook.react.devsupport.JSCHeapCapture;
import com.facebook.react.devsupport.JSCSamplingProfiler;
import com.facebook.react.module.annotations.ReactModuleList;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.modules.appregistry.AppRegistry;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.ExceptionsManagerModule;
import com.facebook.react.modules.core.HeadlessJsTaskSupportModule;
import com.facebook.react.modules.core.JSTimersExecution;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.facebook.react.modules.core.Timing;
import com.facebook.react.modules.debug.AnimationsDebugModule;
import com.facebook.react.modules.debug.SourceCodeModule;
@@ -42,7 +36,6 @@
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.uimanager.debug.DebugComponentOwnershipModule;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.systrace.Systrace;
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_END;
@@ -187,26 +180,6 @@ public NativeModule get() {
return moduleSpecList;
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
List<Class<? extends JavaScriptModule>> jsModules = new ArrayList<>(Arrays.asList(
DeviceEventManagerModule.RCTDeviceEventEmitter.class,
JSTimersExecution.class,
RCTEventEmitter.class,
RCTNativeAppEventEmitter.class,
AppRegistry.class,
com.facebook.react.bridge.Systrace.class,
HMRClient.class));
if (ReactBuildConfig.DEBUG) {
jsModules.add(DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
jsModules.add(JSCHeapCapture.HeapCapture.class);
jsModules.add(JSCSamplingProfiler.SamplingProfiler.class);
}
return jsModules;
}
@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
// This has to be done via reflection or we break open source.
@@ -926,7 +926,6 @@ private ReactApplicationContext createReactContext(
reactContext,
this,
mLazyNativeModulesEnabled);
JavaScriptModuleRegistry.Builder jsModulesBuilder = new JavaScriptModuleRegistry.Builder();
if (mUseDeveloperSupport) {
reactContext.setNativeModuleCallExceptionHandler(mDevSupportManager);
}
@@ -942,7 +941,7 @@ private ReactApplicationContext createReactContext(
mBackBtnHandler,
mUIImplementationProvider,
mLazyViewManagersEnabled);
processPackage(coreModulesPackage, nativeModuleRegistryBuilder, jsModulesBuilder);
processPackage(coreModulesPackage, nativeModuleRegistryBuilder);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
@@ -953,7 +952,7 @@ private ReactApplicationContext createReactContext(
TRACE_TAG_REACT_JAVA_BRIDGE,
"createAndProcessCustomReactPackage");
try {
processPackage(reactPackage, nativeModuleRegistryBuilder, jsModulesBuilder);
processPackage(reactPackage, nativeModuleRegistryBuilder);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
@@ -979,7 +978,6 @@ private ReactApplicationContext createReactContext(
ReactQueueConfigurationSpec.createDefault())
.setJSExecutor(jsExecutor)
.setRegistry(nativeModuleRegistry)
.setJSModuleRegistry(jsModulesBuilder.build())
.setJSBundleLoader(jsBundleLoader)
.setNativeModuleCallExceptionHandler(exceptionHandler);
@@ -1010,8 +1008,7 @@ private ReactApplicationContext createReactContext(
private void processPackage(
ReactPackage reactPackage,
NativeModuleRegistryBuilder nativeModuleRegistryBuilder,
JavaScriptModuleRegistry.Builder jsModulesBuilder) {
NativeModuleRegistryBuilder nativeModuleRegistryBuilder) {
SystraceMessage.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "processPackage")
.arg("className", reactPackage.getClass().getSimpleName())
.flush();
@@ -1020,9 +1017,6 @@ private void processPackage(
}
nativeModuleRegistryBuilder.processPackage(reactPackage);
for (Class<? extends JavaScriptModule> jsModuleClass : reactPackage.createJSModules()) {
jsModulesBuilder.add(jsModuleClass);
}
if (reactPackage instanceof ReactPackageLogger) {
((ReactPackageLogger) reactPackage).endProcessPackage();
}
Oops, something went wrong.

3 comments on commit ce6fb33

@ujwal-setlur

This comment has been minimized.

Show comment
Hide comment
@ujwal-setlur

ujwal-setlur Aug 4, 2017

This is causing compile breakage of a lot of third party modules. This is because they override createJSModules.

ujwal-setlur replied Aug 4, 2017

This is causing compile breakage of a lot of third party modules. This is because they override createJSModules.

@krunalsshah

This comment has been minimized.

Show comment
Hide comment
@krunalsshah

krunalsshah Sep 14, 2017

Can you please let us know what's the best practice for a case where we want to support react-native version 0.42 & upgrade to 0.48? Update the minor version with this breaking change?

krunalsshah replied Sep 14, 2017

Can you please let us know what's the best practice for a case where we want to support react-native version 0.42 & upgrade to 0.48? Update the minor version with this breaking change?

@CesarLanderos

This comment has been minimized.

Show comment
Hide comment
@CesarLanderos

CesarLanderos Nov 12, 2017

This is what i did, should be safe for everyone:

  1. If a package breaks with this react-native version, do not upgrade your react-native version.
  2. If you know for sure that this breaking change is causing an specific package to brake, go to that package repo and open a PR (follow this example: CORBmx/react-native-openpay#3) and tell the mantainers that this is a breaking change, so they can publish a new version with that change (which shoul include increasing the major version of that package).
  3. Bump your own app major version (if you are using semver, if not, do something similar for whichever schema you are using) that includes both bumps of RN >= 0.47 and the now fixed third party package.

that is my own recommendation 😬

CesarLanderos replied Nov 12, 2017

This is what i did, should be safe for everyone:

  1. If a package breaks with this react-native version, do not upgrade your react-native version.
  2. If you know for sure that this breaking change is causing an specific package to brake, go to that package repo and open a PR (follow this example: CORBmx/react-native-openpay#3) and tell the mantainers that this is a breaking change, so they can publish a new version with that change (which shoul include increasing the major version of that package).
  3. Bump your own app major version (if you are using semver, if not, do something similar for whichever schema you are using) that includes both bumps of RN >= 0.47 and the now fixed third party package.

that is my own recommendation 😬

Please sign in to comment.