Skip to content

Commit 53f58b4

Browse files
authored
Merge pull request #476 from steelbrain/stelbrain/no-trim-followup
No trim follow up
2 parents c4bc27f + 8b49f1a commit 53f58b4

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#### Upcoming
2+
3+
- Add `noTrim` option to exec methods for cases where you do not want node-ssh to automatically trim the outputs.
4+
15
#### 13.1.0
26

37
- Add new methods around sockets forwarding. #460 (Thanks @mat-sz)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export interface SSHExecCommandOptions {
143143
stdin?: string | stream.Readable
144144
execOptions?: ExecOptions
145145
encoding?: BufferEncoding
146+
noTrim?: boolean
146147
onChannel?: (clientChannel: ClientChannel) => void
147148
onStdout?: (chunk: Buffer) => void
148149
onStderr?: (chunk: Buffer) => void

src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ export class NodeSSH {
369369
options.onStderr == null || typeof options.onStderr === 'function',
370370
'options.onStderr must be a valid function',
371371
)
372+
invariant(options.noTrim == null || typeof options.noTrim === 'boolean', 'options.noTrim must be a boolean')
372373

373374
let command = givenCommand
374375

@@ -428,8 +429,8 @@ export class NodeSSH {
428429
resolve({
429430
code: code != null ? code : null,
430431
signal: signal != null ? signal : null,
431-
stdout: stdout,
432-
stderr: stderr,
432+
stdout,
433+
stderr,
433434
})
434435
})
435436
})

test/main-test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,11 @@ sshit('forwards an inbound TCP/IP connection to client with automatically assign
494494
connectWithPassword(port, client)
495495
})
496496
})
497+
sshit('has a working noTrim option', async function (t, port, client) {
498+
await connectWithPassword(port, client)
499+
const resultWithTrim = await client.exec('echo', ["\nhello\n\n\n\n"], {stream: 'stdout'})
500+
t.is(resultWithTrim, 'hello')
501+
502+
const resultWithoutTrim = await client.exec('echo', ['\n\n\nhi\n\n\n'], {stream: 'stdout', noTrim: true})
503+
t.is(resultWithoutTrim, '\n\n\nhi\n\n\n\n')
504+
})

0 commit comments

Comments
 (0)