"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
This commit is contained in:
committed by
Facebook Github Bot
parent
7c69aba8fa
commit
71573257ae
@@ -17,15 +17,7 @@ const expandTilde = require('expand-tilde');
|
|||||||
const pMap = require('p-map');
|
const pMap = require('p-map');
|
||||||
const HOME_DIR = require('os').homedir();
|
const HOME_DIR = require('os').homedir();
|
||||||
|
|
||||||
/* eslint-disable prettier/prettier */
|
const DEFAULT_COMPILE_OPTIONS = {
|
||||||
/*::
|
|
||||||
type CompileOptions = {|
|
|
||||||
force: boolean,
|
|
||||||
failSilently: boolean,
|
|
||||||
|};
|
|
||||||
*/
|
|
||||||
|
|
||||||
const DEFAULT_COMPILE_OPTIONS /*: CompileOptions */ = {
|
|
||||||
force: false,
|
force: false,
|
||||||
failSilently: true,
|
failSilently: true,
|
||||||
};
|
};
|
||||||
@@ -41,10 +33,14 @@ module.exports = async (
|
|||||||
fs.mkdirSync(pluginCache);
|
fs.mkdirSync(pluginCache);
|
||||||
}
|
}
|
||||||
watchChanges(plugins, reloadCallback, pluginCache, options);
|
watchChanges(plugins, reloadCallback, pluginCache, options);
|
||||||
const compilations = pMap(Object.values(plugins), plugin => {
|
const compilations = pMap(
|
||||||
const dynamicOptions = Object.assign(options, {force: false});
|
Object.values(plugins),
|
||||||
return compilePlugin(plugin, pluginCache, dynamicOptions);
|
plugin => {
|
||||||
}, {concurrency: 4});
|
const dynamicOptions = Object.assign(options, {force: false});
|
||||||
|
return compilePlugin(plugin, pluginCache, dynamicOptions);
|
||||||
|
},
|
||||||
|
{concurrency: 4},
|
||||||
|
);
|
||||||
|
|
||||||
const dynamicPlugins = (await compilations).filter(c => c != null);
|
const dynamicPlugins = (await compilations).filter(c => c != null);
|
||||||
console.log('✅ Compiled all plugins.');
|
console.log('✅ Compiled all plugins.');
|
||||||
@@ -62,11 +58,12 @@ function watchChanges(
|
|||||||
|
|
||||||
const delayedCompilation = {};
|
const delayedCompilation = {};
|
||||||
const kCompilationDelayMillis = 1000;
|
const kCompilationDelayMillis = 1000;
|
||||||
|
|
||||||
Object.values(plugins)
|
Object.values(plugins)
|
||||||
// no hot reloading for plugins in .flipper folder. This is to prevent
|
// no hot reloading for plugins in .flipper folder. This is to prevent
|
||||||
// Flipper from reloading, while we are doing changes on thirdparty plugins.
|
// 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 =>
|
.map(plugin =>
|
||||||
fs.watch(plugin.rootDir, {recursive: true}, (eventType, filename) => {
|
fs.watch(plugin.rootDir, {recursive: true}, (eventType, filename) => {
|
||||||
// only recompile for changes in not hidden files. Watchman might create
|
// only recompile for changes in not hidden files. Watchman might create
|
||||||
@@ -77,7 +74,9 @@ function watchChanges(
|
|||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`🕵️ Detected changes in ${plugin.name}`);
|
console.log(`🕵️ Detected changes in ${plugin.name}`);
|
||||||
const watchOptions = Object.assign(options, {force: true});
|
const watchOptions = Object.assign(options, {force: true});
|
||||||
compilePlugin(plugin, pluginCache, watchOptions).then(reloadCallback);
|
compilePlugin(plugin, pluginCache, watchOptions).then(
|
||||||
|
reloadCallback,
|
||||||
|
);
|
||||||
}, kCompilationDelayMillis);
|
}, kCompilationDelayMillis);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -129,11 +128,7 @@ function entryPointForPluginFolder(pluginPath) {
|
|||||||
}
|
}
|
||||||
return fs
|
return fs
|
||||||
.readdirSync(pluginPath)
|
.readdirSync(pluginPath)
|
||||||
.filter(name =>
|
.filter(name => fs.lstatSync(path.join(pluginPath, name)).isDirectory())
|
||||||
fs
|
|
||||||
.lstatSync(path.join(pluginPath, name))
|
|
||||||
.isDirectory(),
|
|
||||||
)
|
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map(name => {
|
.map(name => {
|
||||||
let packageJSON;
|
let packageJSON;
|
||||||
@@ -178,7 +173,7 @@ function mostRecentlyChanged(dir) {
|
|||||||
async function compilePlugin(
|
async function compilePlugin(
|
||||||
{rootDir, name, entry, packageJSON},
|
{rootDir, name, entry, packageJSON},
|
||||||
pluginCache,
|
pluginCache,
|
||||||
options/*: CompileOptions */,
|
options,
|
||||||
) {
|
) {
|
||||||
const fileName = `${name}@${packageJSON.version || '0.0.0'}.js`;
|
const fileName = `${name}@${packageJSON.version || '0.0.0'}.js`;
|
||||||
const out = path.join(pluginCache, fileName);
|
const out = path.join(pluginCache, fileName);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const url = require('url');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const fixPath = require('fix-path');
|
const fixPath = require('fix-path');
|
||||||
const {exec} = require('child_process');
|
const {exec} = require('child_process');
|
||||||
const compilePlugins = require('./compilePlugins.js');
|
const compilePlugins = require('./compilePlugins');
|
||||||
const setup = require('./setup');
|
const setup = require('./setup');
|
||||||
const delegateToLauncher = require('./launcher');
|
const delegateToLauncher = require('./launcher');
|
||||||
const expandTilde = require('expand-tilde');
|
const expandTilde = require('expand-tilde');
|
||||||
|
|||||||
Reference in New Issue
Block a user