Fix Flipper lints #18

Summary: Fixed several lint errors mainly related to Warning/node/no-sync.

Reviewed By: passy

Differential Revision: D31795894

fbshipit-source-id: 020597d93232a8e84b25ea11a87d9481a6d2616f
This commit is contained in:
Roman Karpenko
2021-10-21 03:43:32 -07:00
committed by Facebook GitHub Bot
parent 37498ad5a9
commit 2be631ea4d
3 changed files with 122 additions and 87 deletions

View File

@@ -10,7 +10,6 @@
import os from 'os';
import fs from 'fs';
import path from 'path';
import {promisify} from 'util';
import {spawn} from 'child_process';
import xdg from 'xdg-basedir';
import mkdirp from 'mkdirp';
@@ -18,14 +17,19 @@ import mkdirp from 'mkdirp';
const isProduction = () =>
!/node_modules[\\/]electron[\\/]/.test(process.execPath);
const isLauncherInstalled = () => {
const isLauncherInstalled = async () => {
if (os.type() == 'Darwin') {
const receipt = 'com.facebook.flipper.launcher';
const plistLocation = '/Applications/Flipper.app/Contents/Info.plist';
return (
fs.existsSync(plistLocation) &&
fs.readFileSync(plistLocation).indexOf(receipt) > 0
);
try {
return (
(await fs.promises.stat(plistLocation)) &&
(await fs.promises.readFile(plistLocation)).indexOf(receipt) > 0
);
} catch (e) {
console.error('Error while reading Info.plist', e);
return false;
}
}
return false;
@@ -54,17 +58,14 @@ const checkIsCycle = async () => {
let backThen;
try {
backThen = parseInt(
(await promisify(fs.readFile)(filePath)).toString(),
10,
);
backThen = parseInt((await fs.promises.readFile(filePath)).toString(), 10);
} catch (e) {
backThen = 0;
}
const delta = rightNow - backThen;
await mkdirp(dir);
await promisify(fs.writeFile)(filePath, '' + rightNow);
await fs.promises.writeFile(filePath, '' + rightNow);
// If the last startup was less than 5s ago, something's not okay.
return Math.abs(delta) < 5000;
@@ -79,7 +80,7 @@ export default async function delegateToLauncher(argv: {
file?: string;
url?: string;
}) {
if (argv.launcher && isProduction() && isLauncherInstalled()) {
if (argv.launcher && isProduction() && (await isLauncherInstalled())) {
if (await checkIsCycle()) {
console.error(
'Launcher cycle detected. Not delegating even though I usually would.',