Cleanup plugin watch folders

Summary:
Watch folders weren't updated for cross plugin/flipper boundaries that have recently been removed

Fix changes in several source folders not being picked up when fast refresh wasn't enabled

Reviewed By: passy, aigoncharov

Differential Revision: D32626139

fbshipit-source-id: 2c830ec8154ff859ce1e3ee101e5963162d2e0a2
This commit is contained in:
Michel Weststrate
2021-12-08 04:25:28 -08:00
committed by Facebook GitHub Bot
parent e742322eb1
commit 2b81be6c29
2 changed files with 13 additions and 16 deletions

View File

@@ -9,25 +9,12 @@
import fs from 'fs-extra';
import pFilter from 'p-filter';
import path from 'path';
import {getWatchFolders} from 'flipper-pkg-lib';
import {appDir, publicPluginsDir, fbPluginsDir} from './paths';
/**
* Flipper references code from below plugins directly. Such directly referenced plugins
* and their dependencies should be added as watch folders so Metro bundled can resolve them.
*/
const pluginsReferencedDirectlyFromFlipper = [
path.join(publicPluginsDir, 'navigation'),
path.join(fbPluginsDir, 'mobileconfig'),
path.join(fbPluginsDir, 'watch'),
];
import {appDir} from './paths';
export default async function getAppWatchFolders() {
const getWatchFoldersResults = await Promise.all(
[appDir, ...pluginsReferencedDirectlyFromFlipper].map((dir) =>
getWatchFolders(dir),
),
[appDir].map((dir) => getWatchFolders(dir)),
);
const watchFolders = ([] as string[]).concat(...getWatchFoldersResults);
return pFilter(

View File

@@ -244,6 +244,8 @@ async function startMetroServer(app: Express, server: http.Server) {
const watchFolders = (await getAppWatchFolders()).concat(
await getPluginSourceFolders(),
);
console.log('Source dirs\n\t' + watchFolders.join('\n\t'));
const baseConfig = await Metro.loadConfig();
const config = Object.assign({}, baseConfig, {
projectRoot: rootDir,
@@ -339,7 +341,15 @@ async function startWatchChanges(io: socketIo.Server) {
const watchman = new Watchman(path.resolve(__dirname, '..'));
await watchman.initialize();
await Promise.all(
['app', 'pkg', 'doctor', 'plugin-lib', 'flipper-plugin'].map((dir) =>
[
'app',
'pkg',
'doctor',
'plugin-lib',
'flipper-plugin',
'flipper-common',
'flipper-ui-core',
].map((dir) =>
watchman.startWatchFiles(
dir,
() => {