@@ -1,6 +1,5 @@
11const repl = require('repl');
22const path = require('path');
3−const { isatty } = require('tty');
43const assets_dir =
54 process.env.PRYBAR_ASSETS_DIR || path.join(process.cwd(), 'prybar_assets');
65/**
@@ -13,7 +12,7 @@ const rl = require(path.join(assets_dir, 'nodejs', 'input-sync.js'));
1312const { runCode, runModule, getRepl } = require(path.join(
1413 assets_dir,
1514 'nodejs',
16− 'module-context-hook.js',
15+ 'module-context-hook.js'
1716));
1817
1918// imports to builtin modules don't get added to require.cache.
@@ -32,7 +31,7 @@ Error.prepareStackTrace = function prepareStackTrace(error, callSites) {
3231
3332 const idx = callSites.findIndex((frame) => frame.getFunctionName() === null);
3433 const domainIndex = callSites.findIndex(
35− (site) => site.getFileName() === 'domain.js',
34+ (site) => site.getFileName() === 'domain.js'
3635 );
3736
3837 if (domainIndex !== -1 && domainIndex < idx) {
@@ -43,7 +42,7 @@ Error.prepareStackTrace = function prepareStackTrace(error, callSites) {
4342 callSites.reverse();
4443
4544 const lowestPrybarFileIndex = callSites.findIndex((site) =>
46− prybarFilenames.includes(site.getFileName()),
45+ prybarFilenames.includes(site.getFileName())
4746 );
4847
4948 callSites = callSites.slice(0, lowestPrybarFileIndex);
@@ -68,18 +67,16 @@ if (!process.env.PRYBAR_QUIET) {
6867 console.log('Node ' + process.version + ' on ' + process.platform);
6968}
7069
71−const isTTY = isatty(process.stdin.fd);
72−
73−// Red errors (if stdout is a TTY)
70+// Red errors (if stderr is a TTY)
7471function logError(msg) {
75− if (isTTY) {
76− process.stdout.write(`\u001b[0m\u001b[31m${msg}\u001b[0m`);
72+ if (process.stderr.isTTY) {
73+ process.stderr.write(`\u001b[0m\u001b[31m${msg}\u001b[0m`);
7774 } else {
78− process.stdout.write(msg);
75+ process.stderr.write(msg);
7976 }
8077
8178 if (!msg.endsWith('\n')) {
82− process.stdout.write('\n');
79+ process.stderr.write('\n');
8380 }
8481}
8582
@@ -99,7 +96,7 @@ function resumeRepl() {
9996
10097// Clear the line if it has anything on it.
10198function clearLine() {
102− if (isTTY && r && r.line) r.clearLine();
99+ if (process.stdout.isTTY && r && r.line) r.clearLine();
103100}
104101
105102// Adapted from the internal node repl code just a lot simpler and adds
@@ -179,6 +176,10 @@ if (process.env.PRYBAR_CODE) {
179176 runCode(process.env.PRYBAR_CODE, isInterractive);
180177 } catch (err) {
181178 handleError(err);
179+
180+ if (!isInterractive) {
181+ process.exit(1);
182+ }
182183 }
183184
184185 if (isInterractive) {
@@ -189,18 +190,26 @@ if (process.env.PRYBAR_CODE) {
189190 console.log(runCode(process.env.PRYBAR_EXP, false));
190191 } catch (err) {
191192 handleError(err);
193+
194+ if (!isInterractive) {
195+ process.exit(1);
196+ }
192197 }
193198} else if (process.env.PRYBAR_FILE) {
194199 try {
195200 runModule(process.env.PRYBAR_FILE, isInterractive);
196201 } catch (err) {
197202 handleError(err);
203+
204+ if (!isInterractive) {
205+ process.exit(1);
206+ }
198207 }
199208
200209 if (isInterractive) {
201− if (isTTY) {
210+ if (process.stdout.isTTY && process.stdin.isTTY) {
202211 console.log(
203− '\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m',
212+ '\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m'
204213 );
205214 }
206215