From 0a6c5a0ec414c4728fe930b85df588e2f2e6de2d Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Fri, 23 Jul 2021 22:24:04 +0100 Subject: [PATCH] fix(fs): replace fs imports with locally defined WriteStream interface --- src/api/viya/saveLog.ts | 2 +- src/api/viya/writeStream.ts | 4 ++-- src/types/WriteStream.ts | 4 ++++ src/types/index.ts | 1 + src/utils/index.ts | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 src/types/WriteStream.ts diff --git a/src/api/viya/saveLog.ts b/src/api/viya/saveLog.ts index 3bbd498..2b5ec08 100644 --- a/src/api/viya/saveLog.ts +++ b/src/api/viya/saveLog.ts @@ -1,7 +1,7 @@ import { Job } from '../..' import { RequestClient } from '../../request/RequestClient' import { fetchLog } from '../../utils' -import { WriteStream } from 'fs' +import { WriteStream } from '../../types' import { writeStream } from './writeStream' /** diff --git a/src/api/viya/writeStream.ts b/src/api/viya/writeStream.ts index dc09885..0baaaa0 100644 --- a/src/api/viya/writeStream.ts +++ b/src/api/viya/writeStream.ts @@ -1,11 +1,11 @@ -import { WriteStream } from 'fs' +import { WriteStream } from '../../types' export const writeStream = async ( stream: WriteStream, content: string ): Promise => { return new Promise((resolve, reject) => { - stream.write(content + '\n\nnext chunk\n\n', (e) => { + stream.write(content + '\n', (e) => { if (e) { return reject(e) } diff --git a/src/types/WriteStream.ts b/src/types/WriteStream.ts new file mode 100644 index 0000000..83a1d13 --- /dev/null +++ b/src/types/WriteStream.ts @@ -0,0 +1,4 @@ +export interface WriteStream { + write: (content: string, callback: (err?: Error) => any) => void + path: string +} diff --git a/src/types/index.ts b/src/types/index.ts index 313aef2..2303619 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -11,3 +11,4 @@ export * from './SASjsRequest' export * from './Session' export * from './UploadFile' export * from './PollOptions' +export * from './WriteStream' diff --git a/src/utils/index.ts b/src/utils/index.ts index 9f70293..2a05d63 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,7 @@ export * from './asyncForEach' export * from './compareTimestamps' export * from './convertToCsv' +export * from './isNode' export * from './isRelativePath' export * from './isUri' export * from './isUrl'