Skip to content

Commit

Permalink
Symlink support for packager
Browse files Browse the repository at this point in the history
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 facebook/react-native#9009

Differential Revision: D3648828

Pulled By: matryoshcow

fbshipit-source-id: 99cf313bfa70324ca904fa6919ef112180974e9e
  • Loading branch information
Kureev Alexey authored and Facebook Github Bot 9 committed Aug 1, 2016
1 parent b22eec4 commit 3e7091c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions server/findSymlinksPaths.js
Original file line number Diff line number Diff line change
@@ -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;
};
6 changes: 5 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down

0 comments on commit 3e7091c

Please sign in to comment.