From 71573257ae43299c358dff0c767b5dd769bddb73 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 4 Nov 2019 05:05:17 -0800 Subject: [PATCH] "un-flow" compilePlugins.js Summary: `compilePlugins.js` was still flow typed, but our current formatting setup breaks the file as soon as it is changed. This diff removes the (minimal) flow types and applies prettier Reviewed By: jknoxville Differential Revision: D18297696 fbshipit-source-id: 4af2318083188d8758981183f10ccd80e14feea2 --- static/compilePlugins.js | 39 +++++++++++++++++---------------------- static/index.js | 2 +- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/static/compilePlugins.js b/static/compilePlugins.js index 130b0e51c..af34a3866 100644 --- a/static/compilePlugins.js +++ b/static/compilePlugins.js @@ -17,15 +17,7 @@ const expandTilde = require('expand-tilde'); const pMap = require('p-map'); const HOME_DIR = require('os').homedir(); -/* eslint-disable prettier/prettier */ -/*:: -type CompileOptions = {| - force: boolean, - failSilently: boolean, -|}; -*/ - -const DEFAULT_COMPILE_OPTIONS /*: CompileOptions */ = { +const DEFAULT_COMPILE_OPTIONS = { force: false, failSilently: true, }; @@ -41,10 +33,14 @@ module.exports = async ( fs.mkdirSync(pluginCache); } watchChanges(plugins, reloadCallback, pluginCache, options); - const compilations = pMap(Object.values(plugins), plugin => { - const dynamicOptions = Object.assign(options, {force: false}); - return compilePlugin(plugin, pluginCache, dynamicOptions); - }, {concurrency: 4}); + const compilations = pMap( + Object.values(plugins), + plugin => { + const dynamicOptions = Object.assign(options, {force: false}); + return compilePlugin(plugin, pluginCache, dynamicOptions); + }, + {concurrency: 4}, + ); const dynamicPlugins = (await compilations).filter(c => c != null); console.log('✅ Compiled all plugins.'); @@ -62,11 +58,12 @@ function watchChanges( const delayedCompilation = {}; const kCompilationDelayMillis = 1000; - Object.values(plugins) // no hot reloading for plugins in .flipper folder. This is to prevent // Flipper from reloading, while we are doing changes on thirdparty plugins. - .filter(plugin => !plugin.rootDir.startsWith(path.join(HOME_DIR, '.flipper'))) + .filter( + plugin => !plugin.rootDir.startsWith(path.join(HOME_DIR, '.flipper')), + ) .map(plugin => fs.watch(plugin.rootDir, {recursive: true}, (eventType, filename) => { // only recompile for changes in not hidden files. Watchman might create @@ -77,7 +74,9 @@ function watchChanges( // eslint-disable-next-line no-console console.log(`🕵️‍ Detected changes in ${plugin.name}`); const watchOptions = Object.assign(options, {force: true}); - compilePlugin(plugin, pluginCache, watchOptions).then(reloadCallback); + compilePlugin(plugin, pluginCache, watchOptions).then( + reloadCallback, + ); }, kCompilationDelayMillis); } }), @@ -129,11 +128,7 @@ function entryPointForPluginFolder(pluginPath) { } return fs .readdirSync(pluginPath) - .filter(name => - fs - .lstatSync(path.join(pluginPath, name)) - .isDirectory(), - ) + .filter(name => fs.lstatSync(path.join(pluginPath, name)).isDirectory()) .filter(Boolean) .map(name => { let packageJSON; @@ -178,7 +173,7 @@ function mostRecentlyChanged(dir) { async function compilePlugin( {rootDir, name, entry, packageJSON}, pluginCache, - options/*: CompileOptions */, + options, ) { const fileName = `${name}@${packageJSON.version || '0.0.0'}.js`; const out = path.join(pluginCache, fileName); diff --git a/static/index.js b/static/index.js index 733e14b75..3c8181c64 100644 --- a/static/index.js +++ b/static/index.js @@ -16,7 +16,7 @@ const url = require('url'); const fs = require('fs'); const fixPath = require('fix-path'); const {exec} = require('child_process'); -const compilePlugins = require('./compilePlugins.js'); +const compilePlugins = require('./compilePlugins'); const setup = require('./setup'); const delegateToLauncher = require('./launcher'); const expandTilde = require('expand-tilde');