From d504fb4145a95691e145ef9c99da8705a113c5d0 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Tue, 28 Feb 2023 10:23:36 -0800 Subject: [PATCH] Revert ESM imports Summary: Changelog: [Internal] - Remove all imports back to CJS for changelog in 0.72 We are reverting these imports as it may regress perf as we don't have a recommended inlining solution for ES modules at the current time. Reviewed By: NickGerleman Differential Revision: D43630911 fbshipit-source-id: ff3bb80009f327c4d51dad21f2cd287ce46d5964 --- Libraries/ActionSheetIOS/ActionSheetIOS.js | 2 +- Libraries/Image/AssetSourceResolver.js | 3 +-- Libraries/Inspector/ElementBox.js | 3 +-- Libraries/Inspector/Inspector.js | 3 +-- Libraries/Inspector/InspectorOverlay.js | 3 +-- Libraries/Network/XMLHttpRequest.js | 2 +- Libraries/ReactNative/getNativeComponentAttributes.js | 3 +-- Libraries/Share/Share.js | 2 +- Libraries/StyleSheet/StyleSheet.js | 3 +-- Libraries/StyleSheet/__tests__/processColor-test.js | 3 +-- Libraries/Utilities/PixelRatio.js | 2 +- Libraries/YellowBox/YellowBoxDeprecated.js | 3 +-- Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js | 3 +-- jest/mockScrollView.js | 3 ++- packages/babel-plugin-codegen/__test_fixtures__/fixtures.js | 2 +- .../__tests__/__snapshots__/index-test.js.snap | 2 +- 16 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Libraries/ActionSheetIOS/ActionSheetIOS.js b/Libraries/ActionSheetIOS/ActionSheetIOS.js index 3d92cc5074b731..b5959aca24f6fa 100644 --- a/Libraries/ActionSheetIOS/ActionSheetIOS.js +++ b/Libraries/ActionSheetIOS/ActionSheetIOS.js @@ -11,9 +11,9 @@ import type {ProcessedColorValue} from '../StyleSheet/processColor'; import type {ColorValue} from '../StyleSheet/StyleSheet'; -import processColor from '../StyleSheet/processColor'; import RCTActionSheetManager from './NativeActionSheetManager'; +const processColor = require('../StyleSheet/processColor').default; const invariant = require('invariant'); /** diff --git a/Libraries/Image/AssetSourceResolver.js b/Libraries/Image/AssetSourceResolver.js index 34f068adf802b5..d7ae700437b732 100644 --- a/Libraries/Image/AssetSourceResolver.js +++ b/Libraries/Image/AssetSourceResolver.js @@ -20,8 +20,7 @@ export type ResolvedAssetSource = {| import type {PackagerAsset} from '@react-native/assets-registry/registry'; -import PixelRatio from '../Utilities/PixelRatio'; - +const PixelRatio = require('../Utilities/PixelRatio').default; const Platform = require('../Utilities/Platform'); const {pickScale} = require('./AssetUtils'); const { diff --git a/Libraries/Inspector/ElementBox.js b/Libraries/Inspector/ElementBox.js index 96f5cf76454fcf..49c98dbb31e7b1 100644 --- a/Libraries/Inspector/ElementBox.js +++ b/Libraries/Inspector/ElementBox.js @@ -10,11 +10,10 @@ 'use strict'; -import Dimensions from '../Utilities/Dimensions'; - const View = require('../Components/View/View'); const flattenStyle = require('../StyleSheet/flattenStyle'); const StyleSheet = require('../StyleSheet/StyleSheet'); +const Dimensions = require('../Utilities/Dimensions').default; const BorderBox = require('./BorderBox'); const resolveBoxStyle = require('./resolveBoxStyle'); const React = require('react'); diff --git a/Libraries/Inspector/Inspector.js b/Libraries/Inspector/Inspector.js index c09ef3723b5fe3..bc76e794870dbb 100644 --- a/Libraries/Inspector/Inspector.js +++ b/Libraries/Inspector/Inspector.js @@ -13,13 +13,12 @@ import type {TouchedViewDataAtPoint} from '../Renderer/shims/ReactNativeTypes'; import type {HostRef} from './getInspectorDataForViewAtPoint'; -import Dimensions from '../Utilities/Dimensions'; - const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes'); const View = require('../Components/View/View'); const PressabilityDebug = require('../Pressability/PressabilityDebug'); const {findNodeHandle} = require('../ReactNative/RendererProxy'); const StyleSheet = require('../StyleSheet/StyleSheet'); +const Dimensions = require('../Utilities/Dimensions').default; const Platform = require('../Utilities/Platform'); const getInspectorDataForViewAtPoint = require('./getInspectorDataForViewAtPoint'); const InspectorOverlay = require('./InspectorOverlay'); diff --git a/Libraries/Inspector/InspectorOverlay.js b/Libraries/Inspector/InspectorOverlay.js index 6eb639d22d2ca6..0c239f2db51411 100644 --- a/Libraries/Inspector/InspectorOverlay.js +++ b/Libraries/Inspector/InspectorOverlay.js @@ -13,10 +13,9 @@ import type {ViewStyleProp} from '../StyleSheet/StyleSheet'; import type {PressEvent} from '../Types/CoreEventTypes'; -import Dimensions from '../Utilities/Dimensions'; - const View = require('../Components/View/View'); const StyleSheet = require('../StyleSheet/StyleSheet'); +const Dimensions = require('../Utilities/Dimensions').default; const ElementBox = require('./ElementBox'); const React = require('react'); diff --git a/Libraries/Network/XMLHttpRequest.js b/Libraries/Network/XMLHttpRequest.js index 22547c5e25b7cd..f66d194863a457 100644 --- a/Libraries/Network/XMLHttpRequest.js +++ b/Libraries/Network/XMLHttpRequest.js @@ -13,10 +13,10 @@ import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger'; import {type EventSubscription} from '../vendor/emitter/EventEmitter'; -import RCTNetworking from './RCTNetworking'; const BlobManager = require('../Blob/BlobManager'); const GlobalPerformanceLogger = require('../Utilities/GlobalPerformanceLogger'); +const RCTNetworking = require('./RCTNetworking').default; const base64 = require('base64-js'); const EventTarget = require('event-target-shim'); const invariant = require('invariant'); diff --git a/Libraries/ReactNative/getNativeComponentAttributes.js b/Libraries/ReactNative/getNativeComponentAttributes.js index 759918b0d6c8ff..6c9f11f06882f6 100644 --- a/Libraries/ReactNative/getNativeComponentAttributes.js +++ b/Libraries/ReactNative/getNativeComponentAttributes.js @@ -10,10 +10,9 @@ 'use strict'; -import processColor from '../StyleSheet/processColor'; - const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes'); const resolveAssetSource = require('../Image/resolveAssetSource'); +const processColor = require('../StyleSheet/processColor').default; const processColorArray = require('../StyleSheet/processColorArray'); const insetsDiffer = require('../Utilities/differ/insetsDiffer'); const matricesDiffer = require('../Utilities/differ/matricesDiffer'); diff --git a/Libraries/Share/Share.js b/Libraries/Share/Share.js index 2183870105889f..59ffde5133629e 100644 --- a/Libraries/Share/Share.js +++ b/Libraries/Share/Share.js @@ -9,9 +9,9 @@ */ import NativeActionSheetManager from '../ActionSheetIOS/NativeActionSheetManager'; -import processColor from '../StyleSheet/processColor'; import NativeShareModule from './NativeShareModule'; +const processColor = require('../StyleSheet/processColor').default; const Platform = require('../Utilities/Platform'); const invariant = require('invariant'); diff --git a/Libraries/StyleSheet/StyleSheet.js b/Libraries/StyleSheet/StyleSheet.js index 0d830033d73fa9..523cd748423c4d 100644 --- a/Libraries/StyleSheet/StyleSheet.js +++ b/Libraries/StyleSheet/StyleSheet.js @@ -23,9 +23,8 @@ import type { ____ViewStyleProp_Internal, } from './StyleSheetTypes'; -import PixelRatio from '../Utilities/PixelRatio'; - const ReactNativeStyleAttributes = require('../Components/View/ReactNativeStyleAttributes'); +const PixelRatio = require('../Utilities/PixelRatio').default; const flatten = require('./flattenStyle'); /** diff --git a/Libraries/StyleSheet/__tests__/processColor-test.js b/Libraries/StyleSheet/__tests__/processColor-test.js index 607ddaa9ff7a36..8761fc0d156505 100644 --- a/Libraries/StyleSheet/__tests__/processColor-test.js +++ b/Libraries/StyleSheet/__tests__/processColor-test.js @@ -10,8 +10,6 @@ 'use strict'; -import processColor from '../processColor'; - const {OS} = require('../../Utilities/Platform'); const PlatformColorAndroid = require('../PlatformColorValueTypes.android').PlatformColor; @@ -19,6 +17,7 @@ const PlatformColorIOS = require('../PlatformColorValueTypes.ios').PlatformColor; const DynamicColorIOS = require('../PlatformColorValueTypesIOS.ios').DynamicColorIOS; +const processColor = require('../processColor').default; const platformSpecific = OS === 'android' diff --git a/Libraries/Utilities/PixelRatio.js b/Libraries/Utilities/PixelRatio.js index 3cfb6b7783d42d..e69b62730d4d47 100644 --- a/Libraries/Utilities/PixelRatio.js +++ b/Libraries/Utilities/PixelRatio.js @@ -10,7 +10,7 @@ 'use strict'; -import Dimensions from './Dimensions'; +const Dimensions = require('./Dimensions').default; /** * PixelRatio class gives access to the device pixel density. diff --git a/Libraries/YellowBox/YellowBoxDeprecated.js b/Libraries/YellowBox/YellowBoxDeprecated.js index 78c5b319f557d6..a0d0d3c8ace21e 100644 --- a/Libraries/YellowBox/YellowBoxDeprecated.js +++ b/Libraries/YellowBox/YellowBoxDeprecated.js @@ -12,8 +12,7 @@ import type {IgnorePattern} from '../LogBox/Data/LogBoxData'; -import LogBox from '../LogBox/LogBox'; - +const LogBox = require('../LogBox/LogBox').default; const React = require('react'); type Props = $ReadOnly<{||}>; diff --git a/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js b/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js index a1d71cc7b5e6e8..c0ffbf8d833e0d 100644 --- a/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js +++ b/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js @@ -11,8 +11,7 @@ 'use strict'; -import LogBox from '../../LogBox/LogBox'; - +const LogBox = require('../../LogBox/LogBox').default; const YellowBox = require('../YellowBoxDeprecated'); describe('YellowBox', () => { diff --git a/jest/mockScrollView.js b/jest/mockScrollView.js index 59c7cec3392c6c..e8eb6937087615 100644 --- a/jest/mockScrollView.js +++ b/jest/mockScrollView.js @@ -15,7 +15,8 @@ const React = require('react'); const View = require('../Libraries/Components/View/View'); -import requireNativeComponent from '../Libraries/ReactNative/requireNativeComponent'; +const requireNativeComponent = + require('../Libraries/ReactNative/requireNativeComponent').default; const RCTScrollView: $FlowFixMe = requireNativeComponent('RCTScrollView'); function mockScrollView(BaseComponent: $FlowFixMe) { diff --git a/packages/babel-plugin-codegen/__test_fixtures__/fixtures.js b/packages/babel-plugin-codegen/__test_fixtures__/fixtures.js index 61992d8aa33fdf..1aec6340d2f65b 100644 --- a/packages/babel-plugin-codegen/__test_fixtures__/fixtures.js +++ b/packages/babel-plugin-codegen/__test_fixtures__/fixtures.js @@ -10,7 +10,7 @@ 'use strict'; const NOT_A_NATIVE_COMPONENT = ` -import requireNativeComponent from 'requireNativeComponent'; +const requireNativeComponent = require('requireNativeComponent').default; export default 'Not a view config' `; diff --git a/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap b/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap index 68440b3f72baa6..7ea01935ac3a2b 100644 --- a/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap +++ b/packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap @@ -127,7 +127,7 @@ export const Commands = { `; exports[`Babel plugin inline view configs can inline config for NotANativeComponent.js 1`] = ` -"import requireNativeComponent from 'requireNativeComponent'; +"const requireNativeComponent = require('requireNativeComponent').default; export default 'Not a view config';" `;