diff --git a/package.json b/package.json index 598994b20..0769554e4 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@types/react-window": "^1.8.1", "@types/redux-persist": "^4.3.1", "@types/rsocket-core": "^0.0.2", + "@types/tmp": "^0.1.0", "@types/uuid": "^3.4.5", "@typescript-eslint/eslint-plugin": "^1.11.0", "@typescript-eslint/parser": "^1.13.0", diff --git a/src/App.tsx b/src/App.tsx index d4c386a65..395b0ece2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,7 +32,7 @@ import { ACTIVE_SHEET_SELECT_PLUGINS_TO_EXPORT, ACTIVE_SHEET_PLUGIN_SHEET, } from './reducers/application'; -import {Logger} from './fb-interfaces/Logger.js'; +import {Logger} from './fb-interfaces/Logger'; import BugReporter from './fb-stubs/BugReporter'; import BaseDevice from './devices/BaseDevice'; import {State as Store} from './reducers/index'; diff --git a/src/Client.tsx b/src/Client.tsx index 586d00d37..1dad3e497 100644 --- a/src/Client.tsx +++ b/src/Client.tsx @@ -8,7 +8,7 @@ import {FlipperPlugin, FlipperDevicePlugin} from './plugin'; import BaseDevice, {OS} from './devices/BaseDevice'; import {App} from './App.js'; -import {Logger} from './fb-interfaces/Logger.js'; +import {Logger} from './fb-interfaces/Logger'; import {Store} from './reducers/index'; import {setPluginState} from './reducers/pluginStates'; import {RSocketClientSocket} from 'rsocket-core/RSocketClient'; diff --git a/src/chrome/ShareSheet.tsx b/src/chrome/ShareSheet.tsx index f96a3b5a7..f3b00f72c 100644 --- a/src/chrome/ShareSheet.tsx +++ b/src/chrome/ShareSheet.tsx @@ -18,7 +18,7 @@ import { } from 'flipper'; import React, {Component} from 'react'; import {setExportStatusComponent, unsetShare} from '../reducers/application'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {Idler} from '../utils/Idler'; import {shareFlipperData, DataExportResult} from '../fb-stubs/user'; import {exportStore, EXPORT_FLIPPER_TRACE_EVENT} from '../utils/exportData'; diff --git a/src/chrome/ShareSheetExportFile.tsx b/src/chrome/ShareSheetExportFile.tsx index 8c91c9e95..58f088e56 100644 --- a/src/chrome/ShareSheetExportFile.tsx +++ b/src/chrome/ShareSheetExportFile.tsx @@ -19,7 +19,7 @@ import {setExportStatusComponent, unsetShare} from '../reducers/application'; import {reportPlatformFailures} from '../utils/metrics'; import CancellableExportStatus from './CancellableExportStatus'; import {performance} from 'perf_hooks'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {Idler} from '../utils/Idler'; import { exportStoreToFile, diff --git a/src/dispatcher/androidDevice.tsx b/src/dispatcher/androidDevice.tsx index 6dd28ec1f..3ebbbea7b 100644 --- a/src/dispatcher/androidDevice.tsx +++ b/src/dispatcher/androidDevice.tsx @@ -9,7 +9,7 @@ import AndroidDevice from '../devices/AndroidDevice'; import child_process from 'child_process'; import {Store} from '../reducers/index'; import BaseDevice from '../devices/BaseDevice'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {registerDeviceCallbackOnPlugins} from '../utils/onRegisterDevice'; import {getAdbClient} from '../utils/adbClient'; import {default as which} from 'which'; diff --git a/src/dispatcher/application.tsx b/src/dispatcher/application.tsx index 1fb1bc6c4..3b982e97c 100644 --- a/src/dispatcher/application.tsx +++ b/src/dispatcher/application.tsx @@ -8,7 +8,7 @@ import {remote, ipcRenderer} from 'electron'; import {toggleAction} from '../reducers/application'; import {Store} from '../reducers/index.js'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {parseFlipperPorts} from '../utils/environmentVariables'; import { importDataToStore, diff --git a/src/dispatcher/desktopDevice.tsx b/src/dispatcher/desktopDevice.tsx index 1be77280b..7a83950a1 100644 --- a/src/dispatcher/desktopDevice.tsx +++ b/src/dispatcher/desktopDevice.tsx @@ -6,7 +6,7 @@ */ import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import MacDevice from '../devices/MacDevice'; import WindowsDevice from '../devices/WindowsDevice'; diff --git a/src/dispatcher/iOSDevice.tsx b/src/dispatcher/iOSDevice.tsx index e8345be73..e66cdba40 100644 --- a/src/dispatcher/iOSDevice.tsx +++ b/src/dispatcher/iOSDevice.tsx @@ -7,7 +7,7 @@ import {ChildProcess} from 'child_process'; import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {DeviceType} from '../devices/BaseDevice'; import {promisify} from 'util'; import path from 'path'; diff --git a/src/dispatcher/index.tsx b/src/dispatcher/index.tsx index fac1eea97..514f34bc2 100644 --- a/src/dispatcher/index.tsx +++ b/src/dispatcher/index.tsx @@ -15,7 +15,7 @@ import notifications from './notifications'; import plugins from './plugins'; import user from './user'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {Store} from '../reducers/index'; import {Dispatcher} from './types'; diff --git a/src/dispatcher/notifications.tsx b/src/dispatcher/notifications.tsx index b23b59691..ce2366404 100644 --- a/src/dispatcher/notifications.tsx +++ b/src/dispatcher/notifications.tsx @@ -6,7 +6,7 @@ */ import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {PluginNotification} from '../reducers/notifications'; import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import isHeadless from '../utils/isHeadless'; diff --git a/src/dispatcher/plugins.tsx b/src/dispatcher/plugins.tsx index d968816ef..94d9baa46 100644 --- a/src/dispatcher/plugins.tsx +++ b/src/dispatcher/plugins.tsx @@ -6,7 +6,7 @@ */ import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {FlipperPlugin, FlipperDevicePlugin} from '../plugin'; import {State} from '../reducers/plugins'; import React from 'react'; diff --git a/src/dispatcher/server.tsx b/src/dispatcher/server.tsx index 0961c4222..42ba1c878 100644 --- a/src/dispatcher/server.tsx +++ b/src/dispatcher/server.tsx @@ -8,7 +8,7 @@ import Server from '../server'; import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import Client from '../Client.js'; import {UninitializedClient} from '../UninitializedClient'; diff --git a/src/dispatcher/tracking.tsx b/src/dispatcher/tracking.tsx index cbcc3acda..9e62a333c 100644 --- a/src/dispatcher/tracking.tsx +++ b/src/dispatcher/tracking.tsx @@ -10,7 +10,7 @@ import {ipcRenderer} from 'electron'; import {performance} from 'perf_hooks'; import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import Client from '../Client'; export default (store: Store, logger: Logger) => { diff --git a/src/dispatcher/user.tsx b/src/dispatcher/user.tsx index 306dadd4b..4a10e5701 100644 --- a/src/dispatcher/user.tsx +++ b/src/dispatcher/user.tsx @@ -6,7 +6,7 @@ */ import {Store} from '../reducers/index'; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; import {login} from '../reducers/user'; import {getUser, logoutUser} from '../fb-stubs/user'; diff --git a/src/fb-interfaces/Logger.js b/src/fb-interfaces/Logger.tsx similarity index 80% rename from src/fb-interfaces/Logger.js rename to src/fb-interfaces/Logger.tsx index 1f25f3568..e1ae853bf 100644 --- a/src/fb-interfaces/Logger.js +++ b/src/fb-interfaces/Logger.tsx @@ -14,9 +14,9 @@ export type TrackType = | 'operation-cancelled'; export interface Logger { - track(type: TrackType, event: string, data: ?any, plugin?: string): void; + track(type: TrackType, event: string, data?: any, plugin?: string): void; - trackTimeSince(mark: string, eventName: ?string): void; + trackTimeSince(mark: string, eventName?: string | null | undefined): void; info(data: any, category: string): void; diff --git a/src/fb-stubs/ScribeLogger.tsx b/src/fb-stubs/ScribeLogger.tsx index 6dd8648d4..4aa74393d 100644 --- a/src/fb-stubs/ScribeLogger.tsx +++ b/src/fb-stubs/ScribeLogger.tsx @@ -10,7 +10,7 @@ export type ScribeMessage = { message: string; }; -import {Logger} from '../fb-interfaces/Logger.js'; +import {Logger} from '../fb-interfaces/Logger'; export default class ScribeLogger { constructor(logger: Logger) {} diff --git a/src/plugin.tsx b/src/plugin.tsx index 68805d8df..3fa9c0e37 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -7,7 +7,7 @@ import {KeyboardActions} from './MenuBar'; import {App} from './App'; -import {Logger} from './fb-interfaces/Logger.js'; +import {Logger} from './fb-interfaces/Logger'; import Client from './Client'; import {Store, MiddlewareAPI} from './reducers/index'; import {MetricType} from './utils/exportMetrics'; diff --git a/src/plugins/layout/InspectorSidebar.js b/src/plugins/layout/InspectorSidebar.js index d075fca70..134e68a2d 100644 --- a/src/plugins/layout/InspectorSidebar.js +++ b/src/plugins/layout/InspectorSidebar.js @@ -8,7 +8,7 @@ import type {Element} from 'flipper'; import type {PluginClient} from 'flipper'; import type Client from '../../Client.tsx'; -import type {Logger} from '../../fb-interfaces/Logger.js'; +import type {Logger} from '../../fb-interfaces/Logger.tsx'; import { ManagedDataInspector, diff --git a/src/ui/components/elements-inspector/sidebar.tsx b/src/ui/components/elements-inspector/sidebar.tsx index 71b7a5719..f04185b00 100644 --- a/src/ui/components/elements-inspector/sidebar.tsx +++ b/src/ui/components/elements-inspector/sidebar.tsx @@ -8,7 +8,7 @@ import {Element} from './ElementsInspector'; import {PluginClient} from '../../../plugin'; import Client from '../../../Client'; -import {Logger} from '../../../fb-interfaces/Logger.js'; +import {Logger} from '../../../fb-interfaces/Logger'; import Panel from '../Panel'; import ManagedDataInspector from '../data-inspector/ManagedDataInspector'; import {Component} from 'react'; diff --git a/src/utils/CertificateProvider.tsx b/src/utils/CertificateProvider.tsx index d9f520fa8..c54a59f23 100644 --- a/src/utils/CertificateProvider.tsx +++ b/src/utils/CertificateProvider.tsx @@ -14,16 +14,19 @@ import { isInstalled as opensslInstalled, } from './openssl-wrapper-with-promises'; import path from 'path'; -import tmp from 'tmp'; -const tmpFile = promisify(tmp.file); -const tmpDir = promisify(tmp.dir); +import tmp, {DirOptions, FileOptions} from 'tmp'; import iosUtil from '../fb-stubs/iOSContainerUtility'; import {reportPlatformFailures} from './metrics'; import {getAdbClient} from './adbClient'; import * as androidUtil from './androidContainerUtility'; +import os from 'os'; + +const tmpFile = promisify(tmp.file) as ( + options?: FileOptions, +) => Promise; +const tmpDir = promisify(tmp.dir) as (options?: DirOptions) => Promise; // Desktop file paths -const os = require('os'); const caKey = getFilePath('ca.key'); const caCert = getFilePath('ca.crt'); const serverKey = getFilePath('server.key'); @@ -398,7 +401,7 @@ export default class CertificateProvider { }), ) .then(([path, subject]) => { - return new Promise(function(resolve, reject) { + return new Promise(function(resolve, reject) { fs.unlink(path, err => { if (err) { reject(err); @@ -408,7 +411,7 @@ export default class CertificateProvider { }); }); }) - .then((subject: string) => { + .then(subject => { const matches = subject.trim().match(x509SubjectCNRegex); if (!matches || matches.length < 2) { throw new Error(`Cannot extract CN from ${subject}`); @@ -441,14 +444,14 @@ export default class CertificateProvider { if (!fs.existsSync(caKey)) { return this.generateCertificateAuthority(); } - return this.checkCertIsValid(caCert).catch(e => + return this.checkCertIsValid(caCert).catch(() => this.generateCertificateAuthority(), ); } checkCertIsValid(filename: string): Promise { if (!fs.existsSync(filename)) { - return Promise.reject(); + return Promise.reject(new Error(`${filename} does not exist`)); } // openssl checkend is a nice feature but it only checks for certificates // expiring in the future, not those that have already expired. @@ -459,7 +462,7 @@ export default class CertificateProvider { checkend: minCertExpiryWindowSeconds, in: filename, }) - .then(output => undefined) + .then(() => undefined) .catch(e => { console.warn(`Certificate will expire soon: ${filename}`, logTag); throw e; @@ -492,7 +495,9 @@ export default class CertificateProvider { } verifyServerCertWasIssuedByCA() { - const options = {CAfile: caCert}; + const options: { + [key: string]: any; + } = {CAfile: caCert}; options[serverCert] = false; return openssl('verify', options).then(output => { const verified = output.match(/[^:]+: OK/); @@ -534,8 +539,8 @@ export default class CertificateProvider { } return this.checkCertIsValid(serverCert) - .then(_ => this.verifyServerCertWasIssuedByCA()) - .catch(e => this.generateServerCertificate()); + .then(() => this.verifyServerCertWasIssuedByCA()) + .catch(() => this.generateServerCertificate()); } generateServerCertificate(): Promise { @@ -567,7 +572,7 @@ export default class CertificateProvider { } writeToTempFile(content: string): Promise { - return tmpFile().then((path, fd, cleanupCallback) => + return tmpFile().then(path => promisify(fs.writeFile)(path, content).then(_ => path), ); } diff --git a/src/utils/electronCrashReporter.tsx b/src/utils/electronCrashReporter.tsx index 3ef36b6e7..23da428e4 100644 --- a/src/utils/electronCrashReporter.tsx +++ b/src/utils/electronCrashReporter.tsx @@ -10,12 +10,16 @@ import {promisify} from 'util'; import {crashReporter, remote} from 'electron'; import isProduction from '../utils/isProduction'; import constants from '../fb-stubs/constants'; -import {tmpName} from 'tmp'; +import {tmpName as tmpNameCallback, TmpNameOptions} from 'tmp'; import {resolve} from 'path'; +const tmpName = promisify(tmpNameCallback) as ( + options?: TmpNameOptions, +) => Promise; + // Cross platform way to find the /tmp directory or equivalent. // The tempPath set should be persistent across app restarts. -const tempPathPromise: Promise = promisify(tmpName)({ +const tempPathPromise: Promise = tmpName({ template: '/tmp/tmp-XXXXXX', }).then(name => resolve(name, '..', 'flipper')); diff --git a/src/utils/openssl-wrapper-with-promises.tsx b/src/utils/openssl-wrapper-with-promises.tsx index 1b0cf5213..433323256 100644 --- a/src/utils/openssl-wrapper-with-promises.tsx +++ b/src/utils/openssl-wrapper-with-promises.tsx @@ -5,16 +5,17 @@ * @format */ -import {exec as opensslWithCallback} from 'openssl-wrapper'; +import {exec as opensslWithCallback, Action} from 'openssl-wrapper'; import child_process from 'child_process'; -export function openssl(action: string, options: {}): Promise { +export function openssl(action: Action, options: {}): Promise { return new Promise((resolve, reject) => { opensslWithCallback(action, options, (err, buffer) => { if (err) { reject(err); + } else if (buffer) { + resolve(buffer.toString()); } - resolve(buffer.toString()); }); }); } diff --git a/types/openssl-wrapper.d.tsx b/types/openssl-wrapper.d.tsx new file mode 100644 index 000000000..46e26fd6e --- /dev/null +++ b/types/openssl-wrapper.d.tsx @@ -0,0 +1,27 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +declare module 'openssl-wrapper' { + export type Action = + | 'cms.verify' + | 'genrsa' + | 'pkcs12' + | 'req' + | 'req.new' + | 'req.verify' + | 'verify' + | 'rsa' + | 'smime.verify' + | 'x509.req' + | 'x509'; + + export function exec( + action: Action, + options: {[key: string]: string}, + cb: (error: Error | undefined, buffer: Buffer | undefined) => any, + ): void; +} diff --git a/yarn.lock b/yarn.lock index 7b7e117f8..127d56670 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1279,6 +1279,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw== +"@types/tmp@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.1.0.tgz#19cf73a7bcf641965485119726397a096f0049bd" + integrity sha512-6IwZ9HzWbCq6XoQWhxLpDjuADodH/MKXRUIDFudvgjcVdjFknvmR+DNsoUeer4XPrEnrZs04Jj+kfV9pFsrhmA== + "@types/uuid@^3.4.5": version "3.4.5" resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.4.5.tgz#d4dc10785b497a1474eae0ba7f0cb09c0ddfd6eb"