Skip to content

Commit

Permalink
Refactor how symlinks are discovered in local-cli, support scoped mod…
Browse files Browse the repository at this point in the history
…ules

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
  • Loading branch information
Adam Miskiewicz authored and ide committed Sep 14, 2017
1 parent 6b39d64 commit 5d95e99
Show file tree
Hide file tree
Showing 4 changed files with 842 additions and 9 deletions.
19 changes: 10 additions & 9 deletions local-cli/util/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

const blacklist = require('metro-bundler/src/blacklist');
const findSymlinksPaths = require('./findSymlinksPaths');
const findSymlinkedModules = require('./findSymlinkedModules');
const fs = require('fs');
const getPolyfills = require('../../rn-get-polyfills');
const invariant = require('fbjs/lib/invariant');
Expand Down Expand Up @@ -150,14 +150,15 @@ function getProjectPath() {
return path.resolve(__dirname, '../..');
}

const resolveSymlink = (roots) =>
roots.concat(
findSymlinksPaths(
path.join(getProjectPath(), 'node_modules'),
roots
)
const resolveSymlinksForRoots = roots =>
roots.reduce(
(arr, rootPath) => arr.concat(
findSymlinkedModules(rootPath, roots)
),
[...roots]
);


/**
* Module capable of getting the configuration out of a given file.
*
Expand All @@ -177,9 +178,9 @@ const Config = {
getProjectRoots: () => {
const root = process.env.REACT_NATIVE_APP_ROOT;
if (root) {
return resolveSymlink([path.resolve(root)]);
return resolveSymlinksForRoots([path.resolve(root)]);
}
return resolveSymlink([getProjectPath()]);
return resolveSymlinksForRoots([getProjectPath()]);
},
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
getSourceExts: () => [],
Expand Down
Loading

0 comments on commit 5d95e99

Please sign in to comment.