Files
flipper/desktop/scripts/get-app-watch-folders.ts
Pascal Hartig f8117240af 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
2021-10-28 05:36:52 -07:00

38 lines
1.2 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
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'),
];
export default async function getAppWatchFolders() {
const getWatchFoldersResults = await Promise.all(
[appDir, ...pluginsReferencedDirectlyFromFlipper].map((dir) =>
getWatchFolders(dir),
),
);
const watchFolders = ([] as string[]).concat(...getWatchFoldersResults);
return pFilter(
watchFolders.filter((value, index, self) => self.indexOf(value) === index),
(f) => fs.pathExists(f),
);
}