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