Skip to content

Commit

Permalink
Migrated Libraries/WebSocket/* to export syntax. (#48884)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #48884

## Motivation
Modernising the react-native codebase to allow for ingestion by modern Flow tooling.

## This diff
- Updates files in `Libraries/WebSocket` to use `export` syntax
- Appends `.default` to requires of the changed files.
- Updates mocks.
- Updates the public API snapshot (intented breaking change)

Changelog:
[General][Breaking] - Files inside `Libraries/WebSocket` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax.

Reviewed By: cortinico

Differential Revision: D68554260

fbshipit-source-id: 90a660fe9e76b255171189101819253521354fda
  • Loading branch information
iwoplaza authored and facebook-github-bot committed Jan 23, 2025
1 parent b8ee2b3 commit 7df73ee
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Core/setUpReactDevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ if (__DEV__) {
? window.__REACT_DEVTOOLS_PORT__
: 8097;

const WebSocket = require('../WebSocket/WebSocket');
const WebSocket = require('../WebSocket/WebSocket').default;
ws = new WebSocket('ws://' + host + ':' + port);
ws.addEventListener('close', event => {
isWebSocketOpen = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Core/setUpXHR.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ polyfillGlobal('fetch', () => require('../Network/fetch').fetch);
polyfillGlobal('Headers', () => require('../Network/fetch').Headers);
polyfillGlobal('Request', () => require('../Network/fetch').Request);
polyfillGlobal('Response', () => require('../Network/fetch').Response);
polyfillGlobal('WebSocket', () => require('../WebSocket/WebSocket'));
polyfillGlobal('WebSocket', () => require('../WebSocket/WebSocket').default);
polyfillGlobal('Blob', () => require('../Blob/Blob').default);
polyfillGlobal('File', () => require('../Blob/File').default);
polyfillGlobal('FileReader', () => require('../Blob/FileReader').default);
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/Libraries/Inspector/NetworkOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const FlatList = require('../Lists/FlatList');
const XHRInterceptor = require('../Network/XHRInterceptor');
const StyleSheet = require('../StyleSheet/StyleSheet');
const Text = require('../Text/Text');
const WebSocketInterceptor = require('../WebSocket/WebSocketInterceptor');
const WebSocketInterceptor =
require('../WebSocket/WebSocketInterceptor').default;

const LISTVIEW_CELL_HEIGHT = 15;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/WebSocket/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,4 @@ class WebSocket extends (EventTarget(...WEBSOCKET_EVENTS): typeof EventTarget) {
}
}

module.exports = WebSocket;
export default WebSocket;
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ class WebSocketEvent {
}
}

module.exports = WebSocketEvent;
export default WebSocketEvent;
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,4 @@ const WebSocketInterceptor = {
},
};

module.exports = WebSocketInterceptor;
export default WebSocketInterceptor;
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function EventTarget() {
}
}

module.exports = EventTarget;
export default EventTarget;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jest.setMock('../../BatchedBridge/NativeModules', {
},
});

const WebSocket = require('../WebSocket');
const WebSocket = require('../WebSocket').default;

describe('WebSocket', function () {
it('should have connection lifecycle constants defined on the class', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9480,7 +9480,7 @@ declare class WebSocket extends EventTarget {
_unregisterEvents(): void;
_registerEvents(): void;
}
declare module.exports: WebSocket;
declare export default typeof WebSocket;
"
`;

Expand All @@ -9489,7 +9489,7 @@ exports[`public API should not change unintentionally Libraries/WebSocket/WebSoc
type: string;
constructor(type: string, eventInitDict: ?{ ... }): void;
}
declare module.exports: WebSocketEvent;
declare export default typeof WebSocketEvent;
"
`;

Expand All @@ -9509,7 +9509,7 @@ exports[`public API should not change unintentionally Libraries/WebSocket/WebSoc
_arrayBufferToString(data: string): ArrayBuffer | string,
disableInterception(): void,
};
declare module.exports: WebSocketInterceptor;
declare export default typeof WebSocketInterceptor;
"
`;

Expand Down

0 comments on commit 7df73ee

Please sign in to comment.