From bcf762af6067d44effb489a6ac751f0b64c4c6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Mon, 26 Oct 2015 12:59:54 -0700 Subject: [PATCH] Move files from `packager/` to `local-cli` Summary: public This is not only to put the files on a place where it makes more sense but also to allow to use ES6 features on them as `/packager` is not whitelisted on `babel`. Reviewed By: mkonicek Differential Revision: D2577267 fb-gh-sync-id: b69a17c0aad349a3eda987e33d1778d97a8e1549 --- local-cli/bundle/bundle.js | 2 +- local-cli/dependencies/dependencies.js | 2 +- local-cli/generate/generate.js | 2 +- local-cli/library/library.js | 2 +- local-cli/runAndroid/runAndroid.js | 2 +- .../middleware}/cpuProfilerMiddleware.js | 0 .../middleware}/getDevToolsMiddleware.js | 4 +-- .../middleware}/getFlowTypeCheckMiddleware.js | 2 +- .../middleware}/loadRawBodyMiddleware.js | 0 .../openStackFrameInEditorMiddleware.js | 2 +- .../middleware}/statusPageMiddleware.js | 0 .../middleware}/systraceProfileMiddleware.js | 0 local-cli/server/runServer.js | 26 +++++++++++++------ local-cli/server/server.js | 8 ++---- .../server/util}/debugger.html | 0 .../server/util}/debuggerWorker.js | 0 .../server/util}/launchEditor.js | 0 .../server/util}/webSocketProxy.js | 2 +- .../util}/parseCommandLine.js | 0 19 files changed, 30 insertions(+), 24 deletions(-) rename {packager => local-cli/server/middleware}/cpuProfilerMiddleware.js (100%) rename {packager => local-cli/server/middleware}/getDevToolsMiddleware.js (92%) rename {packager => local-cli/server/middleware}/getFlowTypeCheckMiddleware.js (98%) rename {packager => local-cli/server/middleware}/loadRawBodyMiddleware.js (100%) rename {packager => local-cli/server/middleware}/openStackFrameInEditorMiddleware.js (91%) rename {packager => local-cli/server/middleware}/statusPageMiddleware.js (100%) rename {packager => local-cli/server/middleware}/systraceProfileMiddleware.js (100%) rename {packager => local-cli/server/util}/debugger.html (100%) rename {packager => local-cli/server/util}/debuggerWorker.js (100%) rename {packager => local-cli/server/util}/launchEditor.js (100%) rename {packager => local-cli/server/util}/webSocketProxy.js (99%) rename {packager => local-cli/util}/parseCommandLine.js (100%) diff --git a/local-cli/bundle/bundle.js b/local-cli/bundle/bundle.js index 425d2e213..6826de71f 100644 --- a/local-cli/bundle/bundle.js +++ b/local-cli/bundle/bundle.js @@ -10,7 +10,7 @@ const buildBundle = require('./buildBundle'); const bundleCommandLineArgs = require('./bundleCommandLineArgs'); -const parseCommandLine = require('../../packager/parseCommandLine'); +const parseCommandLine = require('../util/parseCommandLine'); /** * Builds the bundle starting to look for dependencies at the given entry path. diff --git a/local-cli/dependencies/dependencies.js b/local-cli/dependencies/dependencies.js index ee395f6a8..54c1b004f 100644 --- a/local-cli/dependencies/dependencies.js +++ b/local-cli/dependencies/dependencies.js @@ -10,7 +10,7 @@ const fs = require('fs'); const log = require('../util/log').out('dependencies'); -const parseCommandLine = require('../../packager/parseCommandLine'); +const parseCommandLine = require('../util/parseCommandLine'); const path = require('path'); const Promise = require('promise'); const ReactPackager = require('../../packager/react-packager'); diff --git a/local-cli/generate/generate.js b/local-cli/generate/generate.js index 5d073e961..8e43f8b43 100644 --- a/local-cli/generate/generate.js +++ b/local-cli/generate/generate.js @@ -8,7 +8,7 @@ */ 'use strict'; -const parseCommandLine = require('../../packager/parseCommandLine'); +const parseCommandLine = require('../util/parseCommandLine'); const path = require('path'); const Promise = require('promise'); const yeoman = require('yeoman-environment'); diff --git a/local-cli/library/library.js b/local-cli/library/library.js index d495b28b9..107c4455b 100644 --- a/local-cli/library/library.js +++ b/local-cli/library/library.js @@ -11,7 +11,7 @@ const copyAndReplace = require('../util/copyAndReplace'); const fs = require('fs'); const isValidPackageName = require('../util/isValidPackageName'); -const parseCommandLine = require('../../packager/parseCommandLine'); +const parseCommandLine = require('../util/parseCommandLine'); const path = require('path'); const Promise = require('promise'); const walk = require('../util/walk'); diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index 37520f4ea..9bcb95b31 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -12,7 +12,7 @@ const chalk = require('chalk'); const child_process = require('child_process'); const fs = require('fs'); const path = require('path'); -const parseCommandLine = require('../../packager/parseCommandLine'); +const parseCommandLine = require('../util/parseCommandLine'); const isPackagerRunning = require('../util/isPackagerRunning'); const Promise = require('promise'); diff --git a/packager/cpuProfilerMiddleware.js b/local-cli/server/middleware/cpuProfilerMiddleware.js similarity index 100% rename from packager/cpuProfilerMiddleware.js rename to local-cli/server/middleware/cpuProfilerMiddleware.js diff --git a/packager/getDevToolsMiddleware.js b/local-cli/server/middleware/getDevToolsMiddleware.js similarity index 92% rename from packager/getDevToolsMiddleware.js rename to local-cli/server/middleware/getDevToolsMiddleware.js index 966e47c45..53c73d8d6 100644 --- a/packager/getDevToolsMiddleware.js +++ b/local-cli/server/middleware/getDevToolsMiddleware.js @@ -27,11 +27,11 @@ function getChromeAppName() { module.exports = function(options, isDebuggerConnected) { return function(req, res, next) { if (req.url === '/debugger-ui') { - var debuggerPath = path.join(__dirname, 'debugger.html'); + var debuggerPath = path.join(__dirname, '..', 'util', 'debugger.html'); res.writeHead(200, {'Content-Type': 'text/html'}); fs.createReadStream(debuggerPath).pipe(res); } else if (req.url === '/debuggerWorker.js') { - var workerPath = path.join(__dirname, 'debuggerWorker.js'); + var workerPath = path.join(__dirname, '..', 'util', 'debuggerWorker.js'); res.writeHead(200, {'Content-Type': 'application/javascript'}); fs.createReadStream(workerPath).pipe(res); } else if (req.url === '/launch-safari-devtools') { diff --git a/packager/getFlowTypeCheckMiddleware.js b/local-cli/server/middleware/getFlowTypeCheckMiddleware.js similarity index 98% rename from packager/getFlowTypeCheckMiddleware.js rename to local-cli/server/middleware/getFlowTypeCheckMiddleware.js index f34815512..3d90507dd 100644 --- a/packager/getFlowTypeCheckMiddleware.js +++ b/local-cli/server/middleware/getFlowTypeCheckMiddleware.js @@ -11,7 +11,7 @@ var chalk = require('chalk'); var exec = require('child_process').exec; var url = require('url'); -var Activity = require('./react-packager').Activity; +var Activity = require('../../../packager/react-packager').Activity; var hasWarned = {}; diff --git a/packager/loadRawBodyMiddleware.js b/local-cli/server/middleware/loadRawBodyMiddleware.js similarity index 100% rename from packager/loadRawBodyMiddleware.js rename to local-cli/server/middleware/loadRawBodyMiddleware.js diff --git a/packager/openStackFrameInEditorMiddleware.js b/local-cli/server/middleware/openStackFrameInEditorMiddleware.js similarity index 91% rename from packager/openStackFrameInEditorMiddleware.js rename to local-cli/server/middleware/openStackFrameInEditorMiddleware.js index 78baa1057..bdda77f62 100644 --- a/packager/openStackFrameInEditorMiddleware.js +++ b/local-cli/server/middleware/openStackFrameInEditorMiddleware.js @@ -8,7 +8,7 @@ */ 'use strict'; -const launchEditor = require('./launchEditor'); +const launchEditor = require('../util/launchEditor'); module.exports = function(req, res, next) { if (req.url === '/open-stack-frame') { diff --git a/packager/statusPageMiddleware.js b/local-cli/server/middleware/statusPageMiddleware.js similarity index 100% rename from packager/statusPageMiddleware.js rename to local-cli/server/middleware/statusPageMiddleware.js diff --git a/packager/systraceProfileMiddleware.js b/local-cli/server/middleware/systraceProfileMiddleware.js similarity index 100% rename from packager/systraceProfileMiddleware.js rename to local-cli/server/middleware/systraceProfileMiddleware.js diff --git a/local-cli/server/runServer.js b/local-cli/server/runServer.js index 12458dd37..051979bac 100644 --- a/local-cli/server/runServer.js +++ b/local-cli/server/runServer.js @@ -9,21 +9,23 @@ 'use strict'; const connect = require('connect'); -const cpuProfilerMiddleware = require('../../packager/cpuProfilerMiddleware'); -const getDevToolsMiddleware = require('../../packager/getDevToolsMiddleware'); +const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware'); +const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware'); const http = require('http'); const isAbsolutePath = require('absolute-path'); -const loadRawBodyMiddleware = require('../../packager/loadRawBodyMiddleware'); -const openStackFrameInEditorMiddleware = require('../../packager/openStackFrameInEditorMiddleware'); +const loadRawBodyMiddleware = require('./middleware/loadRawBodyMiddleware'); +const openStackFrameInEditorMiddleware = require('./middleware/openStackFrameInEditorMiddleware'); const path = require('path'); const ReactPackager = require('../../packager/react-packager'); -const statusPageMiddleware = require('../../packager/statusPageMiddleware.js'); -const systraceProfileMiddleware = require('../../packager/systraceProfileMiddleware.js'); +const statusPageMiddleware = require('./middleware/statusPageMiddleware.js'); +const systraceProfileMiddleware = require('./middleware/systraceProfileMiddleware.js'); +const webSocketProxy = require('./util/webSocketProxy.js'); function runServer(args, config, readyCallback) { + var wsProxy = null; const app = connect() .use(loadRawBodyMiddleware) - .use(getDevToolsMiddleware(args)) + .use(getDevToolsMiddleware(args, () => wsProxy && wsProxy.isChromeConnected())) .use(openStackFrameInEditorMiddleware) .use(statusPageMiddleware) .use(systraceProfileMiddleware) @@ -38,7 +40,15 @@ function runServer(args, config, readyCallback) { .use(connect.compress()) .use(connect.errorHandler()); - return http.createServer(app).listen(args.port, '::', readyCallback); + const serverInstance = http.createServer(app).listen( + args.port, + '::', + function() { + wsProxy = webSocketProxy.attachToServer(serverInstance, '/debugger-proxy'); + webSocketProxy.attachToServer(serverInstance, '/devtools'); + readyCallback(); + } + ); } function getAppMiddleware(args, config) { diff --git a/local-cli/server/server.js b/local-cli/server/server.js index 9ac27d795..266bc5bd4 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -11,11 +11,10 @@ const chalk = require('chalk'); const checkNodeVersion = require('./checkNodeVersion'); const formatBanner = require('./formatBanner'); -const parseCommandLine = require('../../packager/parseCommandLine'); +const parseCommandLine = require('../util/parseCommandLine'); const path = require('path'); const Promise = require('promise'); const runServer = require('./runServer'); -const webSocketProxy = require('../../packager/webSocketProxy.js'); /** * Starts the React Native Packager Server. @@ -138,12 +137,9 @@ function _server(argv, config, resolve, reject) { } function startServer(args, config) { - const serverInstance = runServer(args, config, () => + runServer(args, config, () => console.log('\nReact packager ready.\n') ); - - webSocketProxy.attachToServer(serverInstance, '/debugger-proxy'); - webSocketProxy.attachToServer(serverInstance, '/devtools'); } function argToArray(arg) { diff --git a/packager/debugger.html b/local-cli/server/util/debugger.html similarity index 100% rename from packager/debugger.html rename to local-cli/server/util/debugger.html diff --git a/packager/debuggerWorker.js b/local-cli/server/util/debuggerWorker.js similarity index 100% rename from packager/debuggerWorker.js rename to local-cli/server/util/debuggerWorker.js diff --git a/packager/launchEditor.js b/local-cli/server/util/launchEditor.js similarity index 100% rename from packager/launchEditor.js rename to local-cli/server/util/launchEditor.js diff --git a/packager/webSocketProxy.js b/local-cli/server/util/webSocketProxy.js similarity index 99% rename from packager/webSocketProxy.js rename to local-cli/server/util/webSocketProxy.js index f5ff7ea01..66eaefb15 100644 --- a/packager/webSocketProxy.js +++ b/local-cli/server/util/webSocketProxy.js @@ -63,7 +63,7 @@ function attachToServer(server, path) { return clients .map(function(ws) { return ws.upgradeReq.headers['user-agent']; }) .filter(Boolean) - .some(function(userAgent) { return userAgent.includes('Chrome'); }) + .some(function(userAgent) { return userAgent.includes('Chrome'); }); } }; } diff --git a/packager/parseCommandLine.js b/local-cli/util/parseCommandLine.js similarity index 100% rename from packager/parseCommandLine.js rename to local-cli/util/parseCommandLine.js