Packager: Options Cleanup

Reviewed By: matryoshcow

Differential Revision: D4235221

fbshipit-source-id: 6930a106ed02bec1d77a790641c3dcad46c779b9
This commit is contained in:
Tim Yung 2016-11-28 12:40:11 -08:00 committed by Facebook Github Bot
parent c858420b2d
commit ebc65cecd6
2 changed files with 12 additions and 12 deletions

View File

@ -8,11 +8,11 @@
*/ */
'use strict'; 'use strict';
const child_process = require('child_process');
const execFile = require('child_process').execFile;
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const launchChrome = require('../util/launchChrome'); const launchChrome = require('../util/launchChrome');
const path = require('path');
const {exec} = require('child_process');
function launchChromeDevTools(port) { function launchChromeDevTools(port) {
var debuggerURL = 'http://localhost:' + port + '/debugger-ui'; var debuggerURL = 'http://localhost:' + port + '/debugger-ui';
@ -20,25 +20,25 @@ function launchChromeDevTools(port) {
launchChrome(debuggerURL); launchChrome(debuggerURL);
} }
function escapePath(path) { function escapePath(pathname) {
return '"' + path + '"'; // " Can escape paths with spaces in OS X, Windows, and *nix return '"' + pathname + '"'; // " Can escape paths with spaces in OS X, Windows, and *nix
} }
function launchDevTools(options, isChromeConnected) { function launchDevTools({port, projectRoots}, isChromeConnected) {
// Explicit config always wins // Explicit config always wins
var customDebugger = process.env.REACT_DEBUGGER; var customDebugger = process.env.REACT_DEBUGGER;
if (customDebugger) { if (customDebugger) {
var projects = options.projectRoots.map(escapePath).join(' '); var projects = projectRoots.map(escapePath).join(' ');
var command = customDebugger + ' ' + projects; var command = customDebugger + ' ' + projects;
console.log('Starting custom debugger by executing: ' + command); console.log('Starting custom debugger by executing: ' + command);
child_process.exec(command, function (error, stdout, stderr) { exec(command, function (error, stdout, stderr) {
if (error !== null) { if (error !== null) {
console.log('Error while starting custom debugger: ' + error); console.log('Error while starting custom debugger: ' + error);
} }
}); });
} else if (!isChromeConnected()) { } else if (!isChromeConnected()) {
// Dev tools are not yet open; we need to open a session // Dev tools are not yet open; we need to open a session
launchChromeDevTools(options.port); launchChromeDevTools(port);
} }
} }

View File

@ -10,11 +10,11 @@
const launchEditor = require('../util/launchEditor'); const launchEditor = require('../util/launchEditor');
module.exports = function(args) { module.exports = function({projectRoots}) {
return function(req, res, next) { return function(req, res, next) {
if (req.url === '/open-stack-frame') { if (req.url === '/open-stack-frame') {
var frame = JSON.parse(req.rawBody); const frame = JSON.parse(req.rawBody);
launchEditor(frame.file, frame.lineNumber, args['projectRoots']); launchEditor(frame.file, frame.lineNumber, projectRoots);
res.end('OK'); res.end('OK');
} else { } else {
next(); next();