diff --git a/packages/cli/src/tools/findSymlinkedModules.js b/packages/cli/src/tools/findSymlinkedModules.ts similarity index 64% rename from packages/cli/src/tools/findSymlinkedModules.js rename to packages/cli/src/tools/findSymlinkedModules.ts index 90a0f5933..0e7befe6c 100644 --- a/packages/cli/src/tools/findSymlinkedModules.js +++ b/packages/cli/src/tools/findSymlinkedModules.ts @@ -3,9 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @format - * @flow strict */ import path from 'path'; @@ -32,7 +29,7 @@ import fs from 'fs'; */ export default function findSymlinkedModules( projectRoot: string, - ignoredRoots?: Array = [], + ignoredRoots: Array = [], ) { const nodeModuleRoot = path.join(projectRoot, 'node_modules'); const resolvedSymlinks = findModuleSymlinks(nodeModuleRoot, [ @@ -52,19 +49,22 @@ function findModuleSymlinks( // Find module symlinks const moduleFolders = fs.readdirSync(modulesPath); - const symlinks = moduleFolders.reduce((links, folderName) => { - const folderPath = path.join(modulesPath, folderName); - const maybeSymlinkPaths = []; - if (folderName.startsWith('@')) { - const scopedModuleFolders = fs.readdirSync(folderPath); - maybeSymlinkPaths.push( - ...scopedModuleFolders.map(name => path.join(folderPath, name)), - ); - } else { - maybeSymlinkPaths.push(folderPath); - } - return links.concat(resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths)); - }, []); + const symlinks = moduleFolders.reduce( + (links, folderName) => { + const folderPath = path.join(modulesPath, folderName); + const maybeSymlinkPaths = []; + if (folderName.startsWith('@')) { + const scopedModuleFolders = fs.readdirSync(folderPath); + maybeSymlinkPaths.push( + ...scopedModuleFolders.map(name => path.join(folderPath, name)), + ); + } else { + maybeSymlinkPaths.push(folderPath); + } + return links.concat(resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths)); + }, + [] as string[], + ); // For any symlinks found, look in _that_ modules node_modules directory // and find any symlinked modules @@ -78,23 +78,29 @@ function findModuleSymlinks( ...symlinks, ]), ), - [], + [] as string[], ); return [...new Set([...symlinks, ...nestedSymlinks])]; } -function resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths) { - return maybeSymlinkPaths.reduce((links, maybeSymlinkPath) => { - if (fs.lstatSync(maybeSymlinkPath).isSymbolicLink()) { - const resolved = path.resolve( - path.dirname(maybeSymlinkPath), - fs.readlinkSync(maybeSymlinkPath), - ); - if (ignoredPaths.indexOf(resolved) === -1 && fs.existsSync(resolved)) { - links.push(resolved); +function resolveSymlinkPaths( + maybeSymlinkPaths: string[], + ignoredPaths: string[], +) { + return maybeSymlinkPaths.reduce( + (links, maybeSymlinkPath) => { + if (fs.lstatSync(maybeSymlinkPath).isSymbolicLink()) { + const resolved = path.resolve( + path.dirname(maybeSymlinkPath), + fs.readlinkSync(maybeSymlinkPath), + ); + if (ignoredPaths.indexOf(resolved) === -1 && fs.existsSync(resolved)) { + links.push(resolved); + } } - } - return links; - }, []); + return links; + }, + [] as string[], + ); } diff --git a/packages/cli/src/tools/loadMetroConfig.js b/packages/cli/src/tools/loadMetroConfig.js index aa6280ffb..78ac92a31 100644 --- a/packages/cli/src/tools/loadMetroConfig.js +++ b/packages/cli/src/tools/loadMetroConfig.js @@ -7,6 +7,7 @@ import {createBlacklist} from 'metro'; import {loadConfig} from 'metro-config'; import {existsSync} from 'fs'; import {type ConfigT} from 'types'; +// $FlowFixMe - converted to TS import findSymlinkedModules from './findSymlinkedModules'; const resolveSymlinksForRoots = roots =>