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 || '' 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)