From 5cf7f040a5b3dbec6f46631aad7a3b67c211a02f Mon Sep 17 00:00:00 2001 From: Kureev Alexey Date: Mon, 1 Aug 2016 04:37:34 -0700 Subject: [PATCH] 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 https://github.com/facebook/react-native/pull/9009 Differential Revision: D3648828 Pulled By: matryoshcow fbshipit-source-id: 99cf313bfa70324ca904fa6919ef112180974e9e --- local-cli/server/findSymlinksPaths.js | 15 +++++++++++++++ local-cli/server/server.js | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 local-cli/server/findSymlinksPaths.js diff --git a/local-cli/server/findSymlinksPaths.js b/local-cli/server/findSymlinksPaths.js new file mode 100644 index 000000000..804e1d488 --- /dev/null +++ b/local-cli/server/findSymlinksPaths.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; +}; diff --git a/local-cli/server/server.js b/local-cli/server/server.js index 945accf85..ef1cc65ec 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -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' +