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:
committed by
Facebook Github Bot
parent
8e7ca24e72
commit
64e85f226c
@@ -73,6 +73,7 @@
|
|||||||
"@types/jest": "^25.1.0",
|
"@types/jest": "^25.1.0",
|
||||||
"@types/lodash.debounce": "^4.0.6",
|
"@types/lodash.debounce": "^4.0.6",
|
||||||
"@types/lodash.isequal": "^4.5.5",
|
"@types/lodash.isequal": "^4.5.5",
|
||||||
|
"@types/mkdirp": "^1.0.0",
|
||||||
"@types/node": "^12.12.20",
|
"@types/node": "^12.12.20",
|
||||||
"@types/react": "^16.9.17",
|
"@types/react": "^16.9.17",
|
||||||
"@types/react-dom": "^16.9.4",
|
"@types/react-dom": "^16.9.4",
|
||||||
|
|||||||
@@ -7,13 +7,13 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const os = require('os');
|
import os from 'os';
|
||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
const promisify = require('util').promisify;
|
import {promisify} from 'util';
|
||||||
const {spawn} = require('child_process');
|
import {spawn} from 'child_process';
|
||||||
const xdg = require('xdg-basedir');
|
import xdg from 'xdg-basedir';
|
||||||
const mkdirp = require('mkdirp');
|
import mkdirp from 'mkdirp';
|
||||||
|
|
||||||
const isProduction = () =>
|
const isProduction = () =>
|
||||||
!/node_modules[\\/]electron[\\/]/.test(process.execPath);
|
!/node_modules[\\/]electron[\\/]/.test(process.execPath);
|
||||||
@@ -31,7 +31,7 @@ const isLauncherInstalled = () => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const startLauncher = argv => {
|
const startLauncher = (argv: {file?: string; url?: string}) => {
|
||||||
const args = [];
|
const args = [];
|
||||||
if (argv.file) {
|
if (argv.file) {
|
||||||
args.push('--file', argv.file);
|
args.push('--file', argv.file);
|
||||||
@@ -45,7 +45,7 @@ const startLauncher = argv => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const checkIsCycle = async () => {
|
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');
|
const filePath = path.join(dir, 'last-launcher-run');
|
||||||
// This isn't monotonically increasing, so there's a change we get time drift
|
// 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
|
// between the checks, but the worst case here is that we do two roundtrips
|
||||||
@@ -54,7 +54,10 @@ const checkIsCycle = async () => {
|
|||||||
|
|
||||||
let backThen;
|
let backThen;
|
||||||
try {
|
try {
|
||||||
backThen = parseInt(await promisify(fs.readFile)(filePath), 10);
|
backThen = parseInt(
|
||||||
|
(await promisify(fs.readFile)(filePath)).toString(),
|
||||||
|
10,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
backThen = 0;
|
backThen = 0;
|
||||||
}
|
}
|
||||||
@@ -71,7 +74,11 @@ const checkIsCycle = async () => {
|
|||||||
* Runs the launcher if required and returns a boolean based on whether
|
* 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.
|
* 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 (argv.launcher && isProduction() && isLauncherInstalled()) {
|
||||||
if (await checkIsCycle()) {
|
if (await checkIsCycle()) {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -89,4 +96,4 @@ module.exports = async function delegateToLauncher(argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
@@ -18,7 +18,7 @@ import fixPath from 'fix-path';
|
|||||||
import {exec} from 'child_process';
|
import {exec} from 'child_process';
|
||||||
const compilePlugins = require('./compilePlugins');
|
const compilePlugins = require('./compilePlugins');
|
||||||
import setup from './setup';
|
import setup from './setup';
|
||||||
const delegateToLauncher = require('./launcher');
|
import delegateToLauncher from './launcher';
|
||||||
import expandTilde from 'expand-tilde';
|
import expandTilde from 'expand-tilde';
|
||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
|
|
||||||
|
|||||||
@@ -1423,6 +1423,13 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "*"
|
"@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":
|
"@types/node-fetch@^2.5.4":
|
||||||
version "2.5.4"
|
version "2.5.4"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.4.tgz#5245b6d8841fc3a6208b82291119bc11c4e0ce44"
|
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.4.tgz#5245b6d8841fc3a6208b82291119bc11c4e0ce44"
|
||||||
|
|||||||
Reference in New Issue
Block a user