1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = findSymlinkedModules;
|
7 |
|
8 | function _path() {
|
9 | const data = _interopRequireDefault(require("path"));
|
10 |
|
11 | _path = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _fs() {
|
19 | const data = _interopRequireDefault(require("fs"));
|
20 |
|
21 | _fs = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function findSymlinkedModules(projectRoot, ignoredRoots = []) {
|
57 | const nodeModuleRoot = _path().default.join(projectRoot, 'node_modules');
|
58 |
|
59 | const resolvedSymlinks = findModuleSymlinks(nodeModuleRoot, [...ignoredRoots, projectRoot]);
|
60 | return resolvedSymlinks;
|
61 | }
|
62 |
|
63 | function findModuleSymlinks(modulesPath, ignoredPaths = []) {
|
64 | if (!_fs().default.existsSync(modulesPath)) {
|
65 | return [];
|
66 | }
|
67 |
|
68 |
|
69 | const moduleFolders = _fs().default.readdirSync(modulesPath);
|
70 |
|
71 | const symlinks = moduleFolders.reduce((links, folderName) => {
|
72 | const folderPath = _path().default.join(modulesPath, folderName);
|
73 |
|
74 | const maybeSymlinkPaths = [];
|
75 |
|
76 | if (folderName.startsWith('@')) {
|
77 | const scopedModuleFolders = _fs().default.readdirSync(folderPath);
|
78 |
|
79 | maybeSymlinkPaths.push(...scopedModuleFolders.map(name => _path().default.join(folderPath, name)));
|
80 | } else {
|
81 | maybeSymlinkPaths.push(folderPath);
|
82 | }
|
83 |
|
84 | return links.concat(resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths));
|
85 | }, []);
|
86 |
|
87 |
|
88 | const nestedSymlinks = symlinks.reduce((links, symlinkPath) => links.concat(
|
89 | findModuleSymlinks(_path().default.join(symlinkPath, 'node_modules'), [...ignoredPaths, ...symlinks])), []);
|
90 | return [...new Set([...symlinks, ...nestedSymlinks])];
|
91 | }
|
92 |
|
93 | function resolveSymlinkPaths(maybeSymlinkPaths, ignoredPaths) {
|
94 | return maybeSymlinkPaths.reduce((links, maybeSymlinkPath) => {
|
95 | if (_fs().default.lstatSync(maybeSymlinkPath).isSymbolicLink()) {
|
96 | const resolved = _path().default.resolve(_path().default.dirname(maybeSymlinkPath), _fs().default.readlinkSync(maybeSymlinkPath));
|
97 |
|
98 | if (ignoredPaths.indexOf(resolved) === -1 && _fs().default.existsSync(resolved)) {
|
99 | links.push(resolved);
|
100 | }
|
101 | }
|
102 |
|
103 | return links;
|
104 | }, []);
|
105 | } |
\ | No newline at end of file |