Permalink
Browse files

Symlink support for packager

Summary:
I saw we have quite a few user requests for symlink support...

**Test plan (required)**

1. Create a symlink in `node_modules` (for instance use `npm link`)
2. Run `npm start`
3. Profit!

**Code formatting**

Look around. Match the style of the rest of the codebase. See also the simple [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).

For more info, see the ["Pull Requests" section of our "Contributing" guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests).
Closes #9009

Differential Revision: D3648828

Pulled By: matryoshcow

fbshipit-source-id: 99cf313bfa70324ca904fa6919ef112180974e9e
  • Loading branch information...
1 parent f634a0f commit 5cf7f040a5b3dbec6f46631aad7a3b67c211a02f @Kureev Kureev committed with Facebook Github Bot 9 Aug 1, 2016
Showing with 20 additions and 1 deletion.
  1. +15 −0 local-cli/server/findSymlinksPaths.js
  2. +5 −1 local-cli/server/server.js
@@ -0,0 +1,15 @@
+const path = require('path');
+const fs = require('fs');
+
+module.exports = function findSymlinksPaths(lookupFolder) {
+ const timeStart = Date.now();
+ const folders = fs.readdirSync(lookupFolder);
+ const resolvedSymlinks = folders.map(folder => path.resolve(lookupFolder, folder))
+ .filter(folderPath => fs.lstatSync(folderPath).isSymbolicLink())
+ .map(symlink => path.resolve(process.cwd(), fs.readlinkSync(symlink)));
+ const timeEnd = Date.now();
+
+ console.log(`Scanning ${folders.length} folders for symlinks in ${lookupFolder} (${timeEnd - timeStart}ms)`);
+
+ return resolvedSymlinks;
+};
@@ -12,12 +12,16 @@ const chalk = require('chalk');
const formatBanner = require('./formatBanner');
const path = require('path');
const runServer = require('./runServer');
+const findSymlinksPaths = require('./findSymlinksPaths');
/**
* Starts the React Native Packager Server.
*/
function server(argv, config, args) {
- args.projectRoots = args.projectRoots.concat(args.root);
+ args.projectRoots = args.projectRoots.concat(
+ args.root,
+ findSymlinkPaths(path.resolve(process.cwd(), 'node_modules'))
+ );
console.log(formatBanner(
'Running packager on port ' + args.port + '.\n\n' +

0 comments on commit 5cf7f04

Please sign in to comment.