From c2649982797bf448fa4d1837e70c503d4b003875 Mon Sep 17 00:00:00 2001 From: Joshua Wulf Date: Sun, 21 Oct 2012 00:08:00 -0400 Subject: [PATCH 1/2] added --debug and --debug_brk options to meteor run --- app/meteor/meteor.js | 7 ++++++- app/meteor/run.js | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/meteor/meteor.js b/app/meteor/meteor.js index 57de848134..a1b1499556 100644 --- a/app/meteor/meteor.js +++ b/app/meteor/meteor.js @@ -88,6 +88,10 @@ Commands.push({ .describe('port', 'Port to listen on. NOTE: Also uses port N+1 and N+2.') .boolean('production') .describe('production', 'Run in production mode. Minify and bundle CSS and JS files.') + .boolean('debug') + .describe('debug', 'Run in debug mode for node-inspector') + .boolean('debug_brk') + .describe('debug_brk', 'Run in debug mode and break on first line') .usage( "Usage: meteor run [options]\n" + "\n" + @@ -111,7 +115,8 @@ Commands.push({ } var app_dir = path.resolve(require_project("run", true)); // app or package - var bundle_opts = { no_minify: !new_argv.production, symlink_dev_bundle: true }; + var bundle_opts = { no_minify: !new_argv.production, symlink_dev_bundle: true, + debug: new_argv.debug, debug_brk: new_argv.debug_brk}; require('./run.js').run(app_dir, bundle_opts, new_argv.port); } }); diff --git a/app/meteor/run.js b/app/meteor/run.js index 180b2f4f59..9e50ab1f05 100644 --- a/app/meteor/run.js +++ b/app/meteor/run.js @@ -15,6 +15,7 @@ var _ = require('../lib/third/underscore.js'); ////////// Globals ////////// +var debug, debug_brk; // list of log objects from the child process. var server_log = []; @@ -178,10 +179,24 @@ var start_server = function (bundle_path, outer_port, inner_port, mongo_url, env.MONGO_URL = mongo_url; env.ROOT_URL = env.ROOT_URL || ('http://localhost:' + outer_port); - var proc = spawn(process.execPath, + //spawn inner server, with debug enabled if requested + if (debug_brk){ console.log('Debug break on first line'); + var proc = spawn(process.execPath, + ['--debug-brk', path.join(bundle_path, 'main.js'), '--keepalive'], + {env: env}); + } else { + if (debug) { var proc = spawn(process.execPath, + ['--debug', path.join(bundle_path, 'main.js'), '--keepalive'], + {env: env}); + } else { + var proc = spawn(process.execPath, [path.join(bundle_path, 'main.js'), '--keepalive'], {env: env}); + } } + + + // XXX deal with test server logging differently?! proc.stdout.setEncoding('utf8'); @@ -450,6 +465,8 @@ var start_update_checks = function () { // can't continue. If you change this, remember to call // watcher.destroy() as appropriate. exports.run = function (app_dir, bundle_opts, port) { + debug = bundle_opts.debug; + debug_brk = bundle_opts.debug_brk; var outer_port = port || 3000; var inner_port = outer_port + 1; var mongo_port = outer_port + 2; From 7bfa178bbdb8b745a4f78418049743007866d9d5 Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Mon, 3 Dec 2012 12:02:12 -0800 Subject: [PATCH 2/2] Clean up & style-ify debug and debug-brk options * --debug-brk instead of --debug_brk to match node.js * Use an enum passed through functions instead of global vars --- app/meteor/meteor.js | 13 ++++++++----- app/meteor/run.js | 39 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/meteor/meteor.js b/app/meteor/meteor.js index ff5a6d0825..9190bf3e93 100644 --- a/app/meteor/meteor.js +++ b/app/meteor/meteor.js @@ -3,6 +3,7 @@ var files = require(path.join(__dirname, '..', 'lib', 'files.js')); var _ = require(path.join(__dirname, '..', 'lib', 'third', 'underscore.js')); var deploy = require(path.join(__dirname, 'deploy')); var fs = require("fs"); +var runner = require(path.join(__dirname, 'run.js')); // This code is duplicated in app/server/server.js. var MIN_NODE_VERSION = 'v0.8.11'; @@ -98,8 +99,8 @@ Commands.push({ .describe('production', 'Run in production mode. Minify and bundle CSS and JS files.') .boolean('debug') .describe('debug', 'Run in debug mode for node-inspector') - .boolean('debug_brk') - .describe('debug_brk', 'Run in debug mode and break on first line') + .boolean('debug-brk') + .describe('debug-brk', 'Run in debug mode and break on first line') .usage( "Usage: meteor run [options]\n" + "\n" + @@ -123,9 +124,11 @@ Commands.push({ } var app_dir = path.resolve(require_project("run", true)); // app or package - var bundle_opts = { no_minify: !new_argv.production, symlink_dev_bundle: true, - debug: new_argv.debug, debug_brk: new_argv.debug_brk}; - require(path.join(__dirname, 'run.js')).run(app_dir, bundle_opts, new_argv.port); + var bundle_opts = { no_minify: !new_argv.production, symlink_dev_bundle: true}; + var debugStatus = runner.DebugStatus.OFF; + if (new_argv['debug']) debugStatus = runner.DebugStatus.DEBUG; + if (new_argv['debug-brk']) debugStatus = runner.DebugStatus.BREAK; + runner.run(app_dir, bundle_opts, new_argv.port, debugStatus); } }); diff --git a/app/meteor/run.js b/app/meteor/run.js index c72aec9876..3f41659fa6 100644 --- a/app/meteor/run.js +++ b/app/meteor/run.js @@ -15,7 +15,6 @@ var _ = require(path.join(__dirname, '..', 'lib', 'third', 'underscore.js')); ////////// Globals ////////// -var debug, debug_brk; // list of log objects from the child process. var server_log = []; @@ -170,7 +169,7 @@ var log_to_clients = function (msg) { ////////// Launch server process ////////// var start_server = function (bundle_path, outer_port, inner_port, mongo_url, - on_exit_callback, on_listen_callback) { + on_exit_callback, on_listen_callback, dbg) { // environment var env = {}; for (var k in process.env) @@ -178,24 +177,17 @@ var start_server = function (bundle_path, outer_port, inner_port, mongo_url, env.PORT = inner_port; env.MONGO_URL = mongo_url; env.ROOT_URL = env.ROOT_URL || ('http://localhost:' + outer_port); - + var nodeOptions = []; + if (dbg === exports.DebugStatus.DEBUG) + nodeOptions.push('--debug'); + if (dbg === exports.DebugStatus.BREAK) { + console.log('Debug will break on the first line'); + nodeOptions.push('--debug-brk'); + } //spawn inner server, with debug enabled if requested - if (debug_brk){ console.log('Debug break on first line'); - var proc = spawn(process.execPath, - ['--debug-brk', path.join(bundle_path, 'main.js'), '--keepalive'], - {env: env}); - } else { - if (debug) { var proc = spawn(process.execPath, - ['--debug', path.join(bundle_path, 'main.js'), '--keepalive'], + var proc = spawn(process.execPath, + nodeOptions.concat([path.join(bundle_path, 'main.js'), '--keepalive']), {env: env}); - } else { - var proc = spawn(process.execPath, - [path.join(bundle_path, 'main.js'), '--keepalive'], - {env: env}); - - } } - - // XXX deal with test server logging differently?! @@ -461,10 +453,16 @@ var start_update_checks = function () { // XXX leave a pidfile and check if we are already running +exports.DebugStatus = { + OFF : "OFF", + DEBUG : "DEBUG", + BREAK : "BREAK" +}; + // This function never returns and will call process.exit() if it // can't continue. If you change this, remember to call // watcher.destroy() as appropriate. -exports.run = function (app_dir, bundle_opts, port) { +exports.run = function (app_dir, bundle_opts, port, dbg) { debug = bundle_opts.debug; debug_brk = bundle_opts.debug_brk; var outer_port = port || 3000; @@ -577,7 +575,8 @@ exports.run = function (app_dir, bundle_opts, port) { Status.listening = true; _.each(request_queue, function (f) { f(); }); request_queue = []; - }); + }, + dbg); // launch test bundle and server if needed.