From 6a32006a78322d09f3542183a2aeff66116ceb44 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sun, 26 Apr 2020 01:10:28 -0400 Subject: [PATCH 1/2] Fix interactive flag so that it forces REPL even when stdin is not a tty --- src/bin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bin.ts b/src/bin.ts index 9d923967d..001e1f483 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -227,7 +227,8 @@ export function main (argv: string[]) { Module.runMain() } else { // Piping of execution _only_ occurs when no other script is specified. - if (process.stdin.isTTY) { + // --interactive flag forces REPL + if (interactive || process.stdin.isTTY) { startRepl(service, state, code) } else { let buffer = code || '' From 9bd86e88ed7ee26c76f19da58919d6beb1bd84c4 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Sun, 26 Apr 2020 01:31:30 -0400 Subject: [PATCH 2/2] Add test --- src/index.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/index.spec.ts b/src/index.spec.ts index ce3ba1639..8e7007175 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -260,6 +260,21 @@ describe('ts-node', function () { cp.stdin!.end('true') }) + it('should run REPL when --interactive passed and stdin is not a TTY', function (done) { + const cp = exec(`${cmd} --interactive`, function (err, stdout) { + expect(err).to.equal(null) + expect(stdout).to.equal( + '> 123\n' + + 'undefined\n' + + '> ' + ) + return done() + }) + + cp.stdin!.end('console.log("123")\n') + + }) + it('should support require flags', function (done) { exec(`${cmd} -r ./tests/hello-world -pe "console.log('success')"`, function (err, stdout) { expect(err).to.equal(null)