Skip to content

Commit 4d6785b

Browse files
iwoplazafacebook-github-bot
authored andcommitted
Migrate LayoutAnimation and Linking libraries to use export syntax (#49021)
Summary: Pull Request resolved: #49021 ## Motivation Modernising the RN codebase to allow for modern Flow tooling to process it. ## This diff - Migrates files in `Libraries/LayoutAnimation/*.js` and `Libraries/Linking/*.js` to use the `export` syntax. - Updates deep-imports of these files to use `.default` - Updates jest mocks - Updates the current iteration of API snapshots (intended). Changelog: [General][Breaking] - Deep imports to modules inside `Libraries/LayoutAnimation` and `Libraries/Linking` with `require` syntax need to be appended with '.default'. Reviewed By: huntie Differential Revision: D68782429 fbshipit-source-id: c9ea4fadbc44587a165d311b054fcd03444842c8
1 parent 45a2d9c commit 4d6785b

File tree

10 files changed

+38
-31
lines changed

10 files changed

+38
-31
lines changed

packages/react-native/Libraries/Components/Keyboard/__tests__/Keyboard-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* @oncall react_native
1010
*/
1111

12-
const LayoutAnimation = require('../../../LayoutAnimation/LayoutAnimation');
12+
const LayoutAnimation =
13+
require('../../../LayoutAnimation/LayoutAnimation').default;
1314
const dismissKeyboard = require('../../../Utilities/dismissKeyboard');
1415
const Keyboard = require('../Keyboard').default;
1516

packages/react-native/Libraries/Core/setUpDeveloperTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare var console: {[string]: $FlowFixMe};
1919
if (__DEV__) {
2020
// Set up inspector
2121
const JSInspector = require('../JSInspector/JSInspector');
22-
JSInspector.registerAgent(require('../JSInspector/NetworkAgent'));
22+
JSInspector.registerAgent(require('../JSInspector/NetworkAgent').default);
2323

2424
// Note we can't check if console is "native" because it would appear "native" in JSC and Hermes.
2525
// We also can't check any properties that don't exist in the Chrome worker environment.

packages/react-native/Libraries/JSInspector/InspectorAgent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ class InspectorAgent {
2424
}
2525
}
2626

27-
module.exports = InspectorAgent;
27+
export default InspectorAgent;

packages/react-native/Libraries/JSInspector/NetworkAgent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,4 @@ class NetworkAgent extends InspectorAgent {
293293
}
294294
}
295295

296-
module.exports = NetworkAgent;
296+
export default NetworkAgent;

packages/react-native/Libraries/LayoutAnimation/LayoutAnimation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@ const LayoutAnimation = {
197197
setEnabled,
198198
};
199199

200-
module.exports = LayoutAnimation;
200+
export default LayoutAnimation;

packages/react-native/Libraries/Linking/Linking.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import {NativeEventEmitter} from '../EventEmitter/NativeEventEmitter';
1111
import {EmitterSubscription} from '../vendor/emitter/EventEmitter';
1212

13-
export interface LinkingStatic extends NativeEventEmitter {
13+
export interface LinkingImpl extends NativeEventEmitter {
1414
/**
1515
* Add a handler to Linking changes by listening to the `url` event type
1616
* and providing the handler
@@ -57,5 +57,5 @@ export interface LinkingStatic extends NativeEventEmitter {
5757
): Promise<void>;
5858
}
5959

60-
export const Linking: LinkingStatic;
61-
export type Linking = LinkingStatic;
60+
export const Linking: LinkingImpl;
61+
export type Linking = LinkingImpl;

packages/react-native/Libraries/Linking/Linking.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ type LinkingEventDefinitions = {
2121
url: [{url: string}],
2222
};
2323

24-
/**
25-
* `Linking` gives you a general interface to interact with both incoming
26-
* and outgoing app links.
27-
*
28-
* See https://reactnative.dev/docs/linking
29-
*/
30-
class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
24+
class LinkingImpl extends NativeEventEmitter<LinkingEventDefinitions> {
3125
constructor() {
3226
super(Platform.OS === 'ios' ? nullthrows(NativeLinkingManager) : undefined);
3327
}
@@ -129,4 +123,12 @@ class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
129123
}
130124
}
131125

132-
module.exports = (new Linking(): Linking);
126+
const Linking: LinkingImpl = new LinkingImpl();
127+
128+
/**
129+
* `Linking` gives you a general interface to interact with both incoming
130+
* and outgoing app links.
131+
*
132+
* See https://reactnative.dev/docs/linking
133+
*/
134+
export default Linking;

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5406,7 +5406,7 @@ declare class InspectorAgent {
54065406
constructor(eventSender: EventSender): void;
54075407
sendEvent(name: string, params: mixed): void;
54085408
}
5409-
declare module.exports: InspectorAgent;
5409+
declare export default typeof InspectorAgent;
54105410
"
54115411
`;
54125412

@@ -5461,7 +5461,7 @@ declare class NetworkAgent extends InspectorAgent {
54615461
};
54625462
interceptor(): Interceptor;
54635463
}
5464-
declare module.exports: NetworkAgent;
5464+
declare export default typeof NetworkAgent;
54655465
"
54665466
`;
54675467

@@ -5497,15 +5497,15 @@ declare const LayoutAnimation: {
54975497
spring: (onAnimationDidEnd?: OnAnimationDidEndCallback) => void,
54985498
setEnabled: setEnabled,
54995499
};
5500-
declare module.exports: LayoutAnimation;
5500+
declare export default typeof LayoutAnimation;
55015501
"
55025502
`;
55035503

55045504
exports[`public API should not change unintentionally Libraries/Linking/Linking.js 1`] = `
55055505
"type LinkingEventDefinitions = {
55065506
url: [{ url: string }],
55075507
};
5508-
declare class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
5508+
declare class LinkingImpl extends NativeEventEmitter<LinkingEventDefinitions> {
55095509
constructor(): void;
55105510
addEventListener<K: $Keys<LinkingEventDefinitions>>(
55115511
eventType: K,
@@ -5525,7 +5525,8 @@ declare class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
55255525
): Promise<void>;
55265526
_validateURL(url: string): void;
55275527
}
5528-
declare module.exports: Linking;
5528+
declare const Linking: LinkingImpl;
5529+
declare export default typeof Linking;
55295530
"
55305531
`;
55315532

packages/react-native/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,10 @@ module.exports = {
277277
return require('./Libraries/Components/Keyboard/Keyboard').default;
278278
},
279279
get LayoutAnimation(): LayoutAnimation {
280-
return require('./Libraries/LayoutAnimation/LayoutAnimation');
280+
return require('./Libraries/LayoutAnimation/LayoutAnimation').default;
281281
},
282282
get Linking(): Linking {
283-
return require('./Libraries/Linking/Linking');
283+
return require('./Libraries/Linking/Linking').default;
284284
},
285285
get LogBox(): LogBox {
286286
return require('./Libraries/LogBox/LogBox').default;

packages/react-native/jest/setup.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,17 @@ jest
236236
},
237237
}))
238238
.mock('../Libraries/Linking/Linking', () => ({
239-
openURL: jest.fn(),
240-
canOpenURL: jest.fn(() => Promise.resolve(true)),
241-
openSettings: jest.fn(),
242-
addEventListener: jest.fn(() => ({
243-
remove: jest.fn(),
244-
})),
245-
getInitialURL: jest.fn(() => Promise.resolve()),
246-
sendIntent: jest.fn(),
239+
__esModule: true,
240+
default: {
241+
openURL: jest.fn(),
242+
canOpenURL: jest.fn(() => Promise.resolve(true)),
243+
openSettings: jest.fn(),
244+
addEventListener: jest.fn(() => ({
245+
remove: jest.fn(),
246+
})),
247+
getInitialURL: jest.fn(() => Promise.resolve()),
248+
sendIntent: jest.fn(),
249+
},
247250
}))
248251
// Mock modules defined by the native layer (ex: Objective-C, Java)
249252
.mock('../Libraries/BatchedBridge/NativeModules', () => ({

0 commit comments

Comments
 (0)