Skip to content

Commit 9fee232

Browse files
authored
Fix interactive flag so that it forces REPL even when stdin is not a tty (#1019)
* Fix interactive flag so that it forces REPL even when stdin is not a tty * Add test
1 parent 47a560b commit 9fee232

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/bin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ export function main (argv: string[]) {
227227
Module.runMain()
228228
} else {
229229
// Piping of execution _only_ occurs when no other script is specified.
230-
if (process.stdin.isTTY) {
230+
// --interactive flag forces REPL
231+
if (interactive || process.stdin.isTTY) {
231232
startRepl(service, state, code)
232233
} else {
233234
let buffer = code || ''

src/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ describe('ts-node', function () {
260260
cp.stdin!.end('true')
261261
})
262262

263+
it('should run REPL when --interactive passed and stdin is not a TTY', function (done) {
264+
const cp = exec(`${cmd} --interactive`, function (err, stdout) {
265+
expect(err).to.equal(null)
266+
expect(stdout).to.equal(
267+
'> 123\n' +
268+
'undefined\n' +
269+
'> '
270+
)
271+
return done()
272+
})
273+
274+
cp.stdin!.end('console.log("123")\n')
275+
276+
})
277+
263278
it('should support require flags', function (done) {
264279
exec(`${cmd} -r ./tests/hello-world -pe "console.log('success')"`, function (err, stdout) {
265280
expect(err).to.equal(null)

0 commit comments

Comments
 (0)