From 9af5c3330c95057526a52a3de4be78af0c24873a Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Tue, 3 Jan 2023 18:09:06 -0800 Subject: [PATCH] ESM LogBox Summary: Changelog: [General][Changed] - ESM Logbox Reviewed By: yungsters Differential Revision: D42202344 fbshipit-source-id: 8b09fb261c61bd3fb3ab8df66e5732046187cdd8 --- Libraries/Core/ExceptionsManager.js | 2 +- Libraries/Core/InitializeCore.js | 2 +- Libraries/Core/__tests__/ExceptionsManager-test.js | 9 ++++++--- Libraries/LogBox/LogBox.js | 2 +- Libraries/LogBox/__tests__/LogBox-test.js | 2 +- Libraries/YellowBox/YellowBoxDeprecated.js | 3 ++- .../YellowBox/__tests__/YellowBoxDeprecated-test.js | 3 ++- index.js | 2 +- 8 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Libraries/Core/ExceptionsManager.js b/Libraries/Core/ExceptionsManager.js index 4616569b4b28ab..e0adb5648a4122 100644 --- a/Libraries/Core/ExceptionsManager.js +++ b/Libraries/Core/ExceptionsManager.js @@ -103,7 +103,7 @@ function reportException( } if (__DEV__) { - const LogBox = require('../LogBox/LogBox'); + const LogBox = require('../LogBox/LogBox').default; LogBox.addException({ ...data, isComponentError: !!e.isComponentError, diff --git a/Libraries/Core/InitializeCore.js b/Libraries/Core/InitializeCore.js index 1379ffd6cbe7d5..827edefeade6ad 100644 --- a/Libraries/Core/InitializeCore.js +++ b/Libraries/Core/InitializeCore.js @@ -40,7 +40,7 @@ require('./setUpSegmentFetcher'); if (__DEV__) { require('./checkNativeVersion'); require('./setUpDeveloperTools'); - require('../LogBox/LogBox').install(); + require('../LogBox/LogBox').default.install(); } require('../ReactNative/AppRegistry'); diff --git a/Libraries/Core/__tests__/ExceptionsManager-test.js b/Libraries/Core/__tests__/ExceptionsManager-test.js index e1dc1f535c1bf6..48d69a7965d2ef 100644 --- a/Libraries/Core/__tests__/ExceptionsManager-test.js +++ b/Libraries/Core/__tests__/ExceptionsManager-test.js @@ -10,7 +10,8 @@ 'use strict'; -const LogBox = require('../../LogBox/LogBox'); +import LogBox from '../../LogBox/LogBox'; + const ExceptionsManager = require('../ExceptionsManager'); const NativeExceptionsManager = require('../NativeExceptionsManager').default; const ReactFiberErrorDialog = require('../ReactFiberErrorDialog').default; @@ -57,9 +58,12 @@ function runExceptionsManagerTests() { let logBoxAddException; beforeEach(() => { + logBoxAddException = jest.fn(); jest.resetModules(); jest.mock('../../LogBox/LogBox', () => ({ - addException: jest.fn(), + default: { + addException: logBoxAddException, + }, })); jest.mock('../NativeExceptionsManager', () => { return { @@ -80,7 +84,6 @@ function runExceptionsManagerTests() { ); jest.spyOn(console, 'error').mockReturnValue(undefined); nativeReportException = NativeExceptionsManager.reportException; - logBoxAddException = LogBox.addException; }); afterEach(() => { diff --git a/Libraries/LogBox/LogBox.js b/Libraries/LogBox/LogBox.js index a597ca5acf9199..22c7596fe063b9 100644 --- a/Libraries/LogBox/LogBox.js +++ b/Libraries/LogBox/LogBox.js @@ -258,4 +258,4 @@ if (__DEV__) { }; } -module.exports = (LogBox: ILogBox); +export default (LogBox: ILogBox); diff --git a/Libraries/LogBox/__tests__/LogBox-test.js b/Libraries/LogBox/__tests__/LogBox-test.js index 2ac93a18f810a1..689c05fd578930 100644 --- a/Libraries/LogBox/__tests__/LogBox-test.js +++ b/Libraries/LogBox/__tests__/LogBox-test.js @@ -12,7 +12,7 @@ 'use strict'; const LogBoxData = require('../Data/LogBoxData'); -const LogBox = require('../LogBox'); +const LogBox = require('../LogBox').default; declare var console: any; diff --git a/Libraries/YellowBox/YellowBoxDeprecated.js b/Libraries/YellowBox/YellowBoxDeprecated.js index be97a77f03610e..78c5b319f557d6 100644 --- a/Libraries/YellowBox/YellowBoxDeprecated.js +++ b/Libraries/YellowBox/YellowBoxDeprecated.js @@ -12,7 +12,8 @@ import type {IgnorePattern} from '../LogBox/Data/LogBoxData'; -const LogBox = require('../LogBox/LogBox'); +import LogBox from '../LogBox/LogBox'; + const React = require('react'); type Props = $ReadOnly<{||}>; diff --git a/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js b/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js index fe642e268e4576..a1d71cc7b5e6e8 100644 --- a/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js +++ b/Libraries/YellowBox/__tests__/YellowBoxDeprecated-test.js @@ -11,7 +11,8 @@ 'use strict'; -const LogBox = require('../../LogBox/LogBox'); +import LogBox from '../../LogBox/LogBox'; + const YellowBox = require('../YellowBoxDeprecated'); describe('YellowBox', () => { diff --git a/index.js b/index.js index 5f4e3fda480e50..7965754840d252 100644 --- a/index.js +++ b/index.js @@ -282,7 +282,7 @@ module.exports = { return require('./Libraries/Linking/Linking'); }, get LogBox(): LogBox { - return require('./Libraries/LogBox/LogBox'); + return require('./Libraries/LogBox/LogBox').default; }, get NativeDialogManagerAndroid(): NativeDialogManagerAndroid { return require('./Libraries/NativeModules/specs/NativeDialogManagerAndroid')