From f8117240af8ad658de5b09bb48bb74a6119bc13a Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 28 Oct 2021 05:34:03 -0700 Subject: [PATCH] Fix async filtering (#3008) Summary: I relied too much on the types which in this case don't help at all. Filtering on a promise will just automatically get all values to pass. Pull Request resolved: https://github.com/facebook/flipper/pull/3008 Test Plan: `yarn build --mac` works again on the GH checkout. Reviewed By: mweststrate Differential Revision: D31991576 Pulled By: passy fbshipit-source-id: f632d29ddfc09b7130b68b4b17264fd30e1969ce --- desktop/plugin-lib/src/pluginPaths.ts | 3 ++- desktop/scripts/get-app-watch-folders.ts | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/desktop/plugin-lib/src/pluginPaths.ts b/desktop/plugin-lib/src/pluginPaths.ts index 13592f1c3..e0338f4bb 100644 --- a/desktop/plugin-lib/src/pluginPaths.ts +++ b/desktop/plugin-lib/src/pluginPaths.ts @@ -10,6 +10,7 @@ import path from 'path'; import {homedir} from 'os'; import fs from 'fs-extra'; +import pFilter from 'p-filter'; import expandTilde from 'expand-tilde'; const flipperDataDir = path.join(homedir(), '.flipper'); @@ -43,7 +44,7 @@ export async function getPluginSourceFolders(): Promise { } pluginFolders.push(path.resolve(__dirname, '..', '..', 'plugins', 'public')); pluginFolders.push(path.resolve(__dirname, '..', '..', 'plugins', 'fb')); - return pluginFolders.map(expandTilde).filter(async (f) => fs.pathExists(f)); + return pFilter(pluginFolders.map(expandTilde), (p) => fs.pathExists(p)); } export function getPluginInstallationDir(name: string) { diff --git a/desktop/scripts/get-app-watch-folders.ts b/desktop/scripts/get-app-watch-folders.ts index 655bab859..a6605e5c6 100644 --- a/desktop/scripts/get-app-watch-folders.ts +++ b/desktop/scripts/get-app-watch-folders.ts @@ -8,6 +8,7 @@ */ 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'; @@ -29,7 +30,8 @@ export default async function getAppWatchFolders() { ), ); const watchFolders = ([] as string[]).concat(...getWatchFoldersResults); - return watchFolders - .filter((value, index, self) => self.indexOf(value) === index) - .filter(async (f) => fs.pathExists(f)); + return pFilter( + watchFolders.filter((value, index, self) => self.indexOf(value) === index), + (f) => fs.pathExists(f), + ); }