Skip to content

Commit 3ff8ff3

Browse files
pveyesthymikee
authored andcommitted
chore: convert findSymlinkedModules to TS (#693)
* convert findSymlinkedModules to ts * lint --fix * remove @flow strict and @Format
1 parent b4ff7e9 commit 3ff8ff3

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

packages/cli/src/tools/findSymlinkedModules.js renamed to packages/cli/src/tools/findSymlinkedModules.ts

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @format
8-
* @flow strict
96
*/
107

118
import path from 'path';
@@ -32,7 +29,7 @@ import fs from 'fs';
3229
*/
3330
export default function findSymlinkedModules(
3431
projectRoot: string,
35-
ignoredRoots?: Array<string> = [],
32+
ignoredRoots: Array<string> = [],
3633
) {
3734
const nodeModuleRoot = path.join(projectRoot, 'node_modules');
3835
const resolvedSymlinks = findModuleSymlinks(nodeModuleRoot, [
@@ -52,19 +49,22 @@ function findModuleSymlinks(
5249

5350
// Find module symlinks
5451
const moduleFolders = fs.readdirSync(modulesPath);
55-
const symlinks = moduleFolders.reduce((links, folderName) => {
56-
const folderPath = path.join(modulesPath, folderName);
57-
const maybeSymlinkPaths = [];
58-
if (folderName.startsWith('@')) {
59-
const scopedModuleFolders = fs.readdirSync(folderPath);
60-
maybeSymlinkPaths.push(
61-
...scopedModuleFolders.map(name => path.join(folderPath, name)),
62-
);
63-
} else {
64-
maybeSymlinkPaths.push(folderPath);
65-
}
66-
return links.concat(resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths));
67-
}, []);
52+
const symlinks = moduleFolders.reduce(
53+
(links, folderName) => {
54+
const folderPath = path.join(modulesPath, folderName);
55+
const maybeSymlinkPaths = [];
56+
if (folderName.startsWith('@')) {
57+
const scopedModuleFolders = fs.readdirSync(folderPath);
58+
maybeSymlinkPaths.push(
59+
...scopedModuleFolders.map(name => path.join(folderPath, name)),
60+
);
61+
} else {
62+
maybeSymlinkPaths.push(folderPath);
63+
}
64+
return links.concat(resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths));
65+
},
66+
[] as string[],
67+
);
6868

6969
// For any symlinks found, look in _that_ modules node_modules directory
7070
// and find any symlinked modules
@@ -78,23 +78,29 @@ function findModuleSymlinks(
7878
...symlinks,
7979
]),
8080
),
81-
[],
81+
[] as string[],
8282
);
8383

8484
return [...new Set([...symlinks, ...nestedSymlinks])];
8585
}
8686

87-
function resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths) {
88-
return maybeSymlinkPaths.reduce((links, maybeSymlinkPath) => {
89-
if (fs.lstatSync(maybeSymlinkPath).isSymbolicLink()) {
90-
const resolved = path.resolve(
91-
path.dirname(maybeSymlinkPath),
92-
fs.readlinkSync(maybeSymlinkPath),
93-
);
94-
if (ignoredPaths.indexOf(resolved) === -1 && fs.existsSync(resolved)) {
95-
links.push(resolved);
87+
function resolveSymlinkPaths(
88+
maybeSymlinkPaths: string[],
89+
ignoredPaths: string[],
90+
) {
91+
return maybeSymlinkPaths.reduce(
92+
(links, maybeSymlinkPath) => {
93+
if (fs.lstatSync(maybeSymlinkPath).isSymbolicLink()) {
94+
const resolved = path.resolve(
95+
path.dirname(maybeSymlinkPath),
96+
fs.readlinkSync(maybeSymlinkPath),
97+
);
98+
if (ignoredPaths.indexOf(resolved) === -1 && fs.existsSync(resolved)) {
99+
links.push(resolved);
100+
}
96101
}
97-
}
98-
return links;
99-
}, []);
102+
return links;
103+
},
104+
[] as string[],
105+
);
100106
}

packages/cli/src/tools/loadMetroConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {createBlacklist} from 'metro';
77
import {loadConfig} from 'metro-config';
88
import {existsSync} from 'fs';
99
import {type ConfigT} from 'types';
10+
// $FlowFixMe - converted to TS
1011
import findSymlinkedModules from './findSymlinkedModules';
1112

1213
const resolveSymlinksForRoots = roots =>

0 commit comments

Comments
 (0)