Converted some left-over JavaScript file to TypeScript
Summary: Found some errors in a CI failure originating from a JavaScript file. The horror! Reviewed By: jknoxville Differential Revision: D29549998 fbshipit-source-id: 633100ec9a446050bb0c703dcc37e9b132b17198
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9ca8bee208
commit
04ec026034
@@ -16,16 +16,17 @@
|
||||
|
||||
// // const DevSettings = require('./DevSettings');
|
||||
import invariant from 'invariant';
|
||||
// @ts-ignore
|
||||
import {default as MetroHMRClient} from 'metro-runtime/src/modules/HMRClient';
|
||||
// // const Platform = require('./Platform');
|
||||
import prettyFormat from 'pretty-format';
|
||||
|
||||
const pendingEntryPoints = [];
|
||||
let hmrClient = null;
|
||||
let hmrUnavailableReason = null;
|
||||
let currentCompileErrorMessage = null;
|
||||
const pendingEntryPoints: string[] = [];
|
||||
let hmrClient: any = null;
|
||||
let hmrUnavailableReason: null | string = null;
|
||||
let currentCompileErrorMessage: null | string = null;
|
||||
let didConnect = false;
|
||||
const pendingLogs = [];
|
||||
const pendingLogs: [string, any][] = [];
|
||||
|
||||
/**
|
||||
* HMR Client that receives from the server HMR updates and propagates them
|
||||
@@ -75,13 +76,13 @@ const HMRClient = {
|
||||
hmrClient.disable();
|
||||
},
|
||||
|
||||
registerBundle(requestUrl) {
|
||||
registerBundle(requestUrl: string) {
|
||||
invariant(hmrClient, 'Expected HMRClient.setup() call at startup.');
|
||||
pendingEntryPoints.push(requestUrl);
|
||||
registerBundleEntryPoints(hmrClient);
|
||||
},
|
||||
|
||||
log(level, data) {
|
||||
log(level: string, data: any) {
|
||||
if (!hmrClient) {
|
||||
// Catch a reasonable number of early logs
|
||||
// in case hmrClient gets initialized later.
|
||||
@@ -96,7 +97,7 @@ const HMRClient = {
|
||||
JSON.stringify({
|
||||
type: 'log',
|
||||
level,
|
||||
data: data.map((item) =>
|
||||
data: data.map((item: any) =>
|
||||
typeof item === 'string'
|
||||
? item
|
||||
: prettyFormat(item, {
|
||||
@@ -104,7 +105,7 @@ const HMRClient = {
|
||||
highlight: true,
|
||||
maxDepth: 3,
|
||||
min: true,
|
||||
plugins: [prettyFormat.plugins.ReactElement],
|
||||
plugins: [(prettyFormat as any).plugins.ReactElement],
|
||||
}),
|
||||
),
|
||||
}),
|
||||
@@ -117,7 +118,13 @@ const HMRClient = {
|
||||
|
||||
// Called once by the bridge on startup, even if Fast Refresh is off.
|
||||
// It creates the HMR client but doesn't actually set up the socket yet.
|
||||
setup(platform, bundleEntry, host, port, isEnabled) {
|
||||
setup(
|
||||
platform: string,
|
||||
bundleEntry: string,
|
||||
host: string,
|
||||
port: string,
|
||||
isEnabled: boolean,
|
||||
) {
|
||||
invariant(platform, 'Missing required parameter `platform`');
|
||||
invariant(bundleEntry, 'Missing required parameter `bundleEntry`');
|
||||
invariant(host, 'Missing required parameter `host`');
|
||||
@@ -133,7 +140,7 @@ const HMRClient = {
|
||||
`ws://${wsHost}/hot?bundleEntry=${bundleEntry}&platform=${platform}`,
|
||||
);
|
||||
|
||||
client.on('connection-error', (e) => {
|
||||
client.on('connection-error', (e: any) => {
|
||||
let error = `Cannot connect to the Metro server.
|
||||
Try the following to fix the issue:
|
||||
- Ensure that the Metro server is running and available on the same network`;
|
||||
@@ -150,7 +157,7 @@ Error: ${e.message}`;
|
||||
setHMRUnavailableReason(error);
|
||||
});
|
||||
|
||||
client.on('update-start', ({isInitialUpdate}) => {
|
||||
client.on('update-start', ({isInitialUpdate}: any) => {
|
||||
currentCompileErrorMessage = null;
|
||||
didConnect = true;
|
||||
|
||||
@@ -160,7 +167,7 @@ Error: ${e.message}`;
|
||||
}
|
||||
});
|
||||
|
||||
client.on('update', ({isInitialUpdate}) => {
|
||||
client.on('update', ({isInitialUpdate}: any) => {
|
||||
if (client.isEnabled() && !isInitialUpdate) {
|
||||
dismissRedbox();
|
||||
//// LogBoxData.clear();
|
||||
@@ -172,7 +179,7 @@ Error: ${e.message}`;
|
||||
console.log('Loading end');
|
||||
});
|
||||
|
||||
client.on('error', (data) => {
|
||||
client.on('error', (data: any) => {
|
||||
//// LoadingView.hide();
|
||||
console.log('Loading end');
|
||||
|
||||
@@ -194,7 +201,7 @@ Error: ${e.message}`;
|
||||
}
|
||||
});
|
||||
|
||||
client.on('close', (data) => {
|
||||
client.on('close', (data: any) => {
|
||||
//// LoadingView.hide();
|
||||
console.log('Loading end');
|
||||
setHMRUnavailableReason('Disconnected from the Metro server.');
|
||||
@@ -211,7 +218,7 @@ Error: ${e.message}`;
|
||||
},
|
||||
};
|
||||
|
||||
function setHMRUnavailableReason(reason) {
|
||||
function setHMRUnavailableReason(reason: string) {
|
||||
invariant(hmrClient, 'Expected HMRClient.setup() call at startup.');
|
||||
if (hmrUnavailableReason !== null) {
|
||||
// Don't show more than one warning.
|
||||
@@ -228,7 +235,7 @@ function setHMRUnavailableReason(reason) {
|
||||
}
|
||||
}
|
||||
|
||||
function registerBundleEntryPoints(client) {
|
||||
function registerBundleEntryPoints(client: any) {
|
||||
if (hmrUnavailableReason) {
|
||||
// // DevSettings.reload('Bundle Splitting – Metro disconnected');
|
||||
console.log('Bundle Spliiting - Metro disconnected');
|
||||
@@ -246,7 +253,7 @@ function registerBundleEntryPoints(client) {
|
||||
}
|
||||
}
|
||||
|
||||
function flushEarlyLogs(client) {
|
||||
function flushEarlyLogs(_client: any) {
|
||||
try {
|
||||
pendingLogs.forEach(([level, data]) => {
|
||||
HMRClient.log(level, data);
|
||||
@@ -287,7 +294,7 @@ function showCompileError() {
|
||||
const error = new Error(message);
|
||||
// Symbolicating compile errors is wasted effort
|
||||
// because the stack trace is meaningless:
|
||||
error.preventSymbolication = true;
|
||||
(error as any).preventSymbolication = true;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {formatError} from '../ShareSheetErrorList.tsx';
|
||||
import {formatError} from '../ShareSheetErrorList';
|
||||
|
||||
test('normal error is formatted', () => {
|
||||
const e = new Error('something went wrong');
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
import {default as HmrClient} from './HMRClient';
|
||||
// @ts-ignore
|
||||
import {default as ReactRefreshRuntime} from 'react-refresh/runtime';
|
||||
|
||||
HmrClient.setup(
|
||||
@@ -21,7 +22,7 @@ HmrClient.setup(
|
||||
ReactRefreshRuntime.injectIntoGlobalHook(window);
|
||||
|
||||
const Refresh = {
|
||||
performFullRefresh(reason) {
|
||||
performFullRefresh(reason: string) {
|
||||
console.log('Perform full refresh', reason);
|
||||
window.location.reload();
|
||||
},
|
||||
@@ -46,7 +47,7 @@ const Refresh = {
|
||||
},
|
||||
};
|
||||
|
||||
require.Refresh = Refresh;
|
||||
(require as any).Refresh = Refresh;
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
require('./init.tsx');
|
||||
@@ -7,8 +7,8 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {IdlerImpl, TestIdler} from '../Idler.tsx';
|
||||
import {sleep} from '../promiseTimeout.tsx';
|
||||
import {IdlerImpl, TestIdler} from '../Idler';
|
||||
import {sleep} from '../promiseTimeout';
|
||||
|
||||
test('Idler should interrupt', async () => {
|
||||
const idler = new IdlerImpl();
|
||||
@@ -64,7 +64,7 @@ test('TestIdler can be controlled', async () => {
|
||||
expect(idler.shouldIdle()).toBe(true);
|
||||
|
||||
let threw = false;
|
||||
const p = idler.idle().catch((e) => {
|
||||
const p = idler.idle().catch((e: any) => {
|
||||
threw = true;
|
||||
expect(e).toMatchInlineSnapshot(
|
||||
`[CancelledPromiseError: Idler got killed]`,
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import adbConfig from '../adbConfig.tsx';
|
||||
import adbConfig from '../adbConfig';
|
||||
|
||||
test('get host and port from ADB_SERVER_SOCKET', () => {
|
||||
process.env.ANDROID_ADB_SERVER_PORT = undefined;
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {parseFlipperPorts} from '../environmentVariables.tsx';
|
||||
import {parseFlipperPorts} from '../environmentVariables';
|
||||
|
||||
test('Valid port overrides are parsed correctly', () => {
|
||||
const overrides = parseFlipperPorts('1111,2222');
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import JsonFileStorage from '../jsonFileReduxPersistStorage.tsx';
|
||||
import JsonFileStorage from '../jsonFileReduxPersistStorage';
|
||||
import fs from 'fs';
|
||||
|
||||
const validSerializedData = fs
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {readCurrentRevision} from '../packageMetadata.tsx';
|
||||
import {readCurrentRevision} from '../packageMetadata';
|
||||
|
||||
test('readCurrentRevision does not return something meaningful in dev mode', async () => {
|
||||
const ret = await readCurrentRevision();
|
||||
@@ -7,7 +7,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {default as config, resetConfigForTesting} from '../processConfig.tsx';
|
||||
import {default as config, resetConfigForTesting} from '../processConfig';
|
||||
|
||||
afterEach(() => {
|
||||
resetConfigForTesting();
|
||||
@@ -7,12 +7,12 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import promiseTimeout from '../promiseTimeout.tsx';
|
||||
import promiseTimeout from '../promiseTimeout';
|
||||
|
||||
test('test promiseTimeout for timeout to happen', () => {
|
||||
const promise = promiseTimeout(
|
||||
200,
|
||||
new Promise((resolve, reject) => {
|
||||
new Promise<void>((resolve) => {
|
||||
const id = setTimeout(() => {
|
||||
clearTimeout(id);
|
||||
resolve();
|
||||
@@ -27,7 +27,7 @@ test('test promiseTimeout for timeout to happen', () => {
|
||||
test('test promiseTimeout for timeout not to happen', () => {
|
||||
const promise = promiseTimeout(
|
||||
200,
|
||||
new Promise((resolve, reject) => {
|
||||
new Promise<string | void>((resolve) => {
|
||||
const id = setTimeout(() => {
|
||||
clearTimeout(id);
|
||||
resolve();
|
||||
Reference in New Issue
Block a user