Skip to content

Commit c89c5d7

Browse files
iwoplazafacebook-github-bot
authored andcommitted
Migrated Alert/*.js and ActionSheetIOS/*.js to use export syntax. (#48703)
Summary: Pull Request resolved: #48703 ## Motivation Modernising the react-native codebase to allow for ingestion by modern Flow tooling ## This diff - Updates files in Libraries/Alert and Libraries/ActionSheetIOS to use `export` syntax - `export default` for qualified objects, many `export` statements for collections (determined by how it's imported) - Appends `.default` to requires of the changed files. - Updates Jest mocks of the related modules - Updates the public API snapshot (intented breaking change) Changelog: [General][Breaking] - Files inside `Libraries/Alert` and `Libraries/ActionSheetIOS` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax. Differential Revision: D68210738 fbshipit-source-id: a984034b165908f75485f2bad33fcccadd865494
1 parent 1126bbb commit c89c5d7

File tree

10 files changed

+14
-14
lines changed

10 files changed

+14
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ const ActionSheetIOS = {
172172
},
173173
};
174174

175-
module.exports = ActionSheetIOS;
175+
export default ActionSheetIOS;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ class Alert {
174174
}
175175
}
176176

177-
module.exports = Alert;
177+
export default Alert;

packages/react-native/Libraries/Alert/RCTAlertManager.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import NativeDialogManagerAndroid from '../NativeModules/specs/NativeDialogManag
1111

1212
function emptyCallback() {}
1313

14-
module.exports = {
14+
export default {
1515
alertWithArgs: function (args, callback) {
1616
// TODO(5998984): Polyfill it correctly with DialogManagerAndroid
1717
if (!NativeDialogManagerAndroid) {

packages/react-native/Libraries/Alert/RCTAlertManager.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {Args} from './NativeAlertManager';
1212

1313
import NativeAlertManager from './NativeAlertManager';
1414

15-
module.exports = {
15+
export default {
1616
alertWithArgs(
1717
args: Args,
1818
callback: (id: number, value: string) => void,

packages/react-native/Libraries/Alert/RCTAlertManager.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import type {Args} from './NativeAlertManager';
1212

13-
declare module.exports: {
13+
declare export default {
1414
alertWithArgs(
1515
args: Args,
1616
callback: (id: number, value: string) => void,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ if (global?.HermesInternal?.hasPromise?.()) {
3434
);
3535
}
3636
} else {
37-
polyfillGlobal('Promise', () => require('../Promise'));
37+
polyfillGlobal('Promise', () => require('../Promise').default);
3838
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ if (!global.alert) {
1818
global.alert = function (text: string) {
1919
// Require Alert on demand. Requiring it too early can lead to issues
2020
// with things like Platform not being fully initialized.
21-
require('../Alert/Alert').alert('Alert', '' + text);
21+
require('../Alert/Alert').default.alert('Alert', '' + text);
2222
};
2323
}

packages/react-native/Libraries/Promise.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ if (__DEV__) {
2020
);
2121
}
2222

23-
module.exports = Promise;
23+
export default Promise;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exports[`public API should not change unintentionally Libraries/ActionSheetIOS/A
2525
): void,
2626
dismissActionSheet: () => void,
2727
};
28-
declare module.exports: ActionSheetIOS;
28+
declare export default typeof ActionSheetIOS;
2929
"
3030
`;
3131

@@ -72,7 +72,7 @@ declare class Alert {
7272
options?: Options
7373
): void;
7474
}
75-
declare module.exports: Alert;
75+
declare export default typeof Alert;
7676
"
7777
`;
7878

@@ -83,7 +83,7 @@ declare export default typeof NativeAlertManager;
8383
`;
8484

8585
exports[`public API should not change unintentionally Libraries/Alert/RCTAlertManager.js.flow 1`] = `
86-
"declare module.exports: {
86+
"declare export default {
8787
alertWithArgs(
8888
args: Args,
8989
callback: (id: number, value: string) => void
@@ -7203,7 +7203,7 @@ exports[`public API should not change unintentionally Libraries/Pressability/use
72037203

72047204
exports[`public API should not change unintentionally Libraries/Promise.js 1`] = `
72057205
"declare const Promise: $FlowFixMe;
7206-
declare module.exports: Promise;
7206+
declare export default typeof Promise;
72077207
"
72087208
`;
72097209

packages/react-native/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ module.exports = {
212212

213213
// APIs
214214
get ActionSheetIOS(): ActionSheetIOS {
215-
return require('./Libraries/ActionSheetIOS/ActionSheetIOS');
215+
return require('./Libraries/ActionSheetIOS/ActionSheetIOS').default;
216216
},
217217
get Alert(): Alert {
218-
return require('./Libraries/Alert/Alert');
218+
return require('./Libraries/Alert/Alert').default;
219219
},
220220
// Include any types exported in the Animated module together with its default export, so
221221
// you can references types such as Animated.Numeric

0 commit comments

Comments
 (0)