Skip to content

Commit 39f83c4

Browse files
Adam Miskiewiczfacebook-github-bot
authored andcommitted
Refactor how symlinks are discovered in local-cli, support scoped modules
Summary: This PR refactors the symlink finding logic in local-cli in order to support nested symlinked modules as well as symlinked scoped NPM modules. Run tests, or try project with `npm link`'ed or `yarn link`'ed dependencies. Closes #15776 Reviewed By: cpojer Differential Revision: D5823008 Pulled By: jeanlauliac fbshipit-source-id: f2daeceef37bed2f8a136a0a5918730f9832884c
1 parent e846a9f commit 39f83c4

File tree

4 files changed

+842
-9
lines changed

4 files changed

+842
-9
lines changed

local-cli/util/Config.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* found when Flow v0.54 was deployed. To see the error delete this comment and
1515
* run Flow. */
1616
const blacklist = require('metro-bundler/src/blacklist');
17-
const findSymlinksPaths = require('./findSymlinksPaths');
17+
const findSymlinkedModules = require('./findSymlinkedModules');
1818
const fs = require('fs');
1919
const getPolyfills = require('../../rn-get-polyfills');
2020
const invariant = require('fbjs/lib/invariant');
@@ -168,14 +168,15 @@ function getProjectPath() {
168168
return path.resolve(__dirname, '../..');
169169
}
170170

171-
const resolveSymlink = (roots) =>
172-
roots.concat(
173-
findSymlinksPaths(
174-
path.join(getProjectPath(), 'node_modules'),
175-
roots
176-
)
171+
const resolveSymlinksForRoots = roots =>
172+
roots.reduce(
173+
(arr, rootPath) => arr.concat(
174+
findSymlinkedModules(rootPath, roots)
175+
),
176+
[...roots]
177177
);
178178

179+
179180
/**
180181
* Module capable of getting the configuration out of a given file.
181182
*
@@ -195,9 +196,9 @@ const Config = {
195196
getProjectRoots: () => {
196197
const root = process.env.REACT_NATIVE_APP_ROOT;
197198
if (root) {
198-
return resolveSymlink([path.resolve(root)]);
199+
return resolveSymlinksForRoots([path.resolve(root)]);
199200
}
200-
return resolveSymlink([getProjectPath()]);
201+
return resolveSymlinksForRoots([getProjectPath()]);
201202
},
202203
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
203204
getSourceExts: () => [],

0 commit comments

Comments
 (0)