diff --git a/package.json b/package.json index 4f455f6e4..5b7324e76 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/static/launcher.js b/static/launcher.ts similarity index 79% rename from static/launcher.js rename to static/launcher.ts index ac00e2b89..369f0d016 100644 --- a/static/launcher.js +++ b/static/launcher.ts @@ -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; -}; +} diff --git a/static/main.ts b/static/main.ts index cf493b8fa..b57ec5470 100644 --- a/static/main.ts +++ b/static/main.ts @@ -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'; diff --git a/yarn.lock b/yarn.lock index 12db25a04..2f4419efd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"