GeezerVison is showing github.com — repl: avoid interpreting 'npm' as a command when errors are recoverable · nodejs/node@67b1d4c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/repl.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -931,7 +931,9 @@ function REPLServer(prompt, | 931 | 931 | ReflectApply(_memory, self, [cmd]); | 932 | 932 |
| 933 | 933 | if (e && !self[kBufferedCommandSymbol] && | 934 | | - StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ')) { | | 934 | + StringPrototypeStartsWith(StringPrototypeTrim(cmd), 'npm ') && | | 935 | + !(e instanceof Recoverable) | | 936 | + ) { | 935 | 937 | self.output.write('npm should be run outside of the ' + | 936 | 938 | 'Node.js REPL, in your normal shell.\n' + | 937 | 939 | '(Press Ctrl+D to exit.)\n'); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-repl.js +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -129,6 +129,17 @@ const strictModeTests = [ | 129 | 129 | }, | 130 | 130 | ]; | 131 | 131 |
| | 132 | +const possibleTokensAfterIdentifierWithLineBreak = [ | | 133 | + '(\n)', | | 134 | + '[\n0]', | | 135 | + '+\n1', '- \n1', '* \n1', '/ \n1', '% \n1', '** \n1', | | 136 | + '== \n1', '=== \n1', '!= \n1', '!== \n1', '< \n1', '> \n1', '<= \n1', '>= \n1', | | 137 | + '&& \n1', '|| \n1', '?? \n1', | | 138 | + '= \n1', '+= \n1', '-= \n1', '*= \n1', '/= \n1', '%= \n1', | | 139 | + ': \n', | | 140 | + '? \n1: 1', | | 141 | +]; | | 142 | + | 132 | 143 | const errorTests = [ | 133 | 144 | // Uncaught error throws and prints out | 134 | 145 | { | @@ -386,6 +397,16 @@ const errorTests = [ | 386 | 397 | '(Press Ctrl+D to exit.)', | 387 | 398 | ] | 388 | 399 | }, | | 400 | + { | | 401 | + send: 'let npm = () => {};', | | 402 | + expect: 'undefined' | | 403 | + }, | | 404 | + ...possibleTokensAfterIdentifierWithLineBreak.map((token) => ( | | 405 | + { | | 406 | + send: `npm ${token}; undefined`, | | 407 | + expect: '... undefined' | | 408 | + } | | 409 | + )), | 389 | 410 | { | 390 | 411 | send: '(function() {\n\nreturn 1;\n})()', | 391 | 412 | expect: '... ... ... 1' | |
|