Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,7 +29,7 @@ import fs from 'fs';
*/
export default function findSymlinkedModules(
projectRoot: string,
ignoredRoots?: Array<string> = [],
ignoredRoots: Array<string> = [],
) {
const nodeModuleRoot = path.join(projectRoot, 'node_modules');
const resolvedSymlinks = findModuleSymlinks(nodeModuleRoot, [
Expand All @@ -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
Expand All @@ -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[],
);
}
1 change: 1 addition & 0 deletions packages/cli/src/tools/loadMetroConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down