Typescriptify the main process code (7/N)

Summary: Typescriptified static/launcher.js

Reviewed By: passy

Differential Revision: D20066497

fbshipit-source-id: 64fc47086fc599f36f2313406e2c72a76c481fb0
This commit is contained in:
Anton Nikolaev
2020-02-24 19:01:37 -08:00
committed by Facebook Github Bot
parent 8e7ca24e72
commit 64e85f226c
4 changed files with 28 additions and 13 deletions

View File

@@ -73,6 +73,7 @@
"@types/jest": "^25.1.0",
"@types/lodash.debounce": "^4.0.6",
"@types/lodash.isequal": "^4.5.5",
"@types/mkdirp": "^1.0.0",
"@types/node": "^12.12.20",
"@types/react": "^16.9.17",
"@types/react-dom": "^16.9.4",

View File

@@ -7,13 +7,13 @@
* @format
*/
const os = require('os');
const fs = require('fs');
const path = require('path');
const promisify = require('util').promisify;
const {spawn} = require('child_process');
const xdg = require('xdg-basedir');
const mkdirp = require('mkdirp');
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';
const isProduction = () =>
!/node_modules[\\/]electron[\\/]/.test(process.execPath);
@@ -31,7 +31,7 @@ const isLauncherInstalled = () => {
return false;
};
const startLauncher = argv => {
const startLauncher = (argv: {file?: string; url?: string}) => {
const args = [];
if (argv.file) {
args.push('--file', argv.file);
@@ -45,7 +45,7 @@ const startLauncher = argv => {
};
const checkIsCycle = async () => {
const dir = path.join(xdg.cache, 'flipper');
const dir = path.join(xdg.cache!, 'flipper');
const filePath = path.join(dir, 'last-launcher-run');
// This isn't monotonically increasing, so there's a change we get time drift
// between the checks, but the worst case here is that we do two roundtrips
@@ -54,7 +54,10 @@ const checkIsCycle = async () => {
let backThen;
try {
backThen = parseInt(await promisify(fs.readFile)(filePath), 10);
backThen = parseInt(
(await promisify(fs.readFile)(filePath)).toString(),
10,
);
} catch (e) {
backThen = 0;
}
@@ -71,7 +74,11 @@ const checkIsCycle = async () => {
* Runs the launcher if required and returns a boolean based on whether
* it has. You should shut down this instance of the app in that case.
*/
module.exports = async function delegateToLauncher(argv) {
export default async function delegateToLauncher(argv: {
launcher: boolean;
file?: string;
url?: string;
}) {
if (argv.launcher && isProduction() && isLauncherInstalled()) {
if (await checkIsCycle()) {
console.error(
@@ -89,4 +96,4 @@ module.exports = async function delegateToLauncher(argv) {
}
return false;
};
}

View File

@@ -18,7 +18,7 @@ import fixPath from 'fix-path';
import {exec} from 'child_process';
const compilePlugins = require('./compilePlugins');
import setup from './setup';
const delegateToLauncher = require('./launcher');
import delegateToLauncher from './launcher';
import expandTilde from 'expand-tilde';
import yargs from 'yargs';

View File

@@ -1423,6 +1423,13 @@
dependencies:
"@types/node" "*"
"@types/mkdirp@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-1.0.0.tgz#16ce0eabe4a9a3afe64557ad0ee6886ec3d32927"
integrity sha512-ONFY9//bCEr3DWKON3iDv/Q8LXnhaYYaNDeFSN0AtO5o4sLf9F0pstJKKKjQhXE0kJEeHs8eR6SAsROhhc2Csw==
dependencies:
"@types/node" "*"
"@types/node-fetch@^2.5.4":
version "2.5.4"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.4.tgz#5245b6d8841fc3a6208b82291119bc11c4e0ce44"