diff options
author | isaacs <i@izs.me> | 2012-06-05 12:02:37 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-06-05 12:35:49 -0700 |
commit | 28e851c169ad589a7f6a1357fd84fd75254a2ab7 (patch) | |
tree | 2db9d799f7fc7d49b35be7ec5fcebe4aef0c8e06 | |
parent | c69d7f1a6cbec87b2ef2fa3b5de6d8db05858d2d (diff) | |
download | node-28e851c169ad589a7f6a1357fd84fd75254a2ab7.tar.gz |
Warn about running npm in the repl
-rw-r--r-- | lib/repl.js | 9 | ||||
-rw-r--r-- | test/simple/test-repl.js | 16 |
2 files changed, 22 insertions, 3 deletions
diff --git a/lib/repl.js b/lib/repl.js index 26f081ce2..a78a467e6 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -280,6 +280,15 @@ function REPLServer(prompt, stream, eval, useGlobal, ignoreUndefined) { // If error was SyntaxError and not JSON.parse error if (isSyntaxError(e)) { + if (cmd.trim().match(/^npm /) && !self.bufferedCommand) { + self.outputStream.write('npm should be run outside of the ' + + 'node repl, in your normal shell.\n' + + '(Press Control-D to exit.)\n'); + self.bufferedCmd = ''; + self.displayPrompt(); + return; + } + // Start buffering data like that: // { // ... x: 1 diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index d61a8231d..ae20a19f0 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -30,6 +30,10 @@ var net = require('net'), prompt_unix = 'node via Unix socket> ', prompt_tcp = 'node via TCP socket> ', prompt_multiline = '... ', + prompt_npm = 'npm should be run outside of the ' + + 'node repl, in your normal shell.\n' + + '(Press Control-D to exit.)\n', + expect_npm = prompt_npm + prompt_unix, server_tcp, server_unix, client_tcp, client_unix, timer; @@ -76,8 +80,11 @@ function error_test() { JSON.stringify(client_unix.expect))); if (read_buffer.indexOf(prompt_unix) !== -1) { - assert.ok(read_buffer.match(client_unix.expect)); - common.error('match'); + // if it's an exact match, then don't do the regexp + if (read_buffer !== client_unix.expect) { + assert.ok(read_buffer.match(client_unix.expect)); + common.error('match'); + } read_buffer = ''; if (client_unix.list && client_unix.list.length > 0) { send_expect(client_unix.list); @@ -140,7 +147,10 @@ function error_test() { { client: client_unix, send: 'return 1;', expect: prompt_multiline }, { client: client_unix, send: '})()', - expect: '1' } + expect: '1' }, + // npm prompt error message + { client: client_unix, send: 'npm install foobar', + expect: expect_npm } ]); } |