Permalink
Browse files

Add symlinks under node_modules as part of projectRoots

Summary:
Support symlinks under `node_modules` for all local-cli commands. PR #9009 only adds symlink support to the packager.

But other cli commands like `react-native bundle` creates its own instance of packager that doesn't have symlinks as part of its project roots, which results in the bundler breaking since it cannot find modules that you have symlinked.

This change ensures all `local-cli` commands add symlinks to its project roots.

Test plan (required)

1.  Create a symlink in node_modules (for instance use npm/yarn link)
2. Run `react-native bundle`.
Closes #11810

Differential Revision: D4487741

fbshipit-source-id: 87fe44194134d086dca4eaca99ee5742d6eadb69
  • Loading branch information...
harshil07 authored and facebook-github-bot committed Jan 31, 2017
1 parent af111ab commit bce6ece5f6927bcc06252dc2368840aa0c6fa30e
@@ -22,6 +22,9 @@ const windows = require('./windows');
const wrapCommands = require('./wrapCommands');
const findPlugins = require('./findPlugins');
+const findSymlinksPaths = require('../util/findSymlinksPaths');
+const NODE_MODULES = path.resolve(__dirname, '..', '..', '..');
+
import type {ConfigT} from './index';
const getRNPMConfig = (folder) =>
@@ -32,6 +35,9 @@ const attachPackage = (command, pkg) => Array.isArray(command)
? command.map(cmd => attachPackage(cmd, pkg))
: { ...command, pkg };
+const addSymlinkToRoots = (roots) =>
+ roots.concat(findSymlinksPaths(NODE_MODULES, roots));
+
/**
* Default configuration for the CLI.
*
@@ -97,18 +103,21 @@ const config: ConfigT = {
getProjectRoots() {
const root = process.env.REACT_NATIVE_APP_ROOT;
if (root) {
- return [path.resolve(root)];
+ return addSymlinkToRoots([path.resolve(root)]);
}
+
+ var roots;
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]core$/)) {
// Packager is running from node_modules.
// This is the default case for all projects created using 'react-native init'.
- return [path.resolve(__dirname, '../../../..')];
+ roots = [path.resolve(__dirname, '../../../..')];
} else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) {
// React Native was installed using CocoaPods.
- return [path.resolve(__dirname, '../../../..')];
+ roots = [path.resolve(__dirname, '../../../..')];
} else {
- return [path.resolve(__dirname, '../..')];
+ roots = [path.resolve(__dirname, '../..')];
}
+ return addSymlinkToRoots(roots);
},
};
@@ -9,20 +9,15 @@
'use strict';
const chalk = require('chalk');
-const findSymlinksPaths = require('./findSymlinksPaths');
const formatBanner = require('./formatBanner');
const path = require('path');
const runServer = require('./runServer');
-const NODE_MODULES = path.resolve(__dirname, '..', '..', '..');
/**
* Starts the React Native Packager Server.
*/
function server(argv, config, args) {
- const roots = args.projectRoots.concat(args.root);
- args.projectRoots = roots.concat(
- findSymlinksPaths(NODE_MODULES, roots)
- );
+ args.projectRoots.concat(args.root);

This comment has been minimized.

Show comment
Hide comment
@Swaagie

Swaagie Feb 14, 2017

For the record this killed merging root with projectRoots, concat has a return value that should be assigned...

@Swaagie

Swaagie Feb 14, 2017

For the record this killed merging root with projectRoots, concat has a return value that should be assigned...

This comment has been minimized.

Show comment
Hide comment
@rmevans9

rmevans9 Mar 2, 2017

Contributor

I ran into this issue and needed a fix. #12659

@rmevans9

rmevans9 Mar 2, 2017

Contributor

I ran into this issue and needed a fix. #12659

console.log(formatBanner(
'Running packager on port ' + args.port + '.\n\n' +

0 comments on commit bce6ece

Please sign in to comment.