Skip to content

Commit

Permalink
Migrate Libraries/ReactNative/*.js to use export syntax.
Browse files Browse the repository at this point in the history
Summary:
## Motivation
Modernising the RN codebase to allow for modern Flow tooling to process it.

## This diff
- Migrates the `Libraries/ReactNative/*.js` files to use the `export` syntax.
- Updates deep-imports of these files to use `.default`
- Updates the current iteration of API snapshots (intended).

Changelog:
[General][Breaking] - Deep imports to modules inside `Libraries/ReactNative` with `require` syntax need to be appended with '.default'.

Differential Revision: D68109193
  • Loading branch information
iwoplaza authored and facebook-github-bot committed Jan 13, 2025
1 parent 1e00094 commit 60c1f42
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const I18nManager = require('../ReactNative/I18nManager');
const I18nManager = require('../ReactNative/I18nManager').default;

/**
* Resolve a style property into its component parts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNa
import {getFabricUIManager} from '../ReactNative/FabricUIManager';
import Platform from '../Utilities/Platform';

const UIManager = require('../ReactNative/UIManager');
const UIManager = require('../ReactNative/UIManager').default;

// Reexport type
export type LayoutAnimationConfig = LayoutAnimationConfig_;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {VirtualizedListContextResetter} from '@react-native/virtualized-lists';

const ScrollView = require('../Components/ScrollView/ScrollView');
const View = require('../Components/View/View');
const AppContainer = require('../ReactNative/AppContainer');
const I18nManager = require('../ReactNative/I18nManager');
const AppContainer = require('../ReactNative/AppContainer').default;
const I18nManager = require('../ReactNative/I18nManager').default;
const {RootTagContext} = require('../ReactNative/RootTag');
const StyleSheet = require('../StyleSheet/StyleSheet');
const Platform = require('../Utilities/Platform');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.useFakeTimers({legacyFakeTimers: true});
import type {PressEvent} from '../../Types/CoreEventTypes';
import type {PressabilityConfig} from '../Pressability';

const UIManager = require('../../ReactNative/UIManager');
const UIManager = require('../../ReactNative/UIManager').default;
const Platform = require('../../Utilities/Platform');
const HoverState = require('../HoverState');
const Pressability = require('../Pressability').default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ const AppContainer: component(...Props) = __DEV__
? require('./AppContainer-dev').default
: require('./AppContainer-prod').default;

module.exports = AppContainer;
export default AppContainer;
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/ReactNative/AppRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,4 @@ global.RN$SurfaceRegistry = {

registerCallableModule('AppRegistry', AppRegistry);

module.exports = AppRegistry;
export default AppRegistry;
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,4 @@ if (getUIManagerConstants) {
}
}

module.exports = UIManagerJS;
export default UIManagerJS;
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/ReactNative/I18nManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getI18nManagerConstants(): I18nManagerConstants {
};
}

module.exports = {
export default {
getConstants: (): I18nManagerConstants => {
return i18nConstants;
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/Libraries/ReactNative/PaperUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import nullthrows from 'nullthrows';
const NativeModules = require('../BatchedBridge/NativeModules');
const defineLazyObjectProperty = require('../Utilities/defineLazyObjectProperty');
const Platform = require('../Utilities/Platform');
const UIManagerProperties = require('./UIManagerProperties');
const UIManagerProperties = require('./UIManagerProperties').default;

const viewManagerConfigs: {[string]: any | null} = {};

Expand Down Expand Up @@ -188,4 +188,4 @@ if (!global.nativeCallSyncHook) {
});
}

module.exports = UIManagerJS;
export default UIManagerJS;
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ const ReactNativeFeatureFlags: FeatureFlags = {
shouldPressibilityUseW3CPointerEventsForHover: () => false,
};

module.exports = ReactNativeFeatureFlags;
export default ReactNativeFeatureFlags;
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ const ReactNativeRuntimeDiagnostics: RuntimeDiagnostics = {
},
};

module.exports = ReactNativeRuntimeDiagnostics;
export default ReactNativeRuntimeDiagnostics;
6 changes: 3 additions & 3 deletions packages/react-native/Libraries/ReactNative/UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function isFabricReactTag(reactTag: number): boolean {

const UIManagerImpl: UIManagerJSInterface =
global.RN$Bridgeless === true
? require('./BridgelessUIManager')
: require('./PaperUIManager');
? require('./BridgelessUIManager').default
: require('./PaperUIManager').default;

// $FlowFixMe[cannot-spread-interface]
const UIManager: UIManagerJSInterface = {
Expand Down Expand Up @@ -190,4 +190,4 @@ const UIManager: UIManagerJSInterface = {
},
};

module.exports = UIManager;
export default UIManager;
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ const UIManagerProperties: $ReadOnlyArray<string> = [
'lazilyLoadView',
];

module.exports = UIManagerProperties;
export default UIManagerProperties;
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const insetsDiffer = require('../Utilities/differ/insetsDiffer');
const matricesDiffer = require('../Utilities/differ/matricesDiffer');
const pointsDiffer = require('../Utilities/differ/pointsDiffer');
const sizesDiffer = require('../Utilities/differ/sizesDiffer');
const UIManager = require('./UIManager');
const UIManager = require('./UIManager').default;
const nullthrows = require('nullthrows');

function getNativeComponentAttributes(uiViewClassName: string): any {
Expand Down Expand Up @@ -209,4 +209,4 @@ function getProcessorForType(typeName: string): ?(nextProp: any) => any {
return null;
}

module.exports = getNativeComponentAttributes;
export default getNativeComponentAttributes;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';

const createReactNativeComponentClass =
require('../Renderer/shims/createReactNativeComponentClass').default;
const getNativeComponentAttributes = require('./getNativeComponentAttributes');
const getNativeComponentAttributes =
require('./getNativeComponentAttributes').default;

/**
* Creates values that can be used like React components which represent native
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module.exports = {
return require('../Components/TextInput/TextInputState');
},
get UIManager(): UIManager {
return require('../ReactNative/UIManager');
return require('../ReactNative/UIManager').default;
},
// TODO: Remove when React has migrated to `createAttributePayload` and `diffAttributePayloads`
get deepDiffer(): deepDiffer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const UIManager = require('../../ReactNative/UIManager');
const UIManager = require('../../ReactNative/UIManager').default;
const codegenNativeComponent = require('../codegenNativeComponent').default;

// We need to unmock requireNativeComponent since it's under test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7452,7 +7452,7 @@ declare const AppRegistry: {
startHeadlessTask(taskId: number, taskKey: string, data: any): void,
cancelHeadlessTask(taskId: number, taskKey: string): void,
};
declare module.exports: AppRegistry;
declare export default typeof AppRegistry;
"
`;

Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ module.exports = {
return require('./Libraries/Utilities/Appearance');
},
get AppRegistry(): AppRegistry {
return require('./Libraries/ReactNative/AppRegistry');
return require('./Libraries/ReactNative/AppRegistry').default;
},
get AppState(): AppState {
return require('./Libraries/AppState/AppState');
Expand Down Expand Up @@ -263,7 +263,7 @@ module.exports = {
return require('./Libraries/ReactNative/RendererProxy').findNodeHandle;
},
get I18nManager(): I18nManager {
return require('./Libraries/ReactNative/I18nManager');
return require('./Libraries/ReactNative/I18nManager').default;
},
get InteractionManager(): InteractionManager {
return require('./Libraries/Interaction/InteractionManager');
Expand Down Expand Up @@ -328,7 +328,7 @@ module.exports = {
return require('./Libraries/TurboModule/TurboModuleRegistry');
},
get UIManager(): UIManager {
return require('./Libraries/ReactNative/UIManager');
return require('./Libraries/ReactNative/UIManager').default;
},
get unstable_batchedUpdates(): $PropertyType<
ReactNative,
Expand Down

0 comments on commit 60c1f42

Please sign in to comment.