Skip to content

Commit

Permalink
Migrate Libraries/ReactNative/*.js to use export syntax. (#48650)
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 14, 2025
1 parent 8b5e2ea commit 248d783
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 37 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 @@ -22,8 +22,8 @@ import React from 'react';

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,10 +15,11 @@ jest.useFakeTimers({legacyFakeTimers: true});
import type {PressEvent} from '../../Types/CoreEventTypes';
import type {PressabilityConfig} from '../Pressability';

const UIManager = require('../../ReactNative/UIManager');
const Platform = require('../../Utilities/Platform');
import UIManager from '../../ReactNative/UIManager';
import Platform from '../../Utilities/Platform';
import Pressability from '../Pressability';

const HoverState = require('../HoverState');
const Pressability = require('../Pressability').default;
const invariant = require('invariant');

const isWindows = process.platform === 'win32';
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;
1 change: 1 addition & 0 deletions packages/react-native/Libraries/ReactNative/UIManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ export interface UIManagerStatic {

export const UIManager: UIManagerStatic;
export type UIManager = UIManagerStatic;
export default UIManager;
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 @@ -7345,7 +7345,7 @@ exports[`public API should not change unintentionally Libraries/ReactNative/AppC
internal_excludeInspector?: boolean,
|}>;
declare const AppContainer: component(...Props);
declare module.exports: AppContainer;
declare export default typeof AppContainer;
"
`;

Expand Down Expand Up @@ -7445,13 +7445,13 @@ 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;
"
`;

exports[`public API should not change unintentionally Libraries/ReactNative/BridgelessUIManager.js 1`] = `
"declare const UIManagerJS: UIManagerJSInterface & { [string]: any };
declare module.exports: UIManagerJS;
declare export default typeof UIManagerJS;
"
`;

Expand Down Expand Up @@ -7528,7 +7528,7 @@ exports[`public API should not change unintentionally Libraries/ReactNative/Head
`;

exports[`public API should not change unintentionally Libraries/ReactNative/I18nManager.js 1`] = `
"declare module.exports: {
"declare export default {
getConstants: () => I18nManagerConstants,
allowRTL: (shouldAllow: boolean) => void,
forceRTL: (shouldForce: boolean) => void,
Expand Down Expand Up @@ -7559,7 +7559,7 @@ declare export default typeof NativeUIManager;

exports[`public API should not change unintentionally Libraries/ReactNative/PaperUIManager.js 1`] = `
"declare const UIManagerJS: UIManagerJSInterface;
declare module.exports: UIManagerJS;
declare export default typeof UIManagerJS;
"
`;

Expand Down Expand Up @@ -7643,7 +7643,7 @@ exports[`public API should not change unintentionally Libraries/ReactNative/Reac
shouldPressibilityUseW3CPointerEventsForHover: () => boolean,
|};
declare const ReactNativeFeatureFlags: FeatureFlags;
declare module.exports: ReactNativeFeatureFlags;
declare export default typeof ReactNativeFeatureFlags;
"
`;

Expand All @@ -7654,7 +7654,7 @@ exports[`public API should not change unintentionally Libraries/ReactNative/Reac
|};
export type RuntimeDiagnosticFlag = \\"early_js_errors\\" | \\"all\\";
declare const ReactNativeRuntimeDiagnostics: RuntimeDiagnostics;
declare module.exports: ReactNativeRuntimeDiagnostics;
declare export default typeof ReactNativeRuntimeDiagnostics;
"
`;

Expand Down Expand Up @@ -7715,13 +7715,13 @@ declare export function createRootTag(rootTag: number | RootTag): RootTag;

exports[`public API should not change unintentionally Libraries/ReactNative/UIManager.js 1`] = `
"declare const UIManager: UIManagerJSInterface;
declare module.exports: UIManager;
declare export default typeof UIManager;
"
`;

exports[`public API should not change unintentionally Libraries/ReactNative/UIManagerProperties.js 1`] = `
"declare const UIManagerProperties: $ReadOnlyArray<string>;
declare module.exports: UIManagerProperties;
declare export default typeof UIManagerProperties;
"
`;

Expand All @@ -7735,7 +7735,7 @@ declare export default function getCachedComponentWithDisplayName(

exports[`public API should not change unintentionally Libraries/ReactNative/getNativeComponentAttributes.js 1`] = `
"declare function getNativeComponentAttributes(uiViewClassName: string): any;
declare module.exports: getNativeComponentAttributes;
declare export default typeof getNativeComponentAttributes;
"
`;

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 248d783

Please sign in to comment.